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"
14 static gpointer setup_sendkey_func(xmlNodePtr node);
15 static void free_sendkey_func(gpointer options);
16 static gboolean sendkey(ObActionsData *data, gpointer options);
17 static gboolean settarget(ObActionsData *data, gpointer options);
21 void action_sendkeyevent_startup(void)
23 actions_register("SendKeyEvent",
24 setup_sendkey_func, g_free,
27 actions_register("SetKeyTarget",
31 OBT_PROP_GET32(obt_root(ob_screen), OB_TARGET_WINDOW, WINDOW, (guint32 *)&target);
34 static KeyCode parse_key(gchar *s)
38 sym = XStringToKeysym(s);
39 if (sym == NoSymbol) {
40 g_warning(_("Invalid key name '%s' in SendKeyEvent action."), s);
44 return XKeysymToKeycode(obt_display, sym);
47 static gpointer setup_sendkey_func(xmlNodePtr node)
52 o = g_new0(Options, 1);
55 if ((n = obt_parse_find_node(node, "key"))) {
56 gchar *s = obt_parse_node_string(n);
57 o->key = parse_key(s);
60 o->key = parse_key("space");
61 if ((n = obt_parse_find_node(node, "usetarget")))
62 o->target = obt_parse_node_bool(n);
67 /* Always return FALSE because its not interactive */
68 static gboolean sendkey(ObActionsData *data, gpointer options)
74 if (!o->key) /* the key couldn't be parsed */
79 else if (data->client)
80 win = data->client->window;
86 ev.xkey.keycode = o->key;
87 obt_display_ignore_errors(TRUE);
89 XSendEvent(obt_display, win, False, 0, &ev);
91 XSendEvent(obt_display, win, False, 0, &ev);
92 obt_display_ignore_errors(FALSE);
97 /* Always return FALSE because its not interactive */
98 static gboolean settarget(ObActionsData *data, gpointer options)
101 target = data->client->window;
102 OBT_PROP_SET32(obt_root(ob_screen), OB_TARGET_WINDOW, WINDOW, target);