alex-courtis / way-displays

way-displays: Auto Manage Your Wayland Displays
MIT License
239 stars 12 forks source link

Feature: recipe for using rofi as menu for way-displays #140

Closed jeadorf closed 6 months ago

jeadorf commented 7 months ago

rofi

A beautiful TUI to manage displays. Would you care to share your setup / configuration? That would be the start of the Recipes wiki page.

Originally posted by @alex-courtis in https://github.com/alex-courtis/way-displays/issues/121#issuecomment-1807269270

jeadorf commented 7 months ago

I'm using rofi (https://github.com/davatorium/rofi, https://wiki.archlinux.org/title/rofi), together with a customized rust program driving the interactive menu, displayed by rofi. In order to make the recipes more self-contained and thus useful (minimal dependencies), I need to post some examples on how to use rofi and way-displays with the least amount of customization. But once you get the gist on how rofi works, should be fairly straight-forward to include shortcuts to way-displays like the ones in the screenshot.

jeadorf commented 7 months ago

The following example

rofi-example

allows user to switch between internal only, external only, or both displays.

#/bin/sh

# Configure names of external and internal displays
EXTERNAL="HDMI-A-1"
INTERNAL="eDP-1"

function show() {
  way-displays --delete DISABLED "$1" > /dev/null
}

function hide() {
  way-displays -s DISABLED "$1" > /dev/null
}

OPT_INTERNAL="Internal display"
OPT_EXTERNAL="External display"
OPT_BOTH="Both displays"

function menu() {
  echo "${OPT_INTERNAL}"
  echo "${OPT_EXTERNAL}"
  echo "${OPT_BOTH}"
}

OPTION=$( (menu)  | rofi -dmenu -p "Configure displays")

# Invoke way-displays. Only hide a display if showing the other display
# succeeded. This reduces the chances to end up with both displays turned off,
# which is typically rather inconvenient.
if [ "${OPTION}" == "${OPT_INTERNAL}" ]
then
  show "${INTERNAL}" && hide "${EXTERNAL}"
elif [ "${OPTION}" == "${OPT_EXTERNAL}" ]
then
  show "${EXTERNAL}" && hide "${INTERNAL}"
elif [ "${OPTION}" == "${OPT_BOTH}" ]
then
  show "${EXTERNAL}"
  show "${INTERNAL}"
fi
alex-courtis commented 7 months ago

That is just fantastic! Thank you so much.

I've moved things to a wiki, with a recipes page.

I'd be most grateful if you could add you recipe in there - you should get the credit ;)

jeadorf commented 7 months ago

Happy to make the edit myself.

alex-courtis commented 6 months ago

Added to the recipes.

jeadorf commented 6 months ago

Sorry for sitting on this so long ... https://github.com/alex-courtis/way-displays/wiki/Recipes looks good. Thank you!

alex-courtis commented 6 months ago

No worries; please do update it as needed.