How to minimize an X-window on a low-level (not wmctrl or xdotool)?

There are quite some X tools by default installed on a modern OS such as Ubuntu. According to the man pages there is xprop, xdpyinfo, xwininfo, xdriinfo, glxinfo and nvinfo.

For example, it seems to be the case that I can set:

xprop -id $id -f _NET_WM_STATE 32a -set _NET_WM_STATE "_NET_WM_ACTION_MINIMIZE"

Here a as according to the manual corresponds with the "atom" property.

However, this doesn't seem to work. Am I perhaps setting only a property and doesn't it actually get updated? And in that case, how can I enforce the latter?

A more complete script so you can test yourself, suppose we have started chrome with the -maximized flag and want to minimize it later on:

#!/bin/bash

search=chrome
filter=maximized

findpid=$(ps aux | grep $search | grep $filter | tr -s '  ' ' ' | cut -f2 -d' ')

# pick only one pid
findpid=$(echo $findpid | cut -f1 -d' ')
echo "Search for window with pid=$findpid"

known_windows=$(xwininfo -root -children|sed -e 's/^ *//'|grep -E "^0x"|awk '{ print $1 }')

for id in ${known_windows}
do
	xp=$(xprop -id $id _NET_WM_PID)
	if test $? -eq 0; then
		pid=$(xprop -id $id _NET_WM_PID|cut -d'=' -f2|tr -d ' ')

		if test "x${pid}" = x${findpid}
		then
			echo "Windows Id: $id"
			xprop -id $id 
			xprop -id $id -f _NET_WM_STATE 32a -set _NET_WM_STATE "_NET_WM_ACTION_MINIMIZE"
		fi
	fi
done

Maybe I should use something different than xprop, but xset etc seem not to be on the level of the individual windows themselves.

Answers

_NET_WM_ACTION_MINIMIZE is an atom used to indicate "can be maximized" flag in a list of window's supported actions. To ask for action, you send _NET_WM_STATE client message to a root window and emwh-compliant WM would perform action for you, see http://standards.freedesktop.org/wm-spec/wm-spec-1.3.html#idm140130317598336

To un-maximise, you set _NET_WM_STATE_REMOVE as action and send message with _NET_WM_STATE_MAXIMIZED_VERT as first property and _NET_WM_STATE_MAXIMIZED_HORIZ as second property.

Posted on by Andrey Sidorov