From: Luca CPZ <1777696+lcpz@users.noreply.github.com> Date: Sat, 17 Feb 2018 11:19:53 +0000 (+0100) Subject: Merge pull request #377 from sim590/menu-iterator X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/af3427c7dfcf991c56a099ac1450e54db867ae51?hp=1d2f4a102ed4fe4c536a76d03b91c19001f48ec6 Merge pull request #377 from sim590/menu-iterator menu_iterator: naughty.notify based menu utility --- diff --git a/helpers.lua b/helpers.lua index ce65576..313579f 100644 --- a/helpers.lua +++ b/helpers.lua @@ -1,11 +1,11 @@ --[[ 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, @@ -112,7 +112,7 @@ end function helpers.async(cmd, callback) return spawn.easy_async(cmd, function (stdout, stderr, reason, exit_code) - callback(stdout) + callback(stdout, exit_code) end) end @@ -120,10 +120,19 @@ 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 diff --git a/init.lua b/init.lua index 46c7659..b59d5dd 100644 --- a/init.lua +++ b/init.lua @@ -4,7 +4,7 @@ Layouts, widgets and utilities for Awesome WM Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ --]] diff --git a/layout/cascade.lua b/layout/cascade.lua index f7dffb9..cbc3877 100644 --- a/layout/cascade.lua +++ b/layout/cascade.lua @@ -2,7 +2,7 @@ Licensed under GNU General Public License v2 * (c) 2014, projektile - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ * (c) 2010-2012, Peter Hofmann --]] diff --git a/layout/centerwork.lua b/layout/centerwork.lua index aff2771..cb83709 100644 --- a/layout/centerwork.lua +++ b/layout/centerwork.lua @@ -4,30 +4,28 @@ * (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) @@ -42,7 +40,7 @@ local function do_centerwork(p, orientation) 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 @@ -51,7 +49,7 @@ local function do_centerwork(p, orientation) 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 @@ -62,92 +60,76 @@ local function do_centerwork(p, orientation) 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 diff --git a/layout/init.lua b/layout/init.lua index b311f45..6478b06 100644 --- a/layout/init.lua +++ b/layout/init.lua @@ -6,7 +6,7 @@ Layouts section Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ * (c) 2010-2012, Peter Hofmann --]] diff --git a/layout/termfair.lua b/layout/termfair.lua index 60b3c7d..f57f715 100644 --- a/layout/termfair.lua +++ b/layout/termfair.lua @@ -2,7 +2,7 @@ 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 diff --git a/scripts/dfs b/scripts/dfs deleted file mode 100755 index 9e02a87..0000000 --- a/scripts/dfs +++ /dev/null @@ -1,397 +0,0 @@ -#!/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= | --exclude-type=]" - -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 ("\n"); - - printf ( \ - "\n" \ - "

%s -- STATUS OF ALCOR FILE SYSTEMS


