add the moveto action
This commit is contained in:
parent
06ed8ab6c0
commit
1e6c375fdd
11 changed files with 131 additions and 75 deletions
|
@ -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 \
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -21,4 +21,5 @@ void action_all_startup()
|
|||
action_iconify_startup();
|
||||
action_fullscreen_startup();
|
||||
action_maximize_startup();
|
||||
action_moveto_startup();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
111
openbox/actions/moveto.c
Normal file
111
openbox/actions/moveto.c
Normal file
|
@ -0,0 +1,111 @@
|
|||
#include "openbox/actions.h"
|
||||
#include "openbox/client.h"
|
||||
#include "openbox/screen.h"
|
||||
#include "openbox/frame.h"
|
||||
#include <stdlib.h> /* 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;
|
||||
}
|
|
@ -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)) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue