Add basic battery widget

- this gives me a place to mouse over and check but the dynamic
updates are not working yet!!
master
josiah 4 years ago
parent 0d68d021c8
commit 9b42c1d297

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 956 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -0,0 +1,45 @@
# Batteryarc widget
This widget is more informative version of [battery widget](https://github.com/streetturtle/awesome-wm-widgets/tree/master/battery-widget).
Depending of the battery status it could look following ways:
- ![10_d](./10_d.png) - less than 15 percent
- ![10_c](./10_c.png) - less than 15 percent, charging
- ![20_d](./20_d.png) - between 15 and 40 percent
- ![20_c](./20_c.png) - between 15 and 40 percent, charging
- ![80_d](./80_d.png) - more than 40 percent
- ![80_c](./80_c.png) - more than 40 percent, charging
Widget uses following beautiful variables with values:
```lua
theme.widget_main_color = "#74aeab"
theme.widget_red = "#e53935"
theme.widget_yellow = "#c0ca33"
theme.widget_green = "#43a047"
theme.widget_black = "#000000"
theme.widget_transparent = "#00000000"
```
which means that you need to copy the code above and paste it in your **theme.lua**. Otherwise you can change colors directly in the widget.
## Installation
Clone repo, include widget and use it in **rc.lua**:
```lua
require("volumearc")
...
s.mytasklist, -- Middle widget
{ -- Right widgets
layout = wibox.layout.fixed.horizontal,
...
batteryarc_widget,
...
```
You can get the icon for warning popup [here](https://vk.com/images/stickers/1933/512.png)
## Troubleshooting
In case of any doubts or questions don't hesitate to raise an [issue](https://github.com/streetturtle/awesome-wm-widgets/issues/new).

@ -0,0 +1,135 @@
local awful = require("awful")
local beautiful = require("beautiful")
local naughty = require("naughty")
local wibox = require("wibox")
local watch = require("awful.widget.watch")
local HOME = os.getenv("HOME")
-- only text
local text = wibox.widget {
id = "txt",
font = "Play 8",
widget = wibox.widget.textbox
}
-- mirror the text, because the whole widget will be mirrored after
local mirrored_text = wibox.container.mirror(text, { horizontal = true })
-- mirrored text with background
local mirrored_text_with_background = wibox.container.background(mirrored_text)
local batteryarc = wibox.widget {
mirrored_text_with_background,
max_value = 1,
rounded_edge = true,
thickness = 2,
start_angle = 4.71238898, -- 2pi*3/4
forced_height = 32,
forced_width = 32,
bg = "#ffffff11",
paddings = 4,
widget = wibox.container.arcchart,
set_value = function(self, value)
self.value = value
end,
}
-- mirror the widget, so that chart value increases clockwise
local batteryarc_widget = wibox.container.mirror(batteryarc, { horizontal = true })
watch("acpi", 30,
function(widget, stdout, stderr, exitreason, exitcode)
local batteryType
local _, status, charge_str, time = string.match(stdout, '(.+): (%a+), (%d?%d%d)%%,? ?.*')
local charge = tonumber(charge_str)
widget.value = charge / 100
if status == 'Charging' then
mirrored_text_with_background.fg = beautiful.widget_green
--mirrored_text_with_background.fg = beautiful.widget_black
--naughty.notify {
--text = stdout,
--title = "Battery status",
--timeout = 5,
--hover_timeout = 0.5,
--width = 400,
--}
else
mirrored_text_with_background.bg = beautiful.widget_transparent
mirrored_text_with_background.fg = beautiful.widget_main_color
end
if charge <= 12 then
batteryarc.colors = { beautiful.border_marked }
mirrored_text_with_background.bg = beautiful.border_marked
mirrored_text_with_background.fg = beautiful.fg_normal
show_battery_warning()
elseif charge > 12 and charge < 25 then
batteryarc.colors = { beautiful.widget_yellow }
mirrored_text_with_background.bg = beautiful.widget_yellow
mirrored_text_with_background.fg = beautiful.bg_normal
elseif charge < 100 then
if status == 'Charging' then
batteryarc.colors = { beautiful.widget_green }
mirrored_text_with_background.bg = beautiful.bg_normal
mirrored_text_with_background.fg = beautiful.fg_normal
else
batteryarc.colors = { beautiful.widget_main_color }
end
else
batteryarc.colors = { beautiful.widget_main_color }
end
if charge == 100 then
--text.text = string.format("%03d", charge)
text.text = "OK"
text.font = "Play 10"
else
text.text = charge
text.font = "Play 12"
end
end,
batteryarc)
-- Popup with battery info
-- One way of creating a pop-up notification - naughty.notify
local notification
function show_battery_status()
awful.spawn.easy_async([[bash -c 'acpi']],
function(stdout, _, _, _)
notification = naughty.notify {
text = stdout,
title = "Battery status",
timeout = 5,
hover_timeout = 0.5,
}
end)
end
batteryarc:connect_signal("mouse::enter", function() show_battery_status() end)
batteryarc:connect_signal("mouse::leave", function() naughty.destroy(notification) end)
-- Alternative to naughty.notify - tooltip. You can compare both and choose the preferred one
--battery_popup = awful.tooltip({objects = {battery_widget}})
-- To use colors from beautiful theme put
-- following lines in rc.lua before require("battery"):
-- beautiful.tooltip_fg = beautiful.fg_normal
-- beautiful.tooltip_bg = beautiful.bg_normal
--[[ Show warning notification ]]
function show_battery_warning()
naughty.notify {
preset = naughty.config.presets.critical,
icon = "/usr/share/icons/Arc/emblems/128/emblem-danger.png",
icon_size = 200,
text = "La batterie est bientôt épuisée !",
title = "ATTENTION !",
timeout = 5,
hover_timeout = 0.5,
position = "bottom_right",
}
end
return batteryarc_widget

@ -0,0 +1,140 @@
---------------------------
-- Default awesome theme --
---------------------------
local theme_assets = require("beautiful.theme_assets")
local xresources = require("beautiful.xresources")
local dpi = xresources.apply_dpi
local gfs = require("gears.filesystem")
local themes_path = gfs.get_themes_dir()
local theme = {}
theme.font = "sans 8"
theme.bg_normal = "#222222"
theme.bg_focus = "#535d6c"
theme.bg_urgent = "#ff0000"
theme.bg_minimize = "#444444"
theme.bg_systray = theme.bg_normal
theme.fg_normal = "#aaaaaa"
theme.fg_focus = "#ffffff"
theme.fg_urgent = "#ffffff"
theme.fg_minimize = "#ffffff"
theme.useless_gap = dpi(0)
theme.border_width = dpi(1)
theme.border_normal = "#000000"
theme.border_focus = "#535d6c"
theme.border_marked = "#91231c"
-- customize the battery widget
-- as of 2020-05-09 this is not working, fuckin. -jlj
theme.widget_main_color = "#74aeab"
theme.widget_red = "#e53935"
theme.widget_yellow = "#c0ca33"
theme.widget_green = "#43a047"
theme.widget_black = "#000000"
theme.widget_transparent = "#00000000"
-- There are other variable sets
-- overriding the default one when
-- defined, the sets are:
-- taglist_[bg|fg]_[focus|urgent|occupied|empty|volatile]
-- tasklist_[bg|fg]_[focus|urgent]
-- titlebar_[bg|fg]_[normal|focus]
-- tooltip_[font|opacity|fg_color|bg_color|border_width|border_color]
-- mouse_finder_[color|timeout|animate_timeout|radius|factor]
-- prompt_[fg|bg|fg_cursor|bg_cursor|font]
-- hotkeys_[bg|fg|border_width|border_color|shape|opacity|modifiers_fg|label_bg|label_fg|group_margin|font|description_font]
-- Example:
--theme.taglist_bg_focus = "#ff0000"
-- Generate taglist squares:
local taglist_square_size = dpi(4)
theme.taglist_squares_sel = theme_assets.taglist_squares_sel(
taglist_square_size, theme.fg_normal
)
theme.taglist_squares_unsel = theme_assets.taglist_squares_unsel(
taglist_square_size, theme.fg_normal
)
-- Variables set for theming notifications:
-- notification_font
-- notification_[bg|fg]
-- notification_[width|height|margin]
-- notification_[border_color|border_width|shape|opacity]
-- Variables set for theming the menu:
-- menu_[bg|fg]_[normal|focus]
-- menu_[border_color|border_width]
theme.menu_submenu_icon = themes_path.."default/submenu.png"
theme.menu_height = dpi(15)
theme.menu_width = dpi(100)
-- You can add as many variables as
-- you wish and access them by using
-- beautiful.variable in your rc.lua
--theme.bg_widget = "#cc0000"
-- Define the image to load
theme.titlebar_close_button_normal = themes_path.."default/titlebar/close_normal.png"
theme.titlebar_close_button_focus = themes_path.."default/titlebar/close_focus.png"
theme.titlebar_minimize_button_normal = themes_path.."default/titlebar/minimize_normal.png"
theme.titlebar_minimize_button_focus = themes_path.."default/titlebar/minimize_focus.png"
theme.titlebar_ontop_button_normal_inactive = themes_path.."default/titlebar/ontop_normal_inactive.png"
theme.titlebar_ontop_button_focus_inactive = themes_path.."default/titlebar/ontop_focus_inactive.png"
theme.titlebar_ontop_button_normal_active = themes_path.."default/titlebar/ontop_normal_active.png"
theme.titlebar_ontop_button_focus_active = themes_path.."default/titlebar/ontop_focus_active.png"
theme.titlebar_sticky_button_normal_inactive = themes_path.."default/titlebar/sticky_normal_inactive.png"
theme.titlebar_sticky_button_focus_inactive = themes_path.."default/titlebar/sticky_focus_inactive.png"
theme.titlebar_sticky_button_normal_active = themes_path.."default/titlebar/sticky_normal_active.png"
theme.titlebar_sticky_button_focus_active = themes_path.."default/titlebar/sticky_focus_active.png"
theme.titlebar_floating_button_normal_inactive = themes_path.."default/titlebar/floating_normal_inactive.png"
theme.titlebar_floating_button_focus_inactive = themes_path.."default/titlebar/floating_focus_inactive.png"
theme.titlebar_floating_button_normal_active = themes_path.."default/titlebar/floating_normal_active.png"
theme.titlebar_floating_button_focus_active = themes_path.."default/titlebar/floating_focus_active.png"
theme.titlebar_maximized_button_normal_inactive = themes_path.."default/titlebar/maximized_normal_inactive.png"
theme.titlebar_maximized_button_focus_inactive = themes_path.."default/titlebar/maximized_focus_inactive.png"
theme.titlebar_maximized_button_normal_active = themes_path.."default/titlebar/maximized_normal_active.png"
theme.titlebar_maximized_button_focus_active = themes_path.."default/titlebar/maximized_focus_active.png"
theme.wallpaper = themes_path.."default/background.png"
-- You can use your own layout icons like this:
theme.layout_fairh = themes_path.."default/layouts/fairhw.png"
theme.layout_fairv = themes_path.."default/layouts/fairvw.png"
theme.layout_floating = themes_path.."default/layouts/floatingw.png"
theme.layout_magnifier = themes_path.."default/layouts/magnifierw.png"
theme.layout_max = themes_path.."default/layouts/maxw.png"
theme.layout_fullscreen = themes_path.."default/layouts/fullscreenw.png"
theme.layout_tilebottom = themes_path.."default/layouts/tilebottomw.png"
theme.layout_tileleft = themes_path.."default/layouts/tileleftw.png"
theme.layout_tile = themes_path.."default/layouts/tilew.png"
theme.layout_tiletop = themes_path.."default/layouts/tiletopw.png"
theme.layout_spiral = themes_path.."default/layouts/spiralw.png"
theme.layout_dwindle = themes_path.."default/layouts/dwindlew.png"
theme.layout_cornernw = themes_path.."default/layouts/cornernww.png"
theme.layout_cornerne = themes_path.."default/layouts/cornernew.png"
theme.layout_cornersw = themes_path.."default/layouts/cornersww.png"
theme.layout_cornerse = themes_path.."default/layouts/cornersew.png"
-- Generate Awesome icon:
theme.awesome_icon = theme_assets.awesome_icon(
theme.menu_height, theme.bg_focus, theme.fg_focus
)
-- Define the icon theme for application icons. If not set then the icons
-- from /usr/share/icons and /usr/share/icons/hicolor will be used.
theme.icon_theme = nil
return theme
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

@ -21,6 +21,10 @@ require("awful.hotkeys_popup.keys")
-- volume import
local volume_widget = require("awesome-wm-widgets.volume-widget.volume")
-- battery import and customization
local battery_widget = require("awesome-wm-widgets.batteryarc-widget.batteryarc")
-- {{{ Error handling
-- Check if awesome encountered an error during startup and fell back to
-- another config (This code will only ever execute for the fallback config)
@ -48,7 +52,8 @@ end
-- {{{ Variable definitions
-- Themes define colours, icons, font and wallpapers.
beautiful.init(gears.filesystem.get_themes_dir() .. "default/theme.lua")
beautiful.init(gears.filesystem.get_themes_dir() .. "default/theme.lua") -- this is the OG theme
-- beautiful.init(gears.filesystem.get_themes_dir() .. "jlj-theme.lua") -- this is my shitty test theme
-- This is used later as the default terminal and editor to run.
terminal = "konsole"
@ -217,6 +222,7 @@ awful.screen.connect_for_each_screen(function(s)
wibox.widget.systray(),
mytextclock,
volume_widget({display_notification = true}),
battery_widget,
s.mylayoutbox,
},
}

@ -12,3 +12,10 @@
** adding new files
- ~git add -f <filename>~
** awesomeWM
awesome does a lot for me. it also relies on a lot of bullshit:
- acpi: battery stuff
- arc icons: icons for the task bar
- alsamixer: volume widget
- more to come lol.

Loading…
Cancel
Save