summaryrefslogtreecommitdiff
path: root/event
diff options
context:
space:
mode:
authorJosh Triplett <josh@freedesktop.org>2006-02-18 16:49:41 -0800
committerJosh Triplett <josh@josh-mobile.localdomain>2006-02-18 16:49:41 -0800
commite5d3e856ee2d17c3202a86cd084e2fbd1abc2f1d (patch)
treec004b3a0fb74d0fda154348bc1afc56f7b6e0760 /event
Remove xcl and CVSROOT.
Diffstat (limited to 'event')
-rw-r--r--event/.cvsignore8
-rw-r--r--event/Makefile.am16
-rw-r--r--event/events.c88
-rw-r--r--event/xcb-event.pc.in11
-rw-r--r--event/xcb_event.h59
5 files changed, 182 insertions, 0 deletions
diff --git a/event/.cvsignore b/event/.cvsignore
new file mode 100644
index 0000000..65e939d
--- /dev/null
+++ b/event/.cvsignore
@@ -0,0 +1,8 @@
+.deps
+.libs
+Makefile
+Makefile.in
+*.lo
+*.loT
+*.la
+*.pc
diff --git a/event/Makefile.am b/event/Makefile.am
new file mode 100644
index 0000000..2b83c56
--- /dev/null
+++ b/event/Makefile.am
@@ -0,0 +1,16 @@
+
+MAINTAINERCLEANFILES = Makefile.in
+
+lib_LTLIBRARIES = libXCBEvent.la
+
+xcbinclude_HEADERS = xcb_event.h
+
+AM_CFLAGS = -Wall
+INCLUDES = $(XCB_CFLAGS)
+LDADD = $(XCB_LIBS)
+
+libXCBEvent_la_SOURCES = events.c
+
+pkgconfig_DATA = xcb-event.pc
+
+EXTRA_DIST = xcb-event.pc.in
diff --git a/event/events.c b/event/events.c
new file mode 100644
index 0000000..6649eee
--- /dev/null
+++ b/event/events.c
@@ -0,0 +1,88 @@
+#include <assert.h>
+#include <stdlib.h>
+
+#include "xcb_event.h"
+
+typedef struct {
+ GenericEventHandler handler;
+ void *data;
+} EventHandler;
+
+struct EventHandlers {
+ EventHandler event[126];
+ EventHandler error[256];
+ XCBConnection *c;
+};
+
+EventHandlers *allocEventHandlers(XCBConnection *c)
+{
+ EventHandlers *ret = calloc(1, sizeof(EventHandlers));
+ if(ret)
+ ret->c = c;
+ return ret;
+}
+
+void freeEventHandlers(EventHandlers *evenths)
+{
+ free(evenths);
+}
+
+XCBConnection *getXCBConnection(EventHandlers *evenths)
+{
+ return evenths->c;
+}
+
+static EventHandler *getEventHandler(EventHandlers *evenths, int event)
+{
+ assert(event < 256);
+ event &= 0x7f;
+ assert(event >= 2);
+ return &evenths->event[event - 2];
+}
+
+static EventHandler *getErrorHandler(EventHandlers *evenths, int error)
+{
+ assert(error >= 0 && error < 256);
+ return &evenths->error[error];
+}
+
+static int handleEvent(EventHandlers *evenths, XCBGenericEvent *event)
+{
+ EventHandler *eventh = 0;
+ assert(event->response_type != 1);
+
+ if(event->response_type == 0)
+ eventh = getErrorHandler(evenths, ((XCBGenericError *) event)->error_code);
+ else
+ eventh = getEventHandler(evenths, event->response_type);
+
+ if(eventh->handler)
+ return eventh->handler(eventh->data, evenths->c, event);
+ return 0;
+}
+
+void eventLoop(EventHandlers *evenths)
+{
+ XCBGenericEvent *event;
+ while((event = XCBWaitForEvent(evenths->c)))
+ {
+ handleEvent(evenths, event);
+ free(event);
+ }
+}
+
+static void setHandler(GenericEventHandler handler, void *data, EventHandler *place)
+{
+ EventHandler eventh = { handler, data };
+ *place = eventh;
+}
+
+void setEventHandler(EventHandlers *evenths, int event, GenericEventHandler handler, void *data)
+{
+ setHandler(handler, data, getEventHandler(evenths, event));
+}
+
+void setErrorHandler(EventHandlers *evenths, int error, GenericErrorHandler handler, void *data)
+{
+ setHandler((GenericEventHandler) handler, data, getErrorHandler(evenths, error));
+}
diff --git a/event/xcb-event.pc.in b/event/xcb-event.pc.in
new file mode 100644
index 0000000..863fc6e
--- /dev/null
+++ b/event/xcb-event.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: XCBEvent
+Description: XCB event callback interface
+Version: @PACKAGE_VERSION@
+Requires: xcb
+Libs: -L${libdir} -lXCBEvent @LIBS@
+Cflags: -I${includedir}
diff --git a/event/xcb_event.h b/event/xcb_event.h
new file mode 100644
index 0000000..5d94e4b
--- /dev/null
+++ b/event/xcb_event.h
@@ -0,0 +1,59 @@
+#ifndef EVENTS_H
+#define EVENTS_H
+
+#include <X11/XCB/xcb.h>
+
+typedef struct EventHandlers EventHandlers;
+EventHandlers *allocEventHandlers(XCBConnection *c);
+void freeEventHandlers(EventHandlers *evenths);
+XCBConnection *getXCBConnection(EventHandlers *evenths);
+
+void eventLoop(EventHandlers *evenths);
+
+typedef int (*GenericEventHandler)(void *data, XCBConnection *c, XCBGenericEvent *event);
+typedef int (*GenericErrorHandler)(void *data, XCBConnection *c, XCBGenericError *error);
+
+void setEventHandler(EventHandlers *evenths, int event, GenericEventHandler handler, void *data);
+void setErrorHandler(EventHandlers *evenths, int error, GenericErrorHandler handler, void *data);
+
+#define MAKE_HANDLER(cls,kind) \
+static inline void set##kind##cls##Handler(EventHandlers *evenths, int (*handler)(void *, XCBConnection *, XCB##kind##cls *), void *data) \
+{ \
+ set##cls##Handler(evenths, XCB##kind, (GenericEventHandler) handler, data); \
+}
+
+MAKE_HANDLER(Event, KeyPress)
+MAKE_HANDLER(Event, KeyRelease)
+MAKE_HANDLER(Event, ButtonPress)
+MAKE_HANDLER(Event, ButtonRelease)
+MAKE_HANDLER(Event, MotionNotify)
+MAKE_HANDLER(Event, EnterNotify)
+MAKE_HANDLER(Event, LeaveNotify)
+MAKE_HANDLER(Event, FocusIn)
+MAKE_HANDLER(Event, FocusOut)
+MAKE_HANDLER(Event, KeymapNotify)
+MAKE_HANDLER(Event, Expose)
+MAKE_HANDLER(Event, GraphicsExposure)
+MAKE_HANDLER(Event, NoExposure)
+MAKE_HANDLER(Event, VisibilityNotify)
+MAKE_HANDLER(Event, CreateNotify)
+MAKE_HANDLER(Event, DestroyNotify)
+MAKE_HANDLER(Event, UnmapNotify)
+MAKE_HANDLER(Event, MapNotify)
+MAKE_HANDLER(Event, MapRequest)
+MAKE_HANDLER(Event, ReparentNotify)
+MAKE_HANDLER(Event, ConfigureNotify)
+MAKE_HANDLER(Event, ConfigureRequest)
+MAKE_HANDLER(Event, GravityNotify)
+MAKE_HANDLER(Event, ResizeRequest)
+MAKE_HANDLER(Event, CirculateNotify)
+MAKE_HANDLER(Event, CirculateRequest)
+MAKE_HANDLER(Event, PropertyNotify)
+MAKE_HANDLER(Event, SelectionClear)
+MAKE_HANDLER(Event, SelectionRequest)
+MAKE_HANDLER(Event, SelectionNotify)
+MAKE_HANDLER(Event, ColormapNotify)
+MAKE_HANDLER(Event, ClientMessage)
+MAKE_HANDLER(Event, MappingNotify)
+
+#endif /* EVENTS_H */