Serenity Operating System
at master 63 lines 1.8 kB view raw
1/* 2 * Copyright (c) 2021, Peter Elliott <pelliott@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include "DesktopStatusWindow.h" 8#include <LibCore/System.h> 9#include <LibGUI/Application.h> 10#include <LibGUI/ConnectionToWindowManagerServer.h> 11#include <LibGUI/Desktop.h> 12#include <LibGUI/Painter.h> 13#include <LibMain/Main.h> 14#include <WindowServer/Window.h> 15 16ErrorOr<int> serenity_main(Main::Arguments arguments) 17{ 18 TRY(Core::System::pledge("stdio recvfd sendfd rpath proc exec unix")); 19 20 auto app = TRY(GUI::Application::try_create(arguments)); 21 app->set_quit_when_last_window_deleted(false); 22 23 // We need to obtain the WM connection here as well before the pledge shortening. 24 GUI::ConnectionToWindowManagerServer::the(); 25 26 TRY(Core::System::pledge("stdio recvfd sendfd rpath proc exec")); 27 28 TRY(Core::System::unveil("/res", "r")); 29 TRY(Core::System::unveil("/bin/DisplaySettings", "x")); 30 TRY(Core::System::unveil(nullptr, nullptr)); 31 32 auto window = TRY(DesktopStatusWindow::try_create()); 33 window->set_title("WorkspacePicker"); 34 window->resize(28, 15); 35 36 auto& desktop = GUI::Desktop::the(); 37 38 auto hide_tray_icon = [&] { 39 window->hide(); 40 }; 41 42 auto show_tray_icon = [&] { 43 if (!window->is_visible()) { 44 window->show(); 45 window->make_window_manager(WindowServer::WMEventMask::WorkspaceChanges); 46 } 47 }; 48 49 if (desktop.workspace_rows() != 1 || desktop.workspace_columns() != 1) { 50 show_tray_icon(); 51 } 52 53 desktop.on_receive_screen_rects([&](auto&) { 54 if (desktop.workspace_rows() == 1 && desktop.workspace_columns() == 1) { 55 hide_tray_icon(); 56 } else { 57 window->update(); 58 show_tray_icon(); 59 } 60 }); 61 62 return app->exec(); 63}