[wmii] Re: Best way to select a particular client?

From: Jeremy Hankins <nowan_AT_nowan.org>
Date: Tue, 23 May 2006 15:09:53 -0400

"Anselm R. Garbe" <garbeam_AT_wmii.de> writes:

> Thus they always end up in www. Now you can define exactly what
> you want with:

There were a couple of problems with that, but here's what I tried:

$MODKEY-w)
      if wmiir read /www 2>/dev/null; then
            xwrite /ctl view www
      else
            firefox & #firefox not running
      fi ;;

This isn't really what I want, though. Instead of being task-oriented,
the tags are application-oriented. So, for example, I can't have a
setup like above for firefox and xterm, and then display an xterm next
to a firefox window, switching back and forth with mod-w & mod-return.

> Hope this gives you some inspirations.

Yes, actually. ;)

I evidently didn't poke around hard enough before. The tools for
switching around between windows are all there, it's just a matter of
putting them together. I've attached the result, for anyone who's
interested. It allows you to say "go_class Firefox-bin firefox", and if
there's a firefox displayed somewhere you'll be switched to it,
otherwise it will be run. It's a bit brute-force, I'm afraid, so it may
not scale well for folks with lots and lots of windows. But it does
seem to work. (TODO: repeated invocations should cycle if there are
multiple matches.)

########################################################################
#
# Time-stamp: <2006-05-23 14:40:48 Jeremy Hankins>
#
# The go_class and go_name functions can be used to find and select a
# client window that matches the first argument. If no such client
# exists, the executable (the remaining argument(s)) is run.
#
########################################################################

# {{{ xwrite & xread

xwrite () {
    file="$1"; shift
    echo -n "$@" | wmiir write "$file"
}

xread () {
    file="$1"; shift
    wmiir read $file
}

# }}}
# {{{ match_class & match_name

match_class () {
    for view in `xread /tags`; do
        for area in `xread /$view | awk '{print $NF}' | grep '^[0-9]*$'`; do
            for client in `xread /$view/$area | awk '{print $NF}' | grep '^[0-9]*$'`; do
                if xread /$view/$area/$client/class | grep -q "^$1:"; then
                    # Could break out here, but an exhaustive list may
                    # be useful at some point to implement cycling of
                    # the hits.
                    echo /$view/$area/$client
                fi
            done
        done
    done
}

match_name () {
    for view in `xread /tags`; do
        for area in `xread /$view | awk '{print $NF}' | grep '^[0-9]*$'`; do
            for client in `xread /$view/$area | awk '{print $NF}' | grep '^[0-9]*$'`; do
                if xread /$view/$area/$client/name | grep -q "$1"; then
                    # Could break out here, but an exhaustive list may
                    # be useful at some point to implement cycling of
                    # the hits.
                    echo /$view/$area/$client
                fi
            done
        done
    done
}

# }}}
# {{{ switch_to

switch_to () {
    view=`echo $1 | awk -F / '{print $2}'`
    area=`echo $1 | awk -F / '{print $3}'`
    client=`echo $1 | awk -F / '{print $4}'`

    xwrite /ctl view $view
    xwrite /$view/ctl select $area
    xwrite /$view/$area/ctl select $client
}

# }}}
# {{{ go_class & go_name

go_class () {
    class=$1; shift

    match=`match_class $class | head -1`
    if [ -z "$match" ]; then
        $@ &
        #sh -c "$@"
    else
        switch_to $match
    fi
}

go_name () {
    name=$1; shift

    match=`match_name $name | head -1`
    if [ -z "$match" ]; then
        $@ &
    else
        switch_to $match
    fi
}

# }}}

## Local Variables:
## mode:sh
## folded-file:t
## End:

-- 
Jeremy Hankins <nowan_AT_nowan.org>
PGP fingerprint: 748F 4D16 538E 75D6 8333  9E10 D212 B5ED 37D0 0A03
Received on Tue May 23 2006 - 21:10:28 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 16:06:40 UTC