Exemple #1
0
 def _handle_wm_normal_hints_change(self):
     with xswallow:
         size_hints = X11Window.getSizeHints(self.xid)
     metalog("WM_NORMAL_HINTS=%s", size_hints)
     #getSizeHints exports fields using their X11 names as defined in the "XSizeHints" structure,
     #but we use a different naming (for historical reason and backwards compatibility)
     #so rename the fields:
     hints = {}
     if size_hints:
         TRANSLATED_NAMES = {
             "position": "position",
             "size": "size",
             "base_size": "base-size",
             "resize_inc": "increment",
             "win_gravity": "gravity",
             "min_aspect_ratio": "minimum-aspect-ratio",
             "max_aspect_ratio": "maximum-aspect-ratio",
         }
         for k, v in size_hints.items():
             trans_name = TRANSLATED_NAMES.get(k)
             if trans_name:
                 hints[trans_name] = v
     #handle min-size and max-size,
     #applying our size constraints if we have any:
     mhints = typedict(size_hints or {})
     hminw, hminh = mhints.intlistget("min_size", (0, 0), 2, 2)
     hmaxw, hmaxh = mhints.intlistget("max_size",
                                      (MAX_WINDOW_SIZE, MAX_WINDOW_SIZE), 2,
                                      2)
     d = self.get("decorations", -1)
     decorated = d == -1 or any(
         (d & 2**b)
         for b in (MotifWMHints.ALL_BIT, MotifWMHints.TITLE_BIT,
                   MotifWMHints.MINIMIZE_BIT, MotifWMHints.MAXIMIZE_BIT))
     cminw, cminh, cmaxw, cmaxh = self.size_constraints
     if decorated:
         #min-size only applies to decorated windows
         if cminw > 0 and cminw > hminw:
             hminw = cminw
         if cminh > 0 and cminh > hminh:
             hminh = cminh
     #max-size applies to all windows:
     if cmaxw > 0 and cmaxw < hmaxw:
         hmaxw = cmaxw
     if cmaxh > 0 and cmaxh < hmaxh:
         hmaxh = cmaxh
     #if the values mean something, expose them:
     if hminw > 0 or hminw > 0:
         hints["minimum-size"] = hminw, hminh
     if hmaxw < MAX_WINDOW_SIZE or hmaxh < MAX_WINDOW_SIZE:
         hints["maximum-size"] = hmaxw, hmaxh
     sanitize_size_hints(hints)
     # Don't send out notify and ConfigureNotify events when this property
     # gets no-op updated -- some apps like FSF Emacs 21 like to update
     # their properties every time they see a ConfigureNotify, and this
     # reduces the chance for us to get caught in loops:
     if self._updateprop("size-hints", hints):
         if self._setup_done:
             self._update_client_geometry()
 def test_sanitize(self):
     from xpra.x11.models.size_hints_util import sanitize_size_hints, MAX_ASPECT
     INTPAIRS = (0, "foo", (1,))
     sanitize_size_hints(None)
     for attr, values in {
         "min-aspect"    : (0, -1, MAX_ASPECT, "foo"),
         "max-aspect"    : (0, -1, MAX_ASPECT, "foo"),
         "minimum-aspect-ratio"  : ((0, 1), (0, 0), (MAX_ASPECT, 1), "foo"),
         "maximum-aspect-ratio"  : ((0, 1), (0, 0), (MAX_ASPECT, 1), "foo"),
         "maximum-size"  : INTPAIRS,
         "minimum-size"  : INTPAIRS,
         "base-size"     : INTPAIRS,
         "increment"     : INTPAIRS,
         }.items():
         for value in values:
             hints = {}
             hints[attr] = value
             sanitize_size_hints(hints)
             assert attr not in hints, "%s=%s should have been removed" % (attr, value)
     hints = {
         "minimum-size"  : (-1, -1),
         "maximum-size"  : (-1, -1),
         }
     sanitize_size_hints(hints)
     assert hints.get("minimum-size") is None
     assert hints.get("maximum-size") is None
     for mins, maxs in ((100, 50), (512, 128), (512, 256),):
         hints = {
             "minimum-size"  : (mins, mins),
             "maximum-size"  : (maxs, maxs),
             }
         sanitize_size_hints(hints)
         assert hints.get("minimum-size")==hints.get("maximum-size")