/* * Copyright (c) 2018-2021, Andreas Kling * Copyright (c) 2021, Mustafa Quraish * * SPDX-License-Identifier: BSD-2-Clause */ #include "MainWidget.h" #include #include #include #include #include #include #include #include #include #include #include #include ErrorOr serenity_main(Main::Arguments arguments) { TRY(Core::System::pledge("stdio thread recvfd sendfd rpath unix wpath cpath")); auto app = TRY(GUI::Application::try_create(arguments)); Config::pledge_domain("PixelPaint"); char const* image_file = nullptr; Core::ArgsParser args_parser; args_parser.add_positional_argument(image_file, "Image file to open", "path", Core::ArgsParser::Required::No); args_parser.parse(arguments); TRY(Core::System::unveil("/sys/kernel/processes", "r")); TRY(Core::System::unveil("/res", "r")); TRY(Core::System::unveil("/tmp/session/%sid/portal/clipboard", "rw")); TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw")); TRY(Core::System::unveil("/tmp/session/%sid/portal/image", "rw")); TRY(Core::System::unveil("/etc/FileIconProvider.ini", "r")); TRY(Core::System::unveil(nullptr, nullptr)); auto app_icon = GUI::Icon::default_icon("app-pixel-paint"sv); PixelPaint::g_icon_bag = TRY(PixelPaint::IconBag::try_create()); auto window = GUI::Window::construct(); window->set_title("Pixel Paint"); window->resize(800, 510); window->set_icon(app_icon.bitmap_for_size(16)); auto main_widget = TRY(window->try_set_main_widget()); main_widget->initialize_menubar(*window); window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision { if (main_widget->request_close()) return GUI::Window::CloseRequestDecision::Close; return GUI::Window::CloseRequestDecision::StayOpen; }; auto& statusbar = *main_widget->find_descendant_of_type_named("statusbar"); app->on_action_enter = [&statusbar](GUI::Action& action) { auto text = action.status_tip(); if (text.is_empty()) text = Gfx::parse_ampersand_string(action.text()); statusbar.set_override_text(move(text)); }; app->on_action_leave = [&statusbar](GUI::Action&) { statusbar.set_override_text({}); }; window->show(); if (image_file) { auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window, image_file); if (response.is_error()) return 1; main_widget->open_image(response.value()); } else { main_widget->create_default_image(); } return app->exec(); }