Blame SOURCES/0001-constraints-Enforce-X11-size-limits.patch

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