openbox/dispatch.c (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
#include "dispatch.h" #include "extensions.h" #include <glib.h> static GSList **funcs; void dispatch_startup() { guint i; EventType j; i = 0; j = EVENT_RANGE; while (j > 1) { j >>= 1; ++i; } funcs = g_new(GSList*, i); for (i = 0, j = 1; j < EVENT_RANGE; ++i, j <<= 1) funcs[i] = NULL; } void dispatch_shutdown() { guint i; EventType j; for (i = 0, j = 1; j < EVENT_RANGE; ++i, j <<= 1) { g_slist_free(funcs[i]); funcs[i] = NULL; } g_free(funcs); } void dispatch_register(EventHandler h, EventMask mask) { guint i; EventType j; while (mask) { for (i = 0, j = 1; j < EVENT_RANGE; ++i, j <<= 1) if (mask & j) { funcs[i] = g_slist_append(funcs[i], h); mask ^= j; /* remove from the mask */ } g_assert(j >= EVENT_RANGE); /* an invalid event is in the mask */ } } void dispatch_x(XEvent *xe, Client *c) { EventType e; guint i; GSList *it; ObEvent obe; switch (xe->type) { case EnterNotify: e = Event_X_EnterNotify; break; case LeaveNotify: e = Event_X_LeaveNotify; break; case KeyPress: e = Event_X_KeyPress; break; case KeyRelease: e = Event_X_KeyRelease; break; case ButtonPress: e = Event_X_ButtonPress; break; case ButtonRelease: e = Event_X_ButtonRelease; break; case MotionNotify: e = Event_X_MotionNotify; break; default: /* XKB events */ if (xe->type == extensions_xkb_event_basep) { switch (((XkbAnyEvent*)&e)->xkb_type) { case XkbBellNotify: e = Event_X_Bell; break; } } return; } obe.type = e; obe.data.x.e = xe; obe.data.x.client = c; i = 0; while (e > 1) { e >>= 1; ++i; } for (it = funcs[i]; it != NULL; it = it->next) ((EventHandler)it->data)(&obe); } void dispatch_client(EventType e, Client *c) { guint i; GSList *it; ObEvent obe; obe.type = e; obe.data.client = c; i = 0; while (e > 1) { e >>= 1; ++i; } for (it = funcs[i]; it != NULL; it = it->next) ((EventHandler)it->data)(&obe); } void dispatch_ob(EventType e) { guint i; GSList *it; ObEvent obe; obe.type = e; i = 0; while (e > 1) { e >>= 1; ++i; } for (it = funcs[i]; it != NULL; it = it->next) ((EventHandler)it->data)(&obe); } void dispatch_signal(int signal) { guint i; EventType e = Event_Signal; GSList *it; ObEvent obe; obe.type = e; obe.data.signal = signal; i = 0; while (e > 1) { e >>= 1; ++i; } for (it = funcs[i]; it != NULL; it = it->next) ((EventHandler)it->data)(&obe); } |