add a keyboard plugin

This commit is contained in:
Dana Jansens 2003-03-18 05:29:01 +00:00
parent 9185ca5c1a
commit bfea000a74
13 changed files with 121 additions and 48 deletions

View file

@ -62,6 +62,7 @@ AC_CONFIG_FILES([Makefile po/Makefile.in
engines/Makefile engines/Makefile
engines/openbox/Makefile engines/openbox/Makefile
plugins/Makefile plugins/Makefile
plugins/keyboard/Makefile
doc/Makefile doc/Makefile
doc/doxygen/Makefile doc/doxygen/Makefile
data/Makefile data/Makefile

View file

@ -195,11 +195,11 @@ void client_manage(Window window)
screen_update_struts(); screen_update_struts();
dispatch_client(Event_Client_New, client); dispatch_client(Event_Client_New, client, 0, 0);
client_showhide(client); client_showhide(client);
dispatch_client(Event_Client_Mapped, client); dispatch_client(Event_Client_Mapped, client, 0, 0);
/* grab all mouse bindings */ /* grab all mouse bindings */
/*pointer_grab_all(client, TRUE);XXX*/ /*pointer_grab_all(client, TRUE);XXX*/
@ -223,7 +223,7 @@ void client_unmanage(Client *client)
g_message("Unmanaging window: %lx", client->window); g_message("Unmanaging window: %lx", client->window);
dispatch_client(Event_Client_Destroy, client); dispatch_client(Event_Client_Destroy, client, 0, 0);
/* remove the window from our save set */ /* remove the window from our save set */
XChangeSaveSet(ob_display, client->window, SetModeDelete); XChangeSaveSet(ob_display, client->window, SetModeDelete);
@ -926,7 +926,7 @@ void client_update_wmhints(Client *self)
/* fire the urgent callback if we're mapped, otherwise, wait until /* fire the urgent callback if we're mapped, otherwise, wait until
after we're mapped */ after we're mapped */
if (self->frame) if (self->frame)
dispatch_client(Event_Client_Urgent, self); dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
} }
} }
@ -1220,8 +1220,6 @@ static void client_showhide(Client *self)
engine_frame_show(self->frame); engine_frame_show(self->frame);
else else
engine_frame_hide(self->frame); engine_frame_hide(self->frame);
dispatch_client(Event_Client_Visible, self);
} }
gboolean client_normal(Client *self) { gboolean client_normal(Client *self) {
@ -1246,7 +1244,7 @@ static void client_apply_startup_state(Client *self)
client_shade(self, TRUE); client_shade(self, TRUE);
} }
if (self->urgent) if (self->urgent)
dispatch_client(Event_Client_Urgent, self); dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
if (self->max_vert && self->max_horz) { if (self->max_vert && self->max_horz) {
self->max_vert = self->max_horz = FALSE; self->max_vert = self->max_horz = FALSE;
@ -1626,8 +1624,10 @@ void client_close(Client *self)
XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce); XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
} }
void client_set_desktop(Client *self, unsigned int target) void client_set_desktop(Client *self, guint target)
{ {
guint old;
if (target == self->desktop) return; if (target == self->desktop) return;
g_message("Setting desktop %u\n", target); g_message("Setting desktop %u\n", target);
@ -1636,6 +1636,7 @@ void client_set_desktop(Client *self, unsigned int target)
target == DESKTOP_ALL)) target == DESKTOP_ALL))
return; return;
old = self->desktop;
self->desktop = target; self->desktop = target;
PROP_SET32(self->window, net_wm_desktop, cardinal, target); PROP_SET32(self->window, net_wm_desktop, cardinal, target);
/* the frame can display the current desktop state */ /* the frame can display the current desktop state */
@ -1643,6 +1644,8 @@ void client_set_desktop(Client *self, unsigned int target)
/* 'move' the window to the new desktop */ /* 'move' the window to the new desktop */
client_showhide(self); client_showhide(self);
screen_update_struts(); screen_update_struts();
dispatch_client(Event_Client_Desktop, self, target, old);
} }
static Client *search_modal_tree(Client *node, Client *skip) static Client *search_modal_tree(Client *node, Client *skip)

View file

