[X2Go-Commits] [nx-libs] 13/23: nxagent: use XAllocSizeHints() instead of XSizeHints struct

git-admin at x2go.org git-admin at x2go.org
Sat Jun 16 15:30:48 CEST 2018


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch 3.6.x
in repository nx-libs.

commit 82dc00539c12323bb8daa8e0ada6e8eab8561e09
Author: Ulrich Sibiller <uli42 at gmx.de>
Date:   Wed Apr 11 00:10:20 2018 +0200

    nxagent: use XAllocSizeHints() instead of XSizeHints struct
    
    This is the preferred way. It ensures, that
    a) the data is zeroed
    b) a correct size in case xlib is changing the size of the structure in future releases
---
 nx-X11/programs/Xserver/hw/nxagent/Events.c |  37 ++----
 nx-X11/programs/Xserver/hw/nxagent/Screen.c | 188 +++++++++++++++++-----------
 nx-X11/programs/Xserver/hw/nxagent/Screen.h |   2 +
 3 files changed, 130 insertions(+), 97 deletions(-)

diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c
index 177860d..9ded855 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Events.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c
@@ -575,8 +575,6 @@ void nxagentInternalWindowsTree(WindowPtr pWin, int indent)
 
 void nxagentSwitchResizeMode(ScreenPtr pScreen)
 {
-  XSizeHints sizeHints;
-
   #ifdef DEBUG
   fprintf(stderr, "nxagentSwitchResizeMode called.\n");
   #endif
@@ -585,8 +583,6 @@ void nxagentSwitchResizeMode(ScreenPtr pScreen)
 
   nxagentChangeOption(DesktopResize, !desktopResize);
 
-  sizeHints.flags = PMaxSize;
-
   if (nxagentOption(DesktopResize) == 0)
   {
     fprintf(stderr,"Info: Disabled desktop resize mode in agent.\n");
@@ -595,11 +591,9 @@ void nxagentSwitchResizeMode(ScreenPtr pScreen)
 
     if (nxagentOption(Fullscreen) == 0)
     {
-      sizeHints.max_width = nxagentOption(RootWidth);
-      sizeHints.max_height = nxagentOption(RootHeight);
-
-      XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum],
-                            &sizeHints);
+      nxagentSetWMNormalHintsMaxsize(pScreen,
+                                     nxagentOption(RootWidth),
+                                     nxagentOption(RootHeight));
     }
   }
   else
@@ -616,24 +610,18 @@ void nxagentSwitchResizeMode(ScreenPtr pScreen)
       NXSetExposeParameters(nxagentDisplay, 0, 0, 0);
     }
 
-    sizeHints.max_width = WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
-    sizeHints.max_height = HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
-
-    XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum],
-                          &sizeHints);
+    nxagentSetWMNormalHintsMaxsize(pScreen,
+                                   WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)),
+                                   HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)));
   }
 }
 
 void nxagentShadowSwitchResizeMode(ScreenPtr pScreen)
 {
-  XSizeHints sizeHints;
-
   int desktopResize = nxagentOption(DesktopResize);
 
   nxagentChangeOption(DesktopResize, !desktopResize);
 
-  sizeHints.flags = PMaxSize;
-
   if (nxagentOption(DesktopResize) == 0)
   {
     nxagentShadowSetRatio(1.0, 1.0);
@@ -641,8 +629,9 @@ void nxagentShadowSwitchResizeMode(ScreenPtr pScreen)
     nxagentShadowCreateMainWindow(screenInfo.screens[DefaultScreen(nxagentDisplay)], screenInfo.screens[0]->root,
                                       screenInfo.screens[0]->root -> drawable.width, screenInfo.screens[0]->root -> drawable.height);
 
-    sizeHints.max_width = nxagentOption(RootWidth);
-    sizeHints.max_height = nxagentOption(RootHeight);
+    nxagentSetWMNormalHintsMaxsize(pScreen,
+                                   nxagentOption(RootWidth),
+                                   nxagentOption(RootHeight));
 
     fprintf(stderr,"Info: Disabled resize mode in shadow agent.\n");
   }
@@ -657,14 +646,12 @@ void nxagentShadowSwitchResizeMode(ScreenPtr pScreen)
                                       screenInfo.screens[0]->root, screenInfo.screens[0]->root -> drawable.width,
                                           screenInfo.screens[0]->root -> drawable.height);
 
