mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:58:13 +00:00
Port all apps to GApplication.
This commit is contained in:
parent
9483b39227
commit
3351f1ccc1
10 changed files with 48 additions and 106 deletions
|
@ -1,10 +1,10 @@
|
||||||
#include <LibGUI/GEventLoop.h>
|
#include <LibGUI/GApplication.h>
|
||||||
#include <LibGUI/GWindow.h>
|
#include <LibGUI/GWindow.h>
|
||||||
#include "ClockWidget.h"
|
#include "ClockWidget.h"
|
||||||
|
|
||||||
int main(int, char**)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
GEventLoop loop;
|
GApplication app(argc, argv);
|
||||||
|
|
||||||
auto* window = new GWindow;
|
auto* window = new GWindow;
|
||||||
window->set_title("Clock");
|
window->set_title("Clock");
|
||||||
|
@ -16,7 +16,7 @@ int main(int, char**)
|
||||||
window->set_main_widget(clock_widget);
|
window->set_main_widget(clock_widget);
|
||||||
|
|
||||||
window->show();
|
window->show();
|
||||||
return loop.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <LibGUI/GWindow.h>
|
#include <LibGUI/GWindow.h>
|
||||||
#include <LibGUI/GWidget.h>
|
#include <LibGUI/GWidget.h>
|
||||||
#include <LibGUI/GBoxLayout.h>
|
#include <LibGUI/GBoxLayout.h>
|
||||||
#include <LibGUI/GEventLoop.h>
|
#include <LibGUI/GApplication.h>
|
||||||
#include <LibGUI/GStatusBar.h>
|
#include <LibGUI/GStatusBar.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -9,15 +9,15 @@
|
||||||
|
|
||||||
static GWindow* make_window();
|
static GWindow* make_window();
|
||||||
|
|
||||||
int main(int, char**)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
GEventLoop loop;
|
GApplication app(argc, argv);
|
||||||
|
|
||||||
auto* window = make_window();
|
auto* window = make_window();
|
||||||
window->set_should_exit_app_on_close(true);
|
window->set_should_exit_app_on_close(true);
|
||||||
window->show();
|
window->show();
|
||||||
|
|
||||||
return loop.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
GWindow* make_window()
|
GWindow* make_window()
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
#include "FontEditor.h"
|
#include "FontEditor.h"
|
||||||
#include <LibGUI/GEventLoop.h>
|
#include <LibGUI/GApplication.h>
|
||||||
#include <LibGUI/GWindow.h>
|
#include <LibGUI/GWindow.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
GApplication app(argc, argv);
|
||||||
|
|
||||||
RetainPtr<Font> edited_font;
|
RetainPtr<Font> edited_font;
|
||||||
String path;
|
String path;
|
||||||
|
|
||||||
|
@ -22,7 +24,6 @@ int main(int argc, char** argv)
|
||||||
else
|
else
|
||||||
edited_font = Font::default_font().clone();
|
edited_font = Font::default_font().clone();
|
||||||
|
|
||||||
GEventLoop loop;
|
|
||||||
auto* window = new GWindow;
|
auto* window = new GWindow;
|
||||||
window->set_title("FontEditor");
|
window->set_title("FontEditor");
|
||||||
window->set_rect({ 50, 50, 420, 200 });
|
window->set_rect({ 50, 50, 420, 200 });
|
||||||
|
@ -31,5 +32,5 @@ int main(int argc, char** argv)
|
||||||
window->set_main_widget(font_editor);
|
window->set_main_widget(font_editor);
|
||||||
window->set_should_exit_app_on_close(true);
|
window->set_should_exit_app_on_close(true);
|
||||||
window->show();
|
window->show();
|
||||||
return loop.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <LibGUI/GWindow.h>
|
#include <LibGUI/GWindow.h>
|
||||||
#include <LibGUI/GWidget.h>
|
#include <LibGUI/GWidget.h>
|
||||||
#include <LibGUI/GButton.h>
|
#include <LibGUI/GButton.h>
|
||||||
#include <LibGUI/GEventLoop.h>
|
#include <LibGUI/GApplication.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -19,17 +19,17 @@ void handle_sigchld(int)
|
||||||
ASSERT(pid > 0);
|
ASSERT(pid > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int, char**)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGCHLD, handle_sigchld);
|
GApplication app(argc, argv);
|
||||||
|
|
||||||
GEventLoop loop;
|
signal(SIGCHLD, handle_sigchld);
|
||||||
|
|
||||||
auto* launcher_window = make_launcher_window();
|
auto* launcher_window = make_launcher_window();
|
||||||
launcher_window->set_should_exit_app_on_close(true);
|
launcher_window->set_should_exit_app_on_close(true);
|
||||||
launcher_window->show();
|
launcher_window->show();
|
||||||
|
|
||||||
return loop.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
class LauncherButton final : public GButton {
|
class LauncherButton final : public GButton {
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include <LibC/gui.h>
|
#include <LibC/gui.h>
|
||||||
#include "Terminal.h"
|
#include "Terminal.h"
|
||||||
#include <Kernel/KeyCode.h>
|
#include <Kernel/KeyCode.h>
|
||||||
#include <LibGUI/GEventLoop.h>
|
#include <LibGUI/GApplication.h>
|
||||||
#include <LibGUI/GNotifier.h>
|
#include <LibGUI/GNotifier.h>
|
||||||
#include <LibGUI/GWidget.h>
|
#include <LibGUI/GWidget.h>
|
||||||
#include <LibGUI/GWindow.h>
|
#include <LibGUI/GWindow.h>
|
||||||
|
@ -53,8 +53,10 @@ static void make_shell(int ptm_fd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int, char**)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
GApplication app(argc, argv);
|
||||||
|
|
||||||
int ptm_fd = open("/dev/ptmx", O_RDWR);
|
int ptm_fd = open("/dev/ptmx", O_RDWR);
|
||||||
if (ptm_fd < 0) {
|
if (ptm_fd < 0) {
|
||||||
perror("open(ptmx)");
|
perror("open(ptmx)");
|
||||||
|
@ -63,8 +65,6 @@ int main(int, char**)
|
||||||
|
|
||||||
make_shell(ptm_fd);
|
make_shell(ptm_fd);
|
||||||
|
|
||||||
GEventLoop loop;
|
|
||||||
|
|
||||||
auto* window = new GWindow;
|
auto* window = new GWindow;
|
||||||
window->set_should_exit_app_on_close(true);
|
window->set_should_exit_app_on_close(true);
|
||||||
|
|
||||||
|
@ -80,12 +80,12 @@ int main(int, char**)
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
dbgprintf("Terminal read error: %s\n", strerror(errno));
|
dbgprintf("Terminal read error: %s\n", strerror(errno));
|
||||||
perror("read(ptm)");
|
perror("read(ptm)");
|
||||||
GEventLoop::main().exit(1);
|
GApplication::the().exit(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (nread == 0) {
|
if (nread == 0) {
|
||||||
dbgprintf("Terminal: EOF on master pty, closing.\n");
|
dbgprintf("Terminal: EOF on master pty, closing.\n");
|
||||||
GEventLoop::main().exit(0);
|
GApplication::the().exit(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (ssize_t i = 0; i < nread; ++i)
|
for (ssize_t i = 0; i < nread; ++i)
|
||||||
|
@ -95,84 +95,5 @@ int main(int, char**)
|
||||||
|
|
||||||
window->show();
|
window->show();
|
||||||
|
|
||||||
return loop.exec();
|
return app.exec();
|
||||||
|
|
||||||
#if 0
|
|
||||||
for (;;) {
|
|
||||||
fd_set rfds;
|
|
||||||
FD_ZERO(&rfds);
|
|
||||||
FD_SET(ptm_fd, &rfds);
|
|
||||||
FD_SET(event_fd, &rfds);
|
|
||||||
int nfds = select(max(ptm_fd, event_fd) + 1, &rfds, nullptr, nullptr, nullptr);
|
|
||||||
if (nfds < 0) {
|
|
||||||
dbgprintf("Terminal(%u) select() failed :( errno=%d\n", getpid(), errno);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FD_ISSET(ptm_fd, &rfds)) {
|
|
||||||
byte buffer[4096];
|
|
||||||
ssize_t nread = read(ptm_fd, buffer, sizeof(buffer));
|
|
||||||
if (nread < 0) {
|
|
||||||
dbgprintf("Terminal read error: %s\n", strerror(errno));
|
|
||||||
perror("read(ptm)");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (nread == 0) {
|
|
||||||
dbgprintf("Terminal: EOF on master pty, closing.\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for (ssize_t i = 0; i < nread; ++i)
|
|
||||||
terminal.on_char(buffer[i]);
|
|
||||||
terminal.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FD_ISSET(event_fd, &rfds)) {
|
|
||||||
GUI_Event event;
|
|
||||||
ssize_t nread = read(event_fd, &event, sizeof(event));
|
|
||||||
if (nread < 0) {
|
|
||||||
perror("read(event)");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(nread != 0);
|
|
||||||
assert(nread == sizeof(event));
|
|
||||||
|
|
||||||
if (event.type == GUI_Event::Type::Paint) {
|
|
||||||
terminal.update();
|
|
||||||
} else if (event.type == GUI_Event::Type::KeyDown) {
|
|
||||||
char ch = event.key.character;
|
|
||||||
if (event.key.ctrl) {
|
|
||||||
if (ch >= 'a' && ch <= 'z') {
|
|
||||||
ch = ch - 'a' + 1;
|
|
||||||
} else if (ch == '\\') {
|
|
||||||
ch = 0x1c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch (event.key.key) {
|
|
||||||
case KeyCode::Key_Up:
|
|
||||||
write(ptm_fd, "\033[A", 3);
|
|
||||||
break;
|
|
||||||
case KeyCode::Key_Down:
|
|
||||||
write(ptm_fd, "\033[B", 3);
|
|
||||||
break;
|
|
||||||
case KeyCode::Key_Right:
|
|
||||||
write(ptm_fd, "\033[C", 3);
|
|
||||||
break;
|
|
||||||
case KeyCode::Key_Left:
|
|
||||||
write(ptm_fd, "\033[D", 3);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
write(ptm_fd, &ch, 1);
|
|
||||||
}
|
|
||||||
} else if (event.type == GUI_Event::Type::WindowActivated) {
|
|
||||||
terminal.set_in_active_window(true);
|
|
||||||
} else if (event.type == GUI_Event::Type::WindowDeactivated) {
|
|
||||||
terminal.set_in_active_window(false);
|
|
||||||
} else if (event.type == GUI_Event::Type::WindowCloseRequest) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,18 @@
|
||||||
#include <LibGUI/GEventLoop.h>
|
#include <LibGUI/GEventLoop.h>
|
||||||
#include <LibGUI/GMenuBar.h>
|
#include <LibGUI/GMenuBar.h>
|
||||||
|
|
||||||
|
static GApplication* s_the;
|
||||||
|
|
||||||
|
GApplication& GApplication::the()
|
||||||
|
{
|
||||||
|
ASSERT(s_the);
|
||||||
|
return *s_the;
|
||||||
|
}
|
||||||
|
|
||||||
GApplication::GApplication(int argc, char** argv)
|
GApplication::GApplication(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
ASSERT(!s_the);
|
||||||
|
s_the = this;
|
||||||
m_event_loop = make<GEventLoop>();
|
m_event_loop = make<GEventLoop>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +26,11 @@ int GApplication::exec()
|
||||||
return m_event_loop->exec();
|
return m_event_loop->exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GApplication::exit(int exit_code)
|
||||||
|
{
|
||||||
|
m_event_loop->exit(exit_code);
|
||||||
|
}
|
||||||
|
|
||||||
void GApplication::set_menubar(OwnPtr<GMenuBar>&& menubar)
|
void GApplication::set_menubar(OwnPtr<GMenuBar>&& menubar)
|
||||||
{
|
{
|
||||||
m_menubar = move(menubar);
|
m_menubar = move(menubar);
|
||||||
|
|
|
@ -7,9 +7,12 @@ class GMenuBar;
|
||||||
|
|
||||||
class GApplication {
|
class GApplication {
|
||||||
public:
|
public:
|
||||||
|
static GApplication& the();
|
||||||
GApplication(int argc, char** argv);
|
GApplication(int argc, char** argv);
|
||||||
|
~GApplication();
|
||||||
|
|
||||||
int exec();
|
int exec();
|
||||||
|
void exit(int);
|
||||||
|
|
||||||
void set_menubar(OwnPtr<GMenuBar>&&);
|
void set_menubar(OwnPtr<GMenuBar>&&);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <LibGUI/GStyle.h>
|
#include <LibGUI/GStyle.h>
|
||||||
#include <SharedGraphics/Painter.h>
|
#include <SharedGraphics/Painter.h>
|
||||||
|
|
||||||
GStyle* s_the;
|
static GStyle* s_the;
|
||||||
|
|
||||||
GStyle& GStyle::the()
|
GStyle& GStyle::the()
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,7 @@ LIBGUI_OBJS = \
|
||||||
GMenuBar.o \
|
GMenuBar.o \
|
||||||
GMenu.o \
|
GMenu.o \
|
||||||
GMenuItem.o \
|
GMenuItem.o \
|
||||||
|
GApplication.o \
|
||||||
GWindow.o
|
GWindow.o
|
||||||
|
|
||||||
OBJS = $(SHAREDGRAPHICS_OBJS) $(LIBGUI_OBJS)
|
OBJS = $(SHAREDGRAPHICS_OBJS) $(LIBGUI_OBJS)
|
||||||
|
|
|
@ -13,9 +13,9 @@
|
||||||
#include <LibGUI/GWidget.h>
|
#include <LibGUI/GWidget.h>
|
||||||
#include <LibGUI/GLabel.h>
|
#include <LibGUI/GLabel.h>
|
||||||
#include <LibGUI/GButton.h>
|
#include <LibGUI/GButton.h>
|
||||||
#include <LibGUI/GEventLoop.h>
|
|
||||||
#include <LibGUI/GTextBox.h>
|
#include <LibGUI/GTextBox.h>
|
||||||
#include <LibGUI/GCheckBox.h>
|
#include <LibGUI/GCheckBox.h>
|
||||||
|
#include <LibGUI/GApplication.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
static GWindow* make_font_test_window();
|
static GWindow* make_font_test_window();
|
||||||
|
@ -31,9 +31,10 @@ void handle_sigchld(int)
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
GApplication app(argc, argv);
|
||||||
|
|
||||||
signal(SIGCHLD, handle_sigchld);
|
signal(SIGCHLD, handle_sigchld);
|
||||||
|
|
||||||
GEventLoop loop;
|
|
||||||
#if 0
|
#if 0
|
||||||
auto* font_test_window = make_font_test_window();
|
auto* font_test_window = make_font_test_window();
|
||||||
font_test_window->show();
|
font_test_window->show();
|
||||||
|
@ -43,7 +44,7 @@ int main(int argc, char** argv)
|
||||||
launcher_window->set_should_exit_app_on_close(true);
|
launcher_window->set_should_exit_app_on_close(true);
|
||||||
launcher_window->show();
|
launcher_window->show();
|
||||||
|
|
||||||
return loop.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
GWindow* make_font_test_window()
|
GWindow* make_font_test_window()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue