diff --git a/Launcher/Launcher b/Launcher/Launcher index 16f315c9e5..d0a35e2e36 100755 Binary files a/Launcher/Launcher and b/Launcher/Launcher differ diff --git a/Launcher/main.cpp b/Launcher/main.cpp index 60abbb74cc..55f858149b 100644 --- a/Launcher/main.cpp +++ b/Launcher/main.cpp @@ -3,8 +3,11 @@ #include #include #include +#include #include #include +#include +#include static GWindow* make_launcher_window(); @@ -29,51 +32,46 @@ int main(int, char**) return loop.exec(); } +class LauncherButton final : public GButton { +public: + LauncherButton(const String& icon_path, const String& exec_path, GWidget* parent) + : GButton(parent) + , m_executable_path(exec_path) + { + set_icon(GraphicsBitmap::load_from_file(icon_path, { 32, 32 })); + resize(50, 50); + on_click = [this] (GButton&) { + pid_t child_pid = fork(); + if (!child_pid) { + int rc = execl(m_executable_path.characters(), m_executable_path.characters(), nullptr); + if (rc < 0) + perror("execl"); + } + }; + } + virtual ~LauncherButton() { } + +private: + String m_executable_path; +}; + GWindow* make_launcher_window() { auto* window = new GWindow; window->set_title("Launcher"); - window->set_rect({ 50, 50, 300, 60 }); + window->set_rect(50, 50, 300, 60); auto* widget = new GWidget; window->set_main_widget(widget); - widget->set_relative_rect({ 0, 0, 300, 60 }); - auto* terminal_button = new GButton(widget); - terminal_button->set_relative_rect({ 5, 5, 50, 50 }); - terminal_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/Terminal.rgb", { 32, 32 })); + auto* terminal_button = new LauncherButton("/res/icons/Terminal.rgb", "/bin/Terminal", widget); + terminal_button->move_to(5, 5); - terminal_button->on_click = [] (GButton&) { - pid_t child_pid = fork(); - if (!child_pid) { - execve("/bin/Terminal", nullptr, nullptr); - ASSERT_NOT_REACHED(); - } - }; + auto* font_editor_button = new LauncherButton("/res/icons/FontEditor.rgb", "/bin/FontEditor", widget); + font_editor_button->move_to(60, 5); - auto* font_editor_button = new GButton(widget); - font_editor_button->set_relative_rect({ 60, 5, 50, 50 }); - font_editor_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/FontEditor.rgb", { 32, 32 })); - - font_editor_button->on_click = [] (GButton&) { - pid_t child_pid = fork(); - if (!child_pid) { - execve("/bin/FontEditor", nullptr, nullptr); - ASSERT_NOT_REACHED(); - } - }; - - auto* guitest_editor_button = new GButton(widget); - guitest_editor_button->set_relative_rect({ 115, 5, 50, 50 }); - guitest_editor_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/generic.rgb", { 32, 32 })); - - guitest_editor_button->on_click = [] (GButton&) { - pid_t child_pid = fork(); - if (!child_pid) { - execve("/bin/guitest", nullptr, nullptr); - ASSERT_NOT_REACHED(); - } - }; + auto* guitest_editor_button = new LauncherButton("/res/icons/generic.rgb", "/bin/guitest", widget); + guitest_editor_button->move_to(115, 5); return window; } diff --git a/LibGUI/GButton.h b/LibGUI/GButton.h index 6c40d84401..1e6d6dd3ab 100644 --- a/LibGUI/GButton.h +++ b/LibGUI/GButton.h @@ -5,7 +5,7 @@ #include #include -class GButton final : public GWidget { +class GButton : public GWidget { public: explicit GButton(GWidget* parent); virtual ~GButton() override; diff --git a/LibGUI/GWidget.h b/LibGUI/GWidget.h index a12292d284..39785f1f8c 100644 --- a/LibGUI/GWidget.h +++ b/LibGUI/GWidget.h @@ -56,7 +56,11 @@ public: virtual const char* class_name() const override { return "GWidget"; } void set_relative_rect(const Rect&); + void move_to(const Point& point) { set_relative_rect({ point, relative_rect().size() }); } + void move_to(int x, int y) { move_to({ x, y }); } + void resize(const Size& size) { set_relative_rect({ relative_rect().location(), size }); } + void resize(int width, int height) { resize({ width, height }); } Color background_color() const { return m_background_color; } Color foreground_color() const { return m_foreground_color; } diff --git a/LibGUI/GWindow.h b/LibGUI/GWindow.h index 33af06f2bb..8e0ab3bb69 100644 --- a/LibGUI/GWindow.h +++ b/LibGUI/GWindow.h @@ -27,6 +27,7 @@ public: Rect rect() const; void set_rect(const Rect&); + void set_rect(int x, int y, int width, int height) { set_rect({ x, y, width, height }); } Point position() const { return rect().location(); }