From 5caf307ec0c23da13deb106aa7d512bedc77d73e Mon Sep 17 00:00:00 2001 From: MacDue Date: Tue, 7 Jun 2022 23:41:04 +0100 Subject: [PATCH] WindowServer+MouseSettings: Toggle cursor highlighting with Super+H Rather than enabling/disabling cursor highlighting by going into mouse settings, you can now instead toggle it any time with Super+H. Mouse settings now is only for customising the look of the highlighting. --- .../Applications/MouseSettings/Highlight.gml | 12 ++-- .../MouseSettings/HighlightPreviewWidget.cpp | 10 ++- .../MouseSettings/HighlightWidget.cpp | 5 +- .../Services/WindowServer/WindowManager.cpp | 64 ++++++++++--------- .../Services/WindowServer/WindowManager.h | 3 +- 5 files changed, 46 insertions(+), 48 deletions(-) diff --git a/Userland/Applications/MouseSettings/Highlight.gml b/Userland/Applications/MouseSettings/Highlight.gml index 82fde1e358..21501a5e07 100644 --- a/Userland/Applications/MouseSettings/Highlight.gml +++ b/Userland/Applications/MouseSettings/Highlight.gml @@ -45,20 +45,20 @@ @GUI::Label { autosize: true - text: "0%" + text: "Low" } @GUI::Slider { name: "highlight_opacity_slider" orientation: "Horizontal" max: 230 - min: 0 + min: 30 value: 110 } @GUI::Label { autosize: true - text: "100%" + text: "High" } } } @@ -79,20 +79,20 @@ @GUI::Label { autosize: true - text: "Off" + text: "Small" } @GUI::Slider { name: "highlight_radius_slider" orientation: "Horizontal" max: 60 - min: 19 + min: 20 value: 25 } @GUI::Label { autosize: true - text: "Largest" + text: "Large" } } } diff --git a/Userland/Applications/MouseSettings/HighlightPreviewWidget.cpp b/Userland/Applications/MouseSettings/HighlightPreviewWidget.cpp index 1b467000ae..cfbd300e2a 100644 --- a/Userland/Applications/MouseSettings/HighlightPreviewWidget.cpp +++ b/Userland/Applications/MouseSettings/HighlightPreviewWidget.cpp @@ -51,12 +51,10 @@ ErrorOr HighlightPreviewWidget::reload_cursor() void HighlightPreviewWidget::paint_preview(GUI::PaintEvent&) { GUI::Painter painter(*this); - if (m_radius > 0 && m_color.alpha() > 0) { - Gfx::AntiAliasingPainter aa_painter { painter }; - Gfx::IntRect highlight_rect { 0, 0, m_radius * 2, m_radius * 2 }; - highlight_rect.center_within(frame_inner_rect()); - aa_painter.fill_ellipse(highlight_rect, m_color); - } + Gfx::AntiAliasingPainter aa_painter { painter }; + Gfx::IntRect highlight_rect { 0, 0, m_radius * 2, m_radius * 2 }; + highlight_rect.center_within(frame_inner_rect()); + aa_painter.fill_ellipse(highlight_rect, m_color); if (m_cursor_bitmap) { auto cursor_rect = m_cursor_bitmap->rect(); if (m_cursor_params.frames() > 1) diff --git a/Userland/Applications/MouseSettings/HighlightWidget.cpp b/Userland/Applications/MouseSettings/HighlightWidget.cpp index 2a3293b372..eaa16f88e1 100644 --- a/Userland/Applications/MouseSettings/HighlightWidget.cpp +++ b/Userland/Applications/MouseSettings/HighlightWidget.cpp @@ -52,10 +52,7 @@ Gfx::Color HighlightWidget::highlight_color() int HighlightWidget::highlight_radius() { - auto current_value = m_highlight_radius_slider->value(); - if (current_value <= m_highlight_radius_slider->min()) - return 0; - return current_value; + return m_highlight_radius_slider->value(); } void HighlightWidget::apply_settings() diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index bff7e7fe1c..e60ac68621 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -1697,40 +1697,47 @@ void WindowManager::process_key_event(KeyEvent& event) if (!active_input_window) return; - if (event.type() == Event::KeyDown && event.modifiers() == Mod_Super && active_input_window->type() != WindowType::Desktop) { - if (event.key() == Key_Down) { - if (active_input_window->is_resizable() && active_input_window->is_maximized()) { - maximize_windows(*active_input_window, false); - return; - } - if (active_input_window->is_minimizable()) - minimize_windows(*active_input_window, true); + if (event.type() == Event::KeyDown && event.modifiers() == Mod_Super) { + if (event.key() == Key_H) { + m_cursor_highlight_enabled = !m_cursor_highlight_enabled; + Compositor::the().invalidate_cursor(); return; } - if (active_input_window->is_resizable()) { - if (event.key() == Key_Up) { - maximize_windows(*active_input_window, !active_input_window->is_maximized()); - return; - } - if (event.key() == Key_Left) { - if (active_input_window->tile_type() == WindowTileType::Left) { - active_input_window->set_untiled(); + if (active_input_window->type() != WindowType::Desktop) { + if (event.key() == Key_Down) { + if (active_input_window->is_resizable() && active_input_window->is_maximized()) { + maximize_windows(*active_input_window, false); return; } - if (active_input_window->is_maximized()) - maximize_windows(*active_input_window, false); - active_input_window->set_tiled(WindowTileType::Left); + if (active_input_window->is_minimizable()) + minimize_windows(*active_input_window, true); return; } - if (event.key() == Key_Right) { - if (active_input_window->tile_type() == WindowTileType::Right) { - active_input_window->set_untiled(); + if (active_input_window->is_resizable()) { + if (event.key() == Key_Up) { + maximize_windows(*active_input_window, !active_input_window->is_maximized()); + return; + } + if (event.key() == Key_Left) { + if (active_input_window->tile_type() == WindowTileType::Left) { + active_input_window->set_untiled(); + return; + } + if (active_input_window->is_maximized()) + maximize_windows(*active_input_window, false); + active_input_window->set_tiled(WindowTileType::Left); + return; + } + if (event.key() == Key_Right) { + if (active_input_window->tile_type() == WindowTileType::Right) { + active_input_window->set_untiled(); + return; + } + if (active_input_window->is_maximized()) + maximize_windows(*active_input_window, false); + active_input_window->set_tiled(WindowTileType::Right); return; } - if (active_input_window->is_maximized()) - maximize_windows(*active_input_window, false); - active_input_window->set_tiled(WindowTileType::Right); - return; } } } @@ -2294,11 +2301,6 @@ void WindowManager::set_cursor_highlight_color(Gfx::Color const& color) sync_config_to_disk(); } -bool WindowManager::is_cursor_highlight_enabled() const -{ - return m_cursor_highlight_radius > 0 && m_cursor_highlight_color.alpha() > 0; -} - bool WindowManager::sync_config_to_disk() { if (auto result = m_config->sync(); result.is_error()) { diff --git a/Userland/Services/WindowServer/WindowManager.h b/Userland/Services/WindowServer/WindowManager.h index 035348f819..f2272ebfb5 100644 --- a/Userland/Services/WindowServer/WindowManager.h +++ b/Userland/Services/WindowServer/WindowManager.h @@ -329,7 +329,7 @@ public: void set_cursor_highlight_radius(int radius); void set_cursor_highlight_color(Gfx::Color const& color); - bool is_cursor_highlight_enabled() const; + bool is_cursor_highlight_enabled() const { return m_cursor_highlight_radius > 0 && m_cursor_highlight_enabled; } private: explicit WindowManager(Gfx::PaletteImpl const&); @@ -386,6 +386,7 @@ private: RefPtr m_zoom_cursor; int m_cursor_highlight_radius { 0 }; Gfx::Color m_cursor_highlight_color; + bool m_cursor_highlight_enabled { false }; RefPtr m_overlay_rect_shadow;