Add mostly working LowerOne and very buggy RaiseOne
authorMikael Magnusson <mikachu@gmail.com>
Fri, 17 Sep 2010 01:34:34 +0000 (03:34 +0200)
committerMikael Magnusson <mikachu@gmail.com>
Sun, 19 Sep 2010 15:53:58 +0000 (17:53 +0200)
Makefile.am
openbox/actions/all.c
openbox/actions/all.h
openbox/actions/lowerraiseone.c [new file with mode: 0644]
openbox/stacking.c
openbox/stacking.h

index 62570bd096bc725e550506ac9824e27b95502b22..b166897eef3085d43c374ff5faed97b77faf7881 100644 (file)
@@ -204,6 +204,7 @@ openbox_openbox_SOURCES = \
        openbox/actions/kill.c \
        openbox/actions/layer.c \
        openbox/actions/lower.c \
+       openbox/actions/lowerraiseone.c \
        openbox/actions/maximize.c \
        openbox/actions/move.c \
        openbox/actions/moverelative.c \
index 332e79ca6c92911949ddb269f113751adb755858..2dc3a70c0816a4fa764aedc9703b9719d4ae153a 100644 (file)
@@ -39,6 +39,7 @@ void action_all_startup(void)
     action_growtoedge_startup();
     action_if_startup();
     action_focustobottom_startup();
+    action_lowerraiseone_startup();
     /* 3.4-compatibility */
     action_shadelowerraise_startup();
 }
index 54d63195de6d24480d6256719f439464a4ca3753..aa4e8b05b85faef59dbc5114d1f7f7c8abd6bd0a 100644 (file)
@@ -40,6 +40,7 @@ void action_movetoedge_startup(void);
 void action_growtoedge_startup(void);
 void action_if_startup(void);
 void action_focustobottom_startup(void);
+void action_lowerraiseone_startup(void);
 /* 3.4-compatibility */
 void action_shadelowerraise_startup(void);
 
diff --git a/openbox/actions/lowerraiseone.c b/openbox/actions/lowerraiseone.c
new file mode 100644 (file)
index 0000000..b41a0ed
--- /dev/null
@@ -0,0 +1,52 @@
+#include "openbox/actions.h"
+#include "openbox/stacking.h"
+#include "openbox/window.h"
+#include "openbox/client.h"
+
+static gboolean run_func(ObActionsData *data, gpointer options);
+static gpointer setup_raise(xmlNodePtr node);
+static gpointer setup_lower(xmlNodePtr node);
+
+void action_lowerraiseone_startup(void)
+{
+    actions_register("RaiseOne",
+                     setup_raise, NULL,
+                     run_func);
+    actions_register("LowerOne",
+                     setup_lower, NULL,
+                     run_func);
+}
+
+static gpointer setup_raise(xmlNodePtr node)
+{
+    return GINT_TO_POINTER(1);
+}
+
+static gpointer setup_lower(xmlNodePtr node)
+{
+    return GINT_TO_POINTER(0);
+}
+
+/* Always return FALSE because its not interactive */
+static gboolean run_func(ObActionsData *data, gpointer options)
+{
+    gint dir = GPOINTER_TO_INT(options) ? 1 : -1;
+
+    if (data->client) {
+        ObClient *client = data->client;
+        ObClient *sibling;
+        actions_client_move(data, TRUE);
+        if (dir == 1) {
+          sibling = stacking_occluded(client, NULL);
+          if (sibling)
+              stacking_above(client, sibling);
+        } else {
+          sibling = stacking_occludes(client, NULL);
+          if (sibling)
+              stacking_below(client, sibling);
+        }
+        actions_client_move(data, FALSE);
+    }
+
+    return FALSE;
+}
index 58551b5da28d17474c294cb0f31b81e291207e7c..43eff8531bbd19e5e112b08c24b3a6932972c48f 100644 (file)
@@ -423,6 +423,20 @@ void stacking_lower(ObWindow *window)
     stacking_list_tail = g_list_last(stacking_list);
 }
 
