blob: 39ca7397e3c50169d5663bbd703e645ad0b53310 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// Copyright 2019-2021 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
#include "Screen.h"
#include "MumbleApplication.h"
#include <QScreen>
#include <QWidget>
#include <QWindow>
QWindow *Screen::windowFromWidget(const QWidget &widget) {
QWindow *window = widget.windowHandle();
if (window) {
return window;
}
const QWidget *parent = widget.nativeParentWidget();
if (parent) {
return parent->windowHandle();
}
return nullptr;
}
QScreen *Screen::screenFromWidget(const QWidget &widget) {
const QWindow *window = windowFromWidget(widget);
if (window && window->screen()) {
return window->screen();
}
return qApp->primaryScreen();
}
QScreen *Screen::screenAt(const QPoint &point) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
return qApp->screenAt(point);
#else
// Adapted from qguiapplication.cpp (Qt)
QVarLengthArray< const QScreen *, 8 > visitedScreens;
for (const QScreen *screen : qApp->screens()) {
if (visitedScreens.contains(screen)) {
continue;
}
// The virtual siblings include the screen itself, so iterate directly
for (QScreen *sibling : screen->virtualSiblings()) {
if (sibling->geometry().contains(point)) {
return sibling;
}
visitedScreens.append(sibling);
}
}
return nullptr;
#endif
}
|