forked from quickshell/quickshell

sway: add urgent and focused dispatchers to workspaces flake: add sway toggle WIP sway: add monitor status sway: handle multiple ipc events in one line sway: reuse socket connection for dispatches & better command type handling WIP sway: add associated monitor to a workspace i3/sway: update to allow for i3 compatibility i3/sway: manage setting the focused monitors i3/sway: fix multi monitor crash i3/sway: fix linting errors i3/sway: update nix package flag naming to i3 i3/sway: add documentation, fix module.md and impl monitorFor i3/sway: handle more workspace ipc events i3/sway: fix review i3/sway: fix crash due to newline breaking up an IPC message i3/sway: handle broken messages by forwarding to the next magic sequence i3/sway: break loop when buffer is empty i3/sway: fix monitor focus & focused monitor signal not being emitted i3/sway: use datastreams instead of qbytearrays for socket reading i3/sway: fix lint issues i3/sway: drop second socket connection, remove dispatch return value, recreate IPC connection on fatal error i3/sway: handle run_command responses i3/sway: remove reconnection on unknown event i3/sway: fix formatting, lint & avoid writing to socket if connection is not open
100 lines
2.8 KiB
C++
100 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include <qobject.h>
|
|
|
|
#include "connection.hpp"
|
|
|
|
namespace qs::i3::ipc {
|
|
|
|
///! I3/Sway monitors
|
|
class I3Monitor: public QObject {
|
|
Q_OBJECT;
|
|
|
|
/// The ID of this monitor
|
|
Q_PROPERTY(qint32 id READ id NOTIFY idChanged);
|
|
/// The name of this monitor
|
|
Q_PROPERTY(QString name READ name NOTIFY nameChanged);
|
|
/// Wether this monitor is turned on or not
|
|
Q_PROPERTY(bool power READ power NOTIFY powerChanged);
|
|
|
|
/// The current workspace
|
|
Q_PROPERTY(qs::i3::ipc::I3Workspace* focusedWorkspace READ focusedWorkspace NOTIFY
|
|
focusedWorkspaceChanged);
|
|
|
|
/// The X coordinate of this monitor inside the monitor layout
|
|
Q_PROPERTY(qint32 x READ x NOTIFY xChanged);
|
|
|
|
/// The Y coordinate of this monitor inside the monitor layout
|
|
Q_PROPERTY(qint32 y READ y NOTIFY yChanged);
|
|
|
|
/// The width in pixels of this monitor
|
|
Q_PROPERTY(qint32 width READ width NOTIFY widthChanged);
|
|
|
|
/// The height in pixels of this monitor
|
|
Q_PROPERTY(qint32 height READ height NOTIFY heightChanged);
|
|
|
|
/// The scaling factor of this monitor, 1 means it runs at native resolution
|
|
Q_PROPERTY(qreal scale READ scale NOTIFY scaleChanged);
|
|
|
|
/// Whether this monitor is currently in focus
|
|
Q_PROPERTY(bool focused READ focused NOTIFY focusedChanged);
|
|
|
|
/// Last JSON returned for this monitor, as a JavaScript object.
|
|
///
|
|
/// This updates every time Quickshell receives an `output` event from i3/Sway
|
|
Q_PROPERTY(QVariantMap lastIpcObject READ lastIpcObject NOTIFY lastIpcObjectChanged);
|
|
|
|
QML_ELEMENT;
|
|
QML_UNCREATABLE("I3Monitors must be retrieved from the I3Ipc object.");
|
|
|
|
public:
|
|
explicit I3Monitor(I3Ipc* ipc): QObject(ipc), ipc(ipc) {}
|
|
|
|
[[nodiscard]] qint32 id() const;
|
|
[[nodiscard]] QString name() const;
|
|
[[nodiscard]] bool power() const;
|
|
[[nodiscard]] I3Workspace* focusedWorkspace() const;
|
|
[[nodiscard]] qint32 x() const;
|
|
[[nodiscard]] qint32 y() const;
|
|
[[nodiscard]] qint32 width() const;
|
|
[[nodiscard]] qint32 height() const;
|
|
[[nodiscard]] qreal scale() const;
|
|
[[nodiscard]] bool focused() const;
|
|
[[nodiscard]] QVariantMap lastIpcObject() const;
|
|
|
|
void updateFromObject(const QVariantMap& obj);
|
|
|
|
void setFocusedWorkspace(I3Workspace* workspace);
|
|
void setFocus(bool focus);
|
|
signals:
|
|
void idChanged();
|
|
void nameChanged();
|
|
void powerChanged();
|
|
void focusedWorkspaceChanged();
|
|
void xChanged();
|
|
void yChanged();
|
|
void widthChanged();
|
|
void heightChanged();
|
|
void scaleChanged();
|
|
void lastIpcObjectChanged();
|
|
void focusedChanged();
|
|
|
|
private:
|
|
I3Ipc* ipc;
|
|
|
|
qint32 mId = -1;
|
|
QString mName;
|
|
bool mPower = false;
|
|
qint32 mX = 0;
|
|
qint32 mY = 0;
|
|
qint32 mWidth = 0;
|
|
qint32 mHeight = 0;
|
|
qreal mScale = 1;
|
|
bool mFocused = false;
|
|
QVariantMap mLastIpcObject;
|
|
|
|
I3Workspace* mFocusedWorkspace = nullptr;
|
|
QString mFocusedWorkspaceName; // use for faster change detection
|
|
};
|
|
|
|
} // namespace qs::i3::ipc
|