diff --git a/hw/xnest/Args.c b/hw/xnest/Args.c index cf8c82ac2..ab345de5b 100644 --- a/hw/xnest/Args.c +++ b/hw/xnest/Args.c @@ -28,6 +28,7 @@ is" without express or implied warranty. #include "extinit.h" #include "xnest-xcb.h" +#include "parse-geometry.h" #include "Display.h" #include "Args.h" diff --git a/hw/xnest/meson.build b/hw/xnest/meson.build index 28dc78396..2787bd55c 100644 --- a/hw/xnest/meson.build +++ b/hw/xnest/meson.build @@ -10,6 +10,7 @@ srcs = [ 'Handlers.c', 'Init.c', 'Keyboard.c', + 'parse-geometry.c', 'Pixmap.c', 'Pointer.c', 'Screen.c', diff --git a/hw/xnest/parse-geometry.c b/hw/xnest/parse-geometry.c new file mode 100644 index 000000000..54961921e --- /dev/null +++ b/hw/xnest/parse-geometry.c @@ -0,0 +1,108 @@ +/* SPDX-License-Identifier: MIT OR X11 + * + * Copyright © 2024 Enrico Weigelt, metux IT consult + */ +#include + +#include +#include +#include + +#include "parse-geometry.h" + +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/parse-geometry.h b/hw/xnest/parse-geometry.h new file mode 100644 index 000000000..f011a25b4 --- /dev/null +++ b/hw/xnest/parse-geometry.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: MIT OR X11 + * + * Copyright © 2024 Enrico Weigelt, metux IT consult + */ +#ifndef __XNEST__PARSE_GEOMETRY_H +#define __XNEST__PARSE_GEOMETRY_H + +#include + +int xnest_parse_geometry(const char *string, xRectangle *geometry); + +#endif /* __XNEST__XCB_H */ diff --git a/hw/xnest/xcb.c b/hw/xnest/xcb.c index b0b041017..06fe10628 100644 --- a/hw/xnest/xcb.c +++ b/hw/xnest/xcb.c @@ -329,103 +329,6 @@ xRectangle xnest_get_geometry(xcb_connection_t *conn, uint32_t window) .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; -} - uint32_t xnest_visual_map_to_upstream(VisualID visual) { for (int i = 0; i < xnestNumVisualMap; i++) { diff --git a/hw/xnest/xnest-xcb.h b/hw/xnest/xnest-xcb.h index 71a1aa4ac..5f9596150 100644 --- a/hw/xnest/xnest-xcb.h +++ b/hw/xnest/xnest-xcb.h @@ -64,8 +64,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); - uint32_t xnest_visual_map_to_upstream(VisualID visual); uint32_t xnest_upstream_visual_to_cmap(uint32_t visual); uint32_t xnest_visual_to_upstream_cmap(uint32_t visual);