|
|
657d8e |
From 575490895047e0709bc84826fe6d6a73028d7bbc Mon Sep 17 00:00:00 2001
|
|
|
657d8e |
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
|
|
|
657d8e |
Date: Wed, 12 Mar 2014 02:04:13 +0100
|
|
|
657d8e |
Subject: [PATCH] constraints: Enforce X11 size limits
|
|
|
657d8e |
|
|
|
657d8e |
X11 limits windows to a maximum of 32767x32767, enforce that restriction
|
|
|
657d8e |
to keep insanely huge windows from crashing the WM.
|
|
|
657d8e |
---
|
|
|
657d8e |
src/core/constraints.c | 42 ++++++++++++++++++++++++++++++++++++++++++
|
|
|
657d8e |
1 file changed, 42 insertions(+)
|
|
|
657d8e |
|
|
|
657d8e |
diff --git a/src/core/constraints.c b/src/core/constraints.c
|
|
|
657d8e |
index 117131b15..379372245 100644
|
|
|
657d8e |
--- a/src/core/constraints.c
|
|
|
657d8e |
+++ b/src/core/constraints.c
|
|
|
657d8e |
@@ -109,6 +109,7 @@ typedef enum
|
|
|
657d8e |
PRIORITY_TITLEBAR_VISIBLE = 4,
|
|
|
657d8e |
PRIORITY_PARTIALLY_VISIBLE_ON_WORKAREA = 4,
|
|
|
657d8e |
PRIORITY_CUSTOM_RULE = 4,
|
|
|
657d8e |
+ PRIORITY_XLIMITS = 4,
|
|
|
657d8e |
PRIORITY_MAXIMUM = 4 /* Dummy value used for loop end = max(all priorities) */
|
|
|
657d8e |
} ConstraintPriority;
|
|
|
657d8e |
|
|
|
657d8e |
@@ -201,6 +202,10 @@ static gboolean constrain_partially_onscreen (MetaWindow *window,
|
|
|
657d8e |
ConstraintInfo *info,
|
|
|
657d8e |
ConstraintPriority priority,
|
|
|
657d8e |
gboolean check_only);
|
|
|
657d8e |
+static gboolean constrain_xlimits (MetaWindow *window,
|
|
|
657d8e |
+ ConstraintInfo *info,
|
|
|
657d8e |
+ ConstraintPriority priority,
|
|
|
657d8e |
+ gboolean check_only);
|
|
|
657d8e |
|
|
|
657d8e |
static void setup_constraint_info (ConstraintInfo *info,
|
|
|
657d8e |
MetaWindow *window,
|
|
|
657d8e |
@@ -236,6 +241,7 @@ static const Constraint all_constraints[] = {
|
|
|
657d8e |
{constrain_fully_onscreen, "constrain_fully_onscreen"},
|
|
|
657d8e |
{constrain_titlebar_visible, "constrain_titlebar_visible"},
|
|
|
657d8e |
{constrain_partially_onscreen, "constrain_partially_onscreen"},
|
|
|
657d8e |
+ {constrain_xlimits, "constrain_xlimits"},
|
|
|
657d8e |
{NULL, NULL}
|
|
|
657d8e |
};
|
|
|
657d8e |
|
|
|
657d8e |
@@ -1780,3 +1786,39 @@ constrain_partially_onscreen (MetaWindow *window,
|
|
|
657d8e |
|
|
|
657d8e |
return retval;
|
|
|
657d8e |
}
|
|
|
657d8e |
+
|
|
|
657d8e |
+
|
|
|
657d8e |
+#define MAX_WINDOW_SIZE 32767
|
|
|
657d8e |
+
|
|
|
657d8e |
+static gboolean
|
|
|
657d8e |
+constrain_xlimits (MetaWindow *window,
|
|
|
657d8e |
+ ConstraintInfo *info,
|
|
|
657d8e |
+ ConstraintPriority priority,
|
|
|
657d8e |
+ gboolean check_only)
|
|
|
657d8e |
+{
|
|
|
657d8e |
+ int max_w, max_h;
|
|
|
657d8e |
+ gboolean constraint_already_satisfied;
|
|
|
657d8e |
+
|
|
|
657d8e |
+ if (priority > PRIORITY_XLIMITS)
|
|
|
657d8e |
+ return TRUE;
|
|
|
657d8e |
+
|
|
|
657d8e |
+ max_w = max_h = MAX_WINDOW_SIZE;
|
|
|
657d8e |
+
|
|
|
657d8e |
+ if (window->frame)
|
|
|
657d8e |
+ {
|
|
|
657d8e |
+ MetaFrameBorders borders;
|
|
|
657d8e |
+ meta_frame_calc_borders (window->frame, &borders);
|
|
|
657d8e |
+
|
|
|
657d8e |
+ max_w -= (borders.total.left + borders.total.right);
|
|
|
657d8e |
+ max_h -= (borders.total.top + borders.total.bottom);
|
|
|
657d8e |
+ }
|
|
|
657d8e |
+
|
|
|
657d8e |
+ constraint_already_satisfied = info->current.width < max_w && info->current.height < max_h;
|
|
|
657d8e |
+ if (check_only || constraint_already_satisfied)
|
|
|
657d8e |
+ return constraint_already_satisfied;
|
|
|
657d8e |
+
|
|
|
657d8e |
+ info->current.width = MIN (info->current.width, max_w);
|
|
|
657d8e |
+ info->current.height = MIN (info->current.height, max_h);
|
|
|
657d8e |
+
|
|
|
657d8e |
+ return TRUE;
|
|
|
657d8e |
+}
|
|
|
657d8e |
--
|
|
|
657d8e |
2.21.0
|
|
|
657d8e |
|