ref: 45d5ae0b39ece30ecb7804e1e98239e8fe119bfa
parent: 4fd4bb2017a76e09d8f2309211037479d6219507
author: Jacob Moody <[email protected]>
date: Fri Jan 20 01:47:44 EST 2023
gui-wl: implement pointer warp for wlroots
--- a/gui-wl/Makefile
+++ b/gui-wl/Makefile
@@ -10,6 +10,7 @@
xdg-shell-protocol.h\
xdg-decoration-protocol.h\
xdg-primary-selection-protocol.h\
+ wlr-virtual-pointer.h\
wl-inc.h\
OFILES=\
@@ -16,9 +17,19 @@
xdg-shell-protocol.$O\
xdg-decoration-protocol.$O\
xdg-primary-selection-protocol.$O\
+ wlr-virtual-pointer.$O\
wl-cb.$O\
wl-screen.$O\
wl-util.$O\
+
+wlr-virtual-pointer-unstable-v1.xml:
+ curl https://gitlab.freedesktop.org/wlroots/wlr-protocols/-/raw/master/unstable/wlr-virtual-pointer-unstable-v1.xml > $@
+
+wlr-virtual-pointer.c: wlr-virtual-pointer-unstable-v1.xml
+ wayland-scanner private-code < wlr-virtual-pointer-unstable-v1.xml > $@ || { rm -f $@; exit 1; }
+
+wlr-virtual-pointer.h: wlr-virtual-pointer-unstable-v1.xml
+ wayland-scanner client-header < wlr-virtual-pointer-unstable-v1.xml > $@ || { rm -f $@; exit 1; }
xdg-shell-protocol.c:
wayland-scanner private-code < $(XDG_SHELL) > $@ || { rm -f $@; exit 1; }
--- a/gui-wl/wl-cb.c
+++ b/gui-wl/wl-cb.c
@@ -7,10 +7,12 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <time.h>
#include <xkbcommon/xkbcommon.h>
#include "xdg-shell-protocol.h"
#include "xdg-decoration-protocol.h"
#include "xdg-primary-selection-protocol.h"
+#include "wlr-virtual-pointer.h"
#include "u.h"
#include "lib.h"
@@ -29,6 +31,7 @@
#undef pipe
#undef write
#undef read
+#undef time
static void
xdg_surface_handle_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial)
@@ -660,6 +663,8 @@
wl->decoman = wl_registry_bind(registry, name, &zxdg_decoration_manager_v1_interface, 1);
} else if(strcmp(interface, zwp_primary_selection_device_manager_v1_interface.name) == 0) {
wl->primsel = wl_registry_bind(registry, name, &zwp_primary_selection_device_manager_v1_interface, 1);
+ } else if(strcmp(interface, zwlr_virtual_pointer_manager_v1_interface.name) == 0) {
+ wl->vpmgr = wl_registry_bind(registry, name, &zwlr_virtual_pointer_manager_v1_interface, 1);
}
}
@@ -696,6 +701,9 @@
if(wl->shm == nil || wl->compositor == nil || wl->xdg_wm_base == nil || wl->seat == nil || wl->decoman == nil || wl->primsel == nil)
sysfatal("registration fell short");
+ if(wl->vpmgr != nil)
+ wl->vpointer = zwlr_virtual_pointer_manager_v1_create_virtual_pointer(wl->vpmgr, wl->seat);
+
wlallocbuffer(wl);
wl->surface = wl_compositor_create_surface(wl->compositor);
@@ -760,4 +768,18 @@
s = strdup(wl->clip.content != nil ? wl->clip.content : "");
qunlock(&wl->clip.lk);
return s;
+}
+
+void
+wlsetmouse(Wlwin *wl, Point p)
+{
+ Point delta;
+ if (wl->vpointer == nil)
+ return;
+
+ delta.x = p.x - wl->mouse.xy.x;
+ delta.y = p.y - wl->mouse.xy.y;
+ wl->mouse.xy = p;
+ zwlr_virtual_pointer_v1_motion(wl->vpointer, time(nil) * 1000, delta.x * 256, delta.y * 256);
+ zwlr_virtual_pointer_v1_frame(wl->vpointer);
}
--- a/gui-wl/wl-inc.h
+++ b/gui-wl/wl-inc.h
@@ -80,6 +80,9 @@
struct zwp_primary_selection_device_manager_v1 *primsel;
struct zwp_primary_selection_device_v1 *primsel_device;
+
+ struct zwlr_virtual_pointer_manager_v1 *vpmgr;
+ struct zwlr_virtual_pointer_v1 *vpointer;
};
void wlallocbuffer(Wlwin*);
@@ -87,6 +90,7 @@
void wlsettitle(Wlwin*, char*);
char* wlgetsnarf(Wlwin*);
void wlsetsnarf(Wlwin*, char*);
+void wlsetmouse(Wlwin*, Point);
void wldrawcursor(Wlwin*, Cursorinfo*);
void wlresize(Wlwin*, int, int);
void wlflush(Wlwin*);
--- a/gui-wl/wl-screen.c
+++ b/gui-wl/wl-screen.c
@@ -177,6 +177,7 @@
void
mouseset(Point p)
{
+ wlsetmouse(gwin, p);
}
char*