summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Martinelli <martinellia@google.com>2021-07-08 21:27:05 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-08 22:45:40 +0200
commitab1caad1e95acafa04fc4a65a75810d3763407c6 (patch)
tree58707fa936e039715dfdcadbc328c44725e7e0f9
parentdac7b25b8aa1cb2530d39e0b6a36c2af87ff68f0 (diff)
downloadserenity-ab1caad1e95acafa04fc4a65a75810d3763407c6.zip
Taskbar: Make clicks at the edges and corners work as expected
This makes it easy for the user to just throw the mouse at the corner of the screen and obtain the desired outcome (eg. opening the start menu), without having to precisely position the cursor over one of the buttons.
-rw-r--r--Userland/Services/Taskbar/TaskbarWindow.cpp22
-rw-r--r--Userland/Services/Taskbar/TaskbarWindow.h1
2 files changed, 23 insertions, 0 deletions
diff --git a/Userland/Services/Taskbar/TaskbarWindow.cpp b/Userland/Services/Taskbar/TaskbarWindow.cpp
index 3c2c36e116..0d49e07eab 100644
--- a/Userland/Services/Taskbar/TaskbarWindow.cpp
+++ b/Userland/Services/Taskbar/TaskbarWindow.cpp
@@ -244,6 +244,28 @@ void TaskbarWindow::update_window_button(::Window& window, bool show_as_active)
return parent;
}
+void TaskbarWindow::event(Core::Event& event)
+{
+ if (event.type() == GUI::Event::MouseDown) {
+ // If the cursor is at the edge/corner of the screen but technically not within the start button (or other taskbar buttons),
+ // we adjust it so that the nearest button ends up being clicked anyways.
+
+ auto& mouse_event = static_cast<GUI::MouseEvent&>(event);
+ const int ADJUSTMENT = 4;
+ auto adjusted_x = AK::clamp(mouse_event.x(), ADJUSTMENT, width() - ADJUSTMENT);
+ auto adjusted_y = AK::min(mouse_event.y(), height() - ADJUSTMENT);
+ Gfx::IntPoint adjusted_point = { adjusted_x, adjusted_y };
+
+ if (adjusted_point != mouse_event.position()) {
+ GUI::WindowServerConnection::the().async_set_global_cursor_position(position() + adjusted_point);
+ GUI::MouseEvent adjusted_event = { (GUI::Event::Type)mouse_event.type(), adjusted_point, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers(), mouse_event.wheel_delta() };
+ Window::event(adjusted_event);
+ return;
+ }
+ }
+ Window::event(event);
+}
+
void TaskbarWindow::wm_event(GUI::WMEvent& event)
{
WindowIdentifier identifier { event.client_id(), event.window_id() };
diff --git a/Userland/Services/Taskbar/TaskbarWindow.h b/Userland/Services/Taskbar/TaskbarWindow.h
index 2fbb17d402..1f35507048 100644
--- a/Userland/Services/Taskbar/TaskbarWindow.h
+++ b/Userland/Services/Taskbar/TaskbarWindow.h
@@ -30,6 +30,7 @@ private:
void update_window_button(::Window&, bool);
::Window* find_window_owner(::Window&) const;
+ virtual void event(Core::Event&) override;
virtual void wm_event(GUI::WMEvent&) override;
virtual void screen_rects_change_event(GUI::ScreenRectsChangeEvent&) override;