Skip to content

Commit 4a93776

Browse files
committed
i3/sway: add documentation, fix module.md and impl monitorFor
1 parent 4852454 commit 4a93776

File tree

9 files changed

+102
-10
lines changed

9 files changed

+102
-10
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ boption(HYPRLAND_IPC " Hyprland IPC" ON REQUIRES HYPRLAND)
5656
boption(HYPRLAND_GLOBAL_SHORTCUTS " Hyprland Global Shortcuts" ON REQUIRES HYPRLAND)
5757
boption(HYPRLAND_FOCUS_GRAB " Hyprland Focus Grabbing" ON REQUIRES HYPRLAND)
5858
boption(I3 " I3/Sway" ON)
59-
boption(I3_IPC " I3/Sway IPC" ON)
59+
boption(I3_IPC " I3/Sway IPC" ON REQUIRES I3)
6060
boption(X11 "X11" ON)
6161
boption(SERVICE_STATUS_NOTIFIER "System Tray" ON)
6262
boption(SERVICE_PIPEWIRE "PipeWire" ON)

src/x11/i3/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ qt_add_qml_module(quickshell-i3
1515
IMPORTS ${I3_MODULES}
1616
)
1717

18+
install_qml_module(quickshell-i3)
19+
1820
qs_pch(quickshell-i3)
1921
qs_pch(quickshell-i3plugin)
2022

src/x11/i3/ipc/connection.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <qtypes.h>
2121

