]> Dogcows Code - chaz/openbox/commitdiff
add a keyboard plugin
authorDana Jansens <danakj@orodu.net>
Tue, 18 Mar 2003 05:29:01 +0000 (05:29 +0000)
committerDana Jansens <danakj@orodu.net>
Tue, 18 Mar 2003 05:29:01 +0000 (05:29 +0000)
13 files changed:
configure.ac
openbox/client.c
openbox/client.h
openbox/dispatch.c
openbox/dispatch.h
openbox/engine.c
openbox/focus.c
openbox/openbox.c
openbox/plugin.c
openbox/screen.c
plugins/Makefile.am
plugins/keyboard/Makefile.am [new file with mode: 0644]
plugins/keyboard/keyboard.c [new file with mode: 0644]

index 6754fcb4fce1afa87f6105785d72c2569ad567b4..e4cb6abcee39e452944b3c7f25a808535c221912 100644 (file)
@@ -62,6 +62,7 @@ AC_CONFIG_FILES([Makefile po/Makefile.in
                engines/Makefile
                engines/openbox/Makefile
                plugins/Makefile
+               plugins/keyboard/Makefile
                doc/Makefile
                doc/doxygen/Makefile
                data/Makefile
index 4537f856f4345c3b0ad1aac8e440a4b623b4a40e..b9cebb79f1c4eef04c0ac08d670518182e5f520c 100644 (file)
@@ -195,11 +195,11 @@ void client_manage(Window window)
 
     screen_update_struts();
 
-    dispatch_client(Event_Client_New, client);
+    dispatch_client(Event_Client_New, client, 0, 0);
 
     client_showhide(client);
 
-    dispatch_client(Event_Client_Mapped, client);
+    dispatch_client(Event_Client_Mapped, client, 0, 0);
 
     /* grab all mouse bindings */
     /*pointer_grab_all(client, TRUE);XXX*/
@@ -223,7 +223,7 @@ void client_unmanage(Client *client)
 
     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 */
     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
           after we're mapped */
        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);
     else
         engine_frame_hide(self->frame);
-
-    dispatch_client(Event_Client_Visible, self);
 }
 
 gboolean client_normal(Client *self) {
@@ -1246,7 +1244,7 @@ static void client_apply_startup_state(Client *self)
        client_shade(self, TRUE);
     }
     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) {
        self->max_vert = self->max_horz = FALSE;
@@ -1626,8 +1624,10 @@ void client_close(Client *self)
     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;
   
     g_message("Setting desktop %u\n", target);
@@ -1636,6 +1636,7 @@ void client_set_desktop(Client *self, unsigned int target)
          target == DESKTOP_ALL))
        return;
 
+    old = self->desktop;
     self->desktop = target;
     PROP_SET32(self->window, net_wm_desktop, cardinal, target);
     /* 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 */
     client_showhide(self);
     screen_update_struts();
+
+    dispatch_client(Event_Client_Desktop, self, target, old);
 }
 
 static Client *search_modal_tree(Client *node, Client *skip)
index 442e7107b84431fb67ac9f9552542371ef27e0d7..e575a35aa016ef72fd3619146206058336648ba9 100644 (file)
@@ -372,7 +372,7 @@ void client_shade(Client *self, gboolean shade);
 void client_close(Client *self);
 
 /*! 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, or 0 if none was found.
index 7b71369d226d6200f9699bd4624165e27cc15d84..6ee211fd37d660e02ff3c7be3cdb9343f437165e 100644 (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;
     GSList *it;
@@ -152,7 +152,9 @@ void dispatch_client(EventType e, Client *c)
     g_assert(c != NULL);
 
     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;
     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;
     GSList *it;
     ObEvent obe;
 
     obe.type = e;
+    obe.data.o.num[0] = num0;
+    obe.data.o.num[1] = num1;
 
     i = 0;
     while (e > 1) {
@@ -194,7 +198,7 @@ void dispatch_signal(int signal)
     ObEvent obe;
 
     obe.type = e;
-    obe.data.signal = signal;
+    obe.data.s.signal = signal;
 
     i = 0;
     while (e > 1) {
index 396558db121e9ae92c202706e6b74d397c374249..5fa22e0c5d50dde72f89c61a048c28fd905d6bba 100644 (file)
@@ -23,16 +23,15 @@ typedef enum {
     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_Client_Desktop  = 1 << 15, /* moved to a new desktop */
 
