History

gui-wl: implement pointer warp for wlroots

Jacob Moody committed 3 years ago

Commit 45d5ae01 parent 4fd4bb24 files · +38 −0Browse files

Unified · Split

4 files
  1. gui-wl/Makefile +11 −0
  2. gui-wl/wl-cb.c +22 −0
  3. gui-wl/wl-inc.h +4 −0
  4. gui-wl/wl-screen.c +1 −0
gui-wl/Makefile+11−0
@@ -10,16 +10,27 @@ HFILES=\ · 9 unmodified lines
1010 xdg-shell-protocol.h\
1111 xdg-decoration-protocol.h\
1212 xdg-primary-selection-protocol.h\
13+ wlr-virtual-pointer.h\
1314 wl-inc.h\
1415
1516 OFILES=\
1617 xdg-shell-protocol.$O\
1718 xdg-decoration-protocol.$O\
1819 xdg-primary-selection-protocol.$O\
20+ wlr-virtual-pointer.$O\
1921 wl-cb.$O\
2022 wl-screen.$O\
2123 wl-util.$O\
2224
25+wlr-virtual-pointer-unstable-v1.xml:
26+ curl https://gitlab.freedesktop.org/wlroots/wlr-protocols/-/raw/master/unstable/wlr-virtual-pointer-unstable-v1.xml > $@
27+
28+wlr-virtual-pointer.c: wlr-virtual-pointer-unstable-v1.xml
29+ wayland-scanner private-code < wlr-virtual-pointer-unstable-v1.xml > $@ || { rm -f $@; exit 1; }
30+
31+wlr-virtual-pointer.h: wlr-virtual-pointer-unstable-v1.xml
32+ wayland-scanner client-header < wlr-virtual-pointer-unstable-v1.xml > $@ || { rm -f $@; exit 1; }
33+
2334 xdg-shell-protocol.c:
2435 wayland-scanner private-code < $(XDG_SHELL) > $@ || { rm -f $@; exit 1; }
2536
gui-wl/wl-cb.c+22−0
@@ -7,10 +7,12 @@ · 6 unmodified lines
77 #include <sys/mman.h>
88 #include <sys/stat.h>
99 #include <fcntl.h>
10+#include <time.h>
1011 #include <xkbcommon/xkbcommon.h>
1112 #include "xdg-shell-protocol.h"
1213 #include "xdg-decoration-protocol.h"
1314 #include "xdg-primary-selection-protocol.h"
15+#include "wlr-virtual-pointer.h"
1416
1517 #include "u.h"
1618 #include "lib.h"
@@ -29,6 +31,7 @@ · 12 unmodified lines
2931 #undef pipe
3032 #undef write
3133 #undef read
34+#undef time
3235
3336 static void
3437 xdg_surface_handle_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial)
@@ -660,6 +663,8 @@ handle_global(void *data, struct wl_registry *registry, uint32_t name, const cha · 625 unmodified lines
660663 wl->decoman = wl_registry_bind(registry, name, &zxdg_decoration_manager_v1_interface, 1);
661664 } else if(strcmp(interface, zwp_primary_selection_device_manager_v1_interface.name) == 0) {
662665 wl->primsel = wl_registry_bind(registry, name, &zwp_primary_selection_device_manager_v1_interface, 1);
666+ } else if(strcmp(interface, zwlr_virtual_pointer_manager_v1_interface.name) == 0) {
667+ wl->vpmgr = wl_registry_bind(registry, name, &zwlr_virtual_pointer_manager_v1_interface, 1);
663668 }
664669 }
665670
@@ -696,6 +701,9 @@ wlsetcb(Wlwin *wl) · 30 unmodified lines
696701 if(wl->shm == nil || wl->compositor == nil || wl->xdg_wm_base == nil || wl->seat == nil || wl->decoman == nil || wl->primsel == nil)
697702 sysfatal("registration fell short");
698703
704+ if(wl->vpmgr != nil)
705+ wl->vpointer = zwlr_virtual_pointer_manager_v1_create_virtual_pointer(wl->vpmgr, wl->seat);
706+
699707 wlallocbuffer(wl);
700708 wl->surface = wl_compositor_create_surface(wl->compositor);
701709
@@ -761,3 +769,17 @@ wlgetsnarf(Wlwin *wl) · 59 unmodified lines
761769 qunlock(&wl->clip.lk);
762770 return s;
763771 }
772+
773+void
774+wlsetmouse(Wlwin *wl, Point p)
775+{
776+ Point delta;
777+ if (wl->vpointer == nil)
778+ return;
779+
780+ delta.x = p.x - wl->mouse.xy.x;
781+ delta.y = p.y - wl->mouse.xy.y;
782+ wl->mouse.xy = p;
783+ zwlr_virtual_pointer_v1_motion(wl->vpointer, time(nil) * 1000, delta.x * 256, delta.y * 256);
784+ zwlr_virtual_pointer_v1_frame(wl->vpointer);
785+}
gui-wl/wl-inc.h+4−0
@@ -80,6 +80,9 @@ struct Wlwin { · 79 unmodified lines
8080
8181 struct zwp_primary_selection_device_manager_v1 *primsel;
8282 struct zwp_primary_selection_device_v1 *primsel_device;
83+
84+ struct zwlr_virtual_pointer_manager_v1 *vpmgr;
85+ struct zwlr_virtual_pointer_v1 *vpointer;
8386 };
8487
8588 void wlallocbuffer(Wlwin*);
@@ -87,6 +90,7 @@ void wlsetcb(Wlwin*); · 1 unmodified line
8790 void wlsettitle(Wlwin*, char*);
8891 char* wlgetsnarf(Wlwin*);
8992 void wlsetsnarf(Wlwin*, char*);
93+void wlsetmouse(Wlwin*, Point);
9094 void wldrawcursor(Wlwin*, Cursorinfo*);
9195 void wlresize(Wlwin*, int, int);
9296 void wlflush(Wlwin*);
gui-wl/wl-screen.c+1−0
@@ -177,6 +177,7 @@ setcursor(void) · 176 unmodified lines
177177 void
178178 mouseset(Point p)
179179 {
180+ wlsetmouse(gwin, p);
180181 }
181182
182183 char*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t