Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Commit

Permalink
Mac: allow fullscreen on second monitor
Browse files Browse the repository at this point in the history
fix #93
  • Loading branch information
RSATom committed May 31, 2015
1 parent 5e591aa commit 3fbf6fd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Mac/Chimera_Mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class Chimera_Mac: public QmlChimera
void setQml();
void cleanup();

QScreen* currentScreen();

private Q_SLOTS:
void quickViewStatusChanged();

Expand Down
53 changes: 51 additions & 2 deletions src/Mac/Chimera_Mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@

#include <dlfcn.h>

#include <QGuiApplication>
#include <QtDebug>
#include <QtPlugin>
#include <QCoreApplication>
#include <QQmlContext>
#include <QScreen>

#include <QuickLayer/QuickLayer.h>
#include <QuickLayer/FboQuickView.h>
#include <QuickLayer/FboQuickWrapperWindow.h>

#include <DOM/Window.h>

#include "QtConf.h"

std::string getPluginPath()
Expand Down Expand Up @@ -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<int>( "screenX" ) );
}
if( window->hasProperty( "screenY" ) ) {
winRect.setY( window->getProperty<int>( "screenY" ) );
}
if( window->hasProperty( "outerWidth" ) ) {
winRect.setWidth( window->getProperty<int>( "outerWidth" ) );
}
if( window->hasProperty( "outerHeight" ) ) {
winRect.setHeight( window->getProperty<int>( "outerHeight" ) );
}

QPoint winCenter = winRect.center();

QList<QScreen*> 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];
Expand Down

0 comments on commit 3fbf6fd

Please sign in to comment.