add resizerelative action
authorDana Jansens <danakj@orodu.net>
Fri, 22 Jun 2007 19:24:45 +0000 (19:24 +0000)
committerDana Jansens <danakj@orodu.net>
Fri, 22 Jun 2007 19:24:45 +0000 (19:24 +0000)
Makefile.am
openbox/action.c
openbox/actions/all.c
openbox/actions/all.h
openbox/actions/resizerelative.c [new file with mode: 0644]

index 63c3f84..896597f 100644 (file)
@@ -184,6 +184,7 @@ openbox_openbox_SOURCES = \
        openbox/actions/raiselower.c \
        openbox/actions/reconfigure.c \
        openbox/actions/resize.c \
+       openbox/actions/resizerelative.c \
        openbox/actions/restart.c \
        openbox/actions/shade.c \
        openbox/actions/showdesktop.c \
index 37370e8..24f4b36 100644 (file)
@@ -346,16 +346,6 @@ ActionString actionstrings[] =
         setup_client_action
     },
     {
-        "resizerelativevert",
-        action_resize_relative_vert,
-        setup_client_action
-    },
-    {
-        "resizerelative",
-        action_resize_relative,
-        setup_client_action
-    },
-    {
         "sendtodesktop",
         action_send_to_desktop,
         setup_action_send_to_desktop
@@ -396,11 +386,6 @@ ActionString actionstrings[] =
         NULL
     },
     {
-        "desktoplast",
-        action_desktop_last,
-        NULL
-    },
-    {
         "sendtotoplayer",
         action_send_to_layer,
         setup_action_top_layer
@@ -553,24 +538,7 @@ ObAction *action_parse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
 
     if (parse_attr_string("name", node, &actname)) {
         if ((act = action_from_string(actname, uact))) {
-            } else if (act->func == action_resize_relative) {
-                if ((n = parse_find_node("left", node->xmlChildrenNode)))
-                    act->data.relative.deltaxl = parse_int(doc, n);
-                if ((n = parse_find_node("up", node->xmlChildrenNode)))
-                    act->data.relative.deltayu = parse_int(doc, n);
-                if ((n = parse_find_node("right", node->xmlChildrenNode)))
-                    act->data.relative.deltax = parse_int(doc, n);
-                if ((n = parse_find_node("down", node->xmlChildrenNode)))
-                    act->data.relative.deltay = parse_int(doc, n);
             } else if (act->func == action_desktop) {
-                if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
-                    act->data.desktop.desk = parse_int(doc, n);
-                if (act->data.desktop.desk > 0) act->data.desktop.desk--;
-/*
-                if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
-                    act->data.desktop.inter.any.interactive =
-                        parse_bool(doc, n);
-*/
            } else if (act->func == action_send_to_desktop) {
                 if ((n = parse_find_node("desktop", node->xmlChildrenNode)))
                     act->data.sendto.desk = parse_int(doc, n);
@@ -708,55 +676,8 @@ void action_shadelower(union ActionData *data)
         action_shade(data);
 }
 
-void action_resize_relative_horz(union ActionData *data)
-{
-    ObClient *c = data->relative.any.c;
-    client_action_start(data);
-    client_resize(c,
-                  c->area.width + data->relative.deltax * c->size_inc.width,
-                  c->area.height);
-    client_action_end(data, FALSE);
-}
-
-void action_resize_relative_vert(union ActionData *data)
-{
-    ObClient *c = data->relative.any.c;
-    if (!c->shaded) {
-        client_action_start(data);
-        client_resize(c, c->area.width, c->area.height +
-                      data->relative.deltax * c->size_inc.height);
-        client_action_end(data, FALSE);
-    }
-}
-
 void action_resize_relative(union ActionData *data)
 {
-    ObClient *c = data->relative.any.c;
-    gint x, y, ow, xoff, nw, oh, yoff, nh, lw, lh;
-
-    client_action_start(data);
-
-    x = c->area.x;
-    y = c->area.y;
-    ow = c->area.width;
-    xoff = -data->relative.deltaxl * c->size_inc.width;
-    nw = ow + data->relative.deltax * c->size_inc.width
-        + data->relative.deltaxl * c->size_inc.width;
-    oh = c->area.height;
-    yoff = -data->relative.deltayu * c->size_inc.height;
-    nh = oh + data->relative.deltay * c->size_inc.height
-        + data->relative.deltayu * c->size_inc.height;
-
-    g_print("deltax %d %d x %d ow %d xoff %d nw %d\n",
-            data->relative.deltax, 
-            data->relative.deltaxl, 
-            x, ow, xoff, nw);
-    
-    client_try_configure(c, &x, &y, &nw, &nh, &lw, &lh, TRUE);
-    xoff = xoff == 0 ? 0 : (xoff < 0 ? MAX(xoff, ow-nw) : MIN(xoff, ow-nw));
-    yoff = yoff == 0 ? 0 : (yoff < 0 ? MAX(yoff, oh-nh) : MIN(yoff, oh-nh));
-    client_move_resize(c, x + xoff, y + yoff, nw, nh);
-    client_action_end(data, FALSE);
 }
 
 void action_send_to_desktop(union ActionData *data)
@@ -797,12 +718,6 @@ void action_send_to_desktop_dir(union ActionData *data)
     }
 }
 
