From 21217607006d7b316ae15b022335571234a63cd6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 13 Aug 2022 21:04:11 +0200 Subject: [PATCH] WorkspacePicker: Allow opening workspace settings via a context menu Previously you had to open Display Settings and navigate to the "Workspaces" tab in order to edit workspace settings. This patch adds a context menu shortcut to the same place. --- .../WorkspacePicker/DesktopStatusWindow.cpp | 33 ++++++++++++++++++- Userland/Applets/WorkspacePicker/main.cpp | 7 ++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Userland/Applets/WorkspacePicker/DesktopStatusWindow.cpp b/Userland/Applets/WorkspacePicker/DesktopStatusWindow.cpp index 6a1992f6bc6..a96eea8ab20 100644 --- a/Userland/Applets/WorkspacePicker/DesktopStatusWindow.cpp +++ b/Userland/Applets/WorkspacePicker/DesktopStatusWindow.cpp @@ -7,8 +7,10 @@ */ #include "DesktopStatusWindow.h" +#include #include #include +#include #include #include #include @@ -58,6 +60,9 @@ public: virtual void mousedown_event(GUI::MouseEvent& event) override { + if (event.button() != GUI::MouseButton::Primary) + return; + auto base_rect = rect_for_desktop(0, 0); auto row = event.y() / (base_rect.height() + gap()); auto column = event.x() / (base_rect.width() + gap()); @@ -95,7 +100,31 @@ public: GUI::ConnectionToWindowManagerServer::the().async_set_workspace(row, column); } - unsigned current_row() const { return m_current_row; } + virtual void context_menu_event(GUI::ContextMenuEvent& event) override + { + event.accept(); + + if (!m_context_menu) { + m_context_menu = GUI::Menu::construct(); + + auto settings_icon = MUST(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/settings.png"sv)); + auto open_workspace_settings_action = GUI::Action::create("Workspace &Settings", *settings_icon, [](auto&) { + auto result = Core::Process::spawn("/bin/DisplaySettings"sv, Array { "--open-tab", "workspaces" }.span()); + if (result.is_error()) { + dbgln("Failed to launch DisplaySettings"); + } + }); + m_context_menu->add_action(open_workspace_settings_action); + } + + m_context_menu->popup(event.screen_position()); + } + + unsigned + current_row() const + { + return m_current_row; + } void set_current_row(unsigned row) { m_current_row = row; } unsigned current_column() const { return m_current_column; } void set_current_column(unsigned column) { m_current_column = column; } @@ -109,6 +138,8 @@ private: unsigned m_current_row { 0 }; unsigned m_current_column { 0 }; + + RefPtr m_context_menu; }; DesktopStatusWindow::DesktopStatusWindow() diff --git a/Userland/Applets/WorkspacePicker/main.cpp b/Userland/Applets/WorkspacePicker/main.cpp index c2ba80a94b3..ad658295e36 100644 --- a/Userland/Applets/WorkspacePicker/main.cpp +++ b/Userland/Applets/WorkspacePicker/main.cpp @@ -15,7 +15,7 @@ ErrorOr serenity_main(Main::Arguments arguments) { - TRY(Core::System::pledge("stdio recvfd sendfd rpath unix")); + TRY(Core::System::pledge("stdio recvfd sendfd rpath proc exec unix")); auto app = TRY(GUI::Application::try_create(arguments)); app->set_quit_when_last_window_deleted(false); @@ -23,7 +23,10 @@ ErrorOr serenity_main(Main::Arguments arguments) // We need to obtain the WM connection here as well before the pledge shortening. GUI::ConnectionToWindowManagerServer::the(); - TRY(Core::System::pledge("stdio recvfd sendfd rpath")); + TRY(Core::System::pledge("stdio recvfd sendfd rpath proc exec")); + + TRY(Core::System::unveil("/res", "r")); + TRY(Core::System::unveil("/bin/DisplaySettings", "x")); auto window = TRY(DesktopStatusWindow::try_create()); window->set_title("WorkspacePicker");