stop using python internally. add an event dispatcher

This commit is contained in:
Dana Jansens 2003-03-17 19:54:37 +00:00
parent 055b459cdf
commit 9b33f7ded6
10 changed files with 243 additions and 91 deletions

View file

@ -1,4 +1,4 @@
SUBDIRS = po data themes doc render kernel engines python
SUBDIRS = po data themes doc render kernel engines plugins
MAINTAINERCLEANFILES = aclocal.m4 config.h.in configure Makefile.in stamp-h.in
.PHONY: doc

View file

@ -32,8 +32,6 @@ PKG_CHECK_MODULES(GMODULE, gmodule-2.0)
AC_SUBST(GMODULE_CFLAGS)
AC_SUBST(GMODULE_LIBS)
PYTHON_DEVEL
AC_PROG_LN_S
AC_PROG_LIBTOOL
LIBTOOL="$LIBTOOL --silent"
@ -63,7 +61,7 @@ AC_CONFIG_FILES([Makefile po/Makefile.in
render/Makefile
engines/Makefile
engines/openbox/Makefile
python/Makefile
plugins/Makefile
doc/Makefile
doc/doxygen/Makefile
data/Makefile

View file

@ -1,31 +1,30 @@
localedir=$(datadir)/locale
themercdir=$(datadir)/openbox
scriptdir=$(libdir)/openbox/python
enginedir=$(libdir)/openbox/engines
plugindir=$(libdir)/openbox/plugins
CPPFLAGS=$(XFT_CFLAGS) $(PYTHON_CFLAGS) $(GLIB_CFLAGS) $(GMODULE_CFLAGS) \
CPPFLAGS=$(XFT_CFLAGS) $(GLIB_CFLAGS) $(GMODULE_CFLAGS) \
@CPPFLAGS@ \
-DLOCALEDIR=\"$(localedir)\" \
-DTHEMERCDIR=\"$(themercdir)\" \
-DSCRIPTDIR=\"$(scriptdir)\" \
-DPLUGINDIR=\"$(plugindir)\" \
-DENGINEDIR=\"$(enginedir)\" \
-DDEFAULT_ENGINE=\"openbox\" \
-DG_LOG_DOMAIN=\"Openbox\"
LIBS=$(XFT_LIBS) $(PYTHON_LIBS) $(GLIB_LIBS) $(GMODULE_LIBS) @LIBS@
LIBS=$(XFT_LIBS) $(GLIB_LIBS) $(GMODULE_LIBS) @LIBS@
bin_PROGRAMS= ob3
ob3_LDADD=@LIBINTL@ ../render/librender.a
ob3_LDFLAGS=-export-dynamic
ob3_SOURCES=client.c event.c extensions.c focus.c frame.c openbox.c prop.c \
python.c screen.c stacking.c xerror.c hooks.c themerc.c timer.c \
clientwrap.c openboxwrap.c pointer.c keyboard.c engine.c configwrap.c
screen.c stacking.c xerror.c themerc.c timer.c dispatch.c \
engine.c
noinst_HEADERS=client.h event.h extensions.h focus.h frame.h geom.h gettext.h \
openbox.h prop.h python.h screen.h stacking.h xerror.h themerc.h \
timer.h hooks.h clientwrap.h openboxwrap.h pointer.h keyboard.h \
engine.h configwrap.h
openbox.h prop.h screen.h stacking.h xerror.h themerc.h dispatch.h \
timer.h engine.h
MAINTAINERCLEANFILES= Makefile.in

View file

@ -7,11 +7,8 @@
#include "event.h"
#include "focus.h"
#include "stacking.h"
#include "pointer.h"
#include "hooks.h"
#include "openboxwrap.h"
#include "clientwrap.h"
#include <glib.h>
#include <X11/Xutil.h>
/*! The event mask to grab on client windows */
@ -122,7 +119,6 @@ void client_manage(Window window)
XWindowAttributes attrib;
XSetWindowAttributes attrib_set;
/* XWMHints *wmhint; */
PyObject *cw;
XGrabServer(ob_display);
XSync(ob_display, FALSE);
@ -198,17 +194,12 @@ void client_manage(Window window)
screen_update_struts();
/* add to the python list */
cw = clientwrap_new(client);
PyList_Append(openboxwrap_obj->client_list, cw);
Py_DECREF(cw);
HOOKFIRECLIENT(managed, client);
/*HOOKFIRECLIENT(managed, client);XXX*/
client_showhide(client);
/* grab all mouse bindings */
pointer_grab_all(client, TRUE);
/*pointer_grab_all(client, TRUE);XXX*/
/* update the list hints */
client_set_list();
@ -224,13 +215,12 @@ void client_unmanage_all()
void client_unmanage(Client *client)
{
int j, seq;
PyObject *cw;
int j;
GSList *it;
g_message("Unmanaging window: %lx", client->window);
HOOKFIRECLIENT(closed, client);
/*HOOKFIRECLIENT(closed, client);XXX*/
/* remove the window from our save set */
XChangeSaveSet(ob_display, client->window, SetModeDelete);
@ -239,7 +229,7 @@ void client_unmanage(Client *client)
XSelectInput(ob_display, client->window, NoEventMask);
/* ungrab any mouse bindings */
pointer_grab_all(client, FALSE);
/*pointer_grab_all(client, FALSE);XXX*/
engine_frame_hide(client->frame);
@ -257,19 +247,6 @@ void client_unmanage(Client *client)
influence */
screen_update_struts();
/* remove from the python list */
cw = clientwrap_new(client);
seq = PySequence_Index(openboxwrap_obj->client_list, cw);
if (seq == -1)
PyErr_Clear();
else
PySequence_DelItem(openboxwrap_obj->client_list, seq);
Py_DECREF(cw);
/* notify the wrapper that its useless now */
if (client->wrap != NULL)
client->wrap->client = NULL;
/* tell our parent that we're gone */
if (client->transient_for != NULL)
client->transient_for->transients =
@ -402,7 +379,6 @@ static void client_get_all(Client *self)
self->disabled_decorations = 0;
self->group = None;
self->nicons = 0;
self->wrap = NULL;
client_get_area(self);
client_get_desktop(self);
@ -947,7 +923,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);
/*HOOKFIRECLIENT(urgent, self)XXX*/;
}
}
@ -1242,7 +1218,7 @@ static void client_showhide(Client *self)
else
engine_frame_hide(self->frame);
HOOKFIRECLIENT(visible, self);
/*HOOKFIRECLIENT(visible, self);XXX*/
}
gboolean client_normal(Client *self) {
@ -1267,7 +1243,7 @@ static void client_apply_startup_state(Client *self)
client_shade(self, TRUE);
}
if (self->urgent)
HOOKFIRECLIENT(urgent, self);
/*HOOKFIRECLIENT(urgent, self)XXX*/;
if (self->max_vert && self->max_horz) {
self->max_vert = self->max_horz = FALSE;

View file

@ -6,7 +6,6 @@
#include <glib.h>
#include <X11/Xlib.h>
struct ClientWrap;
struct Frame;
@ -279,9 +278,6 @@ typedef struct Client {
Pixmap pixmap_icon;
/*! The mask for the pixmap_icon, or None if its not masked */
Pixmap pixmap_icon_mask;
/* The instance of the wrapper class if one exists */
struct ClientWrap *wrap;
} Client;
extern GSList *client_list;

151
openbox/dispatch.c Normal file
View file

@ -0,0 +1,151 @@
#include "dispatch.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]);
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)
{
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:
return;
}
obe.type = e;
obe.data.x = xe;
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);
}

