Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions dunstrc
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,14 @@
# * close_all: Close all notifications.
# * context: Open context menu for the notification.
# * context_all: Open context menu for all notifications.
# * mouse_scroll_script: Run script on rule section based on button pressed
# These values can be strung together for each mouse event, and
# will be executed in sequence.
mouse_left_click = close_current
mouse_middle_click = do_action, close_current
mouse_right_click = close_all
mouse_scroll_up = mouse_scroll_script
mouse_scroll_down = mouse_scroll_script

# Experimental features that may or may not work correctly. Do not expect them
# to have a consistent behaviour across releases.
Expand Down Expand Up @@ -401,6 +404,8 @@
# alignment
# hide_text
# override_pause_level
# script_scroll_up
# script_scroll_down
#
# Shell-like globbing will get expanded.
#
Expand Down Expand Up @@ -493,4 +498,8 @@
# appname = "some_volume_notifiers"
# set_stack_tag = "volume"
#
#[volume-changer]
# appname = "some_volume_notifiers"
# script_scroll_up = some_volum_change_up_script
# script_scroll_down = some_volum_change_down_script
# vim: ft=cfg
18 changes: 16 additions & 2 deletions src/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#define BTN_RIGHT (0x111)
#define BTN_MIDDLE (0x112)
#define BTN_TOUCH (0x14a)
#define BTN_FORWARD (0x115)
#define BTN_BACK (0x116)
#endif

int get_notification_clickable_height(struct notification *n, bool first, bool last)
Expand Down Expand Up @@ -79,6 +81,12 @@ void input_handle_click(unsigned int button, bool button_down, int mouse_x, int
// TODO Add separate action for touch
acts = settings.mouse_left_click;
break;
case BTN_FORWARD:
acts = settings.mouse_scroll_up;
break;
case BTN_BACK:
acts = settings.mouse_scroll_down;
break;
default:
LOG_W("Unsupported mouse button: '%d'", button);
return;
Expand All @@ -97,16 +105,22 @@ void input_handle_click(unsigned int button, bool button_down, int mouse_x, int
continue;
}

if (act == MOUSE_DO_ACTION || act == MOUSE_CLOSE_CURRENT || act == MOUSE_CONTEXT || act == MOUSE_OPEN_URL) {
if (act == MOUSE_DO_ACTION || act == MOUSE_CLOSE_CURRENT || act == MOUSE_CONTEXT || act == MOUSE_OPEN_URL || act== MOUSE_SCROLL_SCRIPT) {
struct notification *n = get_notification_at(mouse_y);

if (n) {
if (act == MOUSE_CLOSE_CURRENT) {
n->marked_for_closure = REASON_USER;
} else if (act == MOUSE_DO_ACTION) {
notification_do_action(n);
} else if (act == MOUSE_OPEN_URL) {
notification_open_url(n);
} else if (act == MOUSE_SCROLL_SCRIPT){
Copy link
Member

Choose a reason for hiding this comment

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

could you please properly indent this? we leave a space between if and (
also spaces between == and commas. but the content seems right

if(button==BTN_FORWARD){
notification_invoke_script_rule(n,MOUSE_ACTION_SCROLL_UP);
}
else if(button==BTN_BACK){
notification_invoke_script_rule(n,MOUSE_ACTION_SCROLL_DOWN);
}
} else {
notification_open_context_menu(n);
}
Expand Down
54 changes: 51 additions & 3 deletions src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,30 @@ void notification_print(const struct notification *n)
}
printf("\n");
}
printf("\tscript_mouse_forward_count: %d\n", n->script_scroll_up_count);
if (n->script_scroll_up_count > 0) {
printf("\tscripts_mf: ");
for (int i = 0; i < n->script_scroll_up_count; i++) {
printf("'%s' ", STR_NN(n->script_scroll_up[i]));
}
printf("\n");
}
printf("\tscript_mouse_back_count: %d\n", n->script_scroll_down_count);
if (n->script_scroll_down_count > 0) {
printf("\tscripts_mb: ");
for (int i = 0; i < n->script_scroll_down_count; i++) {
printf("'%s' ", STR_NN(n->script_scroll_down[i]));
}
printf("\n");
}
printf("}\n");
fflush(stdout);
}

/* see notification.h */
void notification_run_script(struct notification *n)
{

Copy link
Member

Choose a reason for hiding this comment

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

this newline seems unnecessary

if (n->script_run && !settings.always_run_script)
return;

Expand All @@ -126,10 +143,33 @@ void notification_run_script(struct notification *n)
const char *icon = n->iconname ? n->iconname : "";

const char *urgency = notification_urgency_to_string(n->urgency);
int script_count = 0;
switch(n->script_choice){
case MOUSE_ACTION_SCROLL_UP:
script_count = n->script_scroll_up_count;
break;
case MOUSE_ACTION_SCROLL_DOWN:
script_count = n->script_scroll_down_count;
break;
default:
script_count = n->script_count;
break;
}

for(int i = 0; i < n->script_count; i++) {
for(int i = 0; i < script_count; i++) {

const char *script = n->scripts[i];
const char *script;
Copy link
Member

Choose a reason for hiding this comment

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

i am not sure about this behaviour. script specified with always_run_script should run even if you use a button I think.
is there a reason for this structure of the code?

switch(n->script_choice){
case MOUSE_ACTION_SCROLL_UP:
script = n->script_scroll_up[i];
break;
case MOUSE_ACTION_SCROLL_DOWN:
script = n->script_scroll_down[i];
break;
default:
script = n->scripts[i];
break;
}

if (STR_EMPTY(script))
continue;
Expand Down Expand Up @@ -173,7 +213,7 @@ void notification_run_script(struct notification *n)
urgency,
(char *)NULL);

LOG_W("Unable to run script %s: %s", n->scripts[i], strerror(errno));
LOG_W("Unable to run script %s: %s", script, strerror(errno));
exit(EXIT_FAILURE);
}
}
Expand Down Expand Up @@ -526,6 +566,8 @@ void notification_init(struct notification *n)
gradient_release(n->colors.highlight);
n->colors.highlight = gradient_acquire(defcolors.highlight);
}
/*Script setup*/
n->script_choice = MOUSE_ACTION_OTHERS;

/* Sanitize misc hints */
if (n->progress < 0)
Expand Down Expand Up @@ -806,6 +848,12 @@ void notification_open_context_menu(struct notification *n)
context_menu_for(notifications);
}

