2
$\begingroup$

With bpy I can call the following function:

bpy.ops.wm.window_fullscreen_toggle()

But how can I track the state of the toggle so that I avoid unnecessary calls to the bpy.ops.wm.window_fullscreen_toggle() function?

$\endgroup$
4
$\begingroup$

You can use the code

size = bpy.context.window.y
if size == 0:
     # it's fullscreen
else:
     # it's not fullscreen

I don't know if that's the proper way to do it, but it works for me

$\endgroup$
1
  • 1
    $\begingroup$ Will depend on screen setup. My desktop has only a title bar across the top with a height of 64. In full screen window y reports as -64 and in max (but not full) as 64. It's been my experience that blenders window.y is dodgy on ubuntu. On toggling out of full screen it sometimes reports as 250 instead. Found this out trying to overlay a decoration free window over a particular area type. (Text editor). $\endgroup$
    – batFINGER
    Dec 26 '20 at 16:54
4
$\begingroup$

Third party window manager.

This may have changed AFAIK there is no property exposed akin to Window.is_full_screen in blender. Have resorted to using a third party window manager.

Get Monitor Resolution in Python

Example run on old monitor where 1200 x 1024 is full screen resolution.

Can get blenders context window height and width via

>>> C.window.height
1024

or loop over all windows in C.window_manager.windows

I'm on ubuntu and have the lightweight ewmh window manager module available. The Gtk gi is another I often use for managing windows (focusing, moving workspace, making thumbnails etc)

Running from blender the current window is the active window.

>>> from ewmh import EWMH
>>> wm = EWMH()
>>> win = wm.getActiveWindow()
>>> win.get_wm_class()
('Blender', 'Blender')

Check its geometry

>>> win.get_geometry()
<<class 'Xlib.protocol.request.GetGeometry'> serial = 15, data = {'depth': 24, 'sequence_number': 15, 'root': <<class 'Xlib.display.Window'> 0x0000028e>, 'x': 0, 'y': 0, 'width': 1280, 'height': 1024, 'border_width': 0}, error = None>

Or query its states

>>> wm.getWmState(win, True)
['_NET_WM_STATE_FULLSCREEN', '_NET_WM_STATE_FOCUSED']

Ok looks like in full screen, run the op

>>> bpy.ops.wm.window_fullscreen_toggle()
{'FINISHED'}

>>> wm.getWmState(win, True)
['_NET_WM_STATE_MAXIMIZED_HORZ', '_NET_WM_STATE_MAXIMIZED_VERT', '_NET_WM_STATE_FOCUSED']

Probably worth mentioning, since I am using a window manager can do away with using the operator.

>>> wm.setWmState(
setWmState(self, win, action, state, state2=0)
Set/unset one or two state(s) for the given window (property
_NET_WM_STATE).
:param win: the window object
:param action: 0 to remove, 1 to add or 2 to toggle state(s)
:param state: a state
:type state: int or str (see :attr:`NET_WM_STATES`)
:param state2: a state or 0
:type state2: int or str (see :attr:`NET_WM_STATES`)

So to set full screen using ewmh

>>> wm.setWmState(win, 1, '_NET_WM_STATE_FULLSCREEN')
>>> wm.display.flush()
$\endgroup$
1
  • $\begingroup$ Thanks for the help. Too bad the blender doesn't have a built-in property $\endgroup$
    – Empty
    Dec 26 '20 at 17:29

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.