You are not logged in.

#1 2014-12-15 00:16:21

raul_l
Member
From: Amsterdam
Registered: 2014-11-04
Posts: 58

[Solved] How to list recently used windows?

I like the Unity feature where a key binding either opens or focuses an application window. With KDE I can define a keyboard shortcut which, for example, performs

wmctrl -xa emacs.Emacs || emacs

However, I'd like it to focus on the last focused window, not the first opened window. Is there a command to list all windows in the order they were recently used? (Clearly the Task Switcher gets this information from somewhere.)

Last edited by raul_l (2014-12-16 16:58:24)


Raul Laasner

Offline

#2 2014-12-16 16:48:30

raul_l
Member
From: Amsterdam
Registered: 2014-11-04
Posts: 58

Re: [Solved] How to list recently used windows?

The command I was looking for is

xprop -root | grep "^_NET_CLIENT_LIST_STACKING"

If anyone is interested, this script

#!/bin/bash

app=$1
workspace=$(wmctrl -d | grep '\*' | cut -d ' ' -f1)
win_list=$(wmctrl -lx | grep $app | grep " $workspace " | awk '{print $1}')

IDs=$(xprop -root|grep "^_NET_CLIENT_LIST_STACKING" | tr "," " ")
IDs=(${IDs##*#})

for (( idx=${#IDs[@]}-1 ; idx>=0 ; idx-- )) ; do
    for i in $win_list; do
	if [ $((i)) = $((IDs[idx])) ]; then
	    wmctrl -ia $i
	    exit 0
	fi
    done
done
    
exit 1

in conjunction with the key binding

the_above_script.sh emacs.Emacs || emacs

produces the correct Unity behavior. (How to mark this thread solved?)

EDIT: I modified the script a little bit. It turns out wmctrl and xprop use slightly different formats for displaying hexadecimal numbers.

Last edited by raul_l (2014-12-17 12:08:07)


Raul Laasner

Offline

#3 2014-12-16 16:52:40

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,019

Re: [Solved] How to list recently used windows?

Edit your first post to change the title.

Offline

Board footer

Powered by FluxBB