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.

https://bugzilla.gnome.org/show_bug.cgi?id=645153
This commit is contained in:
Florian Müllner 2017-09-27 14:53:54 +02:00 committed by Georges Basile Stavracas Neto
parent 56f1da5c66
commit 8f2c86d79e
6 changed files with 32 additions and 24 deletions

View File

@ -943,7 +943,7 @@ constrain_maximization (MetaWindow *window,
/* Calculate target_size = maximized size of (window + frame) */ /* Calculate target_size = maximized size of (window + frame) */
if (META_WINDOW_TILED_MAXIMIZED (window)) 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)) 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 /* Calculate target_size - as the tile previews need this as well, we
* use an external function for the actual calculation * 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 /* Check min size constraints; max size constraints are ignored as for
* maximized windows. * maximized windows.

View File

@ -2222,7 +2222,7 @@ process_mouse_move_resize_grab (MetaDisplay *display,
if (event->keyval == CLUTTER_KEY_Escape) if (event->keyval == CLUTTER_KEY_Escape)
{ {
/* Hide the tiling preview if necessary */ /* 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); meta_screen_hide_tile_preview (screen);
/* Restore the original tile mode */ /* Restore the original tile mode */

View File

@ -56,6 +56,7 @@ struct _MetaScreen
MetaUI *ui; MetaUI *ui;
guint tile_preview_timeout_id; guint tile_preview_timeout_id;
guint preview_tile_mode : 2;
MetaWorkspace *active_workspace; MetaWorkspace *active_workspace;

View File

@ -1414,7 +1414,7 @@ meta_screen_update_tile_preview_timeout (gpointer data)
if (window) if (window)
{ {
switch (window->tile_mode) switch (screen->preview_tile_mode)
{ {
case META_TILE_LEFT: case META_TILE_LEFT:
case META_TILE_RIGHT: case META_TILE_RIGHT:
@ -1439,7 +1439,7 @@ meta_screen_update_tile_preview_timeout (gpointer data)
int monitor; int monitor;
monitor = meta_window_get_current_tile_monitor_number (window); 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, meta_compositor_show_tile_preview (screen->display->compositor,
window, &tile_rect, monitor); window, &tile_rect, monitor);
} }
@ -1483,6 +1483,7 @@ meta_screen_hide_tile_preview (MetaScreen *screen)
g_source_remove (screen->tile_preview_timeout_id); g_source_remove (screen->tile_preview_timeout_id);
screen->tile_preview_timeout_id = 0; screen->tile_preview_timeout_id = 0;
screen->preview_tile_mode = META_TILE_NONE;
meta_compositor_hide_tile_preview (screen->display->compositor); meta_compositor_hide_tile_preview (screen->display->compositor);
} }

View File

