dotfiles/pkgs/mako/0002-consider-long-press-done-even-before-release.patch

152 lines
4.9 KiB
Diff
Raw Normal View History

From 7365261e130016e884371d2e288b83e16a9dcb48 Mon Sep 17 00:00:00 2001
From: chayleaf <chayleaf-git@pavluk.org>
Date: Sat, 24 Aug 2024 13:50:38 +0700
Subject: [PATCH 2/5] consider long press done even before release
---
include/notification.h | 16 ++++++++++------
include/wayland.h | 1 +
notification.c | 22 ++++++++++++++++++++++
wayland.c | 15 ++++++++++++++-
4 files changed, 47 insertions(+), 7 deletions(-)
diff --git a/include/notification.h b/include/notification.h
index a02d855..b1482ec 100644
--- a/include/notification.h
+++ b/include/notification.h
@@ -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;
@@ -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;
@@ -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);
@@ -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,
diff --git a/include/wayland.h b/include/wayland.h
index c8767be..d4d39c4 100644
--- a/include/wayland.h
+++ b/include/wayland.h
@@ -3,6 +3,7 @@
#include <stdbool.h>
#include <wayland-client-protocol.h>
+#include "mako.h"
#define MAX_TOUCHPOINTS 10
diff --git a/notification.c b/notification.c
index 7d3db2f..32e7f7b 100644
--- a/notification.c
+++ b/notification.c
@@ -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);
@@ -447,6 +449,8 @@ 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 {
@@ -454,6 +458,24 @@ void notification_handle_touch(struct mako_notification *notif,
}
}
+void handle_notification_touch_timer(void *data) {
+ struct mako_notification *notif = data;
+ notif->long_press_timer = NULL;
+ struct mako_binding_context ctx = notif->long_press_ctx;
+ notification_execute_binding(notif, &notif->style.long_touch_binding, &ctx);
+ set_dirty(ctx.surface);
+}
+
+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;
+ notif->long_press_timer = 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,
diff --git a/wayland.c b/wayland.c
index d247779..6d8b6ff 100644
--- a/wayland.c
+++ b/wayland.c
@@ -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,
--
2.45.2