mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03: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:
parent
c3eaa73113
commit
2121760700
Notes:
sideshowbarker
2024-07-17 08:18:37 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/2121760700
@ -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()
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user