summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/shell/quickshell/Lockscreen.qml
blob: 7cb1cc67d9fcf420dc430f94dc438d5159b9e259 (plain)
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
import Quickshell
import Quickshell.Wayland
import Quickshell.Io
import Quickshell.Services.Pam
import Quickshell.Widgets
import QtQuick.Effects
import QtQuick.Layouts
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Fusion
import qs.Services
// import QtQml.Models

Scope {
  id: lockscreen

  property string currentText: ""

  PamContext {
    id: pam

    property list<var> messages: []

    config: "quickshell"
    onCompleted: result => {
      if (result === PamResult.Success) {
	lock.locked = false;
      }
    }
    onPamMessage: {
      messages = Array.from(messages).concat([{ "text": pam.message, "error": pam.messageIsError }])
    }
    onActiveChanged: {
      messages = [];
    }
  }

  IpcHandler {
    target: "Lockscreen"

    function setLocked(locked: bool): void { lock.locked = locked; }
    function getLocked(): bool { return lock.locked; }
  }

  WlSessionLock {
    id: lock

    onLockedChanged: {
      if (!locked && pam.active)
        pam.abort();
    }

    WlSessionLockSurface {
      id: lockSurface

      color: "#000000"

      Item {
        id: background

        anchors.fill: parent

	property Img current: one
	property string source: selector.selected

	WallpaperSelector {
	  id: selector
	  seed: lockSurface.screen?.name || ""
	}

	onSourceChanged: {
	  if (!source)
	    current = null;
	  else if (current === one)
	    two.update()
	  else
	    one.update()
	}

	Img { id: one }
	Img { id: two }

	component Img: Item {
	  id: img

	  property string source

	  function update() {
	    source = background.source || ""
	  }

    	  anchors.fill: parent

	  Image {
	    id: imageSource

	    source: img.source
	    sourceSize: Qt.size(parent.width, parent.height)
    	    fillMode: Image.PreserveAspectCrop
	    smooth: true
	    visible: false
	    asynchronous: true
	    cache: false

	    onStatusChanged: {
	      if (status === Image.Ready) {
		background.current = img
	      }
	    }
	  }

	  MultiEffect {
	    id: imageEffect

	    source: imageSource
	    anchors.fill: parent
	    blurEnabled: true
	    blur: 1
	    blurMax: 64
	    blurMultiplier: 2

    	    opacity: 0

	    states: State {
	      name: "visible"
	      when: background.current === img

	      PropertyChanges {
		imageEffect.opacity: 1
	      }
	      StateChangeScript {
		name: "unloadOther"
		script: {
		  if (img === one)
		    two.source = ""
		  if (img === two)
		    one.source = ""
		}
	      }
	    }

	    transitions: Transition {
	      SequentialAnimation {
		NumberAnimation {
		  target: imageEffect
		  properties: "opacity"
		  duration: 5000
		  easing.type: Easing.OutCubic
		}
		ScriptAction {
		  scriptName: "unloadOther"
		}
	      }
	    }
	  }
	}
      }

      Item {
        anchors {
	  top: lockSurface.top
	  left: lockSurface.left
	  right: lockSurface.right
	}

	implicitWidth: lockSurface.width
	implicitHeight: 21

	Rectangle {
	  anchors.fill: parent
  	  color: Qt.rgba(0, 0, 0, 0.75)
	}

	Clock {
	  anchors.centerIn: parent
	  calendarPopup: false
	}
      }

      WrapperRectangle {
        id: unlockUi

	Keys.onPressed: event => {
	  if (!pam.active) {
	    event.accepted = true;
	    pam.start();
	  }
	}
	focus: !passwordBox.visible

        visible: pam.active

	color: Qt.rgba(0, 0, 0, 0.75)
	margin: 8

	anchors.centerIn: parent

	ColumnLayout {
	  spacing: 4

	  BusyIndicator {
	    visible: running
	    running: !Array.from(pam.messages).length && !pam.responseRequired
	  }

	  Repeater {
	    model: pam.messages

	    Text {
	      required property var modelData

	      font.pointSize: 10
	      font.family: "Fira Sans"
	      color: modelData.error ? "#f28a21" : "#ffffff"

	      text: modelData.text

	      Layout.fillWidth: true
	      horizontalAlignment: Text.AlignHCenter
	    }
	  }

	  TextField {
	    id: passwordBox

	    visible: pam.responseRequired
	    echoMode: pam.responseVisible ? TextInput.Normal : TextInput.Password
            inputMethodHints: Qt.ImhSensitiveData

	    onTextChanged: lockscreen.currentText = passwordBox.text
	    onAccepted: {
	      passwordBox.readOnly = true;
	      pam.respond(lockscreen.currentText);
	    }

	    Connections {
	      target: lockscreen
	      function onCurrentTextChanged() {
	        passwordBox.text = lockscreen.currentText
	      }
	    }
	    Connections {
	      target: pam
	      function onResponseRequiredChanged() {
	        if (pam.responseRequired)
	          passwordBox.readOnly = false;
		  passwordBox.focus = true;
		  passwordBox.selectAll();
	      }
	    }

	    Layout.topMargin: 4
	    Layout.fillWidth: true
	  }
	}
      }
    }
  }
}