From cc707270ae1702bdb48c3fbd791acfcf8de1cee9 Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 30 Jun 2021 20:16:19 -0600 Subject: [PATCH] Taskbar: Only show the current desktop's window buttons By tracking what virtual desktop a window is on, and what desktop is being viewed we can show or hide the window buttons accordingly. --- Userland/Services/Taskbar/TaskbarWindow.cpp | 22 +++++++++++++++++++++ Userland/Services/Taskbar/TaskbarWindow.h | 6 ++++++ Userland/Services/Taskbar/WindowList.h | 10 ++++++++++ Userland/Services/Taskbar/main.cpp | 3 ++- 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Userland/Services/Taskbar/TaskbarWindow.cpp b/Userland/Services/Taskbar/TaskbarWindow.cpp index aaa095b921..a69dd1ec31 100644 --- a/Userland/Services/Taskbar/TaskbarWindow.cpp +++ b/Userland/Services/Taskbar/TaskbarWindow.cpp @@ -221,6 +221,7 @@ void TaskbarWindow::update_window_button(::Window& window, bool show_as_active) button->set_text(window.title()); button->set_tooltip(window.title()); button->set_checked(show_as_active); + button->set_visible(is_window_on_current_virtual_desktop(window)); } ::Window* TaskbarWindow::find_window_owner(::Window& window) const @@ -304,6 +305,7 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event) window.set_active(changed_event.is_active()); window.set_minimized(changed_event.is_minimized()); window.set_progress(changed_event.progress()); + window.set_virtual_desktop(changed_event.virtual_desktop_row(), changed_event.virtual_desktop_column()); auto* window_owner = find_window_owner(window); if (window_owner == &window) { @@ -336,6 +338,10 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event) warnln("failed to spawn 'Assistant' when requested via Super+Space"); break; } + case GUI::Event::WM_VirtualDesktopChanged: { + auto& changed_event = static_cast(event); + virtual_desktop_change_event(changed_event.current_row(), changed_event.current_column()); + } default: break; } @@ -345,3 +351,19 @@ void TaskbarWindow::screen_rects_change_event(GUI::ScreenRectsChangeEvent& event { on_screen_rects_change(event.rects(), event.main_screen_index()); } + +bool TaskbarWindow::is_window_on_current_virtual_desktop(::Window& window) const +{ + return window.virtual_desktop_row() == m_current_virtual_desktop_row && window.virtual_desktop_column() == m_current_virtual_desktop_column; +} + +void TaskbarWindow::virtual_desktop_change_event(unsigned current_row, unsigned current_column) +{ + m_current_virtual_desktop_row = current_row; + m_current_virtual_desktop_column = current_column; + + WindowList::the().for_each_window([&](auto& window) { + if (auto* button = window.button()) + button->set_visible(is_window_on_current_virtual_desktop(window)); + }); +} diff --git a/Userland/Services/Taskbar/TaskbarWindow.h b/Userland/Services/Taskbar/TaskbarWindow.h index 3ba5a36795..b89c604243 100644 --- a/Userland/Services/Taskbar/TaskbarWindow.h +++ b/Userland/Services/Taskbar/TaskbarWindow.h @@ -34,6 +34,9 @@ private: void update_applet_area(); + bool is_window_on_current_virtual_desktop(::Window&) const; + void virtual_desktop_change_event(unsigned, unsigned); + NonnullRefPtr m_start_menu; RefPtr m_task_button_container; RefPtr m_default_icon; @@ -43,4 +46,7 @@ private: RefPtr m_start_button; RefPtr m_assistant_app_file; + + unsigned m_current_virtual_desktop_row { 0 }; + unsigned m_current_virtual_desktop_column { 0 }; }; diff --git a/Userland/Services/Taskbar/WindowList.h b/Userland/Services/Taskbar/WindowList.h index de0c96ed2d..6a0eb427f3 100644 --- a/Userland/Services/Taskbar/WindowList.h +++ b/Userland/Services/Taskbar/WindowList.h @@ -48,6 +48,14 @@ public: void set_modal(bool modal) { m_modal = modal; } bool is_modal() const { return m_modal; } + void set_virtual_desktop(unsigned row, unsigned column) + { + m_virtual_desktop_row = row; + m_virtual_desktop_column = column; + } + unsigned virtual_desktop_row() const { return m_virtual_desktop_row; } + unsigned virtual_desktop_column() const { return m_virtual_desktop_column; } + void set_progress(Optional progress) { if (m_progress == progress) @@ -68,6 +76,8 @@ private: Gfx::IntRect m_rect; RefPtr m_button; RefPtr m_icon; + unsigned m_virtual_desktop_row { 0 }; + unsigned m_virtual_desktop_column { 0 }; bool m_active { false }; bool m_minimized { false }; bool m_modal { false }; diff --git a/Userland/Services/Taskbar/main.cpp b/Userland/Services/Taskbar/main.cpp index da61801013..ad5a5a5a1c 100644 --- a/Userland/Services/Taskbar/main.cpp +++ b/Userland/Services/Taskbar/main.cpp @@ -60,7 +60,8 @@ int main(int argc, char** argv) window->make_window_manager( WindowServer::WMEventMask::WindowStateChanges | WindowServer::WMEventMask::WindowRemovals - | WindowServer::WMEventMask::WindowIconChanges); + | WindowServer::WMEventMask::WindowIconChanges + | WindowServer::WMEventMask::VirtualDesktopChanges); return app->exec(); }