Compare commits
No commits in common. "25a0e6243185ef3cbec1715db5f38738ff09e307" and "48b83f444d175496104f3b9ff36f1dff0473e01e" have entirely different histories.
25a0e62431
...
48b83f444d
34
.cspell.json
34
.cspell.json
|
@ -1,34 +0,0 @@
|
||||||
{
|
|
||||||
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
|
|
||||||
"version": "0.2",
|
|
||||||
"useGitignore": true,
|
|
||||||
"ignorePaths": [".git"],
|
|
||||||
"enableGlobDot": true,
|
|
||||||
"words": [
|
|
||||||
"Aire-One",
|
|
||||||
"apikey",
|
|
||||||
"berlam",
|
|
||||||
"constructorfct",
|
|
||||||
"dbus",
|
|
||||||
"drawin",
|
|
||||||
"dryrun",
|
|
||||||
"fatalwarnings",
|
|
||||||
"freedesktop",
|
|
||||||
"JohnnyMorganz",
|
|
||||||
"keygrabber",
|
|
||||||
"ldoc",
|
|
||||||
"luacheck",
|
|
||||||
"luacheckrc",
|
|
||||||
"luadoc",
|
|
||||||
"luarocks",
|
|
||||||
"lunarmodules",
|
|
||||||
"mktemp",
|
|
||||||
"mousegrabber",
|
|
||||||
"rockspec",
|
|
||||||
"rockspecs",
|
|
||||||
"staticfct",
|
|
||||||
"stylua",
|
|
||||||
"upower",
|
|
||||||
"wibox"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
# EditorConfig is awesome: https://EditorConfig.org
|
|
||||||
|
|
||||||
# top-most EditorConfig file
|
|
||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 3
|
|
||||||
end_of_line = lf
|
|
||||||
charset = utf-8
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
insert_final_newline = true
|
|
||||||
|
|
||||||
[*.{json,yaml}]
|
|
||||||
indent_size = 2
|
|
||||||
|
|
||||||
[Makefile]
|
|
||||||
indent_style = tab
|
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
name: Build doc
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
pages: write
|
|
||||||
id-token: write
|
|
||||||
|
|
||||||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
|
|
||||||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
|
|
||||||
concurrency:
|
|
||||||
group: "pages"
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: lunarmodules/ldoc@v1.5.0
|
|
||||||
- uses: actions/upload-pages-artifact@v3
|
|
||||||
id: deployment
|
|
||||||
with:
|
|
||||||
path: doc/
|
|
||||||
deploy:
|
|
||||||
needs: build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
environment:
|
|
||||||
name: github-pages
|
|
||||||
url: ${{ steps.deployment.outputs.page_url }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/deploy-pages@v4
|
|
||||||
id: deployment
|
|
|
@ -1,51 +0,0 @@
|
||||||
name: Lint
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
luacheck:
|
|
||||||
needs: []
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: lunarmodules/luacheck@v1
|
|
||||||
|
|
||||||
stylua:
|
|
||||||
needs: []
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: JohnnyMorganz/stylua-action@v4
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
version: v0.20.0
|
|
||||||
args: --check .
|
|
||||||
|
|
||||||
ldoc:
|
|
||||||
needs: []
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: lunarmodules/ldoc@v1.5.0
|
|
||||||
with:
|
|
||||||
args: --fatalwarnings .
|
|
||||||
|
|
||||||
spellcheck:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: streetsidesoftware/cspell-action@v6
|
|
||||||
with:
|
|
||||||
incremental_files_only: false
|
|
||||||
|
|
||||||
rockspec:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: luarocks/gh-actions-lua@v10
|
|
||||||
- uses: luarocks/gh-actions-luarocks@v5
|
|
||||||
- run: luarocks lint awesome-battery_widget-dev-1.rockspec
|
|
|
@ -1,21 +0,0 @@
|
||||||
name: Upload rock to LuaRocks
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
affected:
|
|
||||||
uses: lunarmodules/.github/.github/workflows/list_affected_rockspecs.yml@main
|
|
||||||
upload:
|
|
||||||
needs: affected
|
|
||||||
if: >-
|
|
||||||
${{
|
|
||||||
github.repository == 'Aire-One/awesome-battery_widget' &&
|
|
||||||
( github.ref_name == 'master' || startsWith(github.ref, 'refs/tags/') ) &&
|
|
||||||
needs.affected.outputs.rockspecs
|
|
||||||
}}
|
|
||||||
uses: lunarmodules/.github/.github/workflows/upload_to_luarocks.yml@main
|
|
||||||
with:
|
|
||||||
rockspecs: ${{ needs.affected.outputs.rockspecs }}
|
|
||||||
secrets:
|
|
||||||
apikey: ${{ secrets.LUAROCKS_APIKEY }}
|
|
|
@ -1 +1 @@
|
||||||
/doc
|
doc/
|
||||||
|
|
31
.luacheckrc
31
.luacheckrc
|
@ -1,31 +0,0 @@
|
||||||
std = "min"
|
|
||||||
|
|
||||||
include_files = {
|
|
||||||
".busted",
|
|
||||||
".luacheckrc",
|
|
||||||
"*.rockspec",
|
|
||||||
"src/",
|
|
||||||
}
|
|
||||||
|
|
||||||
read_globals = {
|
|
||||||
"awesome",
|
|
||||||
"button",
|
|
||||||
"dbus",
|
|
||||||
"drawable",
|
|
||||||
"drawin",
|
|
||||||
"key",
|
|
||||||
"keygrabber",
|
|
||||||
"mousegrabber",
|
|
||||||
"selection",
|
|
||||||
"tag",
|
|
||||||
"window",
|
|
||||||
"table.unpack",
|
|
||||||
"math.atan2",
|
|
||||||
}
|
|
||||||
|
|
||||||
globals = {
|
|
||||||
"screen",
|
|
||||||
"mouse",
|
|
||||||
"root",
|
|
||||||
"client",
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
indent_type = "Spaces"
|
|
||||||
indent_width = 3
|
|
||||||
call_parentheses = "None"
|
|
||||||
|
|
||||||
[sort_requires]
|
|
||||||
enabled = true
|
|
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
"Lua.runtime.path": [
|
|
||||||
"/usr/share/awesome/lib/?.lua",
|
|
||||||
"/usr/share/awesome/lib/?/init.lua"
|
|
||||||
],
|
|
||||||
"[lua]": {
|
|
||||||
"editor.defaultFormatter": "JohnnyMorganz.stylua"
|
|
||||||
},
|
|
||||||
"stylua.targetReleaseVersion": "latest",
|
|
||||||
"files.associations": {
|
|
||||||
".busted": "lua",
|
|
||||||
".luacheckrc": "lua",
|
|
||||||
"*.rockspec": "lua",
|
|
||||||
"config.ld": "lua"
|
|
||||||
}
|
|
||||||
}
|
|
24
Makefile
24
Makefile
|
@ -1,24 +0,0 @@
|
||||||
install:
|
|
||||||
luarocks --local build
|
|
||||||
|
|
||||||
luacheck:
|
|
||||||
luacheck .
|
|
||||||
|
|
||||||
stylua:
|
|
||||||
stylua --check .
|
|
||||||
|
|
||||||
ldoc-dryrun:
|
|
||||||
$(eval TMP := $(shell mktemp -d))
|
|
||||||
ldoc --fatalwarnings --dir $(TMP) .
|
|
||||||
rm -rf $(TMP)
|
|
||||||
|
|
||||||
cspell:
|
|
||||||
cspell lint .
|
|
||||||
|
|
||||||
lint-rockspec:
|
|
||||||
luarocks lint awesome-battery_widget-dev-1.rockspec
|
|
||||||
|
|
||||||
lint: luacheck stylua ldoc-dryrun cspell lint-rockspec
|
|
||||||
|
|
||||||
ldoc:
|
|
||||||
ldoc .
|
|
|
@ -1,6 +1,6 @@
|
||||||
# UPower Battery Widget
|
# UPower Battery Widget
|
||||||
|
|
||||||
This is my re-implementation of the [awesome-upower-battery][awesome-upower-battery-repository] by [berlam][berlam]. This widget has a lot of potential for the [Awesome WM][AwesomeWM] and I wanted to hack it a bit for my personal use.
|
This is my re-implementation of the [awesome-upower-battery][awesome-upower-battery-repository] by [berlam][berlam]. This widget has a lot of potencial for the [Awesome WM][AwesomeWM] and I wanted to hack it a bit for my personal use.
|
||||||
|
|
||||||
UPower is an abstraction for power devices. You can use it to access advanced statistics about your power devices.
|
UPower is an abstraction for power devices. You can use it to access advanced statistics about your power devices.
|
||||||
UPowerGlib is a Glib interface to access data exposed by UPower.
|
UPowerGlib is a Glib interface to access data exposed by UPower.
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
package = "awesome-battery_widget"
|
|
||||||
version = "dev-1"
|
|
||||||
|
|
||||||
source = {
|
|
||||||
url = "git+https://github.com/Aire-One/awesome-battery_widget.git",
|
|
||||||
}
|
|
||||||
|
|
||||||
description = {
|
|
||||||
summary = "A UPowerGlib based battery widget for the Awesome WM with a basic widget template mechanism! 🔋",
|
|
||||||
homepage = "https://github.com/Aire-One/awesome-battery_widget",
|
|
||||||
license = "*** please specify a license ***",
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies = {
|
|
||||||
"lua >= 5.1, < 5.5",
|
|
||||||
}
|
|
||||||
|
|
||||||
build = {
|
|
||||||
type = "builtin",
|
|
||||||
modules = {
|
|
||||||
["awesome-battery_widget.init"] = "src/awesome-battery_widget/init.lua",
|
|
||||||
},
|
|
||||||
copy_directories = {
|
|
||||||
"doc",
|
|
||||||
},
|
|
||||||
}
|
|
11
config.ld
11
config.ld
|
@ -1,12 +1,12 @@
|
||||||
-- Configuration file for ldoc
|
-- Configuration file for ldoc
|
||||||
|
|
||||||
project = "battery_widget"
|
project = 'battery_widget'
|
||||||
title = "A UPowerGlib based battery widget for the Awesome WM with a basic widget template mechanism! 🔋"
|
title = 'Awesome WM - Battery Widget'
|
||||||
|
|
||||||
all = false
|
all = false
|
||||||
dir = "doc"
|
dir = 'doc'
|
||||||
format = "markdown"
|
format='markdown'
|
||||||
pretty = "lua"
|
pretty = 'lua'
|
||||||
prettify_files = true
|
prettify_files = true
|
||||||
backtick_references = true
|
backtick_references = true
|
||||||
merge = true
|
merge = true
|
||||||
|
@ -15,6 +15,7 @@ wrap = true
|
||||||
sort_modules = true
|
sort_modules = true
|
||||||
not_luadoc = true
|
not_luadoc = true
|
||||||
|
|
||||||
|
|
||||||
-- Define some new ldoc tags from the AwesomeWM doc
|
-- Define some new ldoc tags from the AwesomeWM doc
|
||||||
new_type("staticfct", "Static functions", false, "Parameters")
|
new_type("staticfct", "Static functions", false, "Parameters")
|
||||||
new_type("constructorfct", "Constructor", false, "Parameters")
|
new_type("constructorfct", "Constructor", false, "Parameters")
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
-- A battery widget based on the UPower daemon.
|
-- A battery widget based on the UPower deamon.
|
||||||
--
|
--
|
||||||
-- @author Aire-One
|
-- @author Aire-One
|
||||||
-- @copyright 2020 Aire-One
|
-- @copyright 2020 Aire-One
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
local upower = require("lgi").require "UPowerGlib"
|
local upower = require('lgi').require('UPowerGlib')
|
||||||
|
|
||||||
local gtable = require "gears.table"
|
local gtable = require 'gears.table'
|
||||||
local gtimer = require "gears.timer" -- cspell: ignore gtimer
|
local gtimer = require 'gears.timer'
|
||||||
local wbase = require "wibox.widget.base" -- cspell: ignore wbase
|
local wbase = require 'wibox.widget.base'
|
||||||
|
|
||||||
local setmetatable = setmetatable -- luacheck: ignore setmetatable
|
local setmetatable = setmetatable -- luacheck: ignore setmetatable
|
||||||
|
|
||||||
local battery_widget = {}
|
local battery_widget = {}
|
||||||
local mt = {}
|
local mt = {}
|
||||||
|
|
||||||
|
|
||||||
--- Helper to get the path of all connected power devices.
|
--- Helper to get the path of all connected power devices.
|
||||||
-- @treturn table The list of all power devices path.
|
-- @treturn table The list of all power devices path.
|
||||||
-- @staticfct battery_widget.list_devices
|
-- @staticfct battery_widget.list_devices
|
||||||
|
@ -50,7 +51,7 @@ end
|
||||||
-- @treturn string The BAT0 device path.
|
-- @treturn string The BAT0 device path.
|
||||||
-- @staticfct battery_widget.get_BAT0_device_path
|
-- @staticfct battery_widget.get_BAT0_device_path
|
||||||
function battery_widget.get_BAT0_device_path()
|
function battery_widget.get_BAT0_device_path()
|
||||||
local bat0_path = "/org/freedesktop/UPower/devices/battery_BAT0"
|
local bat0_path = '/org/freedesktop/UPower/devices/battery_BAT0'
|
||||||
return bat0_path
|
return bat0_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,14 +65,15 @@ end
|
||||||
-- @staticfct battery_widget.to_clock
|
-- @staticfct battery_widget.to_clock
|
||||||
function battery_widget.to_clock(seconds)
|
function battery_widget.to_clock(seconds)
|
||||||
if seconds <= 0 then
|
if seconds <= 0 then
|
||||||
return "00:00"
|
return '00:00';
|
||||||
else
|
else
|
||||||
local hours = string.format("%02.f", math.floor(seconds / 3600))
|
local hours = string.format('%02.f', math.floor(seconds/3600));
|
||||||
local mins = string.format("%02.f", math.floor(seconds / 60 - hours * 60))
|
local mins = string.format('%02.f', math.floor(seconds/60 - hours*60));
|
||||||
return hours .. ":" .. mins
|
return hours .. ':' .. mins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Gives the default widget to use if user didn't specify one.
|
--- Gives the default widget to use if user didn't specify one.
|
||||||
-- The default widget used is an `empty_widget` instance.
|
-- The default widget used is an `empty_widget` instance.
|
||||||
-- @treturn widget The default widget to use.
|
-- @treturn widget The default widget to use.
|
||||||
|
@ -79,15 +81,17 @@ local function default_template()
|
||||||
return wbase.empty_widget()
|
return wbase.empty_widget()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- The device monitored by the widget.
|
--- The device monitored by the widget.
|
||||||
-- @property device
|
-- @property device
|
||||||
-- @tparam UPowerGlib.Device device
|
-- @tparam UPowerGlib.Device device
|
||||||
|
|
||||||
--- Emitted when the UPower device notify an update.
|
--- Emited when the UPower device notify an update.
|
||||||
-- @signal upower::update
|
-- @signal upower::update
|
||||||
-- @tparam battery_widget widget The widget.
|
-- @tparam battery_widget widget The widget.
|
||||||
-- @tparam UPowerGlib.Device device The Upower device.
|
-- @tparam UPowerGlib.Device device The Upower device.
|
||||||
|
|
||||||
|
|
||||||
--- battery_widget constructor.
|
--- battery_widget constructor.
|
||||||
--
|
--
|
||||||
-- This function creates a new `battery_widget` instance. This widget watches
|
-- This function creates a new `battery_widget` instance. This widget watches
|
||||||
|
@ -105,29 +109,31 @@ end
|
||||||
function battery_widget.new (args)
|
function battery_widget.new (args)
|
||||||
args = gtable.crush({
|
args = gtable.crush({
|
||||||
widget_template = default_template(),
|
widget_template = default_template(),
|
||||||
device_path = "",
|
device_path = '',
|
||||||
use_display_device = false,
|
use_display_device = false
|
||||||
}, args or {})
|
}, args or {})
|
||||||
|
|
||||||
local widget = wbase.make_widget_from_value(args.widget_template)
|
local widget = wbase.make_widget_from_value(args.widget_template)
|
||||||
|
|
||||||
widget.device = args.use_display_device and upower.Client():get_display_device()
|
widget.device = args.use_display_device
|
||||||
|
and upower.Client():get_display_device()
|
||||||
or battery_widget.get_device(args.device_path)
|
or battery_widget.get_device(args.device_path)
|
||||||
|
|
||||||
-- Attach signals:
|
-- Attach signals:
|
||||||
widget.device.on_notify = function (d)
|
widget.device.on_notify = function (d)
|
||||||
widget:emit_signal("upower::update", d)
|
widget:emit_signal('upower::update', d)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Call an update cycle if the user asked to instant update the widget.
|
-- Call an update cycle if the user asked to instan update the widget.
|
||||||
if args.instant_update then
|
if args.instant_update then
|
||||||
gtimer.delayed_call(widget.emit_signal, widget, "upower::update", widget.device)
|
gtimer.delayed_call(widget.emit_signal, widget, 'upower::update', widget.device)
|
||||||
end
|
end
|
||||||
|
|
||||||
return widget
|
return widget
|
||||||
end
|
end
|
||||||
|
|
||||||
function mt.__call(_, ...)
|
|
||||||
|
function mt.__call(self, ...)
|
||||||
return battery_widget.new(...)
|
return battery_widget.new(...)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue