Debian Codegraph @

src/gui/snippingArea/X11SnippingArea.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2018 Damir Porobic <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "X11SnippingArea.h"
21 #include <QGuiApplication>
22 #include <QScreen>
23
24 X11SnippingArea::X11SnippingArea(const QSharedPointer<IConfig> &config) :
25 AbstractSnippingArea(config),
26 mIsDesktopGeometryCalculated(false)
27 {
28 setWindowFlags(windowFlags() | Qt::Tool | Qt::X11BypassWindowManagerHint);
29
30 connect(qGuiApp, &QGuiApplication::screenRemoved, this, &X11SnippingArea::screenCountChanged);
31 connect(qGuiApp, &QGuiApplication::screenAdded, this, &X11SnippingArea::screenCountChanged);
32
33 screenCountChanged();
34 }
35
36 QRect X11SnippingArea::selectedRectArea() const
37 {
38 return getGlobalCaptureArea();
39 }
40
41 void X11SnippingArea::setFullScreen()
42 {
43 setGeometry(mDesktopGeometry.toRect());
44 QWidget::show();
45 }
46
47 QSizeF X11SnippingArea::getSize() const
48 {
49 return mDesktopGeometry.size();
50 }
51
52 void X11SnippingArea::showSnippingArea()
53 {
54 // Just after the screen count is changed the new screen is not positioned
55 // correctly so our calculation is wrong. As a workaround we mark that we
56 // need to recalculate the screen and calculate just before we show the
57 // snipping area.
58 if (!mIsDesktopGeometryCalculated) {
59 calculateDesktopGeometry();
60 mIsDesktopGeometryCalculated = true;
61 }
62
63 AbstractSnippingArea::showSnippingArea();
64 }
65
66 void X11SnippingArea::calculateDesktopGeometry()
67 {
68 mDesktopGeometry = QRectF();
69
70 auto screens = QGuiApplication::screens();
71
72 for(auto screen : screens) {
73 auto scaleFactor = screen->devicePixelRatio();
74 auto screenGeometry = screen->geometry();
75 auto x = screenGeometry.x() / scaleFactor;
76 auto y = screenGeometry.y() / scaleFactor;
77 auto width = (qreal)screenGeometry.width();
78 auto height = (qreal)screenGeometry.height();
79
80 mDesktopGeometry = mDesktopGeometry.united({x, y, width, height});
81 }
82 }
83
84 void X11SnippingArea::screenCountChanged()
85 {
86 desktopGeometryChanged();
87
88 auto screens = QGuiApplication::screens();
89 for(auto screen : screens) {
90 connect(screen, &QScreen::availableGeometryChanged, this, &X11SnippingArea::desktopGeometryChanged, Qt::UniqueConnection);
91 }
92 }
93
94 void X11SnippingArea::desktopGeometryChanged()
95 {
96 mIsDesktopGeometryCalculated = false;
97 }