/* * Copyright (c) 2020, Idan Horowitz * Copyright (c) 2021, the SerenityOS developers * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "MouseSettingsWindow.h" #include #include #include #include #include #include #include #include #include #include constexpr double speed_slider_scale = 100.0; constexpr int default_scroll_length = 4; constexpr int double_click_speed_default = 250; void MouseSettingsWindow::update_window_server() { const float factor = m_speed_slider->value() / speed_slider_scale; GUI::WindowServerConnection::the().send_sync(factor); GUI::WindowServerConnection::the().send_sync(m_scroll_length_spinbox->value()); GUI::WindowServerConnection::the().send_sync(m_double_click_speed_slider->value()); } void MouseSettingsWindow::reset_default_values() { m_speed_slider->set_value(speed_slider_scale); m_scroll_length_spinbox->set_value(default_scroll_length); m_double_click_speed_slider->set_value(double_click_speed_default); update_window_server(); } MouseSettingsWindow::MouseSettingsWindow() { auto& main_widget = set_main_widget(); main_widget.load_from_gml(mouse_settings_window_gml); m_speed_label = *main_widget.find_descendant_of_type_named("speed_label"); m_speed_slider = *main_widget.find_descendant_of_type_named("speed_slider"); m_speed_slider->set_range(WindowServer::mouse_accel_min * speed_slider_scale, WindowServer::mouse_accel_max * speed_slider_scale); m_speed_slider->on_change = [&](const int value) { m_speed_label->set_text(String::formatted("{} %", value)); }; const int slider_value = speed_slider_scale * GUI::WindowServerConnection::the().send_sync()->factor(); m_speed_slider->set_value(slider_value); m_scroll_length_spinbox = *main_widget.find_descendant_of_type_named("scroll_length_spinbox"); m_scroll_length_spinbox->set_min(WindowServer::scroll_step_size_min); m_scroll_length_spinbox->set_value(GUI::WindowServerConnection::the().send_sync()->step_size()); m_double_click_speed_label = *main_widget.find_descendant_of_type_named("double_click_speed_label"); m_double_click_speed_slider = *main_widget.find_descendant_of_type_named("double_click_speed_slider"); m_double_click_speed_slider->set_min(WindowServer::double_click_speed_min); m_double_click_speed_slider->set_max(WindowServer::double_click_speed_max); m_double_click_speed_slider->on_change = [&](const int value) { m_double_click_speed_label->set_text(String::formatted("{} ms", value)); }; m_double_click_speed_slider->set_value(GUI::WindowServerConnection::the().send_sync()->speed()); m_ok_button = *main_widget.find_descendant_of_type_named("ok_button"); m_ok_button->on_click = [this](auto) { update_window_server(); GUI::Application::the()->quit(); }; m_apply_button = *main_widget.find_descendant_of_type_named("apply_button"); m_apply_button->on_click = [this](auto) { update_window_server(); }; m_reset_button = *main_widget.find_descendant_of_type_named("reset_button"); m_reset_button->on_click = [this](auto) { reset_default_values(); }; } MouseSettingsWindow::~MouseSettingsWindow() { }