Skip to content

Commit

Permalink
(wip) consider long press done even before release
Browse files Browse the repository at this point in the history
  • Loading branch information
chayleaf committed Aug 24, 2024
1 parent 85bbcf7 commit f0563b7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
16 changes: 10 additions & 6 deletions include/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ struct mako_hotspot {
int32_t width, height;
};

struct mako_binding_context {
struct mako_surface *surface;
struct mako_seat *seat;
uint32_t serial;
};

struct mako_notification {
struct mako_state *state;
struct mako_surface *surface;
Expand All @@ -38,6 +44,8 @@ struct mako_notification {
char *body;
int32_t requested_timeout;
struct wl_list actions; // mako_action::link
struct mako_timer *long_press_timer;
struct mako_binding_context long_press_ctx;

enum mako_notification_urgency urgency;
char *category;
Expand Down Expand Up @@ -70,12 +78,6 @@ struct mako_hidden_format_data {
size_t count;
};

struct mako_binding_context {
struct mako_surface *surface;
struct mako_seat *seat;
uint32_t serial;
};

typedef char *(*mako_format_func_t)(char variable, bool *markup, void *data);

bool hotspot_at(struct mako_hotspot *hotspot, int32_t x, int32_t y);
Expand All @@ -100,6 +102,8 @@ 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, const struct mako_binding_context *ctx);
void notification_handle_touch_start(struct mako_notification *notif,
const struct mako_binding_context *ctx);
void notification_handle_touch(struct mako_notification *notif,
const struct mako_binding_context *ctx, int32_t duration_ms);
void notification_execute_binding(struct mako_notification *notif,
Expand Down
1 change: 1 addition & 0 deletions include/wayland.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <stdbool.h>
#include <wayland-client-protocol.h>
#include "mako.h"

#define MAX_TOUCHPOINTS 10

Expand Down
27 changes: 27 additions & 0 deletions notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ void reset_notification(struct mako_notification *notif) {

destroy_timer(notif->timer);
notif->timer = NULL;
destroy_timer(notif->long_press_timer);
notif->long_press_timer = NULL;

free(notif->app_name);
free(notif->app_icon);
Expand Down Expand Up @@ -447,13 +449,38 @@ void notification_handle_button(struct mako_notification *notif, uint32_t button

void notification_handle_touch(struct mako_notification *notif,
const struct mako_binding_context *ctx, int32_t duration_ms) {
destroy_timer(notif->long_press_timer);
notif->long_press_timer = NULL;
if (duration_ms >= notif->style.long_press_duration) {
notification_execute_binding(notif, &notif->style.long_touch_binding, ctx);
} else {
notification_execute_binding(notif, &notif->style.touch_binding, ctx);
}
}

void handle_notification_touch_timer(void *data) {
struct mako_notification *notif = data;
notif->long_press_timer = NULL;
notif->long_press_ctx.surface = notif->surface;
const struct mako_binding_context *ctx = &notif->long_press_ctx;
if (notif->surface) {
set_dirty(notif->surface);
} else {
ctx = NULL;
}
notification_execute_binding(notif, &notif->style.long_touch_binding, ctx);
}

void notification_handle_touch_start(struct mako_notification *notif,
const struct mako_binding_context *ctx) {
if (notif->long_press_timer) {
return;
}
notif->long_press_ctx = *ctx;
add_event_loop_timer(&notif->state->event_loop, 500,
handle_notification_touch_timer, notif);
}

/*
* 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
17 changes: 15 additions & 2 deletions wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,23 @@ static void touch_handle_down(void *data, struct wl_touch *wl_touch,
if (id >= MAX_TOUCHPOINTS) {
return;
}
struct mako_state *state = seat->state;
seat->touch.pts[id].x = wl_fixed_to_int(surface_x);
seat->touch.pts[id].y = wl_fixed_to_int(surface_y);
seat->touch.pts[id].time = time;
seat->touch.pts[id].surface = get_surface(seat->state, wl_surface);
seat->touch.pts[id].surface = get_surface(state, wl_surface);

struct mako_notification *notif;
const struct mako_binding_context ctx = {
.surface = seat->touch.pts[id].surface,
.seat = seat,
.serial = serial,
};
wl_list_for_each(notif, &state->notifications, link) {
if (hotspot_at(&notif->hotspot, seat->touch.pts[id].x, seat->touch.pts[id].y)) {
notification_handle_touch_start(notif, &ctx);
}
}
}

static void touch_handle_up(void *data, struct wl_touch *wl_touch,
Expand Down Expand Up @@ -768,7 +781,7 @@ static const struct xdg_activation_token_v1_listener activation_token_listener =
char *create_xdg_activation_token(struct mako_surface *surface,
struct mako_seat *seat, uint32_t serial) {
struct mako_state *state = seat->state;
if (state->xdg_activation == NULL) {
if (state->xdg_activation == NULL || surface->surface == NULL) {
return NULL;
}

Expand Down

0 comments on commit f0563b7

Please sign in to comment.