more using g_slice_new() instead of g_new()
[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 void free_func(gpointer o);
14 static gboolean run_func(ObActionsData *data, gpointer options);
15
16 void action_moverelative_startup(void)
17 {
18     actions_register("MoveRelative", setup_func, free_func, run_func);
19 }
20
21 static gpointer setup_func(xmlNodePtr node)
22 {
23     xmlNodePtr n;
24     Options *o;
25
26     o = g_slice_new0(Options);
27
28     if ((n = obt_xml_find_node(node, "x")))
29         o->x = obt_xml_node_int(n);
30     if ((n = obt_xml_find_node(node, "y")))
31         o->y = obt_xml_node_int(n);
32
33     return o;
34 }
35
36 static void free_func(gpointer o)
37 {
38     g_slice_free(Options, o);
39 }
40
41 /* Always return FALSE because its not interactive */
42 static gboolean run_func(ObActionsData *data, gpointer options)
43 {
44     Options *o = options;
45
46     if (data->client) {
47         ObClient *c;
48         gint x, y, lw, lh, w, h;
49
50         c = data->client;
51         x = c->area.x + o->x;
52         y = c->area.y + o->y;
53         w = c->area.width;
54         h = c->area.height;
55         client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
56         client_find_onscreen(c, &x, &y, w, h, FALSE);
57
58         actions_client_move(data, TRUE);
59         client_configure(c, x, y, w, h, TRUE, TRUE, FALSE);
60         actions_client_move(data, FALSE);
61     }
62
63     return FALSE;
64 }