update openbox to use the current parser interface in libobt
[dana/openbox.git] / openbox / actions / moverelative.c
1 #include "openbox/actions.h"
2 #include "openbox/client.h"
3 #include "openbox/screen.h"
4 #include "openbox/frame.h"
5 #include <stdlib.h> /* for atoi */
6
7 typedef struct {
8     gint x;
9     gint y;
10 } Options;
11
12 static gpointer setup_func(xmlNodePtr node);
13 static gboolean run_func(ObActionsData *data, gpointer options);
14
15 void action_moverelative_startup(void)
16 {
17     actions_register("MoveRelative", setup_func, g_free, run_func, NULL, NULL);
18 }
19
20 static gpointer setup_func(xmlNodePtr node)
21 {
22     xmlNodePtr n;
23     Options *o;
24
25     o = g_new0(Options, 1);
26
27     if ((n = obt_parse_find_node(node, "x")))
28         o->x = obt_parse_node_int(n);
29     if ((n = obt_parse_find_node(node, "y")))
30         o->y = obt_parse_node_int(n);
31
32     return o;
33 }
34
35 /* Always return FALSE because its not interactive */
36 static gboolean run_func(ObActionsData *data, gpointer options)
37 {
38     Options *o = options;
39
40     if (data->client) {
41         ObClient *c;
42         gint x, y, lw, lh, w, h;
43
44         c = data->client;
45         x = data->client->area.x + o->x;
46         y = data->client->area.y + o->y;
47         w = data->client->area.width;
48         h = data->client->area.height;
49         client_try_configure(data->client, &x, &y, &w, &h, &lw, &lh, TRUE);
50         client_find_onscreen(data->client, &x, &y, w, h, FALSE);
51
52         actions_client_move(data, TRUE);
53         client_configure(data->client, x, y, w, h, TRUE, TRUE, FALSE);
54         actions_client_move(data, FALSE);
55     }
56
57     return FALSE;
58 }