diff --git a/src/Mac/Chimera_Mac.h b/src/Mac/Chimera_Mac.h index 330280e..c244ca6 100644 --- a/src/Mac/Chimera_Mac.h +++ b/src/Mac/Chimera_Mac.h @@ -87,6 +87,8 @@ class Chimera_Mac: public QmlChimera void setQml(); void cleanup(); + QScreen* currentScreen(); + private Q_SLOTS: void quickViewStatusChanged(); diff --git a/src/Mac/Chimera_Mac.mm b/src/Mac/Chimera_Mac.mm index 47a7015..8ad8db5 100644 --- a/src/Mac/Chimera_Mac.mm +++ b/src/Mac/Chimera_Mac.mm @@ -20,15 +20,19 @@ #include +#include #include #include #include #include +#include #include #include #include +#include + #include "QtConf.h" std::string getPluginPath() @@ -427,16 +431,61 @@ QMouseEvent mouseEvent( QEvent::MouseMove, mousePoint, mousePoint, return ( nullptr != m_p->fullscreenWindow ); } +QScreen* Chimera_Mac::currentScreen() +{ + QScreen* bestScreen = QGuiApplication::primaryScreen(); + + FB::DOM::WindowPtr window = m_host->getDOMWindow(); + if( !window ) + return bestScreen; + + QRect winRect; + + if( window->hasProperty( "screenX" ) ) { + winRect.setX( window->getProperty( "screenX" ) ); + } + if( window->hasProperty( "screenY" ) ) { + winRect.setY( window->getProperty( "screenY" ) ); + } + if( window->hasProperty( "outerWidth" ) ) { + winRect.setWidth( window->getProperty( "outerWidth" ) ); + } + if( window->hasProperty( "outerHeight" ) ) { + winRect.setHeight( window->getProperty( "outerHeight" ) ); + } + + QPoint winCenter = winRect.center(); + + QList screens = QGuiApplication::screens(); + unsigned intersectedArea = 0; + for( auto* screen : screens ) { + QRect screenRect = screen->geometry(); + if( screenRect.contains( winCenter ) ) { + return screen; + } else { + QRect ir = screenRect.intersected( winRect ); + unsigned ia = ir.width() * ir.height(); + if( ir.isValid() && ia > intersectedArea ) + bestScreen = screen; + } + } + + return bestScreen; +} + void Chimera_Mac::setFullscreen( bool fs ) { if( fs && !isFullscreen() ) { + QScreen* screen = currentScreen(); + m_p->fullscreenWindow = new FboQuickWrapperWindow( m_p->quickViewPtr.data() ); QWindow* fsw = m_p->fullscreenWindow; fsw->setFlags( fsw->flags() | Qt::CustomizeWindowHint ); - const FB::Rect r = GetWindow()->getWindowPosition(); - fsw->setGeometry( r.left, r.top, r.right - r.left, r.bottom - r.top ); + + fsw->setScreen( screen ); + fsw->setGeometry( screen->geometry() ); fsw->showFullScreen(); [m_p->quickLayer setHidden: YES];