1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:37:34 +00:00

MouseSettings: Add option to reverse buttons

Add option to reverse primary and secondary buttons in Mouse Settings.
- WindowServer.ini: add default entry
- switch-mouse-buttons.png: new icon for settings entry
- Mouse.gml/MouseWidget.*: new settings dialog
- ClientConnection/WindowManager/Server: window message for settings
- EventLoop.cpp: swap buttons 1 and 2 if settings are on
This commit is contained in:
Andrew Pardoe 2021-10-24 19:47:33 -07:00 committed by Idan Horowitz
parent 5599d22744
commit 0e68550c05
11 changed files with 90 additions and 0 deletions

View file

@ -921,6 +921,16 @@ Messages::WindowServer::GetDoubleClickSpeedResponse ClientConnection::get_double
return WindowManager::the().double_click_speed();
}
void ClientConnection::set_buttons_switched(bool switched)
{
WindowManager::the().set_buttons_switched(switched);
}
Messages::WindowServer::GetButtonsSwitchedResponse ClientConnection::get_buttons_switched()
{
return WindowManager::the().get_buttons_switched();
}
void ClientConnection::set_unresponsive(bool unresponsive)
{
if (m_unresponsive == unresponsive)

View file

@ -160,6 +160,8 @@ private:
virtual Messages::WindowServer::GetScreenBitmapAroundCursorResponse get_screen_bitmap_around_cursor(Gfx::IntSize const&) override;
virtual void set_double_click_speed(i32) override;
virtual Messages::WindowServer::GetDoubleClickSpeedResponse get_double_click_speed() override;
virtual void set_buttons_switched(bool) override;
virtual Messages::WindowServer::GetButtonsSwitchedResponse get_buttons_switched() override;
virtual void set_window_modified(i32, bool) override;
virtual Messages::WindowServer::IsWindowModifiedResponse is_window_modified(i32) override;
virtual Messages::WindowServer::GetDesktopDisplayScaleResponse get_desktop_display_scale(u32) override;

View file

@ -106,6 +106,20 @@ void EventLoop::drain_mouse()
if (packet.buttons != state.buttons) {
state.buttons = packet.buttons;
dbgln_if(WSMESSAGELOOP_DEBUG, "EventLoop: Mouse Button Event");
// Swap primary (1) and secondary (2) buttons if checked in Settings.
// Doing the swap here avoids all emulator and hardware issues.
if (WindowManager::the().get_buttons_switched()) {
bool has_primary = state.buttons & MousePacket::Button::LeftButton;
bool has_secondary = state.buttons & MousePacket::Button::RightButton;
state.buttons = state.buttons & ~(MousePacket::Button::LeftButton | MousePacket::Button::RightButton);
// Invert the buttons:
if (has_primary)
state.buttons |= MousePacket::Button::RightButton;
if (has_secondary)
state.buttons |= MousePacket::Button::LeftButton;
}
screen_input.on_receive_mouse_data(state);
state_is_sent = true;
if (state.is_relative) {

View file

@ -71,6 +71,7 @@ void WindowManager::reload_config()
apply_virtual_desktop_settings(virtual_desktop_rows, virtual_desktop_columns, false);
m_double_click_speed = m_config->read_num_entry("Input", "DoubleClickSpeed", 250);
m_buttons_switched = m_config->read_bool_entry("Mouse", "ButtonsSwitched", false);
apply_cursor_theme(m_config->read_entry("Mouse", "CursorTheme", "Default"));
auto reload_graphic = [&](RefPtr<MultiScaleBitmaps>& bitmap, String const& name) {
@ -274,6 +275,19 @@ int WindowManager::double_click_speed() const
return m_double_click_speed;
}
void WindowManager::set_buttons_switched(bool switched)
{
m_buttons_switched = switched;
dbgln("Saving mouse buttons switched state {} to config file at {}", switched, m_config->filename());
m_config->write_bool_entry("Mouse", "ButtonsSwitched", switched);
m_config->sync();
}
bool WindowManager::get_buttons_switched() const
{
return m_buttons_switched;
}
WindowStack& WindowManager::window_stack_for_window(Window& window)
{
if (is_stationary_window_type(window.type()))

View file

@ -164,6 +164,8 @@ public:
void set_scroll_step_size(unsigned);
void set_double_click_speed(int);
int double_click_speed() const;
void set_buttons_switched(bool);
bool get_buttons_switched() const;
Window* set_active_input_window(Window*);
void restore_active_input_window(Window*);
@ -409,6 +411,7 @@ private:
int m_double_click_speed { 0 };
int m_max_distance_for_double_click { 4 };
bool m_previous_event_was_super_keydown { false };
bool m_buttons_switched { false };
WeakPtr<Window> m_hovered_window;
WeakPtr<Window> m_highlight_window;

View file

@ -144,6 +144,9 @@ endpoint WindowServer
set_double_click_speed(int speed) =|
get_double_click_speed() => (int speed)
set_buttons_switched(bool switched) =|
get_buttons_switched() => (bool switched)
get_desktop_display_scale(u32 screen_index) => (int desktop_display_scale)
set_flash_flush(bool enabled) =|