aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile17
-rw-r--r--x11.c63
2 files changed, 50 insertions, 30 deletions
diff --git a/Makefile b/Makefile
index 2e62337..da5c16d 100644
--- a/Makefile
+++ b/Makefile
@@ -2,13 +2,16 @@ SRC = $(wildcard *.c)
OBJ = $(SRC:.c=.o)
BIN = comet.bin
-DEPS = cairo \
- xcb \
- xcb-icccm \
- xcb-xrm \
- "xcb-randr >= 1.5" \
- "glib-2.0 >= 2.44" \
- gio-2.0
+DEPS = \
+ cairo \
+ xcb \
+ xcb-icccm \
+ xcb-xrm \
+ xcb-ewmh \
+ xcb-event \
+ "xcb-randr >= 1.5" \
+ "glib-2.0 >= 2.44" \
+ gio-2.0
CFLAGS := $(shell pkg-config --cflags $(DEPS)) -ggdb
LDFLAGS := $(shell pkg-config --libs $(DEPS)) -lm
diff --git a/x11.c b/x11.c
index 7d59038..47c3319 100644
--- a/x11.c
+++ b/x11.c
@@ -9,10 +9,14 @@
#include <xcb/xcb_xrm.h>
#include <xcb/randr.h>
#include <xcb/xcb_atom.h>
+#include <xcb/xcb_event.h>
#include "x11.h"
#include "log.h"
+// TODO: Event logic should be decoupled from Window logic
+#include "draw.h"
+
struct Window {
xcb_screen_t *screen;
xcb_connection_t *connection;
@@ -42,13 +46,6 @@ static xcb_atom_t intern_atom(Window *win, const char *atom)
return xcb_intern_atom_reply(win->connection, cookie, NULL)->atom;
}
-static gboolean xcb_source_prepare(GSource *source, gint *timeout)
-{
- // Always ready to poll
- if (timeout) *timeout = -1;
- return G_SOURCE_REMOVE;
-}
-
static gboolean xcb_source_check(GSource *source)
{
XcbSource *xsource = (XcbSource *)source;
@@ -61,12 +58,29 @@ static gboolean xcb_source_dispatch(GSource *source, GSourceFunc callback, gpoin
{
XcbSource *xsource = (XcbSource *)source;
g_assert_nonnull(xsource->event);
+ g_assert_nonnull(callback);
+ g_assert_nonnull(data);
do {
switch (xsource->event->response_type & ~0x80) {
- case 0:
- log_debug("Error in Xcb event loop");
+ case 0: {
+ xcb_generic_error_t *error = (xcb_generic_error_t *)xsource->event;
+
+ // TODO: This code crashes the program, so we should handle the errors
+ log_warning("Xcb event loop error '%s' [type %d]",
+ xcb_event_get_error_label(error->response_type),
+ error->response_type);
+ break;
+ }
+
+ case XCB_EXPOSE: {
+ xcb_expose_event_t *expose = (xcb_expose_event_t *)xsource->event;
+ log_debug("Processing event 'Expose' [type %d]", XCB_EXPOSE);
+
+ // Redraw
+ callback(data);
break;
+ }
case XCB_BUTTON_PRESS: {
log_debug("Keypress event");
@@ -74,7 +88,9 @@ static gboolean xcb_source_dispatch(GSource *source, GSourceFunc callback, gpoin
}
default: {
- log_debug("Ignoring event '%d'", xsource->event->response_type);
+ log_debug("Ignoring event '%s' [type %d]",
+ xcb_event_get_label(xsource->event->response_type),
+ XCB_EVENT_RESPONSE_TYPE(xsource->event));
}
}
} while ((xsource->event = xcb_poll_for_event(xsource->win->connection)) != NULL);
@@ -88,12 +104,10 @@ static void xcb_source_finalize(GSource *source)
}
static GSourceFuncs source_fns = {
- xcb_source_prepare,
+ NULL,
xcb_source_check,
xcb_source_dispatch,
xcb_source_finalize,
- NULL,
- NULL,
};
static void attach_source(Window *win)
@@ -103,10 +117,13 @@ static void attach_source(Window *win)
source->event = NULL;
win->source = (GSource *)source;
- g_source_set_name(win->source, "XcbSource");
+ g_source_set_static_name(win->source, "XcbSource");
+
+ // TODO: Draw should be decoupled from this file
+ g_source_set_callback(win->source, G_SOURCE_FUNC(draw), win, NULL);
g_source_add_unix_fd(win->source, xcb_get_file_descriptor(win->connection), G_IO_IN | G_IO_HUP | G_IO_ERR);
- g_source_attach(win->source, g_main_context_default());
+ g_source_attach(win->source, NULL);
}
Window *window_create(void)
@@ -214,10 +231,10 @@ found_visual:
};
win->width = win->height = 1;
- log_debug("Window (temporary) size [width=%d, height=%d]", win->width, win->height);
+ log_debug("Window temporary size [width=%d, height=%d]", win->width, win->height);
win->x = win->y = 0;
- log_debug("Window (temporary) position [x=%d, y=%d]", win->x, win->y);
+ log_debug("Window temporary position [x=%d, y=%d]", win->x, win->y);
win->window = xcb_generate_id(win->connection);
xcb_create_window(win->connection,
@@ -236,12 +253,12 @@ found_visual:
xcb_icccm_set_wm_name(win->connection, win->window, XCB_ATOM_STRING, 8, strlen("comet"), "comet");
xcb_map_window(win->connection, win->window);
- xcb_atom_t NET_WM_WINDOW_OPACITY = intern_atom(win, "_NET_WM_WINDOW_OPACITY");
- xcb_atom_t CARDINAL = intern_atom(win, "CARDINAL");
+ //xcb_atom_t NET_WM_WINDOW_OPACITY = intern_atom(win, "_NET_WM_WINDOW_OPACITY");
+ //xcb_atom_t CARDINAL = intern_atom(win, "CARDINAL");
// Value between 0 and 1
- double transparency = 0.8;
- unsigned long opacity = 0xffffffff * transparency;
+ //double transparency = 0.8;
+ //unsigned long opacity = 0xffffffff * transparency;
//error =
//xcb_request_check(win->connection,
@@ -307,7 +324,7 @@ void window_move(Window *win, int x, int y)
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
values);
- log_debug("Window (new) position [x=%d, y=%d]", win->x, win->y);
+ log_debug("Window updated position [x=%d, y=%d]", win->x, win->y);
}
void window_resize(Window *win, int width, int height)
@@ -323,7 +340,7 @@ void window_resize(Window *win, int width, int height)
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
values);
- log_debug("Window (new) size [width=%d, height=%d]", win->width, win->height);
+ log_debug("Window updated size [width=%d, height=%d]", win->width, win->height);
}
void window_paint_surface(Window *win, cairo_surface_t *surface, int width, int height)