summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-11 14:56:23 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-11 14:56:23 +0100
commit3351f1ccc1bcc169b680ff2f4e335a1296a47d67 (patch)
treeb898f84b1b435850b4fce7f5950113b35ac29ce3 /Applications
parent9483b392274dfc7c4ede8a376c8926601e8aecd9 (diff)
downloadserenity-3351f1ccc1bcc169b680ff2f4e335a1296a47d67.zip
Port all apps to GApplication.
Diffstat (limited to 'Applications')
-rw-r--r--Applications/Clock/main.cpp8
-rw-r--r--Applications/FileManager/main.cpp8
-rw-r--r--Applications/FontEditor/main.cpp7
-rw-r--r--Applications/Launcher/main.cpp10
-rw-r--r--Applications/Terminal/main.cpp93
5 files changed, 24 insertions, 102 deletions
diff --git a/Applications/Clock/main.cpp b/Applications/Clock/main.cpp
index 98593d1905..49f25a892c 100644
--- a/Applications/Clock/main.cpp
+++ b/Applications/Clock/main.cpp
@@ -1,10 +1,10 @@
-#include <LibGUI/GEventLoop.h>
+#include <LibGUI/GApplication.h>
#include <LibGUI/GWindow.h>
#include "ClockWidget.h"
-int main(int, char**)
+int main(int argc, char** argv)
{
- GEventLoop loop;
+ GApplication app(argc, argv);
auto* window = new GWindow;
window->set_title("Clock");
@@ -16,7 +16,7 @@ int main(int, char**)
window->set_main_widget(clock_widget);
window->show();
- return loop.exec();
+ return app.exec();
}
diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp
index 2bf781fccb..a648712d5d 100644
--- a/Applications/FileManager/main.cpp
+++ b/Applications/FileManager/main.cpp
@@ -1,7 +1,7 @@
#include <LibGUI/GWindow.h>
#include <LibGUI/GWidget.h>
#include <LibGUI/GBoxLayout.h>
-#include <LibGUI/GEventLoop.h>
+#include <LibGUI/GApplication.h>
#include <LibGUI/GStatusBar.h>
#include <unistd.h>
#include <stdio.h>
@@ -9,15 +9,15 @@
static GWindow* make_window();
-int main(int, char**)
+int main(int argc, char** argv)
{
- GEventLoop loop;
+ GApplication app(argc, argv);
auto* window = make_window();
window->set_should_exit_app_on_close(true);
window->show();
- return loop.exec();
+ return app.exec();
}
GWindow* make_window()
diff --git a/Applications/FontEditor/main.cpp b/Applications/FontEditor/main.cpp
index 99d71aa132..d9bb835cca 100644
--- a/Applications/FontEditor/main.cpp
+++ b/Applications/FontEditor/main.cpp
@@ -1,10 +1,12 @@
#include "FontEditor.h"
-#include <LibGUI/GEventLoop.h>
+#include <LibGUI/GApplication.h>
#include <LibGUI/GWindow.h>
#include <stdio.h>
int main(int argc, char** argv)
{
+ GApplication app(argc, argv);
+
RetainPtr<Font> edited_font;
String path;
@@ -22,7 +24,6 @@ int main(int argc, char** argv)
else
edited_font = Font::default_font().clone();
- GEventLoop loop;
auto* window = new GWindow;
window->set_title("FontEditor");
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_should_exit_app_on_close(true);
window->show();
- return loop.exec();
+ return app.exec();
}
diff --git a/Applications/Launcher/main.cpp b/Applications/Launcher/main.cpp
index bde3303055..9236ba28a2 100644
--- a/Applications/Launcher/main.cpp
+++ b/Applications/Launcher/main.cpp
@@ -2,7 +2,7 @@
#include <LibGUI/GWindow.h>
#include <LibGUI/GWidget.h>
#include <LibGUI/GButton.h>
-#include <LibGUI/GEventLoop.h>
+#include <LibGUI/GApplication.h>
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>
@@ -19,17 +19,17 @@ void handle_sigchld(int)
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();
launcher_window->set_should_exit_app_on_close(true);
launcher_window->show();
- return loop.exec();
+ return app.exec();
}
class LauncherButton final : public GButton {
diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp
index 9de32b14c5..215295efae 100644
--- a/Applications/Terminal/main.cpp
+++ b/Applications/Terminal/main.cpp
@@ -10,7 +10,7 @@
#include <LibC/gui.h>
#include "Terminal.h"
#include <Kernel/KeyCode.h>
-#include <LibGUI/GEventLoop.h>
+#include <LibGUI/GApplication.h>
#include <LibGUI/GNotifier.h>
#include <LibGUI/GWidget.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);
if (ptm_fd < 0) {
perror("open(ptmx)");
@@ -63,8 +65,6 @@ int main(int, char**)
make_shell(ptm_fd);
- GEventLoop loop;
-
auto* window = new GWindow;
window->set_should_exit_app_on_close(true);
@@ -80,12 +80,12 @@ int main(int, char**)
if (nread < 0) {
dbgprintf("Terminal read error: %s\n", strerror(errno));
perror("read(ptm)");
- GEventLoop::main().exit(1);
+ GApplication::the().exit(1);
return;
}
if (nread == 0) {
dbgprintf("Terminal: EOF on master pty, closing.\n");
- GEventLoop::main().exit(0);
+ GApplication::the().exit(0);
return;
}
for (ssize_t i = 0; i < nread; ++i)
@@ -95,84 +95,5 @@ int main(int, char**)
window->show();
- return loop.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;
+ return app.exec();
}