This forum has been archived. All content is frozen. Please use KDE Discuss instead.

HOWTO? - few window actions for single shortcut

Tags: None
(comma "," separated)
anli
Registered Member
Posts
73
Karma
0
OS
I'd want to assign few window actions for single shortcut. In particular, I'd want to move current window to desktop N and switch to this desktop N.

How to?

I have tried to find appropriate dbus commands but have found one for the second step only:

qdbus org.kde.kwin /KWin org.kde.KWin.setCurrentDesktop 1

How to move current window? Would it be possible, I can just call any commands I want in bash script and assign a shortcut for the script executing.

More common. Is there some kind of documentation related to advanced KDE windows manipulation from user's perspective?
anli
Registered Member
Posts
73
Karma
0
OS
OK, have found. Without any KDE-specifics:

Code: Select all
#!/bin/bash

wmctrl -r :ACTIVE: -t $1
wmctrl -s $1

Here the script argument is just desktop number starting form 0. So you can, say, assign 'Win+1' shortcut to 'theScriptName 0'.
User avatar
Wizard
Registered Member
Posts
99
Karma
0
OS
Nice trick. Seems it's pretty useful and powerful thing :)
anli
Registered Member
Posts
73
Karma
0
OS
There is a problem when no app's window is selected (i.e. desktop is selected). I'm on the way to resolve this issue. Will report later...
anli
Registered Member
Posts
73
Karma
0
OS
This is the next version. I'm not bash script writer. Any critics is appreciated.

Code: Select all
#!/bin/bash

IFS=$'\n'

win_id=$(xprop -root | grep '_NET_ACTIVE_WINDOW(WINDOW)' | awk '{print $5}')
win_id_tail=$(echo $win_id | sed 's/^0x//')

windows=$(wmctrl -l)
win_dsk=""

for X in ${windows[@]} ; do
  win_dsk=$(echo "$X" | grep "$win_id_tail" | awk '{print $2}')
  if [[ $win_dsk ]] ; then
    break
  fi
done

if [[ -z "$win_dsk" ]] ; then
  #echo "current desktop not defined, skipping.."
  exit 0
fi

current_dsk=$(wmctrl -d | grep \* | awk '{print $1}')
if [[ "$1" == "$current_dsk" ]] ; then
    #echo "the same desktop, skipping.."
    exit 0
fi

if [[ $win_dsk == "-1" ]]  ; then
  #echo "sticky window, skipping.."
  exit 0
fi

#echo "switching to $1"
wmctrl -r :ACTIVE: -t $1
wmctrl -s $1


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]