aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Sibiller <uli42@gmx.de>2018-04-11 00:10:20 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2018-05-24 09:42:24 +0200
commit82dc00539c12323bb8daa8e0ada6e8eab8561e09 (patch)
treeddc5a99d50ee33951794c36d257e7468b130b03a
parent82c4c28ea726444c355835a5a0850b9dd6865e9a (diff)
downloadnx-libs-82dc00539c12323bb8daa8e0ada6e8eab8561e09.tar.gz
nx-libs-82dc00539c12323bb8daa8e0ada6e8eab8561e09.tar.bz2
nx-libs-82dc00539c12323bb8daa8e0ada6e8eab8561e09.zip
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
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Events.c37
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Screen.c188
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Screen.h2
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 177860d84..9ded855d6 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 39a5b7763..cd50c9698 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 416136e53..8e5865f06 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);
/*