diff --git a/hypr/hyprland.lua b/hypr/hyprland.lua index e98ce99..fa036f8 100644 --- a/hypr/hyprland.lua +++ b/hypr/hyprland.lua @@ -120,6 +120,7 @@ hl.config({ numlock_by_default = true, follow_mouse = 1, sensitivity = 0, + accel_profile = "flat", touchpad = { clickfinger_behavior = true, scroll_factor = 0.4, diff --git a/quickshell/default/Bar.qml b/quickshell/default/Bar.qml index 781ca87..b280282 100644 --- a/quickshell/default/Bar.qml +++ b/quickshell/default/Bar.qml @@ -278,6 +278,12 @@ Variants { property string gpuMemTotal: "NA" readonly property bool gpuAvailable: gpuUtil !== "NA" + // ---- mouse battery (Razer, via openrazer - no-op if not installed/connected) ---- + property bool mouseBatteryAvailable: false + property int mouseBatteryPct: 0 + property bool mouseBatteryCharging: false + readonly property bool mouseBatteryLow: mouseBatteryAvailable && !mouseBatteryCharging && mouseBatteryPct <= 20 + // ---- network ---- property string connType: "" property string connName: "" @@ -351,6 +357,30 @@ Variants { Timer { interval: 100; running: true; repeat: false; onTriggered: statsProc.running = true } Timer { interval: 1000; running: true; repeat: true; onTriggered: statsProc.running = true } + Process { + id: mouseBatteryProc + command: ["python3", root.scriptsDir + "/mouse_battery.py"] + stdout: StdioCollector { id: mouseBatteryCollector } + onExited: { + try { + var d = JSON.parse(mouseBatteryCollector.text) + bar.mouseBatteryAvailable = !!d.available + if (d.available) { + bar.mouseBatteryPct = d.pct + bar.mouseBatteryCharging = !!d.charging + } + } catch (e) { + bar.mouseBatteryAvailable = false + } + } + } + + // 60s, not 1s like statsProc: querying openrazer's daemon over D-Bus is much + // heavier than reading /proc, and a mouse's battery doesn't change fast enough + // to need more than that anyway. + Timer { interval: 200; running: true; repeat: false; onTriggered: mouseBatteryProc.running = true } + Timer { interval: 60000; running: true; repeat: true; onTriggered: mouseBatteryProc.running = true } + Component { id: bellComp Rectangle { @@ -1226,6 +1256,40 @@ Variants { } } + Rectangle { + id: mouseBatteryPill + visible: !bar.taskbarMode && bar.mouseBatteryAvailable + Layout.preferredWidth: mouseBatteryRow.implicitWidth + 14 + Layout.preferredHeight: 26 + radius: 10 + color: bar.hovered === "mouse" ? root.palette.accent : root.argb(root.palette.pill_color, root.pillOpacity) + + Row { + id: mouseBatteryRow + anchors.centerIn: parent + spacing: 4 + Text { + text: "󰍽" + font.family: "JetBrainsMono Nerd Font" + font.pixelSize: 13 + color: bar.hovered === "mouse" ? "#0f111a" : (bar.mouseBatteryLow ? root.palette.color1 : root.palette.color2) + } + Text { + text: bar.mouseBatteryPct + "%" + (bar.mouseBatteryCharging ? "" : "") + font.family: "JetBrainsMono Nerd Font" + font.pixelSize: 13 + color: bar.hovered === "mouse" ? "#0f111a" : root.palette.foreground + } + } + + MouseArea { + anchors.fill: parent + hoverEnabled: true + onEntered: bar.hovered = "mouse" + onExited: bar.hovered = "" + } + } + Loader { visible: bar.taskbarMode Layout.preferredWidth: visible ? 32 : 0 diff --git a/quickshell/default/scripts/mouse_battery.py b/quickshell/default/scripts/mouse_battery.py new file mode 100644 index 0000000..605b672 --- /dev/null +++ b/quickshell/default/scripts/mouse_battery.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +"""Prints the Razer mouse's battery as JSON: {"available": bool, "pct": int, +"charging": bool, "name": str}. "available" is false (nothing else meaningful in the +object) if openrazer isn't installed, its daemon isn't reachable, or no device is +connected - deliberately never raises, since a traceback on stdout would break the +bar's JSON.parse of this output. +""" +import json + +try: + from openrazer.client import DeviceManager + devices = DeviceManager().devices + if not devices: + raise RuntimeError("no device") + d = devices[0] + print(json.dumps({"available": True, "pct": d.battery_level, + "charging": d.is_charging, "name": d.name})) +except Exception: + print(json.dumps({"available": False}))