1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-29 16:02:51 -05:00

lock/greeter: fix font alignment

fixes #1018
This commit is contained in:
bbedward
2025-12-14 11:13:48 -05:00
parent 5e2a418485
commit fb75f4c68b
2 changed files with 236 additions and 258 deletions

View File

@@ -1,13 +1,11 @@
import QtCore import QtCore
import QtQuick import QtQuick
import QtQuick.Controls
import QtQuick.Effects import QtQuick.Effects
import QtQuick.Layouts import QtQuick.Layouts
import Quickshell import Quickshell
import Quickshell.Hyprland import Quickshell.Hyprland
import Quickshell.Io import Quickshell.Io
import Quickshell.Services.Greetd import Quickshell.Services.Greetd
import Quickshell.Services.Pam
import qs.Common import qs.Common
import qs.Services import qs.Services
import qs.Widgets import qs.Widgets
@@ -22,74 +20,67 @@ Item {
property string hyprlandCurrentLayout: "" property string hyprlandCurrentLayout: ""
property string hyprlandKeyboard: "" property string hyprlandKeyboard: ""
property int hyprlandLayoutCount: 0 property int hyprlandLayoutCount: 0
property bool isPrimaryScreen: { property bool isPrimaryScreen: !Quickshell.screens?.length || screenName === Quickshell.screens[0]?.name
if (!Qt.application.screens || Qt.application.screens.length === 0)
return true
if (!screenName || screenName === "")
return true
return screenName === Qt.application.screens[0].name
}
signal launchRequested signal launchRequested
function pickRandomFact() { function pickRandomFact() {
randomFact = Facts.getRandomFact() randomFact = Facts.getRandomFact();
} }
property bool weatherInitialized: false property bool weatherInitialized: false
function initWeatherService() { function initWeatherService() {
if (weatherInitialized) if (weatherInitialized)
return return;
if (!GreetdSettings.settingsLoaded) if (!GreetdSettings.settingsLoaded)
return return;
if (!GreetdSettings.weatherEnabled) if (!GreetdSettings.weatherEnabled)
return return;
weatherInitialized = true;
weatherInitialized = true WeatherService.addRef();
WeatherService.addRef() WeatherService.forceRefresh();
WeatherService.forceRefresh()
} }
Connections { Connections {
target: GreetdSettings target: GreetdSettings
function onSettingsLoadedChanged() { function onSettingsLoadedChanged() {
if (GreetdSettings.settingsLoaded) if (GreetdSettings.settingsLoaded)
initWeatherService() initWeatherService();
} }
} }
Component.onCompleted: { Component.onCompleted: {
pickRandomFact() pickRandomFact();
initWeatherService() initWeatherService();
if (isPrimaryScreen) { if (isPrimaryScreen) {
sessionListProc.running = true sessionListProc.running = true;
applyLastSuccessfulUser() applyLastSuccessfulUser();
} }
if (CompositorService.isHyprland) if (CompositorService.isHyprland)
updateHyprlandLayout() updateHyprlandLayout();
} }
function applyLastSuccessfulUser() { function applyLastSuccessfulUser() {
const lastUser = GreetdMemory.lastSuccessfulUser const lastUser = GreetdMemory.lastSuccessfulUser;
if (lastUser && !GreeterState.showPasswordInput && !GreeterState.username) { if (lastUser && !GreeterState.showPasswordInput && !GreeterState.username) {
GreeterState.username = lastUser GreeterState.username = lastUser;
GreeterState.usernameInput = lastUser GreeterState.usernameInput = lastUser;
GreeterState.showPasswordInput = true GreeterState.showPasswordInput = true;
PortalService.getGreeterUserProfileImage(lastUser) PortalService.getGreeterUserProfileImage(lastUser);
} }
} }
Component.onDestruction: { Component.onDestruction: {
if (weatherInitialized) if (weatherInitialized)
WeatherService.removeRef() WeatherService.removeRef();
} }
function updateHyprlandLayout() { function updateHyprlandLayout() {
if (CompositorService.isHyprland) { if (CompositorService.isHyprland) {
hyprlandLayoutProcess.running = true hyprlandLayoutProcess.running = true;
} }
} }
@@ -100,27 +91,27 @@ Item {
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
try { try {
const data = JSON.parse(text) const data = JSON.parse(text);
const mainKeyboard = data.keyboards.find(kb => kb.main === true) const mainKeyboard = data.keyboards.find(kb => kb.main === true);
hyprlandKeyboard = mainKeyboard.name hyprlandKeyboard = mainKeyboard.name;
if (mainKeyboard && mainKeyboard.active_keymap) { if (mainKeyboard && mainKeyboard.active_keymap) {
const parts = mainKeyboard.active_keymap.split(" ") const parts = mainKeyboard.active_keymap.split(" ");
if (parts.length > 0) { if (parts.length > 0) {
hyprlandCurrentLayout = parts[0].substring(0, 2).toUpperCase() hyprlandCurrentLayout = parts[0].substring(0, 2).toUpperCase();
} else { } else {
hyprlandCurrentLayout = mainKeyboard.active_keymap.substring(0, 2).toUpperCase() hyprlandCurrentLayout = mainKeyboard.active_keymap.substring(0, 2).toUpperCase();
} }
} else { } else {
hyprlandCurrentLayout = "" hyprlandCurrentLayout = "";
} }
if (mainKeyboard && mainKeyboard.layout_names) { if (mainKeyboard && mainKeyboard.layout_names) {
hyprlandLayoutCount = mainKeyboard.layout_names.length hyprlandLayoutCount = mainKeyboard.layout_names.length;
} else { } else {
hyprlandLayoutCount = 0 hyprlandLayoutCount = 0;
} }
} catch (e) { } catch (e) {
hyprlandCurrentLayout = "" hyprlandCurrentLayout = "";
hyprlandLayoutCount = 0 hyprlandLayoutCount = 0;
} }
} }
} }
@@ -132,7 +123,7 @@ Item {
function onRawEvent(event) { function onRawEvent(event) {
if (event.name === "activelayout") if (event.name === "activelayout")
updateHyprlandLayout() updateHyprlandLayout();
} }
} }
@@ -140,7 +131,7 @@ Item {
target: GreetdMemory target: GreetdMemory
enabled: isPrimaryScreen enabled: isPrimaryScreen
function onLastSuccessfulUserChanged() { function onLastSuccessfulUserChanged() {
applyLastSuccessfulUser() applyLastSuccessfulUser();
} }
} }
@@ -148,7 +139,7 @@ Item {
target: GreeterState target: GreeterState
function onUsernameChanged() { function onUsernameChanged() {
if (GreeterState.username) { if (GreeterState.username) {
PortalService.getGreeterUserProfileImage(GreeterState.username) PortalService.getGreeterUserProfileImage(GreeterState.username);
} }
} }
} }
@@ -157,10 +148,10 @@ Item {
anchors.fill: parent anchors.fill: parent
screenName: root.screenName screenName: root.screenName
visible: { visible: {
var _ = SessionData.perMonitorWallpaper var _ = SessionData.perMonitorWallpaper;
var __ = SessionData.monitorWallpapers var __ = SessionData.monitorWallpapers;
var currentWallpaper = SessionData.getMonitorWallpaper(screenName) var currentWallpaper = SessionData.getMonitorWallpaper(screenName);
return !currentWallpaper || currentWallpaper === "" || (currentWallpaper && currentWallpaper.startsWith("#")) return !currentWallpaper || currentWallpaper === "" || (currentWallpaper && currentWallpaper.startsWith("#"));
} }
} }
@@ -169,10 +160,10 @@ Item {
anchors.fill: parent anchors.fill: parent
source: { source: {
var _ = SessionData.perMonitorWallpaper var _ = SessionData.perMonitorWallpaper;
var __ = SessionData.monitorWallpapers var __ = SessionData.monitorWallpapers;
var currentWallpaper = SessionData.getMonitorWallpaper(screenName) var currentWallpaper = SessionData.getMonitorWallpaper(screenName);
return (currentWallpaper && !currentWallpaper.startsWith("#")) ? currentWallpaper : "" return (currentWallpaper && !currentWallpaper.startsWith("#")) ? currentWallpaper : "";
} }
fillMode: Theme.getFillMode(GreetdSettings.wallpaperFillMode) fillMode: Theme.getFillMode(GreetdSettings.wallpaperFillMode)
smooth: true smooth: true
@@ -213,10 +204,12 @@ Item {
color: "transparent" color: "transparent"
Item { Item {
anchors.centerIn: parent id: clockContainer
anchors.verticalCenterOffset: -100 anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.verticalCenter
anchors.bottomMargin: 60
width: parent.width width: parent.width
height: 140 height: clockText.implicitHeight
Row { Row {
id: clockText id: clockText
@@ -225,10 +218,8 @@ Item {
spacing: 0 spacing: 0
property string fullTimeStr: { property string fullTimeStr: {
const format = GreetdSettings.use24HourClock const format = GreetdSettings.use24HourClock ? (GreetdSettings.showSeconds ? "HH:mm:ss" : "HH:mm") : (GreetdSettings.showSeconds ? "h:mm:ss AP" : "h:mm AP");
? (GreetdSettings.showSeconds ? "HH:mm:ss" : "HH:mm") return systemClock.date.toLocaleTimeString(Qt.locale(), format);
: (GreetdSettings.showSeconds ? "h:mm:ss AP" : "h:mm AP")
return systemClock.date.toLocaleTimeString(Qt.locale(), format)
} }
property var timeParts: fullTimeStr.split(':') property var timeParts: fullTimeStr.split(':')
property string hours: timeParts[0] || "" property string hours: timeParts[0] || ""
@@ -236,8 +227,8 @@ Item {
property string secondsWithAmPm: timeParts.length > 2 ? timeParts[2] : "" property string secondsWithAmPm: timeParts.length > 2 ? timeParts[2] : ""
property string seconds: secondsWithAmPm.replace(/\s*(AM|PM|am|pm)$/i, '') property string seconds: secondsWithAmPm.replace(/\s*(AM|PM|am|pm)$/i, '')
property string ampm: { property string ampm: {
const match = fullTimeStr.match(/\s*(AM|PM|am|pm)$/i) const match = fullTimeStr.match(/\s*(AM|PM|am|pm)$/i);
return match ? match[0].trim() : "" return match ? match[0].trim() : "";
} }
property bool hasSeconds: timeParts.length > 2 property bool hasSeconds: timeParts.length > 2
@@ -332,13 +323,15 @@ Item {
} }
StyledText { StyledText {
anchors.centerIn: parent id: dateText
anchors.verticalCenterOffset: -10 anchors.horizontalCenter: parent.horizontalCenter
anchors.top: clockContainer.bottom
anchors.topMargin: 4
text: { text: {
if (GreetdSettings.lockDateFormat && GreetdSettings.lockDateFormat.length > 0) { if (GreetdSettings.lockDateFormat && GreetdSettings.lockDateFormat.length > 0) {
return systemClock.date.toLocaleDateString(Qt.locale(), GreetdSettings.lockDateFormat) return systemClock.date.toLocaleDateString(Qt.locale(), GreetdSettings.lockDateFormat);
} }
return systemClock.date.toLocaleDateString(Qt.locale(), Locale.LongFormat) return systemClock.date.toLocaleDateString(Qt.locale(), Locale.LongFormat);
} }
font.pixelSize: Theme.fontSizeXLarge font.pixelSize: Theme.fontSizeXLarge
color: "white" color: "white"
@@ -346,8 +339,9 @@ Item {
} }
Item { Item {
anchors.centerIn: parent anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenterOffset: 80 anchors.top: dateText.bottom
anchors.topMargin: Theme.spacingL
width: 380 width: 380
height: 140 height: 140
@@ -364,14 +358,14 @@ Item {
Layout.preferredHeight: 60 Layout.preferredHeight: 60
imageSource: { imageSource: {
if (PortalService.profileImage === "") { if (PortalService.profileImage === "") {
return "" return "";
} }
if (PortalService.profileImage.startsWith("/")) { if (PortalService.profileImage.startsWith("/")) {
return "file://" + PortalService.profileImage return "file://" + PortalService.profileImage;
} }
return PortalService.profileImage return PortalService.profileImage;
} }
fallbackIcon: "person" fallbackIcon: "person"
} }
@@ -405,57 +399,58 @@ Item {
anchors.fill: parent anchors.fill: parent
anchors.leftMargin: lockIcon.width + Theme.spacingM * 2 anchors.leftMargin: lockIcon.width + Theme.spacingM * 2
anchors.rightMargin: { anchors.rightMargin: {
let margin = Theme.spacingM let margin = Theme.spacingM;
if (GreeterState.showPasswordInput && revealButton.visible) { if (GreeterState.showPasswordInput && revealButton.visible) {
margin += revealButton.width margin += revealButton.width;
} }
if (virtualKeyboardButton.visible) { if (virtualKeyboardButton.visible) {
margin += virtualKeyboardButton.width margin += virtualKeyboardButton.width;
} }
if (enterButton.visible) { if (enterButton.visible) {
margin += enterButton.width + 2 margin += enterButton.width + 2;
} }
return margin return margin;
} }
opacity: 0 opacity: 0
focus: true focus: true
echoMode: GreeterState.showPasswordInput ? (parent.showPassword ? TextInput.Normal : TextInput.Password) : TextInput.Normal echoMode: GreeterState.showPasswordInput ? (parent.showPassword ? TextInput.Normal : TextInput.Password) : TextInput.Normal
onTextChanged: { onTextChanged: {
if (syncingFromState) return if (syncingFromState)
return;
if (GreeterState.showPasswordInput) { if (GreeterState.showPasswordInput) {
GreeterState.passwordBuffer = text GreeterState.passwordBuffer = text;
} else { } else {
GreeterState.usernameInput = text GreeterState.usernameInput = text;
} }
} }
onAccepted: { onAccepted: {
if (GreeterState.showPasswordInput) { if (GreeterState.showPasswordInput) {
if (Greetd.state === GreetdState.Inactive && GreeterState.username) { if (Greetd.state === GreetdState.Inactive && GreeterState.username) {
Greetd.createSession(GreeterState.username) Greetd.createSession(GreeterState.username);
} }
} else { } else {
if (text.trim()) { if (text.trim()) {
GreeterState.username = text.trim() GreeterState.username = text.trim();
GreeterState.showPasswordInput = true GreeterState.showPasswordInput = true;
PortalService.getGreeterUserProfileImage(GreeterState.username) PortalService.getGreeterUserProfileImage(GreeterState.username);
GreeterState.passwordBuffer = "" GreeterState.passwordBuffer = "";
syncingFromState = true syncingFromState = true;
text = "" text = "";
syncingFromState = false syncingFromState = false;
} }
} }
} }
Component.onCompleted: { Component.onCompleted: {
syncingFromState = true syncingFromState = true;
text = GreeterState.showPasswordInput ? GreeterState.passwordBuffer : GreeterState.usernameInput text = GreeterState.showPasswordInput ? GreeterState.passwordBuffer : GreeterState.usernameInput;
syncingFromState = false syncingFromState = false;
if (isPrimaryScreen && !powerMenu.isVisible) if (isPrimaryScreen && !powerMenu.isVisible)
forceActiveFocus() forceActiveFocus();
} }
onVisibleChanged: { onVisibleChanged: {
if (visible && isPrimaryScreen && !powerMenu.isVisible) if (visible && isPrimaryScreen && !powerMenu.isVisible)
forceActiveFocus() forceActiveFocus();
} }
} }
@@ -475,15 +470,15 @@ Item {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
text: { text: {
if (GreeterState.unlocking) { if (GreeterState.unlocking) {
return "Logging in..." return "Logging in...";
} }
if (Greetd.state !== GreetdState.Inactive) { if (Greetd.state !== GreetdState.Inactive) {
return "Authenticating..." return "Authenticating...";
} }
if (GreeterState.showPasswordInput) { if (GreeterState.showPasswordInput) {
return "Password..." return "Password...";
} }
return "Username..." return "Username...";
} }
color: GreeterState.unlocking ? Theme.primary : (Greetd.state !== GreetdState.Inactive ? Theme.primary : Theme.outline) color: GreeterState.unlocking ? Theme.primary : (Greetd.state !== GreetdState.Inactive ? Theme.primary : Theme.outline)
font.pixelSize: Theme.fontSizeMedium font.pixelSize: Theme.fontSizeMedium
@@ -513,11 +508,11 @@ Item {
text: { text: {
if (GreeterState.showPasswordInput) { if (GreeterState.showPasswordInput) {
if (parent.showPassword) { if (parent.showPassword) {
return GreeterState.passwordBuffer return GreeterState.passwordBuffer;
} }
return "•".repeat(GreeterState.passwordBuffer.length) return "•".repeat(GreeterState.passwordBuffer.length);
} }
return GreeterState.usernameInput return GreeterState.usernameInput;
} }
color: Theme.surfaceText color: Theme.surfaceText
font.pixelSize: (GreeterState.showPasswordInput && !parent.showPassword) ? Theme.fontSizeLarge : Theme.fontSizeMedium font.pixelSize: (GreeterState.showPasswordInput && !parent.showPassword) ? Theme.fontSizeLarge : Theme.fontSizeMedium
@@ -558,9 +553,9 @@ Item {
enabled: visible enabled: visible
onClicked: { onClicked: {
if (keyboard_controller.isKeyboardActive) { if (keyboard_controller.isKeyboardActive) {
keyboard_controller.hide() keyboard_controller.hide();
} else { } else {
keyboard_controller.show() keyboard_controller.show();
} }
} }
} }
@@ -578,15 +573,15 @@ Item {
onClicked: { onClicked: {
if (GreeterState.showPasswordInput) { if (GreeterState.showPasswordInput) {
if (GreeterState.username) { if (GreeterState.username) {
Greetd.createSession(GreeterState.username) Greetd.createSession(GreeterState.username);
} }
} else { } else {
if (inputField.text.trim()) { if (inputField.text.trim()) {
GreeterState.username = inputField.text.trim() GreeterState.username = inputField.text.trim();
GreeterState.showPasswordInput = true GreeterState.showPasswordInput = true;
PortalService.getGreeterUserProfileImage(GreeterState.username) PortalService.getGreeterUserProfileImage(GreeterState.username);
GreeterState.passwordBuffer = "" GreeterState.passwordBuffer = "";
inputField.text = "" inputField.text = "";
} }
} }
} }
@@ -615,10 +610,10 @@ Item {
Layout.bottomMargin: -Theme.spacingS Layout.bottomMargin: -Theme.spacingS
text: { text: {
if (GreeterState.pamState === "error") if (GreeterState.pamState === "error")
return "Authentication error - try again" return "Authentication error - try again";
if (GreeterState.pamState === "fail") if (GreeterState.pamState === "fail")
return "Incorrect password" return "Incorrect password";
return "" return "";
} }
color: Theme.error color: Theme.error
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
@@ -675,9 +670,9 @@ Item {
cornerRadius: parent.radius cornerRadius: parent.radius
enabled: !GreeterState.unlocking && Greetd.state === GreetdState.Inactive && GreeterState.showPasswordInput enabled: !GreeterState.unlocking && Greetd.state === GreetdState.Inactive && GreeterState.showPasswordInput
onClicked: { onClicked: {
GreeterState.reset() GreeterState.reset();
inputField.text = "" inputField.text = "";
PortalService.profileImage = "" PortalService.profileImage = "";
} }
} }
} }
@@ -696,11 +691,11 @@ Item {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
visible: { visible: {
if (CompositorService.isNiri) { if (CompositorService.isNiri) {
return NiriService.keyboardLayoutNames.length > 1 return NiriService.keyboardLayoutNames.length > 1;
} else if (CompositorService.isHyprland) { } else if (CompositorService.isHyprland) {
return hyprlandLayoutCount > 1 return hyprlandLayoutCount > 1;
} }
return false return false;
} }
Row { Row {
@@ -726,17 +721,18 @@ Item {
StyledText { StyledText {
text: { text: {
if (CompositorService.isNiri) { if (CompositorService.isNiri) {
const layout = NiriService.getCurrentKeyboardLayoutName() const layout = NiriService.getCurrentKeyboardLayoutName();
if (!layout) return "" if (!layout)
const parts = layout.split(" ") return "";
const parts = layout.split(" ");
if (parts.length > 0) { if (parts.length > 0) {
return parts[0].substring(0, 2).toUpperCase() return parts[0].substring(0, 2).toUpperCase();
} }
return layout.substring(0, 2).toUpperCase() return layout.substring(0, 2).toUpperCase();
} else if (CompositorService.isHyprland) { } else if (CompositorService.isHyprland) {
return hyprlandCurrentLayout return hyprlandCurrentLayout;
} }
return "" return "";
} }
font.pixelSize: Theme.fontSizeMedium font.pixelSize: Theme.fontSizeMedium
font.weight: Font.Light font.weight: Font.Light
@@ -753,15 +749,10 @@ Item {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onClicked: {
if (CompositorService.isNiri) { if (CompositorService.isNiri) {
NiriService.cycleKeyboardLayout() NiriService.cycleKeyboardLayout();
} else if (CompositorService.isHyprland) { } else if (CompositorService.isHyprland) {
Quickshell.execDetached([ Quickshell.execDetached(["hyprctl", "switchxkblayout", hyprlandKeyboard, "next"]);
"hyprctl", updateHyprlandLayout();
"switchxkblayout",
hyprlandKeyboard,
"next"
])
updateHyprlandLayout()
} }
} }
} }
@@ -773,9 +764,8 @@ Item {
color: Qt.rgba(255, 255, 255, 0.2) color: Qt.rgba(255, 255, 255, 0.2)
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
visible: { visible: {
const keyboardVisible = (CompositorService.isNiri && NiriService.keyboardLayoutNames.length > 1) || const keyboardVisible = (CompositorService.isNiri && NiriService.keyboardLayoutNames.length > 1) || (CompositorService.isHyprland && hyprlandLayoutCount > 1);
(CompositorService.isHyprland && hyprlandLayoutCount > 1) return keyboardVisible && GreetdSettings.weatherEnabled && WeatherService.weather.available;
return keyboardVisible && GreetdSettings.weatherEnabled && WeatherService.weather.available
} }
} }
@@ -832,15 +822,15 @@ Item {
DankIcon { DankIcon {
name: { name: {
if (!AudioService.sink?.audio) { if (!AudioService.sink?.audio) {
return "volume_up" return "volume_up";
} }
if (AudioService.sink.audio.muted || AudioService.sink.audio.volume === 0) { if (AudioService.sink.audio.muted || AudioService.sink.audio.volume === 0) {
return "volume_off" return "volume_off";
} }
if (AudioService.sink.audio.volume * 100 < 33) { if (AudioService.sink.audio.volume * 100 < 33) {
return "volume_down" return "volume_down";
} }
return "volume_up" return "volume_up";
} }
size: Theme.iconSize - 2 size: Theme.iconSize - 2
color: (AudioService.sink && AudioService.sink.audio && (AudioService.sink.audio.muted || AudioService.sink.audio.volume === 0)) ? Qt.rgba(255, 255, 255, 0.5) : "white" color: (AudioService.sink && AudioService.sink.audio && (AudioService.sink.audio.muted || AudioService.sink.audio.volume === 0)) ? Qt.rgba(255, 255, 255, 0.5) : "white"
@@ -866,95 +856,95 @@ Item {
name: { name: {
if (BatteryService.isCharging) { if (BatteryService.isCharging) {
if (BatteryService.batteryLevel >= 90) { if (BatteryService.batteryLevel >= 90) {
return "battery_charging_full" return "battery_charging_full";
} }
if (BatteryService.batteryLevel >= 80) { if (BatteryService.batteryLevel >= 80) {
return "battery_charging_90" return "battery_charging_90";
} }
if (BatteryService.batteryLevel >= 60) { if (BatteryService.batteryLevel >= 60) {
return "battery_charging_80" return "battery_charging_80";
} }
if (BatteryService.batteryLevel >= 50) { if (BatteryService.batteryLevel >= 50) {
return "battery_charging_60" return "battery_charging_60";
} }
if (BatteryService.batteryLevel >= 30) { if (BatteryService.batteryLevel >= 30) {
return "battery_charging_50" return "battery_charging_50";
} }
if (BatteryService.batteryLevel >= 20) { if (BatteryService.batteryLevel >= 20) {
return "battery_charging_30" return "battery_charging_30";
} }
return "battery_charging_20" return "battery_charging_20";
} }
if (BatteryService.isPluggedIn) { if (BatteryService.isPluggedIn) {
if (BatteryService.batteryLevel >= 90) { if (BatteryService.batteryLevel >= 90) {
return "battery_charging_full" return "battery_charging_full";
} }
if (BatteryService.batteryLevel >= 80) { if (BatteryService.batteryLevel >= 80) {
return "battery_charging_90" return "battery_charging_90";
} }
if (BatteryService.batteryLevel >= 60) { if (BatteryService.batteryLevel >= 60) {
return "battery_charging_80" return "battery_charging_80";
} }
if (BatteryService.batteryLevel >= 50) { if (BatteryService.batteryLevel >= 50) {
return "battery_charging_60" return "battery_charging_60";
} }
if (BatteryService.batteryLevel >= 30) { if (BatteryService.batteryLevel >= 30) {
return "battery_charging_50" return "battery_charging_50";
} }
if (BatteryService.batteryLevel >= 20) { if (BatteryService.batteryLevel >= 20) {
return "battery_charging_30" return "battery_charging_30";
} }
return "battery_charging_20" return "battery_charging_20";
} }
if (BatteryService.batteryLevel >= 95) { if (BatteryService.batteryLevel >= 95) {
return "battery_full" return "battery_full";
} }
if (BatteryService.batteryLevel >= 85) { if (BatteryService.batteryLevel >= 85) {
return "battery_6_bar" return "battery_6_bar";
} }
if (BatteryService.batteryLevel >= 70) { if (BatteryService.batteryLevel >= 70) {
return "battery_5_bar" return "battery_5_bar";
} }
if (BatteryService.batteryLevel >= 55) { if (BatteryService.batteryLevel >= 55) {
return "battery_4_bar" return "battery_4_bar";
} }
if (BatteryService.batteryLevel >= 40) { if (BatteryService.batteryLevel >= 40) {
return "battery_3_bar" return "battery_3_bar";
} }
if (BatteryService.batteryLevel >= 25) { if (BatteryService.batteryLevel >= 25) {
return "battery_2_bar" return "battery_2_bar";
} }
return "battery_1_bar" return "battery_1_bar";
} }
size: Theme.iconSize size: Theme.iconSize
color: { color: {
if (BatteryService.isLowBattery && !BatteryService.isCharging) { if (BatteryService.isLowBattery && !BatteryService.isCharging) {
return Theme.error return Theme.error;
} }
if (BatteryService.isCharging || BatteryService.isPluggedIn) { if (BatteryService.isCharging || BatteryService.isPluggedIn) {
return Theme.primary return Theme.primary;
} }
return "white" return "white";
} }
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
@@ -1007,14 +997,14 @@ Item {
} }
property real longestSessionWidth: { property real longestSessionWidth: {
let maxWidth = 0 let maxWidth = 0;
for (var i = 0; i < sessionMetricsRepeater.count; i++) { for (var i = 0; i < sessionMetricsRepeater.count; i++) {
const item = sessionMetricsRepeater.itemAt(i) const item = sessionMetricsRepeater.itemAt(i);
if (item && item.width > maxWidth) { if (item && item.width > maxWidth) {
maxWidth = item.width maxWidth = item.width;
} }
} }
return maxWidth return maxWidth;
} }
Repeater { Repeater {
@@ -1038,52 +1028,42 @@ Item {
openUpwards: true openUpwards: true
alignPopupRight: true alignPopupRight: true
onValueChanged: value => { onValueChanged: value => {
const idx = GreeterState.sessionList.indexOf(value) const idx = GreeterState.sessionList.indexOf(value);
if (idx >= 0) { if (idx >= 0) {
GreeterState.currentSessionIndex = idx GreeterState.currentSessionIndex = idx;
GreeterState.selectedSession = GreeterState.sessionExecs[idx] GreeterState.selectedSession = GreeterState.sessionExecs[idx];
GreetdMemory.setLastSessionId(GreeterState.sessionPaths[idx]) GreetdMemory.setLastSessionId(GreeterState.sessionPaths[idx]);
} }
} }
} }
} }
} }
FileView {
id: pamConfigWatcher
path: "/etc/pam.d/dankshell"
printErrors: false
}
property int sessionCount: 0
property string currentSessionName: GreeterState.sessionList[GreeterState.currentSessionIndex] || "" property string currentSessionName: GreeterState.sessionList[GreeterState.currentSessionIndex] || ""
property int pendingParsers: 0 property int pendingParsers: 0
function finalizeSessionSelection() { function finalizeSessionSelection() {
if (GreeterState.sessionList.length === 0) { if (GreeterState.sessionList.length === 0) {
return return;
} }
root.sessionCount = GreeterState.sessionList.length const savedSession = GreetdMemory.lastSessionId;
let foundSaved = false;
const savedSession = GreetdMemory.lastSessionId
let foundSaved = false
if (savedSession) { if (savedSession) {
for (var i = 0; i < GreeterState.sessionPaths.length; i++) { for (var i = 0; i < GreeterState.sessionPaths.length; i++) {
if (GreeterState.sessionPaths[i] === savedSession) { if (GreeterState.sessionPaths[i] === savedSession) {
GreeterState.currentSessionIndex = i GreeterState.currentSessionIndex = i;
foundSaved = true foundSaved = true;
break break;
} }
} }
} }
if (!foundSaved) { if (!foundSaved) {
GreeterState.currentSessionIndex = 0 GreeterState.currentSessionIndex = 0;
} }
GreeterState.selectedSession = GreeterState.sessionExecs[GreeterState.currentSessionIndex] || GreeterState.sessionExecs[0] || "" GreeterState.selectedSession = GreeterState.sessionExecs[GreeterState.currentSessionIndex] || GreeterState.sessionExecs[0] || "";
} }
Process { Process {
@@ -1091,48 +1071,43 @@ Item {
property string homeDir: Quickshell.env("HOME") || "" property string homeDir: Quickshell.env("HOME") || ""
property string xdgDirs: xdgDataDirs || "" property string xdgDirs: xdgDataDirs || ""
command: { command: {
var paths = [ var paths = ["/usr/share/wayland-sessions", "/usr/share/xsessions", "/usr/local/share/wayland-sessions", "/usr/local/share/xsessions"];
"/usr/share/wayland-sessions",
"/usr/share/xsessions",
"/usr/local/share/wayland-sessions",
"/usr/local/share/xsessions"
]
if (homeDir) { if (homeDir) {
paths.push(homeDir + "/.local/share/wayland-sessions") paths.push(homeDir + "/.local/share/wayland-sessions");
paths.push(homeDir + "/.local/share/xsessions") paths.push(homeDir + "/.local/share/xsessions");
} }
// Add XDG_DATA_DIRS paths // Add XDG_DATA_DIRS paths
if (xdgDirs) { if (xdgDirs) {
xdgDirs.split(":").forEach(function(dir) { xdgDirs.split(":").forEach(function (dir) {
if (dir) { if (dir) {
paths.push(dir + "/wayland-sessions") paths.push(dir + "/wayland-sessions");
paths.push(dir + "/xsessions") paths.push(dir + "/xsessions");
} }
}) });
} }
// 1. Explicit system/user paths // 1. Explicit system/user paths
var explicitFind = "find " + paths.join(" ") + " -maxdepth 1 -name '*.desktop' -type f -follow 2>/dev/null" var explicitFind = "find " + paths.join(" ") + " -maxdepth 1 -name '*.desktop' -type f -follow 2>/dev/null";
// 2. Scan all /home user directories for local session files // 2. Scan all /home user directories for local session files
var homeScan = "find /home -maxdepth 5 \\( -path '*/wayland-sessions/*.desktop' -o -path '*/xsessions/*.desktop' \\) -type f -follow 2>/dev/null" var homeScan = "find /home -maxdepth 5 \\( -path '*/wayland-sessions/*.desktop' -o -path '*/xsessions/*.desktop' \\) -type f -follow 2>/dev/null";
var findCmd = "(" + explicitFind + "; " + homeScan + ") | sort -u" var findCmd = "(" + explicitFind + "; " + homeScan + ") | sort -u";
return ["sh", "-c", findCmd] return ["sh", "-c", findCmd];
} }
running: false running: false
stdout: SplitParser { stdout: SplitParser {
onRead: data => { onRead: data => {
if (data.trim()) { if (data.trim()) {
root.pendingParsers++ root.pendingParsers++;
parseDesktopFile(data.trim()) parseDesktopFile(data.trim());
} }
} }
} }
} }
function parseDesktopFile(path) { function parseDesktopFile(path) {
const parser = desktopParser.createObject(null, { const parser = desktopParser.createObject(null, {
"desktopPath": path "desktopPath": path
}) });
} }
Component { Component {
@@ -1144,42 +1119,41 @@ Item {
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
const lines = text.split("\n") const lines = text.split("\n");
let name = "" let name = "";
let exec = "" let exec = "";
for (const line of lines) { for (const line of lines) {
if (line.startsWith("Name=")) { if (line.startsWith("Name=")) {
name = line.substring(5).trim() name = line.substring(5).trim();
} else if (line.startsWith("Exec=")) { } else if (line.startsWith("Exec=")) {
exec = line.substring(5).trim() exec = line.substring(5).trim();
} }
} }
if (name && exec) { if (name && exec) {
if (!GreeterState.sessionList.includes(name)) { if (!GreeterState.sessionList.includes(name)) {
let newList = GreeterState.sessionList.slice() let newList = GreeterState.sessionList.slice();
let newExecs = GreeterState.sessionExecs.slice() let newExecs = GreeterState.sessionExecs.slice();
let newPaths = GreeterState.sessionPaths.slice() let newPaths = GreeterState.sessionPaths.slice();
newList.push(name) newList.push(name);
newExecs.push(exec) newExecs.push(exec);
newPaths.push(desktopPath) newPaths.push(desktopPath);
GreeterState.sessionList = newList GreeterState.sessionList = newList;
GreeterState.sessionExecs = newExecs GreeterState.sessionExecs = newExecs;
GreeterState.sessionPaths = newPaths GreeterState.sessionPaths = newPaths;
root.sessionCount = GreeterState.sessionList.length
} }
} }
} }
} }
onExited: code => { onExited: code => {
root.pendingParsers-- root.pendingParsers--;
if (root.pendingParsers === 0) { if (root.pendingParsers === 0) {
Qt.callLater(root.finalizeSessionSelection) Qt.callLater(root.finalizeSessionSelection);
} }
destroy() destroy();
} }
} }
} }
@@ -1189,34 +1163,34 @@ Item {
function onAuthMessage(message, error, responseRequired, echoResponse) { function onAuthMessage(message, error, responseRequired, echoResponse) {
if (responseRequired) { if (responseRequired) {
Greetd.respond(GreeterState.passwordBuffer) Greetd.respond(GreeterState.passwordBuffer);
GreeterState.passwordBuffer = "" GreeterState.passwordBuffer = "";
inputField.text = "" inputField.text = "";
} else if (!error) { } else if (!error) {
Greetd.respond("") Greetd.respond("");
} }
} }
function onReadyToLaunch() { function onReadyToLaunch() {
GreeterState.unlocking = true GreeterState.unlocking = true;
const sessionCmd = GreeterState.selectedSession || GreeterState.sessionExecs[GreeterState.currentSessionIndex] const sessionCmd = GreeterState.selectedSession || GreeterState.sessionExecs[GreeterState.currentSessionIndex];
if (sessionCmd) { if (sessionCmd) {
GreetdMemory.setLastSessionId(GreeterState.sessionPaths[GreeterState.currentSessionIndex]) GreetdMemory.setLastSessionId(GreeterState.sessionPaths[GreeterState.currentSessionIndex]);
GreetdMemory.setLastSuccessfulUser(GreeterState.username) GreetdMemory.setLastSuccessfulUser(GreeterState.username);
Greetd.launch(sessionCmd.split(" "), ["XDG_SESSION_TYPE=wayland"]) Greetd.launch(sessionCmd.split(" "), ["XDG_SESSION_TYPE=wayland"]);
} }
} }
function onAuthFailure(message) { function onAuthFailure(message) {
GreeterState.pamState = "fail" GreeterState.pamState = "fail";
GreeterState.passwordBuffer = "" GreeterState.passwordBuffer = "";
inputField.text = "" inputField.text = "";
placeholderDelay.restart() placeholderDelay.restart();
} }
function onError(error) { function onError(error) {
GreeterState.pamState = "error" GreeterState.pamState = "error";
placeholderDelay.restart() placeholderDelay.restart();
} }
} }
@@ -1231,7 +1205,7 @@ Item {
showLogout: false showLogout: false
onClosed: { onClosed: {
if (isPrimaryScreen && inputField && inputField.forceActiveFocus) { if (isPrimaryScreen && inputField && inputField.forceActiveFocus) {
Qt.callLater(() => inputField.forceActiveFocus()) Qt.callLater(() => inputField.forceActiveFocus());
} }
} }
} }

View File

@@ -212,10 +212,12 @@ Item {
color: "transparent" color: "transparent"
Item { Item {
anchors.centerIn: parent id: clockContainer
anchors.verticalCenterOffset: -100 anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.verticalCenter
anchors.bottomMargin: 60
width: parent.width width: parent.width
height: 140 height: clockText.implicitHeight
visible: SettingsData.lockScreenShowTime visible: SettingsData.lockScreenShowTime
Row { Row {
@@ -330,8 +332,10 @@ Item {
} }
StyledText { StyledText {
anchors.centerIn: parent id: dateText
anchors.verticalCenterOffset: -25 anchors.horizontalCenter: parent.horizontalCenter
anchors.top: clockContainer.bottom
anchors.topMargin: 4
visible: SettingsData.lockScreenShowDate visible: SettingsData.lockScreenShowDate
text: { text: {
if (SettingsData.lockDateFormat && SettingsData.lockDateFormat.length > 0) { if (SettingsData.lockDateFormat && SettingsData.lockDateFormat.length > 0) {
@@ -346,8 +350,9 @@ Item {
ColumnLayout { ColumnLayout {
id: passwordLayout id: passwordLayout
anchors.centerIn: parent anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenterOffset: 50 anchors.top: dateText.visible ? dateText.bottom : clockContainer.bottom
anchors.topMargin: Theme.spacingL
spacing: Theme.spacingM spacing: Theme.spacingM
width: 380 width: 380
@@ -384,7 +389,6 @@ Item {
border.width: passwordField.activeFocus ? 2 : 1 border.width: passwordField.activeFocus ? 2 : 1
visible: SettingsData.lockScreenShowPasswordField || root.passwordBuffer.length > 0 visible: SettingsData.lockScreenShowPasswordField || root.passwordBuffer.length > 0
Item { Item {
id: lockIconContainer id: lockIconContainer
anchors.left: parent.left anchors.left: parent.left