Skip to content

Commit f0563b7

Browse files
committed
(wip) consider long press done even before release
1 parent 85bbcf7 commit f0563b7

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

include/notification.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ struct mako_hotspot {
1919
int32_t width, height;
2020
};
2121

22+
struct mako_binding_context {
23+
struct mako_surface *surface;
24+
struct mako_seat *seat;
25+
uint32_t serial;
26+
};
27+
2228
struct mako_notification {
2329
struct mako_state *state;
2430
struct mako_surface *surface;
@@ -38,6 +44,8 @@ struct mako_notification {
3844
char *body;
3945
int32_t requested_timeout;
4046
struct wl_list actions; // mako_action::link
47+
struct mako_timer *long_press_timer;
48+
struct mako_binding_context long_press_ctx;
4149

4250
enum mako_notification_urgency urgency;
4351
char *category;
@@ -70,12 +78,6 @@ struct mako_hidden_format_data {
7078
size_t count;
7179
};
7280

73-
struct mako_binding_context {
74-
struct mako_surface *surface;
75-
struct mako_seat *seat;
76-
uint32_t serial;
77-
};
78-
7981
typedef char *(*mako_format_func_t)(char variable, bool *markup, void *data);
8082

8183
bool hotspot_at(struct mako_hotspot *hotspot, int32_t x, int32_t y);
@@ -100,6 +102,8 @@ size_t format_notification(struct mako_notification *notif, const char *format,
100102
char *buf);
101103
void notification_handle_button(struct mako_notification *notif, uint32_t button,
102104
enum wl_pointer_button_state state, const struct mako_binding_context *ctx);
105+
void notification_handle_touch_start(struct mako_notification *notif,
106+
const struct mako_binding_context *ctx);
103107
void notification_handle_touch(struct mako_notification *notif,
104108
const struct mako_binding_context *ctx, int32_t duration_ms);
105109
void notification_execute_binding(struct mako_notification *notif,

include/wayland.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <stdbool.h>
55
#include <wayland-client-protocol.h>
6+
#include "mako.h"
67

78
#define MAX_TOUCHPOINTS 10
89

notification.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ void reset_notification(struct mako_notification *notif) {
4141

4242
destroy_timer(notif->timer);
4343
notif->timer = NULL;
44+
destroy_timer(notif->long_press_timer);
45+
notif->long_press_timer = NULL;
4446

4547
free(notif->app_name);
4648
free(notif->app_icon);
@@ -447,13 +449,38 @@ void notification_handle_button(struct mako_notification *notif, uint32_t button
447449

448450
void notification_handle_touch(struct mako_notification *notif,
449451
const struct mako_binding_context *ctx, int32_t duration_ms) {
452+
destroy_timer(notif->long_press_timer);
453+
notif->long_press_timer = NULL;
450454
if (duration_ms >= notif->style.long_press_duration) {
451455
notification_execute_binding(notif, &notif->style.long_touch_binding, ctx);
452456
} else {
453457
notification_execute_binding(notif, &notif->style.touch_binding, ctx);
454458
}
455459
}
456460

461+
void handle_notification_touch_timer(void *data) {
462+
struct mako_notification *notif = data;
463+
notif->long_press_timer = NULL;
464+
notif->long_press_ctx.surface = notif->surface;
465+
const struct mako_binding_context *ctx = &notif->long_press_ctx;
466+
if (notif->surface) {
467+
set_dirty(notif->surface);
468+
} else {
469+
ctx = NULL;
470+
}
471+
notification_execute_binding(notif, &notif->style.long_touch_binding, ctx);
472+
}
473+
474+
void notification_handle_touch_start(struct mako_notification *notif,
475+
const struct mako_binding_context *ctx) {
476+
if (notif->long_press_timer) {
477+
return;
478+
}
479+
notif->long_press_ctx = *ctx;
480+
add_event_loop_timer(&notif->state->event_loop, 500,
481+
handle_notification_touch_timer, notif);
482+
}
483+
457484
/*
458485
* Searches through the notifications list and returns the next position at
459486
* which to insert. If no results for the specified urgency are found,

wayland.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,23 @@ static void touch_handle_down(void *data, struct wl_touch *wl_touch,
120120
if (id >= MAX_TOUCHPOINTS) {
121121
return;
122122
}
123+
struct mako_state *state = seat->state;
123124
seat->touch.pts[id].x = wl_fixed_to_int(surface_x);
124125
seat->touch.pts[id].y = wl_fixed_to_int(surface_y);
125126
seat->touch.pts[id].time = time;
126-
seat->touch.pts[id].surface = get_surface(seat->state, wl_surface);
127+
seat->touch.pts[id].surface = get_surface(state, wl_surface);
128+
129+
struct mako_notification *notif;
130+
const struct mako_binding_context ctx = {
131+
.surface = seat->touch.pts[id].surface,
132+
.seat = seat,
133+
.serial = serial,
134+
};
135+
wl_list_for_each(notif, &state->notifications, link) {
136+
if (hotspot_at(&notif->hotspot, seat->touch.pts[id].x, seat->touch.pts[id].y)) {
137+
notification_handle_touch_start(notif, &ctx);
138+
}
139+
}
127140
}
128141

129142
static void touch_handle_up(void *data, struct wl_touch *wl_touch,
@@ -768,7 +781,7 @@ static const struct xdg_activation_token_v1_listener activation_token_listener =
768781
char *create_xdg_activation_token(struct mako_surface *surface,
769782
struct mako_seat *seat, uint32_t serial) {
770783
struct mako_state *state = seat->state;
771-
if (state->xdg_activation == NULL) {
784+
if (state->xdg_activation == NULL || surface->surface == NULL) {
772785
return NULL;
773786
}
774787

0 commit comments

Comments
 (0)