add directionaldesktop action
[mikachu/openbox.git] / openbox / actions / directionaltargetwindow.c
1 #include "openbox/actions.h"
2 #include "openbox/event.h"
3 #include "openbox/focus_cycle.h"
4 #include "openbox/openbox.h"
5 #include "openbox/misc.h"
6 #include "gettext.h"
7
8 typedef struct {
9     gboolean dialog;
10     gboolean dock_windows;
11     gboolean desktop_windows;
12     ObDirection direction;
13     GSList *actions;
14 } Options;
15
16 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
17 static void     free_func(gpointer options);
18 static gboolean run_func(ObActionsData *data, gpointer options);
19
20 void action_directionaltargetwindow_startup()
21 {
22     actions_register("DirectionalTargetWindow",
23                      setup_func,
24                      free_func,
25                      run_func,
26                      NULL, NULL);
27 }
28
29 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
30 {
31     xmlNodePtr n;
32     Options *o;
33
34     o = g_new0(Options, 1);
35     o->dialog = TRUE;
36
37     if ((n = parse_find_node("dialog", node)))
38         o->dialog = parse_bool(doc, n);
39     if ((n = parse_find_node("panels", node)))
40         o->dock_windows = parse_bool(doc, n);
41     if ((n = parse_find_node("desktop", node)))
42         o->desktop_windows = parse_bool(doc, n);
43     if ((n = parse_find_node("direction", node))) {
44         gchar *s = parse_string(doc, n);
45         if (!g_ascii_strcasecmp(s, "north") ||
46             !g_ascii_strcasecmp(s, "up"))
47             o->direction = OB_DIRECTION_NORTH;
48         else if (!g_ascii_strcasecmp(s, "northwest"))
49             o->direction = OB_DIRECTION_NORTHWEST;
50         else if (!g_ascii_strcasecmp(s, "northeast"))
51             o->direction = OB_DIRECTION_NORTHEAST;
52         else if (!g_ascii_strcasecmp(s, "west") ||
53                  !g_ascii_strcasecmp(s, "left"))
54             o->direction = OB_DIRECTION_WEST;
55         else if (!g_ascii_strcasecmp(s, "east") ||
56                  !g_ascii_strcasecmp(s, "right"))
57             o->direction = OB_DIRECTION_EAST;
58         else if (!g_ascii_strcasecmp(s, "south") ||
59                  !g_ascii_strcasecmp(s, "down"))
60             o->direction = OB_DIRECTION_NORTH;
61         else if (!g_ascii_strcasecmp(s, "southwest"))
62             o->direction = OB_DIRECTION_NORTHWEST;
63         else if (!g_ascii_strcasecmp(s, "southeast"))
64             o->direction = OB_DIRECTION_NORTHEAST;
65         g_free(s);
66     }
67
68     if ((n = parse_find_node("actions", node))) {
69         xmlNodePtr m;
70
71         m = parse_find_node("action", n->xmlChildrenNode);
72         while (m) {
73             ObActionsAct *action = actions_parse(i, doc, m);
74             if (action) o->actions = g_slist_prepend(o->actions, action);
75             m = parse_find_node("action", m->next);
76         }
77     }
78     return o;
79 }
80
81 static void free_func(gpointer options)
82 {
83     Options *o = options;
84
85     g_free(o);
86 }
87
88 static gboolean run_func(ObActionsData *data, gpointer options)
89 {
90     Options *o = options;
91     struct _ObClient *ft;
92
93     /* if using focus_delay, stop the timer now so that focus doesn't go moving
94        on us */
95     event_halt_focus_delay();
96     
97     ft = focus_directional_cycle(o->direction,
98                                  o->dock_windows,
99                                  o->desktop_windows,
100                                  FALSE,
101                                  o->dialog,
102                                  TRUE, FALSE);
103
104     if (ft)
105         actions_run_acts(o->actions, data->uact, data->state,
106                          data->x, data->y, data->button, data->context, ft);
107
108     return FALSE;
109 }