sway pointer

This commit is contained in:
Tony Crisci 2017-12-10 15:49:54 -05:00
parent 4d449743c5
commit 9ae906cd37
2 changed files with 37 additions and 2 deletions

View file

@ -10,11 +10,18 @@ struct sway_seat {
struct sway_input_manager *input;
swayc_t *focus;
struct wl_list keyboards;
struct wl_list keyboards; // sway_keyboard::link
struct wl_list pointers; // sway_pointer::link
struct wl_listener focus_destroy;
};
struct sway_pointer {
struct sway_seat *seat;
struct wlr_input_device *device;
struct wl_list link;
};
struct sway_seat *sway_seat_create(struct sway_input_manager *input,
const char *seat_name);

View file

@ -42,6 +42,18 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input,
return seat;
}
static struct sway_pointer *seat_pointer_from_device(struct sway_seat *seat,
struct wlr_input_device *device) {
struct sway_pointer *pointer = NULL;
wl_list_for_each(pointer, &seat->pointers, link) {
if (pointer->device == device) {
return pointer;
}
}
return pointer;
}
static struct sway_keyboard *seat_keyboard_from_device(struct sway_seat *seat,
struct wlr_input_device *device) {
struct sway_keyboard *keyboard = NULL;
@ -57,6 +69,16 @@ static struct sway_keyboard *seat_keyboard_from_device(struct sway_seat *seat,
static void seat_add_pointer(struct sway_seat *seat,
struct wlr_input_device *device) {
// TODO pointer configuration
if (seat_pointer_from_device(seat, device)) {
// already added
return;
}
struct sway_pointer *pointer = calloc(1, sizeof(struct sway_pointer));
pointer->seat = seat;
pointer->device = device;
wl_list_insert(&seat->pointers, &pointer->link);
wlr_cursor_attach_input_device(seat->cursor->cursor, device);
}
@ -100,7 +122,13 @@ static void seat_remove_keyboard(struct sway_seat *seat,
static void seat_remove_pointer(struct sway_seat *seat,
struct wlr_input_device *device) {
wlr_cursor_detach_input_device(seat->cursor->cursor, device);
struct sway_pointer *pointer = seat_pointer_from_device(seat, device);
if (pointer) {
wl_list_remove(&pointer->link);
free(pointer);
wlr_cursor_detach_input_device(seat->cursor->cursor, device);
}
}
void sway_seat_remove_device(struct sway_seat *seat,