Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bonnebulle/3714f2b9d547055402557247bcf5e4ec to your computer and use it in GitHub Desktop.
Save bonnebulle/3714f2b9d547055402557247bcf5e4ec to your computer and use it in GitHub Desktop.
#!/bin/bash
#### HERE... hide all but NOT Focused ONE
#### IF all are already minimized... raise.maximised them all back
# Alt to :: SHOW/HIDE (TOGGLE) Desktop
#if [ $status == "ON" ]; then
# wmctrl -k off
#else
# wmctrl -k on
#fi
fene=0
hfene=0
hhf=0
### BEFORE changing Min/Max
### count already minimized
for u in $(wmctrl -l | awk $2 '!/-1/ {print $1}')
do
### fene COUNT all Windows
((fene++))
### CHECK STATE, minimized ?? SOURCE https://askubuntu.com/questions/1132023/how-to-determine-if-window-is-maximised-or-minimised-from-bash-script
minmin=$(xprop -id $u-| grep "_NET_WM_STATE(ATOM)" | grep "_NET_WM_STATE_HIDDEN")
### IF is MINIMIZED (hfene++)
if [[ $minmin != "" ]]; then
# echo "--- EEE"
((hfene++))
# else
# echo "--- ooo"
fi
done
### GET CURRENT FOCUSED INFOS
current=$(xprop -root | grep '^_NET_ACTIVE_W' | awk -F'# 0x' '{print $2}' | awk -F', ' '{print $1}')
# echo current $current
class=$(xdotool getwindowfocus getwindowclassname)
# echo class $class
currapp_windows=$(wmctrl -mlpx | grep $class | awk '{print $1}')
# echo currapp_windows $currapp_windows
currapp_window_active=$(wmctrl -mlpx | grep $current | awk '{print $1}')
# echo currapp_window_active $currapp_window_active
# echo
### LOOP ALL WINDOWS
for fene_id in $(wmctrl -l | awk $2 '!/-1/ {print $1}')
do
### $fene_id == WIN_ID
# echo n == $fene_id
### DEBUG get name
window=$(wmctrl -mlpx | grep $fene_id | awk '{print $4}')
# echo window $window
# echo
if [[ $fene_id == $currapp_window_active ]];then
# echo "[ FRONT ] : $window"
### KEEP IT in mind, last focused
focused=$fene_id
else
# echo "OOO window : $window"
xdotool windowminimize $fene_id
currapp_windows=$(wmctrl -mlpx | grep $class | awk '{print $1}')
fi
### LAST Focused
# echo focused $focused
### IF ALL are minified
hhf=$(($hfene+1))
if [[ $fene == $hhf ]];then
#### ALL are already minimized
# echo "all"
#### RESTORE
#### DIRTY Restore (raise) all windows ($fene_id, one by one)
xdotool windowraise $fene_id
#### Restore (raise) LAST FOCUSED (into front)
xdotool windowraise $focused
fi
# echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment