Skip to content

Commit 0fc7bb1

Browse files
committed
Don't try to send grants for not realized windows
We rely on composite redirect mode of the X server to get per window pixmaps. Those are setup/teared-down in compRealizeWindow/ compUnrealizeWindow (via compCheckRedirect). So not realized windows don't have a per window pixmap. Sending grant refs for them was always broken since we didn't send the offset into the screen pixmap in those cases. But with the recent change to not allocate grant refs for the screen pixmap this leads to a noticable error message. So don't try to send grant refs for not realized windows. See also added inline comment and #236
1 parent a7d953a commit 0fc7bb1

File tree

7 files changed

+423
-28
lines changed

7 files changed

+423
-28
lines changed

gui-agent/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ CC ?= gcc
2323
CFLAGS += -I../include/ `pkg-config --cflags vchan` -g -Wall -Wextra -Werror -fPIC \
2424
-Wmissing-prototypes -Wstrict-prototypes -Wold-style-declaration \
2525
-Wold-style-definition
26-
OBJS = vmside.o txrx-vchan.o error.o list.o encoding.o
26+
OBJS = vmside.o txrx-vchan.o error.o list.o encoding.o video-ext-client.o
2727
LIBS = -lX11 -lXdamage -lXcomposite -lXfixes `pkg-config --libs vchan` -lqubesdb \
28-
-lunistring
28+
-lunistring -lXext
2929

3030

3131
all: qubes-gui qubes-gui-runuser

gui-agent/video-ext-client.c

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* The Qubes OS Project, https://www.qubes-os.org/
3+
*
4+
* Copyright (C) 2025 Simon Gaiser <[email protected]>
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*/
20+
21+
#include "video-ext-client.h"
22+
23+
#include <X11/Xlibint.h>
24+
#include <X11/extensions/Xext.h>
25+
#include <X11/extensions/extutil.h>
26+
27+
static int close_display(Display *dpy, XExtCodes *codes);
28+
static Bool wire_to_event(Display *dpy, XEvent *libEv, xEvent *wireEv);
29+
30+
static XExtensionHooks ext_hooks = {
31+
NULL, // create_gc
32+
NULL, // copy_gc
33+
NULL, // flush_gc
34+
NULL, // free_gc
35+
NULL, // create_font
36+
NULL, // free_font
37+
close_display, // close_display
38+
wire_to_event, // wire_to_event
39+
NULL, // event_to_wire (we don't need SendEvent)
40+
NULL, // error
41+
NULL, // error_string
42+
};
43+
44+
static XExtensionInfo _ext_info;
45+
static XExtensionInfo *ext_info = &_ext_info;
46+
static const char * ext_name = QVE_NAME;
47+
48+
#define QVECheckExtension(dpy, info, val) \
49+
XextCheckExtension(dpy, info, ext_name, val)
50+
51+
static XEXT_GENERATE_FIND_DISPLAY(find_display,
52+
ext_info,
53+
ext_name,
54+
&ext_hooks,
55+
QVENumberEvents,
56+
NULL);
57+
58+
static XEXT_GENERATE_CLOSE_DISPLAY(close_display, ext_info);
59+
60+
static Bool
61+
wire_to_event(Display *dpy, XEvent *libEv, xEvent *wireEv)
62+
{
63+
XExtDisplayInfo *info = find_display(dpy);
64+
65+
QVECheckExtension(dpy, info, False);
66+
67+
BYTE type = wireEv->u.u.type;
68+
if ((type & 0x7f) != info->codes->first_event + QVEWindowRealized) {
69+
return False;
70+
}
71+
72+
XQVEWindowRealizedEvent *qLibEv = (XQVEWindowRealizedEvent *)libEv;
73+
xQVEWindowRealizedEvent *qWireEv = (xQVEWindowRealizedEvent *)wireEv;
74+
75+
qLibEv->type = type & 0x7f;
76+
qLibEv->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wireEv);
77+
qLibEv->send_event = (type & 0x80) != 0;
78+
qLibEv->display = dpy;
79+
qLibEv->window = qWireEv->window;
80+
qLibEv->unrealized =
81+
(qWireEv->detail & QVEWindowRealizedDetailUnrealized) != 0;
82+
83+
return True;
84+
}
85+
86+
Bool
87+
XQVEQueryExtension(Display *dpy, int *event_base)
88+
{
89+
XExtDisplayInfo *info = find_display(dpy);
90+
91+
if (!XextHasExtension(info)) {
92+
return False;
93+
}
94+
95+
*event_base = info->codes->first_event;
96+
return True;
97+
}
98+
99+
Bool
100+
XQVERegister(Display *dpy)
101+
{
102+
XExtDisplayInfo *info = find_display(dpy);
103+
104+
QVECheckExtension(dpy, info, False);
105+
106+
LockDisplay(dpy);
107+
xQVEReq *req;
108+
#define X_QVE X_QVERegister
109+
GetReq(QVE, req);
110+
#undef X_QVE
111+
req->reqType = info->codes->major_opcode;
112+
req->QVEReqType = X_QVERegister;
113+
UnlockDisplay(dpy);
114+
SyncHandle();
115+
116+
return True;
117+
}

gui-agent/video-ext-client.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* The Qubes OS Project, https://www.qubes-os.org/
3+
*
4+
* Copyright (C) 2025 Simon Gaiser <[email protected]>
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*/
20+
21+
#pragma once
22+
23+
#include "qubes-video-ext.h"
24+
#include <X11/Xlib.h>
25+
26+
typedef struct {
27+
int type;
28+
unsigned long serial;
29+
Bool send_event;
30+
Display *display;
31+
Window window;
32+
Bool unrealized;
33+
} XQVEWindowRealizedEvent;
34+
35+
Bool XQVERegister(Display *dpy);
36+
Bool XQVEQueryExtension(Display *dpy, int *event_base);

0 commit comments

Comments
 (0)