11

I have a bash script that moves my windows from the left screen to right screen in dual-screen setup. Currently the way it works is cycling through the window ids that are given by xdotool search --onlyvisible --maxdepth 2 --class "" and then moves them to the right by the screen width. It already works... unless the window in question is maximises or minimised.

So what is needed is a way to check the current status of the window. I have found an answer that provides the way to add and remove those bits, but where is the way to check if they are set already?

If it is not possible to do via xdotool, it should be possible to reuse the window id provided by the command mentioned above.

  • you can also look at devilspie which is designed to do exactly this kind of window work. So no need to recode, just configure – Ciprian Tomoiagă Apr 8 at 10:08
11

Retrieve info on the window state

You can get the info (and a lot more) from the command:

xprop -id <window_id>

To get what you are specifically looking for:

xprop -id 0x04c00010 | grep "_NET_WM_STATE(ATOM)"

The output will look like:

_NET_WM_STATE(ATOM) = _NET_WM_STATE_MAXIMIZED_HORZ, _NET_WM_STATE_MAXIMIZED_VERT, _NET_WM_STATE_HIDDEN

on a window that is maximized (h + v) and minimized at the same time, or just

_NET_WM_STATE(ATOM) =

(or no output at all) if none of those is the case.

More fun

Of course, using various languages, you can use Wnck, like in the python snippet below. (snippet from window-shuffler). The snippet outputs a list, showing the window name + either True or False (minimized).

#!/usr/bin/env python3
import gi
gi.require_version('Wnck', '3.0')
from gi.repository import Wnck


def get_winlist(scr=None, selecttype=None):
    """
    get the window list. possible args: screen, select_type, in case it is
    already fetched elsewhere. select type is optional, to fetch only
    specific window types.
    """
    if not scr:
        scr = Wnck.Screen.get_default()
        scr.force_update()
    windows = scr.get_windows()
    if selecttype:
        windows = [w for w in windows if check_windowtype(w, selecttype)]
    return windows

wlist = get_winlist()
for w in wlist:
    print(w.get_name(), ",", w.is_maximized())

Output looks like:

Wnck.Window - Classes - Wnck 3.0 - Mozilla Firefox , True
Postvak IN - vlijm@planet.nl - Mozilla Thunderbird , True
Showtime , False
settingsexample.vala - Visual Studio Code , False
*Niet-opgeslagen document 1 - gedit , False
desktop_weather , False
Tilix: Standaard , False

N.B.

  • xprop will handel both hex (as output from e.g. wmctrl) and decimal (as output from e.g. xdotool) id's equally e.g. either use:

    xprop -id 111371626
    

    or

    xprop -id 0x06a3656a
    
  • Methods will not work on Wayland!

  • 1
    Excellent suggestion +1. As a comment, I tried it (under Linux, X11) and got slightly different results. When a window is neither hidden nor maximized, _NET_WM_STATE(ATOM) does not, as shown in the answer, appear with an empty value. Instead, it is not in the output at all. – John1024 Apr 8 at 5:15
  • @John1024 Ah, thanks! will add it to the answer. – Jacob Vlijm Apr 8 at 5:20
  • On my system it is shown in either case, even when empty. – v010dya Apr 8 at 6:25
  • I want to add that window id can be given as a cecimal number, so no need to convert to hex. Just in case this will help somebody. – v010dya Apr 11 at 12:23
  • @v010dya Thanks! See updated answer. – Jacob Vlijm Apr 11 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.