aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlessandro Iezzi <aiezzi@alessandroiezzi.it>2023-05-22 00:24:36 +0200
committerAlessandro Iezzi <aiezzi@alessandroiezzi.it>2023-05-22 00:24:36 +0200
commitb6d3f5a78e3ac4e517608fe51e37d5a7a0e35f61 (patch)
treeca578ea9d179907444e8cabb5b074a92c6e93ec5 /src
parent03911f18bdb58c5aa1cc7c992574d68b61dc1d1c (diff)
downloadcherry-b6d3f5a78e3ac4e517608fe51e37d5a7a0e35f61.tar.gz
cherry-b6d3f5a78e3ac4e517608fe51e37d5a7a0e35f61.zip
Add contexts to retrieve the window when
dispaching events
Diffstat (limited to 'src')
-rw-r--r--src/application.c15
-rw-r--r--src/application.h3
-rw-r--r--src/window.c1
3 files changed, 9 insertions, 10 deletions
diff --git a/src/application.c b/src/application.c
index 3c23898..7e69ca0 100644
--- a/src/application.c
+++ b/src/application.c
@@ -24,6 +24,7 @@ cherry_application_new(const char *name)
app->name = strdup(name);
app->display = NULL;
app->windows = clist_create();
+ app->context = XUniqueContext();
app->listener_activate = NULL;
app->listener_activate_data = NULL;
@@ -40,16 +41,10 @@ static void
dispatch_event(CherryApplication *app,
CherryEvent evt,
XEvent event) {
- iterator_t it = clist_iterator(&app->windows);
- while (clist_iterator_has_next(it)) {
- CherryWindow *w = clist_iterator_next(&it);
- if (w->window_handler == wnd) {
- if (w->listener != NULL) {
- w->listener(w, evt);
- } else {
- return;
- }
- }
+ CherryWindow *w = NULL;
+ XFindContext(event.xany.display, event.xany.window, app->context, (XPointer*) &w);
+ if (w != NULL && w->listener != NULL) {
+ w->listener(w, evt);
}
}
diff --git a/src/application.h b/src/application.h
index 2bc130f..6671272 100644
--- a/src/application.h
+++ b/src/application.h
@@ -4,6 +4,8 @@
#define __CHERRY_APPLICATION_H__
#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xresource.h>
#include <utils.h>
typedef struct CherryApplication {
@@ -14,6 +16,7 @@ typedef struct CherryApplication {
int screen;
int depth;
Visual *visual;
+ XContext context;
void (*listener_activate)(struct CherryApplication *, void *);
void *listener_activate_data;
diff --git a/src/window.c b/src/window.c
index 2d14292..c3f2e2f 100644
--- a/src/window.c
+++ b/src/window.c
@@ -71,6 +71,7 @@ cherry_window_new(void)
XSetForeground(app->display, w->gc, BlackPixel(app->display, app->screen));
clist_add(&(app->windows), w);
+ XSaveContext(app->display, w->window_handler, app->context, (XPointer) w);
return w;
}