@ -199,9 +199,7 @@ struct _MetaWindow
guint maximize_vertically_after_placement : 1; guint maximize_vertically_after_placement : 1;
guint minimize_after_placement : 1; guint minimize_after_placement : 1;
/* The current or requested tile mode. If maximized_vertically is true, /* The current tile mode */
* this is the current mode. If not, it is the mode which will be
* requested after the window grab is released */
guint tile_mode : 2; guint tile_mode : 2;
/* The last "full" maximized/unmaximized state. We need to keep track of /* The last "full" maximized/unmaximized state. We need to keep track of
* that to toggle between normal/tiled or maximized/tiled states. */ * 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); MetaRectangle *area);
int meta_window_get_current_tile_monitor_number (MetaWindow *window); int meta_window_get_current_tile_monitor_number (MetaWindow *window);
void meta_window_get_current_tile_area (MetaWindow *window, void meta_window_get_tile_area (MetaWindow *window,
MetaRectangle *tile_area); MetaTileMode mode,
MetaRectangle *tile_area);
gboolean meta_window_same_application (MetaWindow *window, gboolean meta_window_same_application (MetaWindow *window,

View File

@ -3102,6 +3102,9 @@ meta_window_unmaximize (MetaWindow *window,
meta_window_get_frame_rect (window, &old_frame_rect); meta_window_get_frame_rect (window, &old_frame_rect);
meta_window_get_buffer_rect (window, &old_buffer_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, meta_topic (META_DEBUG_WINDOW_OPS,
"Unmaximizing %s%s\n", "Unmaximizing %s%s\n",
window->desc, window->desc,
@ -5713,6 +5716,7 @@ update_move_maybe_tile (MetaWindow *window,
MetaMonitorManager *monitor_manager = MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend); meta_backend_get_monitor_manager (backend);
MetaLogicalMonitor *logical_monitor; MetaLogicalMonitor *logical_monitor;
MetaScreen *screen = window->screen;
MetaRectangle work_area; MetaRectangle work_area;
/* For side-by-side tiling we are interested in the inside vertical /* For side-by-side tiling we are interested in the inside vertical
@ -5742,18 +5746,18 @@ update_move_maybe_tile (MetaWindow *window,
*/ */
if (meta_window_can_tile_side_by_side (window) && if (meta_window_can_tile_side_by_side (window) &&
x >= logical_monitor->rect.x && x < (work_area.x + shake_threshold)) 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) && else if (meta_window_can_tile_side_by_side (window) &&
x >= work_area.x + work_area.width - shake_threshold && x >= work_area.x + work_area.width - shake_threshold &&
x < (logical_monitor->rect.x + logical_monitor->rect.width)) 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) && else if (meta_window_can_tile_maximized (window) &&
y >= logical_monitor->rect.y && y <= work_area.y) y >= logical_monitor->rect.y && y <= work_area.y)
window->tile_mode = META_TILE_MAXIMIZED; screen->preview_tile_mode = META_TILE_MAXIMIZED;
else 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; window->tile_monitor_number = logical_monitor->number;
} }
@ -5768,6 +5772,7 @@ update_move (MetaWindow *window,
MetaRectangle old; MetaRectangle old;
int shake_threshold; int shake_threshold;
MetaDisplay *display = window->display; MetaDisplay *display = window->display;
MetaScreen *screen = window->screen;
display->grab_latest_motion_x = x; display->grab_latest_motion_x = x;
display->grab_latest_motion_y = y; display->grab_latest_motion_y = y;
@ -5805,7 +5810,7 @@ update_move (MetaWindow *window,
{ {
/* We don't want to tile while snapping. Also, clear any previous tile /* We don't want to tile while snapping. Also, clear any previous tile
request. */ request. */
window->tile_mode = META_TILE_NONE; screen->preview_tile_mode = META_TILE_NONE;
window->tile_monitor_number = -1; window->tile_monitor_number = -1;
} }
else if (meta_prefs_get_edge_tiling () && else if (meta_prefs_get_edge_tiling () &&
@ -5921,8 +5926,8 @@ update_move (MetaWindow *window,
* trigger it unwittingly, e.g. when shaking loose the window or moving * trigger it unwittingly, e.g. when shaking loose the window or moving
* it to another monitor. * it to another monitor.
*/ */
meta_screen_update_tile_preview (window->screen, meta_screen_update_tile_preview (screen,
window->tile_mode != META_TILE_NONE); screen->preview_tile_mode != META_TILE_NONE);
meta_window_get_frame_rect (window, &old); meta_window_get_frame_rect (window, &old);
@ -6118,6 +6123,7 @@ end_grab_op (MetaWindow *window,
{ {
if (meta_grab_op_is_moving (window->display->grab_op)) 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) if (window->tile_mode != META_TILE_NONE)
meta_window_tile (window); meta_window_tile (window);
else else
@ -6133,6 +6139,7 @@ end_grab_op (MetaWindow *window,
TRUE); TRUE);
} }
} }
window->screen->preview_tile_mode = META_TILE_NONE;
meta_display_end_grab_op (window->display, clutter_event_get_time (event)); meta_display_end_grab_op (window->display, clutter_event_get_time (event));
} }
@ -6336,22 +6343,22 @@ meta_window_get_current_tile_monitor_number (MetaWindow *window)
} }
void void
meta_window_get_current_tile_area (MetaWindow *window, meta_window_get_tile_area (MetaWindow *window,
MetaRectangle *tile_area) MetaTileMode tile_mode,
MetaRectangle *tile_area)
{ {
int tile_monitor_number; 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); tile_monitor_number = meta_window_get_current_tile_monitor_number (window);
meta_window_get_work_area_for_monitor (window, tile_monitor_number, tile_area); meta_window_get_work_area_for_monitor (window, tile_monitor_number, tile_area);
if (window->tile_mode == META_TILE_LEFT || if (tile_mode == META_TILE_LEFT || tile_mode == META_TILE_RIGHT)
window->tile_mode == META_TILE_RIGHT)
tile_area->width /= 2; tile_area->width /= 2;
if (window->tile_mode == META_TILE_RIGHT) if (tile_mode == META_TILE_RIGHT)
tile_area->x += tile_area->width; tile_area->x += tile_area->width;
} }