From 94a6dc4d40dbb6ff000464e0911185078211fc16 Mon Sep 17 00:00:00 2001 From: Jonas Haugesen Date: Tue, 4 Aug 2026 11:45:05 +0200 Subject: [PATCH] sway wezterm nudge --- sway/.config/sway/scripts/wezterm-nudge.sh | 35 ++++++++++++++++++++++ sway/.config/sway/windowrules | 9 ++++++ 2 files changed, 44 insertions(+) create mode 100755 sway/.config/sway/scripts/wezterm-nudge.sh diff --git a/sway/.config/sway/scripts/wezterm-nudge.sh b/sway/.config/sway/scripts/wezterm-nudge.sh new file mode 100755 index 0000000..a4c0b2a --- /dev/null +++ b/sway/.config/sway/scripts/wezterm-nudge.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# wezterm-nudge.sh - workaround for the wezterm fractional-scaling bug on sway +# (wezterm#5875 / #6463). On a fractional-scaled output a newly mapped wezterm +# window renders its terminal area as a small rectangle until it receives a +# configure event (manually refocusing or switching workspaces is what normally +# "fixes" it). We force that configure here. +# +# The mis-scaled state is invisible to sway IPC (the window's rect is always the +# correct allocated size), so there is no event to wait on - a short settle delay +# is unavoidable. The matching `for_window ... opacity 0` rule keeps the window +# transparent from its first frame; this script reveals it (opacity 1) only after +# the nudge, so the resize is never visible. +# +# Nudge strategy, cheapest first: +# 1. 1px width resize - works when the window has a horizontal neighbour +# 2. 1px height resize - works when the window has a vertical neighbour +# (both are imperceptible and cause no real reflow once reverted) +# 3. float/unfloat - fallback for a lone window, which cannot be resized +# ("Cannot resize any further"); it has no neighbours, so nothing reflows +c='[con_id=__focused__]' + +# Let the window finish mapping and take focus before nudging. +sleep 0.08 + +if swaymsg "$c resize grow width 1 px" | grep -q '"success": true'; then + swaymsg "$c resize shrink width 1 px" >/dev/null +elif swaymsg "$c resize grow height 1 px" | grep -q '"success": true'; then + swaymsg "$c resize shrink height 1 px" >/dev/null +else + swaymsg "$c floating enable" >/dev/null + swaymsg "$c floating disable" >/dev/null +fi + +# Reveal. Target all wezterm windows so none can ever get stuck transparent. +swaymsg '[app_id=org.wezfurlong.wezterm] opacity 1' >/dev/null diff --git a/sway/.config/sway/windowrules b/sway/.config/sway/windowrules index f2b0084..20c5377 100644 --- a/sway/.config/sway/windowrules +++ b/sway/.config/sway/windowrules @@ -11,3 +11,12 @@ for_window [class="snow_trail_sdl"] floating enable for_window [app_id="destinations"] floating enable for_window [class="destinations"] floating enable for_window [app_id="evidence-quest"] floating enable + +# Workaround for wezterm fractional-scaling bug (wezterm#5875 / #6463): on a +# fractional-scaled output (DP-1 @ 1.5x) a newly mapped wezterm window renders its +# terminal area as a small rectangle until it receives a configure event. The +# window is held transparent from its first frame and revealed by the nudge script +# only after it has been forced to re-configure (resize nudge, or float-toggle when +# alone). See scripts/wezterm-nudge.sh for details. +for_window [app_id="org.wezfurlong.wezterm"] opacity 0 +for_window [app_id="org.wezfurlong.wezterm"] exec ~/.config/sway/scripts/wezterm-nudge.sh