You are not logged in.

#276 2011-10-22 21:58:45

Jabrick
Member
Registered: 2011-05-13
Posts: 79

Re: dzen & xmobar Hacking Thread

Moved to newbie section.

Last edited by Jabrick (2011-10-22 22:18:20)

Offline

#277 2011-12-30 01:18:14

louiswins
Member
Registered: 2007-12-02
Posts: 6

Re: dzen & xmobar Hacking Thread

Here's the bar that I constructed. It's kind of weird in that the left part (workspaces) is a log hook and the right part (system information) is a script, but whatever. Here's what it looks like:
dzen.png

The icons are from Tango and the excellent Silk icon set, but I'll probably change them as they look too garish for my tastes (I just happened to have them handy). In fact, I'll probably change a lot of stuff as I continue customizing xmonad. I just started using it a few days ago, and couldn't live without a status bar. Credit goes to probably about 2/3 of the posts in this forum as I learned how to use dzen2. I didn't keep track of what exactly I pulled from whom.

Features:

  • Easily extensible

  • Click on workspace number to switch

  • Click on layout name to switch

  • Click on volume to toggle mute; mouse wheel to raise/lower volume

  • Highlighted hour/minute in date and time

Problems/TODO:

  • Have just one bar integrating everything, but I'm not really sure how to do that

  • Swap icons for whether we're on wireless or wired network

  • Like redbeard0531, my script doesn't exit cleanly. You can see it try to compensate for that at the end (right above where it creates the pipe) when it tries to kill other executions (I Mod-Q a LOT). If you don't like the fact that it just killalls tail, then you can take that out, but you'll have to clean up after it manually. Happily, the other bar exits cleanly.

Here's the relevant part of xmonad.hs:

-- Requires xdotool.

myDzenPP h = defaultPP
    { ppHidden  = \n -> wrap ("^ca(1, xdotool key super+" ++ n ++ ") ") " ^ca()" n
    , ppCurrent = dzenColor "" "#555555" . wrap " " " " . dzenColor "white" ""
    , ppLayout  = wrap "^ca(1, xdotool key super+space)" "^ca()"
    , ppWsSep   = "|"
    , ppSep     = " :: "
    , ppOutput  = hPutStrLn h
    }

infoBar = statusBar "/path/to/info-bar.sh" defaultPP toggleStrutsKey
    where toggleStrutsKey XConfig {modMask = modm} = (modm, xK_b)

statusBarCmd = "dzen2 -bg '#1a1a1a' -fg '#aaaaaa' -h 12 -e '' -ta l -fn '-*-terminus-*-r-normal-*-12-*-*-*-*-*-iso8859-*'"

main = do
    din <- spawnPipe statusBarCmd
    xmonad =<< infoBar defaultConfig {
        logHook = dynamicLogWithPP $ myDzenPP din
    }

And then info-bar.sh is:

#!/bin/bash

# Requires dzen2 and dmplex.
# Battery widget       requires acpi
# Wireless widget      requires wireless_tools
# Volume widget        requires alsa-utils and inotify-tools
# CPU Frequency widget requires cpufrequtils and bc

# dzen2 options
FG='#aaaaaa'
BG='#1a1a1a'
SCREEN_WIDTH=1366
BAR_WIDTH=500
FONT='-*-terminus-*-r-normal-*-12-*-*-*-*-*-iso8859-*'
PIPE='/path/to/dmpipe'

# icons
ICON_PATH="/path/to/icon_folder"
ICON_WIRELESS="^i(${ICON_PATH}/wireless.xpm)"
ICON_AC="^i(${ICON_PATH}/ac.xpm)"
ICON_BATTERY="^i(${ICON_PATH}/battery.xpm)"
ICON_VOLUME="^i(${ICON_PATH}/vol.xpm)"
ICON_MUTED="^i(${ICON_PATH}/mute.xpm)"
ICON_CPUFREQ="^i(${ICON_PATH}/cpu.xpm)"
ICON_TIME="^i(${ICON_PATH}/time.xpm)"


# Usage: update_bar position icon text
update_bar () {
	echo $1 "  $2 $3" >"$PIPE"
}