-    sizeHints.max_width = WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
-    sizeHints.max_height = HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
+    nxagentSetWMNormalHintsMaxsize(pScreen,
+                                   WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)),
+                                   HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)));
 
     fprintf(stderr,"Info: Enabled resize mode in shadow agent.\n");
   }
-
-  XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum],
-                       &sizeHints);
 }
 
 static void nxagentSwitchDeferMode(void)
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Screen.c b/nx-X11/programs/Xserver/hw/nxagent/Screen.c
index 39a5b77..cd50c96 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Screen.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Screen.c
@@ -376,8 +376,8 @@ Window nxagentCreateIconWindow(void)
   unsigned long valuemask;
   char* window_name;
   XTextProperty windowName;
-  XSizeHints sizeHints;
-  XWMHints wmHints;
+  XSizeHints* sizeHints;
+  XWMHints* wmHints;
   Window w;
   Mask mask;
 
@@ -416,26 +416,40 @@ Window nxagentCreateIconWindow(void)
 
   window_name = nxagentWindowName;
   XStringListToTextProperty(&window_name, 1, &windowName);
-  sizeHints.flags = PMinSize | PMaxSize;
-  sizeHints.min_width = sizeHints.max_width = 1;
-  sizeHints.min_height = sizeHints.max_height = 1;
-  wmHints.flags = IconPixmapHint | IconMaskHint;
-  wmHints.initial_state = IconicState;
-  wmHints.icon_pixmap = nxagentIconPixmap;
-
-  if (useXpmIcon)
+
+  if ((sizeHints = XAllocSizeHints()))
   {
-    wmHints.icon_mask = nxagentIconShape;
-    wmHints.flags = IconPixmapHint | IconMaskHint;
+    sizeHints->flags = PMinSize | PMaxSize;
+    sizeHints->min_width = sizeHints->max_width = 1;
+    sizeHints->min_height = sizeHints->max_height = 1;
   }
