Commit 82dc0053 authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

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
parent 82c4c28e
...@@ -575,8 +575,6 @@ void nxagentInternalWindowsTree(WindowPtr pWin, int indent) ...@@ -575,8 +575,6 @@ void nxagentInternalWindowsTree(WindowPtr pWin, int indent)
void nxagentSwitchResizeMode(ScreenPtr pScreen) void nxagentSwitchResizeMode(ScreenPtr pScreen)
{ {
XSizeHints sizeHints;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentSwitchResizeMode called.\n"); fprintf(stderr, "nxagentSwitchResizeMode called.\n");
#endif #endif
...@@ -585,8 +583,6 @@ void nxagentSwitchResizeMode(ScreenPtr pScreen) ...@@ -585,8 +583,6 @@ void nxagentSwitchResizeMode(ScreenPtr pScreen)
nxagentChangeOption(DesktopResize, !desktopResize); nxagentChangeOption(DesktopResize, !desktopResize);
sizeHints.flags = PMaxSize;
if (nxagentOption(DesktopResize) == 0) if (nxagentOption(DesktopResize) == 0)
{ {
fprintf(stderr,"Info: Disabled desktop resize mode in agent.\n"); fprintf(stderr,"Info: Disabled desktop resize mode in agent.\n");
...@@ -595,11 +591,9 @@ void nxagentSwitchResizeMode(ScreenPtr pScreen) ...@@ -595,11 +591,9 @@ void nxagentSwitchResizeMode(ScreenPtr pScreen)
if (nxagentOption(Fullscreen) == 0) if (nxagentOption(Fullscreen) == 0)
{ {
sizeHints.max_width = nxagentOption(RootWidth); nxagentSetWMNormalHintsMaxsize(pScreen,
sizeHints.max_height = nxagentOption(RootHeight); nxagentOption(RootWidth),
nxagentOption(RootHeight));
XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum],
&sizeHints);
} }
} }
else else
...@@ -616,24 +610,18 @@ void nxagentSwitchResizeMode(ScreenPtr pScreen) ...@@ -616,24 +610,18 @@ void nxagentSwitchResizeMode(ScreenPtr pScreen)
NXSetExposeParameters(nxagentDisplay, 0, 0, 0); NXSetExposeParameters(nxagentDisplay, 0, 0, 0);
} }
sizeHints.max_width = WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)); nxagentSetWMNormalHintsMaxsize(pScreen,
sizeHints.max_height = HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)); WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)),
HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)));
XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum],
&sizeHints);
} }
} }
void nxagentShadowSwitchResizeMode(ScreenPtr pScreen) void nxagentShadowSwitchResizeMode(ScreenPtr pScreen)
{ {
XSizeHints sizeHints;
int desktopResize = nxagentOption(DesktopResize); int desktopResize = nxagentOption(DesktopResize);
nxagentChangeOption(DesktopResize, !desktopResize); nxagentChangeOption(DesktopResize, !desktopResize);
sizeHints.flags = PMaxSize;
if (nxagentOption(DesktopResize) == 0) if (nxagentOption(DesktopResize) == 0)
{ {
nxagentShadowSetRatio(1.0, 1.0); nxagentShadowSetRatio(1.0, 1.0);
...@@ -641,8 +629,9 @@ void nxagentShadowSwitchResizeMode(ScreenPtr pScreen) ...@@ -641,8 +629,9 @@ void nxagentShadowSwitchResizeMode(ScreenPtr pScreen)
nxagentShadowCreateMainWindow(screenInfo.screens[DefaultScreen(nxagentDisplay)], screenInfo.screens[0]->root, nxagentShadowCreateMainWindow(screenInfo.screens[DefaultScreen(nxagentDisplay)], screenInfo.screens[0]->root,
screenInfo.screens[0]->root -> drawable.width, screenInfo.screens[0]->root -> drawable.height); screenInfo.screens[0]->root -> drawable.width, screenInfo.screens[0]->root -> drawable.height);
sizeHints.max_width = nxagentOption(RootWidth); nxagentSetWMNormalHintsMaxsize(pScreen,
sizeHints.max_height = nxagentOption(RootHeight); nxagentOption(RootWidth),
nxagentOption(RootHeight));
fprintf(stderr,"Info: Disabled resize mode in shadow agent.\n"); fprintf(stderr,"Info: Disabled resize mode in shadow agent.\n");
} }
...@@ -657,14 +646,12 @@ void nxagentShadowSwitchResizeMode(ScreenPtr pScreen) ...@@ -657,14 +646,12 @@ void nxagentShadowSwitchResizeMode(ScreenPtr pScreen)
screenInfo.screens[0]->root, screenInfo.screens[0]->root -> drawable.width, screenInfo.screens[0]->root, screenInfo.screens[0]->root -> drawable.width,
screenInfo.screens[0]->root -> drawable.height); screenInfo.screens[0]->root -> drawable.height);
sizeHints.max_width = WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)); nxagentSetWMNormalHintsMaxsize(pScreen,
sizeHints.max_height = HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)); WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)),
HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)));
fprintf(stderr,"Info: Enabled resize mode in shadow agent.\n"); fprintf(stderr,"Info: Enabled resize mode in shadow agent.\n");
} }
XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum],
&sizeHints);
} }
static void nxagentSwitchDeferMode(void) static void nxagentSwitchDeferMode(void)
......
...@@ -376,8 +376,8 @@ Window nxagentCreateIconWindow(void) ...@@ -376,8 +376,8 @@ Window nxagentCreateIconWindow(void)
unsigned long valuemask; unsigned long valuemask;
char* window_name; char* window_name;
XTextProperty windowName; XTextProperty windowName;
XSizeHints sizeHints; XSizeHints* sizeHints;
XWMHints wmHints; XWMHints* wmHints;
Window w; Window w;
Mask mask; Mask mask;
...@@ -416,26 +416,40 @@ Window nxagentCreateIconWindow(void) ...@@ -416,26 +416,40 @@ Window nxagentCreateIconWindow(void)
window_name = nxagentWindowName; window_name = nxagentWindowName;
XStringListToTextProperty(&window_name, 1, &windowName); XStringListToTextProperty(&window_name, 1, &windowName);
sizeHints.flags = PMinSize | PMaxSize;
sizeHints.min_width = sizeHints.max_width = 1; if ((sizeHints = XAllocSizeHints()))
sizeHints.min_height = sizeHints.max_height = 1; {
wmHints.flags = IconPixmapHint | IconMaskHint; sizeHints->flags = PMinSize | PMaxSize;
wmHints.initial_state = IconicState; sizeHints->min_width = sizeHints->max_width = 1;
wmHints.icon_pixmap = nxagentIconPixmap; sizeHints->min_height = sizeHints->max_height = 1;
}
if ((wmHints = XAllocWMHints()))
{
wmHints->flags = IconPixmapHint | IconMaskHint;
wmHints->initial_state = IconicState;
wmHints->icon_pixmap = nxagentIconPixmap;
if (useXpmIcon) if (useXpmIcon)
{ {
wmHints.icon_mask = nxagentIconShape; wmHints->icon_mask = nxagentIconShape;
wmHints.flags = IconPixmapHint | IconMaskHint; wmHints->flags = IconPixmapHint | IconMaskHint;
} }
else else
{ {
wmHints.flags = StateHint | IconPixmapHint; wmHints->flags = StateHint | IconPixmapHint;
}
} }
XSetWMProperties(nxagentDisplay, w, XSetWMProperties(nxagentDisplay, w,
&windowName, &windowName, &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. * Enable events from the icon window.
...@@ -839,8 +853,8 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, ...@@ -839,8 +853,8 @@ Bool nxagentOpenScreen(ScreenPtr pScreen,
unsigned long valuemask; unsigned long valuemask;
XSetWindowAttributes attributes; XSetWindowAttributes attributes;
XWindowAttributes gattributes; XWindowAttributes gattributes;
XSizeHints sizeHints; XSizeHints* sizeHints;
XWMHints wmHints; XWMHints* wmHints;
Mask mask; Mask mask;
Bool resetAgentPosition = False; Bool resetAgentPosition = False;
...@@ -1866,52 +1880,61 @@ N/A ...@@ -1866,52 +1880,61 @@ N/A
XSelectInput(nxagentDisplay, nxagentFullscreenWindow, mask); XSelectInput(nxagentDisplay, nxagentFullscreenWindow, mask);
} }
sizeHints.flags = PPosition | PMinSize | PMaxSize; if ((sizeHints = XAllocSizeHints()))
sizeHints.x = nxagentOption(X) + POSITION_OFFSET; {
sizeHints.y = nxagentOption(Y) + POSITION_OFFSET; sizeHints->flags = PPosition | PMinSize | PMaxSize;
sizeHints.min_width = MIN_NXAGENT_WIDTH; sizeHints->x = nxagentOption(X) + POSITION_OFFSET;
sizeHints.min_height = MIN_NXAGENT_HEIGHT; sizeHints->y = nxagentOption(Y) + POSITION_OFFSET;
sizeHints->min_width = MIN_NXAGENT_WIDTH;
sizeHints->min_height = MIN_NXAGENT_HEIGHT;
sizeHints.width = nxagentOption(RootWidth); sizeHints->width = nxagentOption(RootWidth);
sizeHints.height = nxagentOption(RootHeight); sizeHints->height = nxagentOption(RootHeight);
if (nxagentOption(DesktopResize) == 1 || nxagentOption(Fullscreen) == 1) if (nxagentOption(DesktopResize) == 1 || nxagentOption(Fullscreen) == 1)
{ {
sizeHints.max_width = WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)); sizeHints->max_width = WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
sizeHints.max_height = HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)); sizeHints->max_height = HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
} }
else else
{ {
sizeHints.max_width = nxagentOption(RootWidth); sizeHints->max_width = nxagentOption(RootWidth);
sizeHints.max_height = nxagentOption(RootHeight); sizeHints->max_height = nxagentOption(RootHeight);
} }
if (nxagentUserGeometry.flag & XValue || nxagentUserGeometry.flag & YValue) if (nxagentUserGeometry.flag & XValue || nxagentUserGeometry.flag & YValue)
sizeHints.flags |= USPosition; sizeHints->flags |= USPosition;
if (nxagentUserGeometry.flag & WidthValue || nxagentUserGeometry.flag & HeightValue) if (nxagentUserGeometry.flag & WidthValue || nxagentUserGeometry.flag & HeightValue)
sizeHints.flags |= USSize; sizeHints->flags |= USSize;
}
/* FIXME: deprecated, replaced by XSetWmProperties() */ /* FIXME: deprecated, replaced by XSetWmProperties() */
XSetStandardProperties(nxagentDisplay, XSetStandardProperties(nxagentDisplay,
nxagentDefaultWindows[pScreen->myNum], nxagentDefaultWindows[pScreen->myNum],
nxagentWindowName, nxagentWindowName,
nxagentWindowName, nxagentWindowName,
nxagentIconPixmap, nxagentIconPixmap,
argv, argc, &sizeHints); argv, argc, sizeHints);
wmHints.icon_pixmap = nxagentIconPixmap; if (sizeHints)
XFree(sizeHints);
if ((wmHints = XAllocWMHints()))
{
wmHints->icon_pixmap = nxagentIconPixmap;
if (useXpmIcon) if (useXpmIcon)
{ {
wmHints.icon_mask = nxagentIconShape; wmHints->icon_mask = nxagentIconShape;
wmHints.flags = IconPixmapHint | IconMaskHint; wmHints->flags = IconPixmapHint | IconMaskHint;
} }
else else
{ {
wmHints.flags = IconPixmapHint; wmHints->flags = IconPixmapHint;
} }
XSetWMHints(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum], &wmHints); XSetWMHints(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum], wmHints);
XFree(wmHints);
}
/* /*
* Clear the window but let it unmapped. We'll map it * Clear the window but let it unmapped. We'll map it
...@@ -4531,49 +4554,73 @@ void nxagentRestoreAreas(PixmapPtr pPixmap, RegionPtr prgnRestore, int xorg, ...@@ -4531,49 +4554,73 @@ void nxagentRestoreAreas(PixmapPtr pPixmap, RegionPtr prgnRestore, int xorg,
void nxagentSetWMNormalHints(int screen, int width, int height) void nxagentSetWMNormalHints(int screen, int width, int height)
{ {
XSizeHints sizeHints; XSizeHints* sizeHints = XAllocSizeHints();
if (!sizeHints)
return;
/* /*
* Change agent window size and size hints. * Change agent window size and size hints.
*/ */
sizeHints.flags = PPosition | PMinSize | PMaxSize; sizeHints->flags = PPosition | PMinSize | PMaxSize;
sizeHints.x = nxagentOption(X); sizeHints->x = nxagentOption(X);
sizeHints.y = nxagentOption(Y); sizeHints->y = nxagentOption(Y);
sizeHints.min_width = MIN_NXAGENT_WIDTH; sizeHints->min_width = MIN_NXAGENT_WIDTH;
sizeHints.min_height = MIN_NXAGENT_HEIGHT; sizeHints->min_height = MIN_NXAGENT_HEIGHT;
sizeHints.width = width; sizeHints->width = width;
sizeHints.height = height; sizeHints->height = height;
if (nxagentOption(DesktopResize) == 1) if (nxagentOption(DesktopResize) == 1)
{ {
sizeHints.max_width = WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)); sizeHints->max_width = WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
sizeHints.max_height = HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)); sizeHints->max_height = HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay));
} }
else else
{ {
sizeHints.max_width = nxagentOption(RootWidth); sizeHints->max_width = nxagentOption(RootWidth);
sizeHints.max_height = nxagentOption(RootHeight); sizeHints->max_height = nxagentOption(RootHeight);
} }
if (nxagentUserGeometry.flag & XValue || nxagentUserGeometry.flag & YValue) if (nxagentUserGeometry.flag & XValue || nxagentUserGeometry.flag & YValue)
{ {
sizeHints.flags |= USPosition; sizeHints->flags |= USPosition;
} }
if (nxagentUserGeometry.flag & WidthValue || nxagentUserGeometry.flag & HeightValue) 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) void nxagentShadowAdaptToRatio(void)
{ {
XSizeHints sizeHints;
ScreenPtr pScreen; ScreenPtr pScreen;
RegionRec region; RegionRec region;
BoxRec box; BoxRec box;
...@@ -4585,12 +4632,9 @@ void nxagentShadowAdaptToRatio(void) ...@@ -4585,12 +4632,9 @@ void nxagentShadowAdaptToRatio(void)
nxagentShadowCreateMainWindow(pScreen, screenInfo.screens[0]->root, nxagentShadowWidth, nxagentShadowHeight); nxagentShadowCreateMainWindow(pScreen, screenInfo.screens[0]->root, nxagentShadowWidth, nxagentShadowHeight);
sizeHints.max_width = WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)); nxagentSetWMNormalHintsMaxsize(pScreen,
sizeHints.max_height = HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)); WidthOfScreen(DefaultScreenOfDisplay(nxagentDisplay)),
HeightOfScreen(DefaultScreenOfDisplay(nxagentDisplay)));
sizeHints.flags = PMaxSize;
XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum], &sizeHints);
box.x1 = 0; box.x1 = 0;
box.y1 = 0; box.y1 = 0;
......
...@@ -132,6 +132,8 @@ void nxagentShadowSetWindowsSize(void); ...@@ -132,6 +132,8 @@ void nxagentShadowSetWindowsSize(void);
void nxagentSetWMNormalHints(int, int, int); void nxagentSetWMNormalHints(int, int, int);
void nxagentSetWMNormalHintsMaxsize(ScreenPtr, int, int);
void nxagentShadowSetRatio(float, float); void nxagentShadowSetRatio(float, float);
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment