Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions quickshell/Common/SettingsData.qml
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ Singleton {
property bool batteryNotifyLow: false
property int batteryNotificationType: 0
property bool batteryAutoPowerSaver: false
property bool showBatteryPercent: true
property bool showBatteryPercentOnlyOnBattery: false
property bool showBatteryTime: false
property bool showBatteryTimeOnlyOnBattery: false
property bool lockBeforeSuspend: false
property bool loginctlLockIntegration: true
property bool fadeToLockEnabled: true
Expand Down
12 changes: 12 additions & 0 deletions quickshell/Common/settings/Lists.qml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Singleton {
showMicIcon: false,
showMicPercent: true,
showBatteryIcon: false,
showBatteryPercent: true,
showBatteryPercentOnlyOnBattery: false,
showBatteryTime: false,
showBatteryTimeOnlyOnBattery: false,
showPrinterIcon: false,
showScreenSharingIcon: true
};
Expand Down Expand Up @@ -83,6 +87,14 @@ Singleton {
item.showMicPercent = order[i].showMicPercent;
if (isObj && order[i].showBatteryIcon !== undefined)
item.showBatteryIcon = order[i].showBatteryIcon;
if (isObj && order[i].showBatteryPercent !== undefined)
item.showBatteryPercent = order[i].showBatteryPercent;
if (isObj && order[i].showBatteryPercentOnlyOnBattery !== undefined)
item.showBatteryPercentOnlyOnBattery = order[i].showBatteryPercentOnlyOnBattery;
if (isObj && order[i].showBatteryTime !== undefined)
item.showBatteryTime = order[i].showBatteryTime;
if (isObj && order[i].showBatteryTimeOnlyOnBattery !== undefined)
item.showBatteryTimeOnlyOnBattery = order[i].showBatteryTimeOnlyOnBattery;
if (isObj && order[i].showPrinterIcon !== undefined)
item.showPrinterIcon = order[i].showPrinterIcon;
if (isObj && order[i].showScreenSharingIcon !== undefined)
Expand Down
4 changes: 4 additions & 0 deletions quickshell/Common/settings/SettingsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ var SPEC = {
showClock: { def: true },
showNotificationButton: { def: true },
showBattery: { def: true },
showBatteryPercent: { def: true },
showBatteryPercentOnlyOnBattery: { def: false },
showBatteryTime: { def: false },
showBatteryTimeOnlyOnBattery: { def: false },
showControlCenterButton: { def: true },
showCapsLockIndicator: { def: true },

Expand Down
74 changes: 70 additions & 4 deletions quickshell/Modules/DankBar/Widgets/Battery.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,71 @@ BasePill {

property bool batteryPopupVisible: false
property var popoutTarget: null
property var widgetData: null
readonly property bool showPercentOnlyOnBattery: widgetData?.showBatteryPercentOnlyOnBattery !== undefined ? widgetData.showBatteryPercentOnlyOnBattery : SettingsData.showBatteryPercentOnlyOnBattery
readonly property bool showPercent: {
const base = widgetData?.showBatteryPercent !== undefined ? widgetData.showBatteryPercent : SettingsData.showBatteryPercent;
return base && !(showPercentOnlyOnBattery && BatteryService.isPluggedIn);
}
readonly property bool showTime: widgetData?.showBatteryTime !== undefined ? widgetData.showBatteryTime : SettingsData.showBatteryTime
readonly property bool showTimeOnlyOnBattery: widgetData?.showBatteryTimeOnlyOnBattery !== undefined ? widgetData.showBatteryTimeOnlyOnBattery : SettingsData.showBatteryTimeOnlyOnBattery

readonly property string batteryTimeText: {
if (showTimeOnlyOnBattery && BatteryService.isPluggedIn) {
return "";
}
const time = BatteryService.formatTimeRemaining();
return time !== "Unknown" ? time : "";
}

readonly property string verticalBatteryTimeText: {
if (!batteryTimeText) return "";

// Parse batteryTimeText, e.g., "2h 41m" or "41m"
let hours = 0;
let minutes = 0;

const hourMatch = batteryTimeText.match(/(\d+)h/);
const minMatch = batteryTimeText.match(/(\d+)m/);

if (hourMatch) {
hours = parseInt(hourMatch[1], 10);
}
if (minMatch) {
minutes = parseInt(minMatch[1], 10);
}

const hoursStr = hours < 10 ? "0" + hours : hours.toString();
const minutesStr = minutes < 10 ? "0" + minutes : minutes.toString();

return `${hoursStr}\n${minutesStr}`;
}

readonly property string horizontalDisplayText: {
if (showPercent && showTime && batteryTimeText) {
return `${BatteryService.batteryLevel}% (${batteryTimeText})`;
}
if (showPercent) {
return `${BatteryService.batteryLevel}%`;
}
if (showTime && batteryTimeText) {
return batteryTimeText;
}
return "";
}

readonly property string verticalDisplayText: {
if (showPercent && showTime && batteryTimeText) {
return `${BatteryService.batteryLevel}\n${verticalBatteryTimeText}`;
}
if (showPercent) {
return BatteryService.batteryLevel.toString();
}
if (showTime && batteryTimeText) {
return verticalBatteryTimeText;
}
return "";
}

property real touchpadAccumulator: 0

Expand Down Expand Up @@ -66,11 +131,12 @@ BasePill {
}

StyledText {
text: BatteryService.batteryLevel.toString()
text: battery.verticalDisplayText
font.pixelSize: Theme.barTextSize(battery.barThickness, battery.barConfig?.fontScale, battery.barConfig?.maximizeWidgetText)
color: Theme.widgetTextColor
horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: parent.horizontalCenter
visible: BatteryService.batteryAvailable
visible: BatteryService.batteryAvailable && battery.verticalDisplayText !== ""
}
}

Expand Down Expand Up @@ -102,11 +168,11 @@ BasePill {
}

StyledText {
text: `${BatteryService.batteryLevel}%`
text: battery.horizontalDisplayText
font.pixelSize: Theme.barTextSize(battery.barThickness, battery.barConfig?.fontScale, battery.barConfig?.maximizeWidgetText)
color: Theme.widgetTextColor
anchors.verticalCenter: parent.verticalCenter
visible: BatteryService.batteryAvailable
visible: BatteryService.batteryAvailable && battery.horizontalDisplayText !== ""
}
}
}
Expand Down
16 changes: 15 additions & 1 deletion quickshell/Modules/Settings/WidgetsTab.qml
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,12 @@ Item {
widgetObj.showDoNotDisturbIcon = SettingsData.controlCenterShowDoNotDisturbIcon;
widgetObj.controlCenterGroupOrder = ["network", "vpn", "bluetooth", "audio", "microphone", "brightness", "battery", "printer", "screenSharing", "idleInhibitor", "doNotDisturb"];
}
if (widgetId === "battery") {
widgetObj.showBatteryPercent = SettingsData.showBatteryPercent;
widgetObj.showBatteryPercentOnlyOnBattery = SettingsData.showBatteryPercentOnlyOnBattery;
widgetObj.showBatteryTime = SettingsData.showBatteryTime;
widgetObj.showBatteryTimeOnlyOnBattery = SettingsData.showBatteryTimeOnlyOnBattery;
}
if (widgetId === "runningApps") {
widgetObj.runningAppsCompactMode = SettingsData.runningAppsCompactMode;
widgetObj.runningAppsGroupByApp = SettingsData.runningAppsGroupByApp;
Expand Down Expand Up @@ -460,7 +466,7 @@ Item {
"id": widget.id,
"enabled": widget.enabled
};
var keys = ["size", "selectedGpuIndex", "pciId", "mountPath", "diskUsageMode", "minimumWidth", "showSwap", "showInGb", "mediaSize", "clockCompactMode", "focusedWindowSize", "focusedWindowCompactMode", "runningAppsCompactMode", "keyboardLayoutNameCompactMode", "keyboardLayoutNameShowIcon", "runningAppsGroupByApp", "runningAppsCurrentWorkspace", "runningAppsCurrentMonitor", "showNetworkIcon", "showBluetoothIcon", "showAudioIcon", "showAudioPercent", "showVpnIcon", "showBrightnessIcon", "showBrightnessPercent", "showMicIcon", "showMicPercent", "showBatteryIcon", "showPrinterIcon", "showScreenSharingIcon", "showIdleInhibitorIcon", "showDoNotDisturbIcon", "controlCenterGroupOrder", "barMaxVisibleApps", "barMaxVisibleRunningApps", "barShowOverflowBadge", "trayUseInlineExpansion", "trayPopupSingleLine", "trayAutoOverflow", "trayMaxVisibleItems", "hideWhenIdle"];
var keys = ["size", "selectedGpuIndex", "pciId", "mountPath", "diskUsageMode", "minimumWidth", "showSwap", "showInGb", "mediaSize", "clockCompactMode", "focusedWindowSize", "focusedWindowCompactMode", "runningAppsCompactMode", "keyboardLayoutNameCompactMode", "keyboardLayoutNameShowIcon", "runningAppsGroupByApp", "runningAppsCurrentWorkspace", "runningAppsCurrentMonitor", "showNetworkIcon", "showBluetoothIcon", "showAudioIcon", "showAudioPercent", "showVpnIcon", "showBrightnessIcon", "showBrightnessPercent", "showMicIcon", "showMicPercent", "showBatteryIcon", "showBatteryPercent", "showBatteryPercentOnlyOnBattery", "showBatteryTime", "showBatteryTimeOnlyOnBattery", "showPrinterIcon", "showScreenSharingIcon", "showIdleInhibitorIcon", "showDoNotDisturbIcon", "controlCenterGroupOrder", "barMaxVisibleApps", "barMaxVisibleRunningApps", "barShowOverflowBadge", "trayUseInlineExpansion", "trayPopupSingleLine", "trayAutoOverflow", "trayMaxVisibleItems", "hideWhenIdle"];
for (var i = 0; i < keys.length; i++) {
if (widget[keys[i]] !== undefined)
result[keys[i]] = widget[keys[i]];
Expand Down Expand Up @@ -759,6 +765,14 @@ Item {
item.showMicPercent = widget.showMicPercent;
if (widget.showBatteryIcon !== undefined)
item.showBatteryIcon = widget.showBatteryIcon;
if (widget.showBatteryPercent !== undefined)
item.showBatteryPercent = widget.showBatteryPercent;
if (widget.showBatteryPercentOnlyOnBattery !== undefined)
item.showBatteryPercentOnlyOnBattery = widget.showBatteryPercentOnlyOnBattery;
if (widget.showBatteryTime !== undefined)
item.showBatteryTime = widget.showBatteryTime;
if (widget.showBatteryTimeOnlyOnBattery !== undefined)
item.showBatteryTimeOnlyOnBattery = widget.showBatteryTimeOnlyOnBattery;
if (widget.showPrinterIcon !== undefined)
item.showPrinterIcon = widget.showPrinterIcon;
if (widget.showScreenSharingIcon !== undefined)
Expand Down
Loading
Loading