58
openbox/dispatch.h Normal file
View file

@ -0,0 +1,58 @@
#ifndef __dispatch_h
#define __dispatch_h
#include "client.h"
#include <X11/Xlib.h>
void dispatch_startup();
void dispatch_shutdown();
typedef enum {
Event_X_EnterNotify = 1 << 0,
Event_X_LeaveNotify = 1 << 1,
Event_X_KeyPress = 1 << 2,
Event_X_KeyRelease = 1 << 3,
Event_X_ButtonPress = 1 << 4,
Event_X_ButtonRelease = 1 << 5,
Event_X_MotionNotify = 1 << 6,
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_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_Signal = 1 << 17,
EVENT_RANGE = 1 << 18
} EventType;
typedef union {
XEvent *x; /* for Event_X_* event types */
Client *client; /* for Event_Client_* event types */
int signal;
} EventData;
typedef struct {
EventType type;
EventData data;
} ObEvent;
typedef void (*EventHandler)(const ObEvent *e);
typedef unsigned int EventMask;
void dispatch_register(EventHandler h, EventMask mask);
void dispatch_x(XEvent *e);
void dispatch_client(EventType e, Client *c);
void dispatch_ob(EventType e);
void dispatch_signal(int signal);
#endif

View file

@ -7,9 +7,6 @@
#include "engine.h"
#include "focus.h"
#include "stacking.h"
#include "keyboard.h"
#include "pointer.h"
#include "hooks.h"
#include "extensions.h"
#include "timer.h"
#include "engine.h"
@ -286,37 +283,37 @@ void event_process(XEvent *e)
switch(e->type) {
case EnterNotify:
if (client != NULL) engine_mouse_enter(client->frame, window);
HOOKFIRECLIENT(pointerenter, client);
/*HOOKFIRECLIENT(pointerenter, client);XXX*/
break;
case LeaveNotify:
if (client != NULL) engine_mouse_leave(client->frame, window);
HOOKFIRECLIENT(pointerleave, client);
/*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);
/*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);
/*pointer_event(e, client);XXX*/
break;
case MotionNotify:
pointer_event(e, client);
/*pointer_event(e, client);XXX*/
break;
case KeyPress:
case KeyRelease:
keyboard_event(&e->xkey);
/*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);
/*HOOKFIRECLIENT(bell, client);XXX*/
break;
}
}
@ -494,7 +491,7 @@ static void event_handle_client(Client *client, XEvent *e)
/* we shouldn't be able to get this unless we're iconic */
g_assert(client->iconic);
HOOKFIRECLIENT(requestactivate, client);
/*HOOKFIRECLIENT(requestactivate, client);XXX*/
break;
case ClientMessage:
/* validate cuz we query stuff off the client here */
@ -554,7 +551,7 @@ static void event_handle_client(Client *client, XEvent *e)
/* if its not visible for other reasons, then don't mess
with it */
return;
HOOKFIRECLIENT(requestactivate, client);
/*HOOKFIRECLIENT(requestactivate, client);XXX*/
}
break;
case PropertyNotify:

