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]
Name=Default
[Mouse]
AccelerationFactor=1.0
ScrollStepSize=4
[Cursor]
Hidden=/res/cursors/hidden.png
Arrow=/res/cursors/arrow.x2y2.png

View file

@ -116,11 +116,23 @@ void Screen::set_buffer(int index)
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)
{
auto prev_location = m_cursor_location;
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
dbgprintf("Screen: New Relative mouse point @ X %d, Y %d\n", m_cursor_location.x(), m_cursor_location.y());
#endif
@ -154,7 +166,7 @@ void Screen::on_receive_mouse_data(const MousePacket& packet)
}
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));
}

View file

@ -35,6 +35,10 @@ struct MousePacket;
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 {
public:
Screen(unsigned width, unsigned height);
@ -57,6 +61,12 @@ public:
Gfx::IntPoint cursor_location() const { return m_cursor_location; }
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_keyboard_data(::KeyEvent);
@ -76,6 +86,8 @@ private:
Gfx::IntPoint m_cursor_location;
unsigned m_mouse_button_state { 0 };
unsigned m_modifiers { 0 };
double m_acceleration_factor { 1.0 };
unsigned m_scroll_step_size { 1 };
};
inline Gfx::RGBA32* Screen::scanline(int y)

View file

@ -163,6 +163,22 @@ Gfx::IntSize WindowManager::resolution() const
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)
{
bool is_first_window = m_windows_in_order.is_empty();

View file

@ -145,6 +145,9 @@ public:
bool set_resolution(int width, int height);
Gfx::IntSize resolution() const;
void set_acceleration_factor(double);
void set_scroll_step_size(unsigned);
Window* set_active_input_window(Window*);
void restore_active_input_window(Window*);
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),
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();
auto wm = WindowServer::WindowManager::construct(*palette);
auto am = WindowServer::AppletManager::construct();