From 3c5f6db04cb577fa3f547b45283eac7a0664be39 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 29 Aug 2003 06:52:55 +0000 Subject: [PATCH] remove the event dispatcher --- Makefile.am | 2 - openbox/client.c | 43 +++---- openbox/dispatch.c | 268 ------------------------------------------- openbox/dispatch.h | 106 ----------------- openbox/event.c | 45 +++----- openbox/focus.c | 6 - openbox/moveresize.c | 26 ++--- openbox/openbox.c | 22 +--- openbox/screen.c | 7 -- 9 files changed, 54 insertions(+), 471 deletions(-) delete mode 100644 openbox/dispatch.c delete mode 100644 openbox/dispatch.h diff --git a/Makefile.am b/Makefile.am index 6407ee8c..49d94bf5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -132,8 +132,6 @@ kernel_openbox_SOURCES = \ kernel/config.h \ kernel/debug.c \ kernel/debug.h \ - kernel/dispatch.c \ - kernel/dispatch.h \ kernel/dock.c \ kernel/dock.h \ kernel/event.c \ diff --git a/openbox/client.c b/openbox/client.c index f17e9724..e653ed19 100644 --- a/openbox/client.c +++ b/openbox/client.c @@ -5,6 +5,7 @@ #include "startup.h" #include "screen.h" #include "moveresize.h" +#include "place.h" #include "prop.h" #include "extensions.h" #include "frame.h" @@ -13,7 +14,6 @@ #include "grab.h" #include "focus.h" #include "stacking.h" -#include "dispatch.h" #include "openbox.h" #include "group.h" #include "config.h" @@ -254,10 +254,10 @@ void client_manage(Window window) frame_grab_client(self->frame, self); - client_apply_startup_state(self); - grab_server(FALSE); + client_apply_startup_state(self); + /* update the focus lists */ focus_order_add_new(self); @@ -306,10 +306,24 @@ void client_manage(Window window) #endif } - dispatch_client(Event_Client_New, self, 0, 0); + if (ob_state() == OB_STATE_RUNNING) { + int x = self->area.x, ox = x; + int y = self->area.y, oy = y; + + place_client(self, &x, &y); + + client_find_onscreen(self, &x, &y, + self->frame->area.width, + self->frame->area.height, + client_normal(self)); + + if (x != ox || y != oy) + client_configure(self, OB_CORNER_TOPLEFT, x, y, + self->area.width, self->area.height, + TRUE, TRUE); + } /* make sure the window is visible */ - if (ob_state() == OB_STATE_RUNNING) client_move_onscreen(self, client_normal(self)); client_showhide(self); @@ -339,8 +353,6 @@ void client_manage(Window window) keyboard_grab_for_client(self, TRUE); mouse_grab_for_client(self, TRUE); - dispatch_client(Event_Client_Mapped, self, 0, 0); - ob_debug("Managed window 0x%lx (%s)\n", window, self->class); } @@ -357,7 +369,6 @@ void client_unmanage(ObClient *self) ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class); - dispatch_client(Event_Client_Destroy, self, 0, 0); g_assert(self != NULL); keyboard_grab_for_client(self, FALSE); @@ -425,10 +436,6 @@ void client_unmanage(ObClient *self) self->group = NULL; } - /* dispatch the unmapped event */ - dispatch_client(Event_Client_Unmapped, self, 0, 0); - g_assert(self != NULL); - /* give the client its border back */ client_toggle_border(self, TRUE); @@ -1280,8 +1287,9 @@ void client_update_wmhints(ObClient *self) ur ? "ON" : "OFF"); /* fire the urgent callback if we're mapped, otherwise, wait until after we're mapped */ - if (self->frame) - dispatch_client(Event_Client_Urgent, self, self->urgent, 0); + if (self->frame) { + /* XXX do shit */ + } } } @@ -1705,7 +1713,7 @@ static void client_apply_startup_state(ObClient *self) client_shade(self, TRUE); } if (self->urgent) - dispatch_client(Event_Client_Urgent, self, self->urgent, 0); + /* XXX do shit */; if (self->max_vert && self->max_horz) { self->max_vert = self->max_horz = FALSE; @@ -2062,9 +2070,6 @@ static void client_iconify_recursive(ObClient *self, client_change_state(self); client_showhide(self); screen_update_areas(); - - dispatch_client(iconic ? Event_Client_Unmapped : Event_Client_Mapped, - self, 0, 0); } /* iconify all transients */ @@ -2266,8 +2271,6 @@ void client_set_desktop_recursive(ObClient *self, focus_order_to_top(self); else focus_order_to_bottom(self); - - dispatch_client(Event_Client_Desktop, self, target, old); } /* move all transients */ diff --git a/openbox/dispatch.c b/openbox/dispatch.c deleted file mode 100644 index 291e9580..00000000 --- a/openbox/dispatch.c +++ /dev/null @@ -1,268 +0,0 @@ -#include "dispatch.h" -#include "extensions.h" -#include "client.h" - -#include - -typedef struct { - EventHandler h; - void *data; -} Func; - -/* an array of GSList*s of Func*s */ -static GSList **funcs; - -void dispatch_startup() -{ - guint i; - EventType j; - - i = 0; - j = EVENT_RANGE; - while (j > 1) { - j >>= 1; - ++i; - } - funcs = g_new0(GSList*, i); -} - -void dispatch_shutdown() -{ - guint i; - EventType j; - GSList *it; - - for (i = 0, j = 1; j < EVENT_RANGE; ++i, j <<= 1) { - for (it = funcs[i]; it != NULL; it = it->next) - g_free(it->data); - g_slist_free(funcs[i]); - funcs[i] = NULL; - } - - g_free(funcs); -} - -void dispatch_register(EventMask mask, EventHandler h, void *data) -{ - guint i; - EventType j; - GSList *it, *next; - EventMask m; - Func *f; - - /* add to masks it needs to be registered for */ - m = mask; - while (m) { - for (i = 0, j = 1; j < EVENT_RANGE; ++i, j <<= 1) - if (m & j) { - for (it = funcs[i]; it != NULL; it = it->next) { - f = it->data; - if (f->h == h && f->data == data) - break; - } - if (it == NULL) { /* wasn't already regged */ - f = g_new(Func, 1); - f->h = h; - f->data = data; - funcs[i] = g_slist_append(funcs[i], f); - } - m ^= j; /* remove from the mask */ - } - g_assert(j >= EVENT_RANGE); /* an invalid event is in the mask */ - } - - /* remove from masks its not registered for anymore */ - for (i = 0, j = 1; j < EVENT_RANGE; ++i, j <<= 1) { - if (!(j & mask)) - for (it = funcs[i]; it != NULL; it = next) { - next = it->next; - f = it->data; - if (f->h == h && f->data == data) { - g_free(f); - funcs[i] = g_slist_delete_link(funcs[i], it); - } - } - } -} - -void dispatch_x(XEvent *xe, ObClient *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) { - Func *f = it->data; - f->h(&obe, f->data); - } -} - -void dispatch_client(EventType e, ObClient *c, int num0, int num1) -{ - guint i; - GSList *it; - ObEvent obe; - - g_assert(c != NULL); - - obe.type = e; - obe.data.c.client = c; - obe.data.c.num[0] = num0; - obe.data.c.num[1] = num1; - obe.data.c.num[2] = 0; - - i = 0; - while (e > 1) { - e >>= 1; - ++i; - } - - for (it = funcs[i]; it != NULL; it = it->next) { - Func *f = it->data; - f->h(&obe, f->data); - } -} - -void dispatch_ob(EventType e, int num0, int num1) -{ - guint i; - GSList *it; - ObEvent obe; - - obe.type = e; - obe.data.o.num[0] = num0; - obe.data.o.num[1] = num1; - - i = 0; - while (e > 1) { - e >>= 1; - ++i; - } - - for (it = funcs[i]; it != NULL; it = it->next) { - Func *f = it->data; - f->h(&obe, f->data); - } -} - -void dispatch_signal(int signal) -{ - guint i; - EventType e = Event_Signal; - GSList *it; - ObEvent obe; - - obe.type = e; - obe.data.s.signal = signal; - - i = 0; - while (e > 1) { - e >>= 1; - ++i; - } - - for (it = funcs[i]; it != NULL; it = it->next) { - Func *f = it->data; - f->h(&obe, f->data); - } -} - -void dispatch_move(ObClient *c, int *x, int *y) -{ - guint i; - GSList *it; - EventType e = Event_Client_Moving; - ObEvent obe; - - obe.type = e; - obe.data.c.client = c; - obe.data.c.num[0] = *x; - obe.data.c.num[1] = *y; - - i = 0; - while (e > 1) { - e >>= 1; - ++i; - } - - for (it = funcs[i]; it != NULL; it = it->next) { - Func *f = it->data; - f->h(&obe, f->data); - } - - *x = obe.data.c.num[0]; - *y = obe.data.c.num[1]; -} - -void dispatch_resize(ObClient *c, int *w, int *h, ObCorner corner) -{ - guint i; - GSList *it; - EventType e = Event_Client_Resizing; - ObEvent obe; - - obe.type = e; - obe.data.c.client = c; - obe.data.c.num[0] = *w; - obe.data.c.num[1] = *h; - obe.data.c.num[2] = corner; - - i = 0; - while (e > 1) { - e >>= 1; - ++i; - } - - for (it = funcs[i]; it != NULL; it = it->next) { - Func *f = it->data; - f->h(&obe, f->data); - } - - *w = obe.data.c.num[0]; - *h = obe.data.c.num[1]; -} diff --git a/openbox/dispatch.h b/openbox/dispatch.h deleted file mode 100644 index 93b3e459..00000000 --- a/openbox/dispatch.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef __dispatch_h -#define __dispatch_h - -#include "misc.h" - -#include - -struct _ObClient; - -void dispatch_startup(); -void dispatch_shutdown(); - -typedef enum { - Event_X_EnterNotify = 1 << 0, /* pointer entered a window */ - Event_X_LeaveNotify = 1 << 1, /* pointer left a window */ - Event_X_KeyPress = 1 << 2, /* key pressed */ - Event_X_KeyRelease = 1 << 3, /* key released */ - Event_X_ButtonPress = 1 << 4, /* mouse button pressed */ - Event_X_ButtonRelease = 1 << 5, /* mouse button released */ - Event_X_MotionNotify = 1 << 6, /* mouse motion */ - Event_X_Bell = 1 << 7, /* an XKB bell event */ - - Event_Client_New = 1 << 8, /* new window, before mapping */ - Event_Client_Mapped = 1 << 9, /* new window, after mapping - or uniconified */ - Event_Client_Destroy = 1 << 10, /* unmanaged */ - Event_Client_Unmapped = 1 << 11, /* unmanaged, after unmapping - or iconified */ - Event_Client_Focus = 1 << 12, /* focused */ - Event_Client_Unfocus = 1 << 13, /* unfocused */ - Event_Client_Urgent = 1 << 14, /* entered/left urgent state */ - Event_Client_Desktop = 1 << 15, /* moved to a new desktop */ - Event_Client_Moving = 1 << 16, /* being interactively moved */ - Event_Client_Resizing = 1 << 17, /* being interactively resized */ - - Event_Ob_Desktop = 1 << 18, /* changed desktops */ - Event_Ob_NumDesktops = 1 << 19, /* changed the number of desktops */ - Event_Ob_ShowDesktop = 1 << 20, /* entered/left show-the-desktop mode */ - - Event_Signal = 1 << 21, /* a signal from the OS */ - - EVENT_RANGE = 1 << 22 -} EventType; - -typedef struct { - XEvent *e; - struct _ObClient *client; -} EventData_X; - -typedef struct { - struct _ObClient *client; - int num[3]; - /* Event_Client_Desktop: num[0] = new number, num[1] = old number - Event_Client_Urgent: num[0] = urgent state - Event_Client_Moving: num[0] = dest x coord, num[1] = dest y coord -- - change these in the handler to adjust where the - window will be placed - Event_Client_Resizing: num[0] = dest width, num[1] = dest height -- - change these in the handler to adjust where the - window will be placed - num[2] = the anchored corner - */ -} EventData_Client; - -typedef struct { - int num[2]; - /* Event_Ob_Desktop: num[0] = new number, num[1] = old number - Event_Ob_NumDesktops: num[0] = new number, num[1] = old number - Event_Ob_ShowDesktop: num[0] = new show-desktop mode - */ -} EventData_Ob; - -typedef struct { - int signal; -} EventData_Signal; - -typedef struct { - EventData_X x; /* for Event_X_* event types */ - EventData_Client c; /* for Event_ObClient_* event types */ - EventData_Ob o; /* for Event_Ob_* event types */ - EventData_Signal s; /* for Event_Signal */ -} EventData; - -typedef struct { - EventType type; - EventData data; -} ObEvent; - -typedef void (*EventHandler)(const ObEvent *e, void *data); - -typedef unsigned int EventMask; - -void dispatch_register(EventMask mask, EventHandler h, void *data); - -void dispatch_x(XEvent *e, struct _ObClient *c); -void dispatch_client(EventType e, struct _ObClient *c, int num0, int num1); -void dispatch_ob(EventType e, int num0, int num1); -void dispatch_signal(int signal); -/* *x and *y should be set with the destination of the window, they may be - changed by the event handlers */ -void dispatch_move(struct _ObClient *c, int *x, int *y); -/* *w and *h should be set with the destination of the window, they may be - changed by the event handlers */ -void dispatch_resize(struct _ObClient *c, int *w, int *h, ObCorner corner); - -#endif diff --git a/openbox/event.c b/openbox/event.c index 094d19fe..f71fdf57 100644 --- a/openbox/event.c +++ b/openbox/event.c @@ -17,7 +17,6 @@ #include "stacking.h" #include "extensions.h" #include "timer.h" -#include "dispatch.h" #include "event.h" #include @@ -523,45 +522,29 @@ static void event_process(XEvent *e) xerror_set_ignore(FALSE); } - if (menu_frame_visible) - if (e->type == MotionNotify || e->type == ButtonRelease || - e->type == ButtonPress || - e->type == KeyPress || e->type == KeyRelease) { - event_handle_menu(e); - - return; /* no dispatch! */ - } - - if (moveresize_in_progress) - if (e->type == MotionNotify || e->type == ButtonRelease || - e->type == ButtonPress || - e->type == KeyPress || e->type == KeyRelease) { - moveresize_event(e); - - return; /* no dispatch! */ - } - /* user input (action-bound) events */ if (e->type == ButtonPress || e->type == ButtonRelease || e->type == MotionNotify || e->type == KeyPress || e->type == KeyRelease) { - ObFrameContext context; - - context = frame_context(client, e->xany.window); + if (menu_frame_visible) + event_handle_menu(e); + else if (moveresize_in_progress) + moveresize_event(e); + else { + ObFrameContext context; - if (!keyboard_process_interactive_grab(e, &client, &context)) { + context = frame_context(client, e->xany.window); - if (e->type == ButtonPress || e->type == ButtonRelease || - e->type == MotionNotify) - mouse_event(client, context, e); - else if (e->type == KeyPress) - keyboard_event(client, e); + if (!keyboard_process_interactive_grab(e, &client, &context)) { + if (e->type == ButtonPress || e->type == ButtonRelease || + e->type == MotionNotify) + mouse_event(client, context, e); + else if (e->type == KeyPress) + keyboard_event(client, e); + } } } - - /* dispatch the event to registered handlers */ - dispatch_x(e, client); } static void event_handle_root(XEvent *e) diff --git a/openbox/focus.c b/openbox/focus.c index 28329429..dab6d573 100644 --- a/openbox/focus.c +++ b/openbox/focus.c @@ -9,7 +9,6 @@ #include "screen.h" #include "group.h" #include "prop.h" -#include "dispatch.h" #include "focus.h" #include "stacking.h" #include "popup.h" @@ -96,11 +95,6 @@ void focus_set_client(ObClient *client) PROP_SET32(RootWindow(ob_display, ob_screen), net_active_window, window, active); } - - if (focus_client != NULL) - dispatch_client(Event_Client_Focus, focus_client, 0, 0); - if (old != NULL) - dispatch_client(Event_Client_Unfocus, old, 0, 0); } static gboolean focus_under_pointer() diff --git a/openbox/moveresize.c b/openbox/moveresize.c index 981a9df2..9916c12d 100644 --- a/openbox/moveresize.c +++ b/openbox/moveresize.c @@ -4,7 +4,6 @@ #include "prop.h" #include "client.h" #include "frame.h" -#include "dispatch.h" #include "openbox.h" #include "resist.h" #include "popup.h" @@ -157,8 +156,6 @@ static void do_move(gboolean resist) if (resist) resist_move(moveresize_client, &cur_x, &cur_y); - dispatch_move(moveresize_client, &cur_x, &cur_y); - /* get where the client should be */ frame_frame_gravity(moveresize_client->frame, &cur_x, &cur_y); client_configure(moveresize_client, OB_CORNER_TOPLEFT, cur_x, cur_y, @@ -174,21 +171,20 @@ static void do_move(gboolean resist) static void do_resize(gboolean resist) { - /* dispatch_resize needs the frame size */ - cur_x += moveresize_client->frame->size.left + - moveresize_client->frame->size.right; - cur_y += moveresize_client->frame->size.top + - moveresize_client->frame->size.bottom; + if (resist) { + /* resist_size needs the frame size */ + cur_x += moveresize_client->frame->size.left + + moveresize_client->frame->size.right; + cur_y += moveresize_client->frame->size.top + + moveresize_client->frame->size.bottom; - if (resist) resist_size(moveresize_client, &cur_x, &cur_y, lockcorner); - dispatch_resize(moveresize_client, &cur_x, &cur_y, lockcorner); - - cur_x -= moveresize_client->frame->size.left + - moveresize_client->frame->size.right; - cur_y -= moveresize_client->frame->size.top + - moveresize_client->frame->size.bottom; + cur_x -= moveresize_client->frame->size.left + + moveresize_client->frame->size.right; + cur_y -= moveresize_client->frame->size.top + + moveresize_client->frame->size.bottom; + } client_configure(moveresize_client, lockcorner, moveresize_client->area.x, moveresize_client->area.y, diff --git a/openbox/openbox.c b/openbox/openbox.c index 8e61fa86..59ba7627 100644 --- a/openbox/openbox.c +++ b/openbox/openbox.c @@ -5,7 +5,6 @@ #include "event.h" #include "menu.h" #include "client.h" -#include "dispatch.h" #include "xerror.h" #include "prop.h" #include "startup.h" @@ -66,7 +65,7 @@ static Cursor cursors[OB_NUM_CURSORS]; static KeyCode keys[OB_NUM_KEYS]; static gchar *sm_save_file; -static void signal_handler(const ObEvent *e, void *data); +static void signal_handler(int signal); static void parse_args(int argc, char **argv); int main(int argc, char **argv) @@ -90,13 +89,9 @@ int main(int argc, char **argv) bind_textdomain_codeset(PACKAGE_NAME, "UTF-8"); textdomain(PACKAGE_NAME); - /* start our event dispatcher and register for signals */ - dispatch_startup(); - dispatch_register(Event_Signal, signal_handler, NULL); - /* set up signal handler */ sigemptyset(&sigset); - action.sa_handler = dispatch_signal; + action.sa_handler = signal_handler; action.sa_mask = sigset; action.sa_flags = SA_NOCLDSTOP | SA_NODEFER; sigaction(SIGUSR1, &action, (struct sigaction *) NULL); @@ -284,8 +279,6 @@ int main(int argc, char **argv) config_shutdown(); } - dispatch_shutdown(); - RrThemeFree(ob_rr_theme); RrInstanceFree(ob_rr_inst); @@ -321,12 +314,9 @@ int main(int argc, char **argv) return 0; } -static void signal_handler(const ObEvent *e, void *data) +static void signal_handler(int sig) { - int s; - - s = e->data.s.signal; - switch (s) { + switch (sig) { case SIGUSR1: fprintf(stderr, "Caught SIGUSR1 signal. Restarting."); ob_restart(); @@ -336,13 +326,13 @@ static void signal_handler(const ObEvent *e, void *data) case SIGINT: case SIGTERM: case SIGPIPE: - fprintf(stderr, "Caught signal %d. Exiting.", s); + fprintf(stderr, "Caught signal %d. Exiting.", sig); ob_exit(); break; case SIGFPE: case SIGSEGV: - fprintf(stderr, "Caught signal %d. Aborting and dumping core.", s); + fprintf(stderr, "Caught signal %d. Aborting and dumping core.", sig); abort(); } } diff --git a/openbox/screen.c b/openbox/screen.c index f80f0c2d..1eb0051d 100644 --- a/openbox/screen.c +++ b/openbox/screen.c @@ -12,7 +12,6 @@ #include "frame.h" #include "focus.h" #include "popup.h" -#include "dispatch.h" #include "extensions.h" #include "render/render.h" @@ -402,8 +401,6 @@ void screen_set_num_desktops(guint num) /* change our struts/area to match (after moving windows) */ screen_update_areas(); - dispatch_ob(Event_Ob_NumDesktops, num, old); - /* change our desktop if we're on one that no longer exists! */ if (screen_desktop >= screen_num_desktops) screen_set_desktop(num - 1); @@ -456,8 +453,6 @@ void screen_set_desktop(guint num) #ifdef DEBUG_FOCUS ob_debug("/switch fallback\n"); #endif - - dispatch_ob(Event_Ob_Desktop, num, old); } static void get_row_col(guint d, guint *r, guint *c) @@ -847,8 +842,6 @@ void screen_show_desktop(gboolean show) show = !!show; /* make it boolean */ PROP_SET32(RootWindow(ob_display, ob_screen), net_showing_desktop, cardinal, show); - - dispatch_ob(Event_Ob_ShowDesktop, show, 0); } void screen_install_colormap(ObClient *client, gboolean install) -- 2.39.2