added brightnurrs - needs testing on laptop
This commit is contained in:
parent
ff21191f2d
commit
528cbb6200
5 changed files with 99 additions and 82 deletions
|
@ -13,6 +13,7 @@ import util/pw_generaturr
|
||||||
import util/temperaturr
|
import util/temperaturr
|
||||||
import util/screenshurrt
|
import util/screenshurrt
|
||||||
import util/calculaturr
|
import util/calculaturr
|
||||||
|
import util/brightnurrs
|
||||||
|
|
||||||
proc dispatch*(cfg: Config) =
|
proc dispatch*(cfg: Config) =
|
||||||
case cfg.run
|
case cfg.run
|
||||||
|
@ -42,5 +43,7 @@ proc dispatch*(cfg: Config) =
|
||||||
screenshurrt.go()
|
screenshurrt.go()
|
||||||
of Calculaturr:
|
of Calculaturr:
|
||||||
calculaturr.go()
|
calculaturr.go()
|
||||||
|
of Brightnurrs:
|
||||||
|
brightnurrs.go()
|
||||||
else:
|
else:
|
||||||
echo "No valid run command given"
|
echo "No valid run command given"
|
||||||
|
|
6
src/model/brightness.nim
Normal file
6
src/model/brightness.nim
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
type
|
||||||
|
BrightnessArg* = enum
|
||||||
|
None,
|
||||||
|
BrightUp,
|
||||||
|
BrightDown
|
|
@ -14,4 +14,5 @@ type
|
||||||
PasswurrdGeneraturr,
|
PasswurrdGeneraturr,
|
||||||
Temperaturr,
|
Temperaturr,
|
||||||
Screenshurrt,
|
Screenshurrt,
|
||||||
Calculaturr
|
Calculaturr,
|
||||||
|
Brightnurrs
|
||||||
|
|
|
@ -5,6 +5,7 @@ import argparse
|
||||||
import common
|
import common
|
||||||
import model/pwgen
|
import model/pwgen
|
||||||
import model/volume
|
import model/volume
|
||||||
|
import model/brightness
|
||||||
import model/screenshot
|
import model/screenshot
|
||||||
|
|
||||||
proc parseArgs*() =
|
proc parseArgs*() =
|
||||||
|
@ -42,6 +43,8 @@ proc parseArgs*() =
|
||||||
myConfig.run = Screenshurrt
|
myConfig.run = Screenshurrt
|
||||||
of "calculaturr", "calculator", "calc":
|
of "calculaturr", "calculator", "calc":
|
||||||
myConfig.run = Calculaturr
|
myConfig.run = Calculaturr
|
||||||
|
of "brightnurrs", "brightness", "bright":
|
||||||
|
myConfig.run = Brightnurrs
|
||||||
else:
|
else:
|
||||||
echo p.help
|
echo p.help
|
||||||
quit(1)
|
quit(1)
|
||||||
|
@ -78,6 +81,29 @@ proc parseVolArgs*(): VolArg =
|
||||||
quit(1)
|
quit(1)
|
||||||
return arg
|
return arg
|
||||||
|
|
||||||
|
proc parseBrightnessArgs*(): BrightnessArg =
|
||||||
|
var arg: BrightnessArg
|
||||||
|
let params = commandLineParams()
|
||||||
|
var p = newParser:
|
||||||
|
help("Args for volurrme")
|
||||||
|
arg("brightnurrs",help="can only ever be 'brightnurrs' as you won't have gotten this far otherwise")
|
||||||
|
arg("adjust",help="up, down, or mute",default=some(""))
|
||||||
|
try:
|
||||||
|
var opts = p.parse(params)
|
||||||
|
case opts.adjust
|
||||||
|
of "up":
|
||||||
|
arg = BrightUp
|
||||||
|
of "down":
|
||||||
|
arg = BrightDown
|
||||||
|
except ShortCircuit as err:
|
||||||
|
if err.flag == "argparse_help":
|
||||||
|
echo err.help
|
||||||
|
quit(1)
|
||||||
|
except UsageError:
|
||||||
|
stderr.writeLine getCurrentExceptionMsg()
|
||||||
|
quit(1)
|
||||||
|
return arg
|
||||||
|
|
||||||
proc parsePWGenArgs*(): PWGen =
|
proc parsePWGenArgs*(): PWGen =
|
||||||
var gen = newPWGen()
|
var gen = newPWGen()
|
||||||
let params = commandLineParams()
|
let params = commandLineParams()
|
||||||
|
|
|
@ -1,32 +1,36 @@
|
||||||
import ../../globurrl
|
import os
|
||||||
import std/[os,strutils,osproc,math]
|
import strutils
|
||||||
|
import osproc
|
||||||
|
import math
|
||||||
|
|
||||||
const backlight = "intel_backlight"
|
import ../common
|
||||||
const default_bg = yellow
|
import ../parser
|
||||||
const default_fg = black
|
import ../model/brightness
|
||||||
|
import ../output
|
||||||
|
|
||||||
|
#const backlight = "intel_backlight"
|
||||||
const BACKLIGHT_CMD = "xbacklight"
|
const BACKLIGHT_CMD = "xbacklight"
|
||||||
const UP_X = BACKLIGHT_CMD & " -inc %v" # %v is amount by
|
const UP = BACKLIGHT_CMD & " -inc %v" # %v is amount by
|
||||||
const DOWN_X = BACKLIGHT_CMD & " -dec %v" # %v is amount by
|
const DOWN = BACKLIGHT_CMD & " -dec %v" # %v is amount by
|
||||||
const SET_X = BACKLIGHT_CMD & " -set %v" # %v is amount by
|
const SET = 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 getBacklight(): string =
|
||||||
|
for dir in walkDir("/sys/class/backlight"):
|
||||||
|
echo dir.path
|
||||||
|
var bl = dir.path.replace("/sys/class/backlight/","")
|
||||||
|
echo bl
|
||||||
|
return bl
|
||||||
|
|
||||||
|
proc getLimit(backlight: string): int =
|
||||||
try:
|
try:
|
||||||
|
if backlight != "":
|
||||||
let back_l = readFile("/sys/class/backlight/" & backlight & "/max_brightness")
|
let back_l = readFile("/sys/class/backlight/" & backlight & "/max_brightness")
|
||||||
return parseInt(strip(back_l))
|
return parseInt(strip(back_l))
|
||||||
except:
|
except:
|
||||||
echo "Error getting backlight max : ", getCurrentExceptionMsg()
|
echo "Error getting backlight max : ", getCurrentExceptionMsg()
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
let limit = getLimit()
|
|
||||||
|
|
||||||
proc getDesign(pcnt: float): string =
|
proc getDesign(pcnt: float): string =
|
||||||
var icon = "🌑"
|
var icon = "🌑"
|
||||||
|
@ -52,65 +56,42 @@ proc brightnessDown() =
|
||||||
let cmd = replace(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*(backlight: string) =
|
||||||
var last_pcnt: float = 0
|
let limit = getLimit(backlight)
|
||||||
while true:
|
|
||||||
let current = parseInt(strip(readFile("/sys/class/backlight/" & backlight & "/actual_brightness")))
|
let current = parseInt(strip(readFile("/sys/class/backlight/" & backlight & "/actual_brightness")))
|
||||||
let pcnt = (current/limit)*100
|
let pcnt = (current/limit)*100
|
||||||
if pcnt != last_pcnt:
|
|
||||||
let text = getDesign(pcnt)
|
let text = getDesign(pcnt)
|
||||||
var data = newInfo("Brightnurrs")
|
var data = newInfo("Brightnurrs")
|
||||||
data.full_text = text
|
data.full_text = text
|
||||||
data.selected_bg = default_fg
|
|
||||||
data.selected_fg = default_bg
|
|
||||||
# i3bar stuff
|
|
||||||
data.border = default_fg
|
|
||||||
let args = @["up", "down"]
|
let args = @["up", "down"]
|
||||||
let option = outputData(data,args)
|
let option = outputData(data,args)
|
||||||
if option in args:
|
if option in args:
|
||||||
case option:
|
case option:
|
||||||
of "up":
|
of "up":
|
||||||
brightnessUp()
|
brightnessUp()
|
||||||
getBrightness(true)
|
backlight.getBrightness()
|
||||||
of "down":
|
of "down":
|
||||||
brightnessDown()
|
brightnessDown()
|
||||||
getBrightness(true)
|
backlight.getBrightness()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
let i = parseInt(option)
|
let i = parseInt(option)
|
||||||
let cmd = replace(SET,"%v",$i)
|
let cmd = replace(SET,"%v",$i)
|
||||||
discard execCmd(cmd)
|
discard execCmd(cmd)
|
||||||
getBrightness(true)
|
backlight.getBrightness()
|
||||||
except:
|
except:
|
||||||
echo getCurrentExceptionMsg()
|
echo getCurrentExceptionMsg()
|
||||||
|
|
||||||
if run_once:
|
proc go*() =
|
||||||
break
|
let backlight = getBacklight()
|
||||||
if stoploop:
|
if backlight != "":
|
||||||
break
|
let barg = parseBrightnessArgs()
|
||||||
last_pcnt = pcnt
|
case barg:
|
||||||
sleep(1000)
|
of BrightUp:
|
||||||
|
|
||||||
proc main() =
|
|
||||||
if limit == -1:
|
|
||||||
switchTwmMode()
|
|
||||||
return
|
|
||||||
getBrightness()
|
|
||||||
|
|
||||||
if isMainModule:
|
|
||||||
block start:
|
|
||||||
if wayland:
|
|
||||||
CMD = BACKLIGHT_CMD_WL
|
|
||||||
UP = UP_WL
|
|
||||||
DOWN = DOWN_WL
|
|
||||||
SET = SET_WL
|
|
||||||
for arg in args:
|
|
||||||
case arg:
|
|
||||||
of "up":
|
|
||||||
brightnessUp()
|
brightnessUp()
|
||||||
break start
|
of BrightDown:
|
||||||
of "down":
|
|
||||||
brightnessDown()
|
brightnessDown()
|
||||||
break start
|
else:
|
||||||
|
backlight.getBrightness()
|
||||||
main()
|
else:
|
||||||
|
echo "No Backlight Found"
|
||||||
|
|
Loading…
Reference in a new issue