aboutsummaryrefslogtreecommitdiff
path: root/src/window
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-19 22:12:52 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-19 22:12:52 +0200
commit9da3c2188060dc982412d7a6e1cd2051b9ddb6a6 (patch)
tree18d7cd9ec63c1f2e42dcda3941907f32e34ac241 /src/window
parent3bdf82eec2c915e91ae487e29d72639f9efcad67 (diff)
Change from callback to window poll
Diffstat (limited to 'src/window')
-rw-r--r--src/window/window.c54
1 files changed, 20 insertions, 34 deletions
diff --git a/src/window/window.c b/src/window/window.c
index c155687..d81f98e 100644
--- a/src/window/window.c
+++ b/src/window/window.c
@@ -37,13 +37,12 @@ static void mgl_window_on_resize(mgl_window *self, int width, int height) {
context->gl.glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
}
-int mgl_window_create(mgl_window *self, const char *title, int width, int height, mgl_window_callback *callback) {
- return mgl_window_create_with_params(self, title, width, height, 0, callback);
+int mgl_window_create(mgl_window *self, const char *title, int width, int height) {
+ return mgl_window_create_with_params(self, title, width, height, 0);
}
-int mgl_window_create_with_params(mgl_window *self, const char *title, int width, int height, unsigned long parent_window, mgl_window_callback *callback) {
+int mgl_window_create_with_params(mgl_window *self, const char *title, int width, int height, mgl_window_handle parent_window) {
self->window = 0;
- self->callback = *callback;
mgl_context *context = mgl_get_context();
@@ -127,40 +126,27 @@ static void mgl_window_on_receive_event(mgl_window *self, XEvent *xev) {
}
}
-void mgl_window_events_poll(mgl_window *self) {
+void mgl_window_clear(mgl_window *self, mgl_color color) {
+ mgl_context *context = mgl_get_context();
+ context->gl.glClear(GL_COLOR_BUFFER_BIT);
+ context->gl.glClearColor((float)color.r / 255.0f, (float)color.g / 255.0f, (float)color.b / 255.0f, (float)color.a / 255.0f);
+}
+
+bool mgl_window_events_poll(mgl_window *self, mgl_event *event) {
+ /* TODO: Use |event| */
+
Display *display = mgl_get_context()->connection;
- const int x11_fd = ConnectionNumber(display);
-
- fd_set in_fds;
- FD_ZERO(&in_fds); /* TODO: Optimize */
- FD_SET(x11_fd, &in_fds);
-
- struct timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = 0;
- /*tv.tv_sec = timeout_ms / 1000;
- tv.tv_usec = (timeout_ms * 1000) - (tv.tv_sec * 1000 * 1000);*/
-
- /* TODO: Is this needed when using XPending? */
- /*const int num_ready_fds = select(1 + x11_fd, &in_fds, NULL, NULL, &tv);*/
- const int num_ready_fds = 1;
- if(num_ready_fds > 0) {
- XEvent xev;
- while(self->window && XPending(display)) {
- XNextEvent(display, &xev);
- mgl_window_on_receive_event(self, &xev);
- }
- } else if(num_ready_fds == -1 && errno != EINTR) {
- /* TODO: */
- fprintf(stderr, "Disconnected!\n");
+ if(XPending(display)) {
+ XEvent xev; /* TODO: Move to window struct */
+ XNextEvent(display, &xev);
+ mgl_window_on_receive_event(self, &xev);
+ return true;
+ } else {
+ return false;
}
}
-void mgl_window_draw(mgl_window *self) {
+void mgl_window_display(mgl_window *self) {
mgl_context *context = mgl_get_context();
- context->gl.glClear(GL_COLOR_BUFFER_BIT);
- context->gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- if(self->callback.draw)
- self->callback.draw(self, self->callback.userdata);
context->gl.glXSwapBuffers(context->connection, self->window);
}