Merge branch 'backport' into 3.4-working
[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     gboolean activate;
9 } Options;
10
11 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
12 static gpointer setup_activate_func(ObParseInst *i,
13                                     xmlDocPtr doc, xmlNodePtr node);
14 static void     free_func(gpointer options);
15 static gboolean run_func(ObActionsData *data, gpointer options);
16
17 void action_focus_startup(void)
18 {
19     actions_register("Focus",
20                      setup_func,
21                      free_func,
22                      run_func,
23                      NULL, NULL);
24     actions_register("Activate",
25                      setup_activate_func,
26                      free_func,
27                      run_func,
28                      NULL, NULL);
29 }
30
31 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
32 {
33     xmlNodePtr n;
34     Options *o;
35
36     o = g_new0(Options, 1);
37
38     if ((n = parse_find_node("here", node)))
39         o->here = parse_bool(doc, n);
40     return o;
41 }
42
43 static gpointer setup_activate_func(ObParseInst *i,
44                                     xmlDocPtr doc, xmlNodePtr node)
45 {
46     Options *o = setup_func(i, doc, node);
47     o->activate = TRUE;
48     return o;
49 }
50
51 static void free_func(gpointer options)
52 {
53     Options *o = options;
54
55     g_free(o);
56 }
57
58 /* Always return FALSE because its not interactive */
59 static gboolean run_func(ObActionsData *data, gpointer options)
60 {
61     Options *o = options;
62
63     if (data->client) {
64 /*
65         ob_debug("button %d focusable %d context %d %d %d\n",
66                  data->button, client_mouse_focusable(data->client),
67                  data->context,
68                  OB_FRAME_CONTEXT_CLIENT, OB_FRAME_CONTEXT_FRAME);
69 */
70         if (data->button == 0 || client_mouse_focusable(data->client) ||
71             (data->context != OB_FRAME_CONTEXT_CLIENT &&
72              data->context != OB_FRAME_CONTEXT_FRAME))
73         {
74             actions_client_move(data, TRUE);
75             client_activate(data->client, o->here,
76                             o->activate, o->activate, TRUE);
77             actions_client_move(data, FALSE);
78         }
79     } else if (data->context == OB_FRAME_CONTEXT_DESKTOP) {
80         /* focus action on the root window. make keybindings work for this
81            openbox instance, but don't focus any specific client */
82         focus_nothing();
83     }
84
85     return FALSE;
86 }