@ -372,7 +372,7 @@ void client_shade(Client *self, gboolean shade);
void client_close(Client *self); void client_close(Client *self);
/*! Sends the window to the specified desktop */ /*! Sends the window to the specified desktop */
void client_set_desktop(Client *self, unsigned int target); void client_set_desktop(Client *self, guint target);
/*! Return a modal child of the client window /*! Return a modal child of the client window
@return A modal child of the client window, or 0 if none was found. @return A modal child of the client window, or 0 if none was found.

View file

@ -143,7 +143,7 @@ void dispatch_x(XEvent *xe, Client *c)
} }
} }
void dispatch_client(EventType e, Client *c) void dispatch_client(EventType e, Client *c, int num0, int num1)
{ {
guint i; guint i;
GSList *it; GSList *it;
@ -152,7 +152,9 @@ void dispatch_client(EventType e, Client *c)
g_assert(c != NULL); g_assert(c != NULL);
obe.type = e; obe.type = e;
obe.data.client = c; obe.data.c.client = c;
obe.data.c.num[0] = num0;
obe.data.c.num[1] = num1;
i = 0; i = 0;
while (e > 1) { while (e > 1) {
@ -166,13 +168,15 @@ void dispatch_client(EventType e, Client *c)
} }
} }
void dispatch_ob(EventType e) void dispatch_ob(EventType e, int num0, int num1)
{ {
guint i; guint i;
GSList *it; GSList *it;
ObEvent obe; ObEvent obe;
obe.type = e; obe.type = e;
obe.data.o.num[0] = num0;
obe.data.o.num[1] = num1;
i = 0; i = 0;
while (e > 1) { while (e > 1) {
@ -194,7 +198,7 @@ void dispatch_signal(int signal)
ObEvent obe; ObEvent obe;
obe.type = e; obe.type = e;
obe.data.signal = signal; obe.data.s.signal = signal;
i = 0; i = 0;
while (e > 1) { while (e > 1) {

View file

@ -23,16 +23,15 @@ typedef enum {
Event_Client_Focus = 1 << 11, /* focused */ Event_Client_Focus = 1 << 11, /* focused */
Event_Client_Unfocus = 1 << 12, /* unfocused */ Event_Client_Unfocus = 1 << 12, /* unfocused */
Event_Client_Urgent = 1 << 13, /* entered/left urgent state */ Event_Client_Urgent = 1 << 13, /* entered/left urgent state */
Event_Client_Visible = 1 << 14, /* shown/hidden (not on a workspace or Event_Client_Desktop = 1 << 15, /* moved to a new desktop */
show-the-desktop change though) */
Event_Ob_Desktop = 1 << 15, /* changed desktops */ Event_Ob_Desktop = 1 << 16, /* changed desktops */
Event_Ob_NumDesktops = 1 << 16, /* changed the number of desktops */ Event_Ob_NumDesktops = 1 << 17, /* changed the number of desktops */
Event_Ob_ShowDesktop = 1 << 17, /* entered/left show-the-desktop mode */ Event_Ob_ShowDesktop = 1 << 18, /* entered/left show-the-desktop mode */
Event_Signal = 1 << 18, /* a signal from the OS */ Event_Signal = 1 << 19, /* a signal from the OS */
EVENT_RANGE = 1 << 19 EVENT_RANGE = 1 << 20
} EventType; } EventType;
typedef struct { typedef struct {
@ -40,10 +39,31 @@ typedef struct {
Client *client; Client *client;
} EventData_X; } EventData_X;
typedef union { typedef struct {
EventData_X x; /* for Event_X_* event types */ Client *client;
Client *client; /* for Event_Client_* event types */ int num[2];
/* Event_Client_Desktop: num[0] = new number, num[1] = old number
Event_Client_Urgent: num[0] = urgent state
*/
} 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; int signal;
} EventData_Signal;
typedef struct {
EventData_X x; /* for Event_X_* event types */
EventData_Client c; /* for Event_Client_* event types */
EventData_Ob o; /* for Event_Ob_* event types */
EventData_Signal s; /* for Event_Signal */
} EventData; } EventData;
typedef struct { typedef struct {
@ -58,8 +78,8 @@ typedef unsigned int EventMask;
void dispatch_register(EventMask mask, EventHandler h, void *data); void dispatch_register(EventMask mask, EventHandler h, void *data);
void dispatch_x(XEvent *e, Client *c); void dispatch_x(XEvent *e, Client *c);
void dispatch_client(EventType e, Client *c); void dispatch_client(EventType e, Client *c, int num0, int num1);
void dispatch_ob(EventType e); void dispatch_ob(EventType e, int num0, int num1);
void dispatch_signal(int signal); void dispatch_signal(int signal);
#endif #endif

View file

@ -23,13 +23,13 @@ static gboolean load(char *name)
g_assert(module == NULL); g_assert(module == NULL);
path = g_build_filename(ENGINEDIR, name, NULL); path = g_build_filename(ENGINEDIR, name, NULL);
module = g_module_open(path, G_MODULE_BIND_LAZY); module = g_module_open(path, 0);
g_free(path); g_free(path);
if (module == NULL) { if (module == NULL) {
path = g_build_filename(g_get_home_dir(), ".openbox", "engines", name, path = g_build_filename(g_get_home_dir(), ".openbox", "engines", name,
NULL); NULL);
module = g_module_open(path, G_MODULE_BIND_LAZY); module = g_module_open(path, 0);
g_free(path); g_free(path);
} }

View file

@ -48,7 +48,7 @@ void focus_set_client(Client *client)
} }
if (focus_client != NULL) if (focus_client != NULL)
dispatch_client(Event_Client_Unfocus, focus_client); dispatch_client(Event_Client_Unfocus, focus_client, 0, 0);
focus_client = client; focus_client = client;
@ -57,5 +57,5 @@ void focus_set_client(Client *client)
PROP_SET32(ob_root, net_active_window, window, active); PROP_SET32(ob_root, net_active_window, window, active);
if (focus_client != NULL) if (focus_client != NULL)
dispatch_client(Event_Client_Focus, focus_client); dispatch_client(Event_Client_Focus, focus_client, 0, 0);
} }

