Skip to content

Commit c30a4fa

Browse files
committed
reload-popup: add example
1 parent 7d0bfb6 commit c30a4fa

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed

reload-popup/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Reload Popup
2+
3+
A popup in the corner of the screen that appears when hot reloading the configuration,
4+
which you can easily add to an existing shell.
5+
6+
You can try it out by running `quickshell -p shell.qml` which will put a simple bar
7+
on the screen. The popup will appear if the file is edited, and display the error
8+
if the configuration is invalid.
9+
10+
After making a good edit:
11+
![](./reload-good.png)
12+
13+
After making a bad edit:
14+
![](./reload-bad.png)

reload-popup/ReloadPopup.qml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import QtQuick
2+
import QtQuick.Layouts
3+
import Quickshell
4+
5+
Scope {
6+
id: root
7+
property bool failed;
8+
property string errorString;
9+
10+
// Connect to the Quickshell global to listen for the reload signals.
11+
Connections {
12+
target: Quickshell
13+
14+
function onReloadCompleted() {
15+
root.failed = false;
16+
popupLoader.loading = true;
17+
}
18+
19+
function onReloadFailed(error: string) {
20+
// Close any existing popup before making a new one.
21+
popupLoader.active = false;
22+
23+
root.failed = true;
24+
root.errorString = error;
25+
popupLoader.loading = true;
26+
}
27+
}
28+
29+
// Keep the popup in a loader because it isn't needed most of the timeand will take up
30+
// memory that could be used for something else.
31+
LazyLoader {
32+
id: popupLoader
33+
34+
PanelWindow {
35+
id: popup
36+
37+
anchors {
38+
top: true
39+
left: true
40+
}
41+
42+
margins {
43+
top: 25
44+
left: 25
45+
}
46+
47+
width: rect.width
48+
height: rect.height
49+
50+
// color blending is a bit odd as detailed in the type reference.
51+
color: "transparent"
52+
53+
Rectangle {
54+
id: rect
55+
color: failed ? "#40802020" : "#40009020"
56+
57+
implicitHeight: layout.implicitHeight + 50
58+
implicitWidth: layout.implicitWidth + 30
59+
60+
// Fills the whole area of the rectangle, making any clicks go to it,
61+
// which dismiss the popup.
62+
MouseArea {
63+
id: mouseArea
64+
anchors.fill: parent
65+
onClicked: popupLoader.active = false
66+
67+
// makes the mouse area track mouse hovering, so the hide animation
68+
// can be paused when hovering.
69+
hoverEnabled: true
70+
}
71+
72+
ColumnLayout {
73+
id: layout
74+
anchors {
75+
top: parent.top
76+
topMargin: 20
77+
horizontalCenter: parent.horizontalCenter
78+
}
79+
80+
Text {
81+
text: root.failed ? "Reload failed." : "Reloaded completed!"
82+
color: "white"
83+
}
84+
85+
Text {
86+
text: root.errorString
87+
color: "white"
88+
// When visible is false, it also takes up no space.
89+
visible: root.errorString != ""
90+
}
91+
}
92+
93+
// A progress bar on the bottom of the screen, showing how long until the
94+
// popup is removed.
95+
Rectangle {
96+
id: bar
97+
color: "#20ffffff"
98+
anchors.bottom: parent.bottom
99+
anchors.left: parent.left
100+
height: 20
101+
102+
PropertyAnimation {
103+
id: anim
104+
target: bar
105+
property: "width"
106+
from: rect.width
107+
to: 0
108+
duration: failed ? 10000 : 800
109+
onFinished: popupLoader.active = false
110+
111+
// Pause the animation when the mouse is hovering over the popup,
112+
// so it stays onscreen while reading. This updates reactively
113+
// when the mouse moves on and off the popup.
114+
paused: mouseArea.containsMouse
115+
}
116+
}
117+
118+
// We could set `running: true` inside the animation, but the width of the
119+
// rectangle might not be calculated yet, due to the layout.
120+
// In the `Component.onCompleted` event handler, all of the component's
121+
// properties and children have been initialized.
122+
Component.onCompleted: anim.start()
123+
}
124+
}
125+
}
126+
}

reload-popup/reload-bad.png

72.6 KB
Loading

reload-popup/reload-good.png

52.1 KB
Loading

reload-popup/shell.qml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import QtQuick
2+
import Quickshell
3+
4+
ShellRoot {
5+
// Add the popup to the shell.
6+
ReloadPopup {}
7+
8+
// The rest of your shell, in this case a very simple bar.
9+
// Try editing this.
10+
PanelWindow {
11+
anchors {
12+
left: true
13+
top: true
14+
right: true
15+
}
16+
17+
height: 30
18+
19+
Text {
20+
anchors.centerIn: parent
21+
text: "I'm a bar!"
22+
an error
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)