update_time () {
	while true; do
		update_bar $1 "$ICON_TIME" "$(date '+%a %-d %b %Y ^fg(white)%H:%M^fg():%S')"
		sleep 1
	done
}

update_battery() {
	local bat_text
	local bat_icon
	while true; do
		bat_text="$(acpi -b)"
		if acpi -a | grep -q on-line; then
			bat_icon="$ICON_AC"
		else
			bat_icon="$ICON_BATTERY"
		fi

		if echo $bat_text | grep -q remaining || echo $bat_text | grep -q 'until charged'; then
			bat_text="$(echo $bat_text | sed -rn 's/.* ([0-9]+%), ([0-9]{2}:[0-9]{2}).*/\1 (\2)/p')"
		elif echo $bat_text | grep -q unavailable; then
			bat_text="$(echo $bat_text | sed -rn 's/.* ([0-9]+%), .*/\1 (unknown)/p')"
		elif echo $bat_text | grep -q Full; then
			bat_text='100% (Full)'
		else
			bat_text='No battery'
		fi

		update_bar $1 "$bat_icon" "$bat_text"
		sleep 20
	done
}

update_wireless () {
	while true; do
		update_bar $1 "$ICON_WIRELESS" "$(iwconfig wlan0 | awk '/Quality/{print $2}' | cut -d'=' -f2 | awk -F'/' '{printf("%.0f%%", $1/$2*100)}')"
		sleep 5
	done
}

update_volume() {
	local vol
	local vol_icon
	while true; do
		vol="$(amixer get Master | grep Mono:)"
		if echo $vol | grep -q off; then
			vol_icon="$ICON_MUTED"
		else
			vol_icon="$ICON_VOLUME"
		fi
		# clickable areas for muting, increasing, and decreasing volume
		vol_icon="^ca(1, amixer set Master toggle)^ca(4, amixer set Master 5+ unmute)^ca(5, amixer set Master 5-)$vol_icon"
		vol="$(echo $vol | sed -r 's/.*[0-9] \[([0-9]+)%.*/\1/' | gdbar -h 10 -w 30 -fg '#aaaaaa' -bg '#565656')^ca()^ca()^ca()"

		update_bar $1 "$vol_icon" "$vol"
		inotifywait -t 30 -qq /dev/snd/controlC0
	done
}

update_cpufreq () {
	while true; do
		update_bar $1 "$ICON_CPUFREQ" "$(printf '%3.2f GHz' $(echo 2k$(cpufreq-info -f) 1000000/p | dc))"
		sleep 2
	done
}

# Try to clean up from last time.
killall tail
mypid=$$
pgrep "$(basename $0)" | grep -v $mypid | xargs kill >>~/log 2>&1

# create pipe
rm -f "$PIPE" >/dev/null 2>&1
mkfifo "$PIPE" >/dev/null 2>&1
if [ ! -p "$PIPE" ]; then
	echo "Could not create named pipe $PIPE; execution failed." >&2
	exit 1
fi

tail -f "$PIPE" | dmplex | dzen2 -e '' -w $BAR_WIDTH -x $(($SCREEN_WIDTH - $BAR_WIDTH)) -h 12 -ta r -fg $FG -bg $BG -fn $FONT &
update_wireless 1 &
update_battery 2 &
update_volume 3 &
update_cpufreq 4 &
update_time 5 &
# I like to have a space at the end
echo "1023  " >"$PIPE"

Offline

#278 2012-03-18 18:38:01

gotmor
Member
From: Germany
Registered: 2007-09-03
Posts: 84
Website

Re: dzen & xmobar Hacking Thread

FYI:

Dzen has moved to Github in order to allow for easier collaboration. Feel free to fork it and send pull requests: https://github.com/robm/dzen

Also, as I'm pretty busy with work stuff I'm looking for people who are willing to review patches and apply them to the tree.
If you're interested just drop me a note ...


Bye, Rob.

Offline

#279 2012-03-19 19:54:00

owain
Member
Registered: 2009-08-24
Posts: 233

Re: dzen & xmobar Hacking Thread

