Skip to content

Commit

Permalink
Format and centre window on primary screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
MelissaAutumn committed Apr 21, 2024
1 parent 3b0ea69 commit 11050f7
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ void sigHandler(int s)
qApp->quit();
}

int main(int argc, char *argv[]) {

int main(int argc, char* argv[])
{
#ifdef __linux__
// Force XWayland/X11 mode if nothing is provided, until we have a better solution that works on wayland.
if (!getenv("QT_QPA_PLATFORM")) {
if (!getenv("QT_QPA_PLATFORM"))
{
char x11[] = "QT_QPA_PLATFORM=xcb";
putenv(x11);
}
Expand All @@ -34,7 +35,7 @@ int main(int argc, char *argv[]) {
QApplication a(argc, argv);
#endif

std::signal(SIGINT, sigHandler);
std::signal(SIGINT, sigHandler);
std::signal(SIGTERM, sigHandler);

g_pUnreal = new UnrealGlue(nullptr);
Expand All @@ -43,16 +44,24 @@ int main(int argc, char *argv[]) {
#ifdef COMPILE_WITH_QT
auto* pMainWindow = new Components::MultiEdWindow();
pMainWindow->Init();

// centre on screen
auto primaryScreen = a.primaryScreen();
auto screenWidth = primaryScreen->geometry().width();
auto screenHeight = primaryScreen->geometry().height();
pMainWindow->move((screenWidth / 2) - (pMainWindow->width() / 2), (screenHeight / 2) - (pMainWindow->height() / 2));

#endif

// TODO: Move this in a place where we can re-init this from the UI
#ifdef COMPILE_WITH_QT
pMainWindow->m_pSDLWindow = g_pUnreal->m_pWindow;

int i = 0;
for (auto pWinID : g_pUnreal->m_pWndIDs) {
for (auto pWinID : g_pUnreal->m_pWndIDs)
{
auto pWindow = QWindow::fromWinId((WId)pWinID);
QWidget *widget = QWidget::createWindowContainer(pWindow);
QWidget* widget = QWidget::createWindowContainer(pWindow);
widget->setFocusPolicy(Qt::NoFocus);
pMainWindow->SetViewport(widget, (WId)pWinID, g_pUnreal->m_nViewportModes.at(i));
i++;
Expand All @@ -67,18 +76,21 @@ int main(int argc, char *argv[]) {
/*
* We need to handle two different event loops here!
*/
while (true) {
while (true)
{
#ifdef COMPILE_WITH_QT
// QT loop
qApp->processEvents();
if (!pMainWindow->isVisible()) {
if (!pMainWindow->isVisible())
{
delete g_pUnreal;
break;
}
#endif
// Unreal loop
auto bOkay = g_pUnreal->Loop();
if (!bOkay) {
if (!bOkay)
{
break;
}
}
Expand Down

0 comments on commit 11050f7

Please sign in to comment.