Code Monkey home page Code Monkey logo

battery-widget's Introduction

awesome.battery-widget

Battery indicator widget for awesome window manager.

Screenshot

Displays status information from /sys/class/power_supply.

Installation

Drop the script into your awesome config folder, e.g.:

cd ~/.config/awesome
git clone https://github.com/deficient/battery-widget.git

Optionally, in order to receive status updates, you will also need acpid:

pacman -S acpid
systemctl enable --now acpid

Usage

In order to add a battery widget to your wibox, you have to import the module and then instanciate a widget with the desired options like this:

-- Import module:
local battery_widget = require("battery-widget")

-- Instanciate and add widget to the wibox:
s.mywibox:setup {
    ...,
    { -- Right widgets
        ...,
        battery_widget {
            -- pass options here
        },
    },
}

If you pass an adapter name using the adapter = "..." option, a widget for that specific battery adapter will be instanciated. If the adapter option is not specified, the call will return a table containing widgets for each of the battery adapters in /sys/class/power_supply. In that case if there are no batteries an empty table will be returned and no error will occur on machines without batteries.

Options

The behaviour and appearance of the widget can be tweaked using a few options. This is an example using all available options:

battery_widget {
    ac = "AC",
    adapter = "BAT0",
    ac_prefix = "AC: ",
    battery_prefix = "Bat: ",
    percent_colors = {
        { 25, "red"   },
        { 50, "orange"},
        {999, "green" },
    },
    listen = true,
    timeout = 10,
    widget_text = "${AC_BAT}${color_on}${percent}%${color_off}",
    widget_font = "Deja Vu Sans Mono 16",
    tooltip_text = "Battery ${state}${time_est}\nCapacity: ${capacity_percent}%",
    alert_threshold = 5,
    alert_timeout = 0,
    alert_title = "Low battery !",
    alert_text = "${AC_BAT}${time_est}",
    alert_icon = "~/Downloads/low_battery_icon.png",
    warn_full_battery = true,
    full_battery_icon = "~/Downloads/full_battery_icon.png",
}

adapter The name of the directory entry in /sys/class/power_supply corresponding to the requested battery adapter.

ac The name of the directory entry in /sys/class/power_supply corresponding to your AC status.

ac_prefix The prefix to populate ${AC_BAT} when your computer is using ac power. If your font supports unicode characters, you could use "๐Ÿ”Œ".

battery_prefix The prefix to populate ${AC_BAT} when your computer is using battery power. If your font supports unicode characters, you could use "๐Ÿ”‹". Can also be configured as a table like percent_colors to show different prefixes at different battery percentages.

percent_colors (limits for backwards compatibility) The colors that the percentage changes to, as well as the upper-bound limit of when it will change. Ex. {100, "green"} means any percentage lower than 100 is colored green.

listen Tells the widget to listen to updates via acpi_listen. When an event is fired, the widget updates.

timeout The time interval that the widget waits before it updates itself, in seconds.

widget_text, tooltip_text The text which shows up on the toolbar and when you highlight the widget, respectively. Please refer to function battery_widget:update() for other interpolatable variables.

widget_font The font description used for the widget text, for instance "Deja Vu Sans Mono 16". If this is empty or unspecified, the default font will be used.

alert_threshold The percentage used as the maximum value at which an alert will be generated, -1 to disable alerts. Once the alert is dismissed (or expired) it will not show up again until the battery has been charging.

alert_timeout The time after which the alert expire, 0 for no timeout.

alert_title, alert_text, alert_icon The text which shows up on the alert notification, respectively the title, body text and image path.

warn_full_battery, boolean Whether a notification should be displayed when the battery gets fully charged.

full_battery_icon Path to the image, which should be shown as part of the notification when battery gets fully charged (depends on warn_full_battery).

Usage Examples

Percentage tables can be used for ac_prefix, battery_prefix, and percent_colors to show different things depending on the battery charge level, e.g.:

battery_widget {
    -- Show different prefixes when charging on AC
    ac_prefix = {
        { 25, "not charged" },
        { 50, "1/4 charged" },
        { 75, "2/4 charged" },
        { 95, "3/4 charged" },
        {100, "fully charged" },
    },

    -- Show a visual indicator of charge level when on battery power
    battery_prefix = {
        { 25, "#--- "},
        { 50, "##-- "},
        { 75, "###- "},
        {100, "#### "},
    }
}

ac_prefix, battery_prefix, and widget_text can be further customized with spans to specify colors or fonts, e.g.:

battery_widget {
    -- Use different colors for ac_prefix and battery_prefix
    ac_prefix = '<span color="red">AC: </span>',
    battery_prefix = '<span color="green">Bat: </span>',

    -- Use a bold font for both prefixes (overrides widget_font)
    widget_text = '<span font="Deja Vu Sans Bold 16">${AC_BAT}</span>${color_on}${percent}%${color_off}'
}

