|
| 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 | +} |
0 commit comments