-void action_desktop_last(union ActionData *data)
-{
-    if (screen_last_desktop < screen_num_desktops)
-        screen_set_desktop(screen_last_desktop, TRUE);
-}
-
 void action_directional_focus(union ActionData *data)
 {
     /* if using focus_delay, stop the timer now so that focus doesn't go moving
index cb3f987..5610a48 100644 (file)
@@ -34,4 +34,5 @@ void action_all_startup()
     action_decorations_startup();
     action_desktop_startup();
     action_directionaldesktop_startup();
+    action_resizerelative_startup();
 }
index ea0a3d2..9a940d4 100644 (file)
@@ -35,5 +35,6 @@ void action_resize_startup();
 void action_decorations_startup();
 void action_desktop_startup();
 void action_directionaldesktop_startup();
+void action_resizerelative_startup();
 
 #endif
diff --git a/openbox/actions/resizerelative.c b/openbox/actions/resizerelative.c
new file mode 100644 (file)
index 0000000..1aefb51
--- /dev/null
@@ -0,0 +1,85 @@
+#include "openbox/actions.h"
+#include "openbox/client.h"
+#include "openbox/screen.h"
+#include "openbox/frame.h"
+#include <stdlib.h> /* for atoi */
+
+typedef struct {
+    gint left;
+    gint right;
+    gint top;
+    gint bottom;
+} 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_resizerelative_startup()
+{
+    actions_register("ResizeRelative",
+                     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);
+
+    if ((n = parse_find_node("left", node)))
+        o->left = parse_int(doc, n);
+    if ((n = parse_find_node("right", node)))
+        o->right = parse_int(doc, n);
+    if ((n = parse_find_node("top", node)))
+        o->top = parse_int(doc, n);
+    if ((n = parse_find_node("bottom", node)))
+        o->bottom = parse_int(doc, n);
+
+    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) {
+        ObClient *c = data->client;
+        gint x, y, ow, xoff, nw, oh, yoff, nh, lw, lh;
+
+        x = c->area.x;
+        y = c->area.y;
+        ow = c->area.width;
+        xoff = -o->left * c->size_inc.width;
+        nw = ow + o->right * c->size_inc.width
+            + o->left * c->size_inc.width;
+        oh = c->area.height;
+        yoff = -o->top * c->size_inc.height;
+        nh = oh + o->bottom * c->size_inc.height
+            + o->top * c->size_inc.height;
+
+        client_try_configure(c, &x, &y, &nw, &nh, &lw, &lh, TRUE);
+        xoff = xoff == 0 ? 0 :
+            (xoff < 0 ? MAX(xoff, ow-nw) : MIN(xoff, ow-nw));
+        yoff = yoff == 0 ? 0 :
+            (yoff < 0 ? MAX(yoff, oh-nh) : MIN(yoff, oh-nh));
+
+        actions_client_move(data, FALSE);
+        client_move_resize(c, x + xoff, y + yoff, nw, nh);
+        actions_client_move(data, TRUE);
+    }
+
+    return FALSE;
+}