\n", - current_date ) - - printf ("\n"); - - printf ( \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\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 ("
Mount point%% Usato (*)" \ - " - %% Free (*)%% UsedFreeTotal
\n"); - - printf ("\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 ("\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 ( \ - "%s%s\n", - substr (mount_point, 1, posGroup - 1), - class, - substr (mount_point, posGroup) ); - } - else - { - printf ("%s\n", mount_point); - } - - printf ( \ - "%s%s\n", - substr (all_stars, 1, stars_number), substr (all_stars, stars_number + 1, 49) ); - - if (percentage_free < free_threshold) - { - color_beginning = ""; - color_end = "" - } - else - { - color_beginning = ""; - color_end = "" - } - - if (total_size > 1 * t_bytes) - printf ( \ - "%s%3d%%%s%5.1f Tb%5.1f Tb\n", \ - color_beginning, percentage_occupied, color_end, free_size / t_bytes, total_size / t_bytes \ - ); - else if (total_size > 1 * g_bytes) - printf ( \ - "%s%3d%%%s%5.1f Gb%5.1f Gb\n", \ - color_beginning, percentage_occupied, color_end, free_size / g_bytes, total_size / g_bytes \ - ); - else if (total_size > 1 * m_byptes) - printf ( \ - "%s%3d%%%s%5.1f Mb%5.1f Mb\n", \ - color_beginning, percentage_occupied, color_end, free_size / m_bytes, total_size / m_bytes \ - ); - else - printf ( \ - "%s%3d%%%s%5.1f Kb%5.1f Kb\n", \ - color_beginning, percentage_occupied, color_end, free_size / k_bytes, total_size / k_bytes \ - ); - - printf ("\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 -}' diff --git a/util/init.lua b/util/init.lua index 8e7b8ef..8b8e719 100644 --- a/util/init.lua +++ b/util/init.lua @@ -6,7 +6,7 @@ Utilities section Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ * (c) 2010-2012, Peter Hofmann --]] diff --git a/util/markup.lua b/util/markup.lua index 0eb9bfa..9801331 100644 --- a/util/markup.lua +++ b/util/markup.lua @@ -1,7 +1,7 @@ --[[ Licensed under MIT License - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ * (c) 2009, Uli Schlachter * (c) 2009, Majic diff --git a/util/quake.lua b/util/quake.lua index 38b9917..6271fcd 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2016, Luke Bonham + * (c) 2016, Luca CPZ * (c) 2015, unknown --]] diff --git a/util/separators.lua b/util/separators.lua index c86af92..29d3005 100644 --- a/util/separators.lua +++ b/util/separators.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2015, Luke Bonham + * (c) 2015, Luca CPZ * (c) 2015, plotnikovanton --]] diff --git a/widget/alsa.lua b/widget/alsa.lua index 29e3a05..2d4891d 100644 --- a/widget/alsa.lua +++ b/widget/alsa.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ * (c) 2010, Adrian C. --]] diff --git a/widget/alsabar.lua b/widget/alsabar.lua index 750933a..b253d4b 100644 --- a/widget/alsabar.lua +++ b/widget/alsabar.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ * (c) 2013, Rman --]] @@ -113,9 +113,16 @@ local function factory(args) 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 diff --git a/widget/bat.lua b/widget/bat.lua index 8e04569..34d63e5 100644 --- a/widget/bat.lua +++ b/widget/bat.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ * (c) 2010-2012, Peter Hofmann --]] @@ -47,6 +47,14 @@ local function factory(args) 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", @@ -62,6 +70,9 @@ local function factory(args) 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 @@ -156,18 +167,27 @@ local function factory(args) 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 diff --git a/widget/calendar.lua b/widget/calendar.lua index 4f927b3..84b025d 100644 --- a/widget/calendar.lua +++ b/widget/calendar.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ --]] diff --git a/widget/contrib/init.lua b/widget/contrib/init.lua index ccc1046..9e863a5 100644 --- a/widget/contrib/init.lua +++ b/widget/contrib/init.lua @@ -6,7 +6,7 @@ Users contributed widgets section Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ --]] diff --git a/widget/contrib/tpbat/init.lua b/widget/contrib/tpbat/init.lua index d926e8e..e9675ef 100644 --- a/widget/contrib/tpbat/init.lua +++ b/widget/contrib/tpbat/init.lua @@ -8,7 +8,7 @@ Licensed under GNU General Public License v2 * (c) 2013, Conor Heine - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ * (c) 2010-2012, Peter Hofmann --]] diff --git a/widget/cpu.lua b/widget/cpu.lua index b6ecb9c..6c6e77a 100644 --- a/widget/cpu.lua +++ b/widget/cpu.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ * (c) 2010-2012, Peter Hofmann --]] diff --git a/widget/fs.lua b/widget/fs.lua index 09e2ef5..5e18491 100644 --- a/widget/fs.lua +++ b/widget/fs.lua @@ -1,23 +1,38 @@ --[[ 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 @@ -26,29 +41,20 @@ local function factory(args) 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 @@ -60,54 +66,55 @@ local function factory(args) } 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 @@ -115,7 +122,7 @@ local function factory(args) 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 diff --git a/widget/imap.lua b/widget/imap.lua index 17f37cf..7c13223 100644 --- a/widget/imap.lua +++ b/widget/imap.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ --]] diff --git a/widget/init.lua b/widget/init.lua index e3315d4..57b86bb 100644 --- a/widget/init.lua +++ b/widget/init.lua @@ -6,7 +6,7 @@ Widgets section Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ * (c) 2010-2012, Peter Hofmann --]] diff --git a/widget/mem.lua b/widget/mem.lua index fa2c364..3dcae2b 100644 --- a/widget/mem.lua +++ b/widget/mem.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ * (c) 2010-2012, Peter Hofmann --]] diff --git a/widget/mpd.lua b/widget/mpd.lua index 38c49dd..ff45179 100644 --- a/widget/mpd.lua +++ b/widget/mpd.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ * (c) 2010, Adrian C. --]] diff --git a/widget/net.lua b/widget/net.lua index a72fc3d..987f047 100644 --- a/widget/net.lua +++ b/widget/net.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ * (c) 2010-2012, Peter Hofmann --]] @@ -15,22 +15,23 @@ local string = { format = string.format, match = string.match } -- 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+): ") - 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 @@ -45,7 +46,7 @@ local function factory(args) 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) @@ -66,9 +67,18 @@ local function factory(args) 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, @@ -84,7 +94,7 @@ local function factory(args) 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 diff --git a/widget/pulse.lua b/widget/pulse.lua index aa9d58e..d37e83a 100644 --- a/widget/pulse.lua +++ b/widget/pulse.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2016, Luke Bonham + * (c) 2016, Luca CPZ --]] diff --git a/widget/pulsebar.lua b/widget/pulsebar.lua index 7a0a3d4..30fbb40 100644 --- a/widget/pulsebar.lua +++ b/widget/pulsebar.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ * (c) 2013, Rman --]] @@ -123,9 +123,16 @@ local function factory(args) 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 diff --git a/widget/sysload.lua b/widget/sysload.lua index 98c0ff7..adf3e03 100644 --- a/widget/sysload.lua +++ b/widget/sysload.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ * (c) 2010-2012, Peter Hofmann --]] diff --git a/widget/temp.lua b/widget/temp.lua index cc9f056..3c93252 100644 --- a/widget/temp.lua +++ b/widget/temp.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luca CPZ --]] diff --git a/widget/weather.lua b/widget/weather.lua index b75afc8..a9b886a 100644 --- a/widget/weather.lua +++ b/widget/weather.lua @@ -1,7 +1,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2015, Luke Bonham + * (c) 2015, Luca CPZ --]] @@ -20,7 +20,7 @@ local math, os, string, tonumber = math, os, string, tonumber 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'" @@ -114,22 +114,18 @@ local function factory(args) 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 diff --git a/wiki b/wiki index f395683..e8860c7 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit f395683e491fabd539fa0b5d596dbb5cc451e68e +Subproject commit e8860c7593f86584b45ada7d5232f32915ba20a6