2024-02-04 12:58:58 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <qnamespace.h>
|
|
|
|
#include <qobject.h>
|
|
|
|
#include <qqmlintegration.h>
|
|
|
|
#include <qscreen.h>
|
|
|
|
#include <qtmetamacros.h>
|
|
|
|
#include <qtypes.h>
|
|
|
|
|
|
|
|
// unfortunately QQuickScreenInfo is private.
|
2024-02-12 12:21:24 +00:00
|
|
|
|
2024-02-17 13:14:15 +00:00
|
|
|
/// Monitor object useful for setting the monitor for a [ShellWindow]
|
2024-02-12 12:21:24 +00:00
|
|
|
/// or querying information about the monitor.
|
|
|
|
///
|
|
|
|
/// > [!WARNING] If the monitor is disconnected than any stored copies of its ShellMonitor will
|
|
|
|
/// > be marked as dangling and all properties will return default values.
|
|
|
|
/// > Reconnecting the monitor will not reconnect it to the ShellMonitor object.
|
|
|
|
///
|
|
|
|
/// Due to some technical limitations, it was not possible to reuse the native qml [Screen] type.
|
|
|
|
///
|
2024-02-17 13:14:15 +00:00
|
|
|
/// [ShellWindow]: ../shellwindow
|
2024-02-12 12:21:24 +00:00
|
|
|
/// [Screen]: https://doc.qt.io/qt-6/qml-qtquick-screen.html
|
2024-02-12 10:16:22 +00:00
|
|
|
class QuickShellScreenInfo: public QObject {
|
2024-02-04 12:58:58 +00:00
|
|
|
Q_OBJECT;
|
2024-02-12 12:21:24 +00:00
|
|
|
QML_NAMED_ELEMENT(ShellScreen);
|
|
|
|
QML_UNCREATABLE("ShellScreen can only be obtained via QuickShell.screens");
|
2024-02-04 12:58:58 +00:00
|
|
|
// clang-format off
|
2024-02-12 12:21:24 +00:00
|
|
|
/// The name of the screen as seen by the operating system.
|
|
|
|
///
|
|
|
|
/// Usually something like `DP-1`, `HDMI-1`, `eDP-1`.
|
2024-02-19 03:57:12 +00:00
|
|
|
Q_PROPERTY(QString name READ name CONSTANT);
|
2024-02-19 02:06:32 +00:00
|
|
|
Q_PROPERTY(qint32 width READ width NOTIFY geometryChanged);
|
|
|
|
Q_PROPERTY(qint32 height READ height NOTIFY geometryChanged);
|
2024-02-12 12:21:24 +00:00
|
|
|
/// The number of physical pixels per millimeter.
|
2024-02-19 02:06:32 +00:00
|
|
|
Q_PROPERTY(qreal physicalPixelDensity READ physicalPixelDensity NOTIFY physicalPixelDensityChanged);
|
2024-02-12 12:21:24 +00:00
|
|
|
/// The number of device-independent (scaled) pixels per millimeter.
|
2024-02-04 12:58:58 +00:00
|
|
|
Q_PROPERTY(qreal logicalPixelDensity READ logicalPixelDensity NOTIFY logicalPixelDensityChanged);
|
2024-02-12 12:21:24 +00:00
|
|
|
/// The ratio between physical pixels and device-independent (scaled) pixels.
|
2024-02-19 02:06:32 +00:00
|
|
|
Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY physicalPixelDensityChanged);
|
2024-02-04 12:58:58 +00:00
|
|
|
Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation NOTIFY orientationChanged);
|
|
|
|
Q_PROPERTY(Qt::ScreenOrientation primatyOrientation READ primaryOrientation NOTIFY primaryOrientationChanged);
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
public:
|
2024-02-19 02:06:32 +00:00
|
|
|
QuickShellScreenInfo(QObject* parent, QScreen* screen); //: QObject(parent), screen(screen) {}
|
2024-02-04 12:58:58 +00:00
|
|
|
|
2024-02-12 10:16:22 +00:00
|
|
|
bool operator==(QuickShellScreenInfo& other) const;
|
2024-02-04 12:58:58 +00:00
|
|
|
|
|
|
|
[[nodiscard]] QString name() const;
|
|
|
|
[[nodiscard]] qint32 width() const;
|
|
|
|
[[nodiscard]] qint32 height() const;
|
2024-02-19 02:06:32 +00:00
|
|
|
[[nodiscard]] qreal physicalPixelDensity() const;
|
2024-02-04 12:58:58 +00:00
|
|
|
[[nodiscard]] qreal logicalPixelDensity() const;
|
|
|
|
[[nodiscard]] qreal devicePixelRatio() const;
|
|
|
|
[[nodiscard]] Qt::ScreenOrientation orientation() const;
|
|
|
|
[[nodiscard]] Qt::ScreenOrientation primaryOrientation() const;
|
|
|
|
|
|
|
|
QScreen* screen;
|
|
|
|
|
2024-02-19 03:57:12 +00:00
|
|
|
private:
|
|
|
|
void warnDangling() const;
|
|
|
|
bool dangling = false;
|
|
|
|
|
2024-02-04 12:58:58 +00:00
|
|
|
signals:
|
2024-02-19 02:06:32 +00:00
|
|
|
void geometryChanged();
|
|
|
|
void physicalPixelDensityChanged();
|
2024-02-04 12:58:58 +00:00
|
|
|
void logicalPixelDensityChanged();
|
|
|
|
void orientationChanged();
|
|
|
|
void primaryOrientationChanged();
|
2024-02-19 03:57:12 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void screenDestroyed();
|
2024-02-04 12:58:58 +00:00
|
|
|
};
|