]> Dogcows Code - chaz/openbox/blobdiff - openbox/screen.c
warp desktops when you hit the edge of the screen while moving a window
[chaz/openbox] / openbox / screen.c
index f59856e9d61c79d0f0b0a8a3aaeb69fd8c7ebd3b..1a01bfbfeee22969856e81d544134e403ff8d08f 100644 (file)
@@ -27,6 +27,7 @@
 #include "moveresize.h"
 #include "config.h"
 #include "screen.h"
+#include "composite.h"
 #include "client.h"
 #include "session.h"
 #include "frame.h"
@@ -48,7 +49,7 @@
 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
                         EnterWindowMask | LeaveWindowMask | \
                         SubstructureRedirectMask | FocusChangeMask | \
-                        ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
+                        ButtonPressMask | ButtonReleaseMask)
 
 static gboolean screen_validate_layout(ObDesktopLayout *l);
 static gboolean replace_wm();
@@ -490,13 +491,16 @@ void screen_resize()
 
     for (it = client_list; it; it = g_list_next(it))
         client_move_onscreen(it->data, FALSE);
+
+    /* this needs to be setup whenever the root window's size changes */
+    composite_setup_root_window();
 }
 
 void screen_set_num_desktops(guint num)
 {
     guint old;
     gulong *viewport;
-    GList *it;
+    GList *it, *stacking_copy;
 
     g_assert(num > 0);
 
@@ -516,11 +520,21 @@ void screen_set_num_desktops(guint num)
     /* the number of rows/columns will differ */
     screen_update_layout();
 
-    /* move windows on desktops that will no longer exist! */
-    for (it = client_list; it; it = g_list_next(it)) {
-        ObClient *c = it->data;
-        if (c->desktop >= num && c->desktop != DESKTOP_ALL)
-            client_set_desktop(c, num - 1, FALSE);
+    /* move windows on desktops that will no longer exist!
+       make a copy of the list cuz we're changing it */
+    stacking_copy = g_list_copy(stacking_list);
+    for (it = g_list_last(stacking_copy); it; it = g_list_previous(it)) {
+        if (WINDOW_IS_CLIENT(it->data)) {
+            ObClient *c = it->data;
+            if (c->desktop != DESKTOP_ALL && c->desktop >= num)
+                client_set_desktop(c, num - 1, FALSE, TRUE);
+            /* raise all the windows that are on the current desktop which
+               is being merged */
+            else if (screen_desktop == num - 1 &&
+                     (c->desktop == DESKTOP_ALL ||
+                      c->desktop == screen_desktop))
+                stacking_raise(CLIENT_AS_WINDOW(c));
+        }
     }
  
     /* change our struts/area to match (after moving windows) */
@@ -561,7 +575,7 @@ void screen_set_desktop(guint num, gboolean dofocus)
     ignore_start = event_start_ignore_all_enters();
 
     if (moveresize_client)
-        client_set_desktop(moveresize_client, num, TRUE);
+        client_set_desktop(moveresize_client, num, TRUE, FALSE);
 
     /* show windows before hiding the rest to lessen the enter/leave events */
 
@@ -579,6 +593,11 @@ void screen_set_desktop(guint num, gboolean dofocus)
     allow_omni = focus_client && (client_normal(focus_client) &&
                                   focus_client->desktop == DESKTOP_ALL);
 
+    /* the client moved there already so don't move focus. prevent flicker
+       on sendtodesktop + follow */
+    if (focus_client && focus_client->desktop == screen_desktop)
+        dofocus = FALSE;
+
     /* have to try focus here because when you leave an empty desktop
        there is no focus out to watch for. also, we have different rules
        here. we always allow it to look under the mouse pointer if
@@ -616,6 +635,72 @@ void screen_set_desktop(guint num, gboolean dofocus)
         screen_desktop_user_time = event_curtime;
 }
 
+void screen_add_desktop(gboolean current)
+{
+    screen_set_num_desktops(screen_num_desktops+1);
+
+    /* move all the clients over */
+    if (current) {
+        GList *it;
+
+        for (it = client_list; it; it = g_list_next(it)) {
+            ObClient *c = it->data;
+            if (c->desktop != DESKTOP_ALL && c->desktop >= screen_desktop)
+                client_set_desktop(c, c->desktop+1, FALSE, TRUE);
+        }
+    }
+}
+
+void screen_remove_desktop(gboolean current)
+{
+    guint rmdesktop, movedesktop;
+    GList *it, *stacking_copy;
+
+    if (screen_num_desktops <= 1) return;
+
+    /* what desktop are we removing and moving to? */
+    if (current)
+        rmdesktop = screen_desktop;
+    else
+        rmdesktop = screen_num_desktops - 1;
+    if (rmdesktop < screen_num_desktops - 1)
+        movedesktop = rmdesktop + 1;
+    else
+        movedesktop = rmdesktop;
+
+    /* make a copy of the list cuz we're changing it */
+    stacking_copy = g_list_copy(stacking_list);
+    for (it = g_list_last(stacking_copy); it; it = g_list_previous(it)) {
+        if (WINDOW_IS_CLIENT(it->data)) {
+            ObClient *c = it->data;
+            guint d = c->desktop;
+            if (d != DESKTOP_ALL && d >= movedesktop) {
+                client_set_desktop(c, c->desktop - 1, TRUE, TRUE);
+                ob_debug("moving window %s\n", c->title);
+            }
+            /* raise all the windows that are on the current desktop which
+               is being merged */
+            if ((screen_desktop == rmdesktop - 1 ||
+                 screen_desktop == rmdesktop) &&
+                (d == DESKTOP_ALL || d == screen_desktop))
+            {
+                stacking_raise(CLIENT_AS_WINDOW(c));
+                ob_debug("raising window %s\n", c->title);
+            }
+        }
+    }
+
+    /* act like we're changing desktops */
+    if (screen_desktop < screen_num_desktops - 1) {
+        gint d = screen_desktop;
+        screen_desktop = screen_last_desktop;
+        screen_set_desktop(d, TRUE);
+        ob_debug("fake desktop change\n");
+    }
+
+    screen_set_num_desktops(screen_num_desktops-1);
+}
+
 static void get_row_col(guint d, guint *r, guint *c)
 {
     switch (screen_desktop_layout.orientation) {
@@ -745,22 +830,14 @@ void screen_desktop_popup(guint d, gboolean show)
     }
 }
 
-guint screen_cycle_desktop(ObDirection dir, gboolean wrap, gboolean linear,
-                           gboolean dialog, gboolean done, gboolean cancel)
+guint screen_find_desktop(guint from, ObDirection dir,
+                          gboolean wrap, gboolean linear)
 {
     guint r, c;
-    static guint d = (guint)-1;
-    guint ret, oldd;
+    guint d;
 
-    if (d == (guint)-1)
-        d = screen_desktop;
-
-    if ((cancel || done) && dialog)
-        goto show_cycle_dialog;
-
-    oldd = d;
+    d = from;
     get_row_col(d, &r, &c);
-
     if (linear) {
         switch (dir) {
         case OB_DIRECTION_EAST:
@@ -768,16 +845,20 @@ guint screen_cycle_desktop(ObDirection dir, gboolean wrap, gboolean linear,
                 ++d;
             else if (wrap)
                 d = 0;
+            else
+                return from;
             break;
         case OB_DIRECTION_WEST:
             if (d > 0)
                 --d;
             else if (wrap)
                 d = screen_num_desktops - 1;
+            else
+                return from;
             break;
         default:
-            assert(0);
-            return screen_desktop;
+            g_assert_not_reached();
+            return from;
         }
     } else {
         switch (dir) {
@@ -787,16 +868,14 @@ guint screen_cycle_desktop(ObDirection dir, gboolean wrap, gboolean linear,
                 if (wrap)
                     c = 0;
                 else
-                    goto show_cycle_dialog;
+                    return from;
             }
             d = translate_row_col(r, c);
             if (d >= screen_num_desktops) {
-                if (wrap) {
+                if (wrap)
                     ++c;
-                } else {
-                    d = oldd;
-                    goto show_cycle_dialog;
-                }
+                else
+                    return from;
             }
             break;
         case OB_DIRECTION_WEST:
@@ -805,16 +884,14 @@ guint screen_cycle_desktop(ObDirection dir, gboolean wrap, gboolean linear,
                 if (wrap)
                     c = screen_desktop_layout.columns - 1;
                 else
-                    goto show_cycle_dialog;
+                    return from;
             }
             d = translate_row_col(r, c);
             if (d >= screen_num_desktops) {
-                if (wrap) {
+                if (wrap)
                     --c;
-                } else {
-                    d = oldd;
-                    goto show_cycle_dialog;
-                }
+                else
+                    return from;
             }
             break;
         case OB_DIRECTION_SOUTH:
@@ -823,16 +900,14 @@ guint screen_cycle_desktop(ObDirection dir, gboolean wrap, gboolean linear,
                 if (wrap)
                     r = 0;
                 else
-                    goto show_cycle_dialog;
+                    return from;
             }
             d = translate_row_col(r, c);
             if (d >= screen_num_desktops) {
-                if (wrap) {
+                if (wrap)
                     ++r;
-                } else {
-                    d = oldd;
-                    goto show_cycle_dialog;
-                }
+                else
+                    return from;
             }
             break;
         case OB_DIRECTION_NORTH:
@@ -841,30 +916,41 @@ guint screen_cycle_desktop(ObDirection dir, gboolean wrap, gboolean linear,
                 if (wrap)
                     r = screen_desktop_layout.rows - 1;
                 else
-                    goto show_cycle_dialog;
+                    return from;
             }
             d = translate_row_col(r, c);
             if (d >= screen_num_desktops) {
-                if (wrap) {
+                if (wrap)
                     --r;
-                } else {
-                    d = oldd;
-                    goto show_cycle_dialog;
-                }
+                else
+                    return from;
             }
             break;
         default:
-            assert(0);
-            return d = screen_desktop;
+            g_assert_not_reached();
+            return from;
         }
 
         d = translate_row_col(r, c);
     }
+    return d;
+}
+
+guint screen_cycle_desktop(ObDirection dir, gboolean wrap, gboolean linear,
+                           gboolean dialog, gboolean done, gboolean cancel)
+{
+    static guint d = (guint)-1;
+    guint ret;
+
+    if (d == (guint)-1)
+        d = screen_desktop;
+
+    if ((!cancel && !done) || !dialog)
+        d = screen_find_desktop(d, dir, wrap, linear);
 
-show_cycle_dialog:
-    if (dialog && !cancel && !done) {
+    if (dialog && !cancel && !done)
         screen_desktop_popup(d, TRUE);
-    else
+    else
         screen_desktop_popup(0, FALSE);
     ret = d;
 
@@ -1107,13 +1193,10 @@ typedef struct {
 
 #define ADD_STRUT_TO_LIST(sl, d, s) \
 { \
-    for (i = 0; i < screen_num_desktops; ++i) \
-        if (i == d || d == DESKTOP_ALL) { \
-            ObScreenStrut *ss = g_new(ObScreenStrut, 1); \
-            ss->desktop = i; \
-            ss->strut = s;  \
-            sl = g_slist_prepend(sl, ss); \
-        } \
+    ObScreenStrut *ss = g_new(ObScreenStrut, 1); \
+    ss->desktop = d; \
+    ss->strut = s;  \
+    sl = g_slist_prepend(sl, ss); \
 }
 
 void screen_update_areas()
@@ -1174,22 +1257,26 @@ void screen_update_areas()
 
             for (sit = struts_left; sit; sit = g_slist_next(sit)) {
                 ObScreenStrut *s = sit->data;
-                if (s->desktop == j && STRUT_LEFT_ON_MONITOR(s->strut, i))
+                if ((s->desktop == j || s->desktop == DESKTOP_ALL) &&
+                    STRUT_LEFT_ON_MONITOR(s->strut, i))
                     l = MAX(l, s->strut->left);
             }
             for (sit = struts_top; sit; sit = g_slist_next(sit)) {
                 ObScreenStrut *s = sit->data;
-                if (s->desktop == j && STRUT_TOP_ON_MONITOR(s->strut, i))
+                if ((s->desktop == j || s->desktop == DESKTOP_ALL) &&
+                    STRUT_TOP_ON_MONITOR(s->strut, i))
                     t = MAX(t, s->strut->top);
             }
             for (sit = struts_right; sit; sit = g_slist_next(sit)) {
                 ObScreenStrut *s = sit->data;
-                if (s->desktop == j && STRUT_RIGHT_ON_MONITOR(s->strut, i))
+                if ((s->desktop == j || s->desktop == DESKTOP_ALL) &&
+                    STRUT_RIGHT_ON_MONITOR(s->strut, i))
                     r = MAX(r, s->strut->right);
             }
             for (sit = struts_bottom; sit; sit = g_slist_next(sit)) {
                 ObScreenStrut *s = sit->data;
-                if (s->desktop == j && STRUT_BOTTOM_ON_MONITOR(s->strut, i))
+                if ((s->desktop == j || s->desktop == DESKTOP_ALL) &&
+                    STRUT_BOTTOM_ON_MONITOR(s->strut, i))
                     b = MAX(b, s->strut->bottom);
             }
 
@@ -1205,20 +1292,8 @@ void screen_update_areas()
                 dims, 4 * screen_num_desktops * screen_num_monitors);
 
     /* the area has changed, adjust all the windows if they need it */
-    for (it = client_list; it; it = g_list_next(it)) {
-        gint x, y, w, h, lw, lh;
-        ObClient *client = it->data;
-
-        RECT_TO_DIMS(client->area, x, y, w, h);
-        client_try_configure(client, &x, &y, &w, &h, &lw, &lh, FALSE);
-        if (!RECT_EQUAL_DIMS(client->area, x, y, w, h)) {
-            gulong ignore_start;
-
-            ignore_start = event_start_ignore_all_enters();
-            client_configure(client, x, y, w, h, FALSE, TRUE);
-            event_end_ignore_all_enters(ignore_start);
-        }
-    }
+    for (it = client_list; it; it = g_list_next(it))
+        client_reconfigure(it->data, FALSE);
 
     g_free(dims);
 }
@@ -1264,16 +1339,16 @@ Rect* screen_area_all_monitors(guint desktop)
                       s->bottom_start, s->bottom_end - s->bottom_start + 1))
 
 #define STRUT_LEFT_IGNORE(s, us, search) \
-    (head != SCREEN_AREA_ALL_MONITORS || !us || \
+    (head == SCREEN_AREA_ALL_MONITORS && us && \
      RECT_LEFT(monitor_area[i]) + s->left > RECT_LEFT(*search))
 #define STRUT_RIGHT_IGNORE(s, us, search) \
-    (head != SCREEN_AREA_ALL_MONITORS || !us || \
+    (head == SCREEN_AREA_ALL_MONITORS && us && \
      RECT_RIGHT(monitor_area[i]) - s->right < RECT_RIGHT(*search))
 #define STRUT_TOP_IGNORE(s, us, search) \
-    (head != SCREEN_AREA_ALL_MONITORS || !us || \
+    (head == SCREEN_AREA_ALL_MONITORS && us && \
      RECT_TOP(monitor_area[i]) + s->top > RECT_TOP(*search))
 #define STRUT_BOTTOM_IGNORE(s, us, search) \
-    (head != SCREEN_AREA_ALL_MONITORS || !us || \
+    (head == SCREEN_AREA_ALL_MONITORS && us && \
      RECT_BOTTOM(monitor_area[i]) - s->bottom < RECT_BOTTOM(*search))
 
 Rect* screen_area(guint desktop, guint head, Rect *search)
@@ -1340,31 +1415,31 @@ Rect* screen_area(guint desktop, guint head, Rect *search)
 
             for (it = struts_left; it; it = g_slist_next(it)) {
                 ObScreenStrut *s = it->data;
-                if (s->desktop == d &&
+                if ((s->desktop == d || s->desktop == DESKTOP_ALL) &&
                     STRUT_LEFT_IN_SEARCH(s->strut, search) &&
                     !STRUT_LEFT_IGNORE(s->strut, us, search))
                     l = MAX(l, al + s->strut->left);
             }
             for (it = struts_top; it; it = g_slist_next(it)) {
                 ObScreenStrut *s = it->data;
-                if (s->desktop == d &&
+                if ((s->desktop == d || s->desktop == DESKTOP_ALL) &&
                     STRUT_TOP_IN_SEARCH(s->strut, search) &&
                     !STRUT_TOP_IGNORE(s->strut, us, search))
-                    t = MAX(t, al + s->strut->top);
+                    t = MAX(t, at + s->strut->top);
             }
             for (it = struts_right; it; it = g_slist_next(it)) {
                 ObScreenStrut *s = it->data;
-                if (s->desktop == d &&
+                if ((s->desktop == d || s->desktop == DESKTOP_ALL) &&
                     STRUT_RIGHT_IN_SEARCH(s->strut, search) &&
                     !STRUT_RIGHT_IGNORE(s->strut, us, search))
                     r = MIN(r, ar - s->strut->right);
             }
             for (it = struts_bottom; it; it = g_slist_next(it)) {
                 ObScreenStrut *s = it->data;
-                if (s->desktop == d &&
+                if ((s->desktop == d || s->desktop == DESKTOP_ALL) &&
                     STRUT_BOTTOM_IN_SEARCH(s->strut, search) &&
                     !STRUT_BOTTOM_IGNORE(s->strut, us, search))
-                    b = MIN(b, ar - s->strut->bottom);
+                    b = MIN(b, ab - s->strut->bottom);
             }
 
             /* limit to this monitor */
This page took 0.037778 seconds and 4 git commands to generate.