mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 10:58:11 +00:00

This patch adds a simple GMessageBox that can run in a nested event loop. Here's how you use it: GMessageBox box("Message text here", "Message window title"); int result = box.exec(); The next step is to make the WindowServer respect the modality flag of these windows and prevent interaction with other windows in the same process until the modal window has been closed.
78 lines
2.3 KiB
C++
78 lines
2.3 KiB
C++
#include <SharedGraphics/GraphicsBitmap.h>
|
|
#include <LibGUI/GWindow.h>
|
|
#include <LibGUI/GWidget.h>
|
|
#include <LibGUI/GButton.h>
|
|
#include <LibGUI/GApplication.h>
|
|
#include <LibGUI/GBoxLayout.h>
|
|
#include <sys/wait.h>
|
|
#include <signal.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
|
|
static GWindow* make_launcher_window();
|
|
|
|
void handle_sigchld(int)
|
|
{
|
|
dbgprintf("Launcher(%d) Got SIGCHLD\n", getpid());
|
|
int pid = waitpid(-1, nullptr, 0);
|
|
dbgprintf("Launcher(%d) waitpid() returned %d\n", getpid(), pid);
|
|
ASSERT(pid > 0);
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
GApplication app(argc, argv);
|
|
|
|
signal(SIGCHLD, handle_sigchld);
|
|
|
|
auto* launcher_window = make_launcher_window();
|
|
launcher_window->set_should_exit_event_loop_on_close(true);
|
|
launcher_window->show();
|
|
|
|
return app.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_button_style(GButtonStyle::CoolBar);
|
|
set_icon(GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, icon_path, { 32, 32 }));
|
|
set_preferred_size({ 50, 50 });
|
|
set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
|
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);
|
|
|
|
auto* widget = new GWidget;
|
|
widget->set_fill_with_background_color(true);
|
|
widget->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
|
widget->layout()->set_margins({ 5, 5, 5, 5 });
|
|
window->set_main_widget(widget);
|
|
|
|
new LauncherButton("/res/icons/Terminal.rgb", "/bin/Terminal", widget);
|
|
new LauncherButton("/res/icons/FontEditor.rgb", "/bin/FontEditor", widget);
|
|
new LauncherButton("/res/icons/folder32.rgb", "/bin/FileManager", widget);
|
|
new LauncherButton("/res/icons/TextEditor.rgb", "/bin/TextEditor", widget);
|
|
|
|
return window;
|
|
}
|