summaryrefslogtreecommitdiff
path: root/Userland/guitest.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-14 14:21:51 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-14 14:42:49 +0100
commitb0e3f733759a006622b14f75c5379641ef82776f (patch)
tree010bff69271f7174c1f4728a371785d010a602db /Userland/guitest.cpp
parentb4da4e8fbdccd34792579f82338e09a727177b33 (diff)
downloadserenity-b0e3f733759a006622b14f75c5379641ef82776f.zip
Start refactoring the windowing system to use an event loop.
Userspace programs can now open /dev/gui_events and read a stream of GUI_Event structs one at a time. I was stuck on a stupid problem where we'd reenter Scheduler::yield() due to having one of the has_data_available_for_reading() implementations using locks.
Diffstat (limited to 'Userland/guitest.cpp')
-rw-r--r--Userland/guitest.cpp37
1 files changed, 18 insertions, 19 deletions
diff --git a/Userland/guitest.cpp b/Userland/guitest.cpp
index 597458c635..48af3a9d24 100644
--- a/Userland/guitest.cpp
+++ b/Userland/guitest.cpp
@@ -11,7 +11,7 @@
int main(int argc, char** argv)
{
GUI_CreateWindowParameters wparams;
- wparams.rect = { 200, 200, 300, 200 };
+ wparams.rect = { { 200, 200 }, { 300, 200 } };
wparams.background_color = 0xffc0c0;
strcpy(wparams.title, "GUI test app");
int window_id = syscall(SC_gui_create_window, &wparams);
@@ -20,28 +20,27 @@ int main(int argc, char** argv)
return 1;
}
- GUI_CreateWidgetParameters label_params;
- label_params.type = GUI_WidgetType::Label;
- label_params.rect = { 20, 20, 260, 20 };
- label_params.opaque = false;
- strcpy(label_params.text, "Hello World!");
- int label_id = syscall(SC_gui_create_widget, window_id, &label_params);
- if (label_id < 0) {
- perror("gui_create_widget");
- return 1;
- }
-
- GUI_CreateWidgetParameters button_params;
- button_params.type = GUI_WidgetType::Button;
- button_params.rect = { 60, 60, 120, 20 };
- strcpy(button_params.text, "I'm a button!");
- int button_id = syscall(SC_gui_create_widget, window_id, &button_params);
- if (button_id < 0) {
- perror("gui_create_widget");
+ int fd = open("/dev/gui_events", O_RDONLY);
+ if (fd < 0) {
+ perror("open");
return 1;
}
for (;;) {
+ GUI_Event event;
+ ssize_t nread = read(fd, &event, sizeof(event));
+ if (nread < 0) {
+ perror("read");
+ return 1;
+ }
+ assert(nread == sizeof(event));
+ switch (event.type) {
+ case GUI_Event::Type::Paint: sys_printf("WID=%x Paint [%d,%d %dx%d]\n", event.window_id, event.paint.rect.location.x, event.paint.rect.location.y, event.paint.rect.size.width, event.paint.rect.size.height); break;
+ case GUI_Event::Type::MouseDown: sys_printf("WID=%x MouseDown %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
+ case GUI_Event::Type::MouseUp: sys_printf("WID=%x MouseUp %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
+ case GUI_Event::Type::MouseMove: sys_printf("WID=%x MouseMove %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
+ }
+
}
return 0;
}