Move main window to other display from plugin

Hi,
Unreal 5.0.3, Linux.
I’m working on plugin which will detect some OS parameters and modify main app. My HW has 3 displays and we want to choose where to place app by display ID/index.
First attempt ended with

	UGameViewportClient* viewportClient = GEngine->GameViewport;

	if (viewportClient)
	{
		TSharedPtr<SWindow> slateWindow = viewportClient->GetWindow();

		if (slateWindow)
		{
			TSharedPtr<FGenericWindow> nativeWindow = slateWindow->GetNativeWindow();

			FDisplayMetrics DisplayMetrics;
			FSlateApplication::Get().GetDisplayMetrics(DisplayMetrics);
			if (MonitorIndex < 0 || MonitorIndex>=DisplayMetrics.MonitorInfo.Num())
			{
				UE_LOG( LogTemp, Warning, TEXT("=> Incorrect monitor index (%d)"), MonitorIndex);
				return;
			}
	
			const FMonitorInfo & MonitorInfo = DisplayMetrics.MonitorInfo[MonitorIndex];
			nativeWindow->SetWindowMode(EWindowMode::Windowed);
			nativeWindow->MoveWindowTo(MonitorInfo.DisplayRect.Left, MonitorInfo.DisplayRect.Top);
			nativeWindow->SetWindowMode(EWindowMode::WindowedFullscreen);
		}
	}

Without changing window mode Fullscreen->WIndow->Fullscreen this doesn’t move game window where I want it. And some slight flicker is visible. I would like to avoid it.

Second idea is to dynamically change FCommandLine to add WinX and WinY with above acquired positions and let GameEngine create GameWindow already where I want it to be.
But I’m unable to modify FCommandLine (with Get()/Set() or Append()) in a way that it would be visible to GameEngine class.
Is it possible?
I would welcome any tips to solve this problem.

Hi Sebastian_Mo,
Years ago (UE4.1) I made some changes to the code to allow me to pass in a window handle (was windows only, but the same concept would work for linux) via the command line and UE would open in that - it was pretty smooth, no flickers or anything - and it wasn’t a lot of code that had to be changed… Maybe this way could work for you too, create your window first then open UE into it.

Because we already had some engine patches - I simply added my above mentioned code piece to UGameEngine::CreateGameWindow() where WinX/WinY is processed.
And I achieved my desired result.

1 Like