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