# Expression to get Desktop Mode

**URL:** <https://forum.inductiveautomation.com/t/expression-to-get-desktop-mode/89244>\
**Category:** Ignition\
**Tags:** vision, ignition81\
**Created:** [April 22, 2024, 10:10pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-desktop-mode/89244 "2024-04-22T22:10:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [April 22, 2024, 10:10pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-desktop-mode/89244/1 "2024-04-22T22:10:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 22, 2024, 10:15pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-desktop-mode/89244/2 "2024-04-22T22:15:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [April 23, 2024, 8:40am UTC](https://forum.inductiveautomation.com/t/expression-to-get-desktop-mode/89244/3 "2024-04-23T08:40:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [April 23, 2024, 1:04pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-desktop-mode/89244/4 "2024-04-23T13:04:31Z")

</div>

Yes. This is my script on a button.

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

if Nav.desktopIsWindowedMode(desktop):
	Nav.desktopSwapDisplayMode(desktop)
else:
	Nav.desktopSwapDisplayMode(Nav.openNewDesktop())

```

```python
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)

```

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [April 23, 2024, 1:06pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-desktop-mode/89244/5 "2024-04-23T13:06:27Z")

</div>

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.

> [@justinedwards.jle](#):
>
> 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.

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:

> [@](#):
>
> have 2 separate buttons. One to change the window's mode and one to create a new window

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

Buttons:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/8/28b6d37b873335b454707121891c7ff733ffc7fe.png)

Scripts:

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

```

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

```