+void stacking_above(ObWindow *window, ObWindow *above)
+{
+    GList *wins, *before;
+
+    if (window_layer(window) != window_layer(above))
+        return;
+
+    wins = g_list_append(NULL, window);
+    stacking_list = g_list_remove(stacking_list, window);
+    before = g_list_previous(g_list_find(stacking_list, above));
+    do_restack(wins, before);
+    g_list_free(wins);
+}
+
 void stacking_below(ObWindow *window, ObWindow *below)
 {
     GList *wins, *before;
@@ -564,13 +578,10 @@ void stacking_add_nonintrusive(ObWindow *win)
     stacking_list_tail = g_list_last(stacking_list);
 }
 
-/*! Returns TRUE if client is occluded by the sibling. If sibling is NULL it
-  tries against all other clients.
-*/
-static gboolean stacking_occluded(ObClient *client, ObClient *sibling)
+ObClient *stacking_occluded(ObClient *client, ObClient *sibling)
 {
     GList *it;
-    gboolean occluded = FALSE;
+    ObClient *occluded = NULL;
 
     /* no need for any looping in this case */
     if (sibling && client->layer != sibling->layer)
@@ -589,12 +600,12 @@ static gboolean stacking_occluded(ObClient *client, ObClient *sibling)
                 {
                     if (sibling != NULL) {
                         if (c == sibling) {
-                            occluded = TRUE;
+                            occluded = sibling;
                             break;
                         }
                     }
                     else if (c->layer == client->layer) {
-                        occluded = TRUE;
+                        occluded = c;
                         break;
                     }
                     else if (c->layer > client->layer)
@@ -605,13 +616,10 @@ static gboolean stacking_occluded(ObClient *client, ObClient *sibling)
     return occluded;
 }
 
-/*! Returns TRUE if client occludes the sibling. If sibling is NULL it tries
-  against all other clients.
-*/
-static gboolean stacking_occludes(ObClient *client, ObClient *sibling)
+ObClient *stacking_occludes(ObClient *client, ObClient *sibling)
 {
     GList *it;
-    gboolean occludes = FALSE;
+    ObClient *occludes = NULL;
 
     /* no need for any looping in this case */
     if (sibling && client->layer != sibling->layer)
@@ -630,12 +638,12 @@ static gboolean stacking_occludes(ObClient *client, ObClient *sibling)
                 {
                     if (sibling != NULL) {
                         if (c == sibling) {
-                            occludes = TRUE;
+                            occludes = sibling;
                             break;
                         }
                     }
                     else if (c->layer == client->layer) {
-                        occludes = TRUE;
+                        occludes = c;
                         break;
                     }
                     else if (c->layer < client->layer)
index c14aa2eddb59e62819f73ae4eb45e2e14a5d92e2..c5385766881ce0ccf4057d15418cbf2872f6969e 100644 (file)
@@ -68,6 +68,18 @@ void stacking_lower(struct _ObWindow *window);
   it should really ONLY be used to restore stacking orders from saved sessions
 */
 void stacking_below(struct _ObWindow *window, struct _ObWindow *below);
+/*! Ibid, above */
+void stacking_above(struct _ObWindow *window, struct _ObWindow *above);
+
+/*! Returns sibling if client is occluded by the sibling. If sibling is NULL it
+  tries against all other clients, then the nearest client occluding is returned.
+*/
+struct _ObClient *stacking_occluded(struct _ObClient *client, struct _ObClient *sibling);
+
+/*! Returns sibling if client occludes the sibling. If sibling is NULL it tries
+  against all other clients, then the nearest client occluded is returned.
+*/
+struct _ObClient *stacking_occludes(struct _ObClient *client, struct _ObClient *sibling);
 
 /*! Restack a window based upon a sibling (or all windows) in various ways.
   @param client The client to be restacked