]> icculus.org git repositories - dana/openbox.git/blob - openbox/actions/focus.c
Rename ObActions* to ObAction* and remove more 3.4-compat action stuff that was missed.
[dana/openbox.git] / openbox / actions / focus.c
1 #include "openbox/action.h"
2 #include "openbox/action_value.h"
3 #include "openbox/event.h"
4 #include "openbox/client.h"
5 #include "openbox/focus.h"
6 #include "openbox/screen.h"
7
8 typedef struct {
9     gboolean here;
10     gboolean stop_int;
11 } Options;
12
13 static gpointer setup_func(GHashTable *config);
14 static void free_func(gpointer o);
15 static gboolean run_func(ObActionData *data, gpointer options);
16
17 void action_focus_startup(void)
18 {
19     action_register("Focus", setup_func, free_func, run_func);
20 }
21
22 static gpointer setup_func(GHashTable *config)
23 {
24     ObActionValue *v;
25     Options *o;
26
27     o = g_slice_new0(Options);
28     o->stop_int = TRUE;
29
30     v = g_hash_table_lookup(config, "here");
31     if (v && action_value_is_string(v))
32         o->here = action_value_bool(v);
33     v = g_hash_table_lookup(config, "stopInteractive");
34     if (v && action_value_is_string(v))
35         o->stop_int = action_value_bool(v);
36     return o;
37 }
38
39 static void free_func(gpointer o)
40 {
41     g_slice_free(Options, o);
42 }
43
44 /* Always return FALSE because its not interactive */
45 static gboolean run_func(ObActionData *data, gpointer options)
46 {
47     Options *o = options;
48
49     if (data->client) {
50 /*
51         ob_debug("button %d focusable %d context %d %d %d\n",
52                  data->button, client_mouse_focusable(data->client),
53                  data->context,
54                  OB_FRAME_CONTEXT_CLIENT, OB_FRAME_CONTEXT_FRAME);
55 */
56         if (data->button == 0 || client_mouse_focusable(data->client) ||
57             (data->context != OB_FRAME_CONTEXT_CLIENT &&
58              data->context != OB_FRAME_CONTEXT_FRAME))
59         {
60             if (o->stop_int)
61                 action_interactive_cancel_act();
62
63             action_client_move(data, TRUE);
64             client_activate(data->client, TRUE, o->here, FALSE, FALSE, TRUE);
65             action_client_move(data, FALSE);
66         }
67     } else if (data->context == OB_FRAME_CONTEXT_DESKTOP) {
68         if (o->stop_int)
69             action_interactive_cancel_act();
70
71         /* focus action on the root window. make keybindings work for this
72            openbox instance, but don't focus any specific client */
73         focus_nothing();
74     }
75
76     return FALSE;
77 }