Skip to content

Commit f76b43d

Browse files
committed
followpanel: add focus following panel example
1 parent 9c83cc2 commit f76b43d

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

focus_following_panel/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Focus following panel
2+
3+
This is a hyprland specific panel that follows monitor focus using the hyprland
4+
unix socket for events. To run it you will need to be using hyprland.
5+
6+
You can run the panel with `quickshell -p shell.qml`.

focus_following_panel/shell.qml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import QtQuick
2+
import Quickshell
3+
import Quickshell.Io
4+
5+
ShellRoot {
6+
Socket {
7+
// Create and connect a Socket to the hyprland event socket.
8+
// https://wiki.hyprland.org/IPC/
9+
path: `/tmp/hypr/${Quickshell.env("HYPRLAND_INSTANCE_SIGNATURE")}/.socket2.sock`
10+
connected: true
11+
12+
parser: SplitParser {
13+
// Regex that will return the newly focused monitor when it changes.
14+
property var regex: new RegExp("focusedmon>>(.+),.*");
15+
16+
// Sent for every line read from the socket
17+
onRead: msg => {
18+
const match = regex.exec(msg);
19+
20+
if (match != null) {
21+
// Filter out the right screen from the list and update the panel.
22+
// match[1] will always be the monitor name captured by the regex.
23+
panel.screen = Quickshell.screens.filter(screen => screen.name == match[1])[0];
24+
}
25+
}
26+
}
27+
}
28+
29+
// The default screen a panel will be created on under hyprland is the currently
30+
// focused one. We use this since we don't get a focusedmon event on connect.
31+
PanelWindow {
32+
id: panel
33+
34+
anchors {
35+
left: true
36+
top: true
37+
bottom: true
38+
}
39+
40+
Text {
41+
anchors.centerIn: parent
42+
text: "todo"
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)