all events are dispatched

This commit is contained in:
Dana Jansens 2003-03-17 20:16:32 +00:00
parent 033bd73e7e
commit 75b07a2bb3
7 changed files with 80 additions and 81 deletions

View file

@ -7,6 +7,7 @@
#include "event.h"
#include "focus.h"
#include "stacking.h"
#include "dispatch.h"
#include <glib.h>
#include <X11/Xutil.h>
@ -194,10 +195,12 @@ void client_manage(Window window)
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*/
@ -220,7 +223,7 @@ void client_unmanage(Client *client)
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);
@ -923,7 +926,7 @@ void client_update_wmhints(Client *self)
/* 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);
}
}
@ -1218,7 +1221,7 @@ static void client_showhide(Client *self)
else
engine_frame_hide(self->frame);
/*HOOKFIRECLIENT(visible, self);XXX*/
dispatch_client(Event_Client_Visible, self);
}
gboolean client_normal(Client *self) {
@ -1243,7 +1246,7 @@ static void client_apply_startup_state(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;

View file

@ -1,4 +1,5 @@
#include "dispatch.h"
#include "extensions.h"
#include <glib.h>
@ -26,8 +27,10 @@ void dispatch_shutdown()
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);
}
@ -47,7 +50,7 @@ void dispatch_register(EventHandler h, EventMask mask)
}
}
void dispatch_x(XEvent *xe)
void dispatch_x(XEvent *xe, Client *c)
{
EventType e;
guint i;
@ -77,11 +80,20 @@ void dispatch_x(XEvent *xe)
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) {

View file

@ -15,26 +15,35 @@ typedef enum {
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;
@ -50,7 +59,7 @@ typedef unsigned int EventMask;
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);

View file

@ -10,6 +10,7 @@
#include "extensions.h"
#include "timer.h"
#include "engine.h"
#include "dispatch.h"
#include <X11/Xlib.h>
#include <X11/keysym.h>
@ -252,6 +253,7 @@ void event_process(XEvent *e)
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)
@ -279,45 +281,8 @@ void event_process(XEvent *e)
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)

View file

@ -2,6 +2,7 @@
#include "client.h"
#include "screen.h"
#include "prop.h"
#include "dispatch.h"
#include <X11/Xlib.h>
@ -46,11 +47,15 @@ void focus_set_client(Client *client)
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);
}

View file

@ -47,7 +47,7 @@ gboolean ob_remote = FALSE;
gboolean ob_sync = TRUE;
Cursors ob_cursors;
void signal_handler(int signal);
void signal_handler(const ObEvent *e);
int main(int argc, char **argv)
{
@ -63,9 +63,13 @@ 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);
@ -124,7 +128,6 @@ int main(int argc, char **argv)
if (screen_annex()) { /* it will be ours! */
timer_startup();
dispatch_startup();
render_startup();
font_startup();
themerc_startup();
@ -133,8 +136,8 @@ int main(int argc, char **argv)
screen_startup();
focus_startup();
client_startup();
/*HOOKFIRE(startup, "()");XXX*/
dispatch_ob(Event_Ob_Startup);
/* get all the existing windows */
client_manage_all();
@ -147,7 +150,7 @@ int main(int argc, char **argv)
client_unmanage_all();
/*HOOKFIRE(shutdown, "()");XXX*/
dispatch_ob(Event_Ob_Shutdown);
client_shutdown();
screen_shutdown();
@ -155,20 +158,21 @@ int main(int argc, char **argv)
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;
@ -182,12 +186,12 @@ void signal_handler(int signal)
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);
}
}

View file

@ -5,6 +5,8 @@
#include "frame.h"
#include "engine.h"
#include "focus.h"
#include "dispatch.h"
#include "../render/render.h"
#include <X11/Xlib.h>
#ifdef HAVE_UNISTD_H
@ -233,6 +235,8 @@ void screen_set_num_desktops(guint num)
/* 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);
@ -267,9 +271,7 @@ void screen_set_desktop(guint num)
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()
@ -392,18 +394,17 @@ void screen_show_desktop(gboolean show)
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)) {