1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include <QGuiApplication>
8 #include "nsScreenManagerQt.h"
9 #include "nsScreenQt.h"
11 nsScreenManagerQt::nsScreenManagerQt()
18 nsScreenManagerQt::~nsScreenManagerQt()
23 // addref, release, QI
24 NS_IMPL_ISUPPORTS(nsScreenManagerQt
, nsIScreenManager
)
26 void nsScreenManagerQt::init()
31 nScreens
= QGuiApplication::screens().size();
32 screens
= new nsCOMPtr
<nsIScreen
>[nScreens
];
34 for (int i
= 0; i
< nScreens
; ++i
)
35 screens
[i
] = new nsScreenQt(i
);
42 // Returns the screen that contains the rectangle. If the rect overlaps
43 // multiple screens, it picks the screen with the greatest area of intersection.
45 // The coordinates are in pixels (not twips) and in screen coordinates.
48 nsScreenManagerQt::ScreenForRect(int32_t inLeft
, int32_t inTop
,
49 int32_t inWidth
, int32_t inHeight
,
50 nsIScreen
**outScreen
)
55 QRect
r(inLeft
, inTop
, inWidth
, inHeight
);
58 for (int i
= 0; i
< nScreens
; ++i
) {
59 const QRect
& rect
= QGuiApplication::screens()[i
]->geometry();
60 QRect intersection
= r
&rect
;
61 int a
= intersection
.width()*intersection
.height();
68 NS_IF_ADDREF(*outScreen
= screens
[best
]);
73 nsScreenManagerQt::ScreenForId(uint32_t aId
, nsIScreen
** aOutScreen
)
80 NS_IF_ADDREF(*aOutScreen
= screens
[aId
]);
84 return NS_ERROR_FAILURE
;
90 // The screen with the menubar/taskbar. This shouldn't be needed very
94 nsScreenManagerQt::GetPrimaryScreen(nsIScreen
**aPrimaryScreen
)
99 NS_IF_ADDREF(*aPrimaryScreen
= screens
[0]);
104 // GetNumberOfScreens
106 // Returns how many physical screens are available.
109 nsScreenManagerQt::GetNumberOfScreens(uint32_t *aNumberOfScreens
)
114 *aNumberOfScreens
= nScreens
;
119 nsScreenManagerQt::GetSystemDefaultScale(float *aDefaultScale
)
121 *aDefaultScale
= 1.0f
;
126 nsScreenManagerQt::ScreenForNativeWidget(void *aWidget
, nsIScreen
**outScreen
)
128 // I don't know how to go from GtkWindow to nsIScreen, especially
129 // given xinerama and stuff, so let's just do this
130 QRect
rect(0, 0, 1, 1);
131 return ScreenForRect(rect
.x(), rect
.y(), rect
.width(), rect
.height(), outScreen
);