Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial touch support #170

Merged
merged 1 commit into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ void init_default_config(struct mako_config *config) {
config->sort_criteria = MAKO_SORT_CRITERIA_TIME;
config->sort_asc = 0;

config->button_bindings.left = MAKO_BUTTON_BINDING_INVOKE_DEFAULT_ACTION;
config->button_bindings.right = MAKO_BUTTON_BINDING_DISMISS;
config->button_bindings.middle = MAKO_BUTTON_BINDING_NONE;
config->button_bindings.left = MAKO_BINDING_INVOKE_DEFAULT_ACTION;
config->button_bindings.right = MAKO_BINDING_DISMISS;
config->button_bindings.middle = MAKO_BINDING_NONE;
config->touch = MAKO_BINDING_DISMISS;

config->anchor =
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
Expand Down
14 changes: 8 additions & 6 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include "types.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"

enum mako_button_binding {
MAKO_BUTTON_BINDING_NONE,
MAKO_BUTTON_BINDING_DISMISS,
MAKO_BUTTON_BINDING_DISMISS_ALL,
MAKO_BUTTON_BINDING_INVOKE_DEFAULT_ACTION,
enum mako_binding {
MAKO_BINDING_NONE,
MAKO_BINDING_DISMISS,
MAKO_BINDING_DISMISS_ALL,
MAKO_BINDING_INVOKE_DEFAULT_ACTION,
};

enum mako_sort_criteria {
Expand Down Expand Up @@ -81,8 +81,10 @@ struct mako_config {
struct mako_style superstyle;

struct {
enum mako_button_binding left, right, middle;
enum mako_binding left, right, middle;
} button_bindings;

enum mako_binding touch;
};

void init_default_config(struct mako_config *config);
Expand Down
3 changes: 3 additions & 0 deletions include/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ size_t format_notification(struct mako_notification *notif, const char *format,
char *buf);
void notification_handle_button(struct mako_notification *notif, uint32_t button,
enum wl_pointer_button_state state);
void notification_handle_touch(struct mako_notification *notif);
void notification_execute_binding(struct mako_notification *notif,
enum mako_binding binding);
void insert_notification(struct mako_state *state, struct mako_notification *notif);
int group_notifications(struct mako_state *state, struct mako_criteria *criteria);

Expand Down
5 changes: 5 additions & 0 deletions include/wayland.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ struct mako_seat {
struct wl_pointer *wl_pointer;
int32_t x, y;
} pointer;

struct {
struct wl_touch *wl_touch;
int32_t x, y;
} touch;
};

bool init_wayland(struct mako_state *state);
Expand Down
37 changes: 24 additions & 13 deletions notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ size_t format_text(const char *format, char *buf, mako_format_func_t format_func
return len;
}

static enum mako_button_binding get_button_binding(struct mako_config *config,
static enum mako_binding get_binding(struct mako_config *config,
uint32_t button) {
switch (button) {
case BTN_LEFT:
Expand All @@ -279,25 +279,21 @@ static enum mako_button_binding get_button_binding(struct mako_config *config,
case BTN_MIDDLE:
return config->button_bindings.middle;
}
return MAKO_BUTTON_BINDING_NONE;
return MAKO_BINDING_NONE;
}

void notification_handle_button(struct mako_notification *notif, uint32_t button,
enum wl_pointer_button_state state) {
if (state != WL_POINTER_BUTTON_STATE_PRESSED) {
return;
}

switch (get_button_binding(&notif->state->config, button)) {
case MAKO_BUTTON_BINDING_NONE:
void notification_execute_binding(struct mako_notification *notif,
enum mako_binding binding) {
switch (binding) {
case MAKO_BINDING_NONE:
break;
case MAKO_BUTTON_BINDING_DISMISS:
case MAKO_BINDING_DISMISS:
close_notification(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED);
break;
case MAKO_BUTTON_BINDING_DISMISS_ALL:
case MAKO_BINDING_DISMISS_ALL:
close_all_notifications(notif->state, MAKO_NOTIFICATION_CLOSE_DISMISSED);
break;
case MAKO_BUTTON_BINDING_INVOKE_DEFAULT_ACTION:;
case MAKO_BINDING_INVOKE_DEFAULT_ACTION:;
struct mako_action *action;
wl_list_for_each(action, &notif->actions, link) {
if (strcmp(action->key, DEFAULT_ACTION_KEY) == 0) {
Expand All @@ -310,6 +306,21 @@ void notification_handle_button(struct mako_notification *notif, uint32_t button
}
}

void notification_handle_button(struct mako_notification *notif, uint32_t button,
enum wl_pointer_button_state state) {
if (state != WL_POINTER_BUTTON_STATE_PRESSED) {
return;
}

notification_execute_binding(notif,
get_binding(&notif->state->config, button));
}

void notification_handle_touch(struct mako_notification *notif) {
sheenobu marked this conversation as resolved.
Show resolved Hide resolved
notification_execute_binding(notif,
notif->state->config.touch);
}

/*
* Searches through the notifications list and returns the next position at
* which to insert. If no results for the specified urgency are found,
Expand Down
49 changes: 49 additions & 0 deletions wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,37 @@ static void destroy_output(struct mako_output *output) {
free(output);
}

static void touch_handle_motion(void *data, struct wl_touch *wl_touch,
uint32_t time, int32_t id,
wl_fixed_t surface_x, wl_fixed_t surface_y) {
struct mako_seat *seat = data;
seat->touch.x = wl_fixed_to_int(surface_x);
seat->touch.y = wl_fixed_to_int(surface_y);
}

static void touch_handle_down(void *data, struct wl_touch *wl_touch,
uint32_t serial, uint32_t time, struct wl_surface *sfc, int32_t id,
wl_fixed_t surface_x, wl_fixed_t surface_y) {
struct mako_seat *seat = data;
seat->touch.x = wl_fixed_to_int(surface_x);
seat->touch.y = wl_fixed_to_int(surface_y);
}

static void touch_handle_up(void *data, struct wl_touch *wl_touch,
uint32_t serial, uint32_t time, int32_t id) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up issue: handle id to add support for multitouch.

struct mako_seat *seat = data;
struct mako_state *state = seat->state;

struct mako_notification *notif;
wl_list_for_each(notif, &state->notifications, link) {
if (hotspot_at(&notif->hotspot, seat->touch.x, seat->touch.y)) {
notification_handle_touch(notif);
break;
sheenobu marked this conversation as resolved.
Show resolved Hide resolved
}
}

set_dirty(state);
}

static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
Expand Down Expand Up @@ -129,6 +160,15 @@ static const struct wl_pointer_listener pointer_listener = {
.axis = noop,
};

static const struct wl_touch_listener touch_listener = {
.down = touch_handle_down,
.up = touch_handle_up,
.motion = touch_handle_motion,
.frame = noop,
.cancel = noop,
.shape = noop,
.orientation = noop,
};

static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
uint32_t capabilities) {
Expand All @@ -143,6 +183,15 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
wl_pointer_add_listener(seat->pointer.wl_pointer,
&pointer_listener, seat);
}
if (seat->touch.wl_touch != NULL) {
wl_touch_release(seat->touch.wl_touch);
seat->touch.wl_touch = NULL;
}
if (capabilities & WL_SEAT_CAPABILITY_TOUCH) {
seat->touch.wl_touch = wl_seat_get_touch(wl_seat);
sheenobu marked this conversation as resolved.
Show resolved Hide resolved
wl_touch_add_listener(seat->touch.wl_touch,
&touch_listener, seat);
}
}

static const struct wl_seat_listener seat_listener = {
Expand Down