summaryrefslogtreecommitdiffstats
path: root/source/l/gtk+3/9a693c7228a88b76a007aed41b101d89d084cf9b.diff
blob: b9efbf6fe7197760404b7e2db09df5691d267729 (plain) (blame)
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
diff --git a/configure.ac b/configure.ac
index 62c17b2b8472ee8552405e26f4b1a13307619009..a26b03d3c3e1ece50fa171cfc4af316315da2edd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -61,7 +61,7 @@ m4_define([cairo_required_version], [1.14.0])
 m4_define([gdk_pixbuf_required_version], [2.30.0])
 m4_define([introspection_required_version], [1.39.0])
 m4_define([wayland_required_version], [1.14.91])
-m4_define([wayland_protocols_required_version], [1.14])
+m4_define([wayland_protocols_required_version], [1.17])
 m4_define([epoxy_required_version], [1.4])
 m4_define([cloudproviders_required_version], [0.2.5])
 m4_define([sysprof_required_version], [3.33.2])
diff --git a/gdk/wayland/Makefile.am b/gdk/wayland/Makefile.am
index 31f12251b30b175e353888c6ce4fb315fa34ce13..6595013d3f00314c42d4a530ecfeba39d1c5d477 100644
--- a/gdk/wayland/Makefile.am
+++ b/gdk/wayland/Makefile.am
@@ -40,7 +40,9 @@ BUILT_SOURCES = 				\
 	server-decoration-client-protocol.h		\
 	server-decoration-protocol.c			\
 	gtk-shell-client-protocol.h		\
-	gtk-shell-protocol.c
+	gtk-shell-protocol.c			\
+	primary-selection-unstable-v1-client-protocol.h		\
+	primary-selection-unstable-v1-protocol.c
 
 nodist_libgdk_wayland_la_SOURCES =		\
 	$(BUILT_SOURCES)
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index 7d81eaff3b40e3775e1c21637773145f56acb7bc..c5b273eb908d727751dafc22d710f10a20d16a79 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -237,7 +237,8 @@ struct _GdkWaylandSeat
   uint32_t keyboard_time;
   uint32_t keyboard_key_serial;
 
-  struct gtk_primary_selection_device *primary_data_device;
+  struct gtk_primary_selection_device *gtk_primary_data_device;
+  struct zwp_primary_selection_device_v1 *zwp_primary_data_device_v1;
   struct wl_data_device *data_device;
   GdkDragContext *drop_context;
 
@@ -1308,23 +1309,43 @@ static const struct wl_data_device_listener data_device_listener = {
 };
 
 static void
-primary_selection_data_offer (void                                *data,
-                              struct gtk_primary_selection_device *gtk_primary_selection_device,
-                              struct gtk_primary_selection_offer  *gtk_primary_offer)
+primary_selection_data_offer (void     *data,
+                              gpointer  primary_selection_device,
+                              gpointer  primary_offer)
 {
   GdkWaylandSeat *seat = data;
 
   GDK_NOTE (EVENTS,
             g_message ("primary selection offer, device %p, data offer %p",
-                       gtk_primary_selection_device, gtk_primary_offer));
+                       primary_selection_device, primary_offer));
 
-  gdk_wayland_selection_ensure_primary_offer (seat->display, gtk_primary_offer);
+  gdk_wayland_selection_ensure_primary_offer (seat->display, primary_offer);
 }
 
 static void
-primary_selection_selection (void                                *data,
-                             struct gtk_primary_selection_device *gtk_primary_selection_device,
-                             struct gtk_primary_selection_offer  *gtk_primary_offer)
+gtk_primary_selection_data_offer (void                                *data,
+                                  struct gtk_primary_selection_device *primary_selection_device,
+                                  struct gtk_primary_selection_offer  *primary_offer)
+{
+  primary_selection_data_offer (data,
+                                (gpointer) primary_selection_device,
+                                (gpointer) primary_offer);
+}
+
+static void
+zwp_primary_selection_v1_data_offer (void                                   *data,
+                                     struct zwp_primary_selection_device_v1 *primary_selection_device,
+                                     struct zwp_primary_selection_offer_v1  *primary_offer)
+{
+  primary_selection_data_offer (data,
+                                (gpointer) primary_selection_device,
+                                (gpointer) primary_offer);
+}
+
+static void
+primary_selection_selection (void     *data,
+                             gpointer  primary_selection_device,
+                             gpointer  primary_offer)
 {
   GdkWaylandSeat *seat = data;
   GdkAtom selection;
@@ -1334,16 +1355,41 @@ primary_selection_selection (void                                *data,
 
   GDK_NOTE (EVENTS,
             g_message ("primary selection selection, device %p, data offer %p",
-                       gtk_primary_selection_device, gtk_primary_offer));
+                       primary_selection_device, primary_offer));
 
   selection = gdk_atom_intern_static_string ("PRIMARY");