View file

@ -2,7 +2,6 @@
#include "client.h"
#include "screen.h"
#include "prop.h"
#include "hooks.h"
#include <X11/Xlib.h>
@ -53,5 +52,5 @@ void focus_set_client(Client *client)
active = client ? client->window : None;
PROP_SET32(ob_root, net_active_window, window, active);
HOOKFIRECLIENT(focused, client);
/*HOOKFIRECLIENT(focused, client);XXX*/
}

View file

@ -1,20 +1,14 @@
#include "openbox.h"
#include "event.h"
#include "client.h"
#include "dispatch.h"
#include "xerror.h"
#include "prop.h"
#include "screen.h"
#include "focus.h"
#include "extensions.h"
#include "gettext.h"
#include "keyboard.h"
#include "pointer.h"
#include "engine.h"
#include "python.h"
#include "hooks.h"
#include "clientwrap.h"
#include "openboxwrap.h"
#include "configwrap.h"
#include "themerc.h"
#include "timer.h"
#include "../render/render.h"
@ -130,27 +124,17 @@ int main(int argc, char **argv)
if (screen_annex()) { /* it will be ours! */
timer_startup();
dispatch_startup();
render_startup();
font_startup();
themerc_startup();
engine_startup(themerc_engine);
python_startup();
configwrap_startup();
openboxwrap_startup();
clientwrap_startup();
hooks_startup();
event_startup();
screen_startup();
focus_startup();
client_startup();
keyboard_startup();
pointer_startup();
/* load the user's settings */
if (!python_import("rc"))
g_warning("ERROR LOADING RC FILE");
HOOKFIRE(startup, "()");
/*HOOKFIRE(startup, "()");XXX*/
/* get all the existing windows */
client_manage_all();
@ -163,21 +147,15 @@ int main(int argc, char **argv)
client_unmanage_all();
HOOKFIRE(shutdown, "()");
/*HOOKFIRE(shutdown, "()");XXX*/
pointer_shutdown();
keyboard_shutdown();
client_shutdown();
screen_shutdown();
event_shutdown();
hooks_shutdown();
clientwrap_shutdown();
openboxwrap_shutdown();
configwrap_shutdown();
python_shutdown();
engine_shutdown();
themerc_shutdown();
render_shutdown();
dispatch_shutdown();
timer_shutdown();
}