1 #include "openbox/action.h"
2 #include "openbox/action_list_run.h"
3 #include "openbox/action_value.h"
4 #include "openbox/client.h"
5 #include "openbox/screen.h"
6 #include "openbox/frame.h"
7 #include "openbox/config.h"
26 static gpointer setup_func(GHashTable *config);
27 static void free_func(gpointer o);
28 static gboolean run_func(const ObActionListRun *data, gpointer options);
30 void action_moveresizeto_startup(void)
32 action_register("MoveResizeTo", OB_ACTION_DEFAULT_FILTER_SINGLE,
33 setup_func, free_func, run_func);
36 static gpointer setup_func(GHashTable *config)
41 o = g_slice_new0(Options);
46 o->monitor = CURRENT_MONITOR;
48 v = g_hash_table_lookup(config, "x");
49 if (v && action_value_is_string(v))
50 action_value_gravity_coord(v, &o->x);
51 v = g_hash_table_lookup(config, "y");
52 if (v && action_value_is_string(v))
53 action_value_gravity_coord(v, &o->y);
55 v = g_hash_table_lookup(config, "width");
56 if (v && action_value_is_string(v))
57 if (g_ascii_strcasecmp(action_value_string(v), "current") != 0)
58 action_value_fraction(v, &o->w, &o->w_denom);
59 v = g_hash_table_lookup(config, "height");
60 if (v && action_value_is_string(v))
61 if (g_ascii_strcasecmp(action_value_string(v), "current") != 0)
62 action_value_fraction(v, &o->h, &o->h_denom);
64 v = g_hash_table_lookup(config, "monitor");
65 if (v && action_value_is_string(v)) {
66 const gchar *s = action_value_string(v);
67 if (g_ascii_strcasecmp(s, "current") != 0) {
68 if (!g_ascii_strcasecmp(s, "all"))
69 o->monitor = ALL_MONITORS;
70 else if(!g_ascii_strcasecmp(s, "next"))
71 o->monitor = NEXT_MONITOR;
72 else if(!g_ascii_strcasecmp(s, "prev"))
73 o->monitor = PREV_MONITOR;
75 o->monitor = action_value_int(v) - 1;
82 static void free_func(gpointer o)
84 g_slice_free(Options, o);
87 /* Always return FALSE because its not interactive */
88 static gboolean run_func(const ObActionListRun *data, gpointer options)
96 gint x, y, lw, lh, w, h;
100 cmon = client_monitor(c);
102 case CURRENT_MONITOR:
105 mon = SCREEN_AREA_ALL_MONITORS; break;
107 mon = (cmon + 1 > screen_num_monitors - 1) ? 0 : (cmon + 1); break;
109 mon = (cmon == 0) ? (screen_num_monitors - 1) : (cmon - 1); break;
111 g_assert_not_reached();
114 area = screen_area(c->desktop, mon, NULL);
115 carea = screen_area(c->desktop, cmon, NULL);
118 if (w == G_MININT) w = c->area.width;
119 else if (o->w_denom) w = (w * area->width) / o->w_denom;
122 if (h == G_MININT) h = c->area.height;
123 else if (o->h_denom) h = (h * area->height) / o->h_denom;
125 /* it might not be able to resize how they requested, so find out what
126 it will actually be resized to */
129 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
131 /* get the frame's size */
132 w += c->frame->size.left + c->frame->size.right;
133 h += c->frame->size.top + c->frame->size.bottom;
137 x = (x * area->width) / o->x.denom;
138 if (o->x.center) x = (area->width - w) / 2;
139 else if (x == G_MININT) x = c->frame->area.x - carea->x;
140 else if (o->x.opposite) x = area->width - w - x;
145 y = (y * area->height) / o->y.denom;
146 if (o->y.center) y = (area->height - h) / 2;
147 else if (y == G_MININT) y = c->frame->area.y - carea->y;
148 else if (o->y.opposite) y = area->height - h - y;
151 /* get the client's size back */
152 w -= c->frame->size.left + c->frame->size.right;
153 h -= c->frame->size.top + c->frame->size.bottom;
155 frame_frame_gravity(c->frame, &x, &y); /* get the client coords */
156 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
157 /* force it on screen if its moving to another monitor */
158 client_find_onscreen(c, &x, &y, w, h, mon != cmon);
160 action_client_move(data, TRUE);
161 client_configure(c, x, y, w, h, TRUE, TRUE, FALSE);
162 action_client_move(data, FALSE);
164 g_slice_free(Rect, area);
165 g_slice_free(Rect, carea);