Skip to content

Commit 84a91d9

Browse files
committed
tiling: Disable drag-to-maximize behavior if tiling is disabled,
fix drag re-tile/maximize behavior in all scenarios. - Prevent any drag-and-drop tiling when tiling is disabled (including maximize). - Fix tiling restoration when dragging, and original window size memory. - Partially reverts 696c587
1 parent c2c62e7 commit 84a91d9

File tree

3 files changed

+96
-34
lines changed

3 files changed

+96
-34
lines changed

src/core/keybindings.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,7 +2422,7 @@ process_mouse_move_resize_grab (MetaDisplay *display,
24222422
* need to remaximize it. In normal cases, we need to do a
24232423
* moveresize now to get the position back to the original.
24242424
*/
2425-
if (window->saved_maximize || tile_mode == META_TILE_MAXIMIZED)
2425+
if (window->saved_tile_mode == META_TILE_MAXIMIZED)
24262426
meta_window_maximize (window, META_MAXIMIZE_BOTH);
24272427
else if (tile_mode != META_TILE_NONE)
24282428
meta_window_restore_tile (window,
@@ -2498,7 +2498,7 @@ process_keyboard_move_grab (MetaDisplay *display,
24982498
* remaximize it. In normal cases, we need to do a moveresize
24992499
* now to get the position back to the original.
25002500
*/
2501-
if (window->saved_maximize)
2501+
if (window->saved_tile_mode == META_TILE_MAXIMIZED)
25022502
meta_window_maximize (window, META_MAXIMIZE_BOTH);
25032503
else
25042504
if (tile_mode != META_TILE_NONE)

src/core/window-private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ struct _MetaWindow
243243
MetaTileMode tile_mode;
244244

245245
/* The last "full" maximized/unmaximized state. We need to keep track of
246-
* that to decide whether to tile-top or restore maximization during a drag. */
247-
guint saved_maximize : 1;
246+
* that to toggle between normal/tiled or maximized/tiled states. */
247+
MetaTileMode saved_tile_mode;
248248
int tile_monitor_number;
249249

250250
struct {

src/core/window.c

Lines changed: 92 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2898,7 +2898,10 @@ meta_window_maximize_internal (MetaWindow *window,
28982898
else
28992899
meta_window_save_rect (window);
29002900

2901-
window->saved_maximize = maximize_horizontally && maximize_vertically;
2901+
if (maximize_horizontally && maximize_vertically)
2902+
window->saved_tile_mode = META_TILE_MAXIMIZED;
2903+
else
2904+
window->saved_tile_mode = window->tile_mode;
29022905

29032906
window->maximized_horizontally =
29042907
window->maximized_horizontally || maximize_horizontally;
@@ -2966,7 +2969,7 @@ meta_window_maximize (MetaWindow *window,
29662969
gboolean from_tiled = FALSE;
29672970
MetaRectangle resize_rect;
29682971

2969-
if (window->tile_mode != META_TILE_NONE)
2972+
if (META_WINDOW_MAXIMIZED (window) || META_WINDOW_TILED (window))
29702973
{
29712974
saved_rect = &window->saved_rect;
29722975

@@ -3403,7 +3406,6 @@ meta_window_tile (MetaWindow *window,
34033406
{
34043407
MetaMaximizeFlags directions;
34053408
MetaRectangle old_frame_rect, old_buffer_rect;
3406-
gboolean was_already_tiled = window->tile_mode != META_TILE_NONE || META_WINDOW_MAXIMIZED (window);
34073409
/* Maximization constraints beat tiling constraints, so if the window
34083410
* is maximized, tiling won't have any effect unless we unmaximize it
34093411
* horizontally first; rather than calling meta_window_unmaximize(),
@@ -3431,12 +3433,14 @@ meta_window_tile (MetaWindow *window,
34313433

34323434
GdkRectangle *maybe_saved_rect = NULL;
34333435

3434-
if (window->display->grab_op != META_GRAB_OP_NONE)
3436+
if (window->saved_tile_mode == META_TILE_NONE && window->display->grab_op != META_GRAB_OP_NONE)
34353437
{
3438+
// If we let it save the current rect when initially tiling, the rect position
3439+
// may end up on a different monitor (depending on where the grab anchor is positioned).
34363440
maybe_saved_rect = &window->display->grab_initial_window_pos;
34373441
}
34383442
else
3439-
if (was_already_tiled)
3443+
if (window->saved_tile_mode != META_TILE_NONE)
34403444
{
34413445
maybe_saved_rect = &window->saved_rect;
34423446
}
@@ -3586,10 +3590,8 @@ meta_window_unmaximize (MetaWindow *window,
35863590
unmaximize_vertically = directions & META_MAXIMIZE_VERTICAL;
35873591
g_assert (unmaximize_horizontally || unmaximize_vertically);
35883592

3589-
// Window can be unmaximized (temporarily) during a drag, but saved_maximize should be preserved
3590-
// in case we're to restore a previously maximized window (ignoring the tile_maximize pref).
3591-
if (unmaximize_horizontally && unmaximize_vertically && (window->display->grab_op == META_GRAB_OP_NONE))
3592-
window->saved_maximize = FALSE;
3593+
if (unmaximize_vertically && window->display->grab_op == META_GRAB_OP_NONE)
3594+
window->saved_tile_mode = META_TILE_NONE;
35933595

35943596
/* Only do something if the window isn't already maximized in the
35953597
* given direction(s).
@@ -6438,21 +6440,6 @@ update_move_maybe_tile (MetaWindow *window,
64386440
logical_monitor->number,
64396441
&work_area);
64406442

6441-
if (!meta_prefs_get_edge_tiling ())
6442-
{
6443-
if ((get_tile_zone_at_pointer (window, logical_monitor, work_area, x, y) == ZONE_TOP) && meta_window_can_maximize (window))
6444-
{
6445-
display->preview_tile_mode = META_TILE_MAXIMIZED;
6446-
window->tile_monitor_number = logical_monitor->number;
6447-
}
6448-
else
6449-
{
6450-
display->preview_tile_mode = META_TILE_NONE;
6451-
}
6452-
6453-
return;
6454-
}
6455-
64566443
/* Check if the cursor is in a position which triggers tiling
64576444
* and set tile_mode accordingly.
64586445
*/
@@ -6462,12 +6449,13 @@ update_move_maybe_tile (MetaWindow *window,
64626449
else if (meta_window_can_tile_left_right (window) &&
64636450
get_tile_zone_at_pointer (window, logical_monitor, work_area, x, y) == ZONE_RIGHT)
64646451
display->preview_tile_mode = META_TILE_RIGHT;
6465-
else if (get_tile_zone_at_pointer (window, logical_monitor, work_area, x, y) == ZONE_TOP)
6452+
else if (meta_window_can_tile_top_bottom (window) &&
6453+
// TODO: Handle maximize/tile preference
6454+
get_tile_zone_at_pointer (window, logical_monitor, work_area, x, y) == ZONE_TOP)
64666455
{
6467-
if (window->saved_maximize || (meta_prefs_get_tile_maximize () && meta_window_can_maximize (window)))
6456+
if (window->saved_tile_mode == META_TILE_MAXIMIZED || meta_prefs_get_tile_maximize ())
64686457
display->preview_tile_mode = META_TILE_MAXIMIZED;
64696458
else
6470-
if (meta_window_can_tile_top_bottom (window))
64716459
display->preview_tile_mode = META_TILE_TOP;
64726460
}
64736461
else if (meta_window_can_tile_top_bottom (window) &&
@@ -6543,7 +6531,8 @@ update_move (MetaWindow *window,
65436531
display->preview_tile_mode = META_TILE_NONE;
65446532
window->tile_monitor_number = -1;
65456533
}
6546-
else if (!META_WINDOW_MAXIMIZED (window) &&
6534+
else if (meta_prefs_get_edge_tiling () &&
6535+
!META_WINDOW_MAXIMIZED (window) &&
65476536
!META_WINDOW_TILED (window))
65486537
{
65496538
update_move_maybe_tile (window, shake_threshold, x, y);
@@ -6595,6 +6584,61 @@ update_move (MetaWindow *window,
65956584
return;
65966585
}
65976586

6587+
/* remaximize window on another monitor if window has been shaken
6588+
* loose or it is still maximized (then move straight)
6589+
*/
6590+
else if (window->shaken_loose &&
6591+
(window->tile_mode == META_TILE_NONE || window->tile_mode == META_TILE_MAXIMIZED))
6592+
{
6593+
MetaBackend *backend = meta_get_backend ();
6594+
MetaMonitorManager *monitor_manager =
6595+
meta_backend_get_monitor_manager (backend);
6596+
int n_logical_monitors;
6597+
const MetaLogicalMonitor *wmonitor;
6598+
MetaRectangle work_area;
6599+
int monitor;
6600+
6601+
window->tile_mode = META_TILE_NONE;
6602+
wmonitor = window->monitor;
6603+
n_logical_monitors =
6604+
meta_monitor_manager_get_num_logical_monitors (monitor_manager);
6605+
6606+
for (monitor = 0; monitor < n_logical_monitors; monitor++)
6607+
{
6608+
meta_window_get_work_area_for_monitor (window, monitor, &work_area);
6609+
6610+
/* check if cursor is near the top of a monitor work area */
6611+
if (x >= work_area.x &&
6612+
x < (work_area.x + work_area.width) &&
6613+
y <= work_area.y)
6614+
{
6615+
window->saved_rect.x = work_area.x;
6616+
window->saved_rect.y = work_area.y;
6617+
6618+
if (window->frame)
6619+
{
6620+
window->saved_rect.x += window->frame->child_x;
6621+
window->saved_rect.y += window->frame->child_y;
6622+
}
6623+
6624+
window->unconstrained_rect.x = window->saved_rect.x;
6625+
window->unconstrained_rect.y = window->saved_rect.y;
6626+
6627+
if (monitor != wmonitor->number && window->saved_tile_mode == META_TILE_NONE)
6628+
meta_window_unmaximize (window, META_MAXIMIZE_BOTH);
6629+
6630+
display->grab_initial_window_pos = work_area;
6631+
display->grab_anchor_root_x = x;
6632+
display->grab_anchor_root_y = y;
6633+
window->shaken_loose = FALSE;
6634+
6635+
meta_window_maximize (window, META_MAXIMIZE_BOTH);
6636+
6637+
return;
6638+
}
6639+
}
6640+
}
6641+
65986642
/* Delay showing the tile preview slightly to make it more unlikely to
65996643
* trigger it unwittingly, e.g. when shaking loose the window or moving
66006644
* it to another monitor.
@@ -6767,6 +6811,24 @@ update_resize (MetaWindow *window,
67676811
window->display->grab_last_moveresize_time = g_get_real_time ();
67686812
}
67696813

6814+
static void
6815+
maybe_maximize_tiled_window (MetaWindow *window)
6816+
{
6817+
MetaRectangle work_area;
6818+
gint shake_threshold;
6819+
6820+
if (!META_WINDOW_TILED (window))
6821+
return;
6822+
6823+
shake_threshold = meta_prefs_get_drag_threshold ();
6824+
6825+
meta_window_get_work_area_for_monitor (window,
6826+
window->tile_monitor_number,
6827+
&work_area);
6828+
if (window->rect.width >= work_area.width - shake_threshold)
6829+
meta_window_maximize (window, META_MAXIMIZE_BOTH);
6830+
}
6831+
67706832
void
67716833
meta_window_update_resize (MetaWindow *window,
67726834
gboolean snap,
@@ -6817,8 +6879,8 @@ end_grab_op (MetaWindow *window,
68176879

68186880
meta_window_update_monitor (window, META_WINDOW_UPDATE_MONITOR_FLAGS_USER_OP);
68196881

6820-
if (!(window->maximized_horizontally && window->maximized_vertically))
6821-
window->saved_maximize = FALSE;
6882+
if (!META_WINDOW_MAXIMIZED (window) && !META_WINDOW_TILED (window))
6883+
window->saved_tile_mode = META_TILE_NONE;
68226884

68236885
meta_display_end_grab_op (window->display, clutter_event_get_time (event));
68246886
}

0 commit comments

Comments
 (0)