From 1e6c375fdd1d10ba0b019505436069d21c751945 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 22 Jun 2007 15:18:43 +0000 Subject: [PATCH 1/1] add the moveto action --- Makefile.am | 1 + openbox/action.c | 55 ------------------- openbox/actions/all.c | 1 + openbox/actions/all.h | 1 + openbox/actions/moveto.c | 111 +++++++++++++++++++++++++++++++++++++++ openbox/client.c | 8 +-- openbox/frame.c | 10 ++-- openbox/frame.h | 4 +- openbox/moveresize.c | 4 +- openbox/place.c | 3 +- openbox/resist.c | 8 +-- 11 files changed, 131 insertions(+), 75 deletions(-) create mode 100644 openbox/actions/moveto.c diff --git a/Makefile.am b/Makefile.am index 51921667..1b94d4ff 100644 --- a/Makefile.am +++ b/Makefile.am @@ -168,6 +168,7 @@ openbox_openbox_SOURCES = \ openbox/actions/lower.c \ openbox/actions/maximize.c \ openbox/actions/move.c \ + openbox/actions/moveto.c \ openbox/actions/raise.c \ openbox/actions/raiselower.c \ openbox/actions/reconfigure.c \ diff --git a/openbox/action.c b/openbox/action.c index 5b1fcd6c..61f346b1 100644 --- a/openbox/action.c +++ b/openbox/action.c @@ -499,11 +499,6 @@ ActionString actionstrings[] = action_move_relative_vert, setup_client_action }, - { - "movetocenter", - action_move_to_center, - setup_client_action - }, { "resizerelativehorz", action_resize_relative_horz, @@ -524,36 +519,6 @@ ActionString actionstrings[] = action_resize_relative, setup_client_action }, - { - "maximizehorz", - action_maximize_horz, - setup_client_action - }, - { - "unmaximizehorz", - action_unmaximize_horz, - setup_client_action - }, - { - "togglemaximizehorz", - action_toggle_maximize_horz, - setup_client_action - }, - { - "maximizevert", - action_maximize_vert, - setup_client_action - }, - { - "unmaximizevert", - action_unmaximize_vert, - setup_client_action - }, - { - "togglemaximizevert", - action_toggle_maximize_vert, - setup_client_action - }, { "sendtodesktop", action_send_to_desktop, @@ -1055,18 +1020,6 @@ void action_move_relative_vert(union ActionData *data) client_action_end(data, FALSE); } -void action_move_to_center(union ActionData *data) -{ - ObClient *c = data->client.any.c; - Rect *area; - area = screen_area(c->desktop, client_monitor(c), NULL); - client_action_start(data); - client_move(c, area->x + area->width / 2 - c->area.width / 2, - area->y + area->height / 2 - c->area.height / 2); - client_action_end(data, FALSE); - g_free(area); -} - void action_resize_relative_horz(union ActionData *data) { ObClient *c = data->relative.any.c; @@ -1127,14 +1080,6 @@ void action_resize_relative(union ActionData *data) client_action_end(data, FALSE); } -void action_toggle_maximize_vert(union ActionData *data) -{ - client_action_start(data); - client_maximize(data->client.any.c, - !data->client.any.c->max_vert, 2); - client_action_end(data, config_focus_under_mouse); -} - void action_send_to_desktop(union ActionData *data) { ObClient *c = data->sendto.any.c; diff --git a/openbox/actions/all.c b/openbox/actions/all.c index 72813e3e..e6f5ab06 100644 --- a/openbox/actions/all.c +++ b/openbox/actions/all.c @@ -21,4 +21,5 @@ void action_all_startup() action_iconify_startup(); action_fullscreen_startup(); action_maximize_startup(); + action_moveto_startup(); } diff --git a/openbox/actions/all.h b/openbox/actions/all.h index 069c50a7..846ec6c4 100644 --- a/openbox/actions/all.h +++ b/openbox/actions/all.h @@ -22,5 +22,6 @@ void action_unfocus_startup(); void action_iconify_startup(); void action_fullscreen_startup(); void action_maximize_startup(); +void action_moveto_startup(); #endif diff --git a/openbox/actions/moveto.c b/openbox/actions/moveto.c new file mode 100644 index 00000000..7cc6541d --- /dev/null +++ b/openbox/actions/moveto.c @@ -0,0 +1,111 @@ +#include "openbox/actions.h" +#include "openbox/client.h" +#include "openbox/screen.h" +#include "openbox/frame.h" +#include /* for atoi */ + +typedef struct { + gboolean xcenter; + gboolean ycenter; + gint x; + gint y; + gint monitor; +} Options; + +static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); +static void free_func(gpointer options); +static gboolean run_func(ObActionsData *data, gpointer options); + +void action_moveto_startup() +{ + actions_register("MoveTo", + setup_func, + free_func, + run_func, + NULL, NULL); +} + +static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +{ + xmlNodePtr n; + Options *o; + + o = g_new0(Options, 1); + o->x = G_MININT; + o->y = G_MININT; + o->monitor = -1; + + if ((n = parse_find_node("x", node))) { + gchar *s = parse_string(doc, n); + if (!g_ascii_strcasecmp(s, "center")) + o->xcenter = TRUE; + else + o->x = atoi(s); + g_free(s); + } + + if ((n = parse_find_node("y", node))) { + gchar *s = parse_string(doc, n); + if (!g_ascii_strcasecmp(s, "center")) + o->ycenter = TRUE; + else + o->y = atoi(s); + g_free(s); + } + + if ((n = parse_find_node("monitor", node))) + o->monitor = parse_int(doc, n) - 1; + + return o; +} + +static void free_func(gpointer options) +{ + Options *o = options; + + g_free(o); +} + +/* Always return FALSE because its not interactive */ +static gboolean run_func(ObActionsData *data, gpointer options) +{ + Options *o = options; + + if (data->client) { + Rect *area, *carea; + ObClient *c; + gint mon, cmon; + gint x, y, lw, lh, w, h; + + c = data->client; + mon = o->monitor; + cmon = client_monitor(c); + if (mon < 0) mon = cmon; + area = screen_area(c->desktop, mon, NULL); + carea = screen_area(c->desktop, cmon, NULL); + x = o->x; + if (x == G_MININT) x = c->frame->area.x - carea->x; + if (o->xcenter) x = (area->width - c->frame->area.width) / 2; + x += area->x; + y = o->y; + if (y == G_MININT) y = c->frame->area.y - carea->y; + if (o->ycenter) y = (area->height - c->frame->area.height) / 2; + y += area->y; + w = c->area.width; + h = c->area.height; + + frame_frame_gravity(c->frame, &x, &y); /* get the client coords */ + client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE); + /* force it on screen if its moving to another monitor */ + client_find_onscreen(c, &x, &y, w, h, mon != cmon); + + actions_client_move(data, TRUE); + client_configure(c, x, y, w, h, TRUE, TRUE, FALSE); + actions_client_move(data, FALSE); + + g_free(area); + g_free(carea); + } + + return FALSE; +} diff --git a/openbox/client.c b/openbox/client.c index d65ce4a1..e3a602d5 100644 --- a/openbox/client.c +++ b/openbox/client.c @@ -933,7 +933,7 @@ gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h, frame_rect_to_frame(self->frame, &desired); /* get where the frame would be */ - frame_client_gravity(self->frame, x, y, w, h); + frame_client_gravity(self->frame, x, y); /* get the requested size of the window with decorations */ fw = self->frame->size.left + w + self->frame->size.right; @@ -1021,7 +1021,7 @@ gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h, } /* get where the client should be */ - frame_frame_gravity(self->frame, x, y, w, h); + frame_frame_gravity(self->frame, x, y); return ox != *x || oy != *y; } @@ -2702,7 +2702,7 @@ void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h, frame_adjust_area(self->frame, FALSE, TRUE, TRUE); /* gets the frame's position */ - frame_client_gravity(self->frame, x, y, *w, *h); + frame_client_gravity(self->frame, x, y); /* these positions are frame positions, not client positions */ @@ -2749,7 +2749,7 @@ void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h, } /* gets the client's position */ - frame_frame_gravity(self->frame, x, y, *w, *h); + frame_frame_gravity(self->frame, x, y); /* work within the prefered sizes given by the window */ if (!(*w == self->area.width && *h == self->area.height)) { diff --git a/openbox/frame.c b/openbox/frame.c index 04dbe6e2..9e176a50 100644 --- a/openbox/frame.c +++ b/openbox/frame.c @@ -755,9 +755,7 @@ void frame_adjust_area(ObFrame *self, gboolean moved, frame_client_gravity. */ self->area.x = self->client->area.x; self->area.y = self->client->area.y; - frame_client_gravity(self, &self->area.x, &self->area.y, - self->client->area.width, - self->client->area.height); + frame_client_gravity(self, &self->area.x, &self->area.y); } if (!fake) { @@ -1404,7 +1402,7 @@ ObFrameContext frame_context(ObClient *client, Window win, gint x, gint y) return OB_FRAME_CONTEXT_NONE; } -void frame_client_gravity(ObFrame *self, gint *x, gint *y, gint w, gint h) +void frame_client_gravity(ObFrame *self, gint *x, gint *y) { /* horizontal */ switch (self->client->gravity) { @@ -1467,7 +1465,7 @@ void frame_client_gravity(ObFrame *self, gint *x, gint *y, gint w, gint h) } } -void frame_frame_gravity(ObFrame *self, gint *x, gint *y, gint w, gint h) +void frame_frame_gravity(ObFrame *self, gint *x, gint *y) { /* horizontal */ switch (self->client->gravity) { @@ -1528,7 +1526,7 @@ void frame_rect_to_frame(ObFrame *self, Rect *r) { r->width += self->size.left + self->size.right; r->height += self->size.top + self->size.bottom; - frame_client_gravity(self, &r->x, &r->y, r->width, r->height); + frame_client_gravity(self, &r->x, &r->y); } static void flash_done(gpointer data) diff --git a/openbox/frame.h b/openbox/frame.h index beb6b8a0..f7adbfd4 100644 --- a/openbox/frame.h +++ b/openbox/frame.h @@ -228,13 +228,13 @@ ObFrameContext frame_context(struct _ObClient *self, Window win, be positioned. @return The proper coordinates for the frame, based on the client. */ -void frame_client_gravity(ObFrame *self, gint *x, gint *y, gint w, gint h); +void frame_client_gravity(ObFrame *self, gint *x, gint *y); /*! Reversly applies gravity to the frame's position to find where the client should be positioned. @return The proper coordinates for the client, based on the frame. */ -void frame_frame_gravity(ObFrame *self, gint *x, gint *y, gint w, gint h); +void frame_frame_gravity(ObFrame *self, gint *x, gint *y); /*! Convert a rectangle in client coordinates/sizes to what it would be for the frame, given its current decorations sizes */ diff --git a/openbox/moveresize.c b/openbox/moveresize.c index 69dc18ba..01cbb795 100644 --- a/openbox/moveresize.c +++ b/openbox/moveresize.c @@ -105,7 +105,7 @@ static void get_resize_position(gint *x, gint *y, gboolean cancel) /* see how much it is actually going to resize */ { gint cx = *x, cy = *y; - frame_frame_gravity(moveresize_client->frame, &cx, &cy, w, h); + frame_frame_gravity(moveresize_client->frame, &cx, &cy); client_try_configure(moveresize_client, &cx, &cy, &w, &h, &lw, &lh, TRUE); } @@ -127,7 +127,7 @@ static void get_resize_position(gint *x, gint *y, gboolean cancel) break; } - frame_frame_gravity(moveresize_client->frame, x, y, w, h); + frame_frame_gravity(moveresize_client->frame, x, y); } static void popup_coords(ObClient *c, const gchar *format, gint a, gint b) diff --git a/openbox/place.c b/openbox/place.c index 845becdb..6a210b0f 100644 --- a/openbox/place.c +++ b/openbox/place.c @@ -486,7 +486,6 @@ gboolean place_client(ObClient *client, gint *x, gint *y, g_assert(ret); /* get where the client should be */ - frame_frame_gravity(client->frame, x, y, - client->area.width, client->area.height); + frame_frame_gravity(client->frame, x, y); return ret; } diff --git a/openbox/resist.c b/openbox/resist.c index 211a012c..49875fbb 100644 --- a/openbox/resist.c +++ b/openbox/resist.c @@ -36,7 +36,7 @@ void resist_move_windows(ObClient *c, gint resist, gint *x, gint *y) if (!resist) return; - frame_client_gravity(c->frame, x, y, c->area.width, c->area.height); + frame_client_gravity(c->frame, x, y); w = c->frame->area.width; h = c->frame->area.height; @@ -113,7 +113,7 @@ void resist_move_windows(ObClient *c, gint resist, gint *x, gint *y) if (snapx && snapy) break; } - frame_frame_gravity(c->frame, x, y, c->area.width, c->area.height); + frame_frame_gravity(c->frame, x, y); } void resist_move_monitors(ObClient *c, gint resist, gint *x, gint *y) @@ -129,7 +129,7 @@ void resist_move_monitors(ObClient *c, gint resist, gint *x, gint *y) if (!resist) return; - frame_client_gravity(c->frame, x, y, c->area.width, c->area.height); + frame_client_gravity(c->frame, x, y); w = c->frame->area.width; h = c->frame->area.height; @@ -188,7 +188,7 @@ void resist_move_monitors(ObClient *c, gint resist, gint *x, gint *y) g_free(parea); } - frame_frame_gravity(c->frame, x, y, c->area.width, c->area.height); + frame_frame_gravity(c->frame, x, y); } void resist_size_windows(ObClient *c, gint resist, gint *w, gint *h, -- 2.45.2