all repos — quickshell @ 2892935cc9d183c5ba9a972d81163701e11cd0cd

A desert-witch desktop shell

bar/modules/Battery.qml (view raw)

 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
//Battery.qml
import QtQuick
import Quickshell
import QtQuick.Layouts
import Quickshell.Services.UPower
import "../.."
import "../classes" as Class


Repeater {
  model: UPower.devices.values.filter(d=>d.model)
  RowLayout {
    spacing: 2
    property var lvl: Math.round(modelData.percentage*100)
    property var charge_state: UPowerDeviceState.toString(modelData.state)
    property var device_type: UPowerDeviceType.toString(modelData.type)
    Class.Sep{}
      Text {
        id: battery_device_icon
        font.family: font_icon.name
        text: modelData.isLaptopBattery
          ? Icons.devices.battery
          : modelData.model == "Jupiter of the Monkey"
            ? Icons.devices.headphones
            : {
              "Headphones": Icons.devices.headphones,
              "Headset": Icons.devices.headphones,
              "Gaming Input": Icons.devices.controller,
              "Keyboard": Icons.devices.keyboard,
              "Mouse": Icons.devices.mouse,
              "Unknown": Icons.devices.unknown,
              "Speakers": Icons.devices.speaker,
              "Printer": Icons.devices.printer,
              "Camera": Icons.devices.camera,
              "Phone": Icons.devices.phone,
              }[device_type] ?? modelData.model
      font.pixelSize:
        (device_type == "Gaming Input")
        ? 14*Size.scale
        : Resources.fontsize.bottombar_icon
      color:
        modelData.model == "Jupiter of the Monkey"
        ? "#897bc7"
        : (charge_state == "Charging") 
          ? Resources.palette.saffron 
          : lvl < 20
            ? Resources.palette.scarlet
            : (charge_state == "FullyCharged")
              ? Resources.palette.cyan
              : Resources.palette.orange
    }
    Class.TopbarText {
      id: battery_level_indicator
      text: lvl+"%"
      font.family: font_proggy.name
      color:
        (charge_state == "Charging")
        ? Resources.palette.saffron
        : (lvl < 20)
          ? Resources.palette.scarlet
          : Resources.palette.fg
    }
  }
}