+// Limit the paint region to the window size. Sometimes
+// the paint region is too big, and this risks X11 errors
+static void wxLimitRegionToSize(wxRegion& region, const wxSize& sz)
+{
+ wxRect originalRect = region.GetBox();
+ wxRect rect(originalRect);
+ if (rect.width + rect.x > sz.x)
+ rect.width = sz.x - rect.x;
+ if (rect.height + rect.y > sz.y)
+ rect.height = sz.y - rect.y;
+ if (rect != originalRect)
+ {
+ region = wxRegion(rect);
+ wxLogTrace(wxT("painting"), wxT("Limiting region from %d, %d, %d, %d to %d, %d, %d, %d\n"),
+ originalRect.x, originalRect.y, originalRect.width, originalRect.height,
+ rect.x, rect.y, rect.width, rect.height);
+ }
+}
+