I hope this isn't too obvious: is it possible to specify the vertical position of dzen from the bottom of the screen rather than the top? I have bars at the top and bottom of my laptop screen, and would like the latter to shift to the bottom of an external screen when I switch to it, rather than remain stranded in the middle of the larger desktop. I'm using XMonad, if that's relevant, although the bottom bar is simply displaying an output from conky.

Offline

#280 2012-03-20 13:26:42

gotmor
Member
From: Germany
Registered: 2007-09-03
Posts: 84
Website

Re: dzen & xmobar Hacking Thread

owain wrote:

I hope this isn't too obvious: is it possible to specify the vertical position of dzen from the bottom of the screen rather than the top? I have bars at the top and bottom of my laptop screen, and would like the latter to shift to the bottom of an external screen when I switch to it, rather than remain stranded in the middle of the larger desktop. I'm using XMonad, if that's relevant, although the bottom bar is simply displaying an output from conky.

Sure, e.g.: 

 dzen2 -y -50

There's an '-geometry' option, too.

See here http://dzen.geekmode.org/dwiki/doku.php … een-bottom for further details.



Have fun, Rob.

Offline

#281 2012-03-20 15:23:02

owain
Member
Registered: 2009-08-24
Posts: 233

Re: dzen & xmobar Hacking Thread

Thanks - I found the negative option after posting that. It still doesn't quite do what I want, because it doesn't automatically adjust to the new resolution. However, as I'm using a small script to call xrandr, I can kill and restart the relevant processes.

Offline

#282 2012-03-28 23:23:16

r4
Member
Registered: 2009-10-20
Posts: 19

Re: dzen & xmobar Hacking Thread

Here is the bar I made recently by using various ideas and parts from others. I tried to clean up the code and make it readable/easy to change/configure. In addition, I added some comments on what each piece does.

It utilizes dzen2 + dmplex for a more modular approach. Ideally I would like to use one while loop for everything but it ended up making the code less readable (not good!).

The big reason why I'm trying to make "readable" code is due to the pain I had to endure to get dzen to play nice. Anyway...

Some screenshots...
http://i.imgur.com/9rU5n.png <----Usual look
http://i.imgur.com/VMq0d.png <-----Mail Popup
http://i.imgur.com/LokNc.png <-----Calendar Popup

Now code...

#!/bin/bash
#
# dzenBar - A highly configured dzen2 status bar
#
# created by: Drew Liszewski (r4 on freenode)
#
# Dependencies:
#   bash > 4.0
#   dzen2
#   dmplex
#   tail
#   pgrep
#   date (time and date)
#   find (mail)
#   wget (weather)
#   acpi (battery)
#   coreutils
#

