Merge pull request #1485 from emersion/data-device-serial

primary-selection: add a serial argument
This commit is contained in:
emersion 2019-01-22 20:13:01 +01:00 committed by GitHub
commit 365a75139c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 19 deletions

View file

@ -163,7 +163,8 @@ void wlr_seat_destroy(struct wlr_seat *seat) {
seat->selection_source = NULL;
}
wlr_seat_set_primary_selection(seat, NULL);
wlr_seat_set_primary_selection(seat, NULL,
wl_display_next_serial(seat->display));
struct wlr_seat_client *client, *tmp;
wl_list_for_each_safe(client, tmp, &seat->clients, link) {

View file

@ -208,16 +208,7 @@ static void device_handle_set_selection(struct wl_client *client,
source = &client_source->source;
}
// TODO: improve serial validation
if (device->seat->primary_selection_source != NULL &&
device->selection_serial - serial < UINT32_MAX / 2) {
wlr_log(WLR_DEBUG, "Rejecting set_selection request, invalid serial "
"(%"PRIu32" <= %"PRIu32")", serial, device->selection_serial);
return;
}
device->selection_serial = serial;
wlr_seat_set_primary_selection(device->seat, source);
wlr_seat_set_primary_selection(device->seat, source, serial);
}
static void device_handle_destroy(struct wl_client *client,

View file

@ -1,6 +1,7 @@
#include <assert.h>
#include <stdlib.h>
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/util/log.h>
#include "util/signal.h"
void wlr_primary_selection_source_init(
@ -50,7 +51,14 @@ static void seat_handle_primary_selection_source_destroy(
}
void wlr_seat_set_primary_selection(struct wlr_seat *seat,
struct wlr_primary_selection_source *source) {
struct wlr_primary_selection_source *source, uint32_t serial) {
if (seat->primary_selection_source != NULL &&
seat->primary_selection_serial - serial < UINT32_MAX / 2) {
wlr_log(WLR_DEBUG, "Rejecting set_selection request, invalid serial "
"(%"PRIu32" <= %"PRIu32")", serial, seat->primary_selection_serial);
return;
}
if (seat->primary_selection_source != NULL) {
wl_list_remove(&seat->primary_selection_source_destroy.link);
wlr_primary_selection_source_destroy(seat->primary_selection_source);
@ -58,6 +66,8 @@ void wlr_seat_set_primary_selection(struct wlr_seat *seat,
}
seat->primary_selection_source = source;
seat->primary_selection_serial = serial;
if (source != NULL) {
seat->primary_selection_source_destroy.notify =
seat_handle_primary_selection_source_destroy;