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