Implement side-by-side tiling
When dragging a window over a screen edge and dropping it there, maximize it vertically and scale it horizontally to cover the corresponding half of the current monitor. Whenever a "hot area" which triggers this behavior is entered, an indication of window's target size is displayed after a short delay to avoid distraction when moving a window between monitors. https://bugzilla.gnome.org/show_bug.cgi?id=606260
This commit is contained in:
@@ -772,6 +772,7 @@ meta_window_new_with_attrs (MetaDisplay *display,
|
||||
window->require_on_single_monitor = TRUE;
|
||||
window->require_titlebar_visible = TRUE;
|
||||
window->on_all_workspaces = FALSE;
|
||||
window->tile_mode = META_TILE_NONE;
|
||||
window->shaded = FALSE;
|
||||
window->initially_iconic = FALSE;
|
||||
window->minimized = FALSE;
|
||||
@@ -2970,7 +2971,7 @@ ensure_size_hints_satisfied (MetaRectangle *rect,
|
||||
static void
|
||||
meta_window_save_rect (MetaWindow *window)
|
||||
{
|
||||
if (!(META_WINDOW_MAXIMIZED (window) || window->fullscreen))
|
||||
if (!(META_WINDOW_MAXIMIZED (window) || META_WINDOW_TILED (window) || window->fullscreen))
|
||||
{
|
||||
/* save size/pos as appropriate args for move_resize */
|
||||
if (!window->maximized_horizontally)
|
||||
@@ -3012,7 +3013,7 @@ force_save_user_window_placement (MetaWindow *window)
|
||||
static void
|
||||
save_user_window_placement (MetaWindow *window)
|
||||
{
|
||||
if (!(META_WINDOW_MAXIMIZED (window) || window->fullscreen))
|
||||
if (!(META_WINDOW_MAXIMIZED (window) || META_WINDOW_TILED (window) || window->fullscreen))
|
||||
{
|
||||
MetaRectangle user_rect;
|
||||
|
||||
@@ -3082,6 +3083,7 @@ void
|
||||
meta_window_maximize (MetaWindow *window,
|
||||
MetaMaximizeFlags directions)
|
||||
{
|
||||
MetaRectangle *saved_rect = NULL;
|
||||
gboolean maximize_horizontally, maximize_vertically;
|
||||
|
||||
g_return_if_fail (!window->override_redirect);
|
||||
@@ -3120,9 +3122,16 @@ meta_window_maximize (MetaWindow *window,
|
||||
return;
|
||||
}
|
||||
|
||||
if (window->tile_mode != META_TILE_NONE)
|
||||
{
|
||||
saved_rect = &window->saved_rect;
|
||||
|
||||
window->maximized_vertically = FALSE;
|
||||
}
|
||||
|
||||
meta_window_maximize_internal (window,
|
||||
directions,
|
||||
NULL);
|
||||
saved_rect);
|
||||
|
||||
if (window->display->compositor)
|
||||
{
|
||||
@@ -3148,6 +3157,67 @@ meta_window_maximize (MetaWindow *window,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
meta_window_tile (MetaWindow *window)
|
||||
{
|
||||
/* Don't do anything if no tiling is requested */
|
||||
if (window->tile_mode == META_TILE_NONE)
|
||||
return;
|
||||
|
||||
meta_window_maximize_internal (window, META_MAXIMIZE_VERTICAL, NULL);
|
||||
meta_screen_tile_preview_update (window->screen, FALSE);
|
||||
|
||||
if (window->display->compositor)
|
||||
{
|
||||
MetaRectangle old_rect;
|
||||
MetaRectangle new_rect;
|
||||
|
||||
meta_window_get_outer_rect (window, &old_rect);
|
||||
|
||||
meta_window_move_resize_now (window);
|
||||
|
||||
meta_window_get_outer_rect (window, &new_rect);
|
||||
meta_compositor_maximize_window (window->display->compositor,
|
||||
window,
|
||||
&old_rect,
|
||||
&new_rect);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* move_resize with new tiling constraints
|
||||
*/
|
||||
meta_window_queue (window, META_QUEUE_MOVE_RESIZE);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
meta_window_can_tile (MetaWindow *window)
|
||||
{
|
||||
const MetaMonitorInfo *monitor;
|
||||
MetaRectangle tile_area;
|
||||
|
||||
if (!META_WINDOW_ALLOWS_RESIZE (window))
|
||||
return FALSE;
|
||||
|
||||
monitor = meta_screen_get_current_monitor (window->screen);
|
||||
meta_window_get_work_area_for_monitor (window, monitor->number, &tile_area);
|
||||
|
||||
tile_area.width /= 2;
|
||||
|
||||
if (window->frame)
|
||||
{
|
||||
MetaFrameGeometry fgeom;
|
||||
|
||||
meta_frame_calc_geometry (window->frame, &fgeom);
|
||||
|
||||
tile_area.width -= (fgeom.left_width + fgeom.right_width);
|
||||
tile_area.height -= (fgeom.top_height + fgeom.bottom_height);
|
||||
}
|
||||
|
||||
return tile_area.width >= window->size_hints.min_width &&
|
||||
tile_area.height >= window->size_hints.min_height;
|
||||
}
|
||||
|
||||
static void
|
||||
unmaximize_window_before_freeing (MetaWindow *window)
|
||||
{
|
||||
@@ -3188,6 +3258,14 @@ meta_window_unmaximize (MetaWindow *window,
|
||||
|
||||
g_return_if_fail (!window->override_redirect);
|
||||
|
||||
/* Restore tiling if necessary */
|
||||
if (window->tile_mode != META_TILE_NONE)
|
||||
{
|
||||
window->maximized_horizontally = FALSE;
|
||||
meta_window_tile (window);
|
||||
return;
|
||||
}
|
||||
|
||||
/* At least one of the two directions ought to be set */
|
||||
unmaximize_horizontally = directions & META_MAXIMIZE_HORIZONTAL;
|
||||
unmaximize_vertically = directions & META_MAXIMIZE_VERTICAL;
|
||||
@@ -3233,17 +3311,6 @@ meta_window_unmaximize (MetaWindow *window,
|
||||
*/
|
||||
ensure_size_hints_satisfied (&target_rect, &window->size_hints);
|
||||
|
||||
/* When we unmaximize, if we're doing a mouse move also we could
|
||||
* get the window suddenly jumping to the upper left corner of
|
||||
* the workspace, since that's where it was when the grab op
|
||||
* started. So we need to update the grab state.
|
||||
*/
|
||||
if (meta_grab_op_is_moving (window->display->grab_op) &&
|
||||
window->display->grab_window == window)
|
||||
{
|
||||
window->display->grab_anchor_window_pos = target_rect;
|
||||
}
|
||||
|
||||
if (window->display->compositor)
|
||||
{
|
||||
MetaRectangle old_rect, new_rect;
|
||||
@@ -3277,6 +3344,19 @@ meta_window_unmaximize (MetaWindow *window,
|
||||
*/
|
||||
force_save_user_window_placement (window);
|
||||
|
||||
/* When we unmaximize, if we're doing a mouse move also we could
|
||||
* get the window suddenly jumping to the upper left corner of
|
||||
* the workspace, since that's where it was when the grab op
|
||||
* started. So we need to update the grab state. We have to do
|
||||
* it after the actual operation, as the window may have been moved
|
||||
* by constraints.
|
||||
*/
|
||||
if (meta_grab_op_is_moving (window->display->grab_op) &&
|
||||
window->display->grab_window == window)
|
||||
{
|
||||
window->display->grab_anchor_window_pos = window->user_rect;
|
||||
}
|
||||
|
||||
recalc_window_features (window);
|
||||
set_net_wm_state (window);
|
||||
}
|
||||
@@ -7637,20 +7717,56 @@ update_move (MetaWindow *window,
|
||||
if (dx == 0 && dy == 0)
|
||||
return;
|
||||
|
||||
/* shake loose (unmaximize) maximized window if dragged beyond the threshold
|
||||
* in the Y direction. You can't pull a window loose via X motion.
|
||||
/* Originally for detaching maximized windows, but we use this
|
||||
* for the zones at the sides of the monitor where trigger tiling
|
||||
* because it's about the right size
|
||||
*/
|
||||
|
||||
#define DRAG_THRESHOLD_TO_SHAKE_THRESHOLD_FACTOR 6
|
||||
shake_threshold = meta_ui_get_drag_threshold (window->screen->ui) *
|
||||
DRAG_THRESHOLD_TO_SHAKE_THRESHOLD_FACTOR;
|
||||
|
||||
if (META_WINDOW_MAXIMIZED (window) && ABS (dy) >= shake_threshold)
|
||||
if (meta_prefs_get_side_by_side_tiling () &&
|
||||
meta_window_can_tile (window))
|
||||
{
|
||||
const MetaMonitorInfo *monitor;
|
||||
MetaRectangle work_area;
|
||||
|
||||
/* For tiling we are interested in the work area of the monitor where
|
||||
* the pointer is located.
|
||||
* Also see comment in meta_window_get_current_tile_area()
|
||||
*/
|
||||
monitor = meta_screen_get_current_monitor (window->screen);
|
||||
meta_window_get_work_area_for_monitor (window,
|
||||
monitor->number,
|
||||
&work_area);
|
||||
|
||||
if (y >= monitor->rect.y &&
|
||||
y < (monitor->rect.y + monitor->rect.height))
|
||||
{
|
||||
/* check if cursor is near an edge of the work area */
|
||||
if (x >= monitor->rect.x && x < (work_area.x + shake_threshold))
|
||||
window->tile_mode = META_TILE_LEFT;
|
||||
else if (x >= work_area.x + work_area.width - shake_threshold &&
|
||||
x < (monitor->rect.x + monitor->rect.width))
|
||||
window->tile_mode = META_TILE_RIGHT;
|
||||
else
|
||||
window->tile_mode = META_TILE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
/* shake loose (unmaximize) maximized or tiled window if dragged beyond
|
||||
* the threshold in the Y direction. Tiled windows can also be pulled
|
||||
* loose via X motion.
|
||||
*/
|
||||
|
||||
if ((META_WINDOW_MAXIMIZED (window) && ABS (dy) >= shake_threshold) ||
|
||||
(META_WINDOW_TILED (window) && (MAX (ABS (dx), ABS (dy)) >= shake_threshold)))
|
||||
{
|
||||
double prop;
|
||||
|
||||
/* Shake loose */
|
||||
window->shaken_loose = TRUE;
|
||||
window->shaken_loose = !META_WINDOW_TILED (window);
|
||||
window->tile_mode = META_TILE_NONE;
|
||||
|
||||
/* move the unmaximized window to the cursor */
|
||||
prop =
|
||||
@@ -7677,10 +7793,12 @@ update_move (MetaWindow *window,
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* remaximize window on another monitor if window has been shaken
|
||||
* loose or it is still maximized (then move straight)
|
||||
*/
|
||||
else if (window->shaken_loose || META_WINDOW_MAXIMIZED (window))
|
||||
else if ((window->shaken_loose || META_WINDOW_MAXIMIZED (window)) &&
|
||||
window->tile_mode == META_TILE_NONE)
|
||||
{
|
||||
const MetaMonitorInfo *wmonitor;
|
||||
MetaRectangle work_area;
|
||||
@@ -7734,10 +7852,17 @@ update_move (MetaWindow *window,
|
||||
}
|
||||
}
|
||||
|
||||
/* Delay showing the tile preview slightly to make it more unlikely to
|
||||
* trigger it unwittingly, e.g. when shaking loose the window or moving
|
||||
* it to another monitor.
|
||||
*/
|
||||
meta_screen_tile_preview_update (window->screen,
|
||||
window->tile_mode != META_TILE_NONE);
|
||||
|
||||
meta_window_get_client_root_coords (window, &old);
|
||||
|
||||
/* Don't allow movement in the maximized directions */
|
||||
if (window->maximized_horizontally)
|
||||
/* Don't allow movement in the maximized directions or while tiled */
|
||||
if (window->maximized_horizontally || META_WINDOW_TILED (window))
|
||||
new_x = old.x;
|
||||
if (window->maximized_vertically)
|
||||
new_y = old.y;
|
||||
@@ -8106,7 +8231,9 @@ meta_window_handle_mouse_grab_op_event (MetaWindow *window,
|
||||
{
|
||||
if (meta_grab_op_is_moving (window->display->grab_op))
|
||||
{
|
||||
if (event->xbutton.root == window->screen->xroot)
|
||||
if (window->tile_mode != META_TILE_NONE)
|
||||
meta_window_tile (window);
|
||||
else if (event->xbutton.root == window->screen->xroot)
|
||||
update_move (window, event->xbutton.state & ShiftMask,
|
||||
event->xbutton.x_root, event->xbutton.y_root);
|
||||
}
|
||||
@@ -8264,6 +8391,29 @@ meta_window_get_work_area_all_monitors (MetaWindow *window,
|
||||
window->desc, area->x, area->y, area->width, area->height);
|
||||
}
|
||||
|
||||
void
|
||||
meta_window_get_current_tile_area (MetaWindow *window,
|
||||
MetaRectangle *tile_area)
|
||||
{
|
||||
const MetaMonitorInfo *monitor;
|
||||
|
||||
g_return_if_fail (window->tile_mode != META_TILE_NONE);
|
||||
|
||||
/* The definition of "current" of meta_window_get_work_area_current_monitor()
|
||||
* and meta_screen_get_current_monitor() is slightly different: the former
|
||||
* refers to the monitor which contains the largest part of the window, the
|
||||
* latter to the one where the pointer is located.
|
||||
*/
|
||||
monitor = meta_screen_get_current_monitor (window->screen);
|
||||
meta_window_get_work_area_for_monitor (window, monitor->number, tile_area);
|
||||
|
||||
if (window->tile_mode == META_TILE_LEFT ||
|
||||
window->tile_mode == META_TILE_RIGHT)
|
||||
tile_area->width /= 2;
|
||||
|
||||
if (window->tile_mode == META_TILE_RIGHT)
|
||||
tile_area->x += tile_area->width;
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_window_same_application (MetaWindow *window,
|
||||
|
Reference in New Issue
Block a user