1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:57:34 +00:00

MouseSettings: Use latest (unsaved) setting for testing double-click

Instead of using the doubleclick_event this uses the current double-
click speed setting to check whether or not the colors of the double-
click icon should be inverted. This allows us to use the current (and
unsaved) setting for comparison instead of having to apply the settings
first.
This commit is contained in:
Mathias Jakobsen 2021-07-20 23:49:47 +01:00 committed by Andreas Kling
parent 7e8a5d7323
commit 4384a236b0
2 changed files with 20 additions and 4 deletions

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Mathias Jakobsen <mathias@jbcoding.com>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -54,10 +55,22 @@ void DoubleClickArrowWidget::paint_event(GUI::PaintEvent& event)
text_rect.set_height(font().glyph_height()); text_rect.set_height(font().glyph_height());
} }
void DoubleClickArrowWidget::doubleclick_event(GUI::MouseEvent&) void DoubleClickArrowWidget::mousedown_event(GUI::MouseEvent&)
{ {
m_inverted = !m_inverted; if (!m_double_click_timer.is_valid()) {
update(); m_double_click_timer.start();
return;
}
auto elapsed_time = m_double_click_timer.elapsed();
if (elapsed_time <= m_double_click_speed) {
dbgln("Double-click in {}ms", elapsed_time);
m_inverted = !m_inverted;
update();
}
// Reset the timer after each click
m_double_click_timer.start();
} }
} }

View file

@ -1,11 +1,13 @@
/* /*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Mathias Jakobsen <mathias@jbcoding.com>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#pragma once #pragma once
#include <LibCore/ElapsedTimer.h>
#include <LibGUI/Widget.h> #include <LibGUI/Widget.h>
namespace MouseSettings { namespace MouseSettings {
@ -20,11 +22,12 @@ public:
private: private:
DoubleClickArrowWidget(); DoubleClickArrowWidget();
virtual void paint_event(GUI::PaintEvent&) override; virtual void paint_event(GUI::PaintEvent&) override;
virtual void doubleclick_event(GUI::MouseEvent&) override; virtual void mousedown_event(GUI::MouseEvent&) override;
RefPtr<Gfx::Bitmap> m_arrow_bitmap; RefPtr<Gfx::Bitmap> m_arrow_bitmap;
int m_double_click_speed { 0 }; int m_double_click_speed { 0 };
bool m_inverted { false }; bool m_inverted { false };
Core::ElapsedTimer m_double_click_timer;
}; };
} }