From 7f6f440a65f9d8e62c841c4c1033dee3430a6c62 Mon Sep 17 00:00:00 2001 From: Derek Taylor Date: Sat, 16 May 2020 21:17:15 -0500 Subject: [PATCH] Adding trayer to xmonad with script to adjust for trayer width. --- .config/xmobar/trayer-padding-icon.sh | 48 +++++++++++++++++++++++++++ .config/xmobar/xmobarrc2 | 5 +-- .xmonad/xmonad.hs | 2 +- 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100755 .config/xmobar/trayer-padding-icon.sh diff --git a/.config/xmobar/trayer-padding-icon.sh b/.config/xmobar/trayer-padding-icon.sh new file mode 100755 index 0000000..adee04a --- /dev/null +++ b/.config/xmobar/trayer-padding-icon.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Copied from https://github.com/jaor/xmobar/issues/239#issuecomment-233206552 +# Detects the width of running trayer-srg window (xprop name 'panel') +# and creates an XPM icon of that width, 1px height, and transparent. +# Outputs an -tag for use in xmobar to display the generated +# XPM icon. +# +# Run script from xmobar: +# `Run Com "/where/ever/trayer-padding-icon.sh" [] "trayerpad" 10` +# and use `%trayerpad%` in your template. + + +# Function to create a transparent Wx1 px XPM icon +create_xpm_icon () { + timestamp=$(date) + pixels=$(for i in `seq $1`; do echo -n "."; done) + + cat << EOF > "$2" +/* XPM * +static char * trayer_pad_xpm[] = { +/* This XPM icon is used for padding in xmobar to */ +/* leave room for trayer-srg. It is dynamically */ +/* updated by by trayer-padding-icon.sh which is run */ +/* by xmobar. */ +/* Created: ${timestamp} */ +/* */ +"$1 1 1 1", +/* Colors (none: transparent) */ +". c none", +/* Pixels */ +"$pixels" +}; +EOF +} + +# Width of the trayer window +width=$(xprop -name panel | grep 'program specified minimum size' | cut -d ' ' -f 5) + +# Icon file name +iconfile="/tmp/trayer-padding-${width}px.xpm" + +# If the desired icon does not exist create it +if [ ! -f $iconfile ]; then + create_xpm_icon $width $iconfile +fi + +# Output the icon tag for xmobar +echo "" diff --git a/.config/xmobar/xmobarrc2 b/.config/xmobar/xmobarrc2 index 326acde..8c46720 100755 --- a/.config/xmobar/xmobarrc2 +++ b/.config/xmobar/xmobarrc2 @@ -6,7 +6,7 @@ Config { font = "xft:Mononoki Nerd Font:pixelsize=12:antialias=true:hinting=t , additionalFonts = [ "xft:FontAwesome:pixelsize=13" ] , bgColor = "#292d3e" , fgColor = "#B45BCF" - , position = TopW L 95 + , position = TopW L 100 , lowerOnStart = True , hideOnStart = False , allDesktops = True @@ -30,9 +30,10 @@ Config { font = "xft:Mononoki Nerd Font:pixelsize=12:antialias=true:hinting=t , Run Com "uname" ["-r"] "" 3600 -- Prints out the left side items such as workspaces, layout, etc. -- The workspaces are 'clickable' in my configs. + , Run Com "/home/dt/.config/xmobar/trayer-padding-icon.sh" [] "trayerpad" 10 , Run UnsafeStdinReader ] , sepChar = "%" , alignSep = "}{" - , template = " | %UnsafeStdinReader% }{ |  %uname% | %cpu% | %memory% | %disku% | %enp6s0% |  %pacupdate%| %date% | " + , template = " | %UnsafeStdinReader% }{ |  %uname% | %cpu% | %memory% | %disku% | %enp6s0% |  %pacupdate%| %date% | %trayerpad%" } diff --git a/.xmonad/xmonad.hs b/.xmonad/xmonad.hs index 7bee238..4c2b9e4 100644 --- a/.xmonad/xmonad.hs +++ b/.xmonad/xmonad.hs @@ -115,7 +115,7 @@ myStartupHook = do spawnOnce "picom &" spawnOnce "nm-applet &" spawnOnce "volumeicon &" - spawnOnce "trayer --edge top --align right --width 5 --padding 5 --margin 5 --SetDockType true --SetPartialStrut true --expand true --monitor 1 --transparent true --alpha 0 --tint 0x292d3e --height 18 &" + spawnOnce "trayer --edge top --align right --widthtype request --margin 5 --SetDockType true --SetPartialStrut true --expand true --monitor 1 --transparent true --alpha 0 --tint 0x292d3e --height 18 &" --spawnOnce "emacs --daemon &" setWMName "LG3D"