From 1dd15950439f4027f6412bb3748f7f433e60924b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 4 Jul 2020 14:05:19 +0200 Subject: [PATCH] LibGUI: Make GUI::Application a Core::Object Having this on the stack makes whole-program teardown iffy. Turning it into a Core::Object allows anyone who needs it to extends its lifetime. --- Applications/About/main.cpp | 4 ++-- Applications/Browser/main.cpp | 6 +++--- Applications/Calculator/main.cpp | 6 +++--- Applications/Calendar/main.cpp | 6 +++--- Applications/DisplaySettings/main.cpp | 8 ++++---- Applications/FileManager/main.cpp | 4 ++-- Applications/FontEditor/main.cpp | 6 +++--- Applications/Help/main.cpp | 6 +++--- Applications/HexEditor/main.cpp | 4 ++-- Applications/IRCClient/main.cpp | 8 ++++---- Applications/KeyboardMapper/main.cpp | 8 ++++---- Applications/KeyboardSettings/main.cpp | 12 ++++++------ Applications/Piano/main.cpp | 6 +++--- Applications/PixelPaint/main.cpp | 6 +++--- Applications/QuickShow/main.cpp | 8 ++++---- Applications/SoundPlayer/main.cpp | 8 ++++---- Applications/SystemMonitor/main.cpp | 6 +++--- Applications/Terminal/main.cpp | 8 ++++---- Applications/TextEditor/main.cpp | 4 ++-- Applications/Welcome/main.cpp | 4 ++-- Demos/Cube/Cube.cpp | 4 ++-- Demos/Eyes/main.cpp | 4 ++-- Demos/Fire/Fire.cpp | 4 ++-- Demos/HelloWorld/main.cpp | 6 +++--- Demos/LibGfxDemo/main.cpp | 4 ++-- Demos/Mouse/main.cpp | 8 ++++---- Demos/Screensaver/Screensaver.cpp | 4 ++-- Demos/WebView/main.cpp | 4 ++-- Demos/WidgetGallery/main.cpp | 4 ++-- DevTools/HackStudio/main.cpp | 8 ++++---- DevTools/Inspector/main.cpp | 4 ++-- DevTools/Profiler/main.cpp | 8 ++++---- DevTools/VisualBuilder/main.cpp | 6 +++--- Games/Minesweeper/main.cpp | 6 +++--- Games/Snake/main.cpp | 6 +++--- Games/Solitaire/main.cpp | 8 ++++---- Libraries/LibGUI/Application.cpp | 2 -- Libraries/LibGUI/Application.h | 10 +++++++--- MenuApplets/Audio/main.cpp | 4 ++-- MenuApplets/ClipboardHistory/main.cpp | 4 ++-- MenuApplets/Clock/main.cpp | 4 ++-- MenuApplets/ResourceGraph/main.cpp | 4 ++-- MenuApplets/UserName/main.cpp | 4 ++-- Services/NotificationServer/main.cpp | 4 ++-- Services/SystemMenu/main.cpp | 6 +++--- Services/Taskbar/main.cpp | 4 ++-- Userland/copy.cpp | 2 +- Userland/html.cpp | 8 ++++---- Userland/notify.cpp | 2 +- Userland/pape.cpp | 2 +- Userland/paste.cpp | 2 +- 51 files changed, 140 insertions(+), 138 deletions(-) diff --git a/Applications/About/main.cpp b/Applications/About/main.cpp index c3fa95a3b5f..24418d03216 100644 --- a/Applications/About/main.cpp +++ b/Applications/About/main.cpp @@ -37,7 +37,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio shared_buffer accept rpath", nullptr) < 0) { perror("pledge"); @@ -52,5 +52,5 @@ int main(int argc, char** argv) unveil(nullptr, nullptr); GUI::AboutDialog::show("SerenityOS", nullptr, nullptr, Gfx::Bitmap::load_from_file("/res/icons/16x16/ladybug.png")); - return app.exec(); + return app->exec(); } diff --git a/Applications/Browser/main.cpp b/Applications/Browser/main.cpp index cfe6f3e2026..20f9e2a74d1 100644 --- a/Applications/Browser/main.cpp +++ b/Applications/Browser/main.cpp @@ -68,7 +68,7 @@ int main(int argc, char** argv) args_parser.add_positional_argument(specified_url, "URL to open", "url", Core::ArgsParser::Required::No); args_parser.parse(argc, argv); - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); // Connect to the ProtocolServer immediately so we can drop the "unix" pledge. Web::ResourceLoader::the(); @@ -175,7 +175,7 @@ int main(int argc, char** argv) tab_widget.remove_tab(tab); tab_widget.set_bar_visible(!window->is_fullscreen() && tab_widget.children().size() > 1); if (tab_widget.children().is_empty()) - app.quit(); + app->quit(); }); }; @@ -220,5 +220,5 @@ int main(int argc, char** argv) create_new_tab(first_url, true); window->show(); - return app.exec(); + return app->exec(); } diff --git a/Applications/Calculator/main.cpp b/Applications/Calculator/main.cpp index 7ff679d1fb6..f3fbabbb104 100644 --- a/Applications/Calculator/main.cpp +++ b/Applications/Calculator/main.cpp @@ -41,7 +41,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio shared_buffer rpath accept", nullptr) < 0) { perror("pledge"); @@ -78,7 +78,7 @@ int main(int argc, char** argv) GUI::AboutDialog::show("Calculator", Gfx::Bitmap::load_from_file("/res/icons/16x16/app-calculator.png"), window); })); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); - return app.exec(); + return app->exec(); } diff --git a/Applications/Calendar/main.cpp b/Applications/Calendar/main.cpp index 1bbfc137802..f794584968f 100644 --- a/Applications/Calendar/main.cpp +++ b/Applications/Calendar/main.cpp @@ -42,7 +42,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio shared_buffer rpath accept", nullptr) < 0) { perror("pledge"); @@ -78,7 +78,7 @@ int main(int argc, char** argv) return; })); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); - app.exec(); + app->exec(); } diff --git a/Applications/DisplaySettings/main.cpp b/Applications/DisplaySettings/main.cpp index 9561d8e501f..b321c1ce6a1 100644 --- a/Applications/DisplaySettings/main.cpp +++ b/Applications/DisplaySettings/main.cpp @@ -43,7 +43,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio thread shared_buffer rpath accept cpath wpath", nullptr) < 0) { perror("pledge"); @@ -64,7 +64,7 @@ int main(int argc, char** argv) auto& app_menu = menubar->add_menu("Display settings"); app_menu.add_action(GUI::CommonActions::make_quit_action([&](const GUI::Action&) { - app.quit(); + app->quit(); })); auto& help_menu = menubar->add_menu("Help"); @@ -72,7 +72,7 @@ int main(int argc, char** argv) GUI::AboutDialog::show("Display settings", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-display-settings.png"), window); })); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); window->show(); - return app.exec(); + return app->exec(); } diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index 946386ee948..727d31403b0 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -85,14 +85,14 @@ int main(int argc, char** argv) RefPtr config = Core::ConfigFile::get_for_app("FileManager"); - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio thread shared_buffer accept cpath rpath wpath fattr proc exec unix", nullptr) < 0) { perror("pledge"); return 1; } - if (app.args().contains_slow("--desktop") || app.args().contains_slow("-d")) + if (app->args().contains_slow("--desktop") || app->args().contains_slow("-d")) return run_in_desktop_mode(move(config), Core::StandardPaths::desktop_directory()); // our initial location is defined as, in order of precedence: diff --git a/Applications/FontEditor/main.cpp b/Applications/FontEditor/main.cpp index 9f54b2c42d2..c5333e28c18 100644 --- a/Applications/FontEditor/main.cpp +++ b/Applications/FontEditor/main.cpp @@ -45,7 +45,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio shared_buffer rpath accept cpath wpath", nullptr) < 0) { perror("pledge"); @@ -96,9 +96,9 @@ int main(int argc, char** argv) GUI::AboutDialog::show("Font Editor", app_icon.bitmap_for_size(32), window); })); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); window->show(); - return app.exec(); + return app->exec(); } diff --git a/Applications/Help/main.cpp b/Applications/Help/main.cpp index 64ec6417c89..87824d09476 100644 --- a/Applications/Help/main.cpp +++ b/Applications/Help/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio shared_buffer accept rpath", nullptr) < 0) { perror("pledge"); @@ -201,12 +201,12 @@ int main(int argc, char* argv[]) go_menu.add_action(*go_back_action); go_menu.add_action(*go_forward_action); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); window->set_focused_widget(&tree_view); window->show(); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/book.png")); - return app.exec(); + return app->exec(); } diff --git a/Applications/HexEditor/main.cpp b/Applications/HexEditor/main.cpp index 7ef6b76ea00..bedea6c2092 100644 --- a/Applications/HexEditor/main.cpp +++ b/Applications/HexEditor/main.cpp @@ -35,7 +35,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio shared_buffer accept rpath cpath wpath thread", nullptr) < 0) { perror("pledge"); @@ -60,5 +60,5 @@ int main(int argc, char** argv) if (argc >= 2) hex_editor_widget.open_file(argv[1]); - return app.exec(); + return app->exec(); } diff --git a/Applications/IRCClient/main.cpp b/Applications/IRCClient/main.cpp index 10cb9d7e39b..2344d2736ad 100644 --- a/Applications/IRCClient/main.cpp +++ b/Applications/IRCClient/main.cpp @@ -42,7 +42,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio inet dns unix shared_buffer rpath wpath cpath", nullptr) < 0) { perror("pledge"); @@ -50,8 +50,8 @@ int main(int argc, char** argv) } URL url = ""; - if (app.args().size() >= 1) { - url = URL::create_with_url_or_path(app.args()[0]); + if (app->args().size() >= 1) { + url = URL::create_with_url_or_path(app->args()[0]); if (url.protocol().to_lowercase() == "ircs") { fprintf(stderr, "Secure IRC over SSL/TLS (ircs) is not supported\n"); @@ -74,5 +74,5 @@ int main(int argc, char** argv) auto app_window = IRCAppWindow::construct(url.host(), url.port()); app_window->show(); - return app.exec(); + return app->exec(); } diff --git a/Applications/KeyboardMapper/main.cpp b/Applications/KeyboardMapper/main.cpp index d88b9084308..77a9070d3dd 100644 --- a/Applications/KeyboardMapper/main.cpp +++ b/Applications/KeyboardMapper/main.cpp @@ -41,7 +41,7 @@ int main(int argc, char** argv) args_parser.add_positional_argument(path, "Keyboard character mapping file.", "file", Core::ArgsParser::Required::No); args_parser.parse(argc, argv); - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto app_icon = GUI::Icon::default_icon("app-keyboard-mapper"); @@ -87,7 +87,7 @@ int main(int argc, char** argv) auto quit_action = GUI::CommonActions::make_quit_action( [&](auto&) { - app.quit(); + app->quit(); }); auto about_action = GUI::Action::create("About", @@ -108,7 +108,7 @@ int main(int argc, char** argv) auto& help_menu = menubar->add_menu("Help"); help_menu.add_action(about_action); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); - return app.exec(); + return app->exec(); } diff --git a/Applications/KeyboardSettings/main.cpp b/Applications/KeyboardSettings/main.cpp index 0cb4aaad5a0..dae47939cf7 100644 --- a/Applications/KeyboardSettings/main.cpp +++ b/Applications/KeyboardSettings/main.cpp @@ -50,7 +50,7 @@ int main(int argc, char** argv) } // If there is no command line parameter go for GUI. - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio rpath accept shared_buffer proc exec", nullptr) < 0) { perror("pledge"); @@ -131,7 +131,7 @@ int main(int argc, char** argv) exit(1); } if (quit) - app.quit(); + app->quit(); }; auto& bottom_widget = root_widget.add(); @@ -161,12 +161,12 @@ int main(int argc, char** argv) cancel_button.set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed); cancel_button.set_preferred_size(60, 22); cancel_button.on_click = [&](auto) { - app.quit(); + app->quit(); }; auto quit_action = GUI::CommonActions::make_quit_action( [&](auto&) { - app.quit(); + app->quit(); }); auto about_action = GUI::Action::create("About", @@ -182,9 +182,9 @@ int main(int argc, char** argv) auto& help_menu = menubar->add_menu("Help"); help_menu.add_action(about_action); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); window->show(); - return app.exec(); + return app->exec(); } diff --git a/Applications/Piano/main.cpp b/Applications/Piano/main.cpp index b48afdcc50e..a089508bd29 100644 --- a/Applications/Piano/main.cpp +++ b/Applications/Piano/main.cpp @@ -44,7 +44,7 @@ int main(int argc, char** argv) { - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto audio_client = Audio::ClientConnection::construct(); audio_client->handshake(); @@ -120,7 +120,7 @@ int main(int argc, char** argv) auto& edit_menu = menubar->add_menu("Edit"); main_widget.add_actions(edit_menu); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); - return app.exec(); + return app->exec(); } diff --git a/Applications/PixelPaint/main.cpp b/Applications/PixelPaint/main.cpp index 2e3b2fec10b..67602c20977 100644 --- a/Applications/PixelPaint/main.cpp +++ b/Applications/PixelPaint/main.cpp @@ -53,7 +53,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio thread shared_buffer accept rpath wpath cpath", nullptr) < 0) { perror("pledge"); @@ -196,7 +196,7 @@ int main(int argc, char** argv) GUI::AboutDialog::show("PixelPaint", app_icon.bitmap_for_size(32), window); })); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); image_editor.on_active_layer_change = [&](auto* layer) { layer_list_widget.set_selected_layer(layer); @@ -227,5 +227,5 @@ int main(int argc, char** argv) image_editor.set_image(image); image_editor.set_active_layer(bg_layer); - return app.exec(); + return app->exec(); } diff --git a/Applications/QuickShow/main.cpp b/Applications/QuickShow/main.cpp index 1287ed09db6..cbcc46c0cc1 100644 --- a/Applications/QuickShow/main.cpp +++ b/Applications/QuickShow/main.cpp @@ -55,7 +55,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio shared_buffer accept cpath rpath wpath proc exec thread", nullptr) < 0) { perror("pledge"); @@ -166,7 +166,7 @@ int main(int argc, char** argv) auto quit_action = GUI::CommonActions::make_quit_action( [&](auto&) { - app.quit(); + app->quit(); }); auto rotate_left_action = GUI::Action::create("Rotate Left", { Mod_None, Key_L }, @@ -290,7 +290,7 @@ int main(int argc, char** argv) auto& help_menu = menubar->add_menu("Help"); help_menu.add_action(about_action); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); if (path != nullptr) { widget.load_from_file(path); @@ -298,5 +298,5 @@ int main(int argc, char** argv) window->show(); - return app.exec(); + return app->exec(); } diff --git a/Applications/SoundPlayer/main.cpp b/Applications/SoundPlayer/main.cpp index e5477d02961..938b259ab5b 100644 --- a/Applications/SoundPlayer/main.cpp +++ b/Applications/SoundPlayer/main.cpp @@ -43,7 +43,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio shared_buffer accept rpath unix", nullptr) < 0) { perror("pledge"); @@ -87,7 +87,7 @@ int main(int argc, char** argv) app_menu.add_action(move(hide_scope)); app_menu.add_separator(); app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { - app.quit(); + app->quit(); })); auto& help_menu = menubar->add_menu("Help"); @@ -95,8 +95,8 @@ int main(int argc, char** argv) GUI::AboutDialog::show("SoundPlayer", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-sound-player.png"), window); })); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); window->show(); - return app.exec(); + return app->exec(); } diff --git a/Applications/SystemMonitor/main.cpp b/Applications/SystemMonitor/main.cpp index ae585e4bc93..7d280db561b 100644 --- a/Applications/SystemMonitor/main.cpp +++ b/Applications/SystemMonitor/main.cpp @@ -117,7 +117,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio proc shared_buffer accept rpath exec", nullptr) < 0) { perror("pledge"); @@ -269,7 +269,7 @@ int main(int argc, char** argv) GUI::AboutDialog::show("System Monitor", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-system-monitor.png"), window); })); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); auto& process_tab_unused_widget = process_container_splitter.add("No process selected"); process_tab_unused_widget.set_visible(true); @@ -302,7 +302,7 @@ int main(int argc, char** argv) window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-system-monitor.png")); - return app.exec(); + return app->exec(); } class ProgressBarPaintingDelegate final : public GUI::TableCellPaintingDelegate { diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp index c7450d2e6a9..eb0dc1f3f0a 100644 --- a/Applications/Terminal/main.cpp +++ b/Applications/Terminal/main.cpp @@ -209,7 +209,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio tty rpath accept cpath wpath shared_buffer proc exec unix", nullptr) < 0) { perror("pledge"); @@ -251,7 +251,7 @@ int main(int argc, char** argv) auto& terminal = window->set_main_widget(ptm_fd, true, config); terminal.on_command_exit = [&] { - app.quit(0); + app->quit(0); }; terminal.on_title_change = [&](auto& title) { window->set_title(title); @@ -321,7 +321,7 @@ int main(int argc, char** argv) GUI::AboutDialog::show("Terminal", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-terminal.png"), window); })); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); if (unveil("/res", "r") < 0) { perror("unveil"); @@ -346,5 +346,5 @@ int main(int argc, char** argv) unveil(nullptr, nullptr); config->sync(); - return app.exec(); + return app->exec(); } diff --git a/Applications/TextEditor/main.cpp b/Applications/TextEditor/main.cpp index 3b3bf8d59ba..5589692de0b 100644 --- a/Applications/TextEditor/main.cpp +++ b/Applications/TextEditor/main.cpp @@ -35,7 +35,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio thread rpath accept cpath wpath shared_buffer unix", nullptr) < 0) { perror("pledge"); @@ -62,5 +62,5 @@ int main(int argc, char** argv) window->show(); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/TextEditor16.png")); - return app.exec(); + return app->exec(); } diff --git a/Applications/Welcome/main.cpp b/Applications/Welcome/main.cpp index 49dd34f02e3..937bc46d7ab 100644 --- a/Applications/Welcome/main.cpp +++ b/Applications/Welcome/main.cpp @@ -133,7 +133,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio shared_buffer rpath", nullptr) < 0) { perror("pledge"); @@ -257,5 +257,5 @@ int main(int argc, char** argv) } window->show(); - return app.exec(); + return app->exec(); } diff --git a/Demos/Cube/Cube.cpp b/Demos/Cube/Cube.cpp index 36faa2deafe..8731f6c9481 100644 --- a/Demos/Cube/Cube.cpp +++ b/Demos/Cube/Cube.cpp @@ -190,7 +190,7 @@ void Cube::timer_event(Core::TimerEvent&) int main(int argc, char** argv) { - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto window = GUI::Window::construct(); window->set_double_buffering_enabled(true); @@ -209,5 +209,5 @@ int main(int argc, char** argv) window->show(); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-cube.png")); - return app.exec(); + return app->exec(); } diff --git a/Demos/Eyes/main.cpp b/Demos/Eyes/main.cpp index 32aecc2269e..9058ec56578 100644 --- a/Demos/Eyes/main.cpp +++ b/Demos/Eyes/main.cpp @@ -42,7 +42,7 @@ int main(int argc, char* argv[]) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio shared_buffer accept rpath cpath wpath thread", nullptr) < 0) { perror("pledge"); @@ -58,5 +58,5 @@ int main(int argc, char* argv[]) window->show(); eyes.track_cursor_globally(); - return app.exec(); + return app->exec(); } diff --git a/Demos/Fire/Fire.cpp b/Demos/Fire/Fire.cpp index 29e09e66a7d..35249e5adf2 100644 --- a/Demos/Fire/Fire.cpp +++ b/Demos/Fire/Fire.cpp @@ -222,7 +222,7 @@ void Fire::mouseup_event(GUI::MouseEvent& event) */ int main(int argc, char** argv) { - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto window = GUI::Window::construct(); window->set_double_buffering_enabled(false); @@ -241,5 +241,5 @@ int main(int argc, char** argv) window->show(); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-fire.png")); - return app.exec(); + return app->exec(); } diff --git a/Demos/HelloWorld/main.cpp b/Demos/HelloWorld/main.cpp index 79e69349260..aea01a2d415 100644 --- a/Demos/HelloWorld/main.cpp +++ b/Demos/HelloWorld/main.cpp @@ -33,7 +33,7 @@ int main(int argc, char** argv) { - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto window = GUI::Window::construct(); window->set_rect(100, 100, 240, 160); @@ -53,10 +53,10 @@ int main(int argc, char** argv) button.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); button.set_preferred_size(0, 20); button.on_click = [&](auto) { - app.quit(); + app->quit(); }; window->show(); - return app.exec(); + return app->exec(); } diff --git a/Demos/LibGfxDemo/main.cpp b/Demos/LibGfxDemo/main.cpp index f8383427a15..65e9bb3ddc2 100644 --- a/Demos/LibGfxDemo/main.cpp +++ b/Demos/LibGfxDemo/main.cpp @@ -196,7 +196,7 @@ void Canvas::draw() int main(int argc, char** argv) { - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto window = GUI::Window::construct(); window->set_double_buffering_enabled(true); @@ -206,5 +206,5 @@ int main(int argc, char** argv) window->set_main_widget(); window->show(); - return app.exec(); + return app->exec(); } diff --git a/Demos/Mouse/main.cpp b/Demos/Mouse/main.cpp index 8b4ceb79565..1ed94f6132c 100644 --- a/Demos/Mouse/main.cpp +++ b/Demos/Mouse/main.cpp @@ -171,7 +171,7 @@ private: int main(int argc, char** argv) { - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto window = GUI::Window::construct(); window->set_title("Mouse button demo"); window->resize(160, 155); @@ -181,15 +181,15 @@ int main(int argc, char** argv) auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("Mouse Demo"); - app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); })); + app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); auto& help_menu = menubar->add_menu("Help"); help_menu.add_action(GUI::Action::create("About", [&](auto&) { GUI::AboutDialog::show("Mouse Demo", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-mouse.png"), window); })); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); window->set_resizable(false); window->show(); - return app.exec(); + return app->exec(); } diff --git a/Demos/Screensaver/Screensaver.cpp b/Demos/Screensaver/Screensaver.cpp index e477772b551..ac80bf9e70a 100644 --- a/Demos/Screensaver/Screensaver.cpp +++ b/Demos/Screensaver/Screensaver.cpp @@ -134,7 +134,7 @@ void Screensaver::draw() int main(int argc, char** argv) { - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto window = GUI::Window::construct(); window->set_double_buffering_enabled(true); @@ -148,5 +148,5 @@ int main(int argc, char** argv) window->show(); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-screensaver.png")); - return app.exec(); + return app->exec(); } diff --git a/Demos/WebView/main.cpp b/Demos/WebView/main.cpp index 9afac30fcce..6037a912602 100644 --- a/Demos/WebView/main.cpp +++ b/Demos/WebView/main.cpp @@ -32,7 +32,7 @@ int main(int argc, char** argv) { - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto window = GUI::Window::construct(); auto& view = window->set_main_widget(); window->set_title("WebContentView"); @@ -41,5 +41,5 @@ int main(int argc, char** argv) view.load("file:///res/html/misc/welcome.html"); - return app.exec(); + return app->exec(); } diff --git a/Demos/WidgetGallery/main.cpp b/Demos/WidgetGallery/main.cpp index 17b20a9580e..c79b18b9487 100644 --- a/Demos/WidgetGallery/main.cpp +++ b/Demos/WidgetGallery/main.cpp @@ -46,7 +46,7 @@ int main(int argc, char** argv) { - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto window = GUI::Window::construct(); window->set_rect(100, 100, 433, 487); @@ -245,5 +245,5 @@ int main(int argc, char** argv) window->show(); - return app.exec(); + return app->exec(); } diff --git a/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp index e6357639f7f..b4b99938c6a 100644 --- a/DevTools/HackStudio/main.cpp +++ b/DevTools/HackStudio/main.cpp @@ -160,7 +160,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio tty accept rpath cpath wpath shared_buffer proc exec fattr thread", nullptr) < 0) { perror("pledge"); @@ -525,7 +525,7 @@ int main(int argc, char** argv) app_menu.add_action(save_action); app_menu.add_separator(); app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { - app.quit(); + app->quit(); })); auto& project_menu = menubar->add_menu("Project"); @@ -664,7 +664,7 @@ int main(int argc, char** argv) GUI::AboutDialog::show("HackStudio", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-hack-studio.png"), g_window); })); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); g_window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-hack-studio.png")); @@ -691,7 +691,7 @@ int main(int argc, char** argv) open_file(g_project->default_file()); update_actions(); - return app.exec(); + return app->exec(); } void build(TerminalWrapper& wrapper) diff --git a/DevTools/Inspector/main.cpp b/DevTools/Inspector/main.cpp index ddded558db4..2aa92429e1a 100644 --- a/DevTools/Inspector/main.cpp +++ b/DevTools/Inspector/main.cpp @@ -71,7 +71,7 @@ int main(int argc, char** argv) pid_t pid = pid_opt.value(); - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto window = GUI::Window::construct(); window->set_title("Inspector"); @@ -114,5 +114,5 @@ int main(int argc, char** argv) return 1; } - return app.exec(); + return app->exec(); } diff --git a/DevTools/Profiler/main.cpp b/DevTools/Profiler/main.cpp index 0383bb944fb..20fbe4fb5cd 100644 --- a/DevTools/Profiler/main.cpp +++ b/DevTools/Profiler/main.cpp @@ -58,7 +58,7 @@ int main(int argc, char** argv) args_parser.add_option(pid, "PID to profile", "pid", 'p', "PID"); args_parser.parse(argc, argv, false); - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); const char* path = nullptr; if (argc != 2) { @@ -101,7 +101,7 @@ int main(int argc, char** argv) auto menubar = GUI::MenuBar::construct(); auto& app_menu = menubar->add_menu("Profiler"); - app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); })); + app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); auto& view_menu = menubar->add_menu("View"); auto invert_action = GUI::Action::create_checkable("Invert tree", { Mod_Ctrl, Key_I }, [&](auto& action) { @@ -118,10 +118,10 @@ int main(int argc, char** argv) percent_action->set_checked(false); view_menu.add_action(percent_action); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); window->show(); - return app.exec(); + return app->exec(); } bool prompt_to_stop_profiling() diff --git a/DevTools/VisualBuilder/main.cpp b/DevTools/VisualBuilder/main.cpp index 3f66df42ee0..460217610d2 100644 --- a/DevTools/VisualBuilder/main.cpp +++ b/DevTools/VisualBuilder/main.cpp @@ -47,7 +47,7 @@ static RefPtr make_toolbox_window(); int main(int argc, char** argv) { - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto propbox = VBPropertiesWindow::construct(); @@ -83,7 +83,7 @@ int main(int argc, char** argv) GUI::AboutDialog::show("Visual Builder", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-visual-builder.png"), window); })); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); auto toolbox = make_toolbox_window(); toolbox->show(); @@ -94,7 +94,7 @@ int main(int argc, char** argv) form1->load_from_file(argv[1]); } - return app.exec(); + return app->exec(); } RefPtr make_toolbox_window() diff --git a/Games/Minesweeper/main.cpp b/Games/Minesweeper/main.cpp index a57715d07e1..4f7ce5468f0 100644 --- a/Games/Minesweeper/main.cpp +++ b/Games/Minesweeper/main.cpp @@ -45,7 +45,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio rpath accept wpath cpath shared_buffer", nullptr) < 0) { perror("pledge"); @@ -127,11 +127,11 @@ int main(int argc, char** argv) GUI::AboutDialog::show("Minesweeper", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-minesweeper.png"), window); })); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); window->show(); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/minesweeper/mine.png")); - return app.exec(); + return app->exec(); } diff --git a/Games/Snake/main.cpp b/Games/Snake/main.cpp index 8db863c9905..ad24a3449e3 100644 --- a/Games/Snake/main.cpp +++ b/Games/Snake/main.cpp @@ -42,7 +42,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio rpath wpath cpath shared_buffer accept", nullptr) < 0) { perror("pledge"); @@ -73,11 +73,11 @@ int main(int argc, char** argv) GUI::AboutDialog::show("Snake", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-snake.png"), window); })); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); window->show(); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-snake.png")); - return app.exec(); + return app->exec(); } diff --git a/Games/Solitaire/main.cpp b/Games/Solitaire/main.cpp index 25c98272a51..99a316ef94f 100644 --- a/Games/Solitaire/main.cpp +++ b/Games/Solitaire/main.cpp @@ -35,7 +35,7 @@ int main(int argc, char** argv) { - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio rpath shared_buffer", nullptr) < 0) { perror("pledge"); @@ -56,18 +56,18 @@ int main(int argc, char** argv) app_menu.add_action(GUI::Action::create("Restart game", [&](auto&) { widget->setup(); })); app_menu.add_separator(); - app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); })); + app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); auto& help_menu = menubar->add_menu("Help"); help_menu.add_action(GUI::Action::create("About", [&](auto&) { GUI::AboutDialog::show("Solitaire", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-solitaire.png"), window); })); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); window->set_main_widget(widget); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-solitaire.png")); window->show(); widget->setup(); - return app.exec(); + return app->exec(); } diff --git a/Libraries/LibGUI/Application.cpp b/Libraries/LibGUI/Application.cpp index 8f4631adb4c..127f8471ee7 100644 --- a/Libraries/LibGUI/Application.cpp +++ b/Libraries/LibGUI/Application.cpp @@ -49,8 +49,6 @@ Application& Application::the() Application::Application(int argc, char** argv) { - (void)argc; - (void)argv; ASSERT(!s_the); s_the = this; m_event_loop = make(); diff --git a/Libraries/LibGUI/Application.h b/Libraries/LibGUI/Application.h index b5e84a21295..e669ea4a792 100644 --- a/Libraries/LibGUI/Application.h +++ b/Libraries/LibGUI/Application.h @@ -29,17 +29,19 @@ #include #include #include -#include +#include #include #include #include namespace GUI { -class Application { +class Application : public Core::Object { + C_OBJECT(Application); + public: static Application& the(); - Application(int argc, char** argv); + ~Application(); int exec(); @@ -71,6 +73,8 @@ public: bool focus_debugging_enabled() const { return m_focus_debugging_enabled; } private: + Application(int argc, char** argv); + OwnPtr m_event_loop; RefPtr m_menubar; RefPtr m_palette; diff --git a/MenuApplets/Audio/main.cpp b/MenuApplets/Audio/main.cpp index c90a4adc6eb..df6f859e41f 100644 --- a/MenuApplets/Audio/main.cpp +++ b/MenuApplets/Audio/main.cpp @@ -81,7 +81,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio shared_buffer accept rpath unix", nullptr) < 0) { perror("pledge"); @@ -109,5 +109,5 @@ int main(int argc, char** argv) return 1; } - return app.exec(); + return app->exec(); } diff --git a/MenuApplets/ClipboardHistory/main.cpp b/MenuApplets/ClipboardHistory/main.cpp index fcd1fb5fabc..63173171bd2 100644 --- a/MenuApplets/ClipboardHistory/main.cpp +++ b/MenuApplets/ClipboardHistory/main.cpp @@ -38,7 +38,7 @@ int main(int argc, char* argv[]) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio shared_buffer accept rpath", nullptr) < 0) { perror("pledge"); @@ -85,5 +85,5 @@ int main(int argc, char* argv[]) applet_window->resize(16, 16); applet_window->show(); - return app.exec(); + return app->exec(); } diff --git a/MenuApplets/Clock/main.cpp b/MenuApplets/Clock/main.cpp index 26a8afaa923..e187ef65834 100644 --- a/MenuApplets/Clock/main.cpp +++ b/MenuApplets/Clock/main.cpp @@ -110,7 +110,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio shared_buffer accept rpath exec proc", nullptr) < 0) { perror("pledge"); @@ -137,5 +137,5 @@ int main(int argc, char** argv) unveil(nullptr, nullptr); - return app.exec(); + return app->exec(); } diff --git a/MenuApplets/ResourceGraph/main.cpp b/MenuApplets/ResourceGraph/main.cpp index 775c50a9402..426fef924cd 100644 --- a/MenuApplets/ResourceGraph/main.cpp +++ b/MenuApplets/ResourceGraph/main.cpp @@ -159,7 +159,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio shared_buffer accept proc exec rpath", nullptr) < 0) { perror("pledge"); @@ -235,5 +235,5 @@ int main(int argc, char** argv) unveil(nullptr, nullptr); - return app.exec(); + return app->exec(); } diff --git a/MenuApplets/UserName/main.cpp b/MenuApplets/UserName/main.cpp index 9eb84aefb48..345cc6c6ed8 100644 --- a/MenuApplets/UserName/main.cpp +++ b/MenuApplets/UserName/main.cpp @@ -86,7 +86,7 @@ int main(int argc, char** argv) unveil(nullptr, nullptr); - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto window = GUI::Window::construct(); window->set_title("UserName"); @@ -101,5 +101,5 @@ int main(int argc, char** argv) return 1; } - return app.exec(); + return app->exec(); } diff --git a/Services/NotificationServer/main.cpp b/Services/NotificationServer/main.cpp index f26aeec5674..1eb2152886e 100644 --- a/Services/NotificationServer/main.cpp +++ b/Services/NotificationServer/main.cpp @@ -39,7 +39,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto server = Core::LocalServer::construct(); bool ok = server->take_over_from_system_server(); @@ -67,5 +67,5 @@ int main(int argc, char** argv) return 1; } - return app.exec(); + return app->exec(); } diff --git a/Services/SystemMenu/main.cpp b/Services/SystemMenu/main.cpp index 5de516eeab2..02112635eed 100644 --- a/Services/SystemMenu/main.cpp +++ b/Services/SystemMenu/main.cpp @@ -65,8 +65,8 @@ static NonnullRefPtr build_system_menu(); int main(int argc, char** argv) { - GUI::Application app(argc, argv); - app.set_quit_when_last_window_deleted(false); + auto app = GUI::Application::construct(argc, argv); + app->set_quit_when_last_window_deleted(false); auto menu = build_system_menu(); menu->realize_menu_if_needed(); @@ -95,7 +95,7 @@ int main(int argc, char** argv) unveil(nullptr, nullptr); - return app.exec(); + return app->exec(); } NonnullRefPtr build_system_menu() diff --git a/Services/Taskbar/main.cpp b/Services/Taskbar/main.cpp index 5287515c1c0..3e4f639e054 100644 --- a/Services/Taskbar/main.cpp +++ b/Services/Taskbar/main.cpp @@ -37,7 +37,7 @@ int main(int argc, char** argv) return 1; } - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); signal(SIGCHLD, [](int signo) { (void)signo; @@ -52,5 +52,5 @@ int main(int argc, char** argv) TaskbarWindow window; window.show(); - return app.exec(); + return app->exec(); } diff --git a/Userland/copy.cpp b/Userland/copy.cpp index 1a086df5df4..f0d94dc50d9 100644 --- a/Userland/copy.cpp +++ b/Userland/copy.cpp @@ -75,7 +75,7 @@ Options parse_options(int argc, char* argv[]) int main(int argc, char* argv[]) { - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); Options options = parse_options(argc, argv); diff --git a/Userland/html.cpp b/Userland/html.cpp index 0bc91ff5a4a..3f1418fbf81 100644 --- a/Userland/html.cpp +++ b/Userland/html.cpp @@ -37,7 +37,7 @@ int main(int argc, char** argv) { - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto f = Core::File::construct(); bool success; @@ -67,7 +67,7 @@ int main(int argc, char** argv) auto& app_menu = menubar->add_menu("HTML"); app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { - app.quit(); + app->quit(); })); auto& help_menu = menubar->add_menu("Help"); @@ -75,9 +75,9 @@ int main(int argc, char** argv) GUI::AboutDialog::show("HTML", Gfx::Bitmap::load_from_file("/res/icons/32x32/filetype-html.png"), window); })); - app.set_menubar(move(menubar)); + app->set_menubar(move(menubar)); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png")); - return app.exec(); + return app->exec(); } diff --git a/Userland/notify.cpp b/Userland/notify.cpp index 37431e00ee5..cb596e98e59 100644 --- a/Userland/notify.cpp +++ b/Userland/notify.cpp @@ -32,7 +32,7 @@ int main(int argc, char** argv) { - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); Core::ArgsParser args_parser; const char* title = nullptr; diff --git a/Userland/pape.cpp b/Userland/pape.cpp index 80e6c36d7a7..9c79dd7d5ce 100644 --- a/Userland/pape.cpp +++ b/Userland/pape.cpp @@ -85,7 +85,7 @@ int main(int argc, char** argv) args_parser.add_positional_argument(name, "Wallpaper to set", "name", Core::ArgsParser::Required::No); args_parser.parse(argc, argv); - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (show_all) return handle_show_all(); diff --git a/Userland/paste.cpp b/Userland/paste.cpp index 64334633874..2a15dc00cde 100644 --- a/Userland/paste.cpp +++ b/Userland/paste.cpp @@ -41,7 +41,7 @@ int main(int argc, char* argv[]) args_parser.add_option(no_newline, "Do not append a newline", "no-newline", 'n'); args_parser.parse(argc, argv); - GUI::Application app(argc, argv); + auto app = GUI::Application::construct(argc, argv); auto& clipboard = GUI::Clipboard::the(); auto data_and_type = clipboard.data_and_type();