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:
|
||||||
let back_l = readFile("/sys/class/backlight/" & backlight & "/max_brightness")
|
if backlight != "":
|
||||||
return parseInt(strip(back_l))
|
let back_l = readFile("/sys/class/backlight/" & backlight & "/max_brightness")
|
||||||
|
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
|
let text = getDesign(pcnt)
|
||||||
if pcnt != last_pcnt:
|
var data = newInfo("Brightnurrs")
|
||||||
let text = getDesign(pcnt)
|
data.full_text = text
|
||||||
var data = newInfo("Brightnurrs")
|
let args = @["up", "down"]
|
||||||
data.full_text = text
|
let option = outputData(data,args)
|
||||||
data.selected_bg = default_fg
|
if option in args:
|
||||||
data.selected_fg = default_bg
|
case option:
|
||||||
# i3bar stuff
|
of "up":
|
||||||
data.border = default_fg
|
brightnessUp()
|
||||||
let args = @["up", "down"]
|
backlight.getBrightness()
|
||||||
let option = outputData(data,args)
|
of "down":
|
||||||
if option in args:
|
brightnessDown()
|
||||||
case option:
|
backlight.getBrightness()
|
||||||
of "up":
|
else:
|
||||||
brightnessUp()
|
try:
|
||||||
getBrightness(true)
|
let i = parseInt(option)
|
||||||
of "down":
|
let cmd = replace(SET,"%v",$i)
|
||||||
brightnessDown()
|
discard execCmd(cmd)
|
||||||
getBrightness(true)
|
backlight.getBrightness()
|
||||||
|
except:
|
||||||
|
echo getCurrentExceptionMsg()
|
||||||
|
|
||||||
|
proc go*() =
|
||||||
|
let backlight = getBacklight()
|
||||||
|
if backlight != "":
|
||||||
|
let barg = parseBrightnessArgs()
|
||||||
|
case barg:
|
||||||
|
of BrightUp:
|
||||||
|
brightnessUp()
|
||||||
|
of BrightDown:
|
||||||
|
brightnessDown()
|
||||||
else:
|
else:
|
||||||
try:
|
backlight.getBrightness()
|
||||||
let i = parseInt(option)
|
else:
|
||||||
let cmd = replace(SET,"%v",$i)
|
echo "No Backlight Found"
|
||||||
discard execCmd(cmd)
|
|
||||||
getBrightness(true)
|
|
||||||
except:
|
|
||||||
echo getCurrentExceptionMsg()
|
|
||||||
|
|
||||||
if run_once:
|
|
||||||
break
|
|
||||||
if stoploop:
|
|
||||||
break
|
|
||||||
last_pcnt = pcnt
|
|
||||||
sleep(1000)
|
|
||||||
|
|
||||||
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()
|
|
||||||
break start
|
|
||||||
of "down":
|
|
||||||
brightnessDown()
|
|
||||||
break start
|
|
||||||
|
|
||||||
main()
|
|
||||||
|
|
Loading…
Reference in a new issue