LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 07-03-2009, 12:32 PM   #1
devdol
Member
 
Registered: Dec 2005
Distribution: debian (testing/unstable)
Posts: 68

Rep: Reputation: 17
Post minimize all windows EXCEPT the active one (toggle)


Most Window Managers come with an "Show Desktop" feature, that will toggle all non-minimized (-iconized) Windows to minimized and back.
Futhermore, in KDE3 we had the possibility to script it by:

Code:
dcop kicker kicker toggleShowDesktop
In KDE4, this obviously does not work anymore, we are left off with a button that eats up valuable space in the task bar.

M$ is ostentatiously about a new feature in W****** 7 which does the same but leaves the active window untouched. For this, you have to "shake" the windows (which is quite tedious in comparison to some hotkey).

This really could be handy e.g. if you are working in a file manager (or browser) and want temporarily access to your desktop to place a link there.
And the most comfortable way should be a plain shell script that can be assigned to a hotkey at discretion.

Well, first I thought this would be an easy job to to. The idea is clear and presented below, but far from working as expected. As it took more than an hour of searching and trying to find a method how to determine the active window, I leave the 'pseudocode ' here - maybe we work it out collaboratively...


Code:
 # Minimize/restore all windows except the active one
 UNDOSCRIPT="$0.data"
 
 # Determine whether we have to minimize or to restore in this run
 if [ -f "$UNDOSCRIPT" ]
  then # restore previously minimized windows and forget the past
       sh "$UNDOSCRIPT"
       rm "$UNDOSCRIPT"
  else # minimize all but active window
       # Determine the active window
        activeWinIdLine=`xprop -root | grep _NET_ACTIVE_WINDOW\(WINDOW\) `
        activeWinId="${activeWinIdLine:40}"
       # Store a list of currently existing windows by IDs
        allWindowsIds=`wmctrl -l | cut -f1 --delimiter=" " `
 
       for wnd in $allWindowsIds
       do  # check whether this window is minimized yet
 	 xwininfo -id $wnd -all | grep -q "Map State: IsViewable"
 	 if [ $? -lt 1 ]
 	    then # build a list of currently viewable windows that we have to minimize
 	       unminimizedWindIDs="$unminimizedWindIDs $wnd"
 	    fi
       done
 
       # Minimize all windows except the active one
        xwit -iconify -all
        wmctrl -i -a $activeWinId
 
       # Now we minimize normal and maximized windows and create a script to undo all that the next run
       echo > $UNDOSCRIPT # To be sure it is empty first
       for wnd in $unminimizedWindIDs
 	 do
 	   echo "wmctrl -i -a $wnd" >> "$UNDOSCRIPT"
 	 done
       echo wmctrl "-i -a $activeWinId" >> "$UNDOSCRIPT" # When restoring, we finally have to restore the original focus
  fi

Last edited by devdol; 07-03-2009 at 12:36 PM. Reason: more details
 
Old 07-03-2009, 02:12 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
"xdotool getactivewindow" will give you the window id of the currently-focused window.

Last edited by David the H.; 07-03-2009 at 02:14 PM.
 
Old 07-03-2009, 04:39 PM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
I guess you want this for kde, or are you open to alternative -scriptable- window managers?

In fvwm I'd do

Code:
All (!Focused) Iconify on

Last edited by i92guboj; 07-03-2009 at 04:41 PM.
 
  


Reply

Tags
desktop, manage, script, toggle



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Minimize active window in KDE? Ander Linux - General 4 07-25-2019 03:15 AM
How to minimize all windows? mfeat Red Hat 16 10-31-2017 08:49 PM
Windows minimize to ---nowhere? DougC Fedora 7 10-24-2015 03:52 AM
Minimize all windows tranh2 Linux - Newbie 2 08-28-2006 06:59 PM
Toggle between Linux & windows ppkamma Linux - Newbie 4 05-31-2006 02:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 11:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration