Merge branch 'backport' into work
[mikachu/openbox.git] / openbox / actions / focus.c
1 #include "openbox/actions.h"
2 #include "openbox/event.h"
3 #include "openbox/client.h"
4 #include "openbox/focus.h"
5
6 typedef struct {
7     gboolean here;
8 } Options;
9
10 static gpointer setup_func(xmlNodePtr node);
11 static gboolean run_func(ObActionsData *data, gpointer options);
12
13 void action_focus_startup(void)
14 {
15     actions_register("Focus", setup_func, g_free, run_func, NULL, NULL);
16 }
17
18 static gpointer setup_func(xmlNodePtr node)
19 {
20     xmlNodePtr n;
21     Options *o;
22
23     o = g_new0(Options, 1);
24
25     if ((n = obt_parse_find_node(node, "here")))
26         o->here = obt_parse_node_bool(n);
27     return o;
28 }
29
30 /* Always return FALSE because its not interactive */
31 static gboolean run_func(ObActionsData *data, gpointer options)
32 {
33     Options *o = options;
34
35     if (data->client) {
36 /*
37         ob_debug("button %d focusable %d context %d %d %d\n",
38                  data->button, client_mouse_focusable(data->client),
39                  data->context,
40                  OB_FRAME_CONTEXT_CLIENT, OB_FRAME_CONTEXT_FRAME);
41 */
42         if (data->button == 0 || client_mouse_focusable(data->client) ||
43             (data->context != OB_FRAME_CONTEXT_CLIENT &&
44              data->context != OB_FRAME_CONTEXT_FRAME))
45         {
46             client_activate(data->client, o->here, FALSE, FALSE, TRUE);
47         }
48     } else if (data->context == OB_FRAME_CONTEXT_DESKTOP) {
49         /* focus action on the root window. make keybindings work for this
50            openbox instance, but don't focus any specific client */
51         focus_nothing();
52     }
53
54     return FALSE;
55 }