diff options
Diffstat (limited to 'src/displaysettings')
-rw-r--r-- | src/displaysettings/displaysettings.cpp | 221 | ||||
-rw-r--r-- | src/displaysettings/displaysettings.h | 81 | ||||
-rw-r--r-- | src/displaysettings/displaysettings.pro | 16 | ||||
-rw-r--r-- | src/displaysettings/displaysettings_p.cpp | 278 | ||||
-rw-r--r-- | src/displaysettings/displaysettings_p.h | 119 |
5 files changed, 0 insertions, 715 deletions
diff --git a/src/displaysettings/displaysettings.cpp b/src/displaysettings/displaysettings.cpp deleted file mode 100644 index c7c93c8..0000000 --- a/src/displaysettings/displaysettings.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Device Utilities module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** 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 General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) 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.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-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "displaysettings.h" -#include "displaysettings_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \module QtDisplaySettings - \qtvariable displaysettings - \ingroup qtdevice-utilities-cpp-modules - \ingroup modules - \title Qt Display Settings C++ Classes - \brief Provides access to display settings. - - To use classes from this module, add this directive into the C++ files: - - \code - #include <QtDisplaySettings> - \endcode - - To link against the corresponding C++ libraries, add the following to your - qmake project file: - - \code - QT += displaysettings - \endcode -*/ - -/*! - \class DisplaySettings - \inmodule QtDisplaySettings - - \brief The DisplaySettings class specifies display settings. - - The Boot to Qt demo launcher and Qt Quick Controls scale automatically to - screens of different sizes, from 7-inch touch screens to 60-inch or larger - television screens to ensure readability and touch friendliness. For this, - Qt has to know the physical dimensions of the screen. By default, it tries - to query these values from the framebuffer devices. However, many kernel - drivers do not provide this information. - - The display settings enable overriding and manually setting the physical - screen size. - - In addition, you can set the display brightness. That is, the intensity of - the backlight. -*/ - -/*! - \property DisplaySettings::displayBrightness - \brief The display brightness. - - A value of \c 255 requests the maximum brightness, while that of \c 0 - requests the minimum (typically, the backlight turned off). -*/ - - -/*! - \property DisplaySettings::physicalScreenSizeInch - \brief The physical screen size in inches. -*/ - -/*! - \property DisplaySettings::physicalScreenWidthMm - \brief The physical screen width in millimeters. -*/ - -/*! - \property DisplaySettings::physicalScreenHeightMm - \brief The physical screen height in millimeters. -*/ - -/*! - \property DisplaySettings::physicalScreenSizeOverride - \brief Whether to use the value set for the physical screen size. -*/ - -/*! - Creates a new display settings object with the parent \a parent. -*/ -DisplaySettings::DisplaySettings(QObject *parent) - : QObject(parent) - ,d_ptr(new DisplaySettingsPrivate(this)) -{ -} - -/*! - Deletes the display settings object. -*/ -DisplaySettings::~DisplaySettings() -{ -} - - -/*! - Sets the display brightness to \a v. - - Returns \c true on success. -*/ -bool DisplaySettings::setDisplayBrightness(int v) -{ - Q_D(DisplaySettings); - return d->setDisplayBrightness(v); -} - - -/*! - * Returns the current backlight intensity. - * \sa setDisplayBrightness - */ -int DisplaySettings::displayBrightness() -{ - Q_D(DisplaySettings); - return d->displayBrightness(); -} - -/*! - Returns the physical screen size in inches. -*/ -int DisplaySettings::physicalScreenSizeInch() const -{ - Q_D(const DisplaySettings); - return d->physicalScreenSizeInch(); -} - -/*! - Returns the physical screen width in millimeters. -*/ -int DisplaySettings::physicalScreenWidthMm() const -{ - Q_D(const DisplaySettings); - return d->physicalScreenWidthMm(); -} - -/*! - Returns the physical screen height in millimeters. -*/ -int DisplaySettings::physicalScreenHeightMm() const -{ - Q_D(const DisplaySettings); - return d->physicalScreenHeightMm(); -} - -/*! - Sets the physical screen size to \a inches. -*/ -void DisplaySettings::setPhysicalScreenSizeInch(int inches) -{ - Q_D(DisplaySettings); - d->setPhysicalScreenSizeInch(inches); -} - -/*! - Sets the physical screen width to \a newWidth. -*/ -void DisplaySettings::setPhysicalScreenWidthMm(int newWidth) -{ - Q_D(DisplaySettings); - d->setPhysicalScreenWidthMm(newWidth); -} - -/*! - Sets the physical screen height to \a newHeight. -*/ -void DisplaySettings::setPhysicalScreenHeightMm(int newHeight) -{ - Q_D(DisplaySettings); - d->setPhysicalScreenHeightMm(newHeight); -} - -/*! - Returns whether the value set for the physical screen size is used. - - \sa physicalScreenSizeInch() -*/ -bool DisplaySettings::physicalScreenSizeOverride() const -{ - Q_D(const DisplaySettings); - return d->physicalScreenSizeOverride(); -} - -/*! - Sets whether the value set for the physical screen size is used to - \a enable. - - \sa physicalScreenSizeInch() -*/ -void DisplaySettings::setPhysicalScreenSizeOverride(bool enable) -{ - Q_D(DisplaySettings); - d->setPhysicalScreenSizeOverride(enable); -} - -QT_END_NAMESPACE diff --git a/src/displaysettings/displaysettings.h b/src/displaysettings/displaysettings.h deleted file mode 100644 index 835da3f..0000000 --- a/src/displaysettings/displaysettings.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Device Utilities module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** 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 General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) 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.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-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef DISPLAYSETTINGS_H -#define DISPLAYSETTINGS_H - -#include <qobject.h> - -QT_BEGIN_NAMESPACE - -class DisplaySettingsPrivate; - -class Q_DECL_EXPORT DisplaySettings : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int displayBrightness READ displayBrightness WRITE setDisplayBrightness NOTIFY displayBrightnessChanged) - Q_PROPERTY(int physicalScreenSizeInch READ physicalScreenSizeInch WRITE setPhysicalScreenSizeInch NOTIFY physicalScreenSizeInchChanged) - Q_PROPERTY(int physicalScreenWidthMm READ physicalScreenWidthMm WRITE setPhysicalScreenWidthMm NOTIFY physicalScreenWidthMmChanged) - Q_PROPERTY(int physicalScreenHeightMm READ physicalScreenHeightMm WRITE setPhysicalScreenHeightMm NOTIFY physicalScreenHeightMmChanged) - Q_PROPERTY(bool physicalScreenSizeOverride READ physicalScreenSizeOverride WRITE setPhysicalScreenSizeOverride NOTIFY physicalScreenSizeOverrideChanged) - -public: - DisplaySettings(QObject *parent = Q_NULLPTR); - ~DisplaySettings(); - - int displayBrightness(); - int physicalScreenSizeInch() const; - int physicalScreenWidthMm() const; - int physicalScreenHeightMm() const; - bool physicalScreenSizeOverride() const; - -public Q_SLOTS: - bool setDisplayBrightness(int value); - void setPhysicalScreenSizeInch(int inches); - void setPhysicalScreenSizeOverride(bool enable); - void setPhysicalScreenWidthMm(int newWidth); - void setPhysicalScreenHeightMm(int newHeight); - -Q_SIGNALS: - void displayBrightnessChanged(int newValue); - void physicalScreenSizeInchChanged(int newInches); - void physicalScreenSizeOverrideChanged(bool newValue); - void physicalScreenWidthMmChanged(int newValue); - void physicalScreenHeightMmChanged(int newValue); - -protected: - DisplaySettingsPrivate *d_ptr; - - Q_DISABLE_COPY(DisplaySettings) - Q_DECLARE_PRIVATE(DisplaySettings) -}; - -QT_END_NAMESPACE - -#endif // DISPLAYSETTINGS_H diff --git a/src/displaysettings/displaysettings.pro b/src/displaysettings/displaysettings.pro deleted file mode 100644 index f19d872..0000000 --- a/src/displaysettings/displaysettings.pro +++ /dev/null @@ -1,16 +0,0 @@ -load(qt_build_config) - -TARGET = QtDisplaySettings -VERSION = 1.0 - -QT = core - -MODULE = displaysettings -load(qt_module) - -SOURCES += displaysettings.cpp \ - displaysettings_p.cpp - -HEADERS += displaysettings.h \ - displaysettings_p.h - diff --git a/src/displaysettings/displaysettings_p.cpp b/src/displaysettings/displaysettings_p.cpp deleted file mode 100644 index e62fca7..0000000 --- a/src/displaysettings/displaysettings_p.cpp +++ /dev/null @@ -1,278 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Device Utilities module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** 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 General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) 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.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-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include <QtMath> -#include <QDirIterator> -#include "displaysettings_p.h" - -QT_BEGIN_NAMESPACE - -DisplaySettingsPrivate::DisplaySettingsPrivate(DisplaySettings *qq) - :q_ptr(qq) - ,m_brightness(255) - ,m_lightDevicesInitialized(false) - ,m_physScreenSize(new PhysicalScreenSize(qq)) -{ - -} - -void DisplaySettingsPrivate::initLightDevices() -{ - if (m_lightDevicesInitialized) - return; - QDirIterator it(QStringLiteral("/sys/class/backlight")); - while (it.hasNext()) { - LightDevice ld; - ld.deviceFile = it.next() + QStringLiteral("/brightness"); - QFile maxFile(it.filePath() + QStringLiteral("/max_brightness")); - if (!maxFile.open(QIODevice::ReadOnly)) - continue; - bool ok = false; - ld.maxValue = maxFile.read(10).simplified().toUInt(&ok); - if (!ok || !ld.maxValue) - continue; - QFile valFile(ld.deviceFile); - if (!valFile.open(QIODevice::ReadOnly)) - continue; - ok = false; - uint val = valFile.read(10).simplified().toUInt(&ok); - if (!ok) - continue; - // map max->max as that is a common case, otherwise choose a reasonable value - ld.value = (val == ld.maxValue) ? 255 : (val * 256)/(ld.maxValue+1); - ld.name = it.fileName(); - m_lightDevices.append(ld); - } - if (!m_lightDevices.isEmpty()) - m_brightness = m_lightDevices.at(0).value; - m_lightDevicesInitialized = true; -} - - -bool DisplaySettingsPrivate::setDisplayBrightness(int v) -{ - quint8 value = qBound(0, v, 255); - initLightDevices(); - for (int i = 0; i < m_lightDevices.size(); i++) { - LightDevice &ld = m_lightDevices[i]; - QFile devFile(ld.deviceFile); - if (!devFile.open(QIODevice::WriteOnly)) - continue; - // Maps only 0 to 0, since 0 often means "off"; other values are degrees of "on". - uint newVal = value ? 1 + ((value * ld.maxValue) / 256) : 0; - devFile.write(QByteArray::number(newVal)); - ld.value = value; - } - m_brightness = value; - return true; -} - -int DisplaySettingsPrivate::displayBrightness() -{ - initLightDevices(); - return m_brightness; -} - -int DisplaySettingsPrivate::physicalScreenSizeInch() const -{ - return m_physScreenSize->size(); -} - -int DisplaySettingsPrivate::physicalScreenWidthMm() const -{ - return m_physScreenSize->widthMm(); -} - -int DisplaySettingsPrivate::physicalScreenHeightMm() const -{ - return m_physScreenSize->heightMm(); -} - -void DisplaySettingsPrivate::setPhysicalScreenSizeInch(int inches) -{ - Q_Q(DisplaySettings); - if (m_physScreenSize->size() != inches) { - m_physScreenSize->setSize(inches); - emit q->physicalScreenSizeInchChanged(inches); - } -} - -void DisplaySettingsPrivate::setPhysicalScreenWidthMm(int newWidth) -{ - Q_Q(DisplaySettings); - if (m_physScreenSize->widthMm() != newWidth) { - m_physScreenSize->setSizeMm(newWidth, m_physScreenSize->heightMm()); - emit q->physicalScreenWidthMmChanged(newWidth); - } -} - -void DisplaySettingsPrivate::setPhysicalScreenHeightMm(int newHeight) -{ - Q_Q(DisplaySettings); - if (m_physScreenSize->heightMm() != newHeight) { - m_physScreenSize->setSizeMm(m_physScreenSize->widthMm(), newHeight); - emit q->physicalScreenHeightMmChanged(newHeight); - } -} - -bool DisplaySettingsPrivate::physicalScreenSizeOverride() const -{ - return m_physScreenSize->enabled(); -} - -void DisplaySettingsPrivate::setPhysicalScreenSizeOverride(bool enable) -{ - Q_Q(DisplaySettings); - if (m_physScreenSize->enabled() != enable) { - m_physScreenSize->setEnabled(enable); - emit q->physicalScreenSizeOverrideChanged(enable); - } -} - -PhysicalScreenSize::PhysicalScreenSize(QObject *parent) - : QObject(parent) - ,physScreenSizeEnabled(false), physScreenSizeInch(7) -{ - physWriteTimer.setSingleShot(true); - physWriteTimer.setInterval(1000); - QObject::connect(&physWriteTimer, SIGNAL(timeout()), this, SLOT(onTimeout())); - - read(QStringLiteral("/etc/appcontroller.conf")); - read(QStringLiteral("/var/lib/b2qt/appcontroller.conf.d/physical_screen_size.conf")); -} - -PhysicalScreenSize::~PhysicalScreenSize() -{ - -} - -void PhysicalScreenSize::read(const QString &filename) -{ - QFile f(filename); - if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) - return; - - physScreenWidthMm = 154; - physScreenHeightMm = 90; - int found = 0; - while (!f.atEnd()) { - QByteArray line = f.readLine().trimmed(); - if (line.startsWith(QByteArrayLiteral("env="))) { - QByteArrayList values = line.split('='); - if (values.count() == 3) { - bool ok; - if (values[1] == QByteArrayLiteral("QT_QPA_EGLFS_PHYSICAL_WIDTH")) { - int val = values[2].toInt(&ok); - if (ok) { - ++found; - physScreenWidthMm = val; - } - } else if (values[1] == QByteArrayLiteral("QT_QPA_EGLFS_PHYSICAL_HEIGHT")) { - int val = values[2].toInt(&ok); - if (ok) { - ++found; - physScreenHeightMm = val; - } - } - } - } - } - if (found == 2) - physScreenSizeEnabled = true; - - const qreal diagMM = qSqrt(physScreenWidthMm * physScreenWidthMm + physScreenHeightMm * physScreenHeightMm); - physScreenSizeInch = qRound(diagMM / 25.4); -} - -void PhysicalScreenSize::onTimeout() -{ - write(); -} - -void PhysicalScreenSize::write(bool includePhysSize) -{ - QDir(QStringLiteral("/var/lib")).mkpath(QStringLiteral("b2qt/appcontroller.conf.d")); - write(QStringLiteral("/var/lib/b2qt/appcontroller.conf.d/physical_screen_size.conf"), includePhysSize); -} - -void PhysicalScreenSize::write(const QString &filename, bool includePhysSize) -{ - QFile f(filename); - - QByteArrayList lines; - if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { - while (!f.atEnd()) { - QByteArray line = f.readLine().trimmed(); - if (!line.startsWith(QByteArrayLiteral("env=QT_QPA_EGLFS_PHYSICAL_WIDTH=")) - && !line.startsWith(QByteArrayLiteral("env=QT_QPA_EGLFS_PHYSICAL_HEIGHT="))) - lines.append(line); - } - f.close(); - } - - if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) - return; - - const int physScreenHeight = physScreenHeightMm; - const int physScreenWidth = physScreenWidthMm; - - foreach (const QByteArray &line, lines) - f.write(line + QByteArrayLiteral("\n")); - - if (includePhysSize) - f.write(QByteArrayLiteral("env=QT_QPA_EGLFS_PHYSICAL_WIDTH=") + QByteArray::number(physScreenWidth) - + QByteArrayLiteral("\nenv=QT_QPA_EGLFS_PHYSICAL_HEIGHT=") + QByteArray::number(physScreenHeight) - + QByteArrayLiteral("\n")); -} - -void PhysicalScreenSize::setSize(int inches) -{ - physScreenSizeInch = inches; - physWriteTimer.start(); -} - -void PhysicalScreenSize::setSizeMm(int width, int height) -{ - physScreenWidthMm = width; - physScreenHeightMm = height; - physWriteTimer.start(); -} - -bool PhysicalScreenSize::enabled() const -{ - return physScreenSizeEnabled; -} - -void PhysicalScreenSize::setEnabled(bool enable) -{ - physScreenSizeEnabled = enable; - // Rewrite appcontroller.conf with or without the physical width/height lines. - write(enable); -} - -QT_END_NAMESPACE diff --git a/src/displaysettings/displaysettings_p.h b/src/displaysettings/displaysettings_p.h deleted file mode 100644 index 91825e8..0000000 --- a/src/displaysettings/displaysettings_p.h +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Device Utilities module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** 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 General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) 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.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-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef DISPLAYSETTINGSPRIVATE_H -#define DISPLAYSETTINGSPRIVATE_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QTimer> -#include "displaysettings.h" - -QT_BEGIN_NAMESPACE - -class PhysicalScreenSize : public QObject -{ - Q_OBJECT - -public: - explicit PhysicalScreenSize(QObject *parent = Q_NULLPTR); - virtual ~PhysicalScreenSize(); - - void setSize(int inches); - void setSizeMm(int widthMm, int heightMm); - int size() const { return physScreenSizeInch; } - int widthMm() const { return physScreenWidthMm; } - int heightMm() const { return physScreenHeightMm; } - bool enabled() const; - void setEnabled(bool enable); - -private slots: - void onTimeout(); - -private: - void read(const QString &filename); - void write(bool includePhysSize = true); - void write(const QString &filename, bool includePhysSize = true); - - bool physScreenSizeEnabled; - int physScreenSizeInch; - int physScreenWidthMm; - int physScreenHeightMm; - QTimer physWriteTimer; -}; - -class LightDevice -{ -public: - QString name; - QString deviceFile; - quint8 value; - uint maxValue; -}; - -class DisplaySettingsPrivate -{ - Q_DECLARE_PUBLIC(DisplaySettings) -public: - DisplaySettingsPrivate(DisplaySettings* qq); - int displayBrightness(); - int physicalScreenSizeInch() const; - int physicalScreenWidthMm() const; - int physicalScreenHeightMm() const; - bool physicalScreenSizeOverride() const; - - bool setDisplayBrightness(int value); - void setPhysicalScreenSizeInch(int inches); - void setPhysicalScreenWidthMm(int newWidth); - void setPhysicalScreenHeightMm(int newHeight); - void setPhysicalScreenSizeOverride(bool enable); -private: - void initLightDevices(); - DisplaySettings *q_ptr; - int m_brightness; - int m_screenSizeInch; - int m_screenWidthMm; - int m_screenHeightMm; - bool m_sizeOverride; - QList<LightDevice> m_lightDevices; - bool m_lightDevicesInitialized; - PhysicalScreenSize *m_physScreenSize; -}; - -QT_END_NAMESPACE - -#endif // DISPLAYSETTINGSPRIVATE_H |