-  else
+
+  if ((wmHints = XAllocWMHints()))
   {
-    wmHints.flags = StateHint | IconPixmapHint;
+    wmHints->flags = IconPixmapHint | IconMaskHint;
+    wmHints->initial_state = IconicState;
+    wmHints->icon_pixmap = nxagentIconPixmap;
+
+    if (useXpmIcon)
+    {
+      wmHints->icon_mask = nxagentIconShape;
+      wmHints->flags = IconPixmapHint | IconMaskHint;
+    }
+    else
+    {
+      wmHints->flags = StateHint | IconPixmapHint;
+    }
   }
 
   XSetWMProperties(nxagentDisplay, w,
                       &windowName, &windowName,
-                          NULL , 0 , &sizeHints, &wmHints, NULL);
+                          NULL , 0 , sizeHints, wmHints, NULL);
+
+  if (sizeHints)
+    XFree(sizeHints);
+
+  if (wmHints)
+    XFree(wmHints);
 
   /*
    * Enable events from the icon window.
@@ -839,8 +853,8 @@ Bool nxagentOpenScreen(ScreenPtr pScreen,
   unsigned long valuemask;
   XSetWindowAttributes attributes;
   XWindowAttributes gattributes;
-  XSizeHints sizeHints;
-  XWMHints wmHints;
+  XSizeHints* sizeHints;
+  XWMHints* wmHints;
   Mask mask;
   Bool resetAgentPosition = False;
 
@@ -1866,52 +1880,61 @@ N/A
       XSelectInput(nxagentDisplay, nxagentFullscreenWindow, mask);
     }
 
-    sizeHints.flags = PPosition | PMinSize | PMaxSize;
-    sizeHints.x = nxagentOption(X) + POSITION_OFFSET;
-    sizeHints.y = nxagentOption(Y) + POSITION_OFFSET;
-    sizeHints.min_width = MIN_NXAGENT_WIDTH;
-    sizeHints.min_height = MIN_NXAGENT_HEIGHT;
-
-    sizeHints.width = nxagentOption(RootWidth);
-    sizeHints.height = nxagentOption(RootHeight);
-
-    if (nxagentOption(DesktopResize) == 1 || nxagentOption(Fullscreen) == 1)
-    {
-      sizeHints.max_width = WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
-      sizeHints.max_height = HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
-    }
-    else
+    if ((sizeHints = XAllocSizeHints()))
     {
-      sizeHints.max_width = nxagentOption(RootWidth);
-      sizeHints.max_height = nxagentOption(RootHeight);
-    }
+      sizeHints->flags = PPosition | PMinSize | PMaxSize;
+      sizeHints->x = nxagentOption(X) + POSITION_OFFSET;
+      sizeHints->y = nxagentOption(Y) + POSITION_OFFSET;
+      sizeHints->min_width = MIN_NXAGENT_WIDTH;
+      sizeHints->min_height = MIN_NXAGENT_HEIGHT;
+
+      sizeHints->width = nxagentOption(RootWidth);
+      sizeHints->height = nxagentOption(RootHeight);
 
-    if (nxagentUserGeometry.flag & XValue || nxagentUserGeometry.flag & YValue)
-      sizeHints.flags |= USPosition;
-    if (nxagentUserGeometry.flag & WidthValue || nxagentUserGeometry.flag & HeightValue)
-      sizeHints.flags |= USSize;
+      if (nxagentOption(DesktopResize) == 1 || nxagentOption(Fullscreen) == 1)
+      {
+        sizeHints->max_width = WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
+        sizeHints->max_height = HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
+      }
+      else
+      {
+        sizeHints->max_width = nxagentOption(RootWidth);
+        sizeHints->max_height = nxagentOption(RootHeight);
+      }
 
+      if (nxagentUserGeometry.flag & XValue || nxagentUserGeometry.flag & YValue)
+        sizeHints->flags |= USPosition;
+      if (nxagentUserGeometry.flag & WidthValue || nxagentUserGeometry.flag & HeightValue)
+        sizeHints->flags |= USSize;
+    }
     /* FIXME: deprecated, replaced by XSetWmProperties() */
     XSetStandardProperties(nxagentDisplay,
                            nxagentDefaultWindows[pScreen->myNum],
                            nxagentWindowName,
                            nxagentWindowName,
                            nxagentIconPixmap,
-                           argv, argc, &sizeHints);
+                           argv, argc, sizeHints);
 
-    wmHints.icon_pixmap = nxagentIconPixmap;
+    if (sizeHints)
+      XFree(sizeHints);
 
-    if (useXpmIcon)
-    {
-      wmHints.icon_mask = nxagentIconShape;
-      wmHints.flags = IconPixmapHint | IconMaskHint;
-    }
-    else
+    if ((wmHints = XAllocWMHints()))
     {
-      wmHints.flags = IconPixmapHint;
-    }
+      wmHints->icon_pixmap = nxagentIconPixmap;
 
-    XSetWMHints(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum], &wmHints);
+      if (useXpmIcon)
+      {
+        wmHints->icon_mask = nxagentIconShape;
+        wmHints->flags = IconPixmapHint | IconMaskHint;
+      }
+      else
+      {
+        wmHints->flags = IconPixmapHint;
+      }
+
+      XSetWMHints(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum], wmHints);
+      XFree(wmHints);
+    }
 
     /*
      * Clear the window but let it unmapped. We'll map it
@@ -4531,49 +4554,73 @@ void nxagentRestoreAreas(PixmapPtr pPixmap, RegionPtr prgnRestore, int xorg,
 
 void nxagentSetWMNormalHints(int screen, int width, int height)
 {
-  XSizeHints sizeHints;
+  XSizeHints* sizeHints = XAllocSizeHints();
+
+  if (!sizeHints)
+    return;
 
   /*
    * Change agent window size and size hints.
    */
 
