]> Dogcows Code - chaz/openbox/blob - openbox/actions/moveto.c
a8ba4261b0a34c7969fbd25d8ac96c5c0ed32aa4
[chaz/openbox] / openbox / actions / moveto.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 gboolean xcenter;
9 gboolean ycenter;
10 gint x;
11 gint y;
12 gint monitor;
13 } Options;
14
15 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
16 static void free_func(gpointer options);
17 static gboolean run_func(ObActionsData *data, gpointer options);
18
19 void action_moveto_startup()
20 {
21 actions_register("MoveTo",
22 setup_func,
23 free_func,
24 run_func,
25 NULL, NULL);
26 }
27
28 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
29 {
30 xmlNodePtr n;
31 Options *o;
32
33 o = g_new0(Options, 1);
34 o->x = G_MININT;
35 o->y = G_MININT;
36 o->monitor = -1;
37
38 if ((n = parse_find_node("x", node))) {
39 gchar *s = parse_string(doc, n);
40 if (!g_ascii_strcasecmp(s, "center"))
41 o->xcenter = TRUE;
42 else
43 o->x = atoi(s);
44 g_free(s);
45 }
46
47 if ((n = parse_find_node("y", node))) {
48 gchar *s = parse_string(doc, n);
49 if (!g_ascii_strcasecmp(s, "center"))
50 o->ycenter = TRUE;
51 else
52 o->y = atoi(s);
53 g_free(s);
54 }
55
56 if ((n = parse_find_node("monitor", node)))
57 o->monitor = parse_int(doc, n) - 1;
58
59 return o;
60 }
61
62 static void free_func(gpointer options)
63 {
64 Options *o = options;
65
66 g_free(o);
67 }
68
69 /* Always return FALSE because its not interactive */
70 static gboolean run_func(ObActionsData *data, gpointer options)
71 {
72 Options *o = options;
73
74 if (data->client) {
75 Rect *area, *carea;
76 ObClient *c;
77 gint mon, cmon;
78 gint x, y, lw, lh, w, h;
79
80 c = data->client;
81 mon = o->monitor;
82 cmon = client_monitor(c);
83 if (mon < 0) mon = cmon;
84 area = screen_area(c->desktop, mon, NULL);
85 carea = screen_area(c->desktop, cmon, NULL);
86 x = o->x;
87 if (x == G_MININT) x = c->frame->area.x - carea->x;
88 if (o->xcenter) x = (area->width - c->frame->area.width) / 2;
89 x += area->x;
90 y = o->y;
91 if (y == G_MININT) y = c->frame->area.y - carea->y;
92 if (o->ycenter) y = (area->height - c->frame->area.height) / 2;
93 y += area->y;
94 w = c->area.width;
95 h = c->area.height;
96
97 frame_frame_gravity(c->frame, &x, &y); /* get the client coords */
98 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
99 /* force it on screen if its moving to another monitor */
100 client_find_onscreen(c, &x, &y, w, h, mon != cmon);
101
102 client_configure(c, x, y, w, h, TRUE, TRUE, FALSE);
103
104 g_free(area);
105 g_free(carea);
106 }
107
108 return FALSE;
109 }
This page took 0.04072 seconds and 3 git commands to generate.