-
Notifications
You must be signed in to change notification settings - Fork 361
feat: add mouse scroll action scripting to notificaiton #1489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
4fa0c13
403f579
9befcaf
e5dd87f
0547104
15bef64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
{ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
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; | ||
|
@@ -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); | ||
} | ||
} | ||
|
@@ -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) | ||
|
@@ -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); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
#include <stdbool.h> | ||
#include <pango/pango-layout.h> | ||
#include <cairo.h> | ||
|
||
#include "markup.h" | ||
#include "draw.h" | ||
|
||
|
@@ -19,6 +18,12 @@ enum icon_position { | |
ICON_OFF | ||
}; | ||
|
||
enum mouse_action_type{ | ||
leyuskckiran1510 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
MOUSE_ACTION_OTHERS=0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -86,8 +91,17 @@ struct notification { | |
|
||
enum markup_mode markup; | ||
char *format; | ||
|
||
enum mouse_action_type script_choice; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 */ | ||
|
@@ -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. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
}; | ||
|
||
|
@@ -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 = "*", | ||
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ | |
#define BTN_RIGHT (0x111) | ||
#define BTN_MIDDLE (0x112) | ||
#define BTN_TOUCH (0x14a) | ||
#define BTN_FORWARD (0x115) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? |
||
#define BTN_BACK (0x116) | ||
#endif | ||
|
||
#include "../dbus.h" | ||
|
@@ -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; | ||
|
There was a problem hiding this comment.
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