add the decorations action
[dana/openbox-history.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             o->direction = OB_DIRECTION_NORTH;
47         else if (!g_ascii_strcasecmp(s, "northwest"))
48             o->direction = OB_DIRECTION_NORTHWEST;
49         else if (!g_ascii_strcasecmp(s, "northeast"))
50             o->direction = OB_DIRECTION_NORTHEAST;
51         else if (!g_ascii_strcasecmp(s, "west"))
52             o->direction = OB_DIRECTION_WEST;
53         else if (!g_ascii_strcasecmp(s, "east"))
54             o->direction = OB_DIRECTION_EAST;
55         else if (!g_ascii_strcasecmp(s, "south"))
56             o->direction = OB_DIRECTION_NORTH;
57         else if (!g_ascii_strcasecmp(s, "southwest"))
58             o->direction = OB_DIRECTION_NORTHWEST;
59         else if (!g_ascii_strcasecmp(s, "southeast"))
60             o->direction = OB_DIRECTION_NORTHEAST;
61         g_free(s);
62     }
63
64     if ((n = parse_find_node("actions", node))) {
65         xmlNodePtr m;
66
67         m = parse_find_node("action", n->xmlChildrenNode);
68         while (m) {
69             ObActionsAct *action = actions_parse(i, doc, m);
70             if (action) o->actions = g_slist_prepend(o->actions, action);
71             m = parse_find_node("action", m->next);
72         }
73     }
74     return o;
75 }
76
77 static void free_func(gpointer options)
78 {
79     Options *o = options;
80
81     g_free(o);
82 }
83
84 static gboolean run_func(ObActionsData *data, gpointer options)
85 {
86     Options *o = options;
87     struct _ObClient *ft;
88
89     /* if using focus_delay, stop the timer now so that focus doesn't go moving
90        on us */
91     event_halt_focus_delay();
92     
93     ft = focus_directional_cycle(o->direction,
94                                  o->dock_windows,
95                                  o->desktop_windows,
96                                  FALSE,
97                                  o->dialog,
98                                  TRUE, FALSE);
99
100     if (ft)
101         actions_run_acts(o->actions, data->uact, data->state,
102                          data->x, data->y, data->button, data->context, ft);
103
104     return FALSE;
105 }