Skip to content
Alexander Courtis edited this page May 11, 2024 · 13 revisions

Using Rofi As A Menu

@jeadorf

I'm using rofi (wiki), together with a customized rust program driving the interactive menu, displayed by rofi.

rofi example

  • I wrote this script using the example from i3_switch_workspace.sh
  • It is relatively straight-forward to include other shortcuts to configure the display
  • rofi has various themes, I included a screenshot of the default theme
#/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

Using Gamescope For X11 Applications and Games

X11 Applications And Games Are Blurry

Gamescope can be used to start an Xwayland session for an individual application, which will be rendered at 1:1 pixels.

This wrapper may be used to launch an X11 application at the first display's native resolution. Requires yq.

script: gamescope-run-native
#!/bin/bash

set -o pipefail

# fetch the first display
if ! VARS="$(way-displays -y -g | yq '.STATE.HEADS[0] | "NAME=\"" + .NAME + "\" DESCRIPTION=\"" + .DESCRIPTION + "\" WIDTH=" + .CURRENT.MODE.WIDTH + " HEIGHT=" + .CURRENT.MODE.HEIGHT')"; then
	exit 1
fi

# extract info
eval "${VARS}"
printf "name:   %s\ndesc:   %s\nwidth:  %d\nheight: %d\n" "${NAME}" "${DESCRIPTION}" "${WIDTH}" "${HEIGHT}"

# launch arguments with gamescope
gamescope \
	--prefer-output "${NAME}" \
	--output-width "${WIDTH}" --output-height "${HEIGHT}" \
	--nested-width "${WIDTH}" --nested-height "${HEIGHT}" \
	--adaptive-sync \
	"${@}"

Omit -output-width and --output-height in the event of "source rectangle out of buffer bounds" and repeated "source rectangle out of buffer bounds" failures.

Adaptive sync may not function unless running gamescope as a tty session: https://github.com/ValveSoftware/gamescope/issues/975

Examples

glxgears

gamescope-run-native -- glxgears -fullscreen

Steam And Games It Launches

Using 2 xwayland instances allows the steam window itself to be resized.

gamescope-run-native --xwayland-count 2 --steam -- steam

Individual Steam Game With Mangohud

Launch Options Command: mangohud gamescope-run-native --fullscreen -- %command%

Steam Deck

For reference, the steam deck uses the following to launch steam:

ps
gamescope \
	--generate-drm-mode fixed \
	--xwayland-count 2 \
	-w 1280 -h 800 \
	--default-touch-mode 4 \
	--hide-cursor-delay 3000 \
	--max-scale 2 \
	--fade-out-duration 200 \
	-e \
	-R /run/user/1000/gamescope.1zn7D7r/startup.socket \
	-T /run/user/1000/gamescope.1zn7D7r/stats.pipe \
	-O *,eDP-1 \
	--cursor-hotspot 5,3 \
	--cursor /usr/share/steamos/steamos-cursor.png

Toggle Auto Scaling Via CLI

@alex-courtis

The following script will test whether auto scaling is enabled and toggle it. Requires yq.

Will be unnecessary following Feature: toggles

script: toggle-scaling
#!/bin/sh

# test AUTO_SCALE is enabled
AUTO_SCALE_QUERY='select(.CFG.AUTO_SCALE)'

if way-displays -y -g | yq -e "${AUTO_SCALE_QUERY}" > /dev/null 2>&1; then
	way-displays -s AUTO_SCALE OFF
else
	way-displays -s AUTO_SCALE ON
fi

Toggle DISABLE Via CLI

@alex-courtis

The following script will toggle disabling a display. Requires yq.

Will be unnecessary following Feature: toggles

script: toggle-disabled
#!/bin/sh

# test specific display enabled
ENABLED_QUERY='.STATE.HEADS[] | select(.DESCRIPTION == "*LG Display 0x05EF*" and .CURRENT.ENABLED)'

if way-displays -y -g | yq -e "${ENABLED_QUERY}" > /dev/null 2>&1; then
	# add to the disabled list
	way-displays -s DISABLED "LG Display 0x05EF"
else
	# remove from the disabled list
	way-displays -d DISABLED "LG Display 0x05EF"
fi