1 #include "openbox/actions.h"
2 #include "openbox/client.h"
3 #include "openbox/window.h"
4 #include "obt/display.h"
6 #include "openbox/openbox.h"
13 static gpointer setup_sendkey_func(xmlNodePtr node);
14 static void free_sendkey_func(gpointer options);
15 static gboolean sendkey(ObActionsData *data, gpointer options);
16 static gboolean settarget(ObActionsData *data, gpointer options);
20 void action_sendkeyevent_startup(void)
22 actions_register("SendKeyEvent",
23 setup_sendkey_func, g_free,
26 actions_register("SetKeyTarget",
30 OBT_PROP_GET32(obt_root(ob_screen), OB_TARGET_WINDOW, WINDOW, (guint32 *)&target);
33 static KeyCode parse_key(gchar *s)
37 sym = XStringToKeysym(s);
38 if (sym == NoSymbol) {
39 g_warning(_("Invalid key name '%s' in SendKeyEvent action."), s);
43 return XKeysymToKeycode(obt_display, sym);
46 static gpointer setup_sendkey_func(xmlNodePtr node)
51 o = g_new0(Options, 1);
53 if ((n = obt_parse_find_node(node, "key"))) {
54 gchar *s = obt_parse_node_string(n);
55 o->key = parse_key(s);
58 o->key = parse_key("space");
63 /* Always return FALSE because its not interactive */
64 static gboolean sendkey(ObActionsData *data, gpointer options)
69 if (!o->key) /* the key couldn't be parsed */
72 ev.xkey.window = target;
74 ev.xkey.keycode = o->key;
75 obt_display_ignore_errors(TRUE);
77 XSendEvent(obt_display, target, False, 0, &ev);
79 XSendEvent(obt_display, target, False, 0, &ev);
80 obt_display_ignore_errors(FALSE);
85 /* Always return FALSE because its not interactive */
86 static gboolean settarget(ObActionsData *data, gpointer options)
89 target = data->client->window;
90 OBT_PROP_SET32(obt_root(ob_screen), OB_TARGET_WINDOW, WINDOW, target);