-    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_Desktop      = 1 << 16, /* changed desktops */
+    Event_Ob_NumDesktops  = 1 << 17, /* changed the number of desktops */
+    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;
 
 typedef struct {
@@ -40,10 +39,31 @@ typedef struct {
     Client *client;
 } EventData_X;
 
-typedef union {
-    EventData_X x; /* for Event_X_* event types */
-    Client *client; /* for Event_Client_* event types */
+typedef struct {
+    Client *client;
+    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;
+} 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;
 
 typedef struct {
@@ -58,8 +78,8 @@ typedef unsigned int EventMask;
 void dispatch_register(EventMask mask, EventHandler h, void *data);
 
 void dispatch_x(XEvent *e, Client *c);
-void dispatch_client(EventType e, Client *c);
-void dispatch_ob(EventType e);
+void dispatch_client(EventType e, Client *c, int num0, int num1);
+void dispatch_ob(EventType e, int num0, int num1);
 void dispatch_signal(int signal);
 
 #endif
index 3457da1838bd9c9f8e35ae0a5f7b4fb9fbfdd353..b1873abc9ba939307558a930e920320a11d813c1 100644 (file)
@@ -23,13 +23,13 @@ static gboolean load(char *name)
     g_assert(module == 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);
 
     if (module == NULL) {
        path = g_build_filename(g_get_home_dir(), ".openbox", "engines", name,
                                NULL);
-       module = g_module_open(path, G_MODULE_BIND_LAZY);
+       module = g_module_open(path, 0);
        g_free(path);
     }
 
index db78183d8046b62d7b22eb43bc186255883e7e18..0674c8ff0e5c0a0b95705bb5d4060c72ddf18a23 100644 (file)
@@ -48,7 +48,7 @@ void focus_set_client(Client *client)
     }
 
     if (focus_client != NULL)
-        dispatch_client(Event_Client_Unfocus, focus_client);
+        dispatch_client(Event_Client_Unfocus, focus_client, 0, 0);
 
     focus_client = client;
 
@@ -57,5 +57,5 @@ void focus_set_client(Client *client)
     PROP_SET32(ob_root, net_active_window, window, active);
 
     if (focus_client != NULL)
-        dispatch_client(Event_Client_Focus, focus_client);
+        dispatch_client(Event_Client_Focus, focus_client, 0, 0);
 }
index b10659297e48d616b474728154bfe73813b9ec5a..5c1e017828138b67a2bb6ac424447fcd3034143a 100644 (file)
@@ -140,7 +140,7 @@ int main(int argc, char **argv)
         plugin_startup();
 
         /* XXX load all plugins!! */
-        plugin_open("foo");
+        plugin_open("focus");
 
        /* get all the existing windows */
        client_manage_all();
@@ -174,7 +174,10 @@ int main(int argc, char **argv)
 
 void signal_handler(const ObEvent *e, void *data)
 {
-    switch (e->data.signal) {
+    int s;
+
+    s = e->data.s.signal;
+    switch (s) {
     case SIGUSR1:
        g_message("Caught SIGUSR1 signal. Restarting.");
        ob_shutdown = ob_restart = TRUE;
@@ -188,12 +191,12 @@ void signal_handler(const ObEvent *e, void *data)
     case SIGINT:
     case SIGTERM:
     case SIGPIPE:
-       g_message("Caught signal %d. Exiting.", e->data.signal);
+       g_message("Caught signal %d. Exiting.", s);
        ob_shutdown = TRUE;
        break;
 
     case SIGFPE:
     case SIGSEGV:
-       g_error("Caught signal %d. Aborting and dumping core.",e->data.signal);
+       g_error("Caught signal %d. Aborting and dumping core.", s);
     }
 }
index d4c19b12081d529059b8aa390418cb7a0fdca95b..247d490a5faa03fe5b1c090f8cc6a6f33a2aae52 100644 (file)
@@ -14,9 +14,12 @@ typedef struct {
 
 static gpointer load_sym(GModule *module, char *name, char *symbol)
 {
-    gpointer var = NULL;
-    if (!g_module_symbol(module, symbol, &var))
-        g_warning("Failed to load symbol '%s' from plugin '%s'", symbol, name);
+    gpointer var;
+    if (!g_module_symbol(module, symbol, &var)) {
+        g_warning("Failed to load symbol '%s' from plugin '%s'",
+                  symbol, name);
+        var = NULL;
+    }
     return var;
 }
 
@@ -28,13 +31,13 @@ static Plugin *plugin_new(char *name)
     p = g_new(Plugin, 1);
 
     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);
 
     if (p->module == NULL) {
        path = g_build_filename(g_get_home_dir(), ".openbox", "plugins", name,
                                NULL);
-       p->module = g_module_open(path, G_MODULE_BIND_LAZY);
+       p->module = g_module_open(path, 0);
        g_free(path);
     }
 
@@ -43,8 +46,8 @@ static Plugin *plugin_new(char *name)
         return NULL;
     }
 
-    p->startup = load_sym(p->module, name, "startup");
-    p->shutdown = load_sym(p->module, name, "shutdown");
+    p->startup = load_sym(p->module, name, "plugin_startup");
+    p->shutdown = load_sym(p->module, name, "plugin_shutdown");
 
     if (p->startup == NULL || p->shutdown == NULL) {
         g_module_close(p->module);
index f82275c0a66738e43c7eacafa39cb44d0756d8ab..8f60029ab05211db078eedb8aba896da9a1b9e47 100644 (file)
@@ -195,7 +195,8 @@ void screen_resize()
 
 void screen_set_num_desktops(guint num)
 {
-    unsigned long *viewport;
+    guint old;
+    gulong *viewport;
      
     g_assert(num > 0);
   
@@ -218,11 +219,12 @@ void screen_set_num_desktops(guint num)
        }
     */
 
+    old = screen_num_desktops;
     screen_num_desktops = num;
     PROP_SET32(ob_root, net_number_of_desktops, cardinal, num);
 
     /* 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);
     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 */
     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! */
     if (screen_desktop >= screen_num_desktops)
@@ -245,13 +247,13 @@ void screen_set_num_desktops(guint num)
 void screen_set_desktop(guint num)
 {
     GList *it;
-
-    guint old = screen_desktop;
+    guint old;
      
     g_assert(num < screen_num_desktops);
 
     g_message("Moving to desktop %u", num);
   
+    old = screen_desktop;
     screen_desktop = 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);
     }
 
-    dispatch_ob(Event_Ob_Desktop);
+    dispatch_ob(Event_Ob_Desktop, num, old);
 }
 
 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);
 
-    dispatch_ob(Event_Ob_ShowDesktop);
+    dispatch_ob(Event_Ob_ShowDesktop, show, 0);
 }
 
 void screen_install_colormap(Client *client, gboolean install)
index 78ff2ccf11986b65002dc34b5cbada256a769e3d..42d005b39acbfb065c94f839b2257c1652ac78a6 100644 (file)
@@ -1,5 +1,7 @@
 plugindir=$(libdir)/openbox/plugins
 
+SUBDIRS = keyboard
+
 CPPFLAGS=$(XFT_CFLAGS) $(GLIB_CFLAGS) @CPPFLAGS@ \
 -DPLUGINDIR=\"$(plugindir)\" \
 -DG_LOG_DOMAIN=\"Openbox-Plugin\"
diff --git a/plugins/keyboard/Makefile.am b/plugins/keyboard/Makefile.am
new file mode 100644 (file)
index 0000000..78ff2cc
--- /dev/null
@@ -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 .\#*
diff --git a/plugins/keyboard/keyboard.c b/plugins/keyboard/keyboard.c
new file mode 100644 (file)
index 0000000..3e62184
--- /dev/null
@@ -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);
+}
+
This page took 0.042351 seconds and 4 git commands to generate.