Remove some unneeded stdlib.h includes
[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 "openbox/config.h"
6
7 typedef struct {
8     gint x;
9     gint x_denom;
10     gint y;
11     gint y_denom;
12 } Options;
13
14 static gpointer setup_func(xmlNodePtr node);
15 static void free_func(gpointer o);
16 static gboolean run_func(ObActionsData *data, gpointer options);
17
18 void action_moverelative_startup(void)
19 {
20     actions_register("MoveRelative", setup_func, free_func, run_func);
21 }
22
23 static gpointer setup_func(xmlNodePtr node)
24 {
25     xmlNodePtr n;
26     Options *o;
27     gchar *s;
28
29     o = g_slice_new0(Options);
30
31     if ((n = obt_xml_find_node(node, "x"))) {
32         s = obt_xml_node_string(n);
33         config_parse_relative_number(s, &o->x, &o->x_denom);
34         g_free(s);
35     }
36     if ((n = obt_xml_find_node(node, "y"))) {
37         s = obt_xml_node_string(n);
38         config_parse_relative_number(s, &o->y, &o->y_denom);
39         g_free(s);
40     }
41
42     return o;
43 }
44
45 static void free_func(gpointer o)
46 {
47     g_slice_free(Options, o);
48 }
49
50 /* Always return FALSE because its not interactive */
51 static gboolean run_func(ObActionsData *data, gpointer options)
52 {
53     Options *o = options;
54
55     if (data->client) {
56         ObClient *c;
57         gint x, y, lw, lh, w, h;
58
59         c = data->client;
60         x = o->x;
61         y = o->y;
62         if (o->x_denom || o->y_denom) {
63             const Rect *carea;
64
65             carea = screen_area(c->desktop, client_monitor(c), NULL);
66             if (o->x_denom)
67                 x = (x * carea->width) / o->x_denom;
68             if (o->y_denom)
69                 y = (y * carea->height) / o->y_denom;
70         }
71         x = c->area.x + x;
72         y = c->area.y + y;
73         w = c->area.width;
74         h = c->area.height;
75         client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
76         client_find_onscreen(c, &x, &y, w, h, FALSE);
77
78         actions_client_move(data, TRUE);
79         client_configure(c, x, y, w, h, TRUE, TRUE, FALSE);
80         actions_client_move(data, FALSE);
81     }
82
83     return FALSE;
84 }