void notification_invoke_script_rule(struct notification *n,enum mouse_action_type act){
n->script_choice = act;
notification_run_script(n);
}


void notification_invalidate_actions(struct notification *n) {
g_hash_table_remove_all(n->actions);
}
Expand Down
21 changes: 20 additions & 1 deletion src/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <stdbool.h>
#include <pango/pango-layout.h>
#include <cairo.h>

#include "markup.h"
#include "draw.h"

Expand All @@ -19,6 +18,12 @@ enum icon_position {
ICON_OFF
};

enum mouse_action_type{
MOUSE_ACTION_OTHERS=0,
Copy link
Member

Choose a reason for hiding this comment

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

=0 is unnecessary

MOUSE_ACTION_SCROLL_UP,
MOUSE_ACTION_SCROLL_DOWN,
};

enum behavior_fullscreen {
FS_NULL, //!< Invalid value
FS_DELAY, //!< Delay the notification until leaving fullscreen mode
Expand Down Expand Up @@ -86,8 +91,17 @@ struct notification {

enum markup_mode markup;
char *format;

enum mouse_action_type script_choice;
Copy link
Member

Choose a reason for hiding this comment

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

rather than having this choice variable inside notification I would rather add mouse_action parameter to run_script function. this seems a bit more clean and you don't risk forgetting to set the type of action beforehand

char **scripts;
int script_count;

char **script_scroll_up;
int script_scroll_up_count;

char **script_scroll_down;
int script_scroll_down_count;

struct notification_colors colors;

char *stack_tag; /**< stack notifications by tag */
Expand Down Expand Up @@ -252,6 +266,11 @@ void notification_open_url(struct notification *n);
*/
void notification_open_context_menu(struct notification *n);

/**
* Run script provided inside rules for different mouse actions
*/
void notification_invoke_script_rule(struct notification *n,enum mouse_action_type act);

/**
* Remove all client action data from the notification.
*
Expand Down
26 changes: 26 additions & 0 deletions src/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,28 @@ void rule_apply(struct rule *r, struct notification *n, bool save)
n->scripts[n->script_count + 1] = NULL;
n->script_count++;
}
if (r->script_scroll_up) {
if (save && n->original->script_scroll_up == NULL)
n->original->script_scroll_up = n->script_scroll_up_count > 0
? g_strdup(n->script_scroll_up[0])
: g_strdup(r->script);

n->script_scroll_up = g_renew(char *, n->script_scroll_up, n->script_scroll_up_count + 2);
n->script_scroll_up[n->script_scroll_up_count] = g_strdup(r->script_scroll_up);
n->script_scroll_up[n->script_scroll_up_count + 1] = NULL;
n->script_scroll_up_count++;
}
if (r->script_scroll_down) {
if (save && n->original->script_scroll_down == NULL)
n->original->script_scroll_down = n->script_scroll_down_count > 0
? g_strdup(n->script_scroll_down[0])
: g_strdup(r->script);

n->script_scroll_down = g_renew(char *, n->script_scroll_down, n->script_scroll_down_count + 2);
n->script_scroll_down[n->script_scroll_down_count] = g_strdup(r->script_scroll_down);
n->script_scroll_down[n->script_scroll_down_count + 1] = NULL;
n->script_scroll_down_count++;
}
}

void rule_print(const struct rule *r)
Expand Down Expand Up @@ -185,6 +207,8 @@ void rule_print(const struct rule *r)
if (r->set_category != NULL) printf("\tset_category: '%s'\n", r->set_category);
if (r->format != NULL) printf("\tformat: '%s'\n", r->format);
if (r->script != NULL) printf("\tscript: '%s'\n", r->script);
if (r->script_scroll_up != NULL) printf("\tscript_scroll_up: '%s'\n", r->script_scroll_up);
if (r->script_scroll_down != NULL) printf("\tscript_scroll_down: '%s'\n", r->script_scroll_down);
if (r->fullscreen != FS_NULL) printf("\tfullscreen: %s\n", enum_to_string_fullscreen(r->fullscreen));
if (r->progress_bar_alignment != -1) printf("\tprogress_bar_alignment: %d\n", r->progress_bar_alignment);
if (r->set_stack_tag != NULL) printf("\tset_stack_tag: %s\n", r->set_stack_tag);
Expand Down Expand Up @@ -265,6 +289,8 @@ void rule_free(struct rule *r)
g_free(r->set_category);
g_free(r->format);
g_free(r->script);
g_free(r->script_scroll_down);
g_free(r->script_scroll_up);
g_free(r->set_stack_tag);

g_free(r);
Expand Down
2 changes: 2 additions & 0 deletions src/rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ struct rule {
char *set_category;
char *format;
char *script;
char *script_scroll_up;
char *script_scroll_down;
enum behavior_fullscreen fullscreen;
bool enabled;
int progress_bar_alignment;
Expand Down
2 changes: 2 additions & 0 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ void settings_free(struct settings *s)
g_free(s->mouse_left_click);
g_free(s->mouse_middle_click);
g_free(s->mouse_right_click);
g_free(s->mouse_scroll_down);
g_free(s->mouse_scroll_up);

g_free(s->close_ks.str);
g_free(s->close_all_ks.str);
Expand Down
3 changes: 3 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum separator_color { SEP_FOREGROUND, SEP_AUTO, SEP_FRAME, SEP_CUSTOM };
enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD };
enum mouse_action { MOUSE_NONE, MOUSE_DO_ACTION, MOUSE_CLOSE_CURRENT,
MOUSE_CLOSE_ALL, MOUSE_CONTEXT, MOUSE_CONTEXT_ALL, MOUSE_OPEN_URL,
MOUSE_SCROLL_SCRIPT,
MOUSE_ACTION_END = LIST_END /* indicates the end of a list of mouse actions */};
#ifndef ZWLR_LAYER_SHELL_V1_LAYER_ENUM
#define ZWLR_LAYER_SHELL_V1_LAYER_ENUM
Expand Down Expand Up @@ -160,6 +161,8 @@ struct settings {
enum mouse_action *mouse_left_click;
enum mouse_action *mouse_middle_click;
enum mouse_action *mouse_right_click;
enum mouse_action *mouse_scroll_up;
enum mouse_action *mouse_scroll_down;
int progress_bar_height;
int progress_bar_min_width;
int progress_bar_max_width;
Expand Down
43 changes: 43 additions & 0 deletions src/settings_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ static const struct string_to_enum_def mouse_action_enum_data[] = {
{"context", MOUSE_CONTEXT },
{"context_all", MOUSE_CONTEXT_ALL },
{"open_url", MOUSE_OPEN_URL },
{"mouse_scroll_script", MOUSE_SCROLL_SCRIPT },
ENUM_END,
};

Expand Down Expand Up @@ -519,6 +520,28 @@ static const struct setting allowed_settings[] = {
.parser_data = NULL,
.rule_offset = offsetof(struct rule, script),
},
{
.name = "script_scroll_up",
.section = "*",
.description = "script for mouse scroll up",
.type = TYPE_PATH,
.default_value = "*",
.value = NULL,
.parser = NULL,
.parser_data = NULL,
.rule_offset = offsetof(struct rule, script_scroll_up),
},
{
.name = "script_scroll_down",
.section = "*",
.description = "script for mouse scroll down",
.type = TYPE_PATH,
.default_value = "*",
.value = NULL,
.parser = NULL,
.parser_data = NULL,
.rule_offset = offsetof(struct rule, script_scroll_down),
},
{
.name = "background",
.section = "*",
Expand Down Expand Up @@ -1321,6 +1344,26 @@ static const struct setting allowed_settings[] = {
.parser = NULL,
.parser_data = GINT_TO_POINTER(MOUSE_LIST),
},
{
.name = "mouse_scroll_up",
.section = "global",
.description = "Action of right click event",
.type = TYPE_LIST,
.default_value = "mouse_scroll_script",
.value = &settings.mouse_scroll_up,
.parser = NULL,
.parser_data = GINT_TO_POINTER(MOUSE_LIST),
},
{
.name = "mouse_scroll_down",
.section = "global",
.description = "Action of right click event",
Copy link
Member

Choose a reason for hiding this comment

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

please update the description. also of scroll_up

.type = TYPE_LIST,
.default_value = "mouse_scroll_script",
.value = &settings.mouse_scroll_down,
.parser = NULL,
.parser_data = GINT_TO_POINTER(MOUSE_LIST),
},
{
.name = "icon_theme",
.section = "global",
Expand Down
6 changes: 6 additions & 0 deletions src/x11/x.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#define BTN_RIGHT (0x111)
#define BTN_MIDDLE (0x112)
#define BTN_TOUCH (0x14a)
#define BTN_FORWARD (0x115)
Copy link
Member

Choose a reason for hiding this comment

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

maybe is better to change this as well to SCROLL_UP / SCROLL_DOWN ?
because there are the lateral mouse buttons called forward and backward and it could cause confusion eventually?

#define BTN_BACK (0x116)
#endif

#include "../dbus.h"
Expand Down Expand Up @@ -427,6 +429,10 @@ static unsigned int x_mouse_button_to_linux_event_code(unsigned int x_button)
return BTN_MIDDLE;
case Button3:
return BTN_RIGHT;
case Button4:
return BTN_FORWARD;
case Button5:
return BTN_BACK;
default:
LOG_W("Unsupported mouse button: '%d'", x_button);
return 0;
Expand Down