From bdf4583ee8b31bc40d1929bb2823abc429eacf4c Mon Sep 17 00:00:00 2001 From: Samuel Date: Thu, 10 Sep 2020 10:10:25 +0200 Subject: [PATCH] added module for screen brightness --- widgets/brightness_linux.lua | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 widgets/brightness_linux.lua diff --git a/widgets/brightness_linux.lua b/widgets/brightness_linux.lua new file mode 100644 index 0000000..9c0315f --- /dev/null +++ b/widgets/brightness_linux.lua @@ -0,0 +1,39 @@ +-- template for asynchronous widet types +-- Copyright (C) 2019 Nguyễn Gia Phong +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . + +local helpers = require("vicious.helpers") +local spawn = require("vicious.spawn") +local gears = require("gears") + +local brightness_linux = {} + +function brightness_linux.async(format, warg, callback) + local cmd = "brightnessctl -m" + + local function parse(response) + -- extract percentage which incldues '%' at the end + response = gears.string.split(response, ',')[4] + -- remove '%' at the end + response = response:sub(1, response:len()-1) + return {response} + end + + spawn.easy_async(cmd, function(stdout) callback(parse(stdout)) end) +end + +return helpers.setasyncall(brightness_linux)