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

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