diff options
author | Andreas Kling <kling@serenityos.org> | 2022-08-13 21:04:11 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-14 02:28:25 +0200 |
commit | 21217607006d7b316ae15b022335571234a63cd6 (patch) | |
tree | ec61794b4576115d9ec1e6fc750b4d4cf8125b18 /Userland/Applets | |
parent | c3eaa73113b423df3acc2578023fc1b3b8f8c53c (diff) | |
download | serenity-21217607006d7b316ae15b022335571234a63cd6.zip |
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.
Diffstat (limited to 'Userland/Applets')
-rw-r--r-- | Userland/Applets/WorkspacePicker/DesktopStatusWindow.cpp | 33 | ||||
-rw-r--r-- | 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 6a1992f6bc..a96eea8ab2 100644 --- a/Userland/Applets/WorkspacePicker/DesktopStatusWindow.cpp +++ b/Userland/Applets/WorkspacePicker/DesktopStatusWindow.cpp @@ -7,8 +7,10 @@ */ #include "DesktopStatusWindow.h" +#include <LibCore/Process.h> #include <LibGUI/ConnectionToWindowManagerServer.h> #include <LibGUI/Desktop.h> +#include <LibGUI/Menu.h> #include <LibGUI/Painter.h> #include <LibGUI/Widget.h> #include <LibGfx/Palette.h> @@ -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<GUI::Menu> m_context_menu; }; DesktopStatusWindow::DesktopStatusWindow() diff --git a/Userland/Applets/WorkspacePicker/main.cpp b/Userland/Applets/WorkspacePicker/main.cpp index c2ba80a94b..ad658295e3 100644 --- a/Userland/Applets/WorkspacePicker/main.cpp +++ b/Userland/Applets/WorkspacePicker/main.cpp @@ -15,7 +15,7 @@ ErrorOr<int> 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<int> 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"); |