-  sizeHints.flags = PPosition | PMinSize | PMaxSize;
-  sizeHints.x = nxagentOption(X);
-  sizeHints.y = nxagentOption(Y);
+  sizeHints->flags = PPosition | PMinSize | PMaxSize;
+  sizeHints->x = nxagentOption(X);
+  sizeHints->y = nxagentOption(Y);
 
-  sizeHints.min_width = MIN_NXAGENT_WIDTH;
-  sizeHints.min_height = MIN_NXAGENT_HEIGHT;
+  sizeHints->min_width = MIN_NXAGENT_WIDTH;
+  sizeHints->min_height = MIN_NXAGENT_HEIGHT;
 
-  sizeHints.width = width;
-  sizeHints.height = height;
+  sizeHints->width = width;
+  sizeHints->height = height;
 
   if (nxagentOption(DesktopResize) == 1)
   {
-    sizeHints.max_width = WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
-    sizeHints.max_height = HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
+    sizeHints->max_width = WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
+    sizeHints->max_height = HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
   }
   else
   {
-    sizeHints.max_width = nxagentOption(RootWidth);
-    sizeHints.max_height = nxagentOption(RootHeight);
+    sizeHints->max_width = nxagentOption(RootWidth);
+    sizeHints->max_height = nxagentOption(RootHeight);
   }
 
   if (nxagentUserGeometry.flag & XValue || nxagentUserGeometry.flag & YValue)
   {
-    sizeHints.flags |= USPosition;
+    sizeHints->flags |= USPosition;
   }
 
   if (nxagentUserGeometry.flag & WidthValue || nxagentUserGeometry.flag & HeightValue)
   {
-    sizeHints.flags |= USSize;
+    sizeHints->flags |= USSize;
   }
 
-  XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[screen], &sizeHints);
+  XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[screen], sizeHints);
+
+  XFree(sizeHints);
+}
+
+/*
+  set maxsize in WMNormalSizeHints
+  Note: this will _drop_ all existing hints since XSetWMNormalHints()
+  replaces any existing property
+*/
+void nxagentSetWMNormalHintsMaxsize(ScreenPtr pScreen, int maxwidth, int maxheight)
+{
+  XSizeHints* sizeHints;
+
+  if ((sizeHints = XAllocSizeHints()))
+  {
+    sizeHints->flags = PMaxSize;
+    sizeHints->max_width = maxwidth;
+    sizeHints->max_height = maxheight;
+    XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum],
+                      sizeHints);
+    XFree(sizeHints);
+  }
 }
 
 void nxagentShadowAdaptToRatio(void)
 {
-  XSizeHints sizeHints;
   ScreenPtr pScreen;
   RegionRec region;
   BoxRec box;
@@ -4585,12 +4632,9 @@ void nxagentShadowAdaptToRatio(void)
 
   nxagentShadowCreateMainWindow(pScreen, screenInfo.screens[0]->root, nxagentShadowWidth, nxagentShadowHeight);
 
-  sizeHints.max_width = WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
-  sizeHints.max_height = HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
-
-  sizeHints.flags = PMaxSize;
-
-  XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum], &sizeHints);
+  nxagentSetWMNormalHintsMaxsize(pScreen,
+                                 WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)),
+                                 HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)));
 
   box.x1 = 0;
   box.y1 = 0;
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Screen.h b/nx-X11/programs/Xserver/hw/nxagent/Screen.h
index 416136e..8e5865f 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Screen.h
+++ b/nx-X11/programs/Xserver/hw/nxagent/Screen.h
@@ -132,6 +132,8 @@ void nxagentShadowSetWindowsSize(void);
 
 void nxagentSetWMNormalHints(int, int, int);
 
+void nxagentSetWMNormalHintsMaxsize(ScreenPtr, int, int);
+
 void nxagentShadowSetRatio(float, float);
 
 /*

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/nx-libs.git


More information about the x2go-commits mailing list