1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:37:43 +00:00

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.
This commit is contained in:
Andreas Kling 2022-08-13 21:04:11 +02:00
parent c3eaa73113
commit 2121760700
2 changed files with 37 additions and 3 deletions

View file

@ -7,8 +7,10 @@
*/ */
#include "DesktopStatusWindow.h" #include "DesktopStatusWindow.h"
#include <LibCore/Process.h>
#include <LibGUI/ConnectionToWindowManagerServer.h> #include <LibGUI/ConnectionToWindowManagerServer.h>
#include <LibGUI/Desktop.h> #include <LibGUI/Desktop.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
#include <LibGUI/Widget.h> #include <LibGUI/Widget.h>
#include <LibGfx/Palette.h> #include <LibGfx/Palette.h>
@ -58,6 +60,9 @@ public:
virtual void mousedown_event(GUI::MouseEvent& event) override virtual void mousedown_event(GUI::MouseEvent& event) override
{ {
if (event.button() != GUI::MouseButton::Primary)
return;
auto base_rect = rect_for_desktop(0, 0); auto base_rect = rect_for_desktop(0, 0);
auto row = event.y() / (base_rect.height() + gap()); auto row = event.y() / (base_rect.height() + gap());
auto column = event.x() / (base_rect.width() + gap()); auto column = event.x() / (base_rect.width() + gap());
@ -95,7 +100,31 @@ public:
GUI::ConnectionToWindowManagerServer::the().async_set_workspace(row, column); 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; } void set_current_row(unsigned row) { m_current_row = row; }
unsigned current_column() const { return m_current_column; } unsigned current_column() const { return m_current_column; }
void set_current_column(unsigned column) { m_current_column = column; } void set_current_column(unsigned column) { m_current_column = column; }
@ -109,6 +138,8 @@ private:
unsigned m_current_row { 0 }; unsigned m_current_row { 0 };
unsigned m_current_column { 0 }; unsigned m_current_column { 0 };
RefPtr<GUI::Menu> m_context_menu;
}; };
DesktopStatusWindow::DesktopStatusWindow() DesktopStatusWindow::DesktopStatusWindow()

View file

@ -15,7 +15,7 @@
ErrorOr<int> serenity_main(Main::Arguments arguments) 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)); auto app = TRY(GUI::Application::try_create(arguments));
app->set_quit_when_last_window_deleted(false); 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. // We need to obtain the WM connection here as well before the pledge shortening.
GUI::ConnectionToWindowManagerServer::the(); 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()); auto window = TRY(DesktopStatusWindow::try_create());
window->set_title("WorkspacePicker"); window->set_title("WorkspacePicker");