Allow the SendKeyEvent action to send keys to the "usual" target, so you can use...
authorMikael Magnusson <mikachu@comhem.se>
Sun, 2 Mar 2008 01:37:43 +0000 (02:37 +0100)
committerMikael Magnusson <mikachu@comhem.se>
Sat, 8 Mar 2008 16:23:54 +0000 (17:23 +0100)
openbox/actions/sendkeyevent.c

index 129eb501505c8664c5211f22ab7ce82d5cd0f28d..2b3a6adf8365e204f4bb7c0f18e53431b402eeb8 100644 (file)
@@ -8,6 +8,7 @@
 
 typedef struct {
     KeyCode key;
+    gboolean target;
 } Options;
 
 static gpointer setup_sendkey_func(xmlNodePtr node);
@@ -49,6 +50,7 @@ static gpointer setup_sendkey_func(xmlNodePtr node)
     Options *o;
 
     o = g_new0(Options, 1);
+    o->target = TRUE;
 
     if ((n = obt_parse_find_node(node, "key"))) {
         gchar *s = obt_parse_node_string(n);
@@ -56,6 +58,8 @@ static gpointer setup_sendkey_func(xmlNodePtr node)
         g_free(s);
     } else
         o->key = parse_key("space");
+    if ((n = obt_parse_find_node(node, "usetarget")))
+        o->target = obt_parse_node_bool(n);
 
     return o;
 }
@@ -65,18 +69,26 @@ static gboolean sendkey(ObActionsData *data, gpointer options)
 {
     Options *o = options;
     XEvent ev;
+    Window win;
 
     if (!o->key) /* the key couldn't be parsed */
         return FALSE;
 
-    ev.xkey.window = target;
+    if (o->target)
+        win = target;
+    else if (data->client)
+        win = data->client->window;
+    else
+        return FALSE;
+
+    ev.xkey.window = win;
     ev.xkey.state = 0;
     ev.xkey.keycode = o->key;
     obt_display_ignore_errors(TRUE);
     ev.type = KeyPress;
-    XSendEvent(obt_display, target, False, 0, &ev);
+    XSendEvent(obt_display, win, False, 0, &ev);
     ev.type = KeyRelease;
-    XSendEvent(obt_display, target, False, 0, &ev);
+    XSendEvent(obt_display, win, False, 0, &ev);
     obt_display_ignore_errors(FALSE);
 
     return FALSE;