WindowServer: Add "Natural scrolling" support

Also commonly referred to as "reverse scrolling" or "inverted
scrolling".
This commit is contained in:
Filiph Sandström 2022-11-30 13:45:35 +01:00 committed by Linus Groh
parent bef9ad4e44
commit 5a083c03a6
7 changed files with 39 additions and 1 deletions

View file

@ -23,6 +23,7 @@ AccelerationFactor=1.0
ScrollStepSize=4 ScrollStepSize=4
CursorTheme=Default CursorTheme=Default
ButtonsSwitched=false ButtonsSwitched=false
NaturalScroll=false
[Graphics] [Graphics]
OverlayRectShadow=/res/graphics/overlay-rect-shadow.png OverlayRectShadow=/res/graphics/overlay-rect-shadow.png

View file

@ -1110,6 +1110,16 @@ Messages::WindowServer::GetButtonsSwitchedResponse ConnectionFromClient::get_but
return WindowManager::the().get_buttons_switched(); return WindowManager::the().get_buttons_switched();
} }
void ConnectionFromClient::set_natural_scroll(bool inverted)
{
WindowManager::the().set_natural_scroll(inverted);
}
Messages::WindowServer::IsNaturalScrollResponse ConnectionFromClient::is_natural_scroll()
{
return WindowManager::the().is_natural_scroll();
}
void ConnectionFromClient::set_unresponsive(bool unresponsive) void ConnectionFromClient::set_unresponsive(bool unresponsive)
{ {
if (m_unresponsive == unresponsive) if (m_unresponsive == unresponsive)

View file

@ -178,6 +178,8 @@ private:
virtual Messages::WindowServer::GetDoubleClickSpeedResponse get_double_click_speed() override; virtual Messages::WindowServer::GetDoubleClickSpeedResponse get_double_click_speed() override;
virtual void set_buttons_switched(bool) override; virtual void set_buttons_switched(bool) override;
virtual Messages::WindowServer::GetButtonsSwitchedResponse get_buttons_switched() override; virtual Messages::WindowServer::GetButtonsSwitchedResponse get_buttons_switched() override;
virtual void set_natural_scroll(bool) override;
virtual Messages::WindowServer::IsNaturalScrollResponse is_natural_scroll() override;
virtual void set_window_modified(i32, bool) override; virtual void set_window_modified(i32, bool) override;
virtual Messages::WindowServer::IsWindowModifiedResponse is_window_modified(i32) override; virtual Messages::WindowServer::IsWindowModifiedResponse is_window_modified(i32) override;
virtual Messages::WindowServer::GetDesktopDisplayScaleResponse get_desktop_display_scale(u32) override; virtual Messages::WindowServer::GetDesktopDisplayScaleResponse get_desktop_display_scale(u32) override;

View file

@ -70,10 +70,15 @@ void EventLoop::drain_mouse()
state.x = packet.x; state.x = packet.x;
state.y = packet.y; state.y = packet.y;
} }
state.z += packet.z;
state.w += packet.w; state.w += packet.w;
state_is_sent = false; state_is_sent = false;
// Invert scroll direction if checked in the settings.
if (WindowManager::the().is_natural_scroll())
state.z -= packet.z;
else
state.z += packet.z;
if (packet.buttons != state.buttons) { if (packet.buttons != state.buttons) {
state.buttons = packet.buttons; state.buttons = packet.buttons;
dbgln_if(WSMESSAGELOOP_DEBUG, "EventLoop: Mouse Button Event"); dbgln_if(WSMESSAGELOOP_DEBUG, "EventLoop: Mouse Button Event");

View file

@ -83,6 +83,7 @@ void WindowManager::reload_config()
m_double_click_speed = m_config->read_num_entry("Input", "DoubleClickSpeed", 250); m_double_click_speed = m_config->read_num_entry("Input", "DoubleClickSpeed", 250);
m_buttons_switched = m_config->read_bool_entry("Mouse", "ButtonsSwitched", false); m_buttons_switched = m_config->read_bool_entry("Mouse", "ButtonsSwitched", false);
m_natural_scroll = m_config->read_bool_entry("Mouse", "NaturalScroll", false);
m_cursor_highlight_radius = m_config->read_num_entry("Mouse", "CursorHighlightRadius", 25); m_cursor_highlight_radius = m_config->read_num_entry("Mouse", "CursorHighlightRadius", 25);
Color default_highlight_color = Color::NamedColor::Red; Color default_highlight_color = Color::NamedColor::Red;
default_highlight_color.set_alpha(110); default_highlight_color.set_alpha(110);
@ -305,6 +306,19 @@ bool WindowManager::get_buttons_switched() const
return m_buttons_switched; return m_buttons_switched;
} }
void WindowManager::set_natural_scroll(bool inverted)
{
m_natural_scroll = inverted;
dbgln("Saving scroll inverted state {} to config file at {}", inverted, m_config->filename());
m_config->write_bool_entry("Mouse", "NaturalScroll", inverted);
sync_config_to_disk();
}
bool WindowManager::is_natural_scroll() const
{
return m_natural_scroll;
}
WindowStack& WindowManager::window_stack_for_window(Window& window) WindowStack& WindowManager::window_stack_for_window(Window& window)
{ {
if (is_stationary_window_type(window.type())) if (is_stationary_window_type(window.type()))

View file

@ -153,6 +153,8 @@ public:
int double_click_speed() const; int double_click_speed() const;
void set_buttons_switched(bool); void set_buttons_switched(bool);
bool get_buttons_switched() const; bool get_buttons_switched() const;
void set_natural_scroll(bool);
bool is_natural_scroll() const;
void set_active_window(Window*); void set_active_window(Window*);
void set_hovered_button(Button*); void set_hovered_button(Button*);
@ -433,6 +435,7 @@ private:
int m_max_distance_for_double_click { 4 }; int m_max_distance_for_double_click { 4 };
bool m_previous_event_was_super_keydown { false }; bool m_previous_event_was_super_keydown { false };
bool m_buttons_switched { false }; bool m_buttons_switched { false };
bool m_natural_scroll { false };
bool m_theme_overridden { false }; bool m_theme_overridden { false };
WeakPtr<Window> m_hovered_window; WeakPtr<Window> m_hovered_window;

View file

@ -176,6 +176,9 @@ endpoint WindowServer
set_buttons_switched(bool switched) =| set_buttons_switched(bool switched) =|
get_buttons_switched() => (bool switched) get_buttons_switched() => (bool switched)
set_natural_scroll(bool inverted) =|
is_natural_scroll() => (bool inverted)
get_desktop_display_scale(u32 screen_index) => (int desktop_display_scale) get_desktop_display_scale(u32 screen_index) => (int desktop_display_scale)
set_flash_flush(bool enabled) =| set_flash_flush(bool enabled) =|