diff options
author | jao <jao@gnu.org> | 2018-11-21 21:07:54 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2018-11-21 21:07:54 +0000 |
commit | 9e2a5c7daddf683d4be7c318aefed3da3ea7a89a (patch) | |
tree | ba0cdbe46f12b74c58d5fef51daa25bb550212ae | |
parent | b1eb899495ed996200a9e99c33bcc8f5a4896af9 (diff) | |
download | xmobar-9e2a5c7daddf683d4be7c318aefed3da3ea7a89a.tar.gz xmobar-9e2a5c7daddf683d4be7c318aefed3da3ea7a89a.tar.bz2 |
Padding icon idea stolen from @jonascj
-rw-r--r-- | readme.md | 10 | ||||
-rwxr-xr-x | samples/padding-icon.sh | 56 |
2 files changed, 66 insertions, 0 deletions
@@ -342,6 +342,16 @@ formats suitable for being displayed by the dzen2 status bar, wmii's status bar or xmobar's `StdinReader`. See [i3status manual] for further details. +### Dynamically sizing xmobar + +See [this idea] by Jonas Camillus Jeppensen for a way of adapting +dynamically xmobar's size and run it alongside a system tray widget +such as trayer or stalonetray (although the idea is not limited to +trays, really). For your convenience, there is a version of Jonas' +script in [samples/padding-icon.sh](./samples/padding-icon.sh). + +[this idea]: https://github.com/jaor/xmobar/issues/239#issuecomment-233206552 + ## Command Line Options xmobar can be either configured with a configuration file or with diff --git a/samples/padding-icon.sh b/samples/padding-icon.sh new file mode 100755 index 0000000..31f5eeb --- /dev/null +++ b/samples/padding-icon.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# Detects the width of running window with name given as first +# argument (xprop name '$1') and creates an XPM icon of that width, +# 1px height, and transparent. Outputs an <icon>-tag for use in +# xmobar to display the generated XPM icon. +# +# Run script from xmobar and trayer: +# `Run Com "/where/ever/padding-icon.sh" ["panel"] "trayerpad" 10` +# and use `%trayerpad%` in your template. +# or, if you're using for instance stalonetray: +# `Run Com "/where/ever/padding-icon.sh" ["stalonetray"] "tray" 10` + +# Very heavily based on Jonas Camillus Jeppensen code +# https://github.com/jaor/xmobar/issues/239#issuecomment-233206552 + +# 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-pad-icon.sh which is run */ +/* by xmobar. */ +/* Created: ${timestamp} */ +/* <w/cols> <h/rows> <colors> <chars per pixel> */ +"$1 1 1 1", +/* Colors (none: transparent) */ +". c none", +/* Pixels */ +"$pixels" +}; +EOF +} + +# panel window name +pname=${1:-panel} + +# Width of the trayer window +width=$(xprop -name $pname | grep 'program specified minimum size' | cut -d ' ' -f 5) + +# Icon file name +iconfile="/tmp/$pname-padding-${width:-0}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 "<icon=${iconfile}/>" |