diff --git a/Applications/Welcome/main.cpp b/Applications/Welcome/main.cpp index fe0ed62fd1..2c1e06bb6b 100644 --- a/Applications/Welcome/main.cpp +++ b/Applications/Welcome/main.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -156,10 +155,8 @@ int main(int argc, char** argv) auto window = GUI::Window::construct(); window->set_title("Welcome"); - Gfx::IntRect window_rect { 0, 0, 640, 360 }; - window_rect.center_within(GUI::Desktop::the().rect()); - window->set_resizable(true); - window->set_rect(window_rect); + window->resize(640, 360); + window->center_on_screen(); auto& background = window->set_main_widget(); background.set_fill_with_background_color(false); diff --git a/DevTools/Profiler/main.cpp b/DevTools/Profiler/main.cpp index 7480122303..d709ce6af3 100644 --- a/DevTools/Profiler/main.cpp +++ b/DevTools/Profiler/main.cpp @@ -137,9 +137,8 @@ static bool prompt_to_stop_profiling() auto window = GUI::Window::construct(); window->set_title("Profiling"); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-profiler.png")); - Gfx::IntRect window_rect { 0, 0, 320, 200 }; - window_rect.center_within(GUI::Desktop::the().rect()); - window->set_rect(window_rect); + window->resize(320, 200); + window->center_on_screen(); auto& widget = window->set_main_widget(); widget.set_fill_with_background_color(true); widget.set_layout(); diff --git a/Libraries/LibGUI/ProcessChooser.cpp b/Libraries/LibGUI/ProcessChooser.cpp index 413b3b9888..ad47f4b293 100644 --- a/Libraries/LibGUI/ProcessChooser.cpp +++ b/Libraries/LibGUI/ProcessChooser.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -48,9 +47,8 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView& else if (parent_window) set_icon(parent_window->icon()); - Gfx::IntRect window_rect { 0, 0, 300, 340 }; - window_rect.center_within(GUI::Desktop::the().rect()); - set_rect(window_rect); + resize(300, 340); + center_on_screen(); auto& widget = set_main_widget(); widget.set_fill_with_background_color(true); diff --git a/Libraries/LibGUI/Window.cpp b/Libraries/LibGUI/Window.cpp index a58b04d898..de1206b918 100644 --- a/Libraries/LibGUI/Window.cpp +++ b/Libraries/LibGUI/Window.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -212,6 +213,13 @@ void Window::set_rect(const Gfx::IntRect& a_rect) m_main_widget->resize(window_rect.size()); } +void Window::center_on_screen() +{ + auto window_rect = rect(); + window_rect.center_within(Desktop::the().rect()); + set_rect(window_rect); +} + void Window::set_window_type(WindowType window_type) { m_window_type = window_type; diff --git a/Libraries/LibGUI/Window.h b/Libraries/LibGUI/Window.h index 3284a15644..4d8f96e4ce 100644 --- a/Libraries/LibGUI/Window.h +++ b/Libraries/LibGUI/Window.h @@ -123,6 +123,8 @@ public: void resize(int width, int height) { resize({ width, height }); } void resize(const Gfx::IntSize& size) { set_rect({ position(), size }); } + void center_on_screen(); + virtual void event(Core::Event&) override; bool is_visible() const; diff --git a/Services/SystemMenu/ShutdownDialog.cpp b/Services/SystemMenu/ShutdownDialog.cpp index eb85879251..32db729f45 100644 --- a/Services/SystemMenu/ShutdownDialog.cpp +++ b/Services/SystemMenu/ShutdownDialog.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -62,9 +61,8 @@ Vector ShutdownDialog::show() ShutdownDialog::ShutdownDialog() : Dialog(nullptr) { - Gfx::IntRect rect({ 0, 0, 180, 180 + ((static_cast(options.size()) - 3) * 16) }); - rect.center_within(GUI::Desktop::the().rect()); - set_rect(rect); + resize(180, 180 + ((static_cast(options.size()) - 3) * 16)); + center_on_screen(); set_resizable(false); set_title("SerenityOS"); set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/power.png"));