-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.qml
More file actions
241 lines (224 loc) · 8.16 KB
/
Main.qml
File metadata and controls
241 lines (224 loc) · 8.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import "."
import QtQuick
import SddmComponents
import QtQuick.Effects
import QtMultimedia
import "components"
Item {
id: root
state: Config.lockScreenDisplay ? "lockState" : "loginState"
// TODO: Add own translations: https://github.com/sddm/sddm/wiki/Localization
TextConstants {
id: textConstants
}
property bool capsLockOn: false
Component.onCompleted: {
if (keyboard)
capsLockOn = keyboard.capsLock;
}
onCapsLockOnChanged: {
loginScreen.updateCapsLock();
}
states: [
State {
name: "lockState"
PropertyChanges {
target: lockScreen
opacity: 1.0
}
PropertyChanges {
target: loginScreen
opacity: 0.0
}
PropertyChanges {
target: loginScreen.loginContainer
scale: 0.5
}
PropertyChanges {
target: backgroundEffect
blurMax: Config.lockScreenBlur
brightness: Config.lockScreenBrightness
saturation: Config.lockScreenSaturation
}
},
State {
name: "loginState"
PropertyChanges {
target: lockScreen
opacity: 0.0
}
PropertyChanges {
target: loginScreen
opacity: 1.0
}
PropertyChanges {
target: loginScreen.loginContainer
scale: 1.0
}
PropertyChanges {
target: backgroundEffect
blurMax: Config.loginScreenBlur
brightness: Config.loginScreenBrightness
saturation: Config.loginScreenSaturation
}
}
]
transitions: Transition {
enabled: Config.enableAnimations
PropertyAnimation {
duration: 150
properties: "opacity"
}
PropertyAnimation {
duration: 400
properties: "blurMax"
}
PropertyAnimation {
duration: 400
properties: "brightness"
}
PropertyAnimation {
duration: 400
properties: "saturation"
}
}
Item {
id: mainFrame
property variant geometry: screenModel.geometry(screenModel.primary)
x: geometry.x
y: geometry.y
width: geometry.width
height: geometry.height
// AnimatedImage { // `.gif`s are seg faulting with multi monitors... QT/SDDM issue?
Image {
// Background
id: backgroundImage
property string tsource: root.state === "lockState" ? Config.lockScreenBackground : Config.loginScreenBackground
property bool isVideo: {
if (!tsource || tsource.toString().length === 0)
return false;
var parts = tsource.toString().split(".");
if (parts.length === 0)
return false;
var ext = parts[parts.length - 1];
return ["avi", "mp4", "mov", "mkv", "m4v", "webm"].indexOf(ext) !== -1;
}
property bool displayColor: root.state === "lockState" && Config.lockScreenUseBackgroundColor || root.state === "loginState" && Config.loginScreenUseBackgroundColor
property string placeholder: Config.animatedBackgroundPlaceholder // Idea stolen from astronaut-theme. Not a fan of it, but works...
anchors.fill: parent
source: !isVideo ? "backgrounds/" + tsource : ""
cache: true
mipmap: true
fillMode: {
if (Config.backgroundFillMode === "stretch") {
return Image.Stretch;
} else if (Config.backgroundFillMode === "fit") {
return Image.PreserveAspectFit;
} else {
return Image.PreserveAspectCrop;
}
}
function updateVideo() {
if (isVideo && tsource.toString().length > 0) {
backgroundVideo.source = Qt.resolvedUrl("backgrounds/" + tsource);
if (placeholder.length > 0)
source = "backgrounds/" + placeholder;
}
}
onSourceChanged: {
updateVideo();
}
Component.onCompleted: {
updateVideo();
}
onStatusChanged: {
if (status === Image.Error) {
if (source !== "backgrounds/default.jpg" && source !== "") {
source = "backgrounds/default.jpg";
} else if (source === "backgrounds/default.jpg") {
// If even default fails, show color background
displayColor = true;
}
}
}
Rectangle {
id: backgroundColor
anchors.fill: parent
anchors.margins: 0
color: root.state === "lockState" && Config.lockScreenUseBackgroundColor ? Config.lockScreenBackgroundColor : root.state === "loginState" && Config.loginScreenUseBackgroundColor ? Config.loginScreenBackgroundColor : "black"
visible: parent.displayColor || (backgroundVideo.visible && parent.placeholder.length === 0)
}
// TODO: This is slow af. Removing the property bindings and doing everything at startup should help.
Video {
id: backgroundVideo
anchors.fill: parent
visible: parent.isVideo && !parent.displayColor
enabled: visible
autoPlay: false
loops: MediaPlayer.Infinite
muted: true
fillMode: {
if (Config.backgroundFillMode === "stretch") {
return VideoOutput.Stretch;
} else if (Config.backgroundFillMode === "fit") {
return VideoOutput.PreserveAspectFit;
} else {
return VideoOutput.PreserveAspectCrop;
}
}
onSourceChanged: {
if (source && source.toString().length > 0) {
backgroundVideo.play();
}
}
onErrorOccurred: function (error) {
if (error !== MediaPlayer.NoError && (!backgroundImage.placeholder || backgroundImage.placeholder.length === 0)) {
backgroundImage.displayColor = true;
}
}
}
// Overkill, but fine...
Component.onDestruction: {
if (backgroundVideo) {
backgroundVideo.stop();
backgroundVideo.source = "";
}
}
}
MultiEffect {
// Background effects
id: backgroundEffect
source: backgroundImage
anchors.fill: parent
blurEnabled: backgroundImage.visible && blurMax > 0
blur: blurMax > 0 ? 1.0 : 0.0
autoPaddingEnabled: false
}
Item {
id: screenContainer
anchors.fill: parent
anchors.top: parent.top
LockScreen {
id: lockScreen
z: root.state === "lockState" ? 2 : 1 // Fix tooltips from the login screen showing up on top of the lock screen.
anchors.fill: parent
focus: root.state === "lockState"
enabled: root.state === "lockState"
onLoginRequested: {
root.state = "loginState";
loginScreen.resetFocus();
}
}
LoginScreen {
id: loginScreen
z: root.state === "loginState" ? 2 : 1
anchors.fill: parent
enabled: root.state === "loginState"
opacity: 0.0
onClose: {
root.state = "lockState";
}
}
}
}
}