How to determine if window is maximised or minimised from bash scriptHow to close, minimize, and maximize a specified window from Terminal?What's the best way to implement a script for tiling windows?Look for a tiling window manager, 2D, enabling shortcutsHow can I start a program minimised, and restore maximised?How to close only one window of an application?How do I permanently change window titles?How can I move a window from an invisible viewport to the current one, without switching viewportsSet window size and positionObtain last active time of window from IDX Windows on Ubuntu 16.04 command-line resize infinite loops sometimes?Display maximised version of a window

What is GPS' 19 year rollover and does it present a cybersecurity issue?

Is it possible to make sharp wind that can cut stuff from afar?

Piano - What is the notation for a double stop where both notes in the double stop are different lengths?

Is Social Media Science Fiction?

"My colleague's body is amazing"

What to wear for invited talk in Canada

Why is the design of haulage companies so “special”?

Why was the "bread communication" in the arena of Catching Fire left out in the movie?

How can I fix this gap between bookcases I made?

Why is my log file so massive? 22gb. I am running log backups

Mapping arrows in commutative diagrams

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

Deciding between multiple birth names and dates?

COUNT(id) or MAX(id) - which is faster?

Why is making salt water prohibited on Shabbat?

When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?

What happens when a metallic dragon and a chromatic dragon mate?

Email Account under attack (really) - anything I can do?

Can I find out the caloric content of bread by dehydrating it?

How to deal with fear of taking dependencies

Einstein metrics on spheres

Extreme, but not acceptable situation and I can't start the work tomorrow morning

Is "plugging out" electronic devices an American expression?

Could Giant Ground Sloths have been a Good Pack Animal for the Ancient Mayans



How to determine if window is maximised or minimised from bash script


How to close, minimize, and maximize a specified window from Terminal?What's the best way to implement a script for tiling windows?Look for a tiling window manager, 2D, enabling shortcutsHow can I start a program minimised, and restore maximised?How to close only one window of an application?How do I permanently change window titles?How can I move a window from an invisible viewport to the current one, without switching viewportsSet window size and positionObtain last active time of window from IDX Windows on Ubuntu 16.04 command-line resize infinite loops sometimes?Display maximised version of a window






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








10















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.










share|improve this question
























  • 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ă
    12 hours ago

















10















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.










share|improve this question
























  • 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ă
    12 hours ago













10












10








10








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.










share|improve this question
















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.







command-line window-manager xdotool wmctrl xprop






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 15 hours ago









Jacob Vlijm

66.3k9132230




66.3k9132230










asked 18 hours ago









v010dyav010dya

6272829




6272829












  • 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ă
    12 hours ago

















  • 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ă
    12 hours ago
















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ă
12 hours ago





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ă
12 hours ago










1 Answer
1






active

oldest

votes


















9














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. Methods will not work on Wayland!






share|improve this answer




















  • 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
    17 hours ago











  • @John1024 Ah, thanks! will add it to the answer.

    – Jacob Vlijm
    16 hours ago











  • On my system it is shown in either case, even when empty.

    – v010dya
    15 hours ago











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1132023%2fhow-to-determine-if-window-is-maximised-or-minimised-from-bash-script%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









9














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. Methods will not work on Wayland!






share|improve this answer




















  • 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
    17 hours ago











  • @John1024 Ah, thanks! will add it to the answer.

    – Jacob Vlijm
    16 hours ago











  • On my system it is shown in either case, even when empty.

    – v010dya
    15 hours ago















9














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. Methods will not work on Wayland!






share|improve this answer




















  • 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
    17 hours ago











  • @John1024 Ah, thanks! will add it to the answer.

    – Jacob Vlijm
    16 hours ago











  • On my system it is shown in either case, even when empty.

    – v010dya
    15 hours ago













9












9








9







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. Methods will not work on Wayland!






share|improve this answer















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. Methods will not work on Wayland!







share|improve this answer














share|improve this answer



share|improve this answer








edited 14 hours ago

























answered 17 hours ago









Jacob VlijmJacob Vlijm

66.3k9132230




66.3k9132230







  • 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
    17 hours ago











  • @John1024 Ah, thanks! will add it to the answer.

    – Jacob Vlijm
    16 hours ago











  • On my system it is shown in either case, even when empty.

    – v010dya
    15 hours ago












  • 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
    17 hours ago











  • @John1024 Ah, thanks! will add it to the answer.

    – Jacob Vlijm
    16 hours ago











  • On my system it is shown in either case, even when empty.

    – v010dya
    15 hours ago







1




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
17 hours ago





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
17 hours ago













@John1024 Ah, thanks! will add it to the answer.

– Jacob Vlijm
16 hours ago





@John1024 Ah, thanks! will add it to the answer.

– Jacob Vlijm
16 hours ago













On my system it is shown in either case, even when empty.

– v010dya
15 hours ago





On my system it is shown in either case, even when empty.

– v010dya
15 hours ago

















draft saved

draft discarded
















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1132023%2fhow-to-determine-if-window-is-maximised-or-minimised-from-bash-script%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown