Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved] How to mimic "Win+NUM" (Windows feat.) in Fluxbox?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
solamour
Guru
Guru


Joined: 21 Dec 2004
Posts: 484
Location: San Diego, CA

PostPosted: Mon Oct 07, 2013 12:24 am    Post subject: [Solved] How to mimic "Win+NUM" (Windows feat.) in Reply with quote

I still use Windows (7 and 8, to be specific), and one thing I somewhat miss is "Win + NUM" shortcut. Basically you pin your favorite programs to the taskbar, and when you press, say, "Win+1", the first pinned program shows up. If it's not already running, Windows starts the program and brings it to the front; if the program is already running, Windows just brings it to the front.

How do I perform the same task in either GNOME desktop or Fluxbox? What I have so far is to use "wmctrl -l -x" to list up currently running programs, look for a specific one based on program's name and window title. If it's already running, bring it to the front, and if not, start the program. Somewhat crude, but it works as long as the program's titles don't change. Well, they do change, and that's where it stops working.

Please share your suggestions. Thank you.
__
sol


Last edited by solamour on Sun Oct 13, 2013 3:14 am; edited 1 time in total
Back to top
View user's profile Send private message
nemectic
Apprentice
Apprentice


Joined: 20 Aug 2004
Posts: 181

PostPosted: Wed Oct 09, 2013 10:01 pm    Post subject: Reply with quote

If you're using win+num to launch the program, you could script it to get the PID when launched and store that in a variable, then the next time you press the key look if the PID is still alive, if not look for a program by the same name, else launch a new program.

Just a crude fix, but maybe a slight improvement until you figure something better?
Back to top
View user's profile Send private message
solamour
Guru
Guru


Joined: 21 Dec 2004
Posts: 484
Location: San Diego, CA

PostPosted: Sun Oct 13, 2013 3:13 am    Post subject: Reply with quote

Saving PID on initial launch seems like to great suggestion, but it didn't work for me well, because even if I know the program is already running, in order to bring it in front of others, I need to use "wmctrl -i -a $win_id" where $win_id is the window ID (not PID) managed by the window manager. I have to look though the available windows anyway.

I ended up writing a script with a bunch of if/else statements. It's definitely not going to win any beauty contest, but it works for my purpose, so I'm going to keep it as is until I find something more elegant.

Thanks everyone for taking time to read and respond.
Code:
myhotkey.sh

#!/bin/bash

prog=$1
full_path=$2
file=${full_path##*/}       # Remove longest front.
win_id=0
IFS=$'\n'                   # Split based on newline, not space.


for line in $(wmctrl -l -x); do
    # 0x00c00005  0 gnome-terminal.Gnome-terminal  que solamour@gentoo: ~
    # |--------|    |------------| |------------|      |--------------|
    #   win_id         wm_class       wm_extra             wm_title
    #               |---------------------------|
    #                       wm_class_full
    #
    wm_class_full=$(echo $line | awk '{print $3}')
    wm_class=${wm_class_full%.*}    # Remove shortest back.
    wm_extra=${wm_class_full##*.}   # Remove longest front.
    wm_title=$(echo $line | awk '{print $5}')

    if [ "${wm_class,,}" = "$prog" ]; then
        if [ "$wm_title" = "$file" -o \
             "$wm_class" = 'nautilus' -o \
             "$wm_class" = 'Eclipse' -o \
             "$wm_class" = 'evince' -o \
             "$wm_class" = 'gimp'  ]; then

            win_id=${line%%\ *}         # Remove longest back.
            break
        fi
    fi
done


if (($win_id)); then        # Found in wmctrl.
    wmctrl -i -a $win_id    # Activate window.
else
    if [ "$prog" = 'gnome-terminal' ]; then
        gnome-terminal --geometry=80x32 &
    elif [ "$prog" = 'firefox' ]; then
        /usr/bin/firefox &
    elif [ "$prog" = 'nautilus' ]; then
        /usr/bin/nautilus &
    elif [ "$prog" = 'eclipse' ]; then
        ~/eclipse/eclipse &
    elif [ "$prog" = 'evince' ]; then
        /usr/bin/evince &
    elif [ "$prog" = 'gimp' ]; then
        /usr/bin/gimp &
    fi
fi


Code:
~/.fluxbox/keys
Mod4 e :Exec myhotkey.sh nautilus
Mod4 f :Exec myhotkey.sh firefox
Mod4 6 :Exec myhotkey.sh gimp
Mod4 8 :Exec myhotkey.sh evince
Mod4 9 :Exec myhotkey.sh eclipse
etc...

__
sol
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum