Set Z-index of OS game window

Godot Version

4.3

Question

Hello! I’m wondering if I can set the z-index of the the actual game window. I want to send the game window to behind all other windows so it is just above the desktop.

I been trying to find out how to do this but haven found anything yet so any help would be appreciated! :grinning:

Curious if you have a use case. Also which OS are you referring. I don’t think this can be done within godot unless there is a way to access the OS.

There is a way to minimize it on startup using the command below

DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MINIMIZED)

Thanks for your reply

My use is having a window sit lowest on the desktop so it looks like its part of the wallpaper. Kind of like the desktop gadgets in windows 7.

The main OS I want it to work on is Windows. I’ve had a look at the code for the windows display server and don’t think their is any simple way to do it. So I’ll try to get it working by using C# and the Windows SetWindowPos function SetWindowPos function (winuser.h) - Win32 apps | Microsoft Learn

If anyone has any ideas I would appreciate it but I’ll see if I get it to work in C#.

I recently remembered I posted this and never gave an update.
So for anyone who needs to do this I got the SetWindowPos function I mentioned before to work using C#

Here’s an example that moves the window back on start:

using Godot;
using System;
using System.Runtime.InteropServices;

public partial class ctest : Node
{
	[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
	public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
	
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		const short SWP_NOZORDER = 0X4;
		const short SWP_NOMOVE = 0X2;
		const short SWP_NOSIZE = 1;
		const int SWP_SHOWWINDOW = 0x0040;
		
		//Get the windows handle of the game window
		var handle = new IntPtr(DisplayServer.WindowGetNativeHandle(DisplayServer.HandleType.WindowHandle));
		
		//Move window to back
		SetWindowPos(handle, 1, 0, 0, 0, 0,  SWP_NOMOVE | SWP_NOSIZE);
		
	}

	
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.