-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path325.patch
3678 lines (3465 loc) · 119 KB
/
325.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From cf3a6367f7b7ad8801683b1831c4ebc8197d96c0 Mon Sep 17 00:00:00 2001
From: Andrea Feletto <[email protected]>
Date: Fri, 3 Mar 2023 23:01:23 +0100
Subject: [PATCH 01/18] Initial implementation of RemoteDesktop protocol
---
include/remotedesktop.h | 6 +
include/remotedesktop_common.h | 35 ++
include/wlr_virtual_pointer.h | 15 +
include/xdpw.h | 6 +
meson.build | 2 +
protocols/meson.build | 2 +
protocols/virtual-keyboard-unstable-v1.xml | 113 +++++
protocols/wlr-virtual-pointer-unstable-v1.xml | 152 ++++++
src/core/main.c | 8 +
src/remotedesktop/remotedesktop.c | 433 ++++++++++++++++++
src/remotedesktop/wlr_virtual_pointer.c | 62 +++
wlr.portal | 2 +-
12 files changed, 835 insertions(+), 1 deletion(-)
create mode 100644 include/remotedesktop.h
create mode 100644 include/remotedesktop_common.h
create mode 100644 include/wlr_virtual_pointer.h
create mode 100644 protocols/virtual-keyboard-unstable-v1.xml
create mode 100644 protocols/wlr-virtual-pointer-unstable-v1.xml
create mode 100644 src/remotedesktop/remotedesktop.c
create mode 100644 src/remotedesktop/wlr_virtual_pointer.c
diff --git a/include/remotedesktop.h b/include/remotedesktop.h
new file mode 100644
index 00000000..9fe8cc06
--- /dev/null
+++ b/include/remotedesktop.h
@@ -0,0 +1,6 @@
+#ifndef REMOTE_DESKTOP_H
+#define REMOTE_DESKTOP_H
+
+#include "remotedesktop_common.h"
+
+#endif
diff --git a/include/remotedesktop_common.h b/include/remotedesktop_common.h
new file mode 100644
index 00000000..59ee3449
--- /dev/null
+++ b/include/remotedesktop_common.h
@@ -0,0 +1,35 @@
+#ifndef REMOTEDESKTOP_COMMON_H
+#define REMOTEDESKTOP_COMMON_H
+
+#include <stdbool.h>
+#include <time.h>
+
+#include "wlr-virtual-pointer-unstable-v1-client-protocol.h"
+#include <wayland-client-protocol.h>
+
+#define XDP_REMOTE_PROTO_VER 1
+
+struct xdpw_remotedesktop_context {
+ // xdpw
+ struct xdpw_state *state;
+
+ // wlroots
+ struct wl_registry *registry;
+ struct zwlr_virtual_pointer_manager_v1 *virtual_pointer_manager;
+
+ // sessions
+ struct wl_list remotedesktop_instances;
+};
+
+struct xdpw_remotedesktop_session_data {
+ struct zwlr_virtual_pointer_v1 *virtual_pointer;
+ struct timespec t_start;
+};
+
+enum device_types {
+ KEYBOARD = 1,
+ POINTER = 2,
+ TOUCHSCREEN = 4,
+};
+
+#endif
diff --git a/include/wlr_virtual_pointer.h b/include/wlr_virtual_pointer.h
new file mode 100644
index 00000000..e42f7bd1
--- /dev/null
+++ b/include/wlr_virtual_pointer.h
@@ -0,0 +1,15 @@
+#ifndef WLR_VIRTUAL_POINTER_H
+#define WLR_VIRTUAL_POINTER_H
+
+#define VIRTUAL_POINTER_VERSION 2
+#define VIRTUAL_POINTER_VERSION_MIN 1
+
+#include "remotedesktop_common.h"
+
+struct xdpw_state;
+
+int xdpw_wlr_virtual_pointer_init(struct xdpw_state *state);
+
+void xdpw_wlr_virtual_pointer_finish(struct xdpw_remotedesktop_context *ctx);
+
+#endif
diff --git a/include/xdpw.h b/include/xdpw.h
index 3b956910..098a683f 100644
--- a/include/xdpw.h
+++ b/include/xdpw.h
@@ -12,6 +12,7 @@
#include "screencast_common.h"
#include "screenshot_common.h"
+#include "remotedesktop_common.h"
#include "config.h"
struct xdpw_state {
@@ -24,6 +25,9 @@ struct xdpw_state {
uint32_t screencast_cursor_modes; // bitfield of enum cursor_modes
uint32_t screencast_version;
uint32_t screenshot_version;
+ struct xdpw_remotedesktop_context remotedesktop;
+ uint32_t remotedesktop_version;
+ uint32_t remotedesktop_available_device_types;
struct xdpw_config *config;
int timer_poll_fd;
struct wl_list timers;
@@ -39,6 +43,7 @@ struct xdpw_session {
sd_bus_slot *slot;
char *session_handle;
struct xdpw_screencast_session_data screencast_data;
+ struct xdpw_remotedesktop_session_data remotedesktop_data;
};
typedef void (*xdpw_event_loop_timer_func_t)(void *data);
@@ -59,6 +64,7 @@ enum {
int xdpw_screenshot_init(struct xdpw_state *state);
int xdpw_screencast_init(struct xdpw_state *state);
+int xdpw_remotedesktop_init(struct xdpw_state *state);
struct xdpw_request *xdpw_request_create(sd_bus *bus, const char *object_path);
void xdpw_request_destroy(struct xdpw_request *req);
diff --git a/meson.build b/meson.build
index f2ec8ff5..c8725e17 100644
--- a/meson.build
+++ b/meson.build
@@ -62,6 +62,8 @@ xdpw_files = files(
'src/screencast/wlr_screencopy.c',
'src/screencast/pipewire_screencast.c',
'src/screencast/fps_limit.c',
+ 'src/remotedesktop/remotedesktop.c',
+ 'src/remotedesktop/wlr_virtual_pointer.c',
)
executable(
diff --git a/protocols/meson.build b/protocols/meson.build
index d5d88940..41df44e7 100644
--- a/protocols/meson.build
+++ b/protocols/meson.build
@@ -9,7 +9,9 @@ wayland_scanner = find_program(
client_protocols = [
wl_protocol_dir / 'unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml',
wl_protocol_dir / 'unstable/xdg-output/xdg-output-unstable-v1.xml',
+ 'virtual-keyboard-unstable-v1.xml',
'wlr-screencopy-unstable-v1.xml',
+ 'wlr-virtual-pointer-unstable-v1.xml',
]
wl_proto_files = []
diff --git a/protocols/virtual-keyboard-unstable-v1.xml b/protocols/virtual-keyboard-unstable-v1.xml
new file mode 100644
index 00000000..5095c91b
--- /dev/null
+++ b/protocols/virtual-keyboard-unstable-v1.xml
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="virtual_keyboard_unstable_v1">
+ <copyright>
+ Copyright © 2008-2011 Kristian Høgsberg
+ Copyright © 2010-2013 Intel Corporation
+ Copyright © 2012-2013 Collabora, Ltd.
+ Copyright © 2018 Purism SPC
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice (including the next
+ paragraph) shall be included in all copies or substantial portions of the
+ Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+ </copyright>
+
+ <interface name="zwp_virtual_keyboard_v1" version="1">
+ <description summary="virtual keyboard">
+ The virtual keyboard provides an application with requests which emulate
+ the behaviour of a physical keyboard.
+
+ This interface can be used by clients on its own to provide raw input
+ events, or it can accompany the input method protocol.
+ </description>
+
+ <request name="keymap">
+ <description summary="keyboard mapping">
+ Provide a file descriptor to the compositor which can be
+ memory-mapped to provide a keyboard mapping description.
+
+ Format carries a value from the keymap_format enumeration.
+ </description>
+ <arg name="format" type="uint" summary="keymap format"/>
+ <arg name="fd" type="fd" summary="keymap file descriptor"/>
+ <arg name="size" type="uint" summary="keymap size, in bytes"/>
+ </request>
+
+ <enum name="error">
+ <entry name="no_keymap" value="0" summary="No keymap was set"/>
+ </enum>
+
+ <request name="key">
+ <description summary="key event">
+ A key was pressed or released.
+ The time argument is a timestamp with millisecond granularity, with an
+ undefined base. All requests regarding a single object must share the
+ same clock.
+
+ Keymap must be set before issuing this request.
+
+ State carries a value from the key_state enumeration.
+ </description>
+ <arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
+ <arg name="key" type="uint" summary="key that produced the event"/>
+ <arg name="state" type="uint" summary="physical state of the key"/>
+ </request>
+
+ <request name="modifiers">
+ <description summary="modifier and group state">
+ Notifies the compositor that the modifier and/or group state has
+ changed, and it should update state.
+
+ The client should use wl_keyboard.modifiers event to synchronize its
+ internal state with seat state.
+
+ Keymap must be set before issuing this request.
+ </description>
+ <arg name="mods_depressed" type="uint" summary="depressed modifiers"/>
+ <arg name="mods_latched" type="uint" summary="latched modifiers"/>
+ <arg name="mods_locked" type="uint" summary="locked modifiers"/>
+ <arg name="group" type="uint" summary="keyboard layout"/>
+ </request>
+
+ <request name="destroy" type="destructor" since="1">
+ <description summary="destroy the virtual keyboard keyboard object"/>
+ </request>
+ </interface>
+
+ <interface name="zwp_virtual_keyboard_manager_v1" version="1">
+ <description summary="virtual keyboard manager">
+ A virtual keyboard manager allows an application to provide keyboard
+ input events as if they came from a physical keyboard.
+ </description>
+
+ <enum name="error">
+ <entry name="unauthorized" value="0" summary="client not authorized to use the interface"/>
+ </enum>
+
+ <request name="create_virtual_keyboard">
+ <description summary="Create a new virtual keyboard">
+ Creates a new virtual keyboard associated to a seat.
+
+ If the compositor enables a keyboard to perform arbitrary actions, it
+ should present an error when an untrusted client requests a new
+ keyboard.
+ </description>
+ <arg name="seat" type="object" interface="wl_seat"/>
+ <arg name="id" type="new_id" interface="zwp_virtual_keyboard_v1"/>
+ </request>
+ </interface>
+</protocol>
diff --git a/protocols/wlr-virtual-pointer-unstable-v1.xml b/protocols/wlr-virtual-pointer-unstable-v1.xml
new file mode 100644
index 00000000..ea243e7c
--- /dev/null
+++ b/protocols/wlr-virtual-pointer-unstable-v1.xml
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="wlr_virtual_pointer_unstable_v1">
+ <copyright>
+ Copyright © 2019 Josef Gajdusek
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice (including the next
+ paragraph) shall be included in all copies or substantial portions of the
+ Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+ </copyright>
+
+ <interface name="zwlr_virtual_pointer_v1" version="2">
+ <description summary="virtual pointer">
+ This protocol allows clients to emulate a physical pointer device. The
+ requests are mostly mirror opposites of those specified in wl_pointer.
+ </description>
+
+ <enum name="error">
+ <entry name="invalid_axis" value="0"
+ summary="client sent invalid axis enumeration value" />
+ <entry name="invalid_axis_source" value="1"
+ summary="client sent invalid axis source enumeration value" />
+ </enum>
+
+ <request name="motion">
+ <description summary="pointer relative motion event">
+ The pointer has moved by a relative amount to the previous request.
+
+ Values are in the global compositor space.
+ </description>
+ <arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
+ <arg name="dx" type="fixed" summary="displacement on the x-axis"/>
+ <arg name="dy" type="fixed" summary="displacement on the y-axis"/>
+ </request>
+
+ <request name="motion_absolute">
+ <description summary="pointer absolute motion event">
+ The pointer has moved in an absolute coordinate frame.
+
+ Value of x can range from 0 to x_extent, value of y can range from 0
+ to y_extent.
+ </description>
+ <arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
+ <arg name="x" type="uint" summary="position on the x-axis"/>
+ <arg name="y" type="uint" summary="position on the y-axis"/>
+ <arg name="x_extent" type="uint" summary="extent of the x-axis"/>
+ <arg name="y_extent" type="uint" summary="extent of the y-axis"/>
+ </request>
+
+ <request name="button">
+ <description summary="button event">
+ A button was pressed or released.
+ </description>
+ <arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
+ <arg name="button" type="uint" summary="button that produced the event"/>
+ <arg name="state" type="uint" enum="wl_pointer.button_state" summary="physical state of the button"/>
+ </request>
+
+ <request name="axis">
+ <description summary="axis event">
+ Scroll and other axis requests.
+ </description>
+ <arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
+ <arg name="axis" type="uint" enum="wl_pointer.axis" summary="axis type"/>
+ <arg name="value" type="fixed" summary="length of vector in touchpad coordinates"/>
+ </request>
+
+ <request name="frame">
+ <description summary="end of a pointer event sequence">
+ Indicates the set of events that logically belong together.
+ </description>
+ </request>
+
+ <request name="axis_source">
+ <description summary="axis source event">
+ Source information for scroll and other axis.
+ </description>
+ <arg name="axis_source" type="uint" enum="wl_pointer.axis_source" summary="source of the axis event"/>
+ </request>
+
+ <request name="axis_stop">
+ <description summary="axis stop event">
+ Stop notification for scroll and other axes.
+ </description>
+ <arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
+ <arg name="axis" type="uint" enum="wl_pointer.axis" summary="the axis stopped with this event"/>
+ </request>
+
+ <request name="axis_discrete">
+ <description summary="axis click event">
+ Discrete step information for scroll and other axes.
+
+ This event allows the client to extend data normally sent using the axis
+ event with discrete value.
+ </description>
+ <arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
+ <arg name="axis" type="uint" enum="wl_pointer.axis" summary="axis type"/>
+ <arg name="value" type="fixed" summary="length of vector in touchpad coordinates"/>
+ <arg name="discrete" type="int" summary="number of steps"/>
+ </request>
+
+ <request name="destroy" type="destructor" since="1">
+ <description summary="destroy the virtual pointer object"/>
+ </request>
+ </interface>
+
+ <interface name="zwlr_virtual_pointer_manager_v1" version="2">
+ <description summary="virtual pointer manager">
+ This object allows clients to create individual virtual pointer objects.
+ </description>
+
+ <request name="create_virtual_pointer">
+ <description summary="Create a new virtual pointer">
+ Creates a new virtual pointer. The optional seat is a suggestion to the
+ compositor.
+ </description>
+ <arg name="seat" type="object" interface="wl_seat" allow-null="true"/>
+ <arg name="id" type="new_id" interface="zwlr_virtual_pointer_v1"/>
+ </request>
+
+ <request name="destroy" type="destructor" since="1">
+ <description summary="destroy the virtual pointer manager"/>
+ </request>
+
+ <!-- Version 2 additions -->
+ <request name="create_virtual_pointer_with_output" since="2">
+ <description summary="Create a new virtual pointer">
+ Creates a new virtual pointer. The seat and the output arguments are
+ optional. If the seat argument is set, the compositor should assign the
+ input device to the requested seat. If the output argument is set, the
+ compositor should map the input device to the requested output.
+ </description>
+ <arg name="seat" type="object" interface="wl_seat" allow-null="true"/>
+ <arg name="output" type="object" interface="wl_output" allow-null="true"/>
+ <arg name="id" type="new_id" interface="zwlr_virtual_pointer_v1"/>
+ </request>
+ </interface>
+</protocol>
diff --git a/src/core/main.c b/src/core/main.c
index e27d261c..6e308878 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -120,6 +120,8 @@ int main(int argc, char *argv[]) {
.screencast_cursor_modes = HIDDEN | EMBEDDED,
.screencast_version = XDP_CAST_PROTO_VER,
.screenshot_version = XDP_SHOT_PROTO_VER,
+ .remotedesktop_available_device_types = POINTER,
+ .remotedesktop_version = XDP_REMOTE_PROTO_VER,
.config = &config,
};
@@ -137,6 +139,12 @@ int main(int argc, char *argv[]) {
goto error;
}
+ ret = xdpw_remotedesktop_init(&state);
+ if (ret < 0) {
+ logprint(ERROR, "xdpw: failed to initialize remotedesktop");
+ goto error;
+ }
+
uint64_t flags = SD_BUS_NAME_ALLOW_REPLACEMENT;
if (replace) {
flags |= SD_BUS_NAME_REPLACE_EXISTING;
diff --git a/src/remotedesktop/remotedesktop.c b/src/remotedesktop/remotedesktop.c
new file mode 100644
index 00000000..c76304c0
--- /dev/null
+++ b/src/remotedesktop/remotedesktop.c
@@ -0,0 +1,433 @@
+#include "remotedesktop.h"
+
+#include <time.h>
+
+#include "wlr_virtual_pointer.h"
+#include "xdpw.h"
+
+static const char object_path[] = "/org/freedesktop/portal/desktop";
+static const char interface_name[] = "org.freedesktop.impl.portal.RemoteDesktop";
+
+static uint32_t get_timestamp_ms(struct xdpw_remotedesktop_session_data *remote) {
+ struct timespec *t_start, t_stop;
+
+ t_start = &remote->t_start;
+ clock_gettime(CLOCK_REALTIME, &t_stop);
+
+ return 1000 * (t_stop.tv_sec - t_start->tv_sec) +
+ (t_stop.tv_nsec - t_start->tv_nsec) / 1000000;
+}
+
+static int method_remotedesktop_create_session(sd_bus_message *msg, void *data,
+ sd_bus_error *ret_error) {
+ struct xdpw_state *state = data;
+
+ int ret = 0;
+ char *request_handle, *session_handle, *app_id, *key;
+ struct xdpw_request *req;
+ struct xdpw_session *sess;
+
+ logprint(DEBUG, "remotedesktop: dbus: create session: method invoked");
+
+ ret = sd_bus_message_read(msg, "oos", &request_handle, &session_handle, &app_id);
+ if (ret < 0) {
+ return ret;
+ }
+
+ logprint(DEBUG, "remotedesktop: dbus: create session: request_handle: %s", request_handle);
+ logprint(DEBUG, "remotedesktop: dbus: create session: session_handle: %s", session_handle);
+ logprint(DEBUG, "remotedesktop: dbus: create session: app_id: %s", app_id);
+
+ ret = sd_bus_message_enter_container(msg, 'a', "{sv}");
+ if (ret < 0) {
+ return ret;
+ }
+ while ((ret = sd_bus_message_enter_container(msg, 'e', "sv")) > 0) {
+ ret = sd_bus_message_read(msg, "s", &key);
+ if (ret < 0) {
+ return ret;
+ }
+
+ if (strcmp(key, "session_handle_token") == 0) {
+ char *token;
+ sd_bus_message_read(msg, "v", "s", &token);
+ logprint(DEBUG, "remotedesktop: dbus: create session: session handle token: %s", token);
+ } else {
+ logprint(WARN, "remotedesktop: dbus: create session: unknown option: %s", key);
+ sd_bus_message_skip(msg, "v");
+ }
+
+ ret = sd_bus_message_exit_container(msg);
+ if (ret < 0) {
+ return ret;
+ }
+ }
+ if (ret < 0) {
+ return ret;
+ }
+
+ ret = sd_bus_message_exit_container(msg);
+ if (ret < 0) {
+ return ret;
+ }
+
+ req = xdpw_request_create(
+ sd_bus_message_get_bus(msg), request_handle);
+ if (req == NULL) {
+ return -ENOMEM;
+ }
+
+ sess = xdpw_session_create(state,
+ sd_bus_message_get_bus(msg), strdup(session_handle));
+ if (sess == NULL) {
+ return -ENOMEM;
+ }
+
+ ret = sd_bus_reply_method_return(msg, "ua{sv}", PORTAL_RESPONSE_SUCCESS, 0);
+ if (ret < 0) {
+ return ret;
+ }
+ return 0;
+}
+
+static int method_remotedesktop_select_devices(sd_bus_message *msg, void *data,
+ sd_bus_error *ret_error) {
+ struct xdpw_state *state = data;
+
+ int ret = 0;
+ char *request_handle, *session_handle, *app_id, *key;
+ struct xdpw_session *sess;
+
+ logprint(DEBUG, "remotedesktop: dbus: select devices: method invoked");
+
+ ret = sd_bus_message_read(msg, "oos", &request_handle, &session_handle, &app_id);
+ if (ret < 0) {
+ return ret;
+ }
+
+ logprint(DEBUG, "remotedesktop: dbus: select devices: request_handle: %s", request_handle);
+ logprint(DEBUG, "remotedesktop: dbus: select devices: session_handle: %s", session_handle);
+ logprint(DEBUG, "remotedesktop: dbus: select devices: app_id: %s", app_id);
+
+ wl_list_for_each_reverse(sess, &state->xdpw_sessions, link) {
+ if (strcmp(sess->session_handle, session_handle) == 0) {
+ break;
+ }
+ }
+ if (!sess) {
+ logprint(WARN, "remotedesktop: dbus: select devices: session not found");
+ return -1;
+ }
+ logprint(DEBUG, "remotedesktop: dbus: select devices: session found");
+
+ ret = sd_bus_message_enter_container(msg, 'a', "{sv}");
+ if (ret < 0) {
+ return ret;
+ }
+ while ((ret = sd_bus_message_enter_container(msg, 'e', "sv")) > 0) {
+ ret = sd_bus_message_read(msg, "s", &key);
+ if (ret < 0) {
+ return ret;
+ }
+
+ if (strcmp(key, "types") == 0) {
+ uint32_t types;
+ ret = sd_bus_message_read(msg, "v", "u", &types);
+ if (ret < 0) {
+ return ret;
+ }
+ logprint(DEBUG, "remotedesktop: dbus: select devices: option types: %x", types);
+ } else {
+ logprint(WARN, "remotedesktop: dbus: select devices: unknown option: %s", key);
+ sd_bus_message_skip(msg, "v");
+ }
+
+ ret = sd_bus_message_exit_container(msg);
+ if (ret < 0) {
+ return ret;
+ }
+ }
+ if (ret < 0) {
+ return ret;
+ }
+ ret = sd_bus_message_exit_container(msg);
+ if (ret < 0) {
+ return ret;
+ }
+
+ ret = sd_bus_reply_method_return(msg, "ua{sv}", PORTAL_RESPONSE_SUCCESS, 0);
+ if (ret < 0) {
+ return ret;
+ }
+ return 0;
+}
+
+static int method_remotedesktop_start(sd_bus_message *msg, void *data, sd_bus_error *ret_error) {
+ struct xdpw_state *state = data;
+
+ int ret = 0;
+ char *request_handle, *session_handle, *app_id, *parent_window, *key;
+ struct xdpw_session *sess;
+ struct xdpw_remotedesktop_session_data *remote;
+
+ logprint(DEBUG, "remotedesktop: dbus: start: method invoked");
+
+ ret = sd_bus_message_read(msg, "oos", &request_handle, &session_handle, &app_id);
+ if (ret < 0) {
+ return ret;
+ }
+
+ logprint(DEBUG, "remotedesktop: dbus: start: request_handle: %s", request_handle);
+ logprint(DEBUG, "remotedesktop: dbus: start: session_handle: %s", session_handle);
+ logprint(DEBUG, "remotedesktop: dbus: start: app_id: %s", app_id);
+
+ wl_list_for_each_reverse(sess, &state->xdpw_sessions, link) {
+ if (strcmp(sess->session_handle, session_handle) == 0) {
+ break;
+ }
+ }
+ if (!sess) {
+ logprint(WARN, "remotedesktop: dbus: start: session not found");
+ return -1;
+ }
+ logprint(DEBUG, "remotedesktop: dbus: start: session found");
+
+ remote = &sess->remotedesktop_data;
+ remote->virtual_pointer = zwlr_virtual_pointer_manager_v1_create_virtual_pointer(
+ state->remotedesktop.virtual_pointer_manager, NULL);
+ clock_gettime(CLOCK_REALTIME, &remote->t_start);
+
+ ret = sd_bus_message_read(msg, "s", &parent_window);
+ if (ret < 0) {
+ return ret;
+ }
+ logprint(DEBUG, "remotedesktop: dbus: start: parent window: %s", parent_window);
+
+ ret = sd_bus_message_enter_container(msg, 'a', "{sv}");
+ if (ret < 0) {
+ return ret;
+ }
+ while ((ret = sd_bus_message_enter_container(msg, 'e', "sv")) > 0) {
+ ret = sd_bus_message_read(msg, "s", &key);
+ if (ret < 0) {
+ return ret;
+ }
+
+ logprint(WARN, "remotedesktop: dbus: start: unknown option: %s", key);
+ sd_bus_message_skip(msg, "v");
+
+ ret = sd_bus_message_exit_container(msg);
+ if (ret < 0) {
+ return ret;
+ }
+ }
+ if (ret < 0) {
+ return ret;
+ }
+ ret = sd_bus_message_exit_container(msg);
+ if (ret < 0) {
+ return ret;
+ }
+
+ ret = sd_bus_reply_method_return(msg, "ua{sv}", PORTAL_RESPONSE_SUCCESS,
+ 1, "devices", "u", POINTER | KEYBOARD);
+ if (ret < 0) {
+ return ret;
+ }
+
+ return 0;
+}
+
+static int method_remotedesktop_notify_pointer_motion(sd_bus_message *msg,
+ void *data, sd_bus_error *ret_error) {
+ struct xdpw_state *state = data;
+
+ int ret = 0;
+ char *session_handle;
+ struct xdpw_session *sess;
+ double dx = 0, dy = 0;
+
+ logprint(DEBUG, "remotedesktop: dbus: npm: method invoked");
+
+ ret = sd_bus_message_read(msg, "o", &session_handle);
+ if (ret < 0) {
+ return ret;
+ }
+ logprint(DEBUG, "remotedesktop: dbus: npm: session_handle: %s", session_handle);
+
+ wl_list_for_each_reverse(sess, &state->xdpw_sessions, link) {
+ if (strcmp(sess->session_handle, session_handle) == 0) {
+ break;
+ }
+ }
+ if (!sess) {
+ logprint(WARN, "remotedesktop: dbus: npm: session not found");
+ return -1;
+ }
+ logprint(DEBUG, "remotedesktop: dbus: npm: session found");
+
+ ret = sd_bus_message_skip(msg, "a{sv}");
+ if (ret < 0) {
+ return ret;
+ }
+ ret = sd_bus_message_read(msg, "d", &dx);
+ if (ret < 0) {
+ return ret;
+ }
+ ret = sd_bus_message_read(msg, "d", &dy);
+ if (ret < 0) {
+ return ret;
+ }
+
+ zwlr_virtual_pointer_v1_motion(sess->remotedesktop_data.virtual_pointer,
+ get_timestamp_ms(&sess->remotedesktop_data),
+ wl_fixed_from_double(dx), wl_fixed_from_double(dy));
+
+ return 0;
+}
+
+static int method_remotedesktop_notify_pointer_motion_absolute(
+ sd_bus_message *msg, void *data, sd_bus_error *ret_error) {
+ struct xdpw_state *state = data;
+
+ int ret = 0;
+ char *session_handle;
+ struct xdpw_session *sess;
+ double x = 0, y = 0;
+
+ logprint(DEBUG, "remotedesktop: dbus: npma: method invoked");
+
+ ret = sd_bus_message_read(msg, "o", &session_handle);
+ if (ret < 0) {
+ return ret;
+ }
+ logprint(DEBUG, "remotedesktop: dbus: npma: session_handle: %s", session_handle);
+
+ wl_list_for_each_reverse(sess, &state->xdpw_sessions, link) {
+ if (strcmp(sess->session_handle, session_handle) == 0) {
+ break;
+ }
+ }
+ if (!sess) {
+ logprint(WARN, "remotedesktop: dbus: npma: session not found");
+ return -1;
+ }
+ logprint(DEBUG, "remotedesktop: dbus: npma: session found");
+
+ ret = sd_bus_message_skip(msg, "a{sv}");
+ if (ret < 0) {
+ return ret;
+ }
+ ret = sd_bus_message_read(msg, "d", &x);
+ if (ret < 0) {
+ return ret;
+ }
+ ret = sd_bus_message_read(msg, "d", &y);
+ if (ret < 0) {
+ return ret;
+ }
+
+ // zwlr_virtual_pointer_v1_motion_absolute(sess->remotedesktop_data.virtual_pointer,
+ // get_timestamp_ms(&sess->remotedesktop_data),
+ // wl_fixed_from_double(x), wl_fixed_from_double(y));
+
+ return 0;
+}
+
+static int method_remotedesktop_notify_pointer_button(sd_bus_message *msg,
+ void *data, sd_bus_error *ret_error) {
+ return 0;
+}
+
+static int method_remotedesktop_notify_pointer_axis(sd_bus_message *msg,
+ void *data, sd_bus_error *ret_error) {
+ return 0;
+}
+
+static int method_remotedesktop_notify_pointer_axis_discrete(
+ sd_bus_message *msg, void *data, sd_bus_error *ret_error) {
+ return 0;
+}
+
+static int method_remotedesktop_notify_keyboard_keycode(
+ sd_bus_message *msg, void *data, sd_bus_error *ret_error) {
+ return 0;
+}
+
+static int method_remotedesktop_notify_keyboard_keysym(
+ sd_bus_message *msg, void *data, sd_bus_error *ret_error) {
+ return 0;
+}
+
+static int method_remotedesktop_notify_touch_down(
+ sd_bus_message *msg, void *data, sd_bus_error *ret_error) {
+ return 0;
+}
+
+static int method_remotedesktop_notify_touch_motion(
+ sd_bus_message *msg, void *data, sd_bus_error *ret_error) {
+ return 0;
+}
+
+static int method_remotedesktop_notify_touch_up(
+ sd_bus_message *msg, void *data, sd_bus_error *ret_error) {
+ return 0;
+}
+
+static const sd_bus_vtable remotedesktop_vtable[] = {
+ SD_BUS_VTABLE_START(0),
+ SD_BUS_METHOD("CreateSession", "oosa{sv}", "ua{sv}",
+ method_remotedesktop_create_session, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("SelectDevices", "oosa{sv}", "ua{sv}",
+ method_remotedesktop_select_devices, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("Start", "oossa{sv}", "ua{sv}",
+ method_remotedesktop_start, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("NotifyPointerMotion", "oa{sv}dd", NULL,
+ method_remotedesktop_notify_pointer_motion, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("NotifyPointerMotionAbsolute", "oa{sv}udd", NULL,
+ method_remotedesktop_notify_pointer_motion_absolute, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("NotifyPointerButton", "oa{sv}iu", NULL,
+ method_remotedesktop_notify_pointer_button, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("NotifyPointerAxis", "oa{sv}dd", NULL,
+ method_remotedesktop_notify_pointer_axis, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("NotifyPointerAxisDiscrete", "oa{sv}ui", NULL,
+ method_remotedesktop_notify_pointer_axis_discrete, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("NotifyKeyboardKeycode", "oa{sv}iu", NULL,
+ method_remotedesktop_notify_keyboard_keycode, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("NotifyKeyboardKeysym", "oa{sv}iu", NULL,
+ method_remotedesktop_notify_keyboard_keysym, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("NotifyTouchDown", "oa{sv}uudd", NULL,
+ method_remotedesktop_notify_touch_down, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("NotifyTouchMotion", "oa{sv}uudd", NULL,
+ method_remotedesktop_notify_touch_motion, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("NotifyTouchUp", "oa{sv}u", NULL,
+ method_remotedesktop_notify_touch_up, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_PROPERTY("AvailableDeviceTypes", "u", NULL,
+ offsetof(struct xdpw_state, remotedesktop_available_device_types),
+ SD_BUS_VTABLE_PROPERTY_CONST),
+ SD_BUS_PROPERTY("version", "u", NULL,
+ offsetof(struct xdpw_state, remotedesktop_version),
+ SD_BUS_VTABLE_PROPERTY_CONST),
+ SD_BUS_VTABLE_END
+};
+
+int xdpw_remotedesktop_init(struct xdpw_state *state) {
+ sd_bus_slot *slot = NULL;
+
+ state->remotedesktop = (struct xdpw_remotedesktop_context) { 0 };
+ state->remotedesktop.state = state;
+
+ int err;
+ err = xdpw_wlr_virtual_pointer_init(state);
+ if (err) {
+ goto fail_virtual_pointer;
+ }
+
+ return sd_bus_add_object_vtable(state->bus, &slot, object_path,
+ interface_name, remotedesktop_vtable, state);
+
+fail_virtual_pointer:
+ xdpw_wlr_virtual_pointer_finish(&state->remotedesktop);
+
+ return err;
+}
diff --git a/src/remotedesktop/wlr_virtual_pointer.c b/src/remotedesktop/wlr_virtual_pointer.c
new file mode 100644
index 00000000..06bc71e6
--- /dev/null
+++ b/src/remotedesktop/wlr_virtual_pointer.c
@@ -0,0 +1,62 @@
+#include "wlr_virtual_pointer.h"
+
+#include "wlr-virtual-pointer-unstable-v1-client-protocol.h"
+
+#include "remotedesktop.h"
+#include "xdpw.h"
+#include "logger.h"
+
+static void wlr_registry_handle_add(void *data, struct wl_registry *reg,
+ uint32_t id, const char *interface, uint32_t ver) {
+ struct xdpw_remotedesktop_context *ctx = data;
+
+ logprint(DEBUG, "wlroots: interface to register %s (Version: %u)",
+ interface, ver);
+
+ if (!strcmp(interface, zwlr_virtual_pointer_manager_v1_interface.name)) {
+ uint32_t version = ver;
+ if (VIRTUAL_POINTER_VERSION < ver) {
+ version = VIRTUAL_POINTER_VERSION;
+ } else if (ver < VIRTUAL_POINTER_VERSION_MIN) {
+ version = VIRTUAL_POINTER_VERSION_MIN;
+ }
+ logprint(DEBUG,
+ "wlroots: |-- registered to interface %s (Version %u)",
+ interface, version);
+ ctx->virtual_pointer_manager = wl_registry_bind(reg, id,
+ &zwlr_virtual_pointer_manager_v1_interface, version);
+ }
+}
+
+static const struct wl_registry_listener wlr_registry_listener = {
+ .global = wlr_registry_handle_add,
+ .global_remove = NULL,
+};
+
+int xdpw_wlr_virtual_pointer_init(struct xdpw_state *state) {
+ struct xdpw_remotedesktop_context *ctx = &state->remotedesktop;
+
+ // retrieve registry
+ ctx->registry = wl_display_get_registry(state->wl_display);
+ wl_registry_add_listener(ctx->registry, &wlr_registry_listener, ctx);
+
+ wl_display_roundtrip(state->wl_display);
+
+ logprint(DEBUG, "wayland: registry listeners run");
+ wl_display_roundtrip(state->wl_display);
+
+ // make sure our wlroots supports virtual-pointer protocol
+ if (!ctx->virtual_pointer_manager) {
+ logprint(ERROR, "Compositor doesn't support %s!",
+ zwlr_virtual_pointer_manager_v1_interface.name);
+ return -1;
+ }
+
+ return 0;
+}
+
+void xdpw_wlr_virtual_pointer_finish(struct xdpw_remotedesktop_context *ctx) {
+ if (ctx->virtual_pointer_manager) {
+ zwlr_virtual_pointer_manager_v1_destroy(ctx->virtual_pointer_manager);
+ }
+}
diff --git a/wlr.portal b/wlr.portal
index aa63335b..087c0086 100644
--- a/wlr.portal
+++ b/wlr.portal
@@ -1,4 +1,4 @@
[portal]
DBusName=org.freedesktop.impl.portal.desktop.wlr
-Interfaces=org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.ScreenCast;
+Interfaces=org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.ScreenCast;org.freedesktop.impl.portal.RemoteDesktop;
UseIn=wlroots;sway;Wayfire;river;phosh;Hyprland;
From 60955cd5133acf36a5e400e8cbee9fce1d0989cf Mon Sep 17 00:00:00 2001
From: Andrea Feletto <[email protected]>
Date: Fri, 10 Mar 2023 13:58:45 +0100
Subject: [PATCH 02/18] remotedesktop: add config options
---
include/config.h | 7 +++++++
src/core/config.c | 20 ++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/include/config.h b/include/config.h
index f856dc1a..098cbe9a 100644
--- a/include/config.h