xmobar/trayer-padding-icon.sh (view raw)
1#!/bin/sh
2# Copied from https://github.com/jaor/xmobar/issues/239#issuecomment-233206552
3# Detects the width of running trayer-srg window (xprop name 'panel')
4# and creates an XPM icon of that width, 1px height, and transparent.
5# Outputs an <icon>-tag for use in xmobar to display the generated
6# XPM icon.
7#
8# Run script from xmobar:
9# `Run Com "/where/ever/trayer-padding-icon.sh" [] "trayerpad" 10`
10# and use `%trayerpad%` in your template.
11
12
13# Function to create a transparent Wx1 px XPM icon
14create_xpm_icon () {
15 timestamp=$(date)
16 pixels=$(for i in `seq $1`; do echo -n "."; done)
17
18 cat << EOF > "$2"
19/* XPM *
20static char * trayer_pad_xpm[] = {
21/* This XPM icon is used for padding in xmobar to */
22/* leave room for trayer-srg. It is dynamically */
23/* updated by by trayer-padding-icon.sh which is run */
24/* by xmobar. */
25/* Created: ${timestamp} */
26/* <w/cols> <h/rows> <colors> <chars per pixel> */
27"$1 1 1 1",
28/* Colors (none: transparent) */
29". c none",
30/* Pixels */
31"$pixels"
32};
33EOF
34}
35
36# Width of the trayer window
37width=$(xprop -name panel | grep 'program specified minimum size' | cut -d ' ' -f 5)
38
39# Icon file name
40iconfile="$HOME/.xmonad/xpm/tmp/trayer-padding-${width}px.xpm"
41
42# If the desired icon does not exist create it
43if [ ! -f $iconfile ]; then
44 create_xpm_icon $width $iconfile
45fi
46
47# Output the icon tag for xmobar
48echo "<icon=${iconfile}/>"