WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: screen rez  (Read 1464 times)

Offline vinceASPECT

  • Hero Member
  • *****
  • Posts: 839
screen rez
« on: September 12, 2020, 08:09:07 AM »
Hello forum,

what is a generic command at the terminal to change the screen
resolution on Linux......?

is it a set of commands or one? and what are they?

thx

v
« Last Edit: September 12, 2020, 08:11:11 AM by vinceASPECT »

Offline mocore

  • Hero Member
  • *****
  • Posts: 717
  • ~.~
Re: screen resolution
« Reply #1 on: April 02, 2025, 03:36:57 AM »
wrt>  "screen resolution"

RandR
    RandR (resize and rotate) is a communications protocol written as an extension to the X11[34] protocol. XRandR provides the ability to resize, rotate and reflect the root window of a screen. RandR is responsible for setting the screen refresh rate.[35] It allows for the control of multiple monitors.[36]

arch wiki mentions some alternative gui / cli for randr
+ https://wiki.archlinux.org/title/Xrandr

+ https://gitlab.freedesktop.org/xorg/app/xrandr

this on probably the most relevant to "old" hw 
+ https://www.thinkwiki.org/wiki/Xorg_RandR_1.2

a ux perspective on monitor config  8) .. + "xrandr-smart" script !
@ https://work.lisk.in/2020/10/11/xrandr-ux.html

Quote
The way monitor layouts work for most people with mainstream operating systems or desktop environments
(like GNOME) is this: you connect an external monitor for the first time, your desktop expands to this monitor,
then you can change its position or turn it off in the settings, and then this setup is remembered
so that you don’t need to do it again the next time you connect it.
People with non-mainstream X11 window managers (like xmonad, i3, awesomewm, fluxbox)
can get a similar experience: arandr being the “settings UI” and autorandr handling the initial expansion, saving and restoring.

"xrandr-smart = Wrapper around xrandr which allows shell globs in --output and automatically disables all other outputs."
... https://github.com/liskin/dotfiles/blob/standalone/xrandr-smart/xrandr-smart

Code: [Select]
#!/usr/bin/env bash

# Wrapper around xrandr which allows shell globs in --output and automatically
# disables all other outputs.
#
# see https://work.lisk.in/2020/10/11/xrandr-ux.html

set -eu -o pipefail

export LC_ALL=C

unset xrandr_query

function o { printf -->&2 "%s:%s\\n" "${0##*/}" "$(printf " %q" "$@")"; "$@"; }

function get-xrandr-query {
[[ "${xrandr_query-}" ]] && return

xrandr_query=$(xrandr --query)
}

function get-xrandr-outputs {
<<<"$xrandr_query" grep -P -o '^([\w-]+)(?= (dis)?connected)' | LC_ALL=C sort
}

function get-xrandr-connected-outputs {
<<<"$xrandr_query" grep -P -o '^([\w-]+)(?= connected)' | LC_ALL=C sort
}

function get-xrandr-outputs-except {
get-xrandr-outputs | grep -F -v -x -f <(printf "%s\n" "$@")
}

function get-xrandr-custom-monitors {
xrandr --listmonitors | grep -P -o '^\s*\d+:\s+\K[^+]\S+' | sed -e 's/^[+*]*//'
}

function find-one {
local pat="${1:?}" n="" tmp=""
local -a matches=()

if [[ $pat == *#* ]]; then
n=${pat#*#}
pat=${pat%#*}
fi

while read -r tmp; do
# shellcheck disable=SC2053
if [[ $tmp == $pat ]]; then
matches+=("$tmp")
fi
done

if [[ $n ]]; then
(( n < ${#matches[@]} )) && printf "%s\n" "${matches[$n]}"
else
(( ${#matches[@]} == 1 )) && printf "%s\n" "${matches[0]}"
fi
}

function find-xrandr-output { get-xrandr-outputs | find-one "$1"; }
function find-xrandr-connected-output { get-xrandr-connected-outputs | find-one "$1"; }

function xrandr-auto-off {
local -a outputs=()
local output
local -a args=()
local arg

while (( $# )); do
arg="$1"; shift
args+=("$arg")

[[ $arg == --output ]] && outputs+=("$1")
done

if ! (( ${outputs[@]+${#outputs[@]}} )); then
printf -->&2 "Aborting, would disable all outputs.\n"
exit 1
fi

for output in $(get-xrandr-outputs-except ${outputs[@]+"${outputs[@]}"}); do
args+=(--output "$output" --off)
done

for monitor in $(get-xrandr-custom-monitors); do
o xrandr --delmonitor "$monitor"
done

o xrandr "${args[@]}"
}

function xrandr-auto-find {
local -a args=()
local arg

while (( $# )); do
arg="$1"; shift
args+=("$arg")

if [[ $arg == --@(output|left-of|right-of|above|below|same-as) ]] && (( $# )); then
arg="$1"; shift
arg=$(find-xrandr-connected-output "$arg")
args+=("$arg")
fi
done

o xrandr-auto-off "${args[@]}"
}

get-xrandr-query

# skip main if sourced
return 0 2>/dev/null || :

if (( ! $# )); then
echo "Usage: xrandr-smart --output …"
exit 1
fi

xrandr-auto-find "$@"



 https://github.com/liskin/dotfiles/archive/standalone/xrandr-smart.tar.gz
« Last Edit: April 02, 2025, 03:52:18 AM by mocore »