Unity 8
AvailableDesktopArea.cpp
1 /*
2  * Copyright (C) 2017 Canonical, Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License version 3, as published by
6  * the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10  * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #include "AvailableDesktopArea.h"
18 
19 #include <QGuiApplication>
20 #include <QQuickWindow>
21 #include <qpa/qplatformnativeinterface.h>
22 
23 AvailableDesktopArea::AvailableDesktopArea(QQuickItem *parent)
24  : QQuickItem(parent)
25 {
26  connect(this, &QQuickItem::xChanged, this, &AvailableDesktopArea::updatePlatformWindowProperty);
27  connect(this, &QQuickItem::yChanged, this, &AvailableDesktopArea::updatePlatformWindowProperty);
28  connect(this, &QQuickItem::widthChanged, this, &AvailableDesktopArea::updatePlatformWindowProperty);
29  connect(this, &QQuickItem::heightChanged, this, &AvailableDesktopArea::updatePlatformWindowProperty);
30 }
31 
32 void AvailableDesktopArea::updatePlatformWindowProperty()
33 {
34  if (!window()) {
35  return;
36  }
37 
38  QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
39 
40  QRect rect(x(), y(), width(), height());
41 
42  nativeInterface->setWindowProperty(window()->handle(), "availableDesktopArea", QVariant(rect));
43 }
44 
45 void AvailableDesktopArea::itemChange(ItemChange change, const ItemChangeData &)
46 {
47  if (change == ItemSceneChange) {
48  updatePlatformWindowProperty();
49  }
50 }