Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
Clean up wayland backend tablet support
Browse files Browse the repository at this point in the history
Mostly address feedback from emersion on PR #1694
Remove const qualifier from char *name, to allow free() call
  • Loading branch information
Markus Ongyerth authored and emersion committed Sep 26, 2019
1 parent 2285e36 commit ebeef0f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
6 changes: 1 addition & 5 deletions backend/wayland/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
#include "xdg-shell-client-protocol.h"
#include "tablet-unstable-v2-client-protocol.h"

struct wlr_wl_tablet_seat *wlr_wl_add_tablet_seat(
struct zwp_tablet_manager_v2 *manager,
struct wl_seat *seat, struct wlr_wl_backend *backend);

struct wlr_wl_backend *get_wl_backend_from_backend(struct wlr_backend *backend) {
assert(wlr_backend_is_wl(backend));
return (struct wlr_wl_backend *)backend;
Expand Down Expand Up @@ -118,7 +114,7 @@ static bool backend_start(struct wlr_backend *backend) {
}

if (wl->tablet_manager && wl->seat) {
wlr_wl_add_tablet_seat(wl->tablet_manager,
wl_add_tablet_seat(wl->tablet_manager,
wl->seat, wl);
}

Expand Down
26 changes: 10 additions & 16 deletions backend/wayland/tablet_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@
#include "wlr/util/log.h"
#include "tablet-unstable-v2-client-protocol.h"

#include <backend/wayland.h>
#include "backend/wayland.h"

struct wlr_wl_tablet_seat {
struct zwp_tablet_seat_v2 *tablet_seat;
struct wl_list tablets;
struct wl_list tools;
// struct wl_list pads; // wlr_wl_tablet_pad::link
};

struct wlr_wl_tablet_tool {
Expand Down Expand Up @@ -92,10 +89,6 @@ static uint32_t get_current_time_msec(void) {
return now.tv_nsec / (1000 * 1000) + now.tv_sec * 1000;
}

struct wlr_wl_tablet_seat *wlr_wl_add_tablet_seat(
struct zwp_tablet_manager_v2 *manager,
struct wl_seat *seat, struct wlr_wl_backend *backend);

static void handle_tablet_pad_ring_source(void *data,
struct zwp_tablet_pad_ring_v2 *zwp_tablet_pad_ring_v2,
uint32_t source) {
Expand Down Expand Up @@ -207,6 +200,7 @@ static void handle_tablet_pad_group_buttons(void *data,
struct wl_array *buttons) {
struct wlr_wl_tablet_pad_group *group = data;

free(group->group.buttons);
group->group.buttons = calloc(1, buttons->size);
if (!group->group.buttons) {
// FIXME: Add actual error handling
Expand Down Expand Up @@ -470,9 +464,10 @@ static void handle_tablet_tool_done(void *data,
struct zwp_tablet_tool_v2 *id) {
/* empty */
}

static enum wlr_tablet_tool_type tablet_type_to_wlr_type(enum zwp_tablet_tool_v2_type type) {

switch(type) {
switch (type) {
case ZWP_TABLET_TOOL_V2_TYPE_PEN:
return WLR_TABLET_TOOL_TYPE_PEN;
case ZWP_TABLET_TOOL_V2_TYPE_ERASER:
Expand Down Expand Up @@ -527,7 +522,7 @@ static void handle_tablet_tool_capability(void *data,

enum zwp_tablet_tool_v2_capability cap = capability;

switch(cap) {
switch (cap) {
case ZWP_TABLET_TOOL_V2_CAPABILITY_TILT:
tool->wlr_tool.tilt = true;
break;
Expand Down Expand Up @@ -841,6 +836,8 @@ static void handle_tablet_name(void *data, struct zwp_tablet_v2 *zwp_tablet_v2,
const char *name) {
struct wlr_wl_input_device *dev = data;
struct wlr_tablet *tablet = dev->wlr_input_device.tablet;

free(tablet->name);
tablet->name = strdup(name);
}

Expand Down Expand Up @@ -894,12 +891,13 @@ static void handle_tab_added(void *data,
struct wlr_wl_backend *backend = data;
struct wlr_wl_input_device *dev = create_wl_input_device(
backend, WLR_INPUT_DEVICE_TABLET_TOOL);
dev->resource = id;

if (!dev) {
zwp_tablet_v2_destroy(id);
return;
}
dev->resource = id;

struct wlr_input_device *wlr_dev = &dev->wlr_input_device;
wlr_dev->tablet = calloc(1, sizeof(*wlr_dev->tablet));

Expand All @@ -918,7 +916,7 @@ static const struct zwp_tablet_seat_v2_listener tablet_seat_listener = {
.pad_added = handle_pad_added,
};

struct wlr_wl_tablet_seat *wlr_wl_add_tablet_seat(
struct wlr_wl_tablet_seat *wl_add_tablet_seat(
struct zwp_tablet_manager_v2 *manager,
struct wl_seat *seat, struct wlr_wl_backend *backend) {
struct wlr_wl_tablet_seat *ret =
Expand All @@ -933,9 +931,5 @@ struct wlr_wl_tablet_seat *wlr_wl_add_tablet_seat(
zwp_tablet_seat_v2_add_listener(ret->tablet_seat,
&tablet_seat_listener, backend);

wl_list_init(&ret->tablets);
wl_list_init(&ret->tools);
//wl_list_init(&ret->pads);

return ret;
}
4 changes: 4 additions & 0 deletions include/backend/wayland.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ struct wlr_wl_input_device *create_wl_input_device(

extern const struct wl_seat_listener seat_listener;

struct wlr_wl_tablet_seat *wl_add_tablet_seat(
struct zwp_tablet_manager_v2 *manager,
struct wl_seat *seat, struct wlr_wl_backend *backend);

#endif
2 changes: 1 addition & 1 deletion include/wlr/types/wlr_tablet_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct wlr_tablet {
struct wl_signal button;
} events;

const char *name;
char *name;
struct wlr_list paths; // char *

void *data;
Expand Down

0 comments on commit ebeef0f

Please sign in to comment.