From c44225d17d5d92362064cd13939746a737067bc8 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 14 Aug 2024 15:57:07 +0200 Subject: [PATCH] Xnest: replace XParseGeometry() by own implementation Signed-off-by: Enrico Weigelt, metux IT consult --- hw/xnest/Args.c | 10 +---- hw/xnest/Display.c | 8 ++-- hw/xnest/Display.h | 2 + hw/xnest/Screen.c | 6 ++- hw/xnest/xcb.c | 97 ++++++++++++++++++++++++++++++++++++++++++++ hw/xnest/xnest-xcb.h | 2 + 6 files changed, 111 insertions(+), 14 deletions(-) diff --git a/hw/xnest/Args.c b/hw/xnest/Args.c index 7af0f37d4..14f3245d5 100644 --- a/hw/xnest/Args.c +++ b/hw/xnest/Args.c @@ -27,7 +27,7 @@ is" without express or implied warranty. #include "servermd.h" #include "extinit.h" -#include "Xnest.h" +#include "xnest-xcb.h" #include "Display.h" #include "Args.h" @@ -137,13 +137,7 @@ ddxProcessArgument(int argc, char *argv[], int i) } if (!strcmp(argv[i], "-geometry")) { if (++i < argc) { - int x, y; unsigned w, h; - xnestUserGeometry = XParseGeometry(argv[i], &x, &y, &w, &h); - xnestGeometry = (xRectangle) { - .x = x, .y = y, .width = w, .height = h, - }; - - if (xnestUserGeometry) + if (xnest_parse_geometry(argv[i], &xnestGeometry)) return 2; } return 0; diff --git a/hw/xnest/Display.c b/hw/xnest/Display.c index 924c36ab0..e1b08d654 100644 --- a/hw/xnest/Display.c +++ b/hw/xnest/Display.c @@ -160,17 +160,17 @@ xnestOpenDisplay(int argc, char *argv[]) 0, NULL); - if (!(xnestUserGeometry & XValue)) + if (!(xnestUserGeometry & XCB_CONFIG_WINDOW_X)) xnestGeometry.x = 0; - if (!(xnestUserGeometry & YValue)) + if (!(xnestUserGeometry & XCB_CONFIG_WINDOW_Y)) xnestGeometry.y = 0; if (xnestParentWindow == 0) { - if (!(xnestUserGeometry & WidthValue)) + if (!(xnestUserGeometry & XCB_CONFIG_WINDOW_WIDTH)) 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; } diff --git a/hw/xnest/Display.h b/hw/xnest/Display.h index a972c84b5..d04b538df 100644 --- a/hw/xnest/Display.h +++ b/hw/xnest/Display.h @@ -17,6 +17,8 @@ is" without express or implied warranty. #include "colormap.h" +#include "Xnest.h" + #define UNDEFINED -1 #define MAXDEPTH 32 diff --git a/hw/xnest/Screen.c b/hw/xnest/Screen.c index df2b23ed0..91d8518db 100644 --- a/hw/xnest/Screen.c +++ b/hw/xnest/Screen.c @@ -414,9 +414,11 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[]) .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; - if (xnestUserGeometry & WidthValue || xnestUserGeometry & HeightValue) + if (xnestUserGeometry & XCB_CONFIG_WINDOW_WIDTH || + xnestUserGeometry & XCB_CONFIG_WINDOW_HEIGHT) sizeHints.flags |= XCB_ICCCM_SIZE_HINT_US_SIZE; const size_t windowNameLen = strlen(xnestWindowName); diff --git a/hw/xnest/xcb.c b/hw/xnest/xcb.c index 57dcd4cdf..f3622346e 100644 --- a/hw/xnest/xcb.c +++ b/hw/xnest/xcb.c @@ -318,3 +318,100 @@ xRectangle xnest_get_geometry(xcb_connection_t *conn, uint32_t window) .width = reply->width, .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; +} diff --git a/hw/xnest/xnest-xcb.h b/hw/xnest/xnest-xcb.h index 7b03811e3..1a76fdaae 100644 --- a/hw/xnest/xnest-xcb.h +++ b/hw/xnest/xnest-xcb.h @@ -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); +int xnest_parse_geometry(const char *string, xRectangle *geometry); + #endif /* __XNEST__XCB_H */