## Main Configuration ##
loc_code="KMKC"
metric="0"
date="%a, %b %-d %-l:%M%p"
maildir=( ${HOME}/.mail/*/Inbox/new/ )

## Delays ##
declare -A delay=(
    [weather]=900
    [stats]=5
    [clock]=60
    )

## Colors ##
declare -A color=(
    [default]="#8C8C8C"
    [background]="#000000"
    [gray]="#AAAAAA"
    [lightgray]="#CCCCCC"
    )

## Dzen Configuration ##
declare -A dzen=(
    [fn]="Verdana:bold:pixelsize=11:antialias=false"
    [fg]="${color[default]}"
    [bg]="${color[background]}"
    [x]="400"
    [y]="0"
    [w]="1280"
    [h]="16"
    [ta]="r"
    [e]=""
    )

## End Configuration ##

# Usage: update_bar <position> <text>
# Description: Updates output at specific locations
update_bar () {
    echo $1 "$2" > "$pipe"
}

# Spacer
# Usage: spacer "<string>" <loc>
# Description: Simple method for creating space between modules
spacer () {
    update_bar $2 "^fg(${color[lightgray]})${1}^fg()"
}


# Usage: update_clock <position>
# Description: Updates time display by sane intervals. 
#              ie: 1 second or 1 minute
update_clock () {
    read -r -a _date <<< "$date"
    date="^ca(1,${HOME}/.xmonad/calendar)${_date[*]:0:3} ^fg(${color[gray]})${_date[*]:3}^fg()^ca()" 

	while true; do
	    update_bar $1 "$(date +"${date}")"

        if [ ${delay[clock]} -eq 60 ]; then
            # Update the clock on the minute.
            # This is better than setting the delay to 60
            # because regardless of when the script starts,
            # it guarantess that the time will be accurate.
            sleep $((60-`date +%-S`))
        else
            sleep ${delay[clock]}
        fi
	done
}

# Usage: update_mail <position>
# Description: Updates mail count.
# Note: No timer used, relies on inotifywait
update_mail () {
    update_bar $1 "^ca(1,${HOME}/.xmonad/mail)Mail: ^fg(${color[gray]})$(find "${maildir[@]}" -type f | wc -l)^fg()^ca()"

    while inotifywait -q -e moved_to -e moved_from ${maildir[@]}; do
        update_bar $1 "^ca(1,${HOME}/.xmonad/mail)Mail: ^fg(${color[gray]})$(find "${maildir[@]}" -type f | wc -l)^fg()^ca()"
        sleep 1
    done
}

# Usage: update_stats <position>
# Description: Sends common stats (ie: CPU/MEM usage) to dzenBar
#              Also has ability to send battery stats
update_stats () {
#    local current_batt="/tmp/.batt"
#    [ ! -f $current_batt ] && touch $current_batt

    while true; do
#        ## Get Battery State ##
#        acpi -ab > $current_batt
#
#        while read -a acpi; do
#            case $acpi in
#                Adapter) state="${acpi[2]}" ;;
#                Battery) charge="${acpi[3]%\%*}" ;;
#            esac
#        done < $current_batt
#
#        if [[ "$state" == "on-line" ]]; then
#            batt_state="Adapter: ^fg(${color[gray]})${state:-N/A}^fg()"
#        else
#            batt_state="Battery: $(get_color 2 ${charge:-N/A})%"
#        fi

        ## Get Memory Usage ##
        while read name val unit; do
            case $name in 
                MemTotal:) total=$val ;;
                MemFree:) free=$val ;;
                Buffers:) buf=$val ;;
                Cached:) cache=$val ;;
            esac
        done < /proc/meminfo

        mem_reserved=$(($free+$buf+$cache))
        mem_used=$(($total-$mem_reserved)) 
        mem_pused=$((100*$mem_used/$total))
    
        #update_bar $1 "${batt_state} ^fg(${color[lightgray]})::^fg() Cpu: $(get_color 1 ${cpu:-0})% ^fg(${color[lightgray]})::^fg() Mem: $(get_color 1 ${mem_pused:-0})%"
        update_bar $1 "Cpu: $(get_color 1 ${cpu:-0})% ^fg(${color[lightgray]})::^fg() Mem: $(get_color 1 ${mem_pused:-0})%"

        ## Get CPU Usage ##
        eval $(awk '/^cpu /{print "previdle=" $5 "; prevtotal=" $2+$3+$4+$5 }' /proc/stat)

        sleep ${delay[stats]}

        eval $(awk '/^cpu /{print "idle=" $5 "; total=" $2+$3+$4+$5 }' /proc/stat)
        intervaltotal=$((total-${prevtotal:-0}))
        cpu=$((100*( (intervaltotal) - ($idle-${previdle:-0}) ) / (intervaltotal) ))
    done
}

# Usage: update_weather <position>
# Description: Gets weather from NOAA.gov
update_weather () {
    local url="http://weather.noaa.gov/pub/data/observations/metar/decoded/${loc_code}.TXT"
    local tmp_weather="/tmp/.weather"
    [ ! -f ${tmp_weather} ] && touch ${tmp_weather}
    [ $metric -eq 1 ] && ((++metric))

    while true; do      e
    wget -q -O "${tmp_weather}" "${url}"

    while read -a weather; do
        case "${weather[0]}" in
            Temperature:) temp="${weather[metric+1]#(}"
                          scale="${weather[metric+2]%)}" ;;
            Sky) cond="${weather[*]:2}" ;;
        esac
    done < $tmp_weather

    update_bar $1 "Kansas City, MO: $(get_temp_color ${temp})^fg(${color[gray]})${scale}, ${cond}^fg()"
    sleep ${delay[weather]}

    done
}

# Usage: update_current_song <position>
# Description: Reads from $current_song and prints output to dzenBar
# Note: No timer used, relies on inotifywait
update_current_song () {
    local max_length=50
    local current_song="/tmp/.current_song"
    [ ! -f ${current_song} ] && touch ${current_song}
    
    while inotifywait -q -e modify $current_song; do
        read song_info < "$current_song"

        if [ ! ${#song_info} -eq 0 ]; then
            tmp_song="^fg(${color[gray]})Now Playing:^fg() ${song_info:0:max_length}"
        else
            tmp_song=""
        fi

        update_bar $1 "${tmp_song}"
        sleep 1
    done
}

# Usage get_color <scheme> <int>
# Description: Adds color to a number range dependant on scheme
get_color () {
    local int=${2%.*}

    [[ $1 -eq 1 ]] && scheme=( green orange red )
    [[ $1 -eq 2 ]] && scheme=( red orange green )

    if [ $int -le 33 ]; then
        printf "%s" "^fg(${scheme[0]})$int^fg()"
    elif [ $int -le 66 ]; then
        printf "%s" "^fg(${scheme[1]})$int^fg()"
    elif [ $int -le 100 ]; then
        printf "%s" "^fg(${scheme[2]})$int^fg()"
    fi
}

# Usage get_temp_color <int>
# Description: Adds color to a number range related to freezing
#              and room temperature.
get_temp_color () {
    local int=${1%.*}

    [[ $metric -eq 0 ]] && scale=( 32 72 )
    [[ $metric -eq 1 ]] && scale=( 0 22 )

    if [ $int -le ${scale[0]} ]; then
        printf "%s" "^fg(lightblue)$int^fg()"
    elif [ $int -le ${scale[1]} ]; then
        printf "%s" "^fg(green)$int^fg()"
    elif [ $int -gt ${scale[1]} ]; then
        printf "%s" "^fg(red)$int^fg()"
    fi
}

# Try to clean up from last time.
killall tail
mypid=$$
pgrep "$(basename $0)" | grep -v $mypid | xargs kill >>~/log 2>&1

# Check if pipe already exists
# If not, create the named pipe for dzen
pipe='/tmp/.dmpipe'
[ ! -p $pipe ] && mkfifo $pipe

# Listen on the pipe and multiplex the input to dzen

tail -f $pipe | dmplex | dzen2 \
    -fn ${dzen[fn]} \
    -fg ${dzen[fg]} \
    -bg ${dzen[bg]} \
    -x  ${dzen[x]} \
    -y ${dzen[y]} \
    -w ${dzen[w]} \
    -h  ${dzen[h]} \
    -ta ${dzen[ta]} \
    -e  ${dzen[e]} &

# Intialize Modules
update_current_song 1 &
spacer " | " 2
update_weather 3 &
spacer " :: " 4
update_mail 5 &
spacer " :: " 6
update_stats 7 &
spacer " :: " 8
update_clock 9 &
spacer " |" 10

If anyone is interested, I'll post how I have dzen integrated with xmonad + the other two dzen bash scripts that launch the mail/calendar popups.

Offline

#283 2012-04-05 10:08:06

Sakura
Member
Registered: 2010-05-06
Posts: 20

Re: dzen & xmobar Hacking Thread

Is it possible to change the background using ^bg() of an xpm? From my experience the xpm only retains dzen's original background setting set with -bg, and ignores any ^bg() commands.

Offline

#284 2012-05-04 17:26:35

r4
Member
Registered: 2009-10-20
Posts: 19

Re: dzen & xmobar Hacking Thread

found a decent way to kill all dzen2 processes that come along with running dzen + dmplex + tail + many while loops

i use this as a check...

read -d ' ' GPID <<< $(ps -C "<myscript>" -o "%r" --no-headers)
kill -TERM "${GPID}"

Last edited by r4 (2012-05-06 05:36:34)

Offline

#285 2012-06-04 18:47:48

DrKillPatient
Member
Registered: 2011-07-28
Posts: 85

Re: dzen & xmobar Hacking Thread

Is it possible to have xmobar correctly restart when xmonad does (no duplicate processes) but NOT display output from stdinreader in the bar? I'd like a second instance of xmobar (such as the layout in this screenshot -- top and bottom) for displaying additional information, but if I leave out "%StdinReader%", it fails to be killed by an xmonad restart, and I get a new copy (in addition to the running copy) each time. I've read that spawning it through a shell script is not good practice, but I'm not familiar enough with Haskell to figure it out. What can I do to fix this?

Offline

#286 2012-07-30 06:06:07

chujoii
Member
Registered: 2012-07-30
Posts: 1

Re: dzen & xmobar Hacking Thread

graphs drawn using scheme and dzen2 :

img: monitorus

src: https://github.com/chujoii/monitorus

Offline

#287 2012-07-30 09:53:23

gotmor
Member
From: Germany
Registered: 2007-09-03
Posts: 84
Website

Re: dzen & xmobar Hacking Thread

chujoii wrote:

Wow, great stuff! Looks amazing...

Offline

#288 2012-08-02 18:41:21

Prezioso
Member
Registered: 2011-01-17
Posts: 77

Re: dzen & xmobar Hacking Thread

r4 wrote:

If anyone is interested, I'll post how I have dzen integrated with xmonad + the other two dzen bash scripts that launch the mail/calendar popups.

I am smile

Offline

#289 2012-11-26 15:15:20

r4
Member
Registered: 2009-10-20
Posts: 19

Re: dzen & xmobar Hacking Thread

Prezioso wrote:
r4 wrote:

If anyone is interested, I'll post how I have dzen integrated with xmonad + the other two dzen bash scripts that launch the mail/calendar popups.

I am smile

Haven't checked this thread in awhile. I'm assuming you're the guy who msged me on IRC not too long ago.

When my semester ends, I'll replace this post with all the goodies. I have found a few bugs since my original post. Hopefully I can fix them too. smile

Offline

#290 2012-12-02 13:57:12

gotmor
Member
From: Germany
Registered: 2007-09-03
Posts: 84
Website

Re: dzen & xmobar Hacking Thread

Hey guys,

new feature in dzen2:

- clickable areas support in the slave window

fixes:

- fixed a clickable area bug
- flush on print command

Thanks to TheUnknownCylon and Alexander Sulfrian for submitting those.

You can find the latest code on Github:  http://github.com/robm/dzen


Have fun, Rob.

Offline

#291 2013-08-05 11:04:43

hddnhrst
Member
From: Germany
Registered: 2012-11-20
Posts: 26

Re: dzen & xmobar Hacking Thread

Hello,

I have a question about xmobar and Network command:

Run DynNetwork ["-t", "<rx>|<tx>KB", "--High", "800", "-h", "red" ] 10

Is there a way to have 2 different high threshold values for reception and transmission rate?

My reception rate is significantly lower than my transmission rate, my reception rate will never reach the high threshold.
If I lower the high threshold so my reception rate can reach it, then my transmission rate will exceed it too easily...

Is there a solution for this? Or does this work different?

[edit] nvm I keep it green if > 0 like so:

Run DynNetwork ["-t", "<rx>|<tx>KB", "--Low", "0", "-n", "green" ] 10

big_smile

Last edited by hddnhrst (2013-08-05 14:02:54)

Offline

#292 2013-09-10 16:13:22

ondoho
Member
Registered: 2013-04-30
Posts: 302

Re: dzen & xmobar Hacking Thread

hello,
i have a question about dzen2:
i can't find documentation on all possible commands that can be piped into dzen, like ^ca(1, command to execute) for interactive areas (i found that in a script), and then i'd think there'd be a way to change the font... i think i read the whole wiki on github... no manpage either...
did i miss something?

Offline

#293 2013-09-12 17:32:50

ondoho
Member
Registered: 2013-04-30
Posts: 302

Re: dzen & xmobar Hacking Thread

found it: http://dzen.googlecode.com/svn/trunk/README

especially the in-text-formating is not in the wiki (yet), but in this readme.

Offline

#294 2013-11-26 19:03:03

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,221
Website

Re: dzen & xmobar Hacking Thread

It is now possible to have clickable areas in xmobar using the UnsafeStdinReader plugin,

http://projects.haskell.org/xmobar/#other-plugins

Below is a working example where clickable workspaces are implemented.

xmonad.hs

import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeys)
import System.IO
myManageHook = composeAll
    [ className =? "Gimp"     --> doFloat
    , className =? "rdesktop" --> doFloat
    ]
 
xmobarEscape = concatMap doubleLts
  where doubleLts '<' = "<<"
        doubleLts x   = [x]
 
myWorkspaces :: [String]        
myWorkspaces = clickable . (map xmobarEscape) $ ["1","2","3","4","5"]
                                                                              
  where                                                                      
         clickable l = [ "<action=xdotool key alt+" ++ show (n) ++ ">" ++ ws ++ "</action>" |
                             (i,ws) <- zip [1..5] l,                                        
                            let n = i ]
main = do
    xmproc <- spawnPipe "xmobar /home/regj/.xmobarrc"
    xmonad $ defaultConfig
        { manageHook = manageDocks <+> myManageHook -- make sure to include myManageHook definition from above
                        <+> manageHook defaultConfig
        , layoutHook = avoidStruts  $  layoutHook defaultConfig
        , workspaces = myWorkspaces
        , logHook = dynamicLogWithPP xmobarPP
                        { ppOutput = hPutStrLn xmproc
                        , ppCurrent = xmobarColor "yellow" "" . wrap "[" "]"
                        , ppHiddenNoWindows = xmobarColor "grey" ""
                        , ppTitle   = xmobarColor "green"  "" . shorten 40
                        , ppVisible = wrap "(" ")"
                        , ppUrgent  = xmobarColor "red" "yellow"
                        }
        , modMask = mod1Mask     -- Rebind Mod to the Alt key
        } `additionalKeys`
        [ ((mod1Mask, xK_f), spawn "firefox")
        , ((mod1Mask, xK_Print), spawn "/home/regj/bin/scrotter")
        , ((mod1Mask, xK_Return), spawn "urxvt")
        ]

xmobarrc:

Config { font = "xft:Dina:pixelsize=13"
       , bgColor = "black"
       , fgColor = "grey"
       , position = TopW L 100
       , lowerOnStart = True
       , commands = [ Run Cpu ["-L","3","-H","50","--normal","green","--high","red"] 10
                    , Run Memory ["-t","Mem: <usedratio>%"] 10
                    , Run Swap [] 10
                    , Run Date "%a %b %_d %H:%M" "date" 10
                    , Run UnsafeStdinReader
                    ]
       , sepChar = "%"
       , alignSep = "}{"
       , template = "%UnsafeStdinReader% }{ %cpu% | %memory% * %swap%    <fc=#ee9a00>%date%</fc>"
       }

Extra tidbits and reference found here: www.arch-ed.dk/xmobar-clickable-workspaces/

Offline

#295 2014-02-03 23:38:35

archerie
Member
Registered: 2014-02-01
Posts: 2

Re: dzen & xmobar Hacking Thread

Hi, I'm trying out dzen2 with Ubuntu 13.10 (using default Unity, not Xmonad or anything), how can I get dzen2 not to sit on top of other parts of the screen? Can I get the rest of my screen to move down and make room for this bar at the top, for example? I tried the -dock flag but that didn't change anything.

Offline

#296 2014-02-06 17:26:04

easysid
Member
From: India
Registered: 2013-01-01
Posts: 224

Re: dzen & xmobar Hacking Thread

A calendar popup widget for dzen2

# pop-up calendar for dzen
#
# based on (c) 2007, by Robert Manea
# http://dzen.geekmode.org/dwiki/doku.php?id=dzen:calendar
# modified by easysid 
# Use fifo pipe to change month

FONT="dejavu sans mono"
FONTSIZE="10"
PAD='  '
ACT='onstart=uncollapse;button1=exit;button3=exit'

# Colors
FG="#a0a0a0"
BG="#202020"
highlight="#ffffff"
highlight2="#3f3f3f"

WIDTH=150
LINES=8
XPOS=1194
YPOS=30

# define pipe
PIPE=/tmp/calendar_pipe

TODAY=$(expr `date +'%d'` + 0)
MONTH=$(date +'%m')
YEAR=$(date +'%Y')

MM=${1:-"$MONTH"}
YY=${2:-"$YEAR"}
NEXT=$((MM+1))
PREV=$((MM-1))
let Y_NEXT=Y_PREV=YY

if [[ $NEXT -eq 13 ]]; then
    NEXT=1
    Y_NEXT=$((YY+1))
fi

if [[ $PREV -eq 0 ]]; then
    PREV=12
    Y_PREV=$((YY-1))
fi

# generate calender
if [[ "$MM" -eq "$MONTH" ]] && [[ "$YY" -eq "$YEAR" ]]; then  # current month, highlight header and date
    CAL=$(cal | sed -re "s/^(.*[A-Za-z][A-Za-z]*.*)$/^fg($highlight)\1^fg()/;s/(^|[ ])($TODAY)($|[ ])/\1^bg($highlight2)^fg($highlight)\2^fg()^bg()\3/")
else  # another month, just highlight header
    CAL=$(cal "$MM" "$YY" | sed -re "s/^(.*[A-Za-z][A-Za-z]*.*)$/^fg($highlight)\1^fg()/")
fi

# read from pipe
if [ ! -e "$PIPE" ]; then
  mkfifo "$PIPE"
  ( dzen2 -u -bg $BG -fg $FG -fn "${FONT}:pixelsize=${FONTSIZE}" -x $XPOS -y $YPOS -w $WIDTH -l $LINES -sa 'c' -e "$ACT" -title-name 'popup_calendar' < "$PIPE"
   rm -f "$PIPE") &
fi

# feed the pipe
(
echo "$CAL"
echo "^ca(1, $0 $PREV $Y_PREV)<<Prev^ca()  ^ca(1, $0 $NEXT $Y_NEXT)Next>>^ca()"
sleep 10s
) > "$PIPE"

Offline

#297 2014-05-09 06:27:50

jonascj
Member
Registered: 2014-02-28
Posts: 13

Re: dzen & xmobar Hacking Thread

Hi guys

Do you know if it is possible to "to import variables" into the xmobar config file (xmobarrc). By import I mean that I keep a set of colors in both a Haskell module (for use in xmonad config) and the same colors in a shell script and I would like to import either one of them into xmobarrc so I can do specify base02 instead of #00a244. This would allow me to keep all xmobar+trayer+xmonad colors located a central place (I change color schemes on the fly).

The syntax of xmobarrc looks like Haskell, but that doesn't mean I can import a Haskell module. And if it is a text file with custom syntax (and a custom parser) it will of course not allow me to source a file like in a shell script.

Offline

#298 2015-12-30 20:46:10

cameo
Member
Registered: 2012-08-18
Posts: 54

Re: dzen & xmobar Hacking Thread

Yeah cool dzen, i haz it!

Once I looked for a (simple) weather script to pipe icons to dzen. "shaman" was not my taste, and I couldn't find any other. So I thought, it mustn't be too difficult to write one myself. And that’s now, what has come out of it – the mws (mito’s wx scripts) collection!

Finally they became four, from simple to complex, hope you don’t mind. Also that I became pretty garrulous by spending much effort on comments. But NP, I know all of you guys cope with Bash. Hence the first you would probably do is to eridicate half of the code, or even rewrite it.

Anyway for those who find the scripts useful, help yourself and adapt them to your needs. Yet there’re cases for parsing weather data from NWS, OMW, and yr.no, feel free to add another service. Or to localize a script for your language. – If there aren’t icons that can’t be downloaded as a whole set, one of the scripts shows how to download and convert the current icon on the fly (however I wished dzen supports PNG).


Find the resources here:      dAmws_screen2_preview_by_mitoxd-d9m2bea.gif        githubmws_demo_preview150px_by_mitoxd-d9m2bel.jpg

Offline

#299 2015-12-30 21:06:53

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,532
Website

Re: dzen & xmobar Hacking Thread

Those scripts would be much much less resource intensive if you just made one call to curl the needed url, then parse the result locally.  Currently it grabs the exact same full web resource 4 times just to get 4 different bits of information out of it.  Also grep + tr + awk + tr = awk.


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#300 2015-12-30 21:11:20

cameo
Member
Registered: 2012-08-18
Posts: 54

Re: dzen & xmobar Hacking Thread

*blushes*  Yet I don't have any experience with curl. Could you give an example?

Offline

Board footer

Powered by FluxBB