mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
allow setting a timeout to manual sleep inhibitor
This commit is contained in:
@@ -5,21 +5,64 @@ import qs.Commons
|
||||
import qs.Services.Power
|
||||
import qs.Services.UI
|
||||
import qs.Widgets
|
||||
import qs.Modules.Bar.Extras
|
||||
|
||||
NIconButton {
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property ShellScreen screen
|
||||
|
||||
baseSize: Style.capsuleHeight
|
||||
applyUiScale: false
|
||||
density: Settings.data.bar.density
|
||||
icon: IdleInhibitorService.isInhibited ? "keep-awake-on" : "keep-awake-off"
|
||||
tooltipText: IdleInhibitorService.isInhibited ? I18n.tr("tooltips.disable-keep-awake") : I18n.tr("tooltips.enable-keep-awake")
|
||||
tooltipDirection: BarService.getTooltipDirection()
|
||||
colorBg: IdleInhibitorService.isInhibited ? Color.mPrimary : (Settings.data.bar.showCapsule ? Color.mSurfaceVariant : Color.transparent)
|
||||
colorFg: IdleInhibitorService.isInhibited ? Color.mOnPrimary : Color.mOnSurface
|
||||
colorBorder: Color.transparent
|
||||
colorBorderHover: Color.transparent
|
||||
onClicked: IdleInhibitorService.manualToggle()
|
||||
// Widget properties passed from Bar.qml for per-instance settings
|
||||
property string widgetId: ""
|
||||
property string section: ""
|
||||
property int sectionWidgetIndex: -1
|
||||
property int sectionWidgetsCount: 0
|
||||
|
||||
property var widgetMetadata: BarWidgetRegistry.widgetMetadata[widgetId]
|
||||
property var widgetSettings: {
|
||||
if (section && sectionWidgetIndex >= 0) {
|
||||
var widgets = Settings.data.bar.widgets[section]
|
||||
if (widgets && sectionWidgetIndex < widgets.length) {
|
||||
return widgets[sectionWidgetIndex]
|
||||
}
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
readonly property bool isBarVertical: Settings.data.bar.position === "left" || Settings.data.bar.position === "right"
|
||||
|
||||
implicitWidth: pill.width
|
||||
implicitHeight: pill.height
|
||||
|
||||
BarPill {
|
||||
id: pill
|
||||
|
||||
text: IdleInhibitorService.timeout == null ? "" :
|
||||
Time.formatVagueHumanReadableDuration(IdleInhibitorService.timeout)
|
||||
|
||||
density: Settings.data.bar.density
|
||||
oppositeDirection: BarService.getPillDirection(root)
|
||||
icon: IdleInhibitorService.isInhibited ? "keep-awake-on" : "keep-awake-off"
|
||||
tooltipText: IdleInhibitorService.isInhibited ?
|
||||
I18n.tr("tooltips.disable-keep-awake") :
|
||||
I18n.tr("tooltips.enable-keep-awake")
|
||||
onClicked: IdleInhibitorService.manualToggle()
|
||||
forceOpen: IdleInhibitorService.timeout !== null
|
||||
onWheel: function (delta) {
|
||||
var sign = delta > 0 ? 1 : -1
|
||||
// the offset makes scrolling down feel symmetrical to scrolling up
|
||||
var timeout = IdleInhibitorService.timeout - (delta < 0 ? 60 : 0)
|
||||
if (timeout == null || timeout < 600) {
|
||||
delta = 60 // <= 10m, increment at 1m interval
|
||||
} else if (timeout >= 600 && timeout < 1800) {
|
||||
delta = 300 // >= 10m, increment at 5m interval
|
||||
} else if (timeout >= 1800 && timeout < 3600) {
|
||||
delta = 600 // >= 30m, increment at 10m interval
|
||||
} else if (timeout >= 3600) {
|
||||
delta = 1800 // > 1h, increment at 30m interval
|
||||
}
|
||||
|
||||
IdleInhibitorService.changeTimeout(delta * sign)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user