gamemode 1080p 330hz toggle

This commit is contained in:
2025-12-30 22:48:38 +02:00
parent db810daf00
commit e4296a3251
5 changed files with 133 additions and 6 deletions

View File

@@ -63,6 +63,19 @@ set $menu fuzzel
# File manager (Arch alternatives)
set $filemanager thunar
# Defaults (kept here so the config still loads even if the included file is missing)
set $dp1_mode 3840x2160@165Hz
set $dp1_bar_height 40
set $dp1_bar_font pango: FontAwesome, monospace 14
set $dp2_x 3840
set $dp2_bar_height 24
set $dp2_bar_font pango: FontAwesome, monospace 10
# Display/bar profile overrides (written by a toggle script).
# If this file doesn't exist, sway will just use the defaults below.
include /home/raga/.config/sway/display-profile.conf
###############################################################################
# Output configuration
###############################################################################
@@ -81,11 +94,11 @@ output DP-1 {
# mode 2560x1440@60Hz
# FULL
mode 3840x2160@165Hz
mode $dp1_mode
}
output DP-2 {
position 3840 0
position $dp2_x 0
# ECO
# mode 2560x1440@60Hz
@@ -510,9 +523,9 @@ bar {
output DP-1
position bottom
mode dock
height 40
height $dp1_bar_height
#font pango:monospace 10
font pango: FontAwesome, monospace 14
font $dp1_bar_font
separator_symbol " "
strip_workspace_numbers yes
workspace_min_width 36
@@ -537,9 +550,9 @@ bar {
output DP-2
position bottom
mode dock
height 24
height $dp2_bar_height
#font pango:monospace 10
font pango: FontAwesome, monospace 10
font $dp2_bar_font
separator_symbol " "
strip_workspace_numbers yes
workspace_min_width 36

View File

@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail
PROFILE_FILE="/home/raga/.config/sway/display-profile.conf"
mode_str=""
if [[ -f "$PROFILE_FILE" ]]; then
mode_str="$(awk '$1=="set" && $2=="$dp1_mode" {print $3; found=1} END {if(!found) print ""}' "$PROFILE_FILE" 2>/dev/null)"
fi
# Display-related FontAwesome icon + a short label.
case "$mode_str" in
3840x2160@*|4096x2160@*) echo " 4K";;
1920x1080@*) echo " 1080p";;
"") echo "";;
*) echo "${mode_str}";;
esac

View File

@@ -0,0 +1,75 @@
#!/usr/bin/env bash
set -euo pipefail
# Toggle DP-1 between 4K@165 and 1080p@330 and keep DP-2 positioned flush so
# you don't get a "dead gap" for the mouse.
PROFILE_FILE="/home/raga/.config/sway/display-profile.conf"
MODE_4K="3840x2160@165Hz"
MODE_GAME="1920x1080@330Hz"
# Bar tuning per mode
BAR_HEIGHT_4K="40"
BAR_FONT_4K="pango: FontAwesome, monospace 14"
BAR_HEIGHT_GAME="16"
BAR_FONT_GAME="pango: FontAwesome, monospace 8"
# DP-2 bar settings (static)
DP2_BAR_HEIGHT="24"
DP2_BAR_FONT="pango: FontAwesome, monospace 10"
get_current_profile_mode() {
# Reads the last-written profile state instead of querying the monitor.
# This makes toggling deterministic even if the display reports odd modes.
if [[ ! -f "$PROFILE_FILE" ]]; then
echo "$MODE_4K"
return
fi
# Example line: set $dp1_mode 3840x2160@165Hz
awk '$1=="set" && $2=="$dp1_mode" {print $3; found=1} END {if(!found) exit 1}' "$PROFILE_FILE" 2>/dev/null \
|| echo "$MODE_4K"
}
write_profile() {
local dp1_mode="$1"
local dp1_bar_height="$2"
local dp1_bar_font="$3"
local dp2_x="$4"
local tmp
tmp="$(mktemp)"
cat >"$tmp" <<EOF
# Autogenerated by display-profile-toggle.sh. Manual edits will be overwritten.
set \$dp1_mode ${dp1_mode}
set \$dp1_bar_height ${dp1_bar_height}
set \$dp1_bar_font ${dp1_bar_font}
set \$dp2_x ${dp2_x}
set \$dp2_bar_height ${DP2_BAR_HEIGHT}
set \$dp2_bar_font ${DP2_BAR_FONT}
EOF
mkdir -p "$(dirname "$PROFILE_FILE")"
mv -f "$tmp" "$PROFILE_FILE"
}
main() {
local current_mode
current_mode="$(get_current_profile_mode)"
if [[ "$current_mode" == "$MODE_4K" ]]; then
# Switch to game mode (1080p @ high refresh)
write_profile "$MODE_GAME" "$BAR_HEIGHT_GAME" "$BAR_FONT_GAME" "1920"
else
# Switch back to 4K
write_profile "$MODE_4K" "$BAR_HEIGHT_4K" "$BAR_FONT_4K" "3840"
fi
swaymsg reload >/dev/null
}
main "$@"

View File

@@ -0,0 +1,13 @@
# This file is intended to be rewritten by scripts (see display-profile-toggle.sh).
# Keep it small so the toggle is fast.
# DP-1 (4K / gaming output)
set $dp1_mode 3840x2160@165Hz
set $dp1_bar_height 40
set $dp1_bar_font pango: FontAwesome, monospace 14
# DP-2 (secondary output)
set $dp2_x 3840
set $dp2_bar_height 24
set $dp2_bar_font pango: FontAwesome, monospace 10

View File

@@ -10,6 +10,15 @@ click = [
{button = "left", cmd = "~/.config/sway/osrs-mode-toggle.sh", update = true}
]
[[block]]
block = "custom"
command = "~/.config/sway/display-profile-status.sh"
format = " $text "
interval = 1
click = [
{button = "left", cmd = "~/.config/sway/display-profile-toggle.sh", update = true}
]
[[block]]
block = "custom"
command = "echo ''"