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

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