View file

@ -140,7 +140,7 @@ int main(int argc, char **argv)
plugin_startup(); plugin_startup();
/* XXX load all plugins!! */ /* XXX load all plugins!! */
plugin_open("foo"); plugin_open("focus");
/* get all the existing windows */ /* get all the existing windows */
client_manage_all(); client_manage_all();
@ -174,7 +174,10 @@ int main(int argc, char **argv)
void signal_handler(const ObEvent *e, void *data) void signal_handler(const ObEvent *e, void *data)
{ {
switch (e->data.signal) { int s;
s = e->data.s.signal;
switch (s) {
case SIGUSR1: case SIGUSR1:
g_message("Caught SIGUSR1 signal. Restarting."); g_message("Caught SIGUSR1 signal. Restarting.");
ob_shutdown = ob_restart = TRUE; ob_shutdown = ob_restart = TRUE;
@ -188,12 +191,12 @@ void signal_handler(const ObEvent *e, void *data)
case SIGINT: case SIGINT:
case SIGTERM: case SIGTERM:
case SIGPIPE: case SIGPIPE:
g_message("Caught signal %d. Exiting.", e->data.signal); g_message("Caught signal %d. Exiting.", s);
ob_shutdown = TRUE; ob_shutdown = TRUE;
break; break;
case SIGFPE: case SIGFPE:
case SIGSEGV: case SIGSEGV:
g_error("Caught signal %d. Aborting and dumping core.",e->data.signal); g_error("Caught signal %d. Aborting and dumping core.", s);
} }
} }

View file

