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
10 xdg-shell-protocol.h\10 xdg-shell-protocol.h\
11 xdg-decoration-protocol.h\11 xdg-decoration-protocol.h\
12 xdg-primary-selection-protocol.h\12 xdg-primary-selection-protocol.h\
13 wlr-virtual-pointer.h\
13 wl-inc.h\14 wl-inc.h\
14 15
15OFILES=\16OFILES=\
16 xdg-shell-protocol.$O\17 xdg-shell-protocol.$O\
17 xdg-decoration-protocol.$O\18 xdg-decoration-protocol.$O\
18 xdg-primary-selection-protocol.$O\19 xdg-primary-selection-protocol.$O\
20 wlr-virtual-pointer.$O\
19 wl-cb.$O\21 wl-cb.$O\
20 wl-screen.$O\22 wl-screen.$O\
21 wl-util.$O\23 wl-util.$O\
22 24
25wlr-virtual-pointer-unstable-v1.xml:
26 curl https://gitlab.freedesktop.org/wlroots/wlr-protocols/-/raw/master/unstable/wlr-virtual-pointer-unstable-v1.xml > $@
27
28wlr-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
31wlr-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
23xdg-shell-protocol.c:34xdg-shell-protocol.c:
24 wayland-scanner private-code < $(XDG_SHELL) > $@ || { rm -f $@; exit 1; }35 wayland-scanner private-code < $(XDG_SHELL) > $@ || { rm -f $@; exit 1; }
25 36
gui-wl/wl-cb.c+22−0
@@ -7,10 +7,12 @@ · 6 unmodified lines
7#include <sys/mman.h>7#include <sys/mman.h>
8#include <sys/stat.h>8#include <sys/stat.h>
9#include <fcntl.h>9#include <fcntl.h>
10#include <time.h>
10#include <xkbcommon/xkbcommon.h>11#include <xkbcommon/xkbcommon.h>
11#include "xdg-shell-protocol.h"12#include "xdg-shell-protocol.h"
12#include "xdg-decoration-protocol.h"13#include "xdg-decoration-protocol.h"
13#include "xdg-primary-selection-protocol.h"14#include "xdg-primary-selection-protocol.h"
15#include "wlr-virtual-pointer.h"
14 16
15#include "u.h"17#include "u.h"
16#include "lib.h"18#include "lib.h"
@@ -29,6 +31,7 @@ · 12 unmodified lines
29#undef pipe31#undef pipe
30#undef write32#undef write
31#undef read33#undef read
34#undef time
32 35
33static void36static void
34xdg_surface_handle_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial)37xdg_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
660 wl->decoman = wl_registry_bind(registry, name, &zxdg_decoration_manager_v1_interface, 1);663 wl->decoman = wl_registry_bind(registry, name, &zxdg_decoration_manager_v1_interface, 1);
661 } else if(strcmp(interface, zwp_primary_selection_device_manager_v1_interface.name) == 0) {664 } else if(strcmp(interface, zwp_primary_selection_device_manager_v1_interface.name) == 0) {
662 wl->primsel = wl_registry_bind(registry, name, &zwp_primary_selection_device_manager_v1_interface, 1);665 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);
663 }668 }
664}669}
665 670
@@ -696,6 +701,9 @@ wlsetcb(Wlwin *wl) · 30 unmodified lines
696 if(wl->shm == nil || wl->compositor == nil || wl->xdg_wm_base == nil || wl->seat == nil || wl->decoman == nil || wl->primsel == nil)701 if(wl->shm == nil || wl->compositor == nil || wl->xdg_wm_base == nil || wl->seat == nil || wl->decoman == nil || wl->primsel == nil)
697 sysfatal("registration fell short");702 sysfatal("registration fell short");
698 703
704 if(wl->vpmgr != nil)
705 wl->vpointer = zwlr_virtual_pointer_manager_v1_create_virtual_pointer(wl->vpmgr, wl->seat);
706
699 wlallocbuffer(wl);707 wlallocbuffer(wl);
700 wl->surface = wl_compositor_create_surface(wl->compositor);708 wl->surface = wl_compositor_create_surface(wl->compositor);
701 709
@@ -761,3 +769,17 @@ wlgetsnarf(Wlwin *wl) · 59 unmodified lines
761 qunlock(&wl->clip.lk);769 qunlock(&wl->clip.lk);
762 return s;770 return s;
763}771}
772
773void
774wlsetmouse(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
80 80
81 struct zwp_primary_selection_device_manager_v1 *primsel;81 struct zwp_primary_selection_device_manager_v1 *primsel;
82 struct zwp_primary_selection_device_v1 *primsel_device;82 struct zwp_primary_selection_device_v1 *primsel_device;
83
84 struct zwlr_virtual_pointer_manager_v1 *vpmgr;
85 struct zwlr_virtual_pointer_v1 *vpointer;
83};86};
84 87
85void wlallocbuffer(Wlwin*);88void wlallocbuffer(Wlwin*);
@@ -87,6 +90,7 @@ void wlsetcb(Wlwin*); · 1 unmodified line
87void wlsettitle(Wlwin*, char*);90void wlsettitle(Wlwin*, char*);
88char* wlgetsnarf(Wlwin*);91char* wlgetsnarf(Wlwin*);
89void wlsetsnarf(Wlwin*, char*);92void wlsetsnarf(Wlwin*, char*);
93void wlsetmouse(Wlwin*, Point);
90void wldrawcursor(Wlwin*, Cursorinfo*);94void wldrawcursor(Wlwin*, Cursorinfo*);
91void wlresize(Wlwin*, int, int);95void wlresize(Wlwin*, int, int);
92void wlflush(Wlwin*);96void wlflush(Wlwin*);
gui-wl/wl-screen.c+1−0
@@ -177,6 +177,7 @@ setcursor(void) · 176 unmodified lines
177void177void
178mouseset(Point p)178mouseset(Point p)
179{179{
180 wlsetmouse(gwin, p);
180}181}
181 182
182char*183char*

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