DankMaterialShell icon indicating copy to clipboard operation
DankMaterialShell copied to clipboard

`brightness`: Use pinned output as default target instead of backlight device

Open yuxqiu opened this issue 4 months ago • 1 comments

Feature Description

Continue discussion in #872. When running dms ipc call brightness, it would be nicer if the default device were the currently pinned monitor (when a monitor is pinned and connected) instead of always falling back to the default backlight device.

Use Case

This change would allow users to use a single set of keyboard shortcuts to control the brightness of whichever monitor they are currently using as their main display. This is especially convenient in setups with one external monitor and one internal laptop screen.

Example binding:

XF86MonBrightnessUp allow-when-locked=true {
    spawn "dms" "ipc" "call" "brightness" "increment" "5" "";
}

With this improvement, the same shortcut would automatically adjust the brightness of the active/pinned monitor without requiring separate bindings or manual device selection.

Compositor

Is this feature specific to one compositor?

  • [ ] All compositors
  • [x] niri
  • [x] Hyprland
  • [x] dwl (MangoWC)
  • [ ] sway

yuxqiu avatar Dec 02 '25 04:12 yuxqiu

A workaround script on niri:

#!/bin/bash
set -euo pipefail

focused_connector=$(niri msg --json focused-output | jq -r '.name')

# Built-in laptop panel, let dms use the normal backlight interface
if [[ "$focused_connector" == eDP-* || "$focused_connector" == LVDS-* ]]; then
  exit 0
fi

# Find sysfs entry for the focused connector
shopt -s nullglob
candidates=(/sys/class/drm/card*-"$focused_connector")
shopt -u nullglob

(( ''${#candidates[@]} == 0 )) && exit 0
dir="''${candidates[0]}"

# Modern layout (kernel ≥ 5.17): ./ddc/i2c-dev/i2c-*
for i2c_path in "$dir"/ddc/i2c-dev/i2c-*; do
  [[ -d "$i2c_path" ]] || continue
  bus=$(cut -d: -f2 < "$i2c_path/dev")
  if ddcutil --bus="$bus" getvcp 10 >/dev/null 2>&1; then
    echo "ddc:i2c-$bus"
    exit 0
  fi
done

# If nothing responded, let dms fall back to its own heuristics
exit 0

Then, replace existing brightness key bindings with the following (adjust the script path as needed):

XF86MonBrightnessUp allow-when-locked=true {
    spawn-sh "dms ipc call brightness increment 5 \"$(/path/to/your/script.sh)\"";
}
XF86MonBrightnessDown allow-when-locked=true {
    spawn-sh "dms ipc call brightness decrement 5 \"$(/path/to/your/script.sh)\"";
}

yuxqiu avatar Dec 04 '25 17:12 yuxqiu