-  gdk_wayland_selection_set_offer (seat->display, selection, gtk_primary_offer);
+  gdk_wayland_selection_set_offer (seat->display, selection, primary_offer);
   emit_selection_owner_change (seat->keyboard_focus, selection);
 }
 
-static const struct gtk_primary_selection_device_listener primary_selection_device_listener = {
-  primary_selection_data_offer,
-  primary_selection_selection,
+static void
+gtk_primary_selection_selection (void                                *data,
+                                 struct gtk_primary_selection_device *primary_selection_device,
+                                 struct gtk_primary_selection_offer  *primary_offer)
+{
+  primary_selection_selection (data,
+                               (gpointer) primary_selection_device,
+                               (gpointer) primary_offer);
+}
+
+static void
+zwp_primary_selection_v1_selection (void                                   *data,
+                                    struct zwp_primary_selection_device_v1 *primary_selection_device,
+                                    struct zwp_primary_selection_offer_v1  *primary_offer)
+{
+  primary_selection_selection (data,
+                               (gpointer) primary_selection_device,
+                               (gpointer) primary_offer);
+}
+
+static const struct gtk_primary_selection_device_listener gtk_primary_device_listener = {
+  gtk_primary_selection_data_offer,
+  gtk_primary_selection_selection,
+};
+
+static const struct zwp_primary_selection_device_v1_listener zwp_primary_device_v1_listener = {
+  zwp_primary_selection_v1_data_offer,
+  zwp_primary_selection_v1_selection,
 };
 
 static GdkDevice * get_scroll_device (GdkWaylandSeat              *seat,
@@ -5078,13 +5124,23 @@ _gdk_wayland_device_manager_add_seat (GdkDeviceManager *device_manager,
   wl_seat_add_listener (seat->wl_seat, &seat_listener, seat);
   wl_seat_set_user_data (seat->wl_seat, seat);
 
-  if (display_wayland->primary_selection_manager)
+  if (display_wayland->zwp_primary_selection_manager_v1)
     {
-      seat->primary_data_device =
-        gtk_primary_selection_device_manager_get_device (display_wayland->primary_selection_manager,
+      seat->zwp_primary_data_device_v1 =
+        zwp_primary_selection_device_manager_v1_get_device (display_wayland->zwp_primary_selection_manager_v1,
+                                                            seat->wl_seat);
+      zwp_primary_selection_device_v1_add_listener (seat->zwp_primary_data_device_v1,
+                                                    &zwp_primary_device_v1_listener,
+                                                    seat);
+    }
+  else if (display_wayland->gtk_primary_selection_manager)
+    {
+      seat->gtk_primary_data_device =
+        gtk_primary_selection_device_manager_get_device (display_wayland->gtk_primary_selection_manager,
                                                          seat->wl_seat);
-      gtk_primary_selection_device_add_listener (seat->primary_data_device,
-                                                 &primary_selection_device_listener, seat);
+      gtk_primary_selection_device_add_listener (seat->gtk_primary_data_device,
+                                                 &gtk_primary_device_listener,
+                                                 seat);
     }
 
   seat->data_device =
@@ -5355,8 +5411,8 @@ gdk_wayland_seat_set_selection (GdkSeat               *seat,
 }
 
 void
-gdk_wayland_seat_set_primary (GdkSeat                             *seat,
-                              struct gtk_primary_selection_source *source)
+gdk_wayland_seat_set_primary (GdkSeat  *seat,
+                              gpointer  source)
 {
   GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (seat);
   GdkWaylandDisplay *display_wayland;
@@ -5366,8 +5422,16 @@ gdk_wayland_seat_set_primary (GdkSeat                             *seat,
     {
       display_wayland = GDK_WAYLAND_DISPLAY (gdk_seat_get_display (seat));
       serial = _gdk_wayland_display_get_serial (display_wayland);
-      gtk_primary_selection_device_set_selection (wayland_seat->primary_data_device,
-                                                  source, serial);
+      if (wayland_seat->zwp_primary_data_device_v1)
+        {
+          zwp_primary_selection_device_v1_set_selection (wayland_seat->zwp_primary_data_device_v1,
+                                                         source, serial);
+        }
+      else if (wayland_seat->gtk_primary_data_device)
+        {
+          gtk_primary_selection_device_set_selection (wayland_seat->gtk_primary_data_device,
+                                                      source, serial);
+        }
     }
 }
 
diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c
index d4503c256236ae942bde999c964fbf1d85abdf29..dfb8d3069a36ddb72340815cd2e809596416ccaf 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -476,10 +476,16 @@ gdk_registry_handle_global (void               *data,
     }
   else if (strcmp (interface, "gtk_primary_selection_device_manager") == 0)
     {
-      display_wayland->primary_selection_manager =
+      display_wayland->gtk_primary_selection_manager =
         wl_registry_bind(display_wayland->wl_registry, id,
                          &gtk_primary_selection_device_manager_interface, 1);
     }
+  else if (strcmp (interface, "zwp_primary_selection_device_manager_v1") == 0)
+    {
+      display_wayland->zwp_primary_selection_manager_v1 =
+        wl_registry_bind(display_wayland->wl_registry, id,
+                         &zwp_primary_selection_device_manager_v1_interface, 1);
+    }
   else if (strcmp (interface, "zwp_tablet_manager_v2") == 0)
     {
       display_wayland->tablet_manager =
diff --git a/gdk/wayland/gdkdisplay-wayland.h b/gdk/wayland/gdkdisplay-wayland.h
index 1e4a9860f61c71466bdb58e288abcb83129fc63d..62696300d15531d0ca212428c8eb3325fe10eb96 100644
--- a/gdk/wayland/gdkdisplay-wayland.h
+++ b/gdk/wayland/gdkdisplay-wayland.h
@@ -35,6 +35,7 @@
 #include <gdk/wayland/keyboard-shortcuts-inhibit-unstable-v1-client-protocol.h>
 #include <gdk/wayland/server-decoration-client-protocol.h>
 #include <gdk/wayland/xdg-output-unstable-v1-client-protocol.h>
+#include <gdk/wayland/primary-selection-unstable-v1-client-protocol.h>
 
 #include <glib.h>
 #include <gdk/gdkkeys.h>
@@ -88,7 +89,8 @@ struct _GdkWaylandDisplay
   struct wl_data_device_manager *data_device_manager;
   struct wl_subcompositor *subcompositor;
   struct zwp_pointer_gestures_v1 *pointer_gestures;
-  struct gtk_primary_selection_device_manager *primary_selection_manager;
+  struct gtk_primary_selection_device_manager *gtk_primary_selection_manager;
+  struct zwp_primary_selection_device_manager_v1 *zwp_primary_selection_manager_v1;
   struct zwp_tablet_manager_v2 *tablet_manager;
   struct zxdg_exporter_v1 *xdg_exporter;
   struct zxdg_importer_v1 *xdg_importer;
diff --git a/gdk/wayland/gdkprivate-wayland.h b/gdk/wayland/gdkprivate-wayland.h
index fc8e9fe2800b129a9ac0432ee85511633eb407f5..4a921b3b9965085b580cbb736f280cfae60efb86 100644
--- a/gdk/wayland/gdkprivate-wayland.h
+++ b/gdk/wayland/gdkprivate-wayland.h
@@ -191,8 +191,8 @@ struct wl_data_device * gdk_wayland_device_get_data_device (GdkDevice *gdk_devic
 void gdk_wayland_seat_set_selection (GdkSeat               *seat,
                                      struct wl_data_source *source);
 
-void gdk_wayland_seat_set_primary (GdkSeat                             *seat,
-                                   struct gtk_primary_selection_source *source);
+void gdk_wayland_seat_set_primary (GdkSeat  *seat,
+                                   gpointer  source);
 
 GdkDragContext * gdk_wayland_device_get_drop_context (GdkDevice *gdk_device);
 
@@ -249,8 +249,8 @@ void gdk_wayland_selection_free (GdkWaylandSelection *selection);
 
 void gdk_wayland_selection_ensure_offer (GdkDisplay           *display,
                                          struct wl_data_offer *wl_offer);
-void gdk_wayland_selection_ensure_primary_offer (GdkDisplay                         *display,
-                                                 struct gtk_primary_selection_offer *wp_offer);
+void gdk_wayland_selection_ensure_primary_offer (GdkDisplay *display,
+                                                 gpointer    wp_offer);
 
 void gdk_wayland_selection_set_offer (GdkDisplay           *display,
                                       GdkAtom               selection,
diff --git a/gdk/wayland/gdkselection-wayland.c b/gdk/wayland/gdkselection-wayland.c
index 0dd3aa9ebfd4dbd80666fcd1c122f67fb2d44569..f85f595616a51168be49b3dd92612ccd6d325fa7 100644
--- a/gdk/wayland/gdkselection-wayland.c
+++ b/gdk/wayland/gdkselection-wayland.c
@@ -104,7 +104,7 @@ struct _GdkWaylandSelection
   GArray *source_targets;
   GdkAtom requested_target;
 
-  struct gtk_primary_selection_source *primary_source;
+  gpointer primary_source;
   GdkWindow *primary_owner;
 
   struct wl_data_source *clipboard_source;
@@ -434,6 +434,18 @@ gdk_wayland_selection_new (void)
   return selection;
 }
 
+static void
+primary_selection_source_destroy (gpointer primary_source)
+{
+  GdkDisplay *display = gdk_display_get_default ();
+  GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
+
+  if (display_wayland->zwp_primary_selection_manager_v1)
+    zwp_primary_selection_source_v1_destroy (primary_source);
+  else if (display_wayland->gtk_primary_selection_manager)
+    gtk_primary_selection_source_destroy (primary_source);
+}
+
 void
 gdk_wayland_selection_free (GdkWaylandSelection *selection)
 {
@@ -448,7 +460,7 @@ gdk_wayland_selection_free (GdkWaylandSelection *selection)
   g_ptr_array_unref (selection->stored_selections);
 
   if (selection->primary_source)
-    gtk_primary_selection_source_destroy (selection->primary_source);
+    primary_selection_source_destroy (selection->primary_source);
   if (selection->clipboard_source)
     wl_data_source_destroy (selection->clipboard_source);
   if (selection->dnd_source)
@@ -546,27 +558,47 @@ static const struct wl_data_offer_listener data_offer_listener = {
 };
 
 static void
-primary_offer_offer (void                               *data,
-                     struct gtk_primary_selection_offer *gtk_offer,
-                     const char                         *type)
+primary_offer_offer (void       *data,
+                     gpointer    offer,
+                     const char *type)
 {
   GdkWaylandSelection *selection = data;
   DataOfferData *info;
   GdkAtom atom = gdk_atom_intern (type, FALSE);
 
-  info = g_hash_table_lookup (selection->offers, gtk_offer);
+  info = g_hash_table_lookup (selection->offers, offer);
 
   if (!info || g_list_find (info->targets, atom))
     return;
 
   GDK_NOTE (EVENTS,
-            g_message ("primary offer offer, offer %p, type = %s", gtk_offer, type));
+            g_message ("primary offer offer, offer %p, type = %s", offer, type));
 
   info->targets = g_list_prepend (info->targets, atom);
 }
 
-static const struct gtk_primary_selection_offer_listener primary_offer_listener = {
-  primary_offer_offer,
+static void
+gtk_primary_offer_offer (void                               *data,
+                         struct gtk_primary_selection_offer *offer,
+                         const char                         *type)
+{
+  primary_offer_offer (data, (gpointer) offer, type);
+}
+
+static void
+zwp_primary_offer_v1_offer (void                                  *data,
+                            struct zwp_primary_selection_offer_v1 *offer,
+                            const char                            *type)
+{
+  primary_offer_offer (data, (gpointer) offer, type);
+}
+
+static const struct gtk_primary_selection_offer_listener gtk_primary_offer_listener = {
+  gtk_primary_offer_offer,
+};
+
+static const struct zwp_primary_selection_offer_v1_listener zwp_primary_offer_listener_v1 = {
+  zwp_primary_offer_v1_offer,
 };
 
 SelectionData *
@@ -604,9 +636,10 @@ gdk_wayland_selection_ensure_offer (GdkDisplay           *display,
 }
 
 void
-gdk_wayland_selection_ensure_primary_offer (GdkDisplay                         *display,
-                                            struct gtk_primary_selection_offer *gtk_offer)
+gdk_wayland_selection_ensure_primary_offer (GdkDisplay *display,
+                                            gpointer    gtk_offer)
 {
+  GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
   GdkWaylandSelection *selection = gdk_wayland_display_get_selection (display);
   DataOfferData *info;
 
@@ -614,12 +647,24 @@ gdk_wayland_selection_ensure_primary_offer (GdkDisplay                         *
 
   if (!info)
     {
-      info = data_offer_data_new (gtk_offer,
-                                  (GDestroyNotify) gtk_primary_selection_offer_destroy);
-      g_hash_table_insert (selection->offers, gtk_offer, info);
-      gtk_primary_selection_offer_add_listener (gtk_offer,
-                                                &primary_offer_listener,
-                                                selection);
+      if (display_wayland->zwp_primary_selection_manager_v1)
+        {
+          info = data_offer_data_new (gtk_offer,
+                                      (GDestroyNotify) zwp_primary_selection_offer_v1_destroy);
+          g_hash_table_insert (selection->offers, gtk_offer, info);
+          zwp_primary_selection_offer_v1_add_listener (gtk_offer,
+                                                       &zwp_primary_offer_listener_v1,
+                                                       selection);
+        }
+      else if (display_wayland->gtk_primary_selection_manager)
+        {
+          info = data_offer_data_new (gtk_offer,
+                                      (GDestroyNotify) gtk_primary_selection_offer_destroy);
+          g_hash_table_insert (selection->offers, gtk_offer, info);
+          gtk_primary_selection_offer_add_listener (gtk_offer,
+                                                    &gtk_primary_offer_listener,
+                                                    selection);
+        }
     }
 }
 
@@ -1138,10 +1183,10 @@ static const struct wl_data_source_listener data_source_listener = {
 };
 
 static void
-primary_source_send (void                                *data,
-                     struct gtk_primary_selection_source *source,
-                     const char                          *mime_type,
-                     int32_t                              fd)
+primary_source_send (void       *data,
+                     gpointer    source,
+                     const char *mime_type,
+                     int32_t     fd)
 {
   GdkWaylandSelection *wayland_selection = data;
 
@@ -1163,8 +1208,26 @@ primary_source_send (void                                *data,
 }
 
 static void
-primary_source_cancelled (void                                *data,
-                          struct gtk_primary_selection_source *source)
+gtk_primary_source_send (void                                *data,
+                         struct gtk_primary_selection_source *source,
+                         const char                          *mime_type,
+                         int32_t                              fd)
+{
+  primary_source_send (data, (gpointer) source, mime_type, fd);
+}
+
+static void
+zwp_primary_source_v1_send (void                                   *data,
+                            struct zwp_primary_selection_source_v1 *source,
+                            const char                             *mime_type,
+                            int32_t                                 fd)
+{
+  primary_source_send (data, (gpointer) source, mime_type, fd);
+}
+
+static void
+primary_source_cancelled (void     *data,
+                          gpointer  source)
 {
   GdkDisplay *display;
   GdkAtom atom;
@@ -1180,9 +1243,28 @@ primary_source_cancelled (void                                *data,
   gdk_wayland_selection_unset_data_source (display, atom);
 }
 
-static const struct gtk_primary_selection_source_listener primary_source_listener = {
-  primary_source_send,
-  primary_source_cancelled,
+static void
+gtk_primary_source_cancelled (void                                *data,
+                              struct gtk_primary_selection_source *source)
+{
+  primary_source_cancelled (data, source);
+}
+
+static void
+zwp_primary_source_v1_cancelled (void                                   *data,
+                                 struct zwp_primary_selection_source_v1 *source)
+{
+  primary_source_cancelled (data, source);
+}
+
+static const struct gtk_primary_selection_source_listener gtk_primary_source_listener = {
+  gtk_primary_source_send,
+  gtk_primary_source_cancelled,
+};
+
+static const struct zwp_primary_selection_source_v1_listener zwp_primary_source_v1_listener = {
+  zwp_primary_source_v1_send,
+  zwp_primary_source_v1_cancelled,
 };
 
 struct wl_data_source *
@@ -1204,11 +1286,11 @@ gdk_wayland_selection_get_data_source (GdkWindow *owner,
     {
       if (wayland_selection->primary_source &&
           (!owner || owner == wayland_selection->primary_owner))
-        return (gpointer) wayland_selection->primary_source;
+        return wayland_selection->primary_source;
 
       if (wayland_selection->primary_source)
         {
-          gtk_primary_selection_source_destroy (wayland_selection->primary_source);
+          primary_selection_source_destroy (wayland_selection->primary_source);
           wayland_selection->primary_source = NULL;
         }
     }
@@ -1234,11 +1316,18 @@ gdk_wayland_selection_get_data_source (GdkWindow *owner,
 
   if (selection == atoms[ATOM_PRIMARY])
     {
-      if (display_wayland->primary_selection_manager)
+      if (display_wayland->zwp_primary_selection_manager_v1)
+        {
+          source = zwp_primary_selection_device_manager_v1_create_source (display_wayland->zwp_primary_selection_manager_v1);
+          zwp_primary_selection_source_v1_add_listener (source,
+                                                        &zwp_primary_source_v1_listener,
+                                                        wayland_selection);
+        }
+      else if (display_wayland->gtk_primary_selection_manager)
         {
-          source = gtk_primary_selection_device_manager_create_source (display_wayland->primary_selection_manager);
+          source = gtk_primary_selection_device_manager_create_source (display_wayland->gtk_primary_selection_manager);
           gtk_primary_selection_source_add_listener (source,
-                                                     &primary_source_listener,
+                                                     &gtk_primary_source_listener,
                                                      wayland_selection);
         }
     }
@@ -1278,7 +1367,7 @@ gdk_wayland_selection_unset_data_source (GdkDisplay *display,
     {
       if (wayland_selection->primary_source)
         {
-          gtk_primary_selection_source_destroy (wayland_selection->primary_source);
+          primary_selection_source_destroy (wayland_selection->primary_source);
           wayland_selection->primary_source = NULL;
         }
     }
@@ -1449,6 +1538,7 @@ _gdk_wayland_display_convert_selection (GdkDisplay *display,
                                         GdkAtom     target,
                                         guint32     time)
 {
+  GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
   GdkWaylandSelection *wayland_selection = gdk_wayland_display_get_selection (display);
   const SelectionData *selection_data;
   SelectionBuffer *buffer_data;
@@ -1514,9 +1604,16 @@ _gdk_wayland_display_convert_selection (GdkDisplay *display,
           g_unix_open_pipe (pipe_fd, FD_CLOEXEC, NULL);
 
           if (selection == atoms[ATOM_PRIMARY])
-            gtk_primary_selection_offer_receive (offer, mimetype, pipe_fd[1]);
+            {
+              if (display_wayland->zwp_primary_selection_manager_v1)
+                zwp_primary_selection_offer_v1_receive (offer, mimetype, pipe_fd[1]);
+              else if (display_wayland->gtk_primary_selection_manager)
+                gtk_primary_selection_offer_receive (offer, mimetype, pipe_fd[1]);
+            }
           else
-            wl_data_offer_receive (offer, mimetype, pipe_fd[1]);
+            {
+              wl_data_offer_receive (offer, mimetype, pipe_fd[1]);
+            }
 
           stream = g_unix_input_stream_new (pipe_fd[0], TRUE);
           close (pipe_fd[1]);
diff --git a/gdk/wayland/meson.build b/gdk/wayland/meson.build
index 8f6b7faf31ca379cd602ae437b7864308b1bffd6..e66afd7f95bfc6e39cd200eedf55813862213664 100644
--- a/gdk/wayland/meson.build
+++ b/gdk/wayland/meson.build
@@ -56,6 +56,7 @@ proto_sources = [
   ['keyboard-shortcuts-inhibit', 'unstable', 'v1', ],
   ['server-decoration', 'private' ],
   ['xdg-output', 'unstable', 'v1', ],
+  ['primary-selection', 'unstable', 'v1', ],
 ]
 
 gdk_wayland_gen_headers = []
diff --git a/meson.build b/meson.build
index a3a7545ae103a88fc73cffe917c79848018f1a61..9c80fafc0314aed310018bc1f8851bc00e85f68a 100644
--- a/meson.build
+++ b/meson.build
@@ -30,7 +30,7 @@ atk_req            = '>= 2.15.1'
 cairo_req          = '>= 1.14.0'
 gdk_pixbuf_req     = '>= 2.30.0'
 introspection_req  = '>= 1.39.0'
-wayland_proto_req  = '>= 1.14'
+wayland_proto_req  = '>= 1.17'
 wayland_req        = '>= 1.14.91'
 epoxy_req          = '>= 1.4'
 cloudproviders_req = '>= 0.2.5'