From b083794a194250b331659b23d849986b58150fb4 Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sat, 22 Dec 2018 15:35:24 -0500 Subject: [PATCH 1/2] xeventbind: Change cursor size on resolution change Note that some applications will not respect xsetroot, so using XCURSOR_SIZE as well is necessary. --- xeventbind/.config/xeventbind/on-resolution-change.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xeventbind/.config/xeventbind/on-resolution-change.sh b/xeventbind/.config/xeventbind/on-resolution-change.sh index 6375689b..3a65d0e3 100755 --- a/xeventbind/.config/xeventbind/on-resolution-change.sh +++ b/xeventbind/.config/xeventbind/on-resolution-change.sh @@ -3,6 +3,8 @@ # Get the host width HOST_WIDTH=$(bspc query -T -m | jq '.rectangle.width') +CURSOR_THEME=${XCURSOR_THEME:-breeze_cursors} + # Determine the DPI based on screen width if [ "$HOST_WIDTH" -eq "1920" ]; then X_DPI=96 @@ -18,6 +20,13 @@ fi # If the DPI needs to be changed, change it if [ "$X_DPI" ]; then echo "Xft.dpi:$X_DPI" | xrdb -merge + + # Change the X cursor size as well + # NOTE: For full effect, this needs to be used in combination with XCURSOR_SIZE. + # NOTE: ($X_DPI / 6) here means that 4k will use cursor size 32, so it will appear + # about half the size of the 1080p cursor. If this is not what you want, use + # cursor size 64 instead. + xsetroot -xcf "/usr/share/icons/$CURSOR_THEME/cursors/left_ptr" "$(($X_DPI / 6))" fi # Reload polybar with the new width / DPI From 49e6b759694cccb573c5ee48259b908e1ee011eb Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sat, 22 Dec 2018 15:41:02 -0500 Subject: [PATCH 2/2] rofi: Launch programs with DPI-based cursor size Now it is possible to take advantage of different cursor sizes without restarting the X session. --- rofi/.config/rofi/launch.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/rofi/.config/rofi/launch.sh b/rofi/.config/rofi/launch.sh index f4655a2f..7e95d503 100755 --- a/rofi/.config/rofi/launch.sh +++ b/rofi/.config/rofi/launch.sh @@ -11,10 +11,45 @@ # respects its theming even when XDG_CURRENT_DESKTOP is not set to it # (through settings.ini). +# Note that the xcursor size is specified with: +# +# 1. The X server resource database (xrdb), of which cursor size is +# only applied BEFORE your window manager starts +# 2. The xsetroot command, which affects the cursor shown on the root +# window (your desktop) +# 3. The XCURSOR_SIZE environment variable, which affects the current +# program +# +# There are a few things to take away from this: +# +# 1. The root window (desktop) cursor size MUST be changed with xsetroot +# 2. KDE applications will honor XCURSOR_SIZE but NOT xsetroot +# 3. GTK applications will honor xsetroot but NOT XCURSOR_SIZE +# +# Additionally, +# +# 4. SOME X applications require XCURSOR_SIZE to be set and will NOT +# honor xsetroot +# 5. SOME X applications require xsetroot to be set and will NOT +# honor XCURSOR_SIZE +# +# So for a consistent variable cursor DPI environment, one has to set BOTH +# xsetroot and XCURSOR_SIZE +# +# Note that existing windows will NOT have their X cursor size changed +# if they don't depend on xsetroot. Because of this, and because of the +# fact that active windows will not handle DPI changes anyway, you should +# probably have no GUIs running when switching DPI. + ROFI_DPI=$(xrdb -query | grep Xft.dpi | cut -f 2) ROFI_SCALE=$(expr $ROFI_DPI / 96) ROFI_DPI_SCALE=$(awk "BEGIN { print "1/$ROFI_SCALE" }") +CURSOR_THEME=${XCURSOR_THEME:-breeze_cursors} +CURSOR_SIZE=$((16 * $ROFI_SCALE)) + +xsetroot -xcf "/usr/share/icons/$CURSOR_THEME/cursors/left_ptr" "$CURSOR_SIZE" + env \ XDG_CURRENT_DESKTOP="KDE" \ QT_AUTO_SCREEN_SCALE_FACTOR="0" \ @@ -22,6 +57,7 @@ env \ QT_SCREEN_SCALE_FACTORS="VGA-1=$ROFI_SCALE;" \ GDK_SCALE="$ROFI_SCALE" \ GDK_DPI_SCALE="$ROFI_DPI_SCALE" \ + XCURSOR_SIZE="$CURSOR_SIZE" \ rofi \ -show drun \ -dpi "$ROFI_DPI"