Skip to content

Commit

Permalink
add on-long-touch option
Browse files Browse the repository at this point in the history
  • Loading branch information
chayleaf committed Aug 24, 2024
1 parent 4d48aca commit 85bbcf7
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 8 deletions.
21 changes: 21 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ void init_default_style(struct mako_style *style) {
style->button_bindings.right.action = MAKO_BINDING_DISMISS;
style->button_bindings.middle.action = MAKO_BINDING_NONE;
style->touch_binding.action = MAKO_BINDING_DISMISS;
style->long_touch_binding.action = MAKO_BINDING_INVOKE_ACTION;
style->long_touch_binding.action_name = strdup(DEFAULT_ACTION_KEY);
style->long_press_duration = 500;

// Everything in the default config is explicitly specified.
memset(&style->spec, true, sizeof(struct mako_style_spec));
Expand All @@ -148,6 +151,7 @@ void finish_style(struct mako_style *style) {
finish_binding(&style->button_bindings.middle);
finish_binding(&style->button_bindings.right);
finish_binding(&style->touch_binding);
finish_binding(&style->long_touch_binding);
finish_binding(&style->notify_binding);
free(style->icon_path);
free(style->font);
Expand Down Expand Up @@ -385,6 +389,16 @@ bool apply_style(struct mako_style *target, const struct mako_style *style) {
target->spec.touch_binding = true;
}

if (style->spec.long_touch_binding) {
copy_binding(&target->long_touch_binding, &style->long_touch_binding);
target->spec.long_touch_binding = true;
}

if (style->spec.long_press_duration) {
target->long_press_duration = style->long_press_duration;
target->spec.long_press_duration = true;
}

if (style->spec.notify_binding) {
copy_binding(&target->notify_binding, &style->notify_binding);
target->spec.notify_binding = true;
Expand Down Expand Up @@ -660,6 +674,8 @@ static bool apply_style_option(struct mako_style *style, const char *name,
return true;
} else if (strcmp(name, "anchor") == 0) {
return spec->anchor = parse_anchor(value, &style->anchor);
} else if (strcmp(name, "long-press-duration") == 0) {
return spec->long_press_duration = parse_int_ge(value, &style->long_press_duration, 0);
} else if (has_prefix(name, "on-")) {
struct mako_binding binding = {0};
if (strcmp(value, "none") == 0) {
Expand Down Expand Up @@ -697,6 +713,9 @@ static bool apply_style_option(struct mako_style *style, const char *name,
} else if (strcmp(name, "on-touch") == 0) {
copy_binding(&style->touch_binding, &binding);
style->spec.touch_binding = true;
} else if (strcmp(name, "on-long-touch") == 0) {
copy_binding(&style->long_touch_binding, &binding);
style->spec.long_touch_binding = true;
} else if (strcmp(name, "on-notify") == 0) {
copy_binding(&style->notify_binding, &binding);
style->spec.notify_binding = true;
Expand Down Expand Up @@ -886,6 +905,8 @@ int parse_config_arguments(struct mako_config *config, int argc, char **argv) {
{"on-button-right", required_argument, 0, 0},
{"on-button-middle", required_argument, 0, 0},
{"on-touch", required_argument, 0, 0},
{"on-long-touch", required_argument, 0, 0},
{"long-press-duration", required_argument, 0, 0},
{0},
};

Expand Down
15 changes: 14 additions & 1 deletion doc/mako.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,23 @@ Supported options:
Default: dismiss

*on-touch*=_action_
Performs the action when tapped via a touch device.
Performs the action when tapped via a touch device if the tap
duration is less than *long-press-duration*.

Default: dismiss

*on-long-touch*=_action_
Performs the action when tapped via a touch device if the press
duration is greater or equal to *long-press-duration*.

Default: invoke-default-action

*long-press-duration*=_time_
Specifies the cutoff time (in milliseconds) for a press to be
considered a long press.

Default: 500

*on-notify*=_action_
Performs the action when the notification is opened.

Expand Down
7 changes: 4 additions & 3 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ struct mako_style_spec {
bool width, height, outer_margin, margin, padding, border_size, border_radius, font,
markup, format, text_alignment, actions, default_timeout, ignore_timeout,
icons, max_icon_size, icon_path, group_criteria_spec, invisible, history,
icon_location, max_visible, layer, output, anchor;
icon_location, max_visible, layer, output, anchor, long_press_duration;
struct {
bool background, text, border, progress;
} colors;
struct {
bool left, right, middle;
} button_bindings;
bool touch_binding, notify_binding;
bool touch_binding, long_touch_binding, notify_binding;
};


Expand Down Expand Up @@ -98,7 +98,8 @@ struct mako_style {
struct {
struct mako_binding left, right, middle;
} button_bindings;
struct mako_binding touch_binding, notify_binding;
struct mako_binding touch_binding, long_touch_binding, notify_binding;
int32_t long_press_duration;
};

struct mako_config {
Expand Down
2 changes: 1 addition & 1 deletion include/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ size_t format_notification(struct mako_notification *notif, const char *format,
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(struct mako_notification *notif,
const struct mako_binding_context *ctx);
const struct mako_binding_context *ctx, int32_t duration_ms);
void notification_execute_binding(struct mako_notification *notif,
const struct mako_binding *binding, const struct mako_binding_context *ctx);
void insert_notification(struct mako_state *state, 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 @@ -35,6 +35,7 @@ struct mako_seat {
struct wl_touch *wl_touch;
struct {
int32_t x, y;
uint32_t time;
struct mako_surface *surface;
} pts[MAX_TOUCHPOINTS];
} touch;
Expand Down
8 changes: 6 additions & 2 deletions notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,12 @@ 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) {
notification_execute_binding(notif, &notif->style.touch_binding, ctx);
const struct mako_binding_context *ctx, int32_t duration_ms) {
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);
}
}

/*
Expand Down
3 changes: 2 additions & 1 deletion wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ static void touch_handle_down(void *data, struct wl_touch *wl_touch,
}
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);
}

Expand All @@ -144,7 +145,7 @@ static void touch_handle_up(void *data, struct wl_touch *wl_touch,
wl_list_for_each(notif, &state->notifications, link) {
if (hotspot_at(&notif->hotspot, seat->touch.pts[id].x, seat->touch.pts[id].y)) {
struct mako_surface *surface = notif->surface;
notification_handle_touch(notif, &ctx);
notification_handle_touch(notif, &ctx, time - seat->touch.pts[id].time);
set_dirty(surface);
break;
}
Expand Down

0 comments on commit 85bbcf7

Please sign in to comment.