summaryrefslogtreecommitdiffstats
path: root/src/core/desktop_screen_qt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/desktop_screen_qt.cpp')
-rw-r--r--src/core/desktop_screen_qt.cpp195
1 files changed, 119 insertions, 76 deletions
diff --git a/src/core/desktop_screen_qt.cpp b/src/core/desktop_screen_qt.cpp
index 15a3856fc..fb68f7b09 100644
--- a/src/core/desktop_screen_qt.cpp
+++ b/src/core/desktop_screen_qt.cpp
@@ -1,113 +1,156 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebEngine module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "desktop_screen_qt.h"
#include "ui/display/display.h"
-#include "ui/gfx/geometry/point.h"
-#include <QtGlobal>
+#include "type_conversion.h"
-namespace QtWebEngineCore {
+#include <QGuiApplication>
+#include <QScreen>
-gfx::Point DesktopScreenQt::GetCursorScreenPoint()
-{
- Q_UNREACHABLE();
- return gfx::Point();
-}
+#if defined(USE_OZONE)
+#include "ui/ozone/buildflags.h"
+#if BUILDFLAG(OZONE_PLATFORM_X11)
+#define USE_XSCREENSAVER
+#include "ui/base/x/x11_screensaver.h"
+#include "ui/base/x/x11_util.h"
+#endif
+#endif
-bool DesktopScreenQt::IsWindowUnderCursor(gfx::NativeWindow)
-{
- Q_UNREACHABLE();
- return false;
-}
+#include <cmath>
+
+namespace QtWebEngineCore {
-gfx::NativeWindow DesktopScreenQt::GetWindowAtScreenPoint(const gfx::Point& point)
+static display::Display::Rotation toDisplayRotation(Qt::ScreenOrientation orientation)
{
- Q_UNREACHABLE();
- return gfx::NativeWindow();
+ switch (orientation) {
+ case Qt::PrimaryOrientation:
+ case Qt::LandscapeOrientation:
+ return display::Display::ROTATE_0;
+ case Qt::PortraitOrientation:
+ return display::Display::ROTATE_90;
+ case Qt::InvertedLandscapeOrientation:
+ return display::Display::ROTATE_180;
+ case Qt::InvertedPortraitOrientation:
+ return display::Display::ROTATE_270;
+ }
}
-int DesktopScreenQt::GetNumDisplays() const
+display::Display toDisplayDisplay(int id, const QScreen *screen)
{
- Q_UNREACHABLE();
- return 0;
+ auto display = display::Display(id, toGfx(screen->geometry()));
+ display.set_work_area(toGfx(screen->availableGeometry()));
+ display.set_is_monochrome(screen->depth() == 1);
+ display.set_color_depth(screen->depth());
+ display.set_depth_per_component(8); // FIXME: find the real value
+ display.set_display_frequency(std::ceil(screen->refreshRate()));
+ display.set_rotation(toDisplayRotation(screen->orientation()));
+
+ // FIXME: support lower scale factor
+ float pixelRatio = screen->devicePixelRatio();
+ if (pixelRatio < 1) {
+ qWarning("Unsupported scale factor (%f) detected on Display%d", pixelRatio, id);
+ display.set_device_scale_factor(qGuiApp->devicePixelRatio());
+ } else {
+ display.set_device_scale_factor(pixelRatio);
+ }
+
+ if (screen->nativeOrientation() != Qt::PrimaryOrientation)
+ display.set_panel_rotation(toDisplayRotation(screen->nativeOrientation()));
+ return display;
}
-std::vector<display::Display>& DesktopScreenQt::GetAllDisplays() const
+DesktopScreenQt::DesktopScreenQt()
{
- static std::vector<display::Display> empty;
- return empty;
+ initializeScreens();
}
-display::Display DesktopScreenQt::GetDisplayNearestWindow(gfx::NativeWindow window) const
+DesktopScreenQt::~DesktopScreenQt()
{
- // RenderViewHostImpl::OnStartDragging uses this to determine
- // the scale factor for the view.
- return display::Display(0);
+ for (auto conn : std::as_const(m_connections))
+ QObject::disconnect(conn);
}
-display::Display DesktopScreenQt::GetDisplayNearestPoint(const gfx::Point& point) const
+void DesktopScreenQt::initializeScreens()
{
- Q_UNREACHABLE();
- return display::Display();
+ if (updateAllScreens()) {
+ m_connections[0] =
+ QObject::connect(qApp, &QGuiApplication::primaryScreenChanged, [this] (QScreen *screen) {
+ ProcessDisplayChanged(toDisplayDisplay(0, screen), true /* is_primary */);
+ });
+ // no guarantees how these will affect ids:
+ m_connections[1] =
+ QObject::connect(qApp, &QGuiApplication::screenAdded, [this] (QScreen *) {
+ updateAllScreens();
+ });
+ m_connections[2] =
+ QObject::connect(qApp, &QGuiApplication::screenRemoved, [this] (QScreen *) {
+ updateAllScreens();
+ });
+ } else {
+ // Running headless
+ ProcessDisplayChanged(display::Display::GetDefaultDisplay(), true /* is_primary */);
+ m_connections[0] =
+ QObject::connect(qApp, &QGuiApplication::screenAdded, [this] (QScreen *) {
+ display_list().RemoveDisplay(display::kDefaultDisplayId);
+ QObject::disconnect(m_connections[0]);
+ initializeScreens();
+ });
+ }
}
-display::Display DesktopScreenQt::GetDisplayMatching(const gfx::Rect& match_rect) const
+bool DesktopScreenQt::updateAllScreens()
{
- Q_UNREACHABLE();
- return display::Display();
+ Q_ASSERT(qApp->primaryScreen() == qApp->screens().first());
+ const auto screens = qApp->screens();
+ const int oldLen = GetNumDisplays();
+ for (int i = screens.length(); i < oldLen; ++i)
+ display_list().RemoveDisplay(i);
+ for (int i = 0; i < screens.length(); ++i)
+ ProcessDisplayChanged(toDisplayDisplay(i, screens.at(i)), i == 0 /* is_primary */);
+
+ return screens.length() > 0;
}
-display::Display DesktopScreenQt::GetPrimaryDisplay() const
+display::Display DesktopScreenQt::GetDisplayNearestWindow(gfx::NativeWindow /*window*/) const
{
- return display::Display(0);
+ return GetPrimaryDisplay();
}
-void DesktopScreenQt::AddObserver(display::DisplayObserver* observer)
+#if defined(USE_XSCREENSAVER)
+class XScreenSuspender : public display::Screen::ScreenSaverSuspender
{
- Q_UNREACHABLE();
+public:
+ XScreenSuspender()
+ {
+ ui::SuspendX11ScreenSaver(true);
+ }
+ ~XScreenSuspender() override
+ {
+ ui::SuspendX11ScreenSaver(false);
+ }
+};
+#endif
+#if BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_LINUX)
+std::unique_ptr<display::Screen::ScreenSaverSuspender> DesktopScreenQt::SuspendScreenSaver()
+{
+#if defined(USE_XSCREENSAVER)
+ return std::make_unique<XScreenSuspender>();
+#else
+ return nullptr;
+#endif
}
+#endif
-void DesktopScreenQt::RemoveObserver(display::DisplayObserver* observer)
+bool DesktopScreenQt::IsScreenSaverActive() const
{
- Q_UNREACHABLE();
+#if defined(USE_XSCREENSAVER)
+ return ui::IsXScreensaverActive();
+#else
+ return false;
+#endif
}
} // namespace QtWebEngineCore