[mutter/wip/gbsneto/edge-constraints: 1/4] constraints: Add percentage constraint
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/gbsneto/edge-constraints: 1/4] constraints: Add percentage constraint
- Date: Sat, 19 Aug 2017 00:36:14 +0000 (UTC)
commit 6236e427f0123b1b78b0cafc53fd927b5dd73c23
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Aug 18 21:27:35 2017 -0300
constraints: Add percentage constraint
In the past, the tiling constraint was used to enforce
that windows would have 50% of the workarea, even when
the monitor changes.
Now that windows can be resized when tiled, this aspect
of the tiling constraint was lost. Its purpose, now, is
to keep the tiled windows in the position we expect them
to be, but now, tiled windows have a slightly mistuned
behavior when changing monitors: they keep their widths,
not the percentage of window covered.
Fix that by adding a new percentage constraint. This new
constraint enforces that, when windows are tiled, they
keep the same percentage of the screen.
https://bugzilla.gnome.org/show_bug.cgi?id=645153
src/core/constraints.c | 52 +++++++++++++++++++++++++++++++++++++++++++++
src/core/window-private.h | 3 ++
src/core/window.c | 14 ++++++++++++
3 files changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/src/core/constraints.c b/src/core/constraints.c
index 558e43d..d8898d5 100644
--- a/src/core/constraints.c
+++ b/src/core/constraints.c
@@ -101,6 +101,7 @@ typedef enum
PRIORITY_SIZE_HINTS_INCREMENTS = 1,
PRIORITY_MAXIMIZATION = 2,
PRIORITY_TILING = 2,
+ PRIORITY_PERCENTAGE = 2,
PRIORITY_FULLSCREEN = 2,
PRIORITY_SIZE_HINTS_LIMITS = 3,
PRIORITY_TITLEBAR_VISIBLE = 4,
@@ -164,6 +165,10 @@ static gboolean constrain_tiling (MetaWindow *window,
ConstraintInfo *info,
ConstraintPriority priority,
gboolean check_only);
+static gboolean constrain_percentage (MetaWindow *window,
+ ConstraintInfo *info,
+ ConstraintPriority priority,
+ gboolean check_only);
static gboolean constrain_fullscreen (MetaWindow *window,
ConstraintInfo *info,
ConstraintPriority priority,
@@ -223,6 +228,7 @@ static const Constraint all_constraints[] = {
{constrain_modal_dialog, "constrain_modal_dialog"},
{constrain_maximization, "constrain_maximization"},
{constrain_tiling, "constrain_tiling"},
+ {constrain_percentage, "constrain_percentage"},
{constrain_fullscreen, "constrain_fullscreen"},
{constrain_size_increments, "constrain_size_increments"},
{constrain_size_limits, "constrain_size_limits"},
@@ -1067,6 +1073,52 @@ constrain_tiling (MetaWindow *window,
return TRUE;
}
+static gboolean
+constrain_percentage (MetaWindow *window,
+ ConstraintInfo *info,
+ ConstraintPriority priority,
+ gboolean check_only)
+{
+ MetaRectangle target_size, workarea;
+ MetaRectangle min_size, max_size;
+ gboolean hminbad, vminbad;
+ gboolean horiz_equal, vert_equal;
+ gboolean constraint_already_satisfied;
+
+ if (priority > PRIORITY_PERCENTAGE)
+ return TRUE;
+
+ /* Determine whether constraint applies; exit if it doesn't */
+ if (!META_WINDOW_TILED_SIDE_BY_SIDE (window))
+ return TRUE;
+
+ meta_window_get_work_area_current_monitor (window, &workarea);
+
+ target_size.width = ceil (workarea.width * window->hpercentage);
+ target_size.height = ceil (workarea.height * window->vpercentage);
+
+ /* Check min size constraints; max size constraints are ignored as for
+ * maximized windows.
+ */
+ get_size_limits (window, &min_size, &max_size);
+ hminbad = target_size.width < min_size.width;
+ vminbad = target_size.height < min_size.height;
+ if (hminbad || vminbad)
+ return TRUE;
+
+ /* Determine whether constraint is already satisfied; exit if it is */
+ horiz_equal = target_size.width == info->current.width;
+ vert_equal = target_size.height == info->current.height;
+ constraint_already_satisfied = horiz_equal && vert_equal;
+ if (check_only || constraint_already_satisfied)
+ return constraint_already_satisfied;
+
+ /*** Enforce constraint ***/
+ info->current.width = target_size.width;
+ info->current.height = target_size.height;
+
+ return TRUE;
+}
static gboolean
constrain_fullscreen (MetaWindow *window,
diff --git a/src/core/window-private.h b/src/core/window-private.h
index ce11574..0c58675 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -213,6 +213,9 @@ struct _MetaWindow
guint previous_tile_mode : 2;
guint preview_tile_mode : 2;
+ gdouble hpercentage;
+ gdouble vpercentage;
+
int preferred_output_winsys_id;
/* Whether we're shaded */
diff --git a/src/core/window.c b/src/core/window.c
index 7ebf0ee..4bf8609 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -3723,6 +3723,18 @@ meta_window_update_monitor (MetaWindow *window,
}
}
+static void
+meta_window_update_percentage (MetaWindow *window,
+ MetaRectangle rect)
+{
+ MetaRectangle workarea;
+
+ meta_window_get_work_area_current_monitor (window, &workarea);
+
+ window->hpercentage = rect.width / (gdouble) workarea.width;
+ window->vpercentage = rect.height / (gdouble) workarea.height;
+}
+
void
meta_window_move_resize_internal (MetaWindow *window,
MetaMoveResizeFlags flags,
@@ -3802,6 +3814,8 @@ meta_window_move_resize_internal (MetaWindow *window,
else
g_assert_not_reached ();
+ meta_window_update_percentage (window, unconstrained_rect);
+
constrained_rect = unconstrained_rect;
if (flags & (META_MOVE_RESIZE_MOVE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]