[mutter/wip/fmuellner/contraint-tiling: 3/15] window: Split out preview_tile_mode



commit a2fd90d0befce2b7913daa2b12885b83ca36a219
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Sep 27 14:53:54 2017 +0200

    window: Split out preview_tile_mode
    
    The existing semantics of the tile_mode property are terribly confusing,
    as it depends on some other property whether it represents the requested
    or current mode. Clear this up by just using separate variables for the
    two. As it is unlikely that we will ever support more than one tile
    preview, we can track the requested mode globally instead of adding
    another per-window variable.

 src/core/constraints.c    |    4 ++--
 src/core/keybindings.c    |    2 +-
 src/core/screen-private.h |    1 +
 src/core/screen.c         |    5 +++--
 src/core/window-private.h |    9 ++++-----
 src/core/window.c         |   35 +++++++++++++++++++++--------------
 6 files changed, 32 insertions(+), 24 deletions(-)
---
diff --git a/src/core/constraints.c b/src/core/constraints.c
index 14044a9..f5360ef 100644
--- a/src/core/constraints.c
+++ b/src/core/constraints.c
@@ -943,7 +943,7 @@ constrain_maximization (MetaWindow         *window,
   /* Calculate target_size = maximized size of (window + frame) */
   if (META_WINDOW_TILED_MAXIMIZED (window))
     {
-      meta_window_get_current_tile_area (window, &target_size);
+      meta_window_get_tile_area (window, window->tile_mode, &target_size);
     }
   else if (META_WINDOW_MAXIMIZED (window))
     {
@@ -1030,7 +1030,7 @@ constrain_tiling (MetaWindow         *window,
   /* Calculate target_size - as the tile previews need this as well, we
    * use an external function for the actual calculation
    */
-  meta_window_get_current_tile_area (window, &target_size);
+  meta_window_get_tile_area (window, window->tile_mode, &target_size);
 
   /* Check min size constraints; max size constraints are ignored as for
    * maximized windows.
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index 41becb6..bbf9872 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -2222,7 +2222,7 @@ process_mouse_move_resize_grab (MetaDisplay     *display,
   if (event->keyval == CLUTTER_KEY_Escape)
     {
       /* Hide the tiling preview if necessary */
-      if (window->tile_mode != META_TILE_NONE)
+      if (screen->preview_tile_mode != META_TILE_NONE)
         meta_screen_hide_tile_preview (screen);
 
       /* Restore the original tile mode */
diff --git a/src/core/screen-private.h b/src/core/screen-private.h
index df14699..ff796f0 100644
--- a/src/core/screen-private.h
+++ b/src/core/screen-private.h
@@ -56,6 +56,7 @@ struct _MetaScreen
   MetaUI *ui;
 
   guint tile_preview_timeout_id;
+  guint preview_tile_mode : 2;
 
   MetaWorkspace *active_workspace;
 
diff --git a/src/core/screen.c b/src/core/screen.c
index c96aefd..e6c6cdd 100644
--- a/src/core/screen.c
+++ b/src/core/screen.c
@@ -1410,7 +1410,7 @@ meta_screen_update_tile_preview_timeout (gpointer data)
 
   if (window)
     {
-      switch (window->tile_mode)
+      switch (screen->preview_tile_mode)
         {
           case META_TILE_LEFT:
           case META_TILE_RIGHT:
@@ -1435,7 +1435,7 @@ meta_screen_update_tile_preview_timeout (gpointer data)
       int monitor;
 
       monitor = meta_window_get_current_tile_monitor_number (window);
-      meta_window_get_current_tile_area (window, &tile_rect);
+      meta_window_get_tile_area (window, screen->preview_tile_mode, &tile_rect);
       meta_compositor_show_tile_preview (screen->display->compositor,
                                          window, &tile_rect, monitor);
     }
@@ -1479,6 +1479,7 @@ meta_screen_hide_tile_preview (MetaScreen *screen)
     g_source_remove (screen->tile_preview_timeout_id);
   screen->tile_preview_timeout_id = 0;
 
+  screen->preview_tile_mode = META_TILE_NONE;
   meta_compositor_hide_tile_preview (screen->display->compositor);
 }
 
diff --git a/src/core/window-private.h b/src/core/window-private.h
index c3a1c02..d50beae 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -199,9 +199,7 @@ struct _MetaWindow
   guint maximize_vertically_after_placement : 1;
   guint minimize_after_placement : 1;
 
-  /* The current or requested tile mode. If maximized_vertically is true,
-   * this is the current mode. If not, it is the mode which will be
-   * requested after the window grab is released */
+  /* The current tile mode */
   guint tile_mode : 2;
   /* The last "full" maximized/unmaximized state. We need to keep track of
    * that to toggle between normal/tiled or maximized/tiled states. */
@@ -648,8 +646,9 @@ void meta_window_get_work_area_for_logical_monitor (MetaWindow         *window,
                                                     MetaRectangle      *area);
 
 int meta_window_get_current_tile_monitor_number (MetaWindow *window);
-void meta_window_get_current_tile_area         (MetaWindow    *window,
-                                                MetaRectangle *tile_area);
+void meta_window_get_tile_area                  (MetaWindow    *window,
+                                                 MetaTileMode   mode,
+                                                 MetaRectangle *tile_area);
 
 
 gboolean meta_window_same_application (MetaWindow *window,
diff --git a/src/core/window.c b/src/core/window.c
index 1a0474c..18d1e7b 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -3096,6 +3096,9 @@ meta_window_unmaximize (MetaWindow        *window,
       meta_window_get_frame_rect (window, &old_frame_rect);
       meta_window_get_buffer_rect (window, &old_buffer_rect);
 
+      if (unmaximize_vertically)
+        window->tile_mode = META_TILE_NONE;
+
       meta_topic (META_DEBUG_WINDOW_OPS,
                   "Unmaximizing %s%s\n",
                   window->desc,
@@ -5707,6 +5710,7 @@ update_move_maybe_tile (MetaWindow *window,
   MetaMonitorManager *monitor_manager =
     meta_backend_get_monitor_manager (backend);
   MetaLogicalMonitor *logical_monitor;
+  MetaScreen *screen = window->screen;
   MetaRectangle work_area;
 
   /* For side-by-side tiling we are interested in the inside vertical
@@ -5736,18 +5740,18 @@ update_move_maybe_tile (MetaWindow *window,
    */
   if (meta_window_can_tile_side_by_side (window) &&
       x >= logical_monitor->rect.x && x < (work_area.x + shake_threshold))
-    window->tile_mode = META_TILE_LEFT;
+    screen->preview_tile_mode = META_TILE_LEFT;
   else if (meta_window_can_tile_side_by_side (window) &&
            x >= work_area.x + work_area.width - shake_threshold &&
            x < (logical_monitor->rect.x + logical_monitor->rect.width))
-    window->tile_mode = META_TILE_RIGHT;
+    screen->preview_tile_mode = META_TILE_RIGHT;
   else if (meta_window_can_tile_maximized (window) &&
            y >= logical_monitor->rect.y && y <= work_area.y)
-    window->tile_mode = META_TILE_MAXIMIZED;
+    screen->preview_tile_mode = META_TILE_MAXIMIZED;
   else
-    window->tile_mode = META_TILE_NONE;
+    screen->preview_tile_mode = META_TILE_NONE;
 
-  if (window->tile_mode != META_TILE_NONE)
+  if (screen->preview_tile_mode != META_TILE_NONE)
     window->tile_monitor_number = logical_monitor->number;
 }
 
@@ -5762,6 +5766,7 @@ update_move (MetaWindow  *window,
   MetaRectangle old;
   int shake_threshold;
   MetaDisplay *display = window->display;
+  MetaScreen *screen = window->screen;
 
   display->grab_latest_motion_x = x;
   display->grab_latest_motion_y = y;
@@ -5799,7 +5804,7 @@ update_move (MetaWindow  *window,
     {
       /* We don't want to tile while snapping. Also, clear any previous tile
          request. */
-      window->tile_mode = META_TILE_NONE;
+      screen->preview_tile_mode = META_TILE_NONE;
       window->tile_monitor_number = -1;
     }
   else if (meta_prefs_get_edge_tiling () &&
@@ -5915,8 +5920,8 @@ update_move (MetaWindow  *window,
    * trigger it unwittingly, e.g. when shaking loose the window or moving
    * it to another monitor.
    */
-  meta_screen_update_tile_preview (window->screen,
-                                   window->tile_mode != META_TILE_NONE);
+  meta_screen_update_tile_preview (screen,
+                                   screen->preview_tile_mode != META_TILE_NONE);
 
   meta_window_get_frame_rect (window, &old);
 
@@ -6112,6 +6117,7 @@ end_grab_op (MetaWindow *window,
     {
       if (meta_grab_op_is_moving (window->display->grab_op))
         {
+          window->tile_mode = window->screen->preview_tile_mode;
           if (window->tile_mode != META_TILE_NONE)
             meta_window_tile (window);
           else
@@ -6127,6 +6133,7 @@ end_grab_op (MetaWindow *window,
                          TRUE);
         }
     }
+  window->screen->preview_tile_mode = META_TILE_NONE;
   meta_display_end_grab_op (window->display, clutter_event_get_time (event));
 }
 
@@ -6330,22 +6337,22 @@ meta_window_get_current_tile_monitor_number (MetaWindow *window)
 }
 
 void
-meta_window_get_current_tile_area (MetaWindow    *window,
-                                   MetaRectangle *tile_area)
+meta_window_get_tile_area (MetaWindow    *window,
+                           MetaTileMode   tile_mode,
+                           MetaRectangle *tile_area)
 {
   int tile_monitor_number;
 
-  g_return_if_fail (window->tile_mode != META_TILE_NONE);
+  g_return_if_fail (tile_mode != META_TILE_NONE);
 
   tile_monitor_number = meta_window_get_current_tile_monitor_number (window);
 
   meta_window_get_work_area_for_monitor (window, tile_monitor_number, tile_area);
 
-  if (window->tile_mode == META_TILE_LEFT  ||
-      window->tile_mode == META_TILE_RIGHT)
+  if (tile_mode == META_TILE_LEFT  || tile_mode == META_TILE_RIGHT)
     tile_area->width /= 2;
 
-  if (window->tile_mode == META_TILE_RIGHT)
+  if (tile_mode == META_TILE_RIGHT)
     tile_area->x += tile_area->width;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]