Clean up serial handling and automate proximity acompaning events

This commit is contained in:
Markus Ongyerth 2018-05-17 15:21:20 +02:00
parent 25c2808153
commit dc525a9c5f
3 changed files with 28 additions and 13 deletions

View File

@ -8,7 +8,7 @@
#include "tablet-unstable-v2-protocol.h"
/* This can probably be even lower,the tools don't have a lot of buttons */
#define WLR_TABLEt_V2_TOOL_BUTTONS_CAP 16
#define WLR_TABLET_V2_TOOL_BUTTONS_CAP 16
struct wlr_tablet_client_v2;
struct wlr_tablet_tool_client_v2;
@ -51,8 +51,8 @@ struct wlr_tablet_v2_tablet_tool {
bool is_down;
uint32_t down_serial;
size_t num_buttons;
uint32_t pressed_buttons[WLR_TABLEt_V2_TOOL_BUTTONS_CAP];
uint32_t pressed_serials[WLR_TABLEt_V2_TOOL_BUTTONS_CAP];
uint32_t pressed_buttons[WLR_TABLET_V2_TOOL_BUTTONS_CAP];
uint32_t pressed_serials[WLR_TABLET_V2_TOOL_BUTTONS_CAP];
struct {
struct wl_signal set_cursor; // struct wlr_tablet_v2_event_cursor

View File

@ -117,6 +117,8 @@ void wlr_tablet_seat_client_v2_destroy(struct wl_resource *resource) {
destroy_tablet_tool_v2(tool->resource);
}
wl_list_remove(&seat->seat_link);
wl_list_remove(&seat->client_link);
wl_list_remove(&seat->seat_client_destroy.link);
free(seat);

View File

@ -261,20 +261,22 @@ static ssize_t tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool,
}
}
if (button == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED && !found &&
tool->num_buttons < WLR_TABLEt_V2_TOOL_BUTTONS_CAP) {
if (state == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED && !found &&
tool->num_buttons < WLR_TABLET_V2_TOOL_BUTTONS_CAP) {
i = tool->num_buttons++;
tool->pressed_buttons[i] = button;
}
if (button == ZWP_TABLET_PAD_V2_BUTTON_STATE_RELEASED && found) {
tool->pressed_buttons[i] = 0;
tool->pressed_serials[i] = 0;
tool->num_buttons = push_zeroes_to_end(tool->pressed_buttons, WLR_TABLEt_V2_TOOL_BUTTONS_CAP);
tool->num_buttons = push_zeroes_to_end(tool->pressed_serials, WLR_TABLEt_V2_TOOL_BUTTONS_CAP);
tool->pressed_serials[i] = -1;
} else {
i = -1;
}
if (state == ZWP_TABLET_PAD_V2_BUTTON_STATE_RELEASED && found) {
tool->pressed_buttons[i] = 0;
tool->pressed_serials[i] = 0;
tool->num_buttons = push_zeroes_to_end(tool->pressed_buttons, WLR_TABLET_V2_TOOL_BUTTONS_CAP);
tool->num_buttons = push_zeroes_to_end(tool->pressed_serials, WLR_TABLET_V2_TOOL_BUTTONS_CAP);
}
assert(tool->num_buttons <= WLR_TABLEt_V2_TOOL_BUTTONS_CAP);
assert(tool->num_buttons <= WLR_TABLET_V2_TOOL_BUTTONS_CAP);
return i;
}
@ -378,12 +380,23 @@ void wlr_send_tablet_v2_tablet_tool_motion(
void wlr_send_tablet_v2_tablet_tool_proximity_out(
struct wlr_tablet_v2_tablet_tool *tool) {
if (tool->current_client) {
for (size_t i = 0; i < tool->num_buttons; ++i) {
zwp_tablet_tool_v2_send_button(tool->current_client->resource,
tool->pressed_serials[i],
tool->pressed_buttons[i],
ZWP_TABLET_PAD_V2_BUTTON_STATE_RELEASED);
}
if (tool->is_down) {
zwp_tablet_tool_v2_send_up(tool->current_client->resource);
}
zwp_tablet_tool_v2_send_proximity_out(tool->current_client->resource);
if (tool->current_client->frame_source) {
wl_event_source_remove(tool->current_client->frame_source);
send_tool_frame(tool->current_client);
}
tool->current_client = NULL;
tool->focused_surface = NULL;
}
}