[openbox] switch to a window and then switch back

Łukasz Grabowski graboluk at gmail.com
Mon Sep 26 07:54:04 EDT 2016


I've modified my script (below) so that last window id is stored in a file.

Now it works okayish+1. The only exception when it's not ok is when
you are at the iceweasel window and (by accident) you press C-A-s. The
required behaviour should be "doing nothing", but the script will take
you to the window which was active when you last pressed C-A-s.

Best,
Ł

#!/bin/bash

CLASS="Navigator.main-iceweasel"
FIREFOX_CLASS="Navigator.Firefox"

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 main-iceweasel "$MAIN_FIREFOX_WIN_ID"
fi

if [[ "$ACTIVE_WIN_CLASS" == "$CLASS" ]] && [ "$ACTIVE_WIN_ID" != 0 ]; then
    #~ xdotool key "alt+ctrl+shift+Tab"
    read LAST_ACTIVE_WIN_ID < ~/last_active_win
    wmctrl -i -a "$LAST_ACTIVE_WIN_ID"
    #~ wmctrl -i -r $ACTIVE_WIN_ID -b add,hidden
    exit
fi

# it main-iceweasel exists but it is not active then raise it
if [ ! -z "$MAIN_FIREFOX_WIN_ID" ]; then
    wmctrl -i -a "$MAIN_FIREFOX_WIN_ID"
    echo "$ACTIVE_WIN_ID" >~/last_active_win
    exit
fi

# otherwise start firefox
wmctrl -s0
iceweasel &
exit

2016-09-26 12:12 GMT+01:00 Łukasz Grabowski <graboluk at gmail.com>:
> TT wrote:
>> also it would be nice to see how you achieve what you have atm!
>
> I paste my toggle-main-iceweasel script which I have under C-A-s
> below. Presumably a lot of it can be done directly in openbox 3.6
> using "If" action, but I'm on 3.5.
>
>> Lukasz: I am pretty sure that your particular scenario would require
>> a script, in other words openbox cannot do it as such.
>
> The problem I have to script it is that it requires remembering the state: i.e.
> the second C-A-s should switch back only if it really is the second one.
>
> Mikael Magnusson wrote:
>> As long as you're only switching between two desktops, you can use go
>> to last desktop in both directions.
>
> I think it's unrealistic  and inconvenient to have a desktop _only_
> for firefox. Sooner or later something is bound to appear there, a pdf
> viewer, terminal etc., so the solution should not assume that one is
> on a desktop which is different than firefox's desktop.
>
> btw, don't treat it to seriously, but if I was willing to bend my
> workflow to a window manager I'd be using apple or gnome or whatever
> :-). The whole point of using openbox for me is that it's so flexible
> in adjusting to whatever I see as the best workflow of the month.
>
> Best,
> Ł
>
> ----toggle-main-iceweasel----
> #!/bin/bash
>
> CLASS="Navigator.main-iceweasel"
> FIREFOX_CLASS="Navigator.Firefox"
>
> 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 main-iceweasel "$MAIN_FIREFOX_WIN_ID"
> fi
>
> # if active window is main-iceweasel then hide it
> if [[ "$ACTIVE_WIN_CLASS" == "$CLASS" ]] && [ "$ACTIVE_WIN_ID" != 0 ]; then
>     wmctrl -i -r $ACTIVE_WIN_ID -b add,hidden
>     exit
> fi
>
> # if main-iceweasel exists but it is not active then raise it
> if [ ! -z "$MAIN_FIREFOX_WIN_ID" ]; then
>     wmctrl -i -a "$MAIN_FIREFOX_WIN_ID"
>     exit
> fi
>
> # otherwise start firefox
> wmctrl -s0
> iceweasel &
> exit


More information about the openbox mailing list