Skip to content

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

leyuskckiran1510
Copy link

@leyuskckiran1510 leyuskckiran1510 commented Jun 21, 2025

Adds mouse scroll action scripting to the notification,

how to use it

  • add mouse action mouse_scroll_forward = forward_script as and mouse_scroll_backward = back_script [optional as it's by default]
  • now add your costume rule to trigger for notification in your dunstrc;
# a example 
[volume]
    sumamry = "changevolume"
    script_mouse_forward = change_vup
    script_mouse_back = change_vdown

[note:- script_mouse_forward/back takes single word script to run, you cannot put long script their, make a file of the script you want to execute, and give it a simple single word name and add that to path, do not forget to add executable flag chmod +x my_script ]

  • now you can do something like dunstify "changevolume" "volume=10%"
  • now if you hover to that notification and scroll with mouse wheel, your script should be triggred

why we need this

  • this allows us to control linear actions, through our mouse wheel, instead of just clicking on mouse.
  • this opens ups the possibility of triggering actions, when needed, for example if you have a setup which warns if volume it to high. You can just use mouse wheel to change the volume.

TODOS:

  • if this concept is liked my many, we can also add feature like script_mouse_click1/2/3
  • so that we can execute different set of scripts for different mouse action

Closes #1490

@leyuskckiran1510
Copy link
Author

demo video

output.mp4

@bynect
Copy link
Member

bynect commented Jun 22, 2025

hello. thank you for the contribution. I like the idea however there are some things we might improve. I am busy right now so I will just leave some initial review. also please fix the errors

dunstrc Outdated
# 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_forward = forward_script
mouse_scroll_backward = back_script
Copy link
Member

Choose a reason for hiding this comment

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

a more standard way to say this is scroll up/down

Copy link
Author

@leyuskckiran1510 leyuskckiran1510 Jun 23, 2025

Choose a reason for hiding this comment

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

okay will make those changes tonight and push it, I tried to follow the convention of x11 constant for mouse button, will make those changes

@leyuskckiran1510
Copy link
Author

hello. thank you for the contribution. I like the idea however there are some things we might improve. I am busy right now so I will just leave some initial review. also please fix the errors

about the error, their seems to be memory leak issue in my code, will fix those issues to, thank you

@leyuskckiran1510
Copy link
Author

hello. thank you for the contribution. I like the idea however there are some things we might improve. I am busy right now so I will just leave some initial review. also please fix the errors

about the error, their seems to be memory leak issue in my code, will fix those issues to, thank you

i am working on, it will update when I am done, rn now busy with other stuffs

@bynect
Copy link
Member

bynect commented Jun 24, 2025

dont worry. let me know when its ready for review

@leyuskckiran1510
Copy link
Author

@bynect could you rerun the workflow, I think the leak was due the mouse_script_scroll not being freed, I think the last commits solves the issue. Could you verify that and let me know if that fixes

@codecov-commenter
Copy link

codecov-commenter commented Jun 27, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 16.25000% with 67 lines in your changes missing coverage. Please review.

Project coverage is 64.49%. Comparing base (fb59a30) to head (15bef64).

Files with missing lines Patch % Lines
src/notification.c 17.50% 33 Missing ⚠️
src/rules.c 18.18% 18 Missing ⚠️
src/input.c 0.00% 12 Missing ⚠️
src/x11/x.c 0.00% 4 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1489      +/-   ##
==========================================
- Coverage   64.90%   64.49%   -0.42%     
==========================================
  Files          51       51              
  Lines        9024     9100      +76     
  Branches     1048     1065      +17     
==========================================
+ Hits         5857     5869      +12     
- Misses       3167     3231      +64     
Flag Coverage Δ
unittests 64.49% <16.25%> (-0.42%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leyuskckiran1510
Copy link
Author

@bynect Do i need to make 100% code coverage too ? or the task here is done for me.
Please do let me know on changes required.

@bynect
Copy link
Member

bynect commented Jul 7, 2025

Sorry right now I can't review

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

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

@@ -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

@@ -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

@@ -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?

{
.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


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?

@bynect
Copy link
Member

bynect commented Jul 9, 2025

I left a review. mostly it is formatting. but there are some architecture changes I suggest. let me know what do you think

@leyuskckiran1510
Copy link
Author

I left a review. mostly it is formatting. but there are some architecture changes I suggest. let me know what do you think

okay I will make those changes and let you know, thank you for the time to review the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add mouse action scripting to dunst notifications.
3 participants