Expression to get Desktop Mode

How can I get a window's parent desktop mode (windowed or fullscreen) from an expression?

Parent desktop? Is it even possible to have different desktops in different modes?

This sounds like runScript territory. If I understand what you are asking correctly, it seems like you could do it by calling your Nav.desktopIsWindowedMode library script using self.parent as the argument from a custom property on the root container.

What do you need this for? Whatever it is, I feel like there should be a better approach than using a runScript expression.

Yes. This is my script on a button.

desktop = Nav.getParentDesktop(system.gui.getParentWindow(event))

if Nav.desktopIsWindowedMode(desktop):
	Nav.desktopSwapDisplayMode(desktop)
else:
	Nav.desktopSwapDisplayMode(Nav.openNewDesktop())
def getParentDesktop(window):
	'''
		Get the parent desktop JFrame for supplied window.
		
		Args:
			window	(obj)		:	window on the desktop
			
		Returns:
			desktop	(JFrame)	:	window's parent desktop JFrame
	'''
	while not isinstance(window, JFrame):
		window = window.getParent()
		
	desktop = window
	
	return desktop
	
		
		
def desktopIsWindowedMode(window):
	'''
		Determine if a desktop is in windowed mode or not.
		
		Args:
			window	(ovj)		:	Window to determine if the parent desktop is in fullscreen or windowed mode
			
		Returns:
			isWindowMode	(BOOL)	:	True if desktop is in window mode
	'''
	
	#undecorated = fullscreen
	return not Nav.getParentDesktop(window).isUndecorated()
	
		
def openNewDesktop():
	'''
		Open a new desktop window
		
		Args:
			n/a
			
		Returns:
			desktop (JFrame)	:	newly opened desktop
	'''
	
	#base desktop handle
	dHandle = 'Desktop '
	
	#get handles
	handles = system.gui.getDesktopHandles()
	
	#no desktops open yet
	if len(handles) == 0:
	    nextIndex = 0
	#other desktops open
	else:
	    #get list of the desktop indicies from the handle
	    openDesktopIndicies = [int(handle.replace(dHandle,'')) for handle in handles]
	    #get max index and increment for next index
	    nextIndex = max(openDesktopIndicies)+1
	
	#get the current window
	window = system.nav.getCurrentWindow()
	
	#open new desktop with current window
	desktop = system.gui.openDesktop(handle=dHandle+str(nextIndex),windows = [window, 'Nav'])
	desktop.setAlwaysOnTop(False)
	
	return desktop
	
def desktopSwapDisplayMode(desktop):
    '''
        Swap the selected "desktop" to windowed/fullscreen mode from fullscreen/windowed mode.
        
        Args:
            desktop (JFrame)    :   JFrame of desktop to be swapped to windowed mode.
        
        Returns:
            n/a
    '''

    
    window = desktop
    if window.isUndecorated():
        # Switch to windowed mode.
        window.dispose()
        window.setUndecorated(False)
        window.setExtendedState(JFrame.NORMAL)
        window.setVisible(True)
    else:
        # Switch to full screen mode.
        window.dispose()
        window.setUndecorated(True)
        window.setExtendedState(JFrame.MAXIMIZED_BOTH)
        window.setVisible(True)

I am using the script above to first open a windowed desktop so it can be moved wherever, and then press the same button again to change it to fullscreen mode, effectively docking it where it was moved to.

I want to change the icon on the button based on the current mode of the desktop.

I thought of that as well, but there is no event handler, so there would be no "self"

Perhaps I'll forgo the toggle option and just have 2 separate buttons. One to change the window's mode and one to create a new window, giving complete and clear control to the user.

Edit: I just ended up doing this:

It's a much cleaner user experience and I don't have to try and get the mode in an expression.

Buttons:
image

Scripts:

desktop = Nav.getParentDesktop(system.gui.getParentWindow(event))
Nav.desktopSwapDisplayMode(desktop)
desktop = Nav.getParentDesktop(system.gui.getParentWindow(event))
Nav.openNewDesktop()