#include "event.h"
#include "focus.h"
#include "stacking.h"
+#include "dispatch.h"
#include <glib.h>
#include <X11/Xutil.h>
screen_update_struts();
- /*HOOKFIRECLIENT(managed, client);XXX*/
+ dispatch_client(Event_Client_New, client);
client_showhide(client);
+ dispatch_client(Event_Client_Mapped, client);
+
/* grab all mouse bindings */
/*pointer_grab_all(client, TRUE);XXX*/
g_message("Unmanaging window: %lx", client->window);
- /*HOOKFIRECLIENT(closed, client);XXX*/
+ dispatch_client(Event_Client_Destroy, client);
/* remove the window from our save set */
XChangeSaveSet(ob_display, client->window, SetModeDelete);
/* fire the urgent callback if we're mapped, otherwise, wait until
after we're mapped */
if (self->frame)
- /*HOOKFIRECLIENT(urgent, self)XXX*/;
+ dispatch_client(Event_Client_Urgent, self);
}
}
else
engine_frame_hide(self->frame);
- /*HOOKFIRECLIENT(visible, self);XXX*/
+ dispatch_client(Event_Client_Visible, self);
}
gboolean client_normal(Client *self) {
client_shade(self, TRUE);
}
if (self->urgent)
- /*HOOKFIRECLIENT(urgent, self)XXX*/;
+ dispatch_client(Event_Client_Urgent, self);
if (self->max_vert && self->max_horz) {
self->max_vert = self->max_horz = FALSE;
#include "dispatch.h"
+#include "extensions.h"
#include <glib.h>
guint i;
EventType j;
- for (i = 0, j = 1; j < EVENT_RANGE; ++i, j <<= 1)
+ for (i = 0, j = 1; j < EVENT_RANGE; ++i, j <<= 1) {
g_slist_free(funcs[i]);
+ funcs[i] = NULL;
+ }
g_free(funcs);
}
}
}
-void dispatch_x(XEvent *xe)
+void dispatch_x(XEvent *xe, Client *c)
{
EventType e;
guint i;
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 = xe;
+ obe.data.x.e = xe;
+ obe.data.x.client = c;
i = 0;
while (e > 1) {
Event_X_ButtonPress = 1 << 4,
Event_X_ButtonRelease = 1 << 5,
Event_X_MotionNotify = 1 << 6,
+ Event_X_Bell = 1 << 7,
- Event_Client_New = 1 << 7, /* new window, before mapping */
- Event_Client_Mapped = 1 << 8, /* new window, after mapping */
- Event_Client_Destroy = 1 << 9, /* unmanaged */
- Event_Client_Focus = 1 << 10,
- Event_Client_Unfocus = 1 << 11,
+ Event_Client_New = 1 << 8, /* new window, before mapping */
+ Event_Client_Mapped = 1 << 9, /* new window, after mapping */
+ Event_Client_Destroy = 1 << 10, /* unmanaged */
+ Event_Client_Focus = 1 << 11, /* focused */
+ Event_Client_Unfocus = 1 << 12, /* unfocused */
+ Event_Client_Urgent = 1 << 13, /* entered/left urgent state */
+ Event_Client_Visible = 1 << 14, /* shown/hidden (not on a workspace or
+ show-the-desktop change though) */
- Event_Ob_Desktop = 1 << 12, /* changed desktops */
- Event_Ob_NumDesktops = 1 << 13, /* changed the number of desktops */
- Event_Ob_ShowDesktop = 1 << 14, /* entered/left show-the-desktop mode */
- Event_Ob_Startup = 1 << 15, /* startup complete */
- Event_Ob_Shutdown = 1 << 16, /* shutdown about to start */
+ Event_Ob_Desktop = 1 << 15, /* changed desktops */
+ Event_Ob_NumDesktops = 1 << 16, /* changed the number of desktops */
+ Event_Ob_ShowDesktop = 1 << 17, /* entered/left show-the-desktop mode */
+ Event_Ob_Startup = 1 << 18, /* startup complete */
+ Event_Ob_Shutdown = 1 << 19, /* shutdown about to start */
- Event_Signal = 1 << 17,
+ Event_Signal = 1 << 20,
- EVENT_RANGE = 1 << 18
+ EVENT_RANGE = 1 << 21
} EventType;
+typedef struct {
+ XEvent *e;
+ Client *client;
+} EventData_X;
+
typedef union {
- XEvent *x; /* for Event_X_* event types */
+ EventData_X x; /* for Event_X_* event types */
Client *client; /* for Event_Client_* event types */
int signal;
} EventData;
void dispatch_register(EventHandler h, EventMask mask);
-void dispatch_x(XEvent *e);
+void dispatch_x(XEvent *e, Client *c);
void dispatch_client(EventType e, Client *c);
void dispatch_ob(EventType e);
void dispatch_signal(int signal);
#include "extensions.h"
#include "timer.h"
#include "engine.h"
+#include "dispatch.h"
#include <X11/Xlib.h>
#include <X11/keysym.h>
client = g_hash_table_lookup(client_map, (gpointer)window);
+ /* deal with it in the kernel */
if (client) {
event_handle_client(client, e);
} else if (window == ob_root)
xerror_set_ignore(FALSE);
}
- /* dispatch Crossing, Pointer and Key events to the hooks */
- switch(e->type) {
- case EnterNotify:
- if (client != NULL) engine_mouse_enter(client->frame, window);
- /*HOOKFIRECLIENT(pointerenter, client);XXX*/
- break;
- case LeaveNotify:
- if (client != NULL) engine_mouse_leave(client->frame, window);
- /*HOOKFIRECLIENT(pointerleave, client);XXX*/
- break;
- case ButtonPress:
- if (client != NULL)
- engine_mouse_press(client->frame, window,
- e->xbutton.x, e->xbutton.y);
- /*pointer_event(e, client);XXX*/
- break;
- case ButtonRelease:
- if (client != NULL)
- engine_mouse_release(client->frame, window,
- e->xbutton.x, e->xbutton.y);
- /*pointer_event(e, client);XXX*/
- break;
- case MotionNotify:
- /*pointer_event(e, client);XXX*/
- break;
- case KeyPress:
- case KeyRelease:
- /*keyboard_event(&e->xkey);XXX*/
- break;
- default:
- /* XKB events */
- if (e->type == extensions_xkb_event_basep) {
- switch (((XkbAnyEvent*)&e)->xkb_type) {
- case XkbBellNotify:
- /*HOOKFIRECLIENT(bell, client);XXX*/
- break;
- }
- }
- }
+ /* dispatch the event to registered handlers */
+ dispatch_x(e, client);
}
static void event_handle_root(XEvent *e)
#include "client.h"
#include "screen.h"
#include "prop.h"
+#include "dispatch.h"
#include <X11/Xlib.h>
XSetInputFocus(ob_display, focus_backup, RevertToNone, CurrentTime);
}
+ if (focus_client != NULL)
+ dispatch_client(Event_Client_Unfocus, focus_client);
+
focus_client = client;
/* set the NET_ACTIVE_WINDOW hint */
active = client ? client->window : None;
PROP_SET32(ob_root, net_active_window, window, active);
- /*HOOKFIRECLIENT(focused, client);XXX*/
+ if (focus_client != NULL)
+ dispatch_client(Event_Client_Focus, focus_client);
}
gboolean ob_sync = TRUE;
Cursors ob_cursors;
-void signal_handler(int signal);
+void signal_handler(const ObEvent *e);
int main(int argc, char **argv)
{
bind_textdomain_codeset(PACKAGE, "UTF-8");
textdomain(PACKAGE);
+ /* start our event dispatcher and register for signals */
+ dispatch_startup();
+ dispatch_register(signal_handler, Event_Signal);
+
/* set up signal handler */
sigemptyset(&sigset);
- action.sa_handler = signal_handler;
+ action.sa_handler = dispatch_signal;
action.sa_mask = sigset;
action.sa_flags = SA_NOCLDSTOP | SA_NODEFER;
sigaction(SIGUSR1, &action, (struct sigaction *) NULL);
if (screen_annex()) { /* it will be ours! */
timer_startup();
- dispatch_startup();
render_startup();
font_startup();
themerc_startup();
screen_startup();
focus_startup();
client_startup();
-
- /*HOOKFIRE(startup, "()");XXX*/
+
+ dispatch_ob(Event_Ob_Startup);
/* get all the existing windows */
client_manage_all();
client_unmanage_all();
- /*HOOKFIRE(shutdown, "()");XXX*/
+ dispatch_ob(Event_Ob_Shutdown);
client_shutdown();
screen_shutdown();
engine_shutdown();
themerc_shutdown();
render_shutdown();
- dispatch_shutdown();
timer_shutdown();
}
XCloseDisplay(ob_display);
+ dispatch_shutdown();
+
/* XXX if (ob_restart) */
return 0;
}
-void signal_handler(int signal)
+void signal_handler(const ObEvent *e)
{
- switch (signal) {
+ switch (e->data.signal) {
case SIGUSR1:
g_message("Caught SIGUSR1 signal. Restarting.");
ob_shutdown = ob_restart = TRUE;
case SIGINT:
case SIGTERM:
case SIGPIPE:
- g_message("Caught signal %d. Exiting.", signal);
+ g_message("Caught signal %d. Exiting.", e->data.signal);
ob_shutdown = TRUE;
break;
case SIGFPE:
case SIGSEGV:
- g_error("Caught signal %d. Aborting and dumping core.", signal);
+ g_error("Caught signal %d. Aborting and dumping core.",e->data.signal);
}
}
#include "frame.h"
#include "engine.h"
#include "focus.h"
+#include "dispatch.h"
+#include "../render/render.h"
#include <X11/Xlib.h>
#ifdef HAVE_UNISTD_H
/* may be some unnamed desktops that we need to fill in with names */
screen_update_desktop_names();
+ dispatch_ob(Event_Ob_NumDesktops);
+
/* change our desktop if we're on one that no longer exists! */
if (screen_desktop >= screen_num_desktops)
screen_set_desktop(num - 1);
engine_frame_show(c->frame);
}
- /* force the callbacks to fire */
- if (focus_client == NULL)
- focus_set_client(NULL);
+ dispatch_ob(Event_Ob_Desktop);
}
void screen_update_layout()
show = show ? 1 : 0; /* make it boolean */
PROP_SET32(ob_root, net_showing_desktop, cardinal, show);
+
+ dispatch_ob(Event_Ob_ShowDesktop);
}
void screen_install_colormap(Client *client, gboolean install)
{
if (client == NULL) {
- /* XXX DONT USE THE DEFAULT SHIT HERE */
if (install)
- XInstallColormap(ob_display,
- DefaultColormap(ob_display, ob_screen));
+ XInstallColormap(ob_display, render_colormap);
else
- XUninstallColormap(ob_display,
- DefaultColormap(ob_display, ob_screen));
+ XUninstallColormap(ob_display, render_colormap);
} else {
XWindowAttributes wa;
if (XGetWindowAttributes(ob_display, client->window, &wa)) {