@ -14,9 +14,12 @@ typedef struct {
static gpointer load_sym(GModule *module, char *name, char *symbol) static gpointer load_sym(GModule *module, char *name, char *symbol)
{ {
gpointer var = NULL; gpointer var;
if (!g_module_symbol(module, symbol, &var)) if (!g_module_symbol(module, symbol, &var)) {
g_warning("Failed to load symbol '%s' from plugin '%s'", symbol, name); g_warning("Failed to load symbol '%s' from plugin '%s'",
symbol, name);
var = NULL;
}
return var; return var;
} }
@ -28,13 +31,13 @@ static Plugin *plugin_new(char *name)
p = g_new(Plugin, 1); p = g_new(Plugin, 1);
path = g_build_filename(PLUGINDIR, name, NULL); path = g_build_filename(PLUGINDIR, name, NULL);
p->module = g_module_open(path, G_MODULE_BIND_LAZY); p->module = g_module_open(path, 0);
g_free(path); g_free(path);
if (p->module == NULL) { if (p->module == NULL) {
path = g_build_filename(g_get_home_dir(), ".openbox", "plugins", name, path = g_build_filename(g_get_home_dir(), ".openbox", "plugins", name,
NULL); NULL);
p->module = g_module_open(path, G_MODULE_BIND_LAZY); p->module = g_module_open(path, 0);
g_free(path); g_free(path);
} }
@ -43,8 +46,8 @@ static Plugin *plugin_new(char *name)
return NULL; return NULL;
} }
p->startup = load_sym(p->module, name, "startup"); p->startup = load_sym(p->module, name, "plugin_startup");
p->shutdown = load_sym(p->module, name, "shutdown"); p->shutdown = load_sym(p->module, name, "plugin_shutdown");
if (p->startup == NULL || p->shutdown == NULL) { if (p->startup == NULL || p->shutdown == NULL) {
g_module_close(p->module); g_module_close(p->module);

View file

@ -195,7 +195,8 @@ void screen_resize()
void screen_set_num_desktops(guint num) void screen_set_num_desktops(guint num)
{ {
unsigned long *viewport; guint old;
gulong *viewport;
g_assert(num > 0); g_assert(num > 0);
@ -218,11 +219,12 @@ void screen_set_num_desktops(guint num)
} }
*/ */
old = screen_num_desktops;
screen_num_desktops = num; screen_num_desktops = num;
PROP_SET32(ob_root, net_number_of_desktops, cardinal, num); PROP_SET32(ob_root, net_number_of_desktops, cardinal, num);
/* set the viewport hint */ /* set the viewport hint */
viewport = g_new0(unsigned long, num * 2); viewport = g_new0(gulong, num * 2);
PROP_SET32A(ob_root, net_desktop_viewport, cardinal, viewport, num * 2); PROP_SET32A(ob_root, net_desktop_viewport, cardinal, viewport, num * 2);
g_free(viewport); g_free(viewport);
@ -235,7 +237,7 @@ void screen_set_num_desktops(guint num)
/* may be some unnamed desktops that we need to fill in with names */ /* may be some unnamed desktops that we need to fill in with names */
screen_update_desktop_names(); screen_update_desktop_names();
dispatch_ob(Event_Ob_NumDesktops); dispatch_ob(Event_Ob_NumDesktops, num, old);
/* change our desktop if we're on one that no longer exists! */ /* change our desktop if we're on one that no longer exists! */
if (screen_desktop >= screen_num_desktops) if (screen_desktop >= screen_num_desktops)
@ -245,13 +247,13 @@ void screen_set_num_desktops(guint num)
void screen_set_desktop(guint num) void screen_set_desktop(guint num)
{ {
GList *it; GList *it;
guint old;
guint old = screen_desktop;
g_assert(num < screen_num_desktops); g_assert(num < screen_num_desktops);
g_message("Moving to desktop %u", num); g_message("Moving to desktop %u", num);
old = screen_desktop;
screen_desktop = num; screen_desktop = num;
PROP_SET32(ob_root, net_current_desktop, cardinal, num); PROP_SET32(ob_root, net_current_desktop, cardinal, num);
@ -271,7 +273,7 @@ void screen_set_desktop(guint num)
engine_frame_show(c->frame); engine_frame_show(c->frame);
} }
dispatch_ob(Event_Ob_Desktop); dispatch_ob(Event_Ob_Desktop, num, old);
} }
void screen_update_layout() void screen_update_layout()
@ -392,10 +394,10 @@ void screen_show_desktop(gboolean show)
} }
} }
show = show ? 1 : 0; /* make it boolean */ show = !!show; /* make it boolean */
PROP_SET32(ob_root, net_showing_desktop, cardinal, show); PROP_SET32(ob_root, net_showing_desktop, cardinal, show);
dispatch_ob(Event_Ob_ShowDesktop); dispatch_ob(Event_Ob_ShowDesktop, show, 0);
} }
void screen_install_colormap(Client *client, gboolean install) void screen_install_colormap(Client *client, gboolean install)

View file

@ -1,5 +1,7 @@
plugindir=$(libdir)/openbox/plugins plugindir=$(libdir)/openbox/plugins
SUBDIRS = keyboard
CPPFLAGS=$(XFT_CFLAGS) $(GLIB_CFLAGS) @CPPFLAGS@ \ CPPFLAGS=$(XFT_CFLAGS) $(GLIB_CFLAGS) @CPPFLAGS@ \
-DPLUGINDIR=\"$(plugindir)\" \ -DPLUGINDIR=\"$(plugindir)\" \
-DG_LOG_DOMAIN=\"Openbox-Plugin\" -DG_LOG_DOMAIN=\"Openbox-Plugin\"

View file

@ -0,0 +1,17 @@
plugindir=$(libdir)/openbox/plugins
CPPFLAGS=$(XFT_CFLAGS) $(GLIB_CFLAGS) @CPPFLAGS@ \
-DPLUGINDIR=\"$(plugindir)\" \
-DG_LOG_DOMAIN=\"Openbox-Plugin\"
plugin_LTLIBRARIES=focus.la
focus_la_LDFLAGS=-module -avoid-version
focus_la_SOURCES=focus.c
noinst_HEADERS=
MAINTAINERCLEANFILES= Makefile.in
distclean-local:
$(RM) *\~ *.orig *.rej .\#*

View file

@ -0,0 +1,18 @@
#include "../../kernel/dispatch.h"
static void press(ObEvent *e, void *foo)
{
}
void plugin_startup()
{
dispatch_register(Event_X_KeyPress, (EventHandler)press, NULL);
/* XXX parse config file! */
}
void plugin_shutdown()
{
dispatch_register(0, (EventHandler)press, NULL);
}