Skip to content
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

#65 add ON_CHANGE_CMD to run a shell command in handle_success #162

Merged
merged 21 commits into from
Apr 20, 2024

Conversation

PaideiaDilemma
Copy link
Contributor

@PaideiaDilemma PaideiaDilemma commented Apr 2, 2024

Hi!

This tries to implement a configuration that allows users to execute an arbitrary command when display configurations change. The command gets executed in handle_success, so when the succeeded event gets fired and is processed by way-displays. This is also how kanshi implements it.

Here are some things to discuss:

  • The name "ON_CHANGE_CMD" as suggested in Feature: Run shell command on display change detected #65 is quite easy to understand so I went with that. But maybe something like "CHANGE_SUCCESS_CMD" or something different is preferable, because it is kind of a "AFTER_CHANGE_CMD" :D.
  • The test uses the filesystem because I could not come up with another good solution to check command execution. spawn_async is not tested at all, because it is hard to test. Is that fine?
  • Do we need IPC for this?

Additional note for hyprland:
Hyprland currently does not play well and way-displays needs to handle multiple redundant events, so the command might get executed a few times on a change. I might look into that when I have time. Only gets executed once on sway.
Havn't tried other compositors, but that's why I added the note in cfg.yaml.

@alex-courtis
Copy link
Owner

This looks great! I test and review this on Monday.

@alex-courtis
Copy link
Owner

Looks like you might need to assert the new INFO message during the layout test: https://github.com/alex-courtis/way-displays/actions/runs/8529996247/job/23510275263?pr=162#step:6:332

@alex-courtis
Copy link
Owner

alex-courtis commented Apr 9, 2024

This tries to implement a configuration that allows users to execute an arbitrary command when display configurations change. The command gets executed in handle_success, so when the succeeded event gets fired and is processed by way-displays. This is also how kanshi implements it.

Definitely works. ON_CHANGE_CMD: 'notify-send "$(way-displays -g)"' does what you'd think.

valgrinds successfully for happy path.

Additional note for hyprland:
Hyprland currently does not play well and way-displays needs to handle multiple redundant events, so the command might get executed a few times on a change. I might look into that when I have time. Only gets executed once on sway.
Havn't tried other compositors, but that's why I added the note in cfg.yaml.

Yes, there's nothing we can do about that. We'll also get multiple events for multi-stage changes e.g. mode set, then vrr, then scale.

I think we can make use of that - notifications of successive changes and the fail.

@alex-courtis
Copy link
Owner

  • spawn_async is not tested at all, because it is hard to test. Is that fine?

That's completely fine, you've tested the invocations. It's definitely async and works.

ON_CHANGE_CMD: 'sleep 10'

@alex-courtis
Copy link
Owner

alex-courtis commented Apr 9, 2024

Do we need IPC for this?

Not quite sure what you're asking, however we could add feedback so that the user has something to go with.

Perhaps the ability to send a notify message like:

eDP-1 Changing:
  from:
    scale:     2.000 (2.213)
    size:      1280x720
    position:  0,0
    mode:      2560x1440@60Hz (59,998mHz) (preferred)
    VRR:       off
  to:
    scale:     1.000

We could dump that text to a file like /tmp/way-displays/change.20240409_145421.txt

The user could set something like this to retrieve that file:

ON_CHANGE_CMD: 'notify-send way-displays "$(cat ${WD_CHANGE_FILE})"'
# or
ON_CHANGE_CMD: 'notify-send way-displays "$(cat %%wd_change_file%%)"'

What do you think?

Copy link
Owner

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

This is looking fantastic! Please:

  • add to way-displays -g; adding it to info.c should propagate it everywhere
  • add CLI set and delete commands

@alex-courtis
Copy link
Owner

  • But maybe something like "CHANGE_SUCCESS_CMD" or something different is preferable, because it is kind of a "AFTER_CHANGE_CMD" :D.

Great potential there: CHANGE_FAILED_CMD CHANGE_CANCELLED_CMD.

Let's get the success cases nailed down first.

@PaideiaDilemma
Copy link
Contributor Author

Do we need IPC for this?

I meant set and delete via the cli.
I will do that today :)

Regarding the suggestion about something like a WD_CHANGE_FILE.

I think that would be great and I would be down to implement that.
Do you want me to do that in this PR or in a separate one?

@PaideiaDilemma
Copy link
Contributor Author

Let's get the success cases nailed down first.

Alright I agree. CHANGE_SUCCESS_CMD sounds good.
I will rename.

@alex-courtis
Copy link
Owner

Many thanks for the updates! I'll review them tomorrow or the day after.

FYI my availability for this project is Mon-Tue only.

@alex-courtis
Copy link
Owner

I think that would be great and I would be down to implement that.
Do you want me to do that in this PR or in a separate one?

Very sensible. This change is complete and can be merged.

@alex-courtis
Copy link
Owner

alex-courtis commented Apr 15, 2024

I spoke too soon; there is an odd memory leak reported. Looks like it's reported every loop, for libinput monitor and wl display connect.

I'll take a look...

valgrind --leak-check=full --show-leak-kinds=all --suppressions=/tmp/vg.supp way-displays > /tmp/wd.log 2>&1

wd.log

Bisected to cfbe233

Copy link
Owner

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Looking good, works.

  • simplify spawn
  • add help / man

Do you want me to push changes for help / man?

src/process.c Outdated Show resolved Hide resolved
src/layout.c Show resolved Hide resolved
- only fork once
- rename from spawn_async to spawn_sh_cmd
@PaideiaDilemma
Copy link
Contributor Author

PaideiaDilemma commented Apr 15, 2024

Thanks for the review.

add help / man

Do you want me to push changes for help / man?

Did that as well. Let me know if <shell command> is fine or not. I didn't just want to use <command>, since it is already used in the help text via "COMMAND" as in the command that way-displays should do.

@alex-courtis
Copy link
Owner

Did that as well. Let me know if <shell command> is fine or not. I didn't just want to use <command>, since it is already used in the help text via "COMMAND" as in the command that way-displays should do.

That works well - it's really clear what the user can execute.

Copy link
Owner

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

This is looking fantastic! I'm excited for all the opportunities this opens up.

Let's get that last child bit in and we're good to go.

We can release 1.11 and update the wiki, unless you'd prefer to add something else first.

src/process.c Outdated Show resolved Hide resolved
src/process.c Outdated Show resolved Hide resolved
@PaideiaDilemma
Copy link
Contributor Author

We can release 1.11 and update the wiki, unless you'd prefer to add something else first.

Sounds good!

Copy link
Owner

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Works beautifully - immediate spawn, no zombies, no complaints from valgrind.

Many thanks for your contribution! Hopefully we can work together on more such functionality #164

src/server.c Show resolved Hide resolved
@alex-courtis alex-courtis merged commit 5eb61e0 into alex-courtis:master Apr 20, 2024
1 check passed
@matthewwardrop
Copy link
Contributor

Woohoo! Thanks for working on this @PaideiaDilemma ; and for your consideration @alex-courtis !

@alex-courtis
Copy link
Owner

Thank you... I added a complex command: https://github.com/alex-courtis/way-displays/blob/master/examples/cfg.yaml#L70

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.

3 participants