summaryrefslogtreecommitdiff
path: root/src/core/window.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/window.c')
-rw-r--r--src/core/window.c166
1 files changed, 124 insertions, 42 deletions
diff --git a/src/core/window.c b/src/core/window.c
index b0e69548..a811d668 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -471,6 +471,7 @@ meta_window_new_with_attrs (MetaDisplay *display,
window->require_titlebar_visible = TRUE;
window->on_all_workspaces = FALSE;
window->tile_mode = META_TILE_NONE;
+ window->tile_monitor_number = -1;
window->shaded = FALSE;
window->initially_iconic = FALSE;
window->minimized = FALSE;
@@ -2612,6 +2613,9 @@ meta_window_maximize_internal (MetaWindow *window,
else
meta_window_save_rect (window);
+ if (maximize_horizontally && maximize_vertically)
+ window->saved_maximize = TRUE;
+
window->maximized_horizontally =
window->maximized_horizontally || maximize_horizontally;
window->maximized_vertically =
@@ -2660,13 +2664,15 @@ meta_window_maximize (MetaWindow *window,
*/
if (!window->placed)
{
- window->maximize_horizontally_after_placement =
- window->maximize_horizontally_after_placement ||
- maximize_horizontally;
- window->maximize_vertically_after_placement =
- window->maximize_vertically_after_placement ||
- maximize_vertically;
- return;
+ window->maximize_horizontally_after_placement = window->maximize_horizontally_after_placement || maximize_horizontally;
+ window->maximize_vertically_after_placement = window->maximize_vertically_after_placement || maximize_vertically;
+ return;
+ }
+
+ if (window->tile_mode != META_TILE_NONE)
+ {
+ saved_rect = &window->saved_rect;
+ window->maximized_vertically = FALSE;
}
if (window->tile_mode != META_TILE_NONE)
@@ -2720,7 +2726,7 @@ unmaximize_window_before_freeing (MetaWindow *window)
}
}
-static void
+void
meta_window_tile (MetaWindow *window)
{
/* Don't do anything if no tiling is requested */
@@ -2728,7 +2734,6 @@ meta_window_tile (MetaWindow *window)
return;
meta_window_maximize_internal (window, META_MAXIMIZE_VERTICAL, NULL);
- meta_screen_tile_preview_update (window->screen, FALSE);
/* move_resize with new tiling constraints
*/
@@ -2736,11 +2741,18 @@ meta_window_tile (MetaWindow *window)
}
static gboolean
+meta_window_can_tile_maximized (MetaWindow *window)
+{
+ return window->has_maximize_func;
+}
+
+gboolean
meta_window_can_tile (MetaWindow *window)
{
const MetaXineramaScreenInfo *monitor;
MetaRectangle tile_area;
+ /*if (!META_WINDOW_ALLOWS_RESIZE (window))*/
if (!META_WINDOW_ALLOWS_RESIZE (window))
return FALSE;
@@ -2771,7 +2783,8 @@ meta_window_unmaximize (MetaWindow *window,
gboolean unmaximize_horizontally, unmaximize_vertically;
/* Restore tiling if necessary */
- if (window->tile_mode != META_TILE_NONE)
+ if (window->tile_mode == META_TILE_LEFT ||
+ window->tile_mode == META_TILE_RIGHT)
{
window->maximized_horizontally = FALSE;
meta_window_tile (window);
@@ -2782,6 +2795,9 @@ meta_window_unmaximize (MetaWindow *window,
unmaximize_vertically = directions & META_MAXIMIZE_VERTICAL;
g_assert (unmaximize_horizontally || unmaximize_vertically);
+ if (unmaximize_horizontally && unmaximize_vertically)
+ window->saved_maximize = FALSE;
+
/* Only do something if the window isn't already maximized in the
* given direction(s).
*/
@@ -7019,35 +7035,56 @@ update_move (MetaWindow *window,
DRAG_THRESHOLD_TO_SHAKE_THRESHOLD_FACTOR;
- if (meta_prefs_get_side_by_side_tiling () &&
- meta_window_can_tile (window))
+ if (snap)
+ {
+ /* We don't want to tile while snapping. Also, clear any previous tile
+ request. */
+ window->tile_mode = META_TILE_NONE;
+ window->tile_monitor_number = -1;
+ }
+ else if (meta_prefs_get_side_by_side_tiling () &&
+ !META_WINDOW_MAXIMIZED (window) &&
+ !META_WINDOW_TILED (window))
{
const MetaXineramaScreenInfo *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()
+ /* For side-by-side tiling we are interested in the inside vertical
+ * edges of the work area of the monitor where the pointer is located,
+ * and in the outside top edge for maximized tiling.
+ *
+ * For maximized tiling we use the outside edge instead of the
+ * inside edge, because we don't want to force users to maximize
+ * windows they are placing near the top of their screens.
+ *
+ * The "current" idea 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_xinerama (window->screen);
meta_window_get_work_area_for_xinerama (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 if ((y >= monitor->rect.y) && (y < work_area.y + shake_threshold))
- window->tile_mode = META_TILE_MAXIMIZE;
- else
- window->tile_mode = META_TILE_NONE;
- }
+ /* Check if the cursor is in a position which triggers tiling
+ * and set tile_mode accordingly.
+ */
+ if (meta_window_can_tile (window) &&
+ x >= monitor->rect.x && x < (work_area.x + shake_threshold))
+ window->tile_mode = META_TILE_LEFT;
+ else if (meta_window_can_tile (window) &&
+ x >= work_area.x + work_area.width - shake_threshold &&
+ x < (monitor->rect.x + monitor->rect.width))
+ window->tile_mode = META_TILE_RIGHT;
+ else if (meta_window_can_tile_maximized (window) &&
+ y >= monitor->rect.y && y <= work_area.y)
+ window->tile_mode = META_TILE_MAXIMIZED;
+ else
+ window->tile_mode = META_TILE_NONE;
+
+ if (window->tile_mode != META_TILE_NONE)
+ window->tile_monitor_number = monitor->number;
}
/* shake loose (unmaximize) maximized or tiled window if dragged beyond
@@ -7060,7 +7097,10 @@ update_move (MetaWindow *window,
{
double prop;
- /* Shake loose */
+ /* Shake loose, so that the window snaps back to maximized
+ * when dragged near the top; do not snap back if the window
+ * was tiled.
+ */
window->shaken_loose = META_WINDOW_MAXIMIZED (window);
window->tile_mode = META_TILE_NONE;
@@ -7137,6 +7177,8 @@ update_move (MetaWindow *window,
display->grab_anchor_root_y = y;
window->shaken_loose = FALSE;
+ window->tile_mode = META_TILE_NONE;
+
meta_window_maximize (window,
META_MAXIMIZE_HORIZONTAL |
META_MAXIMIZE_VERTICAL);
@@ -7507,6 +7549,19 @@ check_use_this_motion_notify (MetaWindow *window,
}
}
+static void
+update_tile_mode (MetaWindow *window)
+{
+ switch (window->tile_mode)
+ {
+ case META_TILE_LEFT:
+ case META_TILE_RIGHT:
+ if (!META_WINDOW_TILED (window))
+ window->tile_mode = META_TILE_NONE;
+ break;
+ }
+}
+
void
meta_window_handle_mouse_grab_op_event (MetaWindow *window,
XEvent *event)
@@ -7575,11 +7630,17 @@ meta_window_handle_mouse_grab_op_event (MetaWindow *window,
{
if (meta_grab_op_is_moving (window->display->grab_op))
{
- if (window->tile_mode != META_TILE_NONE)
- meta_window_tile (window);
- else if (window->tile_mode == META_TILE_MAXIMIZE)
- meta_window_maximize (window, META_MAXIMIZE_HORIZONTAL | META_MAXIMIZE_VERTICAL);
- else if (event->xbutton.root == window->screen->xroot)
+ if (window->tile_mode == META_TILE_MAXIMIZED)
+ {
+ meta_window_maximize (window, META_MAXIMIZE_VERTICAL |
+ META_MAXIMIZE_HORIZONTAL);
+ window->tile_mode = META_TILE_NONE;
+ }
+ else 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);
}
@@ -7593,6 +7654,15 @@ meta_window_handle_mouse_grab_op_event (MetaWindow *window,
TRUE);
if (window->display->compositor)
meta_compositor_set_updates (window->display->compositor, window, TRUE);
+
+ /* If a tiled window has been dragged free with a
+ * mouse resize without snapping back to the tiled
+ * state, it will end up with an inconsistent tile
+ * mode on mouse release; cleaning the mode earlier
+ * would break the ability to snap back to the tiled
+ * state, so we wait until mouse release.
+ */
+ update_tile_mode (window);
}
}
@@ -7741,17 +7811,29 @@ void
meta_window_get_current_tile_area (MetaWindow *window,
MetaRectangle *tile_area)
{
- const MetaXineramaScreenInfo *monitor;
+ int tile_monitor_number;
g_return_if_fail (window->tile_mode != META_TILE_NONE);
- /* The definition of "current" of meta_window_get_work_area_current_xinerama()
- * and meta_screen_get_current_xinerama() 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.
+ /* I don't know how to detect monitor configuration changes, so I have to take into account that
+ * tile_monitor_number might be invalid. If this happens, I replace it with whatever monitor
+ * the window is currently on. This is usually the correct monitor anyway, only in some special
+ * cases is the real monitor number actually required (e.g. the window is being moved with the mouse but
+ * is still mostly on the wrong monitor).
*/
- monitor = meta_screen_get_current_xinerama (window->screen);
- meta_window_get_work_area_for_xinerama (window, monitor->number, tile_area);
+ if (window->tile_monitor_number >= window->screen->n_xinerama_infos)
+ {
+ window->tile_monitor_number = meta_screen_get_xinerama_for_window (window->screen, window)->number;
+ }
+
+ tile_monitor_number = window->tile_monitor_number;
+ if (tile_monitor_number < 0)
+ {
+ meta_warning ("%s called with an invalid monitor number; using 0 instead\n", G_STRFUNC);
+ tile_monitor_number = 0;
+ }
+
+ meta_window_get_work_area_for_xinerama (window, tile_monitor_number, tile_area);
if (window->tile_mode == META_TILE_LEFT ||
window->tile_mode == META_TILE_RIGHT)