2222
#include "../../../core/model.hpp"
23+
#include "../../../core/qmlscreen.hpp"
2324
#include "connection.hpp"
2425
#include "monitor.hpp"
2526
#include "workspace.hpp"
@@ -196,6 +197,7 @@ void I3Ipc::eventSocketStateChanged(QLocalSocket::LocalSocketState state) {
196197

197198
QString I3Ipc::socketPath() const { return this->mSocketPath; }
198199
I3Workspace* I3Ipc::focusedWorkspace() const { return this->mFocusedWorkspace; }
200+
I3Monitor* I3Ipc::focusedMonitor() const { return this->mFocusedMonitor; }
199201

200202
void I3Ipc::setFocusedWorkspace(I3Workspace* workspace) {
201203
if (workspace == this->mFocusedWorkspace) return;
@@ -444,6 +446,12 @@ void I3Ipc::handleWorkspaceEvent(I3IpcEvent* event) {
444446
}
445447
}
446448

449+
I3Monitor* I3Ipc::monitorFor(QuickshellScreenInfo* screen) {
450+
if (screen == nullptr) return nullptr;
451+
452+
return this->findMonitorByName(screen->name());
453+
}
454+
447455
I3Workspace* I3Ipc::findWorkspaceByName(const QString& name) {
448456
auto mList = this->mWorkspaces.valueList();
449457
auto workspaceIter = std::find_if(mList.begin(), mList.end(), [name](const I3Workspace* m) {

src/x11/i3/ipc/connection.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <qtypes.h>
1212

1313
#include "../../../core/model.hpp"
14+
#include "../../../core/qmlscreen.hpp"
1415

1516
namespace qs::i3::ipc {
1617

@@ -39,7 +40,7 @@ enum EventCode {
3940

4041
using Event = std::tuple<EventCode, QJsonDocument>;
4142

42-
///! I3 IPC Events
43+
///! I3/Sway IPC Events
4344
/// Emitted by @@I3.rawEvent(s)
4445
class I3IpcEvent: public QObject {
4546
Q_OBJECT;
@@ -86,6 +87,9 @@ class I3Ipc: public QObject {
8687
void refreshWorkspaces();
8788
void refreshMonitors();
8889

90+
I3Monitor* monitorFor(QuickshellScreenInfo* screen);
91+
92+
[[nodiscard]] I3Monitor* focusedMonitor() const;
8993
[[nodiscard]] I3Workspace* focusedWorkspace() const;
9094
[[nodiscard]] ObjectModel<I3Monitor>* monitors();
9195
[[nodiscard]] ObjectModel<I3Workspace>* workspaces();

src/x11/i3/ipc/monitor.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,43 @@
66

77
namespace qs::i3::ipc {
88

9+
///! I3/Sway monitors
910
class I3Monitor: public QObject {
1011
Q_OBJECT;
1112

13+
/// The ID of this monitor
1214
Q_PROPERTY(qint32 id READ id NOTIFY idChanged);
15+
/// The name of this monitor
1316
Q_PROPERTY(QString name READ name NOTIFY nameChanged);
17+
/// Wether this monitor is turned on or not
1418
Q_PROPERTY(bool power READ power NOTIFY powerChanged);
19+
20+
/// The currently active workspace
21+
/// TODO: replace with a list of all workspaces
1522
Q_PROPERTY(qs::i3::ipc::I3Workspace* activeWorkspace READ activeWorkspace NOTIFY
1623
activeWorkspaceChanged);
24+
25+
/// The X coordinate of this monitor inside the monitor layout
1726
Q_PROPERTY(qint32 x READ x NOTIFY xChanged);
27+
28+
/// The Y coordinate of this monitor inside the monitor layout
1829
Q_PROPERTY(qint32 y READ y NOTIFY yChanged);
30+
31+
/// The width in pixels of this monitor
1932
Q_PROPERTY(qint32 width READ width NOTIFY widthChanged);
33+
34+
/// The height in pixels of this monitor
2035
Q_PROPERTY(qint32 height READ height NOTIFY heightChanged);
36+
37+
/// The scaling factor of this monitor, 1 means it runs at native resolution
2138
Q_PROPERTY(qreal scale READ scale NOTIFY scaleChanged);
39+
40+
/// Whether this monitor is currently in focus
2241
Q_PROPERTY(bool focused READ focused NOTIFY focusedChanged);
42+
43+
/// Last JSON returned for this monitor, as a JavaScript object.
44+
///
45+
/// This updates every time Quickshell receives an `output` event from i3/Sway
2346
Q_PROPERTY(QVariantMap lastIpcObject READ lastIpcObject NOTIFY lastIpcObjectChanged);
2447

2548
QML_ELEMENT;

src/x11/i3/ipc/qml.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <qstring.h>
55

66
#include "../../../core/model.hpp"
7+
#include "../../../core/qmlscreen.hpp"
78
#include "connection.hpp"
89
#include "workspace.hpp"
910

@@ -36,4 +37,18 @@ ObjectModel<I3Workspace>* I3IpcQml::workspaces() { return I3Ipc::instance()->wor
3637

3738
I3Workspace* I3IpcQml::focusedWorkspace() { return I3Ipc::instance()->focusedWorkspace(); }
3839

40+
I3Monitor* I3IpcQml::focusedMonitor() { return I3Ipc::instance()->focusedMonitor(); }
41+
42+
I3Workspace* I3IpcQml::findWorkspaceByName(const QString& name) {
43+
return I3Ipc::instance()->findWorkspaceByName(name);
44+
}
45+
46+
I3Monitor* I3IpcQml::findMonitorByName(const QString& name) {
47+
return I3Ipc::instance()->findMonitorByName(name);
48+
}
49+
50+
I3Monitor* I3IpcQml::monitorFor(QuickshellScreenInfo* screen) {
51+
return I3Ipc::instance()->monitorFor(screen);
52+
}
53+
3954
} // namespace qs::i3::ipc

src/x11/i3/ipc/qml.hpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
#include <qobject.h>
44

55
#include "../../../core/doc.hpp"
6+
#include "../../../core/qmlscreen.hpp"
67
#include "connection.hpp"
78

89
namespace qs::i3::ipc {
910

11+
///! I3/Sway IPC integration
1012
class I3IpcQml: public QObject {
1113
Q_OBJECT;
1214
// clang-format off
1315
/// Path to the I3 socket
1416
Q_PROPERTY(QString socketPath READ socketPath CONSTANT);
1517

1618
Q_PROPERTY(qs::i3::ipc::I3Workspace* focusedWorkspace READ focusedWorkspace NOTIFY focusedWorkspaceChanged);
19+
Q_PROPERTY(qs::i3::ipc::I3Monitor* focusedMonitor READ focusedMonitor NOTIFY focusedMonitorChanged);
1720
/// All I3 monitors.
1821
QSDOC_TYPE_OVERRIDE(ObjectModel<qs::i3::ipc::I3Monitor>*);
1922
Q_PROPERTY(UntypedObjectModel* monitors READ monitors CONSTANT);
@@ -27,7 +30,7 @@ class I3IpcQml: public QObject {
2730
public:
2831
explicit I3IpcQml();
2932

30-
/// Execute a I3 command [man 5 I3]
33+
/// Execute an I3/Sway command [man 5 sway](https://man.archlinux.org/man/sway.5.en#COMMANDS)
3134
Q_INVOKABLE static void dispatch(const QString& request);
3235

3336
/// Refresh monitor information.
@@ -36,14 +39,35 @@ class I3IpcQml: public QObject {
3639
/// Refresh workspace information.
3740
Q_INVOKABLE static void refreshWorkspaces();
3841

42+
/// Find an I3Workspace using its name, returns null if the workspace doesn't exist.
43+
Q_INVOKABLE static I3Workspace* findWorkspaceByName(const QString& name);
44+
45+
/// Find an I3Monitor using its name, returns null if the monitor doesn't exist.
46+
Q_INVOKABLE static I3Monitor* findMonitorByName(const QString& name);
47+
48+
/// Return the i3/Sway monitor associated with `screen`
49+
Q_INVOKABLE static I3Monitor* monitorFor(QuickshellScreenInfo* screen);
50+
51+
/// The path to the I3 or Sway socket currently being used
3952
[[nodiscard]] static QString socketPath();
53+
54+
/// All I3Monitors
4055
[[nodiscard]] static ObjectModel<I3Monitor>* monitors();
56+
57+
/// All I3Workspaces
4158
[[nodiscard]] static ObjectModel<I3Workspace>* workspaces();
59+
60+
/// The currently focused Workspace
4261
[[nodiscard]] static I3Workspace* focusedWorkspace();
62+
63+
/// The currently focused Monitor
64+
[[nodiscard]] static I3Monitor* focusedMonitor();
65+
4366
signals:
4467
void rawEvent(I3IpcEvent* event);
4568
void connected();
4669
void focusedWorkspaceChanged();
70+
void focusedMonitorChanged();
4771
};
4872

4973
} // namespace qs::i3::ipc

src/x11/i3/ipc/workspace.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,31 @@
44

55
namespace qs::i3::ipc {
66

7+
///! I3/Sway workspaces
78
class I3Workspace: public QObject {
89
Q_OBJECT;
910

11+
/// The ID of this workspace, it is unique for i3/Sway launch
1012
Q_PROPERTY(qint32 id READ id NOTIFY idChanged);
13+
14+
/// The name of this workspace
1115
Q_PROPERTY(QString name READ name NOTIFY nameChanged);
16+
17+
/// The number of this workspace
1218
Q_PROPERTY(qint32 num READ num NOTIFY numChanged);
19+
20+
/// If a window in this workspace has an urgent notification
1321
Q_PROPERTY(bool urgent READ urgent NOTIFY urgentChanged);
22+
23+
/// If this workspace is the one currently in focus
1424
Q_PROPERTY(bool focused READ focused NOTIFY focusedChanged);
25+
26+
/// The monitor this workspace is being displayed on
1527
Q_PROPERTY(qs::i3::ipc::I3Monitor* monitor READ monitor NOTIFY monitorChanged);
28+
29+
/// Last JSON returned for this workspace, as a JavaScript object.
30+
///
31+
/// This updates every time we receive a `workspace` event from i3/Sway
1632
Q_PROPERTY(QVariantMap lastIpcObject READ lastIpcObject NOTIFY lastIpcObjectChanged);
1733

1834
QML_ELEMENT;

src/x11/i3/module.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name = "Quickshell.Sway"
2-
description = "Sway specific Quickshell types"
1+
name = "Quickshell.I3"
2+
description = "I3 specific Quickshell types"
33
headers = [
4-
./ipc/connection.hpp
5-
./ipc/qml.hpp
6-
./ipc/workspace.hpp
7-
./ipc/monitor.hpp
4+
"ipc/connection.hpp",
5+
"ipc/qml.hpp",
6+
"ipc/workspace.hpp",
7+
"ipc/monitor.hpp",
88
]
9-
---
9+
-----

0 commit comments

Comments
 (0)