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

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