Requirements

battery-widget's People

Contributors

akuskis avatar coldfix avatar dokthar avatar florianmuenchbach avatar informatic avatar ivankayukoff avatar jbarrett687 avatar lmanul avatar rovanion avatar scorfly avatar tamsanh avatar whwright avatar wucke13 avatar xarkes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

battery-widget's Issues

How to add this to the wibar?

Using right_layout:add(battery.widget) throws an error cause there is no object right_layout. How may I add it to the wibar, after initial setup?

error on install

photo6239945620156691145

I cloned the repo into ./widgets/ and I imorted it using local battery_widget = pcall(require, "widgets.battery-widget") but as soon as I reload the wm I get this error and the the wm fall back to the default config

Widget Fails on Battery Power (Pinebook Pro)

I am using a Pinebook Pro, which has a different battery device name than normal (/sys/class/power_supply/cw2015-battery/ instead of /sys/class/power_supply/BATx), which I adjusted for in my Awesome config. When running on AC power, the widget works perfectly. However, when just using the battery, the widget crashes with .config/awesome/battery-widget/init.lua:240: attempt to perform arithmetic on a nil value (field 'charge').

The relevant section of my config is

`local battery_widget = require("battery-widget")
local BAT0 = battery_widget { adapter = "cw2015-battery", ac = "dc-charger", timeout = 10, listen = true }

...

s.mywibox:setup {
...
( -- Right widgets
BAT0,
...`

Rename battery-widget.lua to init.lua

Hey.
Renaming battery-widget.lua to init.lua would make using Your module slightly cleaner in dotfiles-repository-like environments.
By default require('MODULE') will try to load MODULE.lua, and then MODULE/init.lua, thus this repo could be easily used as a submodule in git and such, without playing with symlinks.

Error on init.lua:143

I follow the step to add the battery widget, but I get this error:

/home/user/.config/awesome/battery-widget/init.lua 143: bad argument # 1 to 'tolower' (string expected, got nil)

Unicode character support assistance

Hi, I am new to arch and I was wondering if there are any dependencies or unicode character support packages that work well with the widget. When I change the prefix "Bat:" to "U+1F50B" to display a battery icon, the widget renders "U+1F50B" instead of the icon. Any suggestion would be very much appreciated.

Font to small.

Using this widget in my wibar, I am not sure why, but the font of the widget is very small. I guess it is not respecting my bar config font & size. Here is my bar
image
Some stuff which might help

-- Battery
local battery_widget = require("battery-widget")
local BAT0 = battery_widget { adapter = "BAT0", ac = "AC" }

battery_widget {
    ac = "AC",
    adapter = "BAT0",
    ac_prefix = "AC: ",
    battery_prefix = "Bat: ",
    percent_colors = {
        { 25, "red"   },
        { 50, "orange"},
        {999, "green" },
    },
    listen = true,
    timeout = 10,
    widget_text = "${AC_BAT}${color_on}${percent}%${color_off}",
    widget_text = '<span font="Roboto Mono 10">${AC_BAT}</span>${color_on}${percent}%${color_off}',
    tooltip_text = "Battery ${state}${time_est}\nCapacity: ${capacity_percent}%",
    alert_threshold = 5,
    alert_timeout = 0,
    alert_title = "Low battery !",
    alert_text = "${AC_BAT}${time_est}"
}
    -- Add widgets to the wibox
    s.mywibox:setup {
        layout = wibox.layout.align.horizontal,
        { -- Left widgets
            layout = wibox.layout.fixed.horizontal,
            s.mytaglist,
            s.mypromptbox,
        },
        s.mytasklist, -- Middle widget
        { -- Right widgets
            layout = wibox.layout.fixed.horizontal,
            BAT0,
            mytextclock,
        },
    }
end)
-- }}}

Thanks in advance :)

Port to FreeBSD

I use your battery widget in Linux. I like it. I, however, need to maintain some machines running FreeBSD. FreeBSD doesn't have acpid (it has devd). It also doesn't use sysfs, it uses sysctls. The translations are relatively straightforward (well, acpid->devd is some work)

My lua sucks and I have no interest in improving it, but I can tell you how to accomplish most of what you need in FreeBSD if anyone is interested in porting this. Meanwhile I will try to find another battery monitor.

Widget only displays battery prefix

Title is self explainatory. Widget always displays battery_prefix regardless of whether the ac cord is plugged in or not.

> awesome --version
awesome v4.2-289-g98e59225 (Human after all)
 โ€ข Compiled against Lua 5.3.4 (running with Lua 5.3)
 โ€ข D-Bus support: โœ”
 โ€ข execinfo support: โœ”
 โ€ข xcb-randr version: 1.6
 โ€ข LGI version: 0.9.2


> lua -v
Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio

Nice work btw. Keep it up.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.