Re: [dev] [dwm] NetActiveWindow

From: Peter John Hartman <peterjohnhartman_AT_gmail.com>
Date: Thu, 14 Apr 2011 09:31:52 -0400

On Thu, Apr 14, 2011 at 10:37:31AM +0200, Andreas Amann wrote:
> Sure, see below. I also paste the new version of the patch which now only
> switches on the tags of the selected window. Another option would be to tag
> the window with the currently visible tags (see what is commented out in the
> patch). I prefer the first option which works great for me, thanks again!

The patch itself is perfect. I'd vote this one to go into trunk.

There is one small problem with the shell script (well two):

> -------------- listwin.sh ---------------------
>
> #!/bin/sh
>
> foo=$(for i in $(xdotool search --onlyvisible --classname ".+"); do
> win_id="${i}"
> win_class=$(xprop -id ${win_id} WM_CLASS | cut -d'"' -f2)
> win_title=$(xprop -id ${win_id} _NET_WM_NAME | cut -d'"' -f2)
> printf "%10.10s | %30.30s | %8.8d\n" "${win_class}" "${win_title}" "${win_id}"
> done |sort| dmenu -i -l 10)
> if [ $? -eq 0 ]; then
> xdotool windowactivate $(echo $foo | awk -F'|' '{ print $NF }')
> fi

First:

     win_title=$(xprop -id ${win_id} _NET_WM_NAME | cut -d'"' -f2)

This should rather be something like:

    win_title=$(xprop -id $win_id _NET_WM_NAME | cut -d'=' -f2)

If a _NET_WM_NAME has a " in it, it'll break.

Second:

         printf "%10.10s | %30.30s | %8.8d\n" "${win_class}" "${win_title}" "${win_id}"

This should rather be:

        printf "%10.10s | %30.30s | %d\n" "${win_class}" "{$win_title}" "{$win_id}"

%8.8d added an extra zero to the front of 7 digit win ids.

Other than that, things look great. Here's a little trick I use to also
have dmenu have the precise length of the number of windows:

#!/bin/sh

listing=$(xdotool search --onlyvisible ".+" 2>/dev/null)
count=$(echo "$listing" | wc -l)
foo=$(for i in $listing; do
        win_id=$i
        win_class=$(xprop -id $win_id WM_CLASS | cut -d'"' -f2)
        win_title=$(xprop -id $win_id _NET_WM_NAME | cut -d'=' -f2)
        printf "%10.10s | %120.120s | %d\n" "$win_class" "$win_title" "$win_id"
done | sort | dmenu -i -l $count)

if [ $? -eq 0 ]; then
        xdotool windowactivate $(echo $foo | awk -F'|' '{print $NF }')
fi

-- 
sic dicit magister P
PhD Candidate
Collaborative Programme in Ancient and Medieval Philosophy
University of Toronto
http://individual.utoronto.ca/peterjh
Received on Thu Apr 14 2011 - 15:31:52 CEST

This archive was generated by hypermail 2.2.0 : Thu Apr 14 2011 - 15:36:02 CEST