Search code examples
linuxshow-hidexdotool

Hiding active window in linux


I have written a small script to hide a Chrome window but want to modify the code to hide the active window. I can use xdotool to get the active window id and hide it. I run into problems when I want to unhide it. How do I check for a hidden window and get the id so I can unhide it? Here is my current code for just hiding chrome:

  #!/bin/bash

wid=`xdotool search --name Chrome|head -1`
wstate=`xwininfo -id $wid | grep "Map State:"`

if [[ "$wstate" == *IsViewable ]]
then
    xdotool windowunmap $wid
else
    xdotool windowmap $wid
fi

Solution

  • Thank you @funivan ! That got me going in the right direction. I am mapping the script to one of my mouse side buttons using xbindkeys. I changed the script a little so I can run the same command to hide or unhide a window.

    #!/bin/bash
    
    file=/tmp/last_active_window
    if [[ -s $file ]] ; then
        xdotool windowmap `cat $file`
        cat /dev/null > $file
    else 
        wid=`xdotool getactivewindow`      
        xdotool windowunmap $wid
        echo $wid > $file
    fi