mirror of
https://github.com/X11Libre/xserver.git
synced 2026-04-14 17:18:09 +00:00
Xnest: move out xnest_parse_geometry to separate .c file
Making it easier to let link it to test cases. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -10,6 +10,7 @@ srcs = [
|
||||
'Handlers.c',
|
||||
'Init.c',
|
||||
'Keyboard.c',
|
||||
'parse-geometry.c',
|
||||
'Pixmap.c',
|
||||
'Pointer.c',
|
||||
'Screen.c',
|
||||
|
||||
108
hw/xnest/parse-geometry.c
Normal file
108
hw/xnest/parse-geometry.c
Normal file
@@ -0,0 +1,108 @@
|
||||
/* SPDX-License-Identifier: MIT OR X11
|
||||
*
|
||||
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
|
||||
*/
|
||||
#include <dix-config.h>
|
||||
|
||||
#include <X11/Xproto.h>
|
||||
#include <X11/Xprotostr.h>
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
12
hw/xnest/parse-geometry.h
Normal file
12
hw/xnest/parse-geometry.h
Normal file
@@ -0,0 +1,12 @@
|
||||
/* SPDX-License-Identifier: MIT OR X11
|
||||
*
|
||||
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
|
||||
*/
|
||||
#ifndef __XNEST__PARSE_GEOMETRY_H
|
||||
#define __XNEST__PARSE_GEOMETRY_H
|
||||
|
||||
#include <X11/Xproto.h>
|
||||
|
||||
int xnest_parse_geometry(const char *string, xRectangle *geometry);
|
||||
|
||||
#endif /* __XNEST__XCB_H */
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user