added -w flag for brightness for wayland use

This commit is contained in:
Paul Wilde 2022-07-14 22:28:15 +01:00
parent aab1c244d3
commit 9aba9e1faf

View file

@ -4,10 +4,18 @@ import std/[os,strutils,osproc,math]
const backlight = "intel_backlight" const backlight = "intel_backlight"
const default_bg = yellow const default_bg = yellow
const default_fg = black const default_fg = black
const backlight_cmd = "xbacklight" const BACKLIGHT_CMD = "xbacklight"
const backlight_up = backlight_cmd & " -inc %v" # %v is amount by const UP_X = BACKLIGHT_CMD & " -inc %v" # %v is amount by
const backlight_down = backlight_cmd & " -dec %v" # %v is amount by const DOWN_X = BACKLIGHT_CMD & " -dec %v" # %v is amount by
const backlight_set = backlight_cmd & " -set %v" # %v is amount by const SET_X = BACKLIGHT_CMD & " -set %v" # %v is amount by
const BACKLIGHT_CMD_WL = "brightnessctl"
const UP_WL = BACKLIGHT_CMD_WL & " set %v%+"
const DOWN_WL = BACKLIGHT_CMD_WL & " set %v%-"
const SET_WL = BACKLIGHT_CMD_WL & " set %v%"
var CMD = BACKLIGHT_CMD
var UP = UP_X
var DOWN = DOWN_X
var SET = SET_X
const default_value = "5" const default_value = "5"
proc getLimit(): int = proc getLimit(): int =
@ -38,10 +46,10 @@ proc getDesign(pcnt: float): string =
return text return text
proc brightnessUp() = proc brightnessUp() =
let cmd = replace(backlight_up,"%v",default_value) let cmd = replace(UP,"%v",default_value)
discard execCmd(cmd) discard execCmd(cmd)
proc brightnessDown() = proc brightnessDown() =
let cmd = replace(backlight_down,"%v",default_value) let cmd = replace(DOWN,"%v",default_value)
discard execCmd(cmd) discard execCmd(cmd)
proc getBrightness*(run_once: bool = false) = proc getBrightness*(run_once: bool = false) =
@ -70,7 +78,7 @@ proc getBrightness*(run_once: bool = false) =
else: else:
try: try:
let i = parseInt(option) let i = parseInt(option)
let cmd = replace(backlight_set,"%v",$i) let cmd = replace(SET,"%v",$i)
discard execCmd(cmd) discard execCmd(cmd)
getBrightness(true) getBrightness(true)
except: except:
@ -93,6 +101,11 @@ if isMainModule:
block start: block start:
for arg in args: for arg in args:
case arg: case arg:
of "-w":
CMD = BACKLIGHT_CMD_WL
UP = UP_WL
DOWN = DOWN_WL
SET = SET_WL
of "up": of "up":
brightnessUp() brightnessUp()
break start break start