Alexays / Waybar

Highly customizable Wayland bar for Sway and Wlroots based compositors. :v: :tada:
MIT License
6.71k stars 710 forks source link

Get current screen in custom module #2821

Open ModProg opened 10 months ago

ModProg commented 10 months ago

I want to display a “Sharing Screen!” message on the screen I am currently sharing.

I have set up the necessary code to display a message when I'm sharing any screen, but I'd like to be able to only show it for the screen the current instance of waybar is displayed on (compare “sway/workspaces” for a similar behavior).

Could we have a variable one can use in custom.exec and custom.exec-if that contains the monitor of the waybar?

RobertMueller2 commented 10 months ago

Did you have a look at commit 0ea5143? This adds the output name in env var WAYBAR_OUTPUT_NAME when you use the exec command, at first glance at least in image and custom module.

It does not look like it's present for exec-if, although I have not tried that and could be mistaken. But you could check against it in your exec script, and perhaps just output nothing if it doesn't match?

jgarvin commented 6 months ago

@RobertMueller2 That env var doesn't seem to work, when I have a custom module exec a script to dump env > /tmp/envlog there are no WAYBAR_* env vars defined.

RobertMueller2 commented 6 months ago

@jgarvin it does work for me with the config below.

Might be a bit hard to see, but the script just echos the WAYBAR_TEST_OUTPUT on each of the screens.

satty-20240509-21:31:27

{
    "layer": "top", // Waybar at top layer
    "position": "top", // Waybar position (top|bottom|left|right)
    "height" : 50,
    "modules-center": ["custom/env"],

    "custom/env": {
      "format": "env:: {}",
      "format-alt": "env: {}",
      "exec": "/tmp/test-output.sh",
      "exec-on-event": false
    },
}

But I can't say if it's working with all possible configs. Would you mind sharing yours?

And which version you are using? This commit mentioned above is not included in 0.9.24 or earlier.

jgarvin commented 6 months ago

Ah I'm in 0.9.24, since new Ubuntu was released super recently I assumed it would be more up to date, my bad.

proycon commented 5 months ago

This looks very useful and works in exec. However, I notice that this variable is not set in on-click etc, it would help if it's also available there.

keifufu commented 5 months ago

You can build from 7163752aa07f145e5951e2388b7693e19fc5d446 with this patch if you want on-click, on-scroll-x etc. to have WAYBAR_OUTPUT_NAME.

proycon commented 5 months ago

Thanks!