1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 16:55:08 +00:00

WindowServer: Added configurable mouse acceleration and scroll length

The settings are also saved to the config file to survive reboots.
This commit is contained in:
Idan Horowitz 2020-12-29 23:32:54 +02:00 committed by Andreas Kling
parent 0c51778510
commit db409db4e9
6 changed files with 51 additions and 2 deletions

View file

@ -5,6 +5,10 @@ Height=768
[Theme] [Theme]
Name=Default Name=Default
[Mouse]
AccelerationFactor=1.0
ScrollStepSize=4
[Cursor] [Cursor]
Hidden=/res/cursors/hidden.png Hidden=/res/cursors/hidden.png
Arrow=/res/cursors/arrow.x2y2.png Arrow=/res/cursors/arrow.x2y2.png

View file

@ -116,11 +116,23 @@ void Screen::set_buffer(int index)
ASSERT(rc == 0); ASSERT(rc == 0);
} }
void Screen::set_acceleration_factor(double factor)
{
ASSERT(factor >= mouse_accel_min && factor <= mouse_accel_max);
m_acceleration_factor = factor;
}
void Screen::set_scroll_step_size(unsigned step_size)
{
ASSERT(step_size >= scroll_step_size_min);
m_scroll_step_size = step_size;
}
void Screen::on_receive_mouse_data(const MousePacket& packet) void Screen::on_receive_mouse_data(const MousePacket& packet)
{ {
auto prev_location = m_cursor_location; auto prev_location = m_cursor_location;
if (packet.is_relative) { if (packet.is_relative) {
m_cursor_location.move_by(packet.x, packet.y); m_cursor_location.move_by(packet.x * m_acceleration_factor, packet.y * m_acceleration_factor);
#ifdef WSSCREEN_DEBUG #ifdef WSSCREEN_DEBUG
dbgprintf("Screen: New Relative mouse point @ X %d, Y %d\n", m_cursor_location.x(), m_cursor_location.y()); dbgprintf("Screen: New Relative mouse point @ X %d, Y %d\n", m_cursor_location.x(), m_cursor_location.y());
#endif #endif
@ -154,7 +166,7 @@ void Screen::on_receive_mouse_data(const MousePacket& packet)
} }
if (packet.z) { if (packet.z) {
auto message = make<MouseEvent>(Event::MouseWheel, m_cursor_location, buttons, MouseButton::None, m_modifiers, packet.z); auto message = make<MouseEvent>(Event::MouseWheel, m_cursor_location, buttons, MouseButton::None, m_modifiers, packet.z * m_scroll_step_size);
Core::EventLoop::current().post_event(WindowManager::the(), move(message)); Core::EventLoop::current().post_event(WindowManager::the(), move(message));
} }

View file

@ -35,6 +35,10 @@ struct MousePacket;
namespace WindowServer { namespace WindowServer {
const double mouse_accel_max = 3.5;
const double mouse_accel_min = 0.5;
const unsigned scroll_step_size_min = 1;
class Screen { class Screen {
public: public:
Screen(unsigned width, unsigned height); Screen(unsigned width, unsigned height);
@ -57,6 +61,12 @@ public:
Gfx::IntPoint cursor_location() const { return m_cursor_location; } Gfx::IntPoint cursor_location() const { return m_cursor_location; }
unsigned mouse_button_state() const { return m_mouse_button_state; } unsigned mouse_button_state() const { return m_mouse_button_state; }
double acceleration_factor() const { return m_acceleration_factor; }
void set_acceleration_factor(double);
unsigned scroll_step_size() const { return m_scroll_step_size; }
void set_scroll_step_size(unsigned);
void on_receive_mouse_data(const MousePacket&); void on_receive_mouse_data(const MousePacket&);
void on_receive_keyboard_data(::KeyEvent); void on_receive_keyboard_data(::KeyEvent);
@ -76,6 +86,8 @@ private:
Gfx::IntPoint m_cursor_location; Gfx::IntPoint m_cursor_location;
unsigned m_mouse_button_state { 0 }; unsigned m_mouse_button_state { 0 };
unsigned m_modifiers { 0 }; unsigned m_modifiers { 0 };
double m_acceleration_factor { 1.0 };
unsigned m_scroll_step_size { 1 };
}; };
inline Gfx::RGBA32* Screen::scanline(int y) inline Gfx::RGBA32* Screen::scanline(int y)

View file

@ -163,6 +163,22 @@ Gfx::IntSize WindowManager::resolution() const
return Screen::the().size(); return Screen::the().size();
} }
void WindowManager::set_acceleration_factor(double factor)
{
Screen::the().set_acceleration_factor(factor);
dbgln("Saving acceleration factor {} to config file at {}", factor, m_config->file_name());
m_config->write_entry("Mouse", "AccelerationFactor", String::formatted("{}", factor));
m_config->sync();
}
void WindowManager::set_scroll_step_size(unsigned step_size)
{
Screen::the().set_scroll_step_size(step_size);
dbgln("Saving scroll step size {} to config file at {}", step_size, m_config->file_name());
m_config->write_entry("Mouse", "ScrollStepSize", String::number(step_size));
m_config->sync();
}
void WindowManager::add_window(Window& window) void WindowManager::add_window(Window& window)
{ {
bool is_first_window = m_windows_in_order.is_empty(); bool is_first_window = m_windows_in_order.is_empty();

View file

@ -145,6 +145,9 @@ public:
bool set_resolution(int width, int height); bool set_resolution(int width, int height);
Gfx::IntSize resolution() const; Gfx::IntSize resolution() const;
void set_acceleration_factor(double);
void set_scroll_step_size(unsigned);
Window* set_active_input_window(Window*); Window* set_active_input_window(Window*);
void restore_active_input_window(Window*); void restore_active_input_window(Window*);
void set_active_window(Window*, bool make_input = true); void set_active_window(Window*, bool make_input = true);

View file

@ -91,6 +91,8 @@ int main(int, char**)
WindowServer::Screen screen(wm_config->read_num_entry("Screen", "Width", 1024), WindowServer::Screen screen(wm_config->read_num_entry("Screen", "Width", 1024),
wm_config->read_num_entry("Screen", "Height", 768)); wm_config->read_num_entry("Screen", "Height", 768));
screen.set_acceleration_factor(atof(wm_config->read_entry("Mouse", "AccelerationFactor", "1.0").characters()));
screen.set_scroll_step_size(wm_config->read_num_entry("Mouse", "ScrollStepSize", 4));
WindowServer::Compositor::the(); WindowServer::Compositor::the();
auto wm = WindowServer::WindowManager::construct(*palette); auto wm = WindowServer::WindowManager::construct(*palette);
auto am = WindowServer::AppletManager::construct(); auto am = WindowServer::AppletManager::construct();