add the moveto action
authorDana Jansens <danakj@orodu.net>
Fri, 22 Jun 2007 15:18:43 +0000 (15:18 +0000)
committerDana Jansens <danakj@orodu.net>
Fri, 22 Jun 2007 15:18:43 +0000 (15:18 +0000)
Makefile.am
openbox/action.c
openbox/actions/all.c
openbox/actions/all.h
openbox/actions/moveto.c [new file with mode: 0644]
openbox/client.c
openbox/frame.c
openbox/frame.h
openbox/moveresize.c
openbox/place.c
openbox/resist.c

index 5192166..1b94d4f 100644 (file)
@@ -168,6 +168,7 @@ openbox_openbox_SOURCES = \
        openbox/actions/lower.c \
        openbox/actions/maximize.c \
        openbox/actions/move.c \
        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 \
        openbox/actions/raise.c \
        openbox/actions/raiselower.c \
        openbox/actions/reconfigure.c \
index 5b1fcd6..61f346b 100644 (file)
@@ -500,11 +500,6 @@ ActionString actionstrings[] =
         setup_client_action
     },
     {
         setup_client_action
     },
     {
-        "movetocenter",
-        action_move_to_center,
-        setup_client_action
-    },
-    {
         "resizerelativehorz",
         action_resize_relative_horz,
         setup_client_action
         "resizerelativehorz",
         action_resize_relative_horz,
         setup_client_action
@@ -525,36 +520,6 @@ ActionString actionstrings[] =
         setup_client_action
     },
     {
         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,
         setup_action_send_to_desktop
         "sendtodesktop",
         action_send_to_desktop,
         setup_action_send_to_desktop
@@ -1055,18 +1020,6 @@ void action_move_relative_vert(union ActionData *data)
     client_action_end(data, FALSE);
 }
 
     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;
 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);
 }
 
     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;
 void action_send_to_desktop(union ActionData *data)
 {
     ObClient *c = data->sendto.any.c;
index 72813e3..e6f5ab0 100644 (file)
@@ -21,4 +21,5 @@ void action_all_startup()
     action_iconify_startup();
     action_fullscreen_startup();
     action_maximize_startup();
     action_iconify_startup();
     action_fullscreen_startup();
     action_maximize_startup();
+    action_moveto_startup();
 }
 }
index 069c50a..846ec6c 100644 (file)
@@ -22,5 +22,6 @@ void action_unfocus_startup();
 void action_iconify_startup();
 void action_fullscreen_startup();
 void action_maximize_startup();
 void action_iconify_startup();
 void action_fullscreen_startup();
 void action_maximize_startup();
+void action_moveto_startup();
 
 #endif
 
 #endif
diff --git a/openbox/actions/moveto.c b/openbox/actions/moveto.c
new file mode 100644 (file)
index 0000000..7cc6541
--- /dev/null
@@ -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;
+}
index d65ce4a..e3a602d 100644 (file)
@@ -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_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;
 
     /* 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 */
     }
 
     /* 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;
 }
 
     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_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 */
 
 
     /* 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 */
     }
 
     /* 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)) {
 
     /* work within the prefered sizes given by the window */
     if (!(*w == self->area.width && *h == self->area.height)) {
index 04dbe6e..9e176a5 100644 (file)
@@ -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->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) {
     }
 
     if (!fake) {
@@ -1404,7 +1402,7 @@ ObFrameContext frame_context(ObClient *client, Window win, gint x, gint y)
     return OB_FRAME_CONTEXT_NONE;
 }
 
     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) {
 {
     /* 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) {
 {
     /* 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;
 {
     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)
 }
 
 static void flash_done(gpointer data)
index beb6b8a..f7adbfd 100644 (file)
@@ -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.
 */
   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.
 */
 
 /*! 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 */
 
 /*! Convert a rectangle in client coordinates/sizes to what it would be
   for the frame, given its current decorations sizes */
index 69dc18b..01cbb79 100644 (file)
@@ -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;
     /* 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);
     }
         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;
     }
 
         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)
 }
 
 static void popup_coords(ObClient *c, const gchar *format, gint a, gint b)
index 845becd..6a210b0 100644 (file)
@@ -486,7 +486,6 @@ gboolean place_client(ObClient *client, gint *x, gint *y,
     g_assert(ret);
 
     /* get where the client should be */
     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;
 }
     return ret;
 }
index 211a012..49875fb 100644 (file)
@@ -36,7 +36,7 @@ void resist_move_windows(ObClient *c, gint resist, gint *x, gint *y)
 
     if (!resist) return;
 
 
     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;
 
     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;
     }
 
         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)
 }
 
 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;
 
 
     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;
 
     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);
     }
 
         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,
 }
 
 void resist_size_windows(ObClient *c, gint resist, gint *w, gint *h,