Xnest: replace XGetWindowAttributes() by xcb_get_geometry()

Use xcb function instead of Xlib, and also spare one additional
(unused) request.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-08-14 15:17:44 +02:00
parent 146538a475
commit de13460b05
3 changed files with 31 additions and 4 deletions

View File

@ -147,7 +147,6 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
int numVisuals, numDepths;
int i, j, depthIndex;
unsigned long valuemask;
XWindowAttributes gattributes;
VisualID defaultVisual;
int rootDepth;
miPointerScreenPtr PointPriv;
@ -263,9 +262,9 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
rootDepth = visuals[xnestDefaultVisualIndex].nplanes;
if (xnestParentWindow != 0) {
XGetWindowAttributes(xnestDisplay, xnestParentWindow, &gattributes);
xnestGeometry.width = gattributes.width;
xnestGeometry.height = gattributes.height;
xRectangle r = xnest_get_geometry(xnestUpstreamInfo.conn, xnestParentWindow);
xnestGeometry.width = r.width;
xnestGeometry.height = r.height;
}
/* myNum */

View File

@ -292,3 +292,29 @@ void xnest_get_pointer_control(
*threshold = reply->threshold;
free(reply);
}
xRectangle xnest_get_geometry(xcb_connection_t *conn, uint32_t window)
{
xcb_generic_error_t *err = NULL;
xcb_get_geometry_reply_t *reply = xcb_get_geometry_reply(
xnestUpstreamInfo.conn,
xcb_get_geometry(xnestUpstreamInfo.conn, window),
&err);
if (err) {
ErrorF("failed getting window attributes for %d: %d\n", window, err->error_code);
free(err);
return (xRectangle) { 0 };
}
if (!reply) {
ErrorF("failed getting window attributes for %d: no reply\n", window);
return (xRectangle) { 0 };
}
return (xRectangle) {
.x = reply->x,
.y = reply->y,
.width = reply->width,
.height = reply->height };
}

View File

@ -43,4 +43,6 @@ xcb_get_keyboard_mapping_reply_t *xnest_get_keyboard_mapping(xcb_connection_t *c
void xnest_get_pointer_control(xcb_connection_t *conn, int *acc_num, int *acc_den, int *threshold);
xRectangle xnest_get_geometry(xcb_connection_t *conn, uint32_t window);
#endif /* __XNEST__XCB_H */