[openbox] switch to a window and then switch back

Łukasz Grabowski graboluk at gmail.com
Mon Dec 26 07:59:08 EST 2016


> <keybind key="C-A-s">
> 	<action name="NextWindow">
> 		<allDesktops>yes</allDesktops>
> 		<interactive>no</interactive>
> 		<dialog>none</dialog>
> 	</action>
> </keybind>

How would that possibly work to bring up specifically firefox window?
Or do you mean to have the above plus some firefox-specific binding?

Best,
Ł

P.S. For a record, what I ended up doing is the following script under C-A-s. I've been actually reasonably happy with it for the last couple of months and I have now similar scripts for terminal and geany. To recap: C-A-s brings up firefox, then C-A-s switches back to the previous window. I gave up on the "break up the chain" idea - partially because I could see no clear way to implement it, but also because I think it's not as useful as my current setup (for example when I'm in a pdf viewwer, I press C-A-s to go to firefox, then actually I press arrow-down few time.to find what I want in firefox, then I press C-A-s to go back to pdf viewer again - so in fact  "breaking the chain" with arrow-down would be undesirable here) 

#!/bin/bash

NAME="main-iceweasel"
CLASS_PREFIX="Navigator"
CLASS_SUFFIX="Firefox"

CLASS="$CLASS_PREFIX.$NAME" 
FIREFOX_CLASS="$CLASS_PREFIX.$CLASS_SUFFIX"

ACTIVE_WIN_ID_UNNORMALIZED=$(printf '%x\n' $(xdotool getactivewindow))
ACTIVE_WIN_ID=`wmctrl -lx | grep $ACTIVE_WIN_ID_UNNORMALIZED | awk '{print $1}' | awk '{$1=$1}1'`
ACTIVE_WIN_CLASS=`wmctrl -lx | awk -v winid="$ACTIVE_WIN_ID" '{if ($1==winid) print $3}'`

FIREFOX_WINDOWS=`wmctrl -lx | awk -v winclass="$FIREFOX_CLASS" '{if ($3==winclass) print $0}'`
MAIN_FIREFOX_WIN_ID=`wmctrl -lx |awk -v winclass="$CLASS" '{if ($3==winclass) print $1}'` 


# for debugging
#~ echo "$CLASS"
#~ echo "$FIREFOX_CLASS"
#~ echo "$ACTIVE_WIN_ID_UNNORMALIZED"
#~ echo "$ACTIVE_WIN_ID"
#~ echo "$ACTIVE_WIN_CLASS"
#~ echo "${FIREFOX_WINDOWS[0]}"
#~ echo "$MAIN_FIREFOX_WIN_ID"


# if no windows with main-iceweasel class but there are firefox windows 
# then call the first main-iceweasel
if [ ! ${#FIREFOX_WINDOWS} -eq 0 ] && [[ -z "$MAIN_FIREFOX_WIN_ID" ]]; then
    MAIN_FIREFOX_WIN_ID=`echo "${FIREFOX_WINDOWS[0]}" | awk '{print $1}'`
    xdotool set_window --class "$NAME" "$MAIN_FIREFOX_WIN_ID"
fi

# switch back routine:

if [[ "$ACTIVE_WIN_CLASS" == "$CLASS" ]] && [ "$ACTIVE_WIN_ID" != 0 ]; then
    read LAST_ACTIVE_WIN_ID < ~/.last_active_win_"$NAME"
    wmctrl -i -a "$LAST_ACTIVE_WIN_ID"
    exit
fi

# if main-iceweasel exists but it is not active then raise it and
# remember where we came from
if [ ! -z "$MAIN_FIREFOX_WIN_ID" ]; then
    wmctrl -i -a "$MAIN_FIREFOX_WIN_ID"
    echo "$ACTIVE_WIN_ID" >~/.last_active_win_"$NAME"
    exit
fi

# otherwise start firefox
wmctrl -s0
iceweasel &
exit




> 
> I say "sadly" because, depending on how you switch window focus,
> Openbox does not properly update window focus history.  I call wmctrl
> from scripts, for example, and the "previous" window ends up being
> two (or more) windows ago.
> 
> However, if you perform your window switching exclusively through
> Openbox, I believe this binding will suit your needs.
> _______________________________________________ openbox mailing list
> openbox at icculus.org
> http://icculus.org/mailman/listinfo/openbox


More information about the openbox mailing list