Skip to content

Commit a9cc86d

Browse files
committed
window.c: Fix regression in window positioning when a window is
restored from a tiled state. This reverts 051b8d2, which aimed to fix apps fullscreening to the wrong monitor if they had been originally maximized and dragged between monitors. The fix unfortunately breaks the window's 'saved' unconstrained position. For example, when using keyboard shortcuts to un-tile (push in the opposite direction of the active tile), the size is restored, but the position is not. Instead, translate the saved x and y position relative to the new monitor before calling maximize_internal(). This fixes the original problem without impacting keybindings and other actions that remove the tiled state. Fixes #809. Fixes #810.
1 parent 4accef8 commit a9cc86d

1 file changed

Lines changed: 34 additions & 32 deletions

File tree

src/core/window.c

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,44 +3532,46 @@ meta_window_tile (MetaWindow *window,
35323532
else
35333533
directions = META_MAXIMIZE_VERTICAL;
35343534

3535+
MetaRectangle *maybe_saved_rect = NULL;
35353536

3536-
MetaRectangle existing_rect, work_area, tile_area;
3537-
meta_window_get_frame_rect(window, &existing_rect);
3538-
meta_window_get_work_area_for_monitor(window, window->tile_monitor_number, &work_area);
3539-
tile_area = existing_rect;
3540-
3541-
switch (tile_mode)
3537+
if (window->saved_tile_mode == META_TILE_NONE && window->display->grab_op != META_GRAB_OP_NONE)
35423538
{
3543-
case META_TILE_LEFT:
3544-
tile_area.x = work_area.x;
3545-
tile_area.y = work_area.y;
3546-
break;
3547-
3548-
case META_TILE_RIGHT:
3549-
tile_area.x = work_area.x + work_area.width - existing_rect.width;
3550-
tile_area.y = work_area.y;
3551-
break;
3552-
3553-
case META_TILE_TOP:
3554-
tile_area.x = work_area.x;
3555-
tile_area.y = work_area.y;
3556-
break;
3539+
maybe_saved_rect = &window->display->grab_initial_window_pos;
3540+
}
3541+
else
3542+
if (window->saved_tile_mode != META_TILE_NONE)
3543+
{
3544+
maybe_saved_rect = &window->saved_rect;
3545+
}
35573546

3558-
case META_TILE_BOTTOM:
3559-
tile_area.x = work_area.x;
3560-
tile_area.y = work_area.y + work_area.height - existing_rect.height;
3561-
break;
3547+
// If the saved restore position is not on the target monitor, translate it
3548+
// it so that fullscreening (which un-tiles) happens on the correct monitor.
3549+
if (maybe_saved_rect != NULL)
3550+
{
3551+
MetaRectangle target_work_area;
3552+
meta_window_get_work_area_for_monitor (window, window->tile_monitor_number, &target_work_area);
35623553

3563-
default:
3564-
tile_area.x = work_area.x + (work_area.width - existing_rect.width) / 2;
3565-
tile_area.y = work_area.y + (work_area.height - existing_rect.height) / 2;
3566-
break;
3567-
}
3554+
if (!meta_rectangle_overlap (maybe_saved_rect, &target_work_area))
3555+
{
3556+
MetaBackend *backend = meta_get_backend ();
3557+
MetaMonitorManager *monitor_manager =
3558+
meta_backend_get_monitor_manager (backend);
3559+
const MetaLogicalMonitor *old_monitor =
3560+
meta_monitor_manager_get_logical_monitor_from_rect (monitor_manager,
3561+
maybe_saved_rect);
3562+
3563+
if (old_monitor)
3564+
{
3565+
MetaRectangle old_work_area;
3566+
meta_window_get_work_area_for_monitor (window, old_monitor->number, &old_work_area);
35683567

3569-
window->saved_rect = tile_area;
3570-
window->unconstrained_rect = tile_area;
3568+
maybe_saved_rect->x += target_work_area.x - old_work_area.x;
3569+
maybe_saved_rect->y += target_work_area.y - old_work_area.y;
3570+
}
3571+
}
3572+
}
35713573

3572-
meta_window_maximize_internal (window, directions, &window->saved_rect);
3574+
meta_window_maximize_internal (window, directions, maybe_saved_rect);
35733575
meta_display_update_tile_preview (window->display, FALSE);
35743576

35753577
if ((!window->htile_match || window->htile_match != window->display->grab_window) &&

0 commit comments

Comments
 (0)