From 4f1d45705f40a76cdd61c6c21bbaacaae2ce6abb Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Tue, 26 Oct 2021 12:13:54 +0300 Subject: [PATCH] Demos: Remap mouse button events to physical buttons in MouseDemo This ensures we paint the left button as clicked when the left mouse button is pressed (and vice-versa with the right one) when the right mouse button is set as the primary one in the mouse settings. --- Userland/Demos/Mouse/main.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Userland/Demos/Mouse/main.cpp b/Userland/Demos/Mouse/main.cpp index 30ddda64e5e..b6794826981 100644 --- a/Userland/Demos/Mouse/main.cpp +++ b/Userland/Demos/Mouse/main.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2021, Idan Horowitz * * SPDX-License-Identifier: BSD-2-Clause */ @@ -15,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -70,12 +72,16 @@ public: painter.stroke_path(path, Color::Black, 1); - if (m_buttons & GUI::MouseButton::Left) { + auto primary_secondary_switched = GUI::WindowServerConnection::the().get_buttons_switched(); + auto primary_pressed = m_buttons & GUI::MouseButton::Left; + auto secondary_pressed = m_buttons & GUI::MouseButton::Right; + + if (primary_secondary_switched ? secondary_pressed : primary_pressed) { painter.fill_rect({ 31, 21, 34, 44 }, Color::Blue); painter.draw_triangle({ 30, 21 }, { 65, 21 }, { 65, 12 }, Color::Blue); } - if (m_buttons & GUI::MouseButton::Right) { + if (primary_secondary_switched ? primary_pressed : secondary_pressed) { painter.fill_rect({ 96, 21, 34, 44 }, Color::Blue); painter.draw_triangle({ 96, 12 }, { 96, 21 }, { 132, 21 }, Color::Blue); }