Add mouse battery pill, disable pointer acceleration

Setting up OpenRazer (for the battery read) reset the mouse's DPI to
its 1800 default, exposing that input.accel_profile was never set -
Hyprland/libinput default to an adaptive (accelerated) curve, which
became noticeable once the DPI changed. accel_profile = "flat" for a
linear 1:1 response, which is what was expected all along.

New mouse battery pill in the bar (between network and clock), via
scripts/mouse_battery.py querying openrazer - hidden entirely if no
Razer device is found, so it's a no-op for anyone without one.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dujsk9jYfxUVLtb5B8eC94
This commit is contained in:
nico
2026-10-03 16:13:47 +02:00
parent 0c4a1307a9
commit 3b4e649dc8
3 changed files with 84 additions and 0 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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}))