--[[
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
--]]
-local spawn = require("awful.spawn")
+local spawn = require("awful.spawn")
local timer = require("gears.timer")
local debug = require("debug")
local io = { lines = io.lines,
function helpers.async(cmd, callback)
return spawn.easy_async(cmd,
function (stdout, stderr, reason, exit_code)
- callback(stdout)
+ callback(stdout, exit_code)
end)
end
function helpers.async_with_shell(cmd, callback)
return spawn.easy_async_with_shell(cmd,
function (stdout, stderr, reason, exit_code)
- callback(stdout)
+ callback(stdout, exit_code)
end)
end
+-- run a command and execute a function on its output line by line
+function helpers.line_callback(cmd, callback)
+ return spawn.with_line_callback(cmd, {
+ stdout = function (line)
+ callback(line)
+ end,
+ })
+end
+
-- }}}
-- {{{ A map utility
Layouts, widgets and utilities for Awesome WM
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
--]]
Licensed under GNU General Public License v2
* (c) 2014, projektile
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2010-2012, Peter Hofmann
--]]
* (c) 2016, Henrik Antonsson
* (c) 2015, Joerg Jaspert
* (c) 2014, projektile
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2010-2012, Peter Hofmann
--]]
-local floor = math.floor
-local screen = screen
+local floor, max, screen = math.floor, math.max, screen
local centerwork = {
- name = "centerwork",
- horizontal = { name = "centerworkh" }
+ name = "centerwork",
+ horizontal = { name = "centerworkh" }
}
-local function do_centerwork(p, orientation)
- local t = p.tag or screen[p.screen].selected_tag
- local wa = p.workarea
+local function arrange(p, layout)
+ local t = p.tag or screen[p.screen].selected_tag
+ local wa = p.workarea
local cls = p.clients
if #cls == 0 then return end
- local c = cls[1]
- local g = {}
+ local c, g = cls[1], {}
- -- Main column, fixed width and height.
+ -- Main column, fixed width and height
local mwfact = t.master_width_factor
local mainhei = floor(wa.height * mwfact)
local mainwid = floor(wa.width * mwfact)
local slaveFirstDim, slaveSecondDim = 0, 0
- if orientation == "vertical" then
+ if layout.name == "centerwork" then -- vertical
if nbrFirstSlaves > 0 then slaveFirstDim = floor(wa.height / nbrFirstSlaves) end
if nbrSecondSlaves > 0 then slaveSecondDim = floor(wa.height / nbrSecondSlaves) end
g.x = wa.x + slaveLwid
g.y = wa.y
- else
+ else -- horizontal
if nbrFirstSlaves > 0 then slaveFirstDim = floor(wa.width / nbrFirstSlaves) end
if nbrSecondSlaves > 0 then slaveSecondDim = floor(wa.width / nbrSecondSlaves) end
g.y = wa.y + slaveThei
end
- if g.width < 1 then g.width = 1 end
- if g.height < 1 then g.height = 1 end
+ g.width = max(g.width, 1)
+ g.height = max(g.height, 1)
p.geometries[c] = g
- -- Auxiliary windows.
+ -- Auxiliary clients
if #cls <= 1 then return end
- for i = 2,#cls do
- local c = cls[i]
- local g = {}
+ for i = 2, #cls do
+ local c, g = cls[i], {}
+ local idxChecker, dimToAssign
local rowIndex = floor(i/2)
- if orientation == "vertical" then
- if i % 2 == 0 then
- -- left slave
- g.x = wa.x
- g.y = wa.y + (rowIndex-1)*slaveFirstDim
-
+ if layout.name == "centerwork" then
+ if i % 2 == 0 then -- left slave
+ g.x = wa.x
+ g.y = wa.y + (rowIndex - 1) * slaveFirstDim
g.width = slaveLwid
- -- if last slave in left row use remaining space for that slave
- if rowIndex == nbrFirstSlaves then
- g.height = wa.y + wa.height - g.y
- else
- g.height = slaveFirstDim
- end
- else
- -- right slave
- g.x = wa.x + slaveLwid + mainwid
- g.y = wa.y + (rowIndex-1)*slaveSecondDim
-
+ idxChecker, dimToAssign = nbrFirstSlaves, slaveFirstDim
+ else -- right slave
+ g.x = wa.x + slaveLwid + mainwid
+ g.y = wa.y + (rowIndex - 1) * slaveSecondDim
g.width = slaveRwid
- -- if last slave in right row use remaining space for that slave
- if rowIndex == nbrSecondSlaves then
- g.height = wa.y + wa.height - g.y
- else
- g.height = slaveSecondDim
- end
+ idxChecker, dimToAssign = nbrSecondSlaves, slaveSecondDim
end
- else
- if i % 2 == 0 then
- -- top slave
- g.x = wa.x + (rowIndex-1)*slaveFirstDim
- g.y = wa.y
- g.height = slaveThei
-
- -- if last slave in top row use remaining space for that slave
- if rowIndex == nbrFirstSlaves then
- g.width = wa.x + wa.width - g.x
- else
- g.width = slaveFirstDim
- end
+ -- if last slave in row, use remaining space for it
+ if rowIndex == idxChecker then
+ g.height = wa.y + wa.height - g.y
else
- -- bottom slave
- g.x = wa.x + (rowIndex-1)*slaveSecondDim
- g.y = wa.y + slaveThei + mainhei
+ g.height = dimToAssign
+ end
+ else
+ if i % 2 == 0 then -- top slave
+ g.x = wa.x + (rowIndex - 1) * slaveFirstDim
+ g.y = wa.y
+ g.height = slaveThei
+ idxChecker, dimToAssign = nbrFirstSlaves, slaveFirstDim
+ else -- bottom slave
+ g.x = wa.x + (rowIndex - 1) * slaveSecondDim
+ g.y = wa.y + slaveThei + mainhei
g.height = slaveBhei
- -- if last slave in bottom row use remaining space for that slave
- if rowIndex == nbrSecondSlaves then
- g.width = wa.x + wa.width - g.x
- else
- g.width = slaveSecondDim
- end
+ idxChecker, dimToAssign = nbrSecondSlaves, slaveSecondDim
+ end
+ -- if last slave in row, use remaining space for it
+ if rowIndex == idxChecker then
+ g.width = wa.x + wa.width - g.x
+ else
+ g.width = dimToAssign
end
end
- if g.width < 1 then g.width = 1 end
- if g.height < 1 then g.height = 1 end
+ g.width = max(g.width, 1)
+ g.height = max(g.height, 1)
p.geometries[c] = g
end
end
-
-function centerwork.horizontal.arrange(p)
- return do_centerwork(p, "horizontal")
+function centerwork.arrange(p)
+ return arrange(p, centerwork)
end
-function centerwork.arrange(p)
- return do_centerwork(p, "vertical")
+function centerwork.horizontal.arrange(p)
+ return arrange(p, centerwork.horizontal)
end
return centerwork
Layouts section
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2010-2012, Peter Hofmann
--]]
Licensed under GNU General Public License v2
* (c) 2014, projektile
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2010, Nicolas Estibals
* (c) 2010-2012, Peter Hofmann
+++ /dev/null
-#!/usr/bin/env bash
-#
-# Adapted from Eridan's "fs" (cleanup, enhancements and switch to bash/Linux)
-# JM, 10/12/2004
-#
-# Integrated into Lain in september 2013
-# https://github.com/lcpz/lain
-
-# Requires gawk
-
-# -------------------------------------------------------------------------
-# Decoding options
-# -------------------------------------------------------------------------
-USAGE="Usage: $0 [-h(elp)] | [-n(arrow mode)] | [-w(eb output) | --type=<fstype> | --exclude-type=<fstype>]"
-
-NARROW_MODE=0
-WEB_OUTPUT=0
-DF_OPTIONS=""
-
-while [ $# -gt 0 ]; do
-case "$1" in
-"-h" )
-echo $USAGE
-exit
-;;
-"-d" )
-DEBUG=1
-;;
-"-n" )
-NARROW_MODE=1
-;;
-"-w" )
-WEB_OUTPUT=1
-;;
---type=*)
-DF_OPTIONS+=" $1"
-;;
---exclude-type=*)
-DF_OPTIONS+=" $1"
-;;
-* )
-echo $USAGE
-exit
-;;
-esac
-shift
-done
-
-# -------------------------------------------------------------------------
-# Preparations
-# -------------------------------------------------------------------------
-SYSTEM=`uname -s`
-PATTERN="/"
-
-case "$SYSTEM" in
-"Linux" )
-DF_COMMAND="/usr/bin/env df -k"
-SORT_COMMAND="/usr/bin/env sort -k6"
-AWK_COMMAND="/usr/bin/env awk"
-;;
-* )
-DF_COMMAND="/bin/df -k"
-SORT_COMMAND="/usr/bin/sort -k6"
-AWK_COMMAND="/usr/bin/env gawk"
-;;
-esac
-
-# Add additional df options
-DF_COMMAND+=$DF_OPTIONS
-
-# -------------------------------------------------------------------------
-# Grabbing "df" result
-# -------------------------------------------------------------------------
-DF_RESULT=`$DF_COMMAND`
-if [ ! -z $DEBUG ]; then
-echo "--> DF_RESULT:"
-echo "$DF_RESULT"
-echo ""
-fi
-
-# -------------------------------------------------------------------------
-# Preprocessing "df" result, to join split logical lines
-# -------------------------------------------------------------------------
-PREPROCESSING_RESULT=` \
- echo "$DF_RESULT" | $AWK_COMMAND -v PATTERN=$PATTERN \
- '
- NF == 1 {
- printf ("%s", $0)
- }
-
-NF == 5 {
- printf ("%s\n", $0)
-}
-
-NF > 6 {
-}
-
-NF == 6 {
- printf ("%s\n", $0)
-}'
-`
-if [ ! -z $DEBUG ]; then
-echo "--> PREPROCESSING_RESULT:"
-echo "$PREPROCESSING_RESULT"
-echo ""
-fi
-
-SORTED_FILE_SYSTEMS_INFO=`echo "$PREPROCESSING_RESULT" | $SORT_COMMAND`
-
-if [ ! -z $DEBUG ]; then
-echo "--> SORTED_FILE_SYSTEMS_INFO:"
-echo "$SORTED_FILE_SYSTEMS_INFO"
-echo ""
-fi
-
-# -------------------------------------------------------------------------
-# Computing mount point max length
-# -------------------------------------------------------------------------
-MOUNT_POINT_MAX_LENGTH=` \
- echo "$SORTED_FILE_SYSTEMS_INFO" | $AWK_COMMAND -v PATTERN=$PATTERN \
- '
- BEGIN {
- mount_point_length_max = 15;
- }
-
-END {
- printf ("%d", mount_point_length_max);
-}
-
-$0 ~ PATTERN {
-# printf ("$6 = %s\n", $6);
-
- mount_point = $6;
-# printf ("mount_point = %s\n", mount_point);
-
- mount_point_length = length (mount_point);
-# printf ("mount_point_length = %d\n", mount_point_length);
-
- if (mount_point_length > mount_point_length_max)
- mount_point_length_max = mount_point_length;
-}'
-`
-if [ ! -z $DEBUG ]; then
-echo "MOUNT_POINT_MAX_LENGTH: $MOUNT_POINT_MAX_LENGTH"
-fi
-
-# -------------------------------------------------------------------------
-# Computing mount point data max size
-# -------------------------------------------------------------------------
-MOUNT_POINT_MAX_SIZE=` \
- echo "$SORTED_FILE_SYSTEMS_INFO" | $AWK_COMMAND -v PATTERN=$PATTERN \
- '
- BEGIN {
- mount_point_size_max = 0;
- }
-
-END {
- printf ("%d", mount_point_size_max);
-}
-
-$0 ~ PATTERN {
-# df -k shows k_bytes!
-# printf ("$2 = %s\n", $2);
-
- mount_point_size = $2 * 1024;
-# printf ("mount_point_size = %d\n", mount_point_size);
-
- if (mount_point_size > mount_point_size_max)
- mount_point_size_max = mount_point_size;
-}'
-`
-if [ ! -z $DEBUG ]; then
-echo "MOUNT_POINT_MAX_SIZE: $MOUNT_POINT_MAX_SIZE"
-fi
-
-# -------------------------------------------------------------------------
-# Let's go!
-# -------------------------------------------------------------------------
-echo "$SORTED_FILE_SYSTEMS_INFO" | $AWK_COMMAND -v DEBUG=$DEBUG -v PATTERN=$PATTERN -v NARROW_MODE=$NARROW_MODE -v LEFT_COLUMN=$MOUNT_POINT_MAX_LENGTH -v MAX_SIZE=$MOUNT_POINT_MAX_SIZE -v SCALE=$SCALE -v WEB_OUTPUT=$WEB_OUTPUT \
- '
-# {printf ("$0 = %s\n", $0);}
-# {printf ("$1 = %s\n", $1);}
-# {printf ("PATTERN = %s\n", PATTERN);}
-# {printf ("LEFT_COLUMN = %s\n", LEFT_COLUMN);}
-
- BEGIN {
- k_bytes = 1024.0;
- m_bytes = 1024.0 * k_bytes;
- g_bytes = 1024.0 * m_bytes;
- t_bytes = 1024.0 * g_bytes;
-
- if (WEB_OUTPUT)
- {
- all_stars = "**************************************************";
- current_date = strftime ("%d-%m-%Y @ %H:%M:%S", localtime (systime ()));
- free_threshold = 10; # %
-
- printf ("<!-- DEBUT CONTENU -->\n");
-
- printf ( \
- "<A NAME=\"top\"></A>\n" \
- "<P ALIGN=CENTER><SPAN CLASS=\"titleblue\">%s</SPAN><SPAN CLASS=\"textbold\"> -- STATUS OF <SPAN CLASS=\"titlered\">ALCOR</SPAN> FILE SYSTEMS</SPAN></P><BR>\n",
- current_date )
-
- printf ("<TABLE WIDTH=\"100%%\" BORDER=1>\n");
-
- printf ( \
- "<TR>\n" \
- "<TD ALIGN=LEFT><STRONG>Mount point</STRONG></TD>\n" \
- "<TD ALIGN=CENTER><STRONG>%% Usato (<SPAN CLASS=\"titleblue\">*</SPAN>)" \
- " - %% Free (<SPAN CLASS=\"titlegreen\">*</SPAN>)</STRONG></TD>\n" \
- "<TD ALIGN=CENTER><STRONG>%% Used</STRONG></TD>\n" \
- "<TD ALIGN=CENTER><STRONG>Free</STRONG></TD>\n" \
- "<TD ALIGN=CENTER><STRONG>Total</STRONG></TD>\n" \
- "</TR>\n" );
- }
- else
- {
- narrow_margin = " ";
-# printf ("%-*s", LEFT_COLUMN + 2, "Mount point");
- if (NARROW_MODE)
- printf ("\n%s", narrow_margin);
- else
- printf ("%-*s", LEFT_COLUMN + 2, "");
- print " Used Free Total ";
- if (! NARROW_MODE)
- print " ";
- }
- }
-
-END {
- if (WEB_OUTPUT)
- {
- printf ("</TABLE>\n");
-
- printf ("<!-- FIN CONTENU -->\n");
- }
- else
- {
- if (NARROW_MODE)
- printf ("%s", narrow_margin);
- else
- printf ("%-*s", LEFT_COLUMN + 2, "");
- print "|----|----|----|----|----|----|----|----|----|----|"
- if (NARROW_MODE)
- printf ("\n%s", narrow_margin);
- else
- printf ("%-*s", LEFT_COLUMN + 2, "");
- print "0 10 20 30 40 50 60 70 80 90 100";
- print "";
- }
-}
-
-$0 ~ PATTERN {
-
- if (index ($0, "members") == 0 && index ($0, "Download") == 0 && index ($0, "admin") == 0)
- {
-# df -k shows k_bytes!
-
- total_size = $2 * k_bytes;
- free_size = $4 * k_bytes;
- percentage_occupied = substr($5, 0, 3);
- mount_point = $6;
-
- percentage_free = int (100 - percentage_occupied);
-
-# reduction_factor: 2
- stars_number = int (percentage_occupied / 2);
-
- if (WEB_OUTPUT)
- {
- posGroup = index (mount_point, "scratch");
- if (posGroup == 0)
- posGroup = index (mount_point, "u1");
- if (posGroup == 0)
- posGroup = index (mount_point, "u2");
- if (posGroup == 0)
- posGroup = index (mount_point, "u4");
- if (posGroup == 0)
- posGroup = index (mount_point, "u5");
-
- printf ("<TR>\n");
-
- if (posGroup > 0 || percentage_free < free_threshold)
- {
- if (percentage_free < free_threshold)
- {
- class = "titlered";
- if (posGroup == 0)
- posGroup = 1; # to display the whole mount_point in this color anyway
- }
- else if ((index (mount_point, "scratch") != 0) || (index (mount_point, "u1") != 0) || (index (mount_point, "u2") != 0))
- {
- class = "titleorange";
- posGroup = 1; # to display the whole mount_point in this color
- }
- else if ((index (mount_point, "u4") != 0) || (index (mount_point, "u5") != 0))
- {
- class = "titlebrown";
- posGroup = 1; # to display the whole mount_point in this color
- }
-
- printf ( \
- "<TD ALIGN=LEFT>%s<SPAN CLASS=\"%s\">%s</SPAN></TD>\n",
- substr (mount_point, 1, posGroup - 1),
- class,
- substr (mount_point, posGroup) );
- }
- else
- {
- printf ("<TD ALIGN=LEFT>%s</TD>\n", mount_point);
- }
-
- printf ( \
- "<TD ALIGN=CENTER><SPAN CLASS=\"titleblue\">%s</SPAN><SPAN CLASS=\"titlegreen\">%s</SPAN></TD>\n",
- substr (all_stars, 1, stars_number), substr (all_stars, stars_number + 1, 49) );
-
- if (percentage_free < free_threshold)
- {
- color_beginning = "<SPAN CLASS=\"titlered\">";
- color_end = "</SPAN>"
- }
- else
- {
- color_beginning = "";
- color_end = ""
- }
-
- if (total_size > 1 * t_bytes)
- printf ( \
- "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Tb</TD><TD ALIGN=RIGHT>%5.1f Tb</TD>\n", \
- color_beginning, percentage_occupied, color_end, free_size / t_bytes, total_size / t_bytes \
- );
- else if (total_size > 1 * g_bytes)
- printf ( \
- "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Gb</TD><TD ALIGN=RIGHT>%5.1f Gb</TD>\n", \
- color_beginning, percentage_occupied, color_end, free_size / g_bytes, total_size / g_bytes \
- );
- else if (total_size > 1 * m_byptes)
- printf ( \
- "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Mb</TD><TD ALIGN=RIGHT>%5.1f Mb</TD>\n", \
- color_beginning, percentage_occupied, color_end, free_size / m_bytes, total_size / m_bytes \
- );
- else
- printf ( \
- "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Kb</TD><TD ALIGN=RIGHT>%5.1f Kb</TD>\n", \
- color_beginning, percentage_occupied, color_end, free_size / k_bytes, total_size / k_bytes \
- );
-
- printf ("</TR>\n");
- }
-
- else
- {
-# printf ("percentage_occupied = %d\n", percentage_occupied);
-# printf ("percentage_free = %d\n", percentage_free);
-
- printf ("%-*s", LEFT_COLUMN + 2, mount_point);
- if (NARROW_MODE)
- printf ("\n%s", narrow_margin);
-
-# printf ("stars_number = %d\n", stars_number);
-
- printf ("|");
- for (i = 1; i <= stars_number && i <= 49; i++)
- {
- printf ("%s", "*");
- }
- for (i = stars_number + 1; i <= 49; i++)
- {
- printf ("%s", "-");
- }
-
-
- if (total_size > 1 * t_bytes)
- printf ( \
- "| %3d%% %6.1f %6.1f Tb\n", \
- percentage_occupied, free_size / t_bytes, total_size / t_bytes \
- );
- else if (total_size > 1 * g_bytes)
- printf ( \
- "| %3d%% %6.1f %6.1f Gb\n", \
- percentage_occupied, free_size / g_bytes, total_size / g_bytes \
- );
- else if (total_size > 1 * m_byptes)
- printf ( \
- "| %3d%% %6.1f %6.1f Mb\n", \
- percentage_occupied, free_size / m_bytes, total_size / m_bytes \
- );
- else
- printf ( \
- "| %3d%% %6.1f %6.1f Kb\n", \
- percentage_occupied, free_size / k_bytes, total_size / k_bytes \
- );
- }
- } # if
-}'
Utilities section
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2010-2012, Peter Hofmann
--]]
--[[
Licensed under MIT License
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2009, Uli Schlachter
* (c) 2009, Majic
--[[
Licensed under GNU General Public License v2
- * (c) 2016, Luke Bonham
+ * (c) 2016, Luca CPZ
* (c) 2015, unknown
--]]
--[[
Licensed under GNU General Public License v2
- * (c) 2015, Luke Bonham
+ * (c) 2015, Luca CPZ
* (c) 2015, plotnikovanton
--]]
--[[
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2010, Adrian C. <anrxc@sysphere.org>
--]]
--[[
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2013, Rman
--]]
preset.title = preset.title .. " Muted"
end
- int = math.modf((alsabar._current_level / 100) * awful.screen.focused().mywibox.height)
+ local wib = awful.screen.focused().mywibox
+
+ local tot = wib.height
+ if wib.position == "left" or wib.position == "right" then
+ tot = wib.width
+ end
+
+ int = math.modf((alsabar._current_level / 100) * tot)
preset.text = string.format("[%s%s]", string.rep("|", int),
- string.rep(" ", awful.screen.focused().mywibox.height - int))
+ string.rep(" ", tot - int))
if alsabar.followtag then preset.screen = awful.screen.focused() end
--[[
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2010-2012, Peter Hofmann
--]]
bg = "#CDCDCD"
}
+ bat_notification_charged_preset = {
+ title = "Battery full",
+ text = "You can unplug the cable",
+ timeout = 15,
+ fg = "#202020",
+ bg = "#CDCDCD"
+ }
+
bat_now = {
status = "N/A",
ac_status = "N/A",
bat_now.n_perc[i] = 0
end
+ -- used to notify full charge only once before discharging
+ local fullnotification = false
+
function bat.update()
local sum_rate_current = 0
local sum_rate_voltage = 0
widget = bat.widget
settings()
- -- notifications for critical and low levels
- if notify == "on" and bat_now.status == "Discharging" then
- if tonumber(bat_now.perc) <= n_perc[1] then
- bat.id = naughty.notify({
- preset = bat_notification_critical_preset,
- replaces_id = bat.id
- }).id
- elseif tonumber(bat_now.perc) <= n_perc[2] then
+ -- notifications for critical, low, and full levels
+ if notify == "on" then
+ if bat_now.status == "Discharging" then
+ if tonumber(bat_now.perc) <= n_perc[1] then
+ bat.id = naughty.notify({
+ preset = bat_notification_critical_preset,
+ replaces_id = bat.id
+ }).id
+ elseif tonumber(bat_now.perc) <= n_perc[2] then
+ bat.id = naughty.notify({
+ preset = bat_notification_low_preset,
+ replaces_id = bat.id
+ }).id
+ end
+ fullnotification = false
+ elseif bat_now.status == "Full" and not fullnotification then
bat.id = naughty.notify({
- preset = bat_notification_low_preset,
+ preset = bat_notification_charged_preset,
replaces_id = bat.id
}).id
+ fullnotification = true
end
end
end
--[[
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
--]]
Users contributed widgets section
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
--]]
Licensed under GNU General Public License v2
* (c) 2013, Conor Heine
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2010-2012, Peter Hofmann
--]]
--[[
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2010-2012, Peter Hofmann
--]]
--[[
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2018, Uli Schlacter
+ * (c) 2018, Otto Modinos
+ * (c) 2013, Luca CPZ
--]]
-local helpers = require("lain.helpers")
-local shell = require("awful.util").shell
-local focused = require("awful.screen").focused
-local wibox = require("wibox")
-local naughty = require("naughty")
-local string = string
-local tonumber = tonumber
-
--- File system disk space usage
+local helpers = require("lain.helpers")
+local Gio = require("lgi").Gio
+local focused = require("awful.screen").focused
+local wibox = require("wibox")
+local naughty = require("naughty")
+local math = math
+local sformat = string.format
+local tconcat = table.concat
+local tonumber = tonumber
+local query_size = Gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE
+local query_free = Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE
+local query_used = Gio.FILE_ATTRIBUTE_FILESYSTEM_USED
+local query = query_size .. "," .. query_free .. "," .. query_used
+
+-- File systems info
-- lain.widget.fs
local function factory(args)
- local fs = { unit = { ["mb"] = 1024, ["gb"] = 1024^2 }, widget = wibox.widget.textbox() }
+ local fs = {
+ widget = wibox.widget.textbox(),
+ units = {
+ [1] = "Kb", [2] = "Mb", [3] = "Gb",
+ [4] = "Tb", [5] = "Pb", [6] = "Eb",
+ [7] = "Zb", [8] = "Yb"
+ }
+ }
function fs.hide()
if not fs.notification then return end
end
function fs.show(seconds, scr)
- fs.update()
- fs.hide()
-
- if fs.followtag then
- fs.notification_preset.screen = focused()
- else
- fs.notification_preset.screen = scr or 1
- end
-
- fs.notification = naughty.notify({
+ fs.hide(); fs.update()
+ fs.notification_preset.screen = fs.followtag and focused() or scr or 1
+ fs.notification = naughty.notify {
preset = fs.notification_preset,
timeout = seconds or 5
- })
+ }
end
- local args = args or {}
- local timeout = args.timeout or 600
- local partition = args.partition or "/"
- local showpopup = args.showpopup or "on"
- local notify = args.notify or "on"
- local settings = args.settings or function() end
+ local args = args or {}
+ local timeout = args.timeout or 600
+ local partition = args.partition
+ local showpopup = args.showpopup or "on"
+ local settings = args.settings or function() end
- fs.options = args.options
fs.followtag = args.followtag or false
fs.notification_preset = args.notification_preset
}
end
- helpers.set_map(partition, false)
-
function fs.update()
- fs_info, fs_now = {}, {}
- helpers.async({ shell, "-c", "/usr/bin/env LC_ALL=C df -k --output=target,size,used,avail,pcent" }, function(f)
- for line in string.gmatch(f, "\n[^\n]+") do
- local m,s,u,a,p = string.match(line, "(/.-%s).-(%d+).-(%d+).-(%d+).-([%d]+)%%")
- m = m:gsub(" ", "") -- clean target from any whitespace
-
- fs_info[m .. " size_mb"] = string.format("%.1f", tonumber(s) / fs.unit["mb"])
- fs_info[m .. " size_gb"] = string.format("%.1f", tonumber(s) / fs.unit["gb"])
- fs_info[m .. " used_mb"] = string.format("%.1f", tonumber(u) / fs.unit["mb"])
- fs_info[m .. " used_gb"] = string.format("%.1f", tonumber(u) / fs.unit["gb"])
- fs_info[m .. " used_p"] = p
- fs_info[m .. " avail_mb"] = string.format("%.1f", tonumber(a) / fs.unit["mb"])
- fs_info[m .. " avail_gb"] = string.format("%.1f", tonumber(a) / fs.unit["gb"])
- fs_info[m .. " avail_p"] = string.format("%d", 100 - tonumber(p))
+ local notifytable = { [1] = sformat("%-10s %-5s %s\t%s\t\n", "fs", "used", "free", "size") }
+ fs_now = {}
+
+ for _, mount in ipairs(Gio.unix_mounts_get()) do
+ local path = Gio.unix_mount_get_mount_path(mount)
+ local root = Gio.File.new_for_path(path)
+ local info = root:query_filesystem_info(query)
+ local size = info:get_attribute_uint64(query_size)
+ local used = info:get_attribute_uint64(query_used)
+ local free = info:get_attribute_uint64(query_free)
+
+ if size > 0 then
+ local units = math.floor(math.log(size)/math.log(1024))
+
+ fs_now[path] = {
+ units = fs.units[units],
+ percentage = math.floor(100 * used / size), -- used percentage
+ size = size / math.pow(1024, math.floor(units)),
+ used = used / math.pow(1024, math.floor(units)),
+ free = free / math.pow(1024, math.floor(units))
+ }
+
+ -- don't notify unused file systems
+ if fs_now[path].percentage > 0 then
+ notifytable[#notifytable+1] = sformat("\n%-10s %-5s %3.2f\t%3.2f\t%s", path,
+ fs_now[path].percentage .. "%", fs_now[path].free, fs_now[path].size,
+ fs_now[path].units)
+ end
end
+ end
- fs_now.size_mb = fs_info[partition .. " size_mb"] or "N/A"
- fs_now.size_gb = fs_info[partition .. " size_gb"] or "N/A"
- fs_now.used = fs_info[partition .. " used_p"] or "N/A"
- fs_now.used_mb = fs_info[partition .. " used_mb"] or "N/A"
- fs_now.used_gb = fs_info[partition .. " used_gb"] or "N/A"
- fs_now.available = fs_info[partition .. " avail_p"] or "N/A"
- fs_now.available_mb = fs_info[partition .. " avail_mb"] or "N/A"
- fs_now.available_gb = fs_info[partition .. " avail_gb"] or "N/A"
-
- notification_preset = fs.notification_preset
- widget = fs.widget
- settings()
-
- if notify == "on" and tonumber(fs_now.used) and tonumber(fs_now.used) >= 99 and not helpers.get_map(partition) then
- naughty.notify({
+ widget = fs.widget
+ settings()
+
+ if partition and fs_now[partition] and fs_now[partition].used >= 99 then
+ if not helpers.get_map(partition) then
+ naughty.notify {
preset = naughty.config.presets.critical,
title = "Warning",
text = partition .. " is full",
- })
+ }
helpers.set_map(partition, true)
else
helpers.set_map(partition, false)
end
- end)
+ end
- local notifycmd = (fs.options and string.format("dfs %s", fs.options)) or "dfs"
- helpers.async(helpers.scripts_dir .. notifycmd, function(ws)
- fs.notification_preset.text = ws:gsub("\n*$", "")
- end)
+ fs.notification_preset.text = tconcat(notifytable)
end
if showpopup == "on" then
fs.widget:connect_signal('mouse::leave', function () fs.hide() end)
end
- helpers.newtimer(partition, timeout, fs.update)
+ helpers.newtimer(partition or "fs", timeout, fs.update)
return fs
end
--[[
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
--]]
Widgets section
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2010-2012, Peter Hofmann
--]]
--[[
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2010-2012, Peter Hofmann
--]]
--[[
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2010, Adrian C. <anrxc@sysphere.org>
--]]
--[[
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2010-2012, Peter Hofmann
--]]
-- lain.widget.net
local function factory(args)
- local net = { widget = wibox.widget.textbox(), devices = {} }
- local args = args or {}
- local timeout = args.timeout or 2
- local units = args.units or 1024 -- KB
- local notify = args.notify or "on"
- local screen = args.screen or 1
- local settings = args.settings or function() end
+ local net = { widget = wibox.widget.textbox(), devices = {} }
+ local args = args or {}
+ local timeout = args.timeout or 2
+ local units = args.units or 1024 -- KB
+ local notify = args.notify or "on"
+ local wifi_state = args.wifi_state or "off"
+ local eth_state = args.eth_state or "off"
+ local screen = args.screen or 1
+ local settings = args.settings or function() end
-- Compatibility with old API where iface was a string corresponding to 1 interface
net.iface = (args.iface and (type(args.iface) == "string" and {args.iface}) or
(type(args.iface) == "table" and args.iface)) or {}
function net.get_device()
- helpers.async(string.format("ip link show", device_cmd), function(ws)
- ws = ws:match("(%w+): <BROADCAST,MULTICAST,.-UP,LOWER_UP>")
- net.iface = ws and { ws } or {}
+ helpers.line_callback("ip link", function(line)
+ net.iface[#net.iface + 1] = not string.match(line, "LOOPBACK") and string.match(line, "(%w+): <") or nil
end)
end
received = 0
}
- for i, dev in ipairs(net.iface) do
+ for _, dev in ipairs(net.iface) do
local dev_now = {}
local dev_before = net.devices[dev] or { last_t = 0, last_r = 0 }
local now_t = tonumber(helpers.first_line(string.format("/sys/class/net/%s/statistics/tx_bytes", dev)) or 0)
dev_now.last_t = now_t
dev_now.last_r = now_r
+ if wifi_state == "on" and helpers.first_line(string.format("/sys/class/net/%s/uevent", dev)) == "DEVTYPE=wlan" and string.match(dev_now.carrier, "1") then
+ dev_now.wifi = true
+ dev_now.signal = tonumber(string.match(helpers.lines_from("/proc/net/wireless")[3], "(%-%d+%.)")) or nil
+ end
+
+ if eth_state == "on" and helpers.first_line(string.format("/sys/class/net/%s/uevent", dev)) ~= "DEVTYPE=wlan" and string.match(dev_now.carrier, "1") then
+ dev_now.ethernet = true
+ end
+
net.devices[dev] = dev_now
- -- Notify only once when connection is loss
+ -- Notify only once when connection is lost
if string.match(dev_now.carrier, "0") and notify == "on" and helpers.get_map(dev) then
naughty.notify {
title = dev,
net_now.carrier = dev_now.carrier
net_now.state = dev_now.state
net_now.devices[dev] = dev_now
- -- new_now.sent and net_now.received will be
+ -- net_now.sent and net_now.received will be
-- the totals across all specified devices
end
--[[
Licensed under GNU General Public License v2
- * (c) 2016, Luke Bonham
+ * (c) 2016, Luca CPZ
--]]
--[[
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2013, Rman
--]]
preset.title = preset.title .. " muted"
end
- int = math.modf((pulsebar._current_level / 100) * awful.screen.focused().mywibox.height)
+ local wib = awful.screen.focused().mywibox
+
+ local tot = wib.height
+ if wib.position == "left" or wib.position == "right" then
+ tot = wib.width
+ end
+
+ int = math.modf((pulsebar._current_level / 100) * tot)
preset.text = string.format("[%s%s]", string.rep("|", int),
- string.rep(" ", awful.screen.focused().mywibox.height - int))
+ string.rep(" ", tot - int))
if pulsebar.followtag then preset.screen = awful.screen.focused() end
--[[
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
* (c) 2010-2012, Peter Hofmann
--]]
--[[
Licensed under GNU General Public License v2
- * (c) 2013, Luke Bonham
+ * (c) 2013, Luca CPZ
--]]
--[[
Licensed under GNU General Public License v2
- * (c) 2015, Luke Bonham
+ * (c) 2015, Luca CPZ
--]]
local function factory(args)
local weather = { widget = wibox.widget.textbox() }
local args = args or {}
- local APPID = args.APPID or "3e321f9414eaedbfab34983bda77a66e" -- lain default
+ local APPID = args.APPID or "3e321f9414eaedbfab34983bda77a66e" -- lain's default
local timeout = args.timeout or 60 * 15 -- 15 min
local timeout_forecast = args.timeout or 60 * 60 * 24 -- 24 hrs
local current_call = args.current_call or "curl -s 'http://api.openweathermap.org/data/2.5/weather?id=%s&units=%s&lang=%s&APPID=%s'"
local sunrise = tonumber(weather_now["sys"]["sunrise"])
local sunset = tonumber(weather_now["sys"]["sunset"])
local icon = weather_now["weather"][1]["icon"]
- local loc_now = os.time()
- local loc_m = os.time { year = os.date("%Y"), month = os.date("%m"), day = os.date("%d"), hour = 0 }
- local loc_t = os.difftime(loc_now, loc_m)
- local loc_d = os.date("*t", loc_now)
- local utc_d = os.date("!*t", loc_now)
- local utc_now = os.time(utc_d)
- local offdt = (loc_d.isdst and 1 or 0) * 3600 + 100 * (loc_d.min - utc_d.min) / 60
- local offset = os.difftime(loc_now, utc_now) + offdt
- local offday = (offset < 0 and -86400) or 86400
-
- if math.abs(loc_now - utc_now - offdt + loc_t) >= 86400 then
- utc_now = utc_now + offday
- end
-
- if offday * (loc_now - utc_now - offdt) > 0 then
- sunrise = sunrise + offday
+ local loc_now = os.time() -- local time
+ local loc_m = os.time { year = os.date("%Y"), month = os.date("%m"), day = os.date("%d"), hour = 0 } -- local time from midnight
+ local loc_d = os.date("*t", loc_now) -- table YMDHMS for current local time (for TZ calculation)
+ local utc_d = os.date("!*t", loc_now) -- table YMDHMS for current UTC time
+ local utc_now = os.time(utc_d) -- UTC time now
+ local offdt = (loc_d.isdst and 1 or 0) * 3600 + 100 * (loc_d.min - utc_d.min) / 60 -- DST offset
+ local offset = os.difftime(loc_now, utc_now) + (loc_d.isdst and 1 or 0) * 3600 + 100 * (loc_d.min - utc_d.min) / 60 -- TZ offset (including DST)
+ local offday = (offset < 0 and -86400) or 86400 -- 24 hour correction value (+86400 or -86400)
+
+ -- if current UTC time is earlier then local midnight -> positive offset (negative otherwise)
+ if offset * (loc_m - utc_now + offdt) > 0 then
+ sunrise = sunrise + offday -- Shift sunset and sunrise times by 24 hours
sunset = sunset + offday
end
-Subproject commit f395683e491fabd539fa0b5d596dbb5cc451e68e
+Subproject commit e8860c7593f86584b45ada7d5232f32915ba20a6