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