(!1654) Xnest: replace XParseGeometry() by own implementation
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
		
							parent
							
								
									5bd0415613
								
							
						
					
					
						commit
						25e854979c
					
				| 
						 | 
					@ -26,7 +26,7 @@ is" without express or implied warranty.
 | 
				
			||||||
#include "scrnintstr.h"
 | 
					#include "scrnintstr.h"
 | 
				
			||||||
#include "servermd.h"
 | 
					#include "servermd.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "Xnest.h"
 | 
					#include "xnest-xcb.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "Display.h"
 | 
					#include "Display.h"
 | 
				
			||||||
#include "Args.h"
 | 
					#include "Args.h"
 | 
				
			||||||
| 
						 | 
					@ -125,13 +125,7 @@ ddxProcessArgument(int argc, char *argv[], int i)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (!strcmp(argv[i], "-geometry")) {
 | 
					    if (!strcmp(argv[i], "-geometry")) {
 | 
				
			||||||
        if (++i < argc) {
 | 
					        if (++i < argc) {
 | 
				
			||||||
            int x, y; unsigned w, h;
 | 
					            if (xnest_parse_geometry(argv[i], &xnestGeometry))
 | 
				
			||||||
            xnestUserGeometry = XParseGeometry(argv[i], &x, &y, &w, &h);
 | 
					 | 
				
			||||||
            xnestGeometry = (xRectangle) {
 | 
					 | 
				
			||||||
                .x = x, .y = y, .width = w, .height = h,
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (xnestUserGeometry)
 | 
					 | 
				
			||||||
                return 2;
 | 
					                return 2;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -160,17 +160,17 @@ xnestOpenDisplay(int argc, char *argv[])
 | 
				
			||||||
                  0,
 | 
					                  0,
 | 
				
			||||||
                  NULL);
 | 
					                  NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!(xnestUserGeometry & XValue))
 | 
					    if (!(xnestUserGeometry & XCB_CONFIG_WINDOW_X))
 | 
				
			||||||
        xnestGeometry.x = 0;
 | 
					        xnestGeometry.x = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!(xnestUserGeometry & YValue))
 | 
					    if (!(xnestUserGeometry & XCB_CONFIG_WINDOW_Y))
 | 
				
			||||||
        xnestGeometry.y = 0;
 | 
					        xnestGeometry.y = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (xnestParentWindow == 0) {
 | 
					    if (xnestParentWindow == 0) {
 | 
				
			||||||
        if (!(xnestUserGeometry & WidthValue))
 | 
					        if (!(xnestUserGeometry & XCB_CONFIG_WINDOW_WIDTH))
 | 
				
			||||||
            xnestGeometry.width = 3 * xnestUpstreamInfo.screenInfo->width_in_pixels / 4;
 | 
					            xnestGeometry.width = 3 * xnestUpstreamInfo.screenInfo->width_in_pixels / 4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!(xnestUserGeometry & HeightValue))
 | 
					        if (!(xnestUserGeometry & XCB_CONFIG_WINDOW_HEIGHT))
 | 
				
			||||||
            xnestGeometry.height = 3 * xnestUpstreamInfo.screenInfo->height_in_pixels / 4;
 | 
					            xnestGeometry.height = 3 * xnestUpstreamInfo.screenInfo->height_in_pixels / 4;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,6 +17,8 @@ is" without express or implied warranty.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "colormap.h"
 | 
					#include "colormap.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Xnest.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define UNDEFINED -1
 | 
					#define UNDEFINED -1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MAXDEPTH 32
 | 
					#define MAXDEPTH 32
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -416,9 +416,11 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
 | 
				
			||||||
            .max_height = xnestGeometry.height,
 | 
					            .max_height = xnestGeometry.height,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (xnestUserGeometry & XValue || xnestUserGeometry & YValue)
 | 
					        if (xnestUserGeometry & XCB_CONFIG_WINDOW_X ||
 | 
				
			||||||
 | 
					            xnestUserGeometry & XCB_CONFIG_WINDOW_Y)
 | 
				
			||||||
            sizeHints.flags |= XCB_ICCCM_SIZE_HINT_US_POSITION;
 | 
					            sizeHints.flags |= XCB_ICCCM_SIZE_HINT_US_POSITION;
 | 
				
			||||||
        if (xnestUserGeometry & WidthValue || xnestUserGeometry & HeightValue)
 | 
					        if (xnestUserGeometry & XCB_CONFIG_WINDOW_WIDTH ||
 | 
				
			||||||
 | 
					            xnestUserGeometry & XCB_CONFIG_WINDOW_HEIGHT)
 | 
				
			||||||
            sizeHints.flags |= XCB_ICCCM_SIZE_HINT_US_SIZE;
 | 
					            sizeHints.flags |= XCB_ICCCM_SIZE_HINT_US_SIZE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const size_t windowNameLen = strlen(xnestWindowName);
 | 
					        const size_t windowNameLen = strlen(xnestWindowName);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -318,3 +318,100 @@ xRectangle xnest_get_geometry(xcb_connection_t *conn, uint32_t window)
 | 
				
			||||||
        .width = reply->width,
 | 
					        .width = reply->width,
 | 
				
			||||||
        .height = reply->height };
 | 
					        .height = reply->height };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int __readint(const char *str, const char **next)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int res = 0, sign = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (*str=='+')
 | 
				
			||||||
 | 
					        str++;
 | 
				
			||||||
 | 
					    else if (*str=='-') {
 | 
				
			||||||
 | 
					        str++;
 | 
				
			||||||
 | 
					        sign = -1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (; (*str>='0') && (*str<='9'); str++)
 | 
				
			||||||
 | 
					        res = (res * 10) + (*str-'0');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    *next = str;
 | 
				
			||||||
 | 
					    return sign * res;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int xnest_parse_geometry(const char *string, xRectangle *geometry)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int mask = 0;
 | 
				
			||||||
 | 
					    const char *next;
 | 
				
			||||||
 | 
					    xRectangle temp = { 0 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ((string == NULL) || (*string == '\0')) return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (*string == '=')
 | 
				
			||||||
 | 
					        string++;  /* ignore possible '=' at beg of geometry spec */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (*string != '+' && *string != '-' && *string != 'x') {
 | 
				
			||||||
 | 
					        temp.width = __readint(string, &next);
 | 
				
			||||||
 | 
					        if (string == next)
 | 
				
			||||||
 | 
					            return 0;
 | 
				
			||||||
 | 
					        string = next;
 | 
				
			||||||
 | 
					        mask |= XCB_CONFIG_WINDOW_WIDTH;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (*string == 'x' || *string == 'X') {
 | 
				
			||||||
 | 
					        string++;
 | 
				
			||||||
 | 
					        temp.height = __readint(string, &next);
 | 
				
			||||||
 | 
					        if (string == next)
 | 
				
			||||||
 | 
					            return 0;
 | 
				
			||||||
 | 
					        string = next;
 | 
				
			||||||
 | 
					        mask |= XCB_CONFIG_WINDOW_HEIGHT;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ((*string == '+') || (*string== '-')) {
 | 
				
			||||||
 | 
					        if (*string== '-') {
 | 
				
			||||||
 | 
					            string++;
 | 
				
			||||||
 | 
					            temp.x = -__readint(string, &next);
 | 
				
			||||||
 | 
					            if (string == next)
 | 
				
			||||||
 | 
					                return 0;
 | 
				
			||||||
 | 
					            string = next;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            string++;
 | 
				
			||||||
 | 
					            temp.x = __readint(string, &next);
 | 
				
			||||||
 | 
					            if (string == next)
 | 
				
			||||||
 | 
					                return 0;
 | 
				
			||||||
 | 
					            string = next;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        mask |= XCB_CONFIG_WINDOW_X;
 | 
				
			||||||
 | 
					        if ((*string == '+') || (*string== '-')) {
 | 
				
			||||||
 | 
					            if (*string== '-') {
 | 
				
			||||||
 | 
					                string++;
 | 
				
			||||||
 | 
					                temp.y = -__readint(string, &next);
 | 
				
			||||||
 | 
					                if (string == next)
 | 
				
			||||||
 | 
					                    return 0;
 | 
				
			||||||
 | 
					                string = next;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                string++;
 | 
				
			||||||
 | 
					                temp.y = __readint(string, &next);
 | 
				
			||||||
 | 
					                if (string == next)
 | 
				
			||||||
 | 
					                    return 0;
 | 
				
			||||||
 | 
					                string = next;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            mask |= XCB_CONFIG_WINDOW_Y;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (*string != '\0') return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (mask & XCB_CONFIG_WINDOW_X)
 | 
				
			||||||
 | 
					        geometry->x = temp.x;
 | 
				
			||||||
 | 
					    if (mask & XCB_CONFIG_WINDOW_Y)
 | 
				
			||||||
 | 
					        geometry->y = temp.y;
 | 
				
			||||||
 | 
					    if (mask & XCB_CONFIG_WINDOW_WIDTH)
 | 
				
			||||||
 | 
					        geometry->width = temp.width;
 | 
				
			||||||
 | 
					    if (mask & XCB_CONFIG_WINDOW_HEIGHT)
 | 
				
			||||||
 | 
					        geometry->height = temp.height;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return mask;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -45,4 +45,6 @@ void xnest_get_pointer_control(xcb_connection_t *conn, int *acc_num, int *acc_de
 | 
				
			||||||
 | 
					
 | 
				
			||||||
xRectangle xnest_get_geometry(xcb_connection_t *conn, uint32_t window);
 | 
					xRectangle xnest_get_geometry(xcb_connection_t *conn, uint32_t window);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int xnest_parse_geometry(const char *string, xRectangle *geometry);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* __XNEST__XCB_H */
 | 
					#endif /* __XNEST__XCB_H */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue