Blame SOURCES/deal-more-gracefully-with-oversized-windows.patch

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