]> Dogcows Code - chaz/openbox/blob - openbox/actions/movetoedge.c
f81ded41e0ee8a405f4b4c439e00c8f8e20b0947
[chaz/openbox] / openbox / actions / movetoedge.c
1 #include "openbox/actions.h"
2 #include "openbox/misc.h"
3 #include "openbox/client.h"
4 #include "openbox/frame.h"
5 #include "openbox/geom.h"
6 #include <glib.h>
7
8 typedef struct {
9 ObDirection dir;
10 } Options;
11
12 static gpointer setup_func(xmlNodePtr node);
13 static gboolean run_func(ObActionsData *data, gpointer options);
14 /* 3.4-compatibility */
15 static gpointer setup_north_func(xmlNodePtr node);
16 static gpointer setup_south_func(xmlNodePtr node);
17 static gpointer setup_east_func(xmlNodePtr node);
18 static gpointer setup_west_func(xmlNodePtr node);
19
20 void action_movetoedge_startup(void)
21 {
22 actions_register("MoveToEdge", setup_func, g_free, run_func);
23 /* 3.4-compatibility */
24 actions_register("MoveToEdgeNorth", setup_north_func, g_free, run_func);
25 actions_register("MoveToEdgeSouth", setup_south_func, g_free, run_func);
26 actions_register("MoveToEdgeEast", setup_east_func, g_free, run_func);
27 actions_register("MoveToEdgeWest", setup_west_func, g_free, run_func);
28 }
29
30 static gpointer setup_func(xmlNodePtr node)
31 {
32 xmlNodePtr n;
33 Options *o;
34
35 o = g_new0(Options, 1);
36 o->dir = OB_DIRECTION_NORTH;
37
38 if ((n = obt_xml_find_node(node, "direction"))) {
39 gchar *s = obt_xml_node_string(n);
40 if (!g_ascii_strcasecmp(s, "north") ||
41 !g_ascii_strcasecmp(s, "up"))
42 o->dir = OB_DIRECTION_NORTH;
43 else if (!g_ascii_strcasecmp(s, "south") ||
44 !g_ascii_strcasecmp(s, "down"))
45 o->dir = OB_DIRECTION_SOUTH;
46 else if (!g_ascii_strcasecmp(s, "west") ||
47 !g_ascii_strcasecmp(s, "left"))
48 o->dir = OB_DIRECTION_WEST;
49 else if (!g_ascii_strcasecmp(s, "east") ||
50 !g_ascii_strcasecmp(s, "right"))
51 o->dir = OB_DIRECTION_EAST;
52 g_free(s);
53 }
54
55 return o;
56 }
57
58 /* Always return FALSE because its not interactive */
59 static gboolean run_func(ObActionsData *data, gpointer options)
60 {
61 Options *o = options;
62
63 if (data->client) {
64 gint x, y;
65
66 client_find_move_directional(data->client, o->dir, &x, &y);
67 if (x != data->client->area.x || y != data->client->area.y) {
68 actions_client_move(data, TRUE);
69 client_move(data->client, x, y);
70 actions_client_move(data, FALSE);
71 }
72 }
73
74 return FALSE;
75 }
76
77 /* 3.4-compatibility */
78 static gpointer setup_north_func(xmlNodePtr node)
79 {
80 Options *o = g_new0(Options, 1);
81 o->dir = OB_DIRECTION_NORTH;
82 return o;
83 }
84
85 static gpointer setup_south_func(xmlNodePtr node)
86 {
87 Options *o = g_new0(Options, 1);
88 o->dir = OB_DIRECTION_SOUTH;
89 return o;
90 }
91
92 static gpointer setup_east_func(xmlNodePtr node)
93 {
94 Options *o = g_new0(Options, 1);
95 o->dir = OB_DIRECTION_EAST;
96 return o;
97 }
98
99 static gpointer setup_west_func(xmlNodePtr node)
100 {
101 Options *o = g_new0(Options, 1);
102 o->dir = OB_DIRECTION_WEST;
103 return o;
104 }
105
This page took 0.038984 seconds and 3 git commands to generate.