From ea1e51b5f9ab1649d3abba6ae09cb29f4a1fb905 Mon Sep 17 00:00:00 2001 From: Terencio Agozzino Date: Sat, 10 Dec 2016 15:45:50 +0100 Subject: [PATCH 001/106] Fixed fs display --- widgets/fs.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/widgets/fs.lua b/widgets/fs.lua index 6038746..3c9d9c8 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -117,8 +117,8 @@ local function worker(args) end if showpopup == "on" then - fs.widget:connect_signal('mouse::enter', function () fs:show(0) end) - fs.widget:connect_signal('mouse::leave', function () fs:hide() end) + fs.widget:connect_signal('mouse::enter', function () fs.show(0) end) + fs.widget:connect_signal('mouse::leave', function () fs.hide() end) end helpers.newtimer(partition, timeout, update) From 1363e10b307f468da749aa1e08ab57b3f4e7b913 Mon Sep 17 00:00:00 2001 From: Chris Bruce Date: Sat, 10 Dec 2016 14:02:50 -0800 Subject: [PATCH 002/106] Add track and genre to mpd_now --- widgets/mpd.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/widgets/mpd.lua b/widgets/mpd.lua index 8568764..24cdcda 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -70,6 +70,8 @@ local function worker(args) artist = "N/A", title = "N/A", album = "N/A", + genre = "N/A", + track = "N/A", date = "N/A", time = "N/A", elapsed = "N/A" @@ -83,6 +85,8 @@ local function worker(args) elseif k == "Artist" then mpd_now.artist = escape_f(v) elseif k == "Title" then mpd_now.title = escape_f(v) elseif k == "Album" then mpd_now.album = escape_f(v) + elseif k == "Genre" then mpd_now.genre = escape_f(v) + elseif k == "Track" then mpd_now.track = escape_f(v) elseif k == "Date" then mpd_now.date = escape_f(v) elseif k == "Time" then mpd_now.time = v elseif k == "elapsed" then mpd_now.elapsed = string.match(v, "%d+") From 301faf5370d045e94c9c344acb0fdac84a2f25a6 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 12 Dec 2016 18:20:19 +0100 Subject: [PATCH 003/106] wiki updated --- widgets/fs.lua | 2 +- wiki | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/widgets/fs.lua b/widgets/fs.lua index 3c9d9c8..60b112c 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -44,7 +44,7 @@ function fs.show(seconds, options, scr) if fs.followmouse then fs.notification_preset.screen = mouse.screen elseif scr then - fs.notification_preset.screen = scr + fs.notification_preset.screen = scr end fs_notification = naughty.notify({ diff --git a/wiki b/wiki index d0df450..42fd0d6 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit d0df450d05655c5d8f724c42dc6b5d18b3676a60 +Subproject commit 42fd0d64ad66a66a062eb422fb5f26e63fd5de58 From cf2c44249973125a51c370311e7361d9c1e84771 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 3 Jan 2017 12:21:50 +0100 Subject: [PATCH 004/106] net/mpd widget resize fix; #248 --- helpers.lua | 16 +++++++++++++-- init.lua | 2 -- util/init.lua | 48 ++++++++++++++++++++++---------------------- util/quake.lua | 7 ++++--- widgets/alsabar.lua | 3 ++- widgets/mpd.lua | 6 ++---- widgets/net.lua | 9 +++++---- widgets/pulsebar.lua | 3 ++- wiki | 2 +- 9 files changed, 54 insertions(+), 42 deletions(-) diff --git a/helpers.lua b/helpers.lua index 6c0c3c4..6a47738 100644 --- a/helpers.lua +++ b/helpers.lua @@ -16,6 +16,8 @@ local io = { open = io.open, local rawget = rawget local table = { sort = table.sort } +local wibox = require("wibox") + -- Lain helper functions for internal use -- lain.helpers local helpers = {} @@ -140,7 +142,9 @@ end -- }}} ---{{{ Iterate over table of records sorted by keys +-- {{{ Misc + +-- iterate over table of records sorted by keys function helpers.spairs(t) -- collect the keys local keys = {} @@ -157,7 +161,15 @@ function helpers.spairs(t) end end end ---}}} +-- create a lain textbox widget +function helpers.make_widget_textbox() + local w = wibox.widget.textbox('') + local t = wibox.widget.base.make_widget(w) + t.widget = w + return t +end + +-- }}} return helpers diff --git a/init.lua b/init.lua index 5086435..155d6cc 100644 --- a/init.lua +++ b/init.lua @@ -9,8 +9,6 @@ --]] -package.loaded.lain = nil - local lain = { layout = require("lain.layout"), diff --git a/util/init.lua b/util/init.lua index 5fe8213..14a1e14 100644 --- a/util/init.lua +++ b/util/init.lua @@ -162,29 +162,30 @@ end -- {{{ Dynamic tagging -- -- Add a new tag -function util.add_tag(mypromptbox) - awful.prompt.run({prompt="New tag name: "}, mypromptbox[mouse.screen].widget, - function(text) - if text:len() > 0 then - props = { selected = true } - tag = awful.tag.add(new_name, props) - tag.name = text - tag:emit_signal("property::name") +function util.add_tag() + awful.prompt.run { + prompt = "New tag name: ", + textbox = awful.screen.focused().mypromptbox.widget, + exe_callback = function(name) + if not name or #name == 0 then return end + awful.tag.add(name, { screen = awful.screen.focused() }):view_only() end - end) + } end -- Rename current tag --- @author: minism -function util.rename_tag(mypromptbox) - local tag = awful.tag.selected(mouse.screen) - awful.prompt.run({prompt="Rename tag: "}, mypromptbox[mouse.screen].widget, - function(text) - if text:len() > 0 then - tag.name = text - tag:emit_signal("property::name") +function util.rename_tag() + awful.prompt.run { + prompt = "Rename tag: ", + textbox = awful.screen.focused().mypromptbox.widget, + exe_callback = function(new_name) + if not new_name or #new_name == 0 then return end + local t = awful.screen.focused().selected_tag + if t then + t.name = new_name + end end - end) + } end -- Move current tag @@ -199,14 +200,13 @@ function util.move_tag(pos) end end --- Remove current tag (if empty) +-- Delete current tag -- Any rule set on the tag shall be broken -function util.remove_tag() - local tag = awful.tag.selected(mouse.screen) - local prevtag = awful.tag.gettags(mouse.screen)[awful.tag.getidx(tag) - 1] - awful.tag.delete(tag, prevtag) +function util.delete_tag() + local t = awful.screen.focused().selected_tag + if not t then return end + t:delete() end --- -- }}} -- On the fly useless gaps change diff --git a/util/quake.lua b/util/quake.lua index 771741e..5a47c7d 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -11,6 +11,7 @@ local capi = { client = client, mouse = mouse, screen = screen, timer = timer } +local math = { floor = math.floor } local string = string local pairs = pairs @@ -61,7 +62,7 @@ function quake:display() -- Resize awful.client.floating.set(client, true) - client.border_width = self.border + --client.border_width = self.border client.size_hints_honor = false if self.notexist then client:geometry(self.geometry) @@ -113,8 +114,8 @@ function quake:new(config) -- Compute size local geom = capi.screen[conf.screen].workarea - if width <= 1 then width = geom.width * width end - if height <= 1 then height = geom.height * height end + if width <= 1 then width = math.floor(geom.width * width) end + if height <= 1 then height = math.floor(geom.height * height) end local x, y if horiz == "left" then x = geom.x elseif horiz == "right" then x = geom.width + geom.x - width diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index b20bc40..e5bc667 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -13,6 +13,7 @@ local read_pipe = require("lain.helpers").read_pipe local awful = require("awful") local beautiful = require("beautiful") local naughty = require("naughty") +local wibox = require("wibox") local math = { modf = math.modf } local mouse = mouse @@ -110,7 +111,7 @@ local function worker(args) alsabar.notifications = args.notifications or alsabar.notifications alsabar.followmouse = args.followmouse or false - alsabar.bar = awful.widget.progressbar() + alsabar.bar = wibox.widget.progressbar() alsabar.bar:set_background_color(alsabar.colors.background) alsabar.bar:set_color(alsabar.colors.unmute) diff --git a/widgets/mpd.lua b/widgets/mpd.lua index 24cdcda..c9b3de5 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -26,7 +26,7 @@ local setmetatable = setmetatable -- MPD infos -- lain.widgets.mpd -local mpd = {} +local mpd = helpers.make_widget_textbox() local function worker(args) local args = args or {} @@ -46,8 +46,6 @@ local function worker(args) local mpdh = "telnet://" .. host .. ":" .. port local echo = echo_cmd .. " 'password " .. password .. "\nstatus\ncurrentsong\nclose'" - mpd.widget = wibox.widget.textbox('') - mpd_notification_preset = { title = "Now playing", timeout = 6 @@ -139,7 +137,7 @@ local function worker(args) helpers.newtimer("mpd", timeout, mpd.update) - return setmetatable(mpd, { __index = mpd.widget }) + return mpd end return setmetatable(mpd, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/net.lua b/widgets/net.lua index 1883168..f0b3770 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -21,7 +21,10 @@ local setmetatable = setmetatable -- lain.widgets.net local function worker(args) - local net = { last_t = 0, last_r = 0, devices = {} } + local net = helpers.make_widget_textbox() + net.last_t = 0 + net.last_r = 0 + net.devices = {} function net.get_first_device() local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9") @@ -38,8 +41,6 @@ local function worker(args) local settings = args.settings or function() end local iface = args.iface or net.get_first_device() - net.widget = wibox.widget.textbox('') - -- Compatibility with old API where iface was a string corresponding to 1 interface if type(iface) == "string" then iftable = {iface} @@ -138,7 +139,7 @@ local function worker(args) helpers.newtimer(iface, timeout, update) - return setmetatable(net, { __index = net.widget }) + return net end return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/pulsebar.lua b/widgets/pulsebar.lua index 7f22642..9bac521 100644 --- a/widgets/pulsebar.lua +++ b/widgets/pulsebar.lua @@ -13,6 +13,7 @@ local read_pipe = require("lain.helpers").read_pipe local awful = require("awful") local beautiful = require("beautiful") local naughty = require("naughty") +local wibox = require("wibox") local math = { modf = math.modf } local mouse = mouse @@ -109,7 +110,7 @@ local function worker(args) pulsebar.step = args.step or pulsebar.step pulsebar.followmouse = args.followmouse or false - pulsebar.bar = awful.widget.progressbar() + pulsebar.bar = wibox.widget.progressbar() pulsebar.bar:set_background_color(pulsebar.colors.background) pulsebar.bar:set_color(pulsebar.colors.unmute) diff --git a/wiki b/wiki index 42fd0d6..f6270ed 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 42fd0d64ad66a66a062eb422fb5f26e63fd5de58 +Subproject commit f6270edc9e9d8ba83971fac3dbaca301c4792f34 From 64540340dbe9071bc716c73ca4c90df14fdd6302 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 3 Jan 2017 12:32:47 +0100 Subject: [PATCH 005/106] quake: uncomment client.border --- util/quake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/quake.lua b/util/quake.lua index 5a47c7d..e65f716 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -62,7 +62,7 @@ function quake:display() -- Resize awful.client.floating.set(client, true) - --client.border_width = self.border + client.border_width = self.border client.size_hints_honor = false if self.notexist then client:geometry(self.geometry) From 1bd178f68757099e6c9ccde1992ca5d519ccb8e5 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Thu, 5 Jan 2017 13:53:47 +0100 Subject: [PATCH 006/106] {alsa,pulse}bar updated to awesome 4.0 --- util/quake.lua | 2 +- widgets/alsabar.lua | 65 +++++++++++++++++++++++--------------------- widgets/pulsebar.lua | 44 ++++++++++++++++-------------- wiki | 2 +- 4 files changed, 59 insertions(+), 54 deletions(-) diff --git a/util/quake.lua b/util/quake.lua index e65f716..e54b664 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -10,7 +10,7 @@ local awful = require("awful") local capi = { client = client, mouse = mouse, screen = screen, - timer = timer } + timer = timer or require("gears.timer") } local math = { floor = math.floor } local string = string diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index e5bc667..093c461 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -37,7 +37,7 @@ local alsabar = { }, terminal = terminal or "xterm", - mixer = terminal .. " -e alsamixer", + mixer = string.format("%s -e alsamixer", terminal), notifications = { font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")), @@ -59,23 +59,21 @@ function alsabar.notify() text = "", timeout = 5, screen = alsabar.notifications.screen, - font = alsabar.notifications.font .. " " .. - alsabar.notifications.font_size, + font = string.format("%s %s", alsabar.notifications.font, + alsabar.notifications.font_size), fg = alsabar.notifications.color } if alsabar._muted then - preset.title = alsabar.channel .. " - Muted" + preset.title = string.format("%s - Muted", alsabar.channel) else - preset.title = alsabar.channel .. " - " .. alsabar._current_level .. "%" + preset.title = string.format("%s - %s%%", alsabar.channel, alsabar._current_level) end int = math.modf((alsabar._current_level / 100) * alsabar.notifications.bar_size) - preset.text = "[" - .. string.rep("|", int) - .. string.rep(" ", alsabar.notifications.bar_size - int) - .. "]" + preset.text = string.format("[%s%s]", string.rep("|", int), + string.rep(" ", alsabar.notifications.bar_size - int)) if alsabar.followmouse then preset.screen = mouse.screen @@ -94,14 +92,14 @@ function alsabar.notify() end local function worker(args) - local args = args or {} - local timeout = args.timeout or 5 - local settings = args.settings or function() end - local width = args.width or 63 - local height = args.heigth or 1 - local ticks = args.ticks or false - local ticks_size = args.ticks_size or 7 - local vertical = args.vertical or false + local args = args or {} + local timeout = args.timeout or 5 + local settings = args.settings or function() end + local width = args.width or 63 + local height = args.heigth or 1 + local ticks = args.ticks or false + local ticks_size = args.ticks_size or 7 + local vertical = args.vertical or false alsabar.cmd = args.cmd or "amixer" alsabar.channel = args.channel or alsabar.channel @@ -111,16 +109,20 @@ local function worker(args) alsabar.notifications = args.notifications or alsabar.notifications alsabar.followmouse = args.followmouse or false - alsabar.bar = wibox.widget.progressbar() + alsabar.bar = wibox.widget { + forced_height = height, + forced_width = width, + color = alsabar.colors.unmute, + background_color = alsabar.colors.background, + margins = 1, + paddings = 1, + ticks = ticks, + ticks_size = ticks_size, + widget = wibox.widget.progressbar, + layout = vertical and wibox.container.rotate + } - alsabar.bar:set_background_color(alsabar.colors.background) - alsabar.bar:set_color(alsabar.colors.unmute) alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } }) - alsabar.bar:set_width(width) - alsabar.bar:set_height(height) - alsabar.bar:set_ticks(ticks) - alsabar.bar:set_ticks_size(ticks_size) - alsabar.bar:set_vertical(vertical) function alsabar.update() -- Get mixer control contents @@ -138,20 +140,21 @@ local function worker(args) then alsabar._current_level = tonumber(volu) or alsabar._current_level alsabar.bar:set_value(alsabar._current_level / 100) - if not mute and tonumber(volu) == 0 or mute == "off" + if (not mute and tonumber(volu) == 0) or mute == "off" then alsabar._muted = true - alsabar.tooltip:set_text (" [Muted] ") - alsabar.bar:set_color(alsabar.colors.mute) + alsabar.tooltip:set_text ("[Muted]") + alsabar.bar.color = alsabar.colors.mute else alsabar._muted = false - alsabar.tooltip:set_text(string.format(" %s:%s ", alsabar.channel, volu)) - alsabar.bar:set_color(alsabar.colors.unmute) + alsabar.tooltip:set_text(string.format("%s: %s", alsabar.channel, volu)) + alsabar.bar.color = alsabar.colors.unmute end volume_now = {} volume_now.level = tonumber(volu) volume_now.status = mute + settings() end end @@ -165,7 +168,7 @@ local function worker(args) pulsebar.update() end), awful.button({}, 3, function() - awful.util.spawn(string.format("%s set %s toggle", alsabar.cmd, alsabar.channel)) + awful.util.spawn(string.format("%s set %s toggle", alsabar.cmd, alsabar.togglechannel or alsabar.channel)) alsabar.update() end), awful.button({}, 4, function() diff --git a/widgets/pulsebar.lua b/widgets/pulsebar.lua index 9bac521..c0787c9 100644 --- a/widgets/pulsebar.lua +++ b/widgets/pulsebar.lua @@ -58,23 +58,21 @@ function pulsebar.notify() text = "", timeout = 5, screen = pulsebar.notifications.screen, - font = pulsebar.notifications.font .. " " .. - pulsebar.notifications.font_size, + font = string.format("%s %s", alsabar.notifications.font, + alsabar.notifications.font_size), fg = pulsebar.notifications.color } if pulsebar._muted then - preset.title = "Sink " .. pulsebar.sink .. " - Muted" + preset.title = string.format("Sink %s - Muted", pulsebar.sink) else - preset.title = "Sink " .. pulsebar.sink .. " - " .. pulsebar._current_level .. "%" + preset.title = string.format("%s - %s%%", pulsebar.sink, pulsebar._current_level) end int = math.modf((pulsebar._current_level / 100) * pulsebar.notifications.bar_size) - preset.text = "[" - .. string.rep("|", int) - .. string.rep(" ", pulsebar.notifications.bar_size - int) - .. "]" + preset.text = string.format("[%s%s]", string.rep("|", int), + string.rep(" ", pulsebar.notifications.bar_size - int)) if pulsebar.followmouse then preset.screen = mouse.screen @@ -110,16 +108,20 @@ local function worker(args) pulsebar.step = args.step or pulsebar.step pulsebar.followmouse = args.followmouse or false - pulsebar.bar = wibox.widget.progressbar() + pulsebar.bar = wibox.widget { + forced_height = height, + forced_width = width, + color = pulsebar.colors.unmute, + background_color = pulsebar.colors.background, + margins = 1, + paddings = 1, + ticks = ticks, + ticks_size = ticks_size, + widget = wibox.widget.progressbar, + layout = vertical and wibox.container.rotate + } - pulsebar.bar:set_background_color(pulsebar.colors.background) - pulsebar.bar:set_color(pulsebar.colors.unmute) pulsebar.tooltip = awful.tooltip({ objects = { pulsebar.bar } }) - pulsebar.bar:set_width(width) - pulsebar.bar:set_height(height) - pulsebar.bar:set_ticks(ticks) - pulsebar.bar:set_ticks_size(ticks_size) - pulsebar.bar:set_vertical(vertical) function pulsebar.update() if scallback then pulseaudio.cmd = scallback() end @@ -137,15 +139,15 @@ local function worker(args) then pulsebar._current_level = volu pulsebar.bar:set_value(pulsebar._current_level / 100) - if not mute and volu == 0 or mute == "yes" + if (not mute and volu == 0) or mute == "yes" then pulsebar._muted = true - pulsebar.tooltip:set_text (" [Muted] ") - pulsebar.bar:set_color(pulsebar.colors.mute) + pulsebar.tooltip:set_text ("[Muted]") + pulsebar.bar.color(pulsebar.colors.mute) else pulsebar._muted = false - pulsebar.tooltip:set_text(string.format(" %s:%s ", pulsebar.sink, volu)) - pulsebar.bar:set_color(pulsebar.colors.unmute) + pulsebar.tooltip:set_text(string.format("%s: %s", pulsebar.sink, volu)) + pulsebar.bar.color(pulsebar.colors.unmute) end settings() end diff --git a/wiki b/wiki index f6270ed..bc5582f 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit f6270edc9e9d8ba83971fac3dbaca301c4792f34 +Subproject commit bc5582fb3d3d7bf54f2848e9b58aa01c9c33d79e From bcd37ae4ae4f0e5d11ab6d8f6a9580e840447327 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Fri, 6 Jan 2017 11:21:19 +0100 Subject: [PATCH 007/106] pulsebar: corrected colors typo; closes #251 --- util/init.lua | 8 +--- util/quake.lua | 80 +++++++++++++++++++++------------------ util/separators.lua | 2 +- widgets/alsabar.lua | 12 +++--- widgets/borderbox.lua | 58 ---------------------------- widgets/calendar.lua | 11 +++--- widgets/contrib/gpmdp.lua | 39 ++++++++++--------- widgets/contrib/moc.lua | 21 +++++----- widgets/contrib/task.lua | 12 +++--- widgets/imap.lua | 7 ++-- widgets/mpd.lua | 7 ++-- widgets/pulsebar.lua | 19 ++++------ widgets/weather.lua | 7 ++-- wiki | 2 +- 14 files changed, 113 insertions(+), 172 deletions(-) delete mode 100644 widgets/borderbox.lua diff --git a/util/init.lua b/util/init.lua index 14a1e14..9a6d182 100644 --- a/util/init.lua +++ b/util/init.lua @@ -211,13 +211,7 @@ end -- On the fly useless gaps change function util.useless_gaps_resize(thatmuch) - beautiful.useless_gap_width = tonumber(beautiful.useless_gap_width) + thatmuch - awful.layout.arrange(mouse.screen) -end - --- On the fly global border change -function util.global_border_resize(thatmuch) - beautiful.global_border_width = tonumber(beautiful.global_border_width) + thatmuch + beautiful.useless_gap = tonumber(beautiful.useless_gap) + thatmuch awful.layout.arrange(mouse.screen) end diff --git a/util/quake.lua b/util/quake.lua index e54b664..5020eee 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -6,15 +6,14 @@ --]] -local awful = require("awful") -local capi = { client = client, - mouse = mouse, - screen = screen, - timer = timer or require("gears.timer") } -local math = { floor = math.floor } -local string = string +local awful = require("awful") +local capi = { client = client, + timer = require("gears.timer") } +local math = { floor = math.floor } +local string = string local pairs = pairs +local screen = screen local setmetatable = setmetatable local tostring = tostring @@ -65,21 +64,22 @@ function quake:display() client.border_width = self.border client.size_hints_honor = false if self.notexist then + self:compute_size() client:geometry(self.geometry) self.notexist = false end -- Not sticky and on top + client.sticky = false client.ontop = true client.above = true client.skip_taskbar = true - client.sticky = false -- Toggle display if self.visible then client.hidden = false client:raise() - self.last_tag = tostring(awful.tag.selected(self.screen)) + self.last_tag = awful.tag.selected(self.screen) client:tags({awful.tag.selected(self.screen)}) capi.client.focus = client else @@ -94,36 +94,38 @@ function quake:display() return client end +function quake:compute_size() + local geom = screen[self.screen].workarea + local width, height + if self.width <= 1 then width = math.floor(geom.width * self.width) end + if self.height <= 1 then height = math.floor(geom.height * self.height) end + local x, y + if self.horiz == "left" then x = geom.x + elseif self.horiz == "right" then x = geom.width + geom.x - self.width + else x = geom.x + (geom.width - self.width)/2 end + if self.vert == "top" then y = geom.y + elseif self.vert == "bottom" then y = geom.height + geom.y - self.height + else y = geom.y + (geom.height - self.height)/2 end + self.geometry = { x = x, y = y, width = width, height = height } +end + function quake:new(config) local conf = config or {} - conf.app = conf.app or "xterm" -- application to spawn - conf.name = conf.name or "QuakeDD" -- window name - conf.argname = conf.argname or "-name %s" -- how to specify window name - conf.extra = conf.extra or "" -- extra arguments - conf.visible = conf.visible or false -- initially not visible - conf.screen = conf.screen or capi.mouse.screen - conf.border = conf.border or 1 + conf.app = conf.app or "xterm" -- application to spawn + conf.name = conf.name or "QuakeDD" -- window name + conf.argname = conf.argname or "-name %s" -- how to specify window name + conf.extra = conf.extra or "" -- extra arguments + conf.visible = conf.visible or false -- initially not visible + conf.border = conf.border or 1 -- client border width + conf.followtag = conf.followtag or false -- spawn on currently focused screen + conf.screen = conf.screen or awful.screen.focused() -- If width or height <= 1 this is a proportion of the workspace - wibox_height = conf.wibox_height or 18 -- statusbar weight - height = conf.height or 0.25 -- height - width = conf.width or 1 -- width - vert = conf.vert or "top" -- top, bottom or center - horiz = conf.horiz or "center" -- left, right or center - - -- Compute size - local geom = capi.screen[conf.screen].workarea - if width <= 1 then width = math.floor(geom.width * width) end - if height <= 1 then height = math.floor(geom.height * height) end - local x, y - if horiz == "left" then x = geom.x - elseif horiz == "right" then x = geom.width + geom.x - width - else x = geom.x + (geom.width - width)/2 end - if vert == "top" then y = geom.y - elseif vert == "bottom" then y = geom.height + geom.y - height - else y = geom.y + (geom.height - height)/2 end - conf.geometry = { x = x, y = y + wibox_height, width = width, height = height } + conf.height = conf.height or 0.25 -- height + conf.width = conf.width or 1 -- width + conf.vert = conf.vert or "top" -- top, bottom or center + conf.horiz = conf.horiz or "center" -- left, right or center local console = setmetatable(conf, { __index = quake }) capi.client.connect_signal("manage", function(c) @@ -140,6 +142,9 @@ function quake:new(config) -- "Reattach" currently running quake application. This is in case awesome is restarted. local reattach = capi.timer { timeout = 0 } reattach:connect_signal("timeout", function() + if self.followtag then + self.screen = awful.screen.focused() + end reattach:stop() console:display() end) @@ -149,8 +154,11 @@ function quake:new(config) end function quake:toggle() - current_tag = awful.tag.selected(self.screen) - if self.last_tag ~= tostring(current_tag) and self.visible then + if self.followtag then + self.screen = awful.screen.focused() + end + local current_tag = awful.tag.selected(self.screen) + if self.last_tag ~= current_tag and self.visible then awful.client.movetotag(current_tag, self:display()) else self.visible = not self.visible diff --git a/util/separators.lua b/util/separators.lua index 6e5ef96..af3e3a8 100644 --- a/util/separators.lua +++ b/util/separators.lua @@ -15,7 +15,7 @@ local gears = require("gears") -- lain.util.separators local separators = {} -local height = beautiful.awful_widget_height or 0 +local height = beautiful.separators_height or 0 local width = beautiful.separators_width or 9 -- [[ Arrow diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index 093c461..5a54829 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -16,7 +16,6 @@ local naughty = require("naughty") local wibox = require("wibox") local math = { modf = math.modf } -local mouse = mouse local string = { format = string.format, match = string.match, rep = string.rep } @@ -43,7 +42,6 @@ local alsabar = { font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")), font_size = "11", color = beautiful.fg_normal, - bar_size = 18, screen = 1 }, @@ -71,12 +69,12 @@ function alsabar.notify() preset.title = string.format("%s - %s%%", alsabar.channel, alsabar._current_level) end - int = math.modf((alsabar._current_level / 100) * alsabar.notifications.bar_size) + int = math.modf((alsabar._current_level / 100) * awful.screen.focused().mywibox.height) preset.text = string.format("[%s%s]", string.rep("|", int), - string.rep(" ", alsabar.notifications.bar_size - int)) + string.rep(" ", awful.screen.focused().mywibox.height - int)) - if alsabar.followmouse then - preset.screen = mouse.screen + if alsabar.followtag then + preset.screen = awful.screen.focused() end if alsabar._notify ~= nil then @@ -107,7 +105,7 @@ local function worker(args) alsabar.step = args.step or alsabar.step alsabar.colors = args.colors or alsabar.colors alsabar.notifications = args.notifications or alsabar.notifications - alsabar.followmouse = args.followmouse or false + alsabar.followtag = args.followtag or false alsabar.bar = wibox.widget { forced_height = height, diff --git a/widgets/borderbox.lua b/widgets/borderbox.lua deleted file mode 100644 index 149b835..0000000 --- a/widgets/borderbox.lua +++ /dev/null @@ -1,58 +0,0 @@ - ---[[ - - Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham - * (c) 2010-2012, Peter Hofmann - ---]] - -local wibox = require("awful.wibox") -local setmetatable = setmetatable - --- Creates a thin wibox at a position relative to another wibox --- lain.widgets.borderbox -local borderbox = {} - -local function worker(relbox, s, args) - local where = args.position or 'top' - local color = args.color or '#FFFFFF' - local size = args.size or 1 - local box = nil - local wiboxarg = { position = nil, bg = color } - - if where == 'top' - then - wiboxarg.width = relbox.width - wiboxarg.height = size - box = wibox(wiboxarg) - box.x = relbox.x - box.y = relbox.y - size - elseif where == 'bottom' - then - wiboxarg.width = relbox.width - wiboxarg.height = size - box = wibox(wiboxarg) - box.x = relbox.x - box.y = relbox.y + relbox.height - elseif where == 'left' - then - wiboxarg.width = size - wiboxarg.height = relbox.height - box = wibox(wiboxarg) - box.x = relbox.x - size - box.y = relbox.y - elseif where == 'right' - then - wiboxarg.width = size - wiboxarg.height = relbox.height - box = wibox(wiboxarg) - box.x = relbox.x + relbox.width - box.y = relbox.y - end - - box.screen = s - return box -end - -return setmetatable(borderbox, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/calendar.lua b/widgets/calendar.lua index 1728dfc..76faca4 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -14,7 +14,6 @@ local naughty = require("naughty") local io = { popen = io.popen } local os = { date = os.date } -local mouse = mouse local string = { format = string.format, sub = string.sub, gsub = string.gsub } @@ -47,13 +46,13 @@ function calendar.show(t_out, inc_offset, scr) if offs == 0 or calendar.offset == 0 then -- current month showing, today highlighted calendar.offset = 0 - calendar.notify_icon = calendar.icons .. today .. ".png" + calendar.notify_icon = string.format("%s%s.png", calendar.icons, today) -- bg and fg inverted to highlight today f = io.popen(calendar.cal_format(today)) else -- no current month showing, no day to highlight local month = tonumber(os.date('%m')) - local year = tonumber(os.date('%Y')) + local year = tonumber(os.date('%Y')) month = month + calendar.offset @@ -79,8 +78,8 @@ function calendar.show(t_out, inc_offset, scr) .. "" f:close() - if calendar.followmouse then - scrp = mouse.screen + if calendar.followtag then + scrp = awful.screen.focused() else scrp = scr or calendar.scr_pos end @@ -111,7 +110,7 @@ function calendar.attach(widget, args) calendar.bg = args.bg or beautiful.bg_normal or "#000000" calendar.position = args.position or "top_right" calendar.scr_pos = args.scr_pos or 1 - calendar.followmouse = args.followmouse or false + calendar.followtag = args.followtag or false calendar.offset = 0 calendar.notify_icon = nil diff --git a/widgets/contrib/gpmdp.lua b/widgets/contrib/gpmdp.lua index fa51440..ee40a8d 100644 --- a/widgets/contrib/gpmdp.lua +++ b/widgets/contrib/gpmdp.lua @@ -6,15 +6,18 @@ --]] -local helpers = require("lain.helpers") -local json = require("lain.util.dkjson") -local pread = require("awful.util").pread -local naughty = require("naughty") -local wibox = require("wibox") -local mouse = mouse -local os = { getenv = os.getenv } +local helpers = require("lain.helpers") +local json = require("lain.util.dkjson") +local focused = require("awful.screen").focused +local pread = require("awful.util").pread +local naughty = require("naughty") +local wibox = require("wibox") + +local next = next +local os = { getenv = os.getenv } local setmetatable = setmetatable +local table = table -- Google Play Music Desktop infos -- lain.widget.contrib.gpmdp @@ -24,7 +27,7 @@ local function worker(args) local args = args or {} local timeout = args.timeout or 2 local notify = args.notify or "off" - local followmouse = args.followmouse or false + local followtag = args.followtag or false local file_location = args.file_location or os.getenv("HOME") .. "/.config/Google Play Music Desktop Player/json_store/playback.json" local settings = args.settings or function() end @@ -39,14 +42,14 @@ local function worker(args) helpers.set_map("gpmdp_current", nil) function gpmdp.update() - file, err = io.open(file_location, "r") - if not file + local filelines = helpers.lines_from(file_location) + + if not next(filelines) then - gpm_now = { running = false, playing = false } + local gpm_now = { running = false, playing = false } else - dict, pos, err = json.decode(file:read "*a", 1, nil) - file:close() - gpm_now = {} + dict, pos, err = json.decode(table.concat(filelines), 1, nil) + local gpm_now = {} gpm_now.artist = dict.song.artist gpm_now.album = dict.song.album gpm_now.title = dict.song.title @@ -54,7 +57,7 @@ local function worker(args) gpm_now.playing = dict.playing end - if (pread("pidof 'Google Play Music Desktop Player'") ~= '') then + if pread("pidof 'Google Play Music Desktop Player'") ~= '' then gpm_now.running = true else gpm_now.running = false @@ -69,10 +72,10 @@ local function worker(args) if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current") then helpers.set_map("gpmdp_current", gpm_now.title) - os.execute("curl " .. gpm_now.cover_url .. " -o /tmp/gpmcover.png") + os.execute(string.format("curl %d -o /tmp/gpmcover.png", gpm_now.cover_url)) - if followmouse then - gpmdp_notification_preset.screen = mouse.screen + if followtag then + gpmdp_notification_preset.screen = focused() end gpmdp.id = naughty.notify({ diff --git a/widgets/contrib/moc.lua b/widgets/contrib/moc.lua index b79dbe2..d4571e1 100644 --- a/widgets/contrib/moc.lua +++ b/widgets/contrib/moc.lua @@ -6,18 +6,19 @@ --]] -local helpers = require("lain.helpers") -local async = require("lain.asyncshell") +local helpers = require("lain.helpers") +local async = require("lain.asyncshell") +local focused = require("awful.screen").focused local escape_f = require("awful.util").escape local naughty = require("naughty") local wibox = require("wibox") -local io = { popen = io.popen } -local os = { execute = os.execute, - getenv = os.getenv } -local string = { format = string.format, - gmatch = string.gmatch } +local io = { popen = io.popen } +local os = { execute = os.execute, + getenv = os.getenv } +local string = { format = string.format, + gmatch = string.gmatch } local setmetatable = setmetatable @@ -31,7 +32,7 @@ local function worker(args) local music_dir = args.music_dir or os.getenv("HOME") .. "/Music" local cover_size = args.cover_size or 100 local default_art = args.default_art or "" - local followmouse = args.followmouse or false + local followtag = args.followtag or false local settings = args.settings or function() end local mpdcover = helpers.scripts_dir .. "mpdcover" @@ -85,8 +86,8 @@ local function worker(args) os.execute(string.format("%s %q %q %d %q", mpdcover, "", moc_now.file, cover_size, default_art)) - if followmouse then - moc_notification_preset.screen = mouse.screen + if followtag then + moc_notification_preset.screen = focused() end moc.id = naughty.notify({ diff --git a/widgets/contrib/task.lua b/widgets/contrib/task.lua index fc438d9..1b8f119 100644 --- a/widgets/contrib/task.lua +++ b/widgets/contrib/task.lua @@ -42,8 +42,8 @@ function task.show(scr_pos) local f, c_text, scrp - if task.followmouse then - scrp = mouse.screen + if task.followtag then + scrp = awful.screen.focused() else scrp = scr_pos or task.scr_pos end @@ -69,7 +69,7 @@ end function task.prompt_add() awful.prompt.run({ prompt = "Add task: " }, - mypromptbox[mouse.screen].widget, + mypromptbox[awful.screen.focused()].widget, function (...) local f = io.popen("task add " .. ...) c_text = "\n Date: Fri, 6 Jan 2017 13:46:24 +0100 Subject: [PATCH 010/106] wiki updated --- wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiki b/wiki index 855d236..ad794d1 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 855d23635ea54a66b246df2134b81b3961ea7d44 +Subproject commit ad794d1fea2d2d8082d62e75997329e66276ebfb From fd35485c200a52c9429f9a4f3f5c8282b64dba30 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sat, 7 Jan 2017 15:12:41 +0100 Subject: [PATCH 011/106] alsa/bat textbox resize fix --- README.rst | 2 +- widgets/abase.lua | 3 +-- widgets/alsa.lua | 13 +++++++------ widgets/base.lua | 1 - widgets/bat.lua | 10 ++++------ widgets/cpu.lua | 34 ++++++++++++++++------------------ 6 files changed, 29 insertions(+), 34 deletions(-) diff --git a/README.rst b/README.rst index f6938bd..6c7bb01 100644 --- a/README.rst +++ b/README.rst @@ -15,7 +15,7 @@ Description **Note:** the update to 4.x is still in progress: if you experience issues, please report them in order to speed up the process. -Successor of awesome-vain_, this module provides new layouts, a set of widgets and utility functions, in order to improve Awesome_ usability and configurability. +Successor of awesome-vain_, this module provides new layouts, a set of widgets and utility functions, with the aim of improving Awesome_ usability and configurability. Read the wiki_ for all the info. diff --git a/widgets/abase.lua b/widgets/abase.lua index fb20d76..60d86ab 100644 --- a/widgets/abase.lua +++ b/widgets/abase.lua @@ -12,8 +12,7 @@ local wibox = require("wibox") local setmetatable = setmetatable --- Basic template for custom widgets --- Asynchronous version +-- Basic template for custom widgets (asynchronous version) -- lain.widgets.abase local function worker(args) diff --git a/widgets/alsa.lua b/widgets/alsa.lua index 7500097..670765a 100644 --- a/widgets/alsa.lua +++ b/widgets/alsa.lua @@ -7,7 +7,7 @@ --]] -local newtimer = require("lain.helpers").newtimer +local helpers = require("lain.helpers") local read_pipe = require("lain.helpers").read_pipe local wibox = require("wibox") @@ -19,7 +19,7 @@ local setmetatable = setmetatable -- ALSA volume -- lain.widgets.alsa -local alsa = { last_level = "0", last_status = "" } +local alsa = helpers.make_widget_textbox() local function worker(args) local args = args or {} @@ -29,11 +29,12 @@ local function worker(args) alsa.cmd = args.cmd or "amixer" alsa.channel = args.channel or "Master" alsa.togglechannel = args.togglechannel - alsa.widget = wibox.widget.textbox('') + alsa.last_level = "0" + alsa.last_status = "" function alsa.update() mixer = read_pipe(string.format("%s get %s", alsa.cmd, alsa.channel)) - l,s = string.match(mixer, "([%d]+)%%.*%[([%l]*)") + l, s = string.match(mixer, "([%d]+)%%.*%[([%l]*)") -- HDMIs can have a channel different from Master for toggling mute if alsa.togglechannel then @@ -51,9 +52,9 @@ local function worker(args) end timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel) - newtimer(timer_id, timeout, alsa.update) + helpers.newtimer(timer_id, timeout, alsa.update) - return setmetatable(alsa, { __index = alsa.widget }) + return alsa end return setmetatable(alsa, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/base.lua b/widgets/base.lua index cd84e36..642a858 100644 --- a/widgets/base.lua +++ b/widgets/base.lua @@ -8,7 +8,6 @@ local newtimer = require("lain.helpers").newtimer local read_pipe = require("lain.helpers").read_pipe - local wibox = require("wibox") local setmetatable = setmetatable diff --git a/widgets/bat.lua b/widgets/bat.lua index f63b1fa..8e483f7 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -7,7 +7,7 @@ --]] -local newtimer = require("lain.helpers").newtimer +local helpers = require("lain.helpers") local first_line = require("lain.helpers").first_line local naughty = require("naughty") @@ -27,7 +27,7 @@ local setmetatable = setmetatable -- lain.widgets.bat local function worker(args) - local bat = {} + local bat = helpers.make_widget_textbox() local args = args or {} local timeout = args.timeout or 30 local batteries = args.batteries or (args.battery and {args.battery}) or {"BAT0"} @@ -35,8 +35,6 @@ local function worker(args) local notify = args.notify or "on" local settings = args.settings or function() end - bat.widget = wibox.widget.textbox('') - bat_notification_low_preset = { title = "Battery low", text = "Plug the cable!", @@ -165,9 +163,9 @@ local function worker(args) end end - newtimer(battery, timeout, bat.update) + helpers.newtimer(battery, timeout, bat.update) - return setmetatable(bat, { __index = bat.widget }) + return bat end return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/cpu.lua b/widgets/cpu.lua index 737b6fa..c33c7eb 100644 --- a/widgets/cpu.lua +++ b/widgets/cpu.lua @@ -25,28 +25,26 @@ local cpu = { core = {} } local function worker(args) local args = args or {} - local timeout = args.timeout or 2 - local settings = args.settings or function() end + local timeout = args.timeout or 2 + local settings = args.settings or function() end - cpu.widget = wibox.widget.textbox('') + cpu.widget = wibox.widget.textbox('') - function update() + function update() -- Read the amount of time the CPUs have spent performing - -- different kinds of work. Read the first line of /proc/stat - -- which is the sum of all CPUs. + -- different kinds of work. Read the first line of /proc/stat + -- which is the sum of all CPUs. local times = lines_match("cpu","/proc/stat") - for index,time in pairs(times) - do + for index,time in pairs(times) do local coreid = index - 1 - local core = cpu.core[coreid] or - { last_active = 0 , last_total = 0, usage = 0 } - local at = 1 - local idle = 0 - local total = 0 + local core = cpu.core[coreid] or + { last_active = 0 , last_total = 0, usage = 0 } + local at = 1 + local idle = 0 + local total = 0 - for field in string.gmatch(time, "[%s]+([^%s]+)") - do + for field in string.gmatch(time, "[%s]+([^%s]+)") do -- 4 = idle, 5 = ioWait. Essentially, the CPUs have done -- nothing during these times. if at == 4 or at == 5 then @@ -62,15 +60,14 @@ local function worker(args) -- Read current data and calculate relative values. local dactive = active - core.last_active local dtotal = total - core.last_total - - local usage = math.ceil((dactive / dtotal) * 100) + local usage = math.ceil((dactive / dtotal) * 100) core.last_active = active core.last_total = total core.usage = usage -- Save current data for the next run. - cpu.core[coreid] = core; + cpu.core[coreid] = core end end @@ -82,6 +79,7 @@ local function worker(args) end newtimer("cpu", timeout, update) + return cpu.widget end From d617e1a37693d4a4ee76bdd1948dba8a515247ff Mon Sep 17 00:00:00 2001 From: aajjbb Date: Sat, 7 Jan 2017 13:00:05 -0200 Subject: [PATCH 012/106] fixing typo mentioned in issues --- widgets/alsabar.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index 5a54829..cdbefd2 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -163,7 +163,7 @@ local function worker(args) end), awful.button({}, 2, function() awful.util.spawn(string.format("%s set %s 100%%", alsabar.cmd, alsabar.channel)) - pulsebar.update() + alsabar.update() end), awful.button({}, 3, function() awful.util.spawn(string.format("%s set %s toggle", alsabar.cmd, alsabar.togglechannel or alsabar.channel)) From f59c9644ab3daa1f186c5d4041184327184b9150 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sat, 7 Jan 2017 16:46:38 +0100 Subject: [PATCH 013/106] quake: removed deprecations --- util/quake.lua | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/util/quake.lua b/util/quake.lua index 6023e3f..bda0324 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -54,9 +54,9 @@ function quake:display() if not client then -- The client does not exist, we spawn it - awful.util.spawn(string.format("%s %s %s", self.app, - string.format(self.argname, self.name), self.extra), - false, self.screen) + awful.spawn(string.format("%s %s %s", self.app, + string.format(self.argname, self.name), self.extra), + false, self.screen) self.notexist = true return end @@ -81,8 +81,8 @@ function quake:display() if self.visible then client.hidden = false client:raise() - self.last_tag = awful.tag.selected(self.screen) - client:tags({awful.tag.selected(self.screen)}) + self.last_tag = self.screen.selected_tag + client:tags({self.screen.selected_tag}) capi.client.focus = client else client.hidden = true @@ -155,15 +155,13 @@ end function quake:toggle() if self.followtag then self.screen = awful.screen.focused() end - local current_tag = awful.tag.selected(self.screen) - if self.last_tag ~= current_tag and self.visible then - awful.client.movetotag(current_tag, self:display()) + local current_tag = self.screen.selected_tag + if current_tag and self.last_tag ~= current_tag and self.visible then + self:display():move_to_tag(current_tag) else self.visible = not self.visible self:display() end end -setmetatable(quake, { __call = function(_, ...) return quake:new(...) end }) - -return quake +return setmetatable(quake, { __call = function(_, ...) return quake:new(...) end }) From 42ef1c3f3d6e2431d44cc710f8862cdb7c11a645 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sat, 7 Jan 2017 16:49:48 +0100 Subject: [PATCH 014/106] pulsebar: fixed typos --- widgets/pulsebar.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/widgets/pulsebar.lua b/widgets/pulsebar.lua index 6818a5c..bacd969 100644 --- a/widgets/pulsebar.lua +++ b/widgets/pulsebar.lua @@ -24,7 +24,7 @@ local tonumber = tonumber local setmetatable = setmetatable --- ALSA volume bar +-- Pulseaudio volume bar -- lain.widgets.pulsebar local pulsebar = { sink = 0, @@ -55,8 +55,8 @@ function pulsebar.notify() title = "", text = "", timeout = 5, - font = string.format("%s %s", alsabar.notifications.font, - alsabar.notifications.font_size), + font = string.format("%s %s", pulsebar.notifications.font, + pulsebar.notifications.font_size), fg = pulsebar.notifications.color } From 6ff56e857e13e266eb02d96167132159aa3677f5 Mon Sep 17 00:00:00 2001 From: Stefan Wimmer Date: Sun, 8 Jan 2017 11:21:09 +0100 Subject: [PATCH 015/106] Offer the possibility to show the used space in MB/GB This is also addressed in issue #254 --- widgets/fs.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/widgets/fs.lua b/widgets/fs.lua index 60b112c..4d05df5 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -85,6 +85,8 @@ local function worker(args) if u and m then -- Handle 1st line and broken regexp fs_info[m .. " size_mb"] = string.format("%.1f", tonumber(s) / unit["mb"]) fs_info[m .. " size_gb"] = string.format("%.1f", tonumber(s) / unit["gb"]) + fs_info[m .. " used_mb"] = string.format("%.1f", tonumber(u) / unit["mb"]) + fs_info[m .. " used_gb"] = string.format("%.1f", tonumber(u) / unit["gb"]) fs_info[m .. " used_p"] = tonumber(p) fs_info[m .. " avail_p"] = 100 - tonumber(p) end @@ -96,6 +98,8 @@ local function worker(args) fs_now.available = tonumber(fs_info[partition .. " avail_p"]) or 0 fs_now.size_mb = tonumber(fs_info[partition .. " size_mb"]) or 0 fs_now.size_gb = tonumber(fs_info[partition .. " size_gb"]) or 0 + fs_now.used_mb = tonumber(fs_info[partition .. " used_mb"]) or 0 + fs_now.used_gb = tonumber(fs_info[partition .. " used_gb"]) or 0 notification_preset = fs.notification_preset widget = fs.widget From 2f1f0c572a85f3d393315b6b63aff12a063649b3 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sun, 8 Jan 2017 13:25:09 +0100 Subject: [PATCH 016/106] wiki updated #254; other fixes --- README.rst | 7 +++++-- helpers.lua | 2 +- init.lua | 5 +---- widgets/contrib/redshift.lua | 5 ++--- widgets/fs.lua | 12 ++++++------ widgets/mpd.lua | 3 ++- wiki | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.rst b/README.rst index 6c7bb01..a0cd369 100644 --- a/README.rst +++ b/README.rst @@ -10,11 +10,14 @@ Layouts, widgets and utilities for Awesome WM 4.x :License: GNU-GPL2_ :Source: https://github.com/copycat-killer/lain +Warning +------- + +The update to 4.x is still in progress: if you experience issues, please report them in order to speed up the process. + Description ----------- -**Note:** the update to 4.x is still in progress: if you experience issues, please report them in order to speed up the process. - Successor of awesome-vain_, this module provides new layouts, a set of widgets and utility functions, with the aim of improving Awesome_ usability and configurability. Read the wiki_ for all the info. diff --git a/helpers.lua b/helpers.lua index 6a47738..50254c1 100644 --- a/helpers.lua +++ b/helpers.lua @@ -9,7 +9,7 @@ local debug = require("debug") local assert = assert -local capi = { timer = (type(timer) == 'table' and timer or require ("gears.timer")) } +local capi = { timer = require ("gears.timer") } local io = { open = io.open, lines = io.lines, popen = io.popen } diff --git a/init.lua b/init.lua index 155d6cc..5640861 100644 --- a/init.lua +++ b/init.lua @@ -9,11 +9,8 @@ --]] -local lain = -{ +return { layout = require("lain.layout"), util = require("lain.util"), widgets = require("lain.widgets") } - -return lain diff --git a/widgets/contrib/redshift.lua b/widgets/contrib/redshift.lua index 69247ee..3c4f749 100644 --- a/widgets/contrib/redshift.lua +++ b/widgets/contrib/redshift.lua @@ -8,7 +8,6 @@ local awful = require("awful") local os = os -local spawn = awful.util.spawn_with_shell local setmetatable = setmetatable @@ -26,9 +25,9 @@ local function init() -- toggled off (i.e Awesome on-the-fly restart), kill redshift to make sure os.execute("pkill redshift") -- Remove existing color adjustment - spawn("redshift -x") + awful.spawn_with_shell("redshift -x") -- (Re)start redshift - spawn("redshift") + awful.spawn_with_shell("redshift") running = true active = true end diff --git a/widgets/fs.lua b/widgets/fs.lua index 4d05df5..49cb8f0 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -11,12 +11,12 @@ local helpers = require("lain.helpers") local beautiful = require("beautiful") +local focused = require("awful.screen").focused local wibox = require("wibox") local naughty = require("naughty") local io = { popen = io.popen } local pairs = pairs -local mouse = mouse local string = { match = string.match, format = string.format } local tonumber = tonumber @@ -41,8 +41,8 @@ function fs.show(seconds, options, scr) local cmd = (options and string.format("dfs %s", options)) or "dfs" local ws = helpers.read_pipe(helpers.scripts_dir .. cmd):gsub("\n*$", "") - if fs.followmouse then - fs.notification_preset.screen = mouse.screen + if fs.followtag then + fs.notification_preset.screen = focused() elseif scr then fs.notification_preset.screen = scr end @@ -65,7 +65,7 @@ local function worker(args) local notify = args.notify or "on" local settings = args.settings or function() end - fs.followmouse = args.followmouse or false + fs.followta g = args.followtag or false fs.notification_preset = args.notification_preset or { fg = beautiful.fg_normal } fs.widget = wibox.widget.textbox('') @@ -94,11 +94,11 @@ local function worker(args) f:close() - fs_now.used = tonumber(fs_info[partition .. " used_p"]) or 0 fs_now.available = tonumber(fs_info[partition .. " avail_p"]) or 0 fs_now.size_mb = tonumber(fs_info[partition .. " size_mb"]) or 0 fs_now.size_gb = tonumber(fs_info[partition .. " size_gb"]) or 0 - fs_now.used_mb = tonumber(fs_info[partition .. " used_mb"]) or 0 + fs_now.used = tonumber(fs_info[partition .. " used_p"]) or 0 + fs_now.used_mb = tonumber(fs_info[partition .. " used_mb"]) or 0 fs_now.used_gb = tonumber(fs_info[partition .. " used_gb"]) or 0 notification_preset = fs.notification_preset diff --git a/widgets/mpd.lua b/widgets/mpd.lua index 5a4e534..3e2eaf5 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -11,6 +11,7 @@ local helpers = require("lain.helpers") local async = require("lain.asyncshell") local escape_f = require("awful.util").escape +local focused = require("awful.screen").focused local naughty = require("naughty") local wibox = require("wibox") @@ -118,7 +119,7 @@ local function worker(args) end if followtag then - mpd_notification_preset.screen = awful.screen.focused() + mpd_notification_preset.screen = focused() end mpd.id = naughty.notify({ diff --git a/wiki b/wiki index ad794d1..42ecadb 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit ad794d1fea2d2d8082d62e75997329e66276ebfb +Subproject commit 42ecadbcd535153aa7229b8afed660a3bd349b78 From 557b53288158a01491dbb4d237dfc8dc652f5e20 Mon Sep 17 00:00:00 2001 From: Stefan Wimmer Date: Sun, 8 Jan 2017 14:45:20 +0100 Subject: [PATCH 017/106] Typo in fs.lua --- widgets/fs.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/fs.lua b/widgets/fs.lua index 49cb8f0..aa05bde 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -65,7 +65,7 @@ local function worker(args) local notify = args.notify or "on" local settings = args.settings or function() end - fs.followta g = args.followtag or false + fs.followtag = args.followtag or false fs.notification_preset = args.notification_preset or { fg = beautiful.fg_normal } fs.widget = wibox.widget.textbox('') From b82cb1aaae592497aee6ba0c44de615331ec6940 Mon Sep 17 00:00:00 2001 From: Stefan Wimmer Date: Sun, 8 Jan 2017 20:31:00 +0100 Subject: [PATCH 018/106] - Another "deprecated" warning with Awesome 4.0 silenced --- util/quake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/quake.lua b/util/quake.lua index bda0324..6363578 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -62,7 +62,7 @@ function quake:display() end -- Resize - awful.client.floating.set(client, true) + client.floating = true client.border_width = self.border client.size_hints_honor = false if self.notexist then From f5700be12b68f73d20e26a7293881707897d8f04 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 9 Jan 2017 13:04:02 +0100 Subject: [PATCH 019/106] fs: options moved to constructor; #closes 259 --- lain-git.rockspec | 4 ++-- util/init.lua | 33 ++++++++++++++++++--------------- widgets/fs.lua | 5 +++-- wiki | 2 +- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lain-git.rockspec b/lain-git.rockspec index b8d7abb..c3a7dbd 100644 --- a/lain-git.rockspec +++ b/lain-git.rockspec @@ -15,8 +15,8 @@ description = { license = "GPL v2" } dependencies = { - "lua >= 5.1", - "awesome >= 3.5", + "lua >= 5.3", + "awesome >= 4.0", "alsa-utils", "curl", "imagemagick" diff --git a/util/init.lua b/util/init.lua index 9a6d182..a7b53d2 100644 --- a/util/init.lua +++ b/util/init.lua @@ -33,7 +33,7 @@ local util = { _NAME = "lain.util" } -- tags. function util.menu_clients_current_tags(menu, args) -- List of currently selected tags. - local cls_tags = awful.tag.selectedlist(mouse.screen) + local cls_tags = awful.screen.focused().selected_tags -- Final list of menu items. local cls_t = {} @@ -89,15 +89,18 @@ end function util.mc(c) c = c or magnified_client if not c then return end - awful.client.floating.set(c, true) - local mg = screen[mouse.screen].geometry - local tag = awful.tag.selected(mouse.screen) - local mwfact = awful.tag.getmwfact(tag) - local g = {} - g.width = math.sqrt(mwfact) * mg.width - g.height = math.sqrt(mwfact) * mg.height - g.x = mg.x + (mg.width - g.width) / 2 - g.y = mg.y + (mg.height - g.height) / 2 + + c.floating = true + local s = awful.screen.selected() + local mg = s.geometry + local tag = s.selected_tag + local mwfact = beautiful.master_width_factor or 0.5 + local g = {} + g.width = math.sqrt(mwfact) * mg.width + g.height = math.sqrt(mwfact) * mg.height + g.x = mg.x + (mg.width - g.width) / 2 + g.y = mg.y + (mg.height - g.height) / 2 + if c then c:geometry(g) end -- if c is still a valid object end @@ -148,12 +151,12 @@ end -- Non-empty tag browsing -- direction in {-1, 1} <-> {previous, next} non-empty tag function util.tag_view_nonempty(direction, sc) - local s = sc or mouse.screen or 1 + local s = sc or awful.screen.focused() local scr = screen[s] - for i = 1, #awful.tag.gettags(s) do - awful.tag.viewidx(direction,s) - if #awful.client.visible(s) > 0 then + for i = 1, #s.tags do + awful.tag.viewidx(direction, s) + if #s.clients > 0 then return end end @@ -191,7 +194,7 @@ end -- Move current tag -- pos in {-1, 1} <-> {previous, next} tag position function util.move_tag(pos) - local tag = awful.tag.selected(mouse.screen) + local tag = awful.screen.focused().selected_tag local idx = awful.tag.getidx(tag) if tonumber(pos) <= -1 then awful.tag.move(idx - 1, tag) diff --git a/widgets/fs.lua b/widgets/fs.lua index aa05bde..f578f8b 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -35,10 +35,10 @@ function fs.hide() end end -function fs.show(seconds, options, scr) +function fs.show(seconds, scr) fs.hide() - local cmd = (options and string.format("dfs %s", options)) or "dfs" + local cmd = (fs.options and string.format("dfs %s", fs.options)) or "dfs" local ws = helpers.read_pipe(helpers.scripts_dir .. cmd):gsub("\n*$", "") if fs.followtag then @@ -65,6 +65,7 @@ local function worker(args) local notify = args.notify 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 or { fg = beautiful.fg_normal } diff --git a/wiki b/wiki index 42ecadb..d288b2d 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 42ecadbcd535153aa7229b8afed660a3bd349b78 +Subproject commit d288b2dc5a2021af8ccd23e02c9fb0c6a97eda2a From 5f1fd821a0ebbb2d61cb3c382ca199d109e4bbd8 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 9 Jan 2017 20:21:56 +0100 Subject: [PATCH 020/106] port to awesome 4.0 completed; #248 --- helpers.lua | 10 +++++ scripts/mpdcover | 5 +-- util/init.lua | 94 +++++++++------------------------------------ widgets/maildir.lua | 74 +++++++++++++++-------------------- widgets/mpd.lua | 3 +- 5 files changed, 62 insertions(+), 124 deletions(-) diff --git a/helpers.lua b/helpers.lua index 50254c1..8eed10f 100644 --- a/helpers.lua +++ b/helpers.lua @@ -144,6 +144,16 @@ end -- {{{ Misc +-- check if an element exist on a table +function helpers.element_in_table(element, tbl) + for _, i in pairs(tbl) do + if i == element then + return true + end + end + return false +end + -- iterate over table of records sorted by keys function helpers.spairs(t) -- collect the keys diff --git a/scripts/mpdcover b/scripts/mpdcover index 6f9062c..a611666 100755 --- a/scripts/mpdcover +++ b/scripts/mpdcover @@ -37,9 +37,6 @@ fi # The default cover to use (optional) DEFAULT_ART=$4 -# Thumbnail background (transparent) -COVER_BACKGROUND="none" - #-------------------------------------------------------------------- # check if anything is playing at all @@ -58,7 +55,7 @@ cover="${cover:=$DEFAULT_ART}" # check if art is available if [[ -n $cover ]]; then if [[ -n $COVER_RESIZE ]]; then - convert "$cover" -scale $COVER_RESIZE -gravity "center" -background "$COVER_BACKGROUND" "$TEMP_PATH" + convert "$cover" -scale $COVER_RESIZE "$TEMP_PATH" cover="$TEMP_PATH" fi else diff --git a/util/init.lua b/util/init.lua index a7b53d2..5596afa 100644 --- a/util/init.lua +++ b/util/init.lua @@ -15,7 +15,6 @@ local awful = require("awful") local beautiful = require("beautiful") local math = { sqrt = math.sqrt } -local mouse = mouse local pairs = pairs local string = { gsub = string.gsub } local client = client @@ -29,26 +28,23 @@ local setmetatable = setmetatable -- lain.util local util = { _NAME = "lain.util" } --- Like awful.menu.clients, but only show clients of currently selected --- tags. +-- Like awful.menu.clients, but only show clients of currently selected tags function util.menu_clients_current_tags(menu, args) -- List of currently selected tags. local cls_tags = awful.screen.focused().selected_tags + if cls_tags == nil then return nil end + -- Final list of menu items. local cls_t = {} - if cls_tags == nil then return nil end - -- For each selected tag get all clients of that tag and add them to -- the menu. A click on a menu item will raise that client. - for i = 1,#cls_tags - do - local t = cls_tags[i] + for i = 1,#cls_tags do + local t = cls_tags[i] local cls = t:clients() - for k, c in pairs(cls) - do + for k, c in pairs(cls) do cls_t[#cls_t + 1] = { awful.util.escape(c.name) or "", function () c.minimized = false @@ -68,30 +64,30 @@ function util.menu_clients_current_tags(menu, args) -- Set the list of items and show the menu. menu.items = cls_t - local m = awful.menu.new(menu) + local m = awful.menu(menu) m:show(args) + return m end --- Magnify a client: Set it to "float" and resize it. -local magnified_client = nil +-- Magnify a client: set it to "float" and resize it. function util.magnify_client(c) - if c and not awful.client.floating.get(c) then + if c and not c.floating then util.mc(c) - magnified_client = c + util.magnified_client = c else - awful.client.floating.set(c, false) - magnified_client = nil + c.floating = false + util.magnified_client = nil end end -- https://github.com/copycat-killer/lain/issues/195 function util.mc(c) - c = c or magnified_client + c = c or util.magnified_client if not c then return end c.floating = true - local s = awful.screen.selected() + local s = awful.screen.focused() local mg = s.geometry local tag = s.selected_tag local mwfact = beautiful.master_width_factor or 0.5 @@ -104,55 +100,10 @@ function util.mc(c) if c then c:geometry(g) end -- if c is still a valid object end --- Read the nice value of pid from /proc. -local function get_nice_value(pid) - local n = first_line('/proc/' .. pid .. '/stat') - if not n then return 0 end - - -- Remove pid and tcomm. This is necessary because tcomm may contain - -- nasty stuff such as whitespace or additional parentheses... - n = string.gsub(n, '.*%) ', '') - - -- Field number 17 now is the nice value. - fields = split(n, ' ') - return tonumber(fields[17]) -end - --- To be used as a signal handler for "focus" --- This requires beautiful.border_focus{,_highprio,_lowprio}. -function util.niceborder_focus(c) - local n = get_nice_value(c.pid) - if n == 0 - then - c.border_color = beautiful.border_focus - elseif n < 0 - then - c.border_color = beautiful.border_focus_highprio - else - c.border_color = beautiful.border_focus_lowprio - end -end - --- To be used as a signal handler for "unfocus" --- This requires beautiful.border_normal{,_highprio,_lowprio}. -function util.niceborder_unfocus(c) - local n = get_nice_value(c.pid) - if n == 0 - then - c.border_color = beautiful.border_normal - elseif n < 0 - then - c.border_color = beautiful.border_normal_highprio - else - c.border_color = beautiful.border_normal_lowprio - end -end - -- Non-empty tag browsing -- direction in {-1, 1} <-> {previous, next} non-empty tag function util.tag_view_nonempty(direction, sc) local s = sc or awful.screen.focused() - local scr = screen[s] for i = 1, #s.tags do awful.tag.viewidx(direction, s) @@ -163,7 +114,7 @@ function util.tag_view_nonempty(direction, sc) end -- {{{ Dynamic tagging --- + -- Add a new tag function util.add_tag() awful.prompt.run { @@ -210,22 +161,13 @@ function util.delete_tag() if not t then return end t:delete() end + -- }}} -- On the fly useless gaps change function util.useless_gaps_resize(thatmuch) beautiful.useless_gap = tonumber(beautiful.useless_gap) + thatmuch - awful.layout.arrange(mouse.screen) -end - --- Check if an element exist on a table -function util.element_in_table(element, tbl) - for _, i in pairs(tbl) do - if i == element then - return true - end - end - return false + awful.layout.arrange(awful.screen.focused()) end return setmetatable(util, { __index = wrequire }) diff --git a/widgets/maildir.lua b/widgets/maildir.lua index e963fc6..7d4ca28 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -7,22 +7,22 @@ --]] -local newtimer = require("lain.helpers").newtimer -local read_pipe = require("lain.helpers").read_pipe -local spairs = require("lain.helpers").spairs +local spawn = require("awful").spawn +local wibox = require("wibox") -local wibox = require("wibox") +local element_in_table = require("lain.helpers").element_in_table +local newtimer = require("lain.helpers").newtimer +local read_pipe = require("lain.helpers").read_pipe +local spairs = require("lain.helpers").spairs -local awful = require("awful") -local util = require("lain.util") +local io = { popen = io.popen } +local os = { getenv = os.getenv } +local pairs = pairs +local string = { format = string.format, + len = string.len, + match = string.match } -local io = { popen = io.popen } -local os = { getenv = os.getenv } -local pairs = pairs -local string = { len = string.len, - match = string.match } - -local setmetatable = setmetatable +local setmetatable = setmetatable -- Maildir check -- lain.widgets.maildir @@ -39,67 +39,55 @@ local function worker(args) maildir.widget = wibox.widget.textbox('') function update() - if ext_mail_cmd then - awful.util.spawn(ext_mail_cmd) - end + if ext_mail_cmd then awful.spawn(ext_mail_cmd) end -- Find pathes to mailboxes. - local p = io.popen("find " .. mailpath .. - " -mindepth 1 -maxdepth 2 -type d" .. - " -not -name .git") + local p = io.popen(string.format("find %s -mindepth 1 -maxdepth 2 -type d -not -name .git", mailpath)) local boxes = {} repeat line = p:read("*l") - if line ~= nil - then + if line then -- Find all files in the "new" subdirectory. For each -- file, print a single character (no newline). Don't -- match files that begin with a dot. -- Afterwards the length of this string is the number of -- new mails in that box. - local mailstring = read_pipe("find " .. line .. - "/new -mindepth 1 -type f " .. - "-not -name '.*' -printf a") + local mailstring = read_pipe(string.format("find %s /new -mindepth 1 -type f -not -name '.*' -printf a", line)) -- Strip off leading mailpath. - local box = string.match(line, mailpath .. "/(.*)") + local box = string.match(line, mailpath .. "/(.*)") local nummails = string.len(mailstring) - if nummails > 0 - then + + if nummails > 0 then boxes[box] = nummails end end - until line == nil - + until not line p:close() - newmail = "no mail" + local newmail = "no mail" + local total = 0 - -- Count the total number of mails irrespective of where it was found - total = 0 - - for box, number in spairs(boxes) - do + for box, number in spairs(boxes) do -- Add this box only if it's not to be ignored. - if not util.element_in_table(box, ignore_boxes) - then + if not util.element_in_table(box, ignore_boxes) then total = total + number - if newmail == "no mail" - then - newmail = box .. "(" .. number .. ")" + if newmail == "no mail" then + newmail = string.format("%s(%s)", box, number) else - newmail = newmail .. ", " .. - box .. "(" .. number .. ")" + newmail = string.format("%s, %s(%s)", newmail, box, number) end end end widget = maildir.widget + settings() end newtimer(mailpath, timeout, update, true) - return maildir.widget + + return setmetatable(maildir, { __index = maildir.widget }) end return setmetatable(maildir, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/mpd.lua b/widgets/mpd.lua index 3e2eaf5..ce48014 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -124,7 +124,8 @@ local function worker(args) mpd.id = naughty.notify({ preset = mpd_notification_preset, - icon = current_icon, + icon = os.execute(string.format("ls %s &> /dev/null", current_icon)) + and current_icon, replaces_id = mpd.id, }).id end From 87b323bd06e0d7e4f6e4eca3dee9990d3662b7c5 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 9 Jan 2017 20:22:18 +0100 Subject: [PATCH 021/106] wiki updated --- wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiki b/wiki index d288b2d..7ab4e0b 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit d288b2dc5a2021af8ccd23e02c9fb0c6a97eda2a +Subproject commit 7ab4e0b101587030066c45f0b0a1950532bf8a98 From 5d892e0ceb9d4dece6d2d61b2e5c4046bbc91e9f Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 9 Jan 2017 20:25:08 +0100 Subject: [PATCH 022/106] readme updated --- README.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.rst b/README.rst index a0cd369..563d46a 100644 --- a/README.rst +++ b/README.rst @@ -10,11 +10,6 @@ Layouts, widgets and utilities for Awesome WM 4.x :License: GNU-GPL2_ :Source: https://github.com/copycat-killer/lain -Warning -------- - -The update to 4.x is still in progress: if you experience issues, please report them in order to speed up the process. - Description ----------- From 65300b0098d1b005fd4c1ed9d54bc2a7912a289f Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 10 Jan 2017 13:14:04 +0100 Subject: [PATCH 023/106] readme updated; #260 --- README.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.rst b/README.rst index 563d46a..20ea0ce 100644 --- a/README.rst +++ b/README.rst @@ -10,6 +10,11 @@ Layouts, widgets and utilities for Awesome WM 4.x :License: GNU-GPL2_ :Source: https://github.com/copycat-killer/lain +Warning +------- + +If you still have to use branch 3.5.x, you can refer to the commit 301faf5_. Be aware that it's no longer supported, so update to 4.x ASAP. + Description ----------- @@ -42,6 +47,7 @@ Screenshots .. image:: http://i.imgur.com/STCPcaJ.png .. _GNU-GPL2: http://www.gnu.org/licenses/gpl-2.0.html +.. _201faf5: https://github.com/copycat-killer/lain/tree/301faf5370d045e94c9c344acb0fdac84a2f25a6 .. _awesome-vain: https://github.com/vain/awesome-vain .. _Awesome: https://github.com/awesomeWM/awesome .. _wiki: https://github.com/copycat-killer/lain/wiki From 617675d6c3a7b79d650bfcd52a3c13e8dcdfa459 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 10 Jan 2017 13:15:02 +0100 Subject: [PATCH 024/106] readme typo --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 20ea0ce..e37d210 100644 --- a/README.rst +++ b/README.rst @@ -47,7 +47,7 @@ Screenshots .. image:: http://i.imgur.com/STCPcaJ.png .. _GNU-GPL2: http://www.gnu.org/licenses/gpl-2.0.html -.. _201faf5: https://github.com/copycat-killer/lain/tree/301faf5370d045e94c9c344acb0fdac84a2f25a6 +.. _301faf5: https://github.com/copycat-killer/lain/tree/301faf5370d045e94c9c344acb0fdac84a2f25a6 .. _awesome-vain: https://github.com/vain/awesome-vain .. _Awesome: https://github.com/awesomeWM/awesome .. _wiki: https://github.com/copycat-killer/lain/wiki From ae086776bf94a932719899ec828e002f67ebd098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20D=C3=A9saulniers?= Date: Wed, 11 Jan 2017 00:15:23 -0500 Subject: [PATCH 025/106] bat: find battery status when multiple batteries Battery status was previously assumed to the first battery's status. This is wrong as it doesn't support the case where the first battery is full and the second is discharging, therefor showing battery percentage to 100% when the actual battery percentage is lower. --- widgets/bat.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/widgets/bat.lua b/widgets/bat.lua index 8e483f7..38104b5 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -108,7 +108,16 @@ local function worker(args) end end + -- When one of the battery is charging, others' status are either + -- "Full", "Unknown" or "Charging". When the laptop is not plugged in, + -- one or more of the batteries may be full, but only one battery + -- discharging suffices to set global status to "Discharging". bat_now.status = bat_now.n_status[1] + for _,status in ipairs(bat_now.n_status) do + if status == "Discharging" or status == "Charging" then + bat_now.status = status + end + end bat_now.ac_status = tonumber(first_line(string.format("%s%s/online", pspath, ac))) or "N/A" if bat_now.status ~= "N/A" then From 25af54505b724080278de5a6d3a34931d3537609 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 11 Jan 2017 17:53:21 +0100 Subject: [PATCH 026/106] wiki updated; closes #261 --- widgets/bat.lua | 8 +++++--- wiki | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/widgets/bat.lua b/widgets/bat.lua index 38104b5..0b1bc0c 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -7,8 +7,9 @@ --]] -local helpers = require("lain.helpers") local first_line = require("lain.helpers").first_line +local make_widget = require("lain.helpers").make_widget_textbox +local newtimer = require("lain.helpers").newtimer local naughty = require("naughty") local wibox = require("wibox") @@ -19,6 +20,7 @@ local math = { abs = math.abs, min = math.min } local string = { format = string.format } +local ipairs = ipairs local type = type local tonumber = tonumber local setmetatable = setmetatable @@ -27,7 +29,7 @@ local setmetatable = setmetatable -- lain.widgets.bat local function worker(args) - local bat = helpers.make_widget_textbox() + local bat = make_widget() local args = args or {} local timeout = args.timeout or 30 local batteries = args.batteries or (args.battery and {args.battery}) or {"BAT0"} @@ -172,7 +174,7 @@ local function worker(args) end end - helpers.newtimer(battery, timeout, bat.update) + newtimer(battery, timeout, bat.update) return bat end diff --git a/wiki b/wiki index 7ab4e0b..bcf8a8d 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 7ab4e0b101587030066c45f0b0a1950532bf8a98 +Subproject commit bcf8a8d6050cb57415d8bfa4260ea7547bff0833 From 7072b0805828af867fe4f22ee3360e8f9e052ea3 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Thu, 12 Jan 2017 12:43:29 +0100 Subject: [PATCH 027/106] #263 fix --- util/quake.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/util/quake.lua b/util/quake.lua index 6363578..4314a16 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -98,16 +98,16 @@ end function quake:compute_size() local geom = screen[self.screen].workarea - local width, height - if self.width <= 1 then width = math.floor(geom.width * self.width) - 2 * self.border end - if self.height <= 1 then height = math.floor(geom.height * self.height) end + local width, height = self.width, self.height + if width <= 1 then width = math.floor(geom.width * width) - 2 * self.border end + if height <= 1 then height = math.floor(geom.height * height) end local x, y if self.horiz == "left" then x = geom.x - elseif self.horiz == "right" then x = geom.width + geom.x - self.width - else x = geom.x + (geom.width - self.width)/2 end + elseif self.horiz == "right" then x = geom.width + geom.x - width + else x = geom.x + (geom.width - width)/2 end if self.vert == "top" then y = geom.y - elseif self.vert == "bottom" then y = geom.height + geom.y - self.height - else y = geom.y + (geom.height - self.height)/2 end + elseif self.vert == "bottom" then y = geom.height + geom.y - height + else y = geom.y + (geom.height - height)/2 end self.geometry = { x = x, y = y, width = width, height = height } end From 354fa23548674b83620ea69d42cffdd707e13dbf Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Thu, 12 Jan 2017 13:07:11 +0100 Subject: [PATCH 028/106] #263: followtag default to true; changing quake definition --- util/quake.lua | 2 +- wiki | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/util/quake.lua b/util/quake.lua index 4314a16..8a530f3 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -120,7 +120,7 @@ function quake:new(config) conf.extra = conf.extra or "" -- extra arguments conf.visible = conf.visible or false -- initially not visible conf.border = conf.border or 1 -- client border width - conf.followtag = conf.followtag or false -- spawn on currently focused screen + conf.followtag = conf.followtag or true -- spawn on currently focused screen conf.screen = conf.screen or awful.screen.focused() -- If width or height <= 1 this is a proportion of the workspace diff --git a/wiki b/wiki index bcf8a8d..9a9d036 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit bcf8a8d6050cb57415d8bfa4260ea7547bff0833 +Subproject commit 9a9d036e50fce8ba3fcd89a8f384743b0147b306 From d549219a2eaa9bcd8e9c2a3c65a0342dca74d1b1 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Thu, 12 Jan 2017 18:33:57 +0100 Subject: [PATCH 029/106] quake: skip_wibox option added #263; mpd: removed mpdcover script call (much faster now) --- layout/uselessfair.lua | 108 ------------------- layout/uselesspiral.lua | 123 --------------------- layout/uselesstile.lua | 231 ---------------------------------------- scripts/mpdcover | 65 ----------- util/quake.lua | 24 +++-- widgets/mpd.lua | 76 ++++++------- wiki | 2 +- 7 files changed, 50 insertions(+), 579 deletions(-) delete mode 100644 layout/uselessfair.lua delete mode 100644 layout/uselesspiral.lua delete mode 100644 layout/uselesstile.lua delete mode 100755 scripts/mpdcover diff --git a/layout/uselessfair.lua b/layout/uselessfair.lua deleted file mode 100644 index e1284e0..0000000 --- a/layout/uselessfair.lua +++ /dev/null @@ -1,108 +0,0 @@ - ---[[ - - Licensed under GNU General Public License v2 - * (c) 2014, projektile, worron - * (c) 2013, Luke Bonham - * (c) 2012, Josh Komoroske - * (c) 2010-2012, Peter Hofmann - ---]] - -local beautiful = require("beautiful") -local ipairs = ipairs -local math = { ceil = math.ceil, sqrt = math.sqrt, floor = math.floor, max = math.max } -local tonumber = tonumber - -local uselessfair = {} - --- Transformation functions -local function swap(geometry) - return { x = geometry.y, y = geometry.x, width = geometry.height, height = geometry.width } -end - --- Client geometry correction depending on useless gap and window border -local function size_correction(c, geometry, useless_gap) - geometry.width = math.max(geometry.width - 2 * c.border_width - useless_gap, 1) - geometry.height = math.max(geometry.height - 2 * c.border_width - useless_gap, 1) - geometry.x = geometry.x + useless_gap / 2 - geometry.y = geometry.y + useless_gap / 2 -end - --- Main tiling function -local function fair(p, orientation) - - -- Theme vars - local useless_gap = beautiful.useless_gap_width or 0 - local global_border = beautiful.global_border_width or 0 - - -- Aliases - local wa = p.workarea - local cls = p.clients - - -- Nothing to tile here - if #cls == 0 then return end - - -- Workarea size correction depending on useless gap and global border - wa.height = wa.height - 2 * global_border - useless_gap - wa.width = wa.width - 2 * global_border - useless_gap - wa.x = wa.x + useless_gap / 2 + global_border - wa.y = wa.y + useless_gap / 2 + global_border - - -- Geometry calculation - local row, col = 0, 0 - - local rows = math.ceil(math.sqrt(#cls)) - local cols = math.ceil(#cls / rows) - - for i, c in ipairs(cls) do - local g = {} - - -- find tile orientation for current client and swap geometry if need - local need_swap = (orientation == "east" and #cls <= 2) or (orientation == "south" and #cls > 2) - local area = need_swap and swap(wa) or wa - - -- calculate geometry - if #cls < (cols * rows) and row == cols - 1 then - g.width = area.width / (rows - ((cols * rows) - #cls)) - else - g.width = area.width / rows - end - - g.height = area.height / cols - g.x = area.x + col * g.width - g.y = area.y + row * g.height - - -- turn back to real if geometry was swapped - if need_swap then g = swap(g) end - - -- window size correction depending on useless gap and window border - size_correction(c, g, useless_gap) - - -- set geometry - c:geometry(g) - - -- update tile grid coordinates - col = i % rows - row = math.floor(i / rows) - end -end - --- Layout constructor -local function construct_layout(name, direction) - return { - name = name, - -- @p screen The screen number to tile - arrange = function(p) return fair(p, direction) end - } -end - --- Build layouts with different tile direction -uselessfair.vertical = construct_layout("uselessfair", "south") -uselessfair.horizontal = construct_layout("uselessfairh", "east") - --- Module aliase -uselessfair.arrange = uselessfair.vertical.arrange -uselessfair.name = uselessfair.vertical.name - -return uselessfair diff --git a/layout/uselesspiral.lua b/layout/uselesspiral.lua deleted file mode 100644 index c388961..0000000 --- a/layout/uselesspiral.lua +++ /dev/null @@ -1,123 +0,0 @@ - ---[[ - - Licensed under GNU General Public License v2 - * (c) 2014, projektile - * (c) 2013, Luke Bonham - * (c) 2009, Uli Schlachter - * (c) 2008, Julien Danjolu - ---]] - -local beautiful = require("beautiful") -local ipairs = ipairs -local tonumber = tonumber -local math = require("math") - -local uselesspiral = {} - -local function spiral(p, spiral) - -- A useless gap (like the dwm patch) can be defined with - -- beautiful.useless_gap_width. - local useless_gap = tonumber(beautiful.useless_gap_width) or 0 - if useless_gap < 0 then useless_gap = 0 end - - -- A global border can be defined with - -- beautiful.global_border_width - local global_border = tonumber(beautiful.global_border_width) or 0 - if global_border < 0 then global_border = 0 end - - -- Themes border width requires an offset - local bw = tonumber(beautiful.border_width) or 0 - - -- get our orientation right - local wa = p.workarea - local cls = p.clients - local n = #cls -- number of windows total; k = which window number - - wa.height = wa.height - ((global_border * 2) + (bw * 2)) - wa.width = wa.width - ((global_border * 2) + (bw * 2)) - - local static_wa = wa - - for k, c in ipairs(cls) do - if k < n then - if k % 2 == 0 then - wa.height = (wa.height / 2) - else - wa.width = (wa.width / 2) - end - end - - if k % 4 == 0 and spiral then - wa.x = wa.x - wa.width - elseif k % 2 == 0 or - (k % 4 == 3 and k < n and spiral) then - wa.x = wa.x + wa.width - end - - if k % 4 == 1 and k ~= 1 and spiral then - wa.y = wa.y - wa.height - elseif k % 2 == 1 and k ~= 1 or - (k % 4 == 0 and k < n and spiral) then - wa.y = wa.y + wa.height - end - - local wa2 = {} - wa2.x = wa.x + (useless_gap / 2) + global_border - wa2.y = wa.y + (useless_gap / 2) + global_border - wa2.height = wa.height - (useless_gap / 2) - wa2.width = wa.width - (useless_gap / 2) - - -- Useless gap. - if useless_gap > 0 - then - -- Top and left clients are shrinked by two steps and - -- get moved away from the border. Other clients just - -- get shrinked in one direction. - - top = false - left = false - - if wa2.y == static_wa.y then - top = true - end - - if wa2.x == static_wa.x then - left = true - end - - if top then - wa2.height = wa2.height - useless_gap - wa2.y = wa2.y - (useless_gap / 2) - else - wa2.height = wa2.height - (useless_gap / 2) - end - - if left then - wa2.width = wa2.width - useless_gap - wa2.x = wa2.x - (useless_gap / 2) - else - wa2.width = wa2.width - (useless_gap / 2) - end - end - -- End of useless gap. - - c:geometry(wa2) - end -end - ---- Dwindle layout -uselesspiral.dwindle = {} -uselesspiral.dwindle.name = "uselessdwindle" -function uselesspiral.dwindle.arrange(p) - return spiral(p, false) -end - ---- Spiral layout -uselesspiral.name = "uselesspiral" -function uselesspiral.arrange(p) - return spiral(p, true) -end - -return uselesspiral diff --git a/layout/uselesstile.lua b/layout/uselesstile.lua deleted file mode 100644 index ee33060..0000000 --- a/layout/uselesstile.lua +++ /dev/null @@ -1,231 +0,0 @@ - ---[[ - - Licensed under GNU General Public License v2 - * (c) 2014, projektile, worron - * (c) 2013, Luke Bonham - * (c) 2009, Donald Ephraim Curtis - * (c) 2008, Julien Danjolu - ---]] - -local tag = require("awful.tag") -local beautiful = require("beautiful") -local ipairs = ipairs -local math = { floor = math.floor, - ceil = math.ceil, - max = math.max, - min = math.min } -local tonumber = tonumber - -local uselesstile = {} - --- Transformation functions -local function flip(canvas, geometry) - return { - -- vertical only - x = 2 * canvas.x + canvas.width - geometry.x - geometry.width, - y = geometry.y, - width = geometry.width, - height = geometry.height - } -end - -local function swap(geometry) - return { x = geometry.y, y = geometry.x, width = geometry.height, height = geometry.width } -end - --- Find geometry for secondary windows column -local function cut_column(wa, n, index) - local width = math.floor(wa.width / n) - local area = { x = wa.x + (index - 1) * width, y = wa.y, width = width, height = wa.height } - - return area -end - --- Find geometry for certain window in column -local function cut_row(wa, factor, index, used) - local height = math.floor(wa.height * factor.window[index] / factor.total) - local area = { x = wa.x, y = wa.y + used, width = wa.width, height = height } - - return area -end - --- Client geometry correction depending on useless gap and window border -local function size_correction(c, geometry, useless_gap) - geometry.width = math.max(geometry.width - 2 * c.border_width - useless_gap, 1) - geometry.height = math.max(geometry.height - 2 * c.border_width - useless_gap, 1) - geometry.x = geometry.x + useless_gap / 2 - geometry.y = geometry.y + useless_gap / 2 -end - --- Check size factor for group of clients and calculate total -local function calc_factor(n, winfactors) - local factor = { window = winfactors, total = 0, min = 1 } - - for i = 1, n do - if not factor.window[i] then - factor.window[i] = factor.min - else - factor.min = math.min(factor.window[i], factor.min) - if factor.window[i] < 0.05 then factor.window[i] = 0.05 end - end - factor.total = factor.total + factor.window[i] - end - - return factor -end - --- Tile group of clients in given area --- @canvas need for proper transformation only --- @winfactors table with clients size factors -local function tile_column(canvas, area, list, useless_gap, transformation, winfactors) - local used = 0 - local factor = calc_factor(#list, winfactors) - - for i, c in ipairs(list) do - local g = cut_row(area, factor, i, used) - if i == #list then g.height = area.height - used end - used = used + g.height - - -- swap workarea dimensions - if transformation.flip then g = flip(canvas, g) end - if transformation.swap then g = swap(g) end - - -- useless gap and border correction - size_correction(c, g, useless_gap) - - - c:geometry(g) - end -end - ---Main tile function -local function tile(p, orientation) - - -- Theme vars - local useless_gap = beautiful.useless_gap_width or 0 - local global_border = beautiful.global_border_width or 0 - - -- Aliases - local wa = p.workarea - local cls = p.clients - local t = tag.selected(p.screen) - - -- Nothing to tile here - if #cls == 0 then return end - - -- Get tag prop - local nmaster = math.min(tag.getnmaster(t), #cls) - local mwfact = tag.getmwfact(t) - - if nmaster == 0 then - mwfact = 0 - elseif nmaster == #cls then - mwfact = 1 - end - - -- clients size factor - local data = tag.getdata(t).windowfact - - if not data then - data = {} - tag.getdata(t).windowfact = data - end - - -- Workarea size correction depending on useless gap and global border - wa.height = wa.height - 2 * global_border - useless_gap - wa.width = wa.width - 2 * global_border - useless_gap - wa.x = wa.x + useless_gap / 2 + global_border - wa.y = wa.y + useless_gap / 2 + global_border - - -- Find which transformation we need for given orientation - local transformation = { - swap = orientation == 'top' or orientation == 'bottom', - flip = orientation == 'left' or orientation == 'top' - } - - -- Swap workarea dimensions if orientation vertical - if transformation.swap then wa = swap(wa) end - - -- Split master and other windows - local cls_master, cls_other = {}, {} - - for i, c in ipairs(cls) do - if i <= nmaster then - table.insert(cls_master, c) - else - table.insert(cls_other, c) - end - end - - -- Tile master windows - local master_area = { - x = wa.x, - y = wa.y, - width = nmaster > 0 and math.floor(wa.width * mwfact) or 0, - height = wa.height - } - - if not data[0] then data[0] = {} end - tile_column(wa, master_area, cls_master, useless_gap, transformation, data[0]) - - -- Tile other windows - local other_area = { - x = wa.x + master_area.width, - y = wa.y, - width = wa.width - master_area.width, - height = wa.height - } - - -- get column number for other windows - local ncol = math.min(tag.getncol(t), #cls_other) - - if ncol == 0 then ncol = 1 end - - -- split other windows to column groups - local last_small_column = ncol - #cls_other % ncol - local rows_min = math.floor(#cls_other / ncol) - - local client_index = 1 - local used = 0 - for i = 1, ncol do - local position = transformation.flip and ncol - i + 1 or i - local rows = i <= last_small_column and rows_min or rows_min + 1 - local column = {} - - for j = 1, rows do - table.insert(column, cls_other[client_index]) - client_index = client_index + 1 - end - - -- and tile - local column_area = cut_column(other_area, ncol, position) - if i == ncol then column_area.width = other_area.width - used end - used = used + column_area.width - - if not data[i] then data[i] = {} end - tile_column(wa, column_area, column, useless_gap, transformation, data[i]) - end -end - --- Layout constructor -local function construct_layout(name, orientation) - return { - name = name, - -- @p screen number to tile - arrange = function(p) return tile(p, orientation) end - } -end - --- Build layouts with different tile direction -uselesstile.right = construct_layout("uselesstile", "right") -uselesstile.left = construct_layout("uselesstileleft", "left") -uselesstile.bottom = construct_layout("uselesstilebottom", "bottom") -uselesstile.top = construct_layout("uselesstiletop", "top") - --- Module aliase -uselesstile.arrange = uselesstile.right.arrange -uselesstile.name = uselesstile.right.name - -return uselesstile diff --git a/scripts/mpdcover b/scripts/mpdcover deleted file mode 100755 index a611666..0000000 --- a/scripts/mpdcover +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash -# -# A simple cover fetcher script for current playing song on mpd. -# -# Original author: Wolfgang Mueller -# -# Adapted for Lain internal use. -# https://github.com/copycat-killer/lain -# -# You can use, edit and redistribute this script in any way you like. -# -# Dependencies: imagemagick. -# -# Usage: mpdcover - -# Configuration------------------------------------------------------- - -# Music directory -MUSIC_DIR=$1 - -# Song file -file=$2 - -# Regex expression used for image search -IMG_REG="(Front|front|Cover|cover|Art|art|Folder|folder)\.(jpg|jpeg|png|gif)$" - -# Path of temporary resized cover -TEMP_PATH="/tmp/mpdcover.png" - -# Resize cover -COVER_RESIZE="$3x$3" - -if [ $COVER_RESIZE == "x" ]; then - COVER_RESIZE="100x100" -fi - -# The default cover to use (optional) -DEFAULT_ART=$4 - -#-------------------------------------------------------------------- - -# check if anything is playing at all -[[ -z $file ]] && exit 1 - -# Art directory -art="$MUSIC_DIR/${file%/*}" - -# find every file that matches IMG_REG set the first matching file to be the -# cover. -cover="$(find "$art/" -maxdepth 1 -type f | egrep -i -m1 "$IMG_REG")" - -# when no cover is found, use DEFAULT_ART as cover -cover="${cover:=$DEFAULT_ART}" - -# check if art is available -if [[ -n $cover ]]; then - if [[ -n $COVER_RESIZE ]]; then - convert "$cover" -scale $COVER_RESIZE "$TEMP_PATH" - cover="$TEMP_PATH" - fi -else - rm $TEMP_PATH -fi - -exit 0 diff --git a/util/quake.lua b/util/quake.lua index 8a530f3..9f548a8 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -97,7 +97,12 @@ function quake:display() end function quake:compute_size() - local geom = screen[self.screen].workarea + local geom + if self.skip_wibox then + geom = screen[self.screen].workarea + else + geom = screen[self.screen].geometry + end local width, height = self.width, self.height if width <= 1 then width = math.floor(geom.width * width) - 2 * self.border end if height <= 1 then height = math.floor(geom.height * height) end @@ -114,14 +119,15 @@ end function quake:new(config) local conf = config or {} - conf.app = conf.app or "xterm" -- application to spawn - conf.name = conf.name or "QuakeDD" -- window name - conf.argname = conf.argname or "-name %s" -- how to specify window name - conf.extra = conf.extra or "" -- extra arguments - conf.visible = conf.visible or false -- initially not visible - conf.border = conf.border or 1 -- client border width - conf.followtag = conf.followtag or true -- spawn on currently focused screen - conf.screen = conf.screen or awful.screen.focused() + conf.app = conf.app or "xterm" -- application to spawn + conf.name = conf.name or "QuakeDD" -- window name + conf.argname = conf.argname or "-name %s" -- how to specify window name + conf.extra = conf.extra or "" -- extra arguments + conf.visible = conf.visible or false -- initially not visible + conf.border = conf.border or 1 -- client border width + conf.followtag = conf.followtag or true -- spawn on currently focused screen + conf.skip_wibox = conf.skip_wibox or true -- skip the wibox (defaut) or overlap it + conf.screen = conf.screen or awful.screen.focused() -- If width or height <= 1 this is a proportion of the workspace conf.height = conf.height or 0.25 -- height diff --git a/widgets/mpd.lua b/widgets/mpd.lua index ce48014..ebdda98 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -7,20 +7,18 @@ --]] -local helpers = require("lain.helpers") local async = require("lain.asyncshell") +local helpers = require("lain.helpers") local escape_f = require("awful.util").escape local focused = require("awful.screen").focused local naughty = require("naughty") local wibox = require("wibox") -local os = { execute = os.execute, - getenv = os.getenv } -local math = { floor = math.floor } -local string = { format = string.format, - match = string.match, - gmatch = string.gmatch } +local os = { getenv = os.getenv } +local string = { format = string.format, + gmatch = string.gmatch, + match = string.match } local setmetatable = setmetatable @@ -29,22 +27,22 @@ local setmetatable = setmetatable local mpd = helpers.make_widget_textbox() local function worker(args) - local args = args or {} - local timeout = args.timeout or 2 - local password = args.password or "" - local host = args.host or "127.0.0.1" - local port = args.port or "6600" - local music_dir = args.music_dir or os.getenv("HOME") .. "/Music" - local cover_size = args.cover_size or 100 - local default_art = args.default_art or "" - local notify = args.notify or "on" - local followtag = args.followtag or false - local echo_cmd = args.echo_cmd or "echo" - local settings = args.settings or function() end + local args = args or {} + local timeout = args.timeout or 2 + local password = args.password or "" + local host = args.host or "127.0.0.1" + local port = args.port or "6600" + local music_dir = args.music_dir or os.getenv("HOME") .. "/Music" + local cover_pattern = args.cover_pattern or "*\\.(jpg|jpeg|png|gif)$" + local cover_size = args.cover_size or 100 + local default_art = args.default_art or "" + local notify = args.notify or "on" + local followtag = args.followtag or false + local echo_cmd = args.echo_cmd or "echo" + local settings = args.settings or function() end - local mpdcover = helpers.scripts_dir .. "mpdcover" - local mpdh = "telnet://" .. host .. ":" .. port - local echo = echo_cmd .. " 'password " .. password .. "\nstatus\ncurrentsong\nclose'" + local mpdh = string.format("telnet://%s:%s", host, port) + local echo = string.format("%s 'password %s\nstatus\ncurrentsong\nclose'", echo_cmd, password) mpd_notification_preset = { title = "Now playing", @@ -54,7 +52,7 @@ local function worker(args) helpers.set_map("current mpd track", nil) function mpd.update() - async.request(echo .. " | curl --connect-timeout 1 -fsm 3 " .. mpdh, function (f) + async.request(string.format("%s | curl --connect-timeout 1 -fsm 3 %s", echo, mpdh), function (f) mpd_now = { random_mode = false, single_mode = false, @@ -103,34 +101,28 @@ local function worker(args) widget = mpd.widget settings() - if mpd_now.state == "play" - then - if notify == "on" and mpd_now.title ~= helpers.get_map("current mpd track") - then + if mpd_now.state == "play" then + if notify == "on" and mpd_now.title ~= helpers.get_map("current mpd track") then helpers.set_map("current mpd track", mpd_now.title) - if string.match(mpd_now.file, "http.*://") == nil - then -- local file - os.execute(string.format("%s %q %q %d %q", mpdcover, music_dir, - mpd_now.file, cover_size, default_art)) - current_icon = "/tmp/mpdcover.png" - else -- http stream - current_icon = default_art + local current icon = default_art + + if not string.match(mpd_now.file, "http.*://") then -- local file instead of http stream + local path = string.format("%s/%s", music_dir, string.match(mpd_now.file, ".*/")) + local cover = string.format("find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'", path, cover_pattern) + current_icon = helpers.read_pipe(cover):gsub("\n", "") end - if followtag then - mpd_notification_preset.screen = focused() - end + if followtag then mpd_notification_preset.screen = focused() end mpd.id = naughty.notify({ - preset = mpd_notification_preset, - icon = os.execute(string.format("ls %s &> /dev/null", current_icon)) - and current_icon, + preset = mpd_notification_preset, + icon = current_icon, + icon_size = cover_size, replaces_id = mpd.id, }).id end - elseif mpd_now.state ~= "pause" - then + elseif mpd_now.state ~= "pause" then helpers.set_map("current mpd track", nil) end end) diff --git a/wiki b/wiki index 9a9d036..b0e838a 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 9a9d036e50fce8ba3fcd89a8f384743b0147b306 +Subproject commit b0e838ade84ae851bceb2479bb16c1447057abb7 From 03cd1abf3c61ccd8a3cbfe40317d8112eea8413e Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Thu, 12 Jan 2017 18:37:48 +0100 Subject: [PATCH 030/106] rockspec updated; @aajjbb: please update luarocks entry --- lain-git.rockspec | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lain-git.rockspec b/lain-git.rockspec index c3a7dbd..ce1480c 100644 --- a/lain-git.rockspec +++ b/lain-git.rockspec @@ -7,9 +7,9 @@ source = { description = { summary = "Layout, widgets and utilities for Awesome WM", detailed = [[ - Successor of awesome-vain, this module provides new layouts, a set of widgets and utility functions, in order to improve Awesome usability and configurability. + Successor of awesome-vain, this module provides new layouts, a set of widgets and utility functions, with the aim of Awesome usability and configurability. - Optional dependencies: alsa-utils (for alsamixer); curl; imagemagick. + Optional dependency: curl (for IMAP and weather widgets). ]], homepage = "https://github.com/copycat-killer/lain", license = "GPL v2" @@ -17,9 +17,7 @@ description = { dependencies = { "lua >= 5.3", "awesome >= 4.0", - "alsa-utils", - "curl", - "imagemagick" + "curl" } supported_platforms = { "linux" } build = { From 741b65d5eac36c8800610c2bad62ebd621998cc8 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Thu, 12 Jan 2017 20:35:59 +0100 Subject: [PATCH 031/106] quake: skip_wibox -> overlap and default to false, followtag redefault to faluse; closes #264 #265 --- README.rst | 3 ++- util/quake.lua | 20 ++++++++++---------- wiki | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.rst b/README.rst index e37d210..4072d35 100644 --- a/README.rst +++ b/README.rst @@ -31,7 +31,7 @@ Just make sure that: - Your code fits with the general style of the module. In particular, you should use the same indentation pattern that the code uses, and also avoid adding space at the ends of lines. -- Your code its easy to understand, maintainable, and modularized. You should also avoid code duplication wherever possible by adding functions or using ``lain.helpers``. If something is unclear, and you can't write it in such a way that it will be clear, explain it with a comment. +- Your code its easy to understand, maintainable, and modularized. You should also avoid code duplication wherever possible by adding functions or using lain.helpers_. If something is unclear, and you can't write it in such a way that it will be clear, explain it with a comment. - You test your changes before submitting to make sure that not only your code works, but did not break other parts of the module too! @@ -51,3 +51,4 @@ Screenshots .. _awesome-vain: https://github.com/vain/awesome-vain .. _Awesome: https://github.com/awesomeWM/awesome .. _wiki: https://github.com/copycat-killer/lain/wiki +.. _lain.helpers: https://github.com/copycat-killer/lain/blob/master/helpers.lua diff --git a/util/quake.lua b/util/quake.lua index 9f548a8..6e520b5 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -98,7 +98,7 @@ end function quake:compute_size() local geom - if self.skip_wibox then + if not self.overlap then geom = screen[self.screen].workarea else geom = screen[self.screen].geometry @@ -119,15 +119,15 @@ end function quake:new(config) local conf = config or {} - conf.app = conf.app or "xterm" -- application to spawn - conf.name = conf.name or "QuakeDD" -- window name - conf.argname = conf.argname or "-name %s" -- how to specify window name - conf.extra = conf.extra or "" -- extra arguments - conf.visible = conf.visible or false -- initially not visible - conf.border = conf.border or 1 -- client border width - conf.followtag = conf.followtag or true -- spawn on currently focused screen - conf.skip_wibox = conf.skip_wibox or true -- skip the wibox (defaut) or overlap it - conf.screen = conf.screen or awful.screen.focused() + conf.app = conf.app or "xterm" -- application to spawn + conf.name = conf.name or "QuakeDD" -- window name + conf.argname = conf.argname or "-name %s" -- how to specify window name + conf.extra = conf.extra or "" -- extra arguments + conf.border = conf.border or 1 -- client border width + conf.visible = conf.visible or false -- initially not visible + conf.followtag = conf.followtag or false -- spawn on currently focused screen + conf.overlap = conf.overlap or false -- overlap wibox + conf.screen = conf.screen or awful.screen.focused() -- If width or height <= 1 this is a proportion of the workspace conf.height = conf.height or 0.25 -- height diff --git a/wiki b/wiki index b0e838a..006cb79 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit b0e838ade84ae851bceb2479bb16c1447057abb7 +Subproject commit 006cb79c302aef03dd064430dd2ceba2689dacc7 From f849e631d64e7445ca8abde847191976447f0f93 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Thu, 12 Jan 2017 20:43:23 +0100 Subject: [PATCH 032/106] rockspec typo --- lain-git.rockspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lain-git.rockspec b/lain-git.rockspec index ce1480c..a264384 100644 --- a/lain-git.rockspec +++ b/lain-git.rockspec @@ -7,7 +7,7 @@ source = { description = { summary = "Layout, widgets and utilities for Awesome WM", detailed = [[ - Successor of awesome-vain, this module provides new layouts, a set of widgets and utility functions, with the aim of Awesome usability and configurability. + Successor of awesome-vain, this module provides new layouts, a set of widgets and utility functions, with the aim of improving Awesome usability and configurability. Optional dependency: curl (for IMAP and weather widgets). ]], From 61a2868452d9c4548dbf22c3119739e79f6ff902 Mon Sep 17 00:00:00 2001 From: aajjbb Date: Thu, 12 Jan 2017 18:01:40 -0200 Subject: [PATCH 033/106] fixing redshit spawn_with_shell to be compliant with awesome v4.0 --- widgets/contrib/redshift.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/widgets/contrib/redshift.lua b/widgets/contrib/redshift.lua index 3c4f749..0b54015 100644 --- a/widgets/contrib/redshift.lua +++ b/widgets/contrib/redshift.lua @@ -25,9 +25,9 @@ local function init() -- toggled off (i.e Awesome on-the-fly restart), kill redshift to make sure os.execute("pkill redshift") -- Remove existing color adjustment - awful.spawn_with_shell("redshift -x") + awful.util.spawn_with_shell("redshift -x") -- (Re)start redshift - awful.spawn_with_shell("redshift") + awful.util.spawn_with_shell("redshift") running = true active = true end From e2d9d4f1c815f8f84c230052d5c74cfcc7baf18b Mon Sep 17 00:00:00 2001 From: aajjbb Date: Thu, 12 Jan 2017 18:52:23 -0200 Subject: [PATCH 034/106] changing from awful.util.spawn_with_shell to awful.spawn.with_shell --- widgets/contrib/redshift.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/widgets/contrib/redshift.lua b/widgets/contrib/redshift.lua index 0b54015..25ae023 100644 --- a/widgets/contrib/redshift.lua +++ b/widgets/contrib/redshift.lua @@ -25,9 +25,9 @@ local function init() -- toggled off (i.e Awesome on-the-fly restart), kill redshift to make sure os.execute("pkill redshift") -- Remove existing color adjustment - awful.util.spawn_with_shell("redshift -x") + awful.spawn.with_shell("redshift -x") -- (Re)start redshift - awful.util.spawn_with_shell("redshift") + awful.spawn.with_shell("redshift") running = true active = true end From 669b0de47b35f99857e5e7060ae2cc425381c779 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Thu, 12 Jan 2017 22:46:19 +0100 Subject: [PATCH 035/106] quake: updated spawn call --- util/quake.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/quake.lua b/util/quake.lua index 6e520b5..c563695 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -54,9 +54,9 @@ function quake:display() if not client then -- The client does not exist, we spawn it - awful.spawn(string.format("%s %s %s", self.app, - string.format(self.argname, self.name), self.extra), - false, self.screen) + cmd = string.format("%s %s %s", self.app, + string.format(self.argname, self.name), self.extra) + awful.spawn(cmd, { tag = self.screen.selected_tag }) self.notexist = true return end From 430e70670c3f0a38c1c300273784096aeb8728cd Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 17 Jan 2017 19:13:45 +0100 Subject: [PATCH 036/106] layout: deprecations removed; submodule compacted --- README.rst | 2 +- .../{cascadebrowse.png => cascadetile.png} | Bin .../{cascadebrowsew.png => cascadetilew.png} | Bin icons/layout/default/centerhwork.png | Bin 247 -> 0 bytes icons/layout/default/centerhworkw.png | Bin 265 -> 0 bytes .../{cascadebrowse.png => cascadetile.png} | Bin icons/layout/zenburn/centerworkh.png | Bin 0 -> 251 bytes layout/cascade.lua | 206 +++++++++++---- layout/cascadetile.lua | 174 ------------- layout/centerfair.lua | 164 ------------ layout/centerhwork.lua | 136 ---------- layout/centerwork.lua | 216 +++++++++------- layout/centerworkd.lua | 123 --------- layout/termfair.lua | 243 +++++++++++++----- wiki | 2 +- 15 files changed, 459 insertions(+), 807 deletions(-) rename icons/layout/default/{cascadebrowse.png => cascadetile.png} (100%) rename icons/layout/default/{cascadebrowsew.png => cascadetilew.png} (100%) delete mode 100644 icons/layout/default/centerhwork.png delete mode 100644 icons/layout/default/centerhworkw.png rename icons/layout/zenburn/{cascadebrowse.png => cascadetile.png} (100%) create mode 100644 icons/layout/zenburn/centerworkh.png delete mode 100644 layout/cascadetile.lua delete mode 100644 layout/centerfair.lua delete mode 100644 layout/centerhwork.lua delete mode 100644 layout/centerworkd.lua diff --git a/README.rst b/README.rst index 4072d35..2bb89a8 100644 --- a/README.rst +++ b/README.rst @@ -13,7 +13,7 @@ Layouts, widgets and utilities for Awesome WM 4.x Warning ------- -If you still have to use branch 3.5.x, you can refer to the commit 301faf5_. Be aware that it's no longer supported, so update to 4.x ASAP. +If you still have to use branch 3.5.x, you can refer to the commit 301faf5_, but be aware that it's no longer supported. Description ----------- diff --git a/icons/layout/default/cascadebrowse.png b/icons/layout/default/cascadetile.png similarity index 100% rename from icons/layout/default/cascadebrowse.png rename to icons/layout/default/cascadetile.png diff --git a/icons/layout/default/cascadebrowsew.png b/icons/layout/default/cascadetilew.png similarity index 100% rename from icons/layout/default/cascadebrowsew.png rename to icons/layout/default/cascadetilew.png diff --git a/icons/layout/default/centerhwork.png b/icons/layout/default/centerhwork.png deleted file mode 100644 index 59c90f83912a7e9a3595b1f280eaddabc05186bb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 247 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP~CmS!L)ddcxaG+3&r;B4q#jUru47m;{2)H`(?)*R1 zyw)Re;hzKNUI%p^R^pOeT>1HH?82|wTc5A~&2p!E^2Xgn+a diff --git a/icons/layout/default/centerhworkw.png b/icons/layout/default/centerhworkw.png deleted file mode 100644 index 6866f44d0aa1e11b053eb1778948130980f6c8d9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 265 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=Y)RhkE^8!wY#&i4~CK%r@#E{-7;x8B~e=4vnya5%W8;=lHB zFONip)}IH?y(ipWE4E%+dRRH>>z(pvx2M)JzY|=#|F!MMnZ?z{m-B(f zfWZOJf)`gzcFPuD&Ug6rsO4&W-Q~0H)2Bb^JO41YHg^ZmIXHpCw7y^V2iQC&sd!FO a$*kkAY*z_gE%SUPNQ0-VpUXO@geCy!dR6cM diff --git a/icons/layout/zenburn/cascadebrowse.png b/icons/layout/zenburn/cascadetile.png similarity index 100% rename from icons/layout/zenburn/cascadebrowse.png rename to icons/layout/zenburn/cascadetile.png diff --git a/icons/layout/zenburn/centerworkh.png b/icons/layout/zenburn/centerworkh.png new file mode 100644 index 0000000000000000000000000000000000000000..00beeb50c49d50ade2e964925de8e14afe6db535 GIT binary patch literal 251 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPtqo9D8#P!=>ZGb`@o-U3d6}R4AcjP^wz~gYyNOx+3 z1B=qaxNWaRHmKJAKeqCNlSjvdDD!*WtM>ZwouBji^iDy+@bA(FVdQ&MBb@0MQLa AJpcdz literal 0 HcmV?d00001 diff --git a/layout/cascade.lua b/layout/cascade.lua index 3d7598b..2397a1d 100644 --- a/layout/cascade.lua +++ b/layout/cascade.lua @@ -8,72 +8,186 @@ --]] -local tag = require("awful.tag") -local beautiful = require("beautiful") +local tag = require("awful.tag") +local tonumber = tonumber -local cascade = -{ +local cascade = { name = "cascade", nmaster = 0, offset_x = 32, - offset_y = 8 + offset_y = 8, + tile = { + name = "cascadetile", + nmaster = 0, + ncol = 0, + mwfact = 0, + offset_x = 5, + offset_y = 32, + extra_padding = 0 + } } -function cascade.arrange(p) - - -- Cascade windows. - - -- A global border can be defined with - -- beautiful.global_border_width. - local global_border = tonumber(beautiful.global_border_width) or 0 - if global_border < 0 then global_border = 0 end - +local function do_cascade(p, tiling) -- Screen. - local wa = p.workarea + local wa = p.workarea local cls = p.clients - wa.height = wa.height - (global_border * 2) - wa.width = wa.width - (global_border * 2) - wa.x = wa.x + global_border - wa.y = wa.y + global_border + if #cls <= 0 then return end - -- Opening a new window will usually force all existing windows to - -- get resized. This wastes a lot of CPU time. So let's set a lower - -- bound to "how_many": This wastes a little screen space but you'll - -- get a much better user experience. - local t = tag.selected(p.screen) - local num_c - if cascade.nmaster > 0 - then - num_c = cascade.nmaster + -- Useless gaps. + local useless_gap = tag.gap or 0 + + if not tiling then + -- Cascade windows. + + local num_c + if cascade.nmaster > 0 then + num_c = cascade.nmaster + else + num_c = tag.master_count + end + + -- Opening a new window will usually force all existing windows to + -- get resized. This wastes a lot of CPU time. So let's set a lower + -- bound to "how_many": This wastes a little screen space but you'll + -- get a much better user experience. + local how_many = (#cls >= num_c and #cls) or num_c + + local current_offset_x = cascade.offset_x * (how_many - 1) + local current_offset_y = cascade.offset_y * (how_many - 1) + + -- Iterate. + for i = 1,#cls,1 do + local c = cls[i] + local g = {} + + g.x = wa.x + (how_many - i) * cascade.offset_x + g.y = wa.y + (i - 1) * cascade.offset_y + g.width = wa.width - current_offset_x - 2*c.border_width + g.height = wa.height - current_offset_y - 2*c.border_width + + if g.width < 1 then g.width = 1 end + if g.height < 1 then g.height = 1 end + + c:geometry(g) + end else - num_c = tag.getnmaster(t) - end + -- Layout with one fixed column meant for a master window. Its + -- width is calculated according to mwfact. Other clients are + -- cascaded or "tabbed" in a slave column on the right. - local how_many = #cls - if how_many < num_c - then - how_many = num_c - end + -- (1) (2) (3) (4) + -- +----------+---+ +----------+---+ +----------+---+ +----------+---+ + -- | | | | | 3 | | | 4 | | +---+| + -- | | | -> | | | -> | +---++ -> | +---+|+ + -- | 1 | 2 | | 1 +---++ | 1 | 3 || | 1 +---+|+| + -- | | | | | 2 || | +---++| | +---+|+ | + -- | | | | | || | | 2 | | | | 2 |+ | + -- +----------+---+ +---------+---++ +--------+---+-+ +------+---+---+ - local current_offset_x = cascade.offset_x * (how_many - 1) - local current_offset_y = cascade.offset_y * (how_many - 1) + local mwfact + if cascade.tile.mwfact > 0 then + mwfact = cascade.tile.mwfact + else + mwfact = tag.getmwfact(t) + end - -- Iterate. - for i = 1,#cls,1 - do - local c = cls[i] + -- Make slave windows overlap main window? Do this if ncol is 1. + local overlap_main + if cascade.tile.ncol > 0 then + overlap_main = cascade.tile.ncol + else + overlap_main = tag.column_count + end + + -- Minimum space for slave windows? See cascade.tile.lua. + local num_c + if cascade.tile.nmaster > 0 then + num_c = cascade.tile.nmaster + else + num_c = tag.master_count + end + + local how_many = (#cls - 1 >= num_c and (#cls - 1)) or num_c + + local current_offset_x = cascade.tile.offset_x * (how_many - 1) + local current_offset_y = cascade.tile.offset_y * (how_many - 1) + + if #cls <= 0 then return end + + -- Main column, fixed width and height. + local c = cls[1] local g = {} + -- Subtracting the useless_gap width from the work area width here + -- makes this mwfact calculation work the same as in uselesstile. + -- Rounding is necessary to prevent the rendered size of slavewid + -- from being 1 pixel off when the result is not an integer. + local mainwid = math.floor((wa.width - useless_gap) * mwfact) + local slavewid = wa.width - mainwid - g.x = wa.x + (how_many - i) * cascade.offset_x - g.y = wa.y + (i - 1) * cascade.offset_y - g.width = wa.width - current_offset_x - 2*c.border_width - g.height = wa.height - current_offset_y - 2*c.border_width + if overlap_main == 1 then + g.width = wa.width - 2*c.border_width + + -- The size of the main window may be reduced a little bit. + -- This allows you to see if there are any windows below the + -- main window. + -- This only makes sense, though, if the main window is + -- overlapping everything else. + g.width = g.width - cascade.tile.extra_padding + else + g.width = mainwid - 2*c.border_width + end + + g.height = wa.height - 2*c.border_width + g.x = wa.x + g.y = wa.y + if useless_gap > 0 then + -- Reduce width once and move window to the right. + -- Reduce height twice, however. + g.width = g.width - useless_gap + g.height = g.height - 2 * useless_gap + g.x = g.x + useless_gap + g.y = g.y + useless_gap + + -- When there's no window to the right, add an additional gap. + if overlap_main == 1 then g.width = g.width - useless_gap end + end if g.width < 1 then g.width = 1 end if g.height < 1 then g.height = 1 end - c:geometry(g) + + -- Remaining clients stacked in slave column, new ones on top. + if #cls > 1 then + for i = 2,#cls do + c = cls[i] + g = {} + g.width = slavewid - current_offset_x - 2*c.border_width + g.height = wa.height - current_offset_y - 2*c.border_width + g.x = wa.x + mainwid + (how_many - (i - 1)) * cascade.tile.offset_x + g.y = wa.y + (i - 2) * cascade.tile.offset_y + + if useless_gap > 0 then + g.width = g.width - 2 * useless_gap + g.height = g.height - 2 * useless_gap + g.x = g.x + useless_gap + g.y = g.y + useless_gap + end + + if g.width < 1 then g.width = 1 end + if g.height < 1 then g.height = 1 end + + c:geometry(g) + end + end end end +function cascade.tile.arrange(p) + return do_cascade(p, true) +end + +function cascade.arrange(p) + return do_cascade(p, false) +end + return cascade diff --git a/layout/cascadetile.lua b/layout/cascadetile.lua deleted file mode 100644 index 3baf3e9..0000000 --- a/layout/cascadetile.lua +++ /dev/null @@ -1,174 +0,0 @@ - ---[[ - - Licensed under GNU General Public License v2 - * (c) 2014, projektile - * (c) 2013, Luke Bonham - * (c) 2010-2012, Peter Hofmann - ---]] - -local tag = require("awful.tag") -local beautiful = require("beautiful") -local tonumber = tonumber - -local cascadetile = -{ - name = "cascadetile", - nmaster = 0, - ncol = 0, - mwfact = 0, - offset_x = 5, - offset_y = 32, - extra_padding = 0 -} - -function cascadetile.arrange(p) - - -- Layout with one fixed column meant for a master window. Its - -- width is calculated according to mwfact. Other clients are - -- cascaded or "tabbed" in a slave column on the right. - - -- It's a bit hard to demonstrate the behaviour with ASCII-images... - -- - -- (1) (2) (3) (4) - -- +----------+---+ +----------+---+ +----------+---+ +----------+---+ - -- | | | | | 3 | | | 4 | | +---+| - -- | | | -> | | | -> | +---++ -> | +---+|+ - -- | 1 | 2 | | 1 +---++ | 1 | 3 || | 1 +---+|+| - -- | | | | | 2 || | +---++| | +---+|+ | - -- | | | | | || | | 2 | | | | 2 |+ | - -- +----------+---+ +---------+---++ +--------+---+-+ +------+---+---+ - - -- A useless gap (like the dwm patch) can be defined with - -- beautiful.useless_gap_width. - local useless_gap = tonumber(beautiful.useless_gap_width) or 0 - if useless_gap < 0 then useless_gap = 0 end - - -- A global border can be defined with - -- beautiful.global_border_width - local global_border = tonumber(beautiful.global_border_width) or 0 - if global_border < 0 then global_border = 0 end - - -- Screen. - local wa = p.workarea - local cls = p.clients - - -- Borders are factored in. - wa.height = wa.height - (global_border * 2) - wa.width = wa.width - (global_border * 2) - wa.x = wa.x + global_border - wa.y = wa.y + global_border - - -- Width of main column? - local t = tag.selected(p.screen) - local mwfact - if cascadetile.mwfact > 0 - then - mwfact = cascadetile.mwfact - else - mwfact = tag.getmwfact(t) - end - - -- Make slave windows overlap main window? Do this if ncol is 1. - local overlap_main - if cascadetile.ncol > 0 - then - overlap_main = cascadetile.ncol - else - overlap_main = tag.getncol(t) - end - - -- Minimum space for slave windows? See cascade.lua. - local num_c - if cascadetile.nmaster > 0 - then - num_c = cascadetile.nmaster - else - num_c = tag.getnmaster(t) - end - - local how_many = #cls - 1 - if how_many < num_c - then - how_many = num_c - end - local current_offset_x = cascadetile.offset_x * (how_many - 1) - local current_offset_y = cascadetile.offset_y * (how_many - 1) - - if #cls > 0 - then - -- Main column, fixed width and height. - local c = cls[1] - local g = {} - -- Subtracting the useless_gap width from the work area width here - -- makes this mwfact calculation work the same as in uselesstile. - -- Rounding is necessary to prevent the rendered size of slavewid - -- from being 1 pixel off when the result is not an integer. - local mainwid = math.floor((wa.width - useless_gap) * mwfact) - local slavewid = wa.width - mainwid - - if overlap_main == 1 - then - g.width = wa.width - 2*c.border_width - - -- The size of the main window may be reduced a little bit. - -- This allows you to see if there are any windows below the - -- main window. - -- This only makes sense, though, if the main window is - -- overlapping everything else. - g.width = g.width - cascadetile.extra_padding - else - g.width = mainwid - 2*c.border_width - end - - g.height = wa.height - 2*c.border_width - g.x = wa.x - g.y = wa.y - if useless_gap > 0 - then - -- Reduce width once and move window to the right. Reduce - -- height twice, however. - g.width = g.width - useless_gap - g.height = g.height - 2 * useless_gap - g.x = g.x + useless_gap - g.y = g.y + useless_gap - - -- When there's no window to the right, add an additional - -- gap. - if overlap_main == 1 - then - g.width = g.width - useless_gap - end - end - if g.width < 1 then g.width = 1 end - if g.height < 1 then g.height = 1 end - c:geometry(g) - - -- Remaining clients stacked in slave column, new ones on top. - if #cls > 1 - then - for i = 2,#cls - do - c = cls[i] - g = {} - g.width = slavewid - current_offset_x - 2*c.border_width - g.height = wa.height - current_offset_y - 2*c.border_width - g.x = wa.x + mainwid + (how_many - (i - 1)) * cascadetile.offset_x - g.y = wa.y + (i - 2) * cascadetile.offset_y - if useless_gap > 0 - then - g.width = g.width - 2 * useless_gap - g.height = g.height - 2 * useless_gap - g.x = g.x + useless_gap - g.y = g.y + useless_gap - end - if g.width < 1 then g.width = 1 end - if g.height < 1 then g.height = 1 end - c:geometry(g) - end - end - end -end - -return cascadetile diff --git a/layout/centerfair.lua b/layout/centerfair.lua deleted file mode 100644 index 5022726..0000000 --- a/layout/centerfair.lua +++ /dev/null @@ -1,164 +0,0 @@ - ---[[ - - Licensed under GNU General Public License v2 - * (c) 2014, projektile - * (c) 2013, Luke Bonham - * (c) 2010, Nicolas Estibals - * (c) 2010-2012, Peter Hofmann - ---]] - -local tag = require("awful.tag") -local beautiful = require("beautiful") -local math = { ceil = math.ceil, - floor = math.floor, - max = math.max } -local tonumber = tonumber - -local centerfair = { name = "centerfair" } - -function centerfair.arrange(p) - -- Layout with fixed number of vertical columns (read from nmaster). - -- Cols are centerded until there is nmaster columns, then windows - -- are stacked in the slave columns, with at most ncol clients per - -- column if possible. - - -- with nmaster=3 and ncol=1 you'll have - -- (1) (2) (3) - -- +---+---+---+ +-+---+---+-+ +---+---+---+ - -- | | | | | | | | | | | | | - -- | | 1 | | -> | | 1 | 2 | | -> | 1 | 2 | 3 | -> - -- | | | | | | | | | | | | | - -- +---+---+---+ +-+---+---+-+ +---+---+---+ - - -- (4) (5) - -- +---+---+---+ +---+---+---+ - -- | | | 3 | | | 2 | 4 | - -- + 1 + 2 +---+ -> + 1 +---+---+ - -- | | | 4 | | | 3 | 5 | - -- +---+---+---+ +---+---+---+ - - -- A useless gap (like the dwm patch) can be defined with - -- beautiful.useless_gap_width . - local useless_gap = tonumber(beautiful.useless_gap_width) or 0 - if useless_gap < 0 then useless_gap = 0 end - - -- A global border can be defined with - -- beautiful.global_border_width - local global_border = tonumber(beautiful.global_border_width) or 0 - if global_border < 0 then global_border = 0 end - - -- Screen. - local wa = p.workarea - local cls = p.clients - - -- Borders are factored in. - wa.height = wa.height - (global_border * 2) - wa.width = wa.width - (global_border * 2) - wa.x = wa.x + global_border - wa.y = wa.y + global_border - - -- How many vertical columns? Read from nmaster on the tag. - local t = tag.selected(p.screen) - local num_x = centerfair.nmaster or tag.getnmaster(t) - local ncol = centerfair.ncol or tag.getncol(t) - if num_x <= 2 then num_x = 2 end - - local width = math.floor((wa.width - (num_x + 1)*useless_gap) / num_x) - - if #cls < num_x - then - -- Less clients than the number of columns, let's center it! - local offset_x = wa.x + (wa.width - #cls*width - (#cls - 1)*useless_gap) / 2 - local g = {} - g.y = wa.y + useless_gap - for i = 1, #cls do - local c = cls[i] - g.width = width - 2*c.border_width - g.height = wa.height - 2*useless_gap - 2*c.border_width - if g.width < 1 then g.width = 1 end - if g.height < 1 then g.height = 1 end - g.x = offset_x + (i - 1) * (width + useless_gap) - c:geometry(g) - end - else - -- More clients than the number of columns, let's arrange it! - -- Master client deserves a special treatement - local c = cls[1] - local g = {} - g.width = wa.width - (num_x - 1)*width - (num_x + 1)*useless_gap - 2*c.border_width - g.height = wa.height - 2*useless_gap - 2*c.border_width - if g.width < 1 then g.width = 1 end - if g.height < 1 then g.height = 1 end - g.x = wa.x + useless_gap - g.y = wa.y + useless_gap - - c:geometry(g) - - -- Treat the other clients - - -- Compute distribution of clients among columns - local num_y ={} - do - local remaining_clients = #cls-1 - local ncol_min = math.ceil(remaining_clients/(num_x-1)) - if ncol >= ncol_min - then - for i = (num_x-1), 1, -1 do - if (remaining_clients-i+1) < ncol - then - num_y[i] = remaining_clients-i + 1 - else - num_y[i] = ncol - end - remaining_clients = remaining_clients - num_y[i] - end - else - local rem = remaining_clients % (num_x-1) - if rem ==0 - then - for i = 1, num_x-1 do - num_y[i] = ncol_min - end - else - for i = 1, num_x-1 do - num_y[i] = ncol_min - 1 - end - for i = 0, rem-1 do - num_y[num_x-1-i] = num_y[num_x-1-i] + 1 - end - end - end - end - - -- Compute geometry of the other clients - local nclient = 2 -- we start with the 2nd client - g.x = g.x + g.width + useless_gap + 2*c.border_width - - for i = 1, (num_x-1) do - local height = math.floor((wa.height - (num_y[i] + 1)*useless_gap) / num_y[i]) - g.y = wa.y + useless_gap - for j = 0, (num_y[i]-2) do - local c = cls[nclient] - g.height = height - 2*c.border_width - g.width = width - 2*c.border_width - if g.width < 1 then g.width = 1 end - if g.height < 1 then g.height = 1 end - c:geometry(g) - nclient = nclient + 1 - g.y = g.y + height + useless_gap - end - local c = cls[nclient] - g.height = wa.height - (num_y[i] + 1)*useless_gap - (num_y[i] - 1)*height - 2*c.border_width - g.width = width - 2*c.border_width - if g.width < 1 then g.width = 1 end - if g.height < 1 then g.height = 1 end - c:geometry(g) - nclient = nclient + 1 - g.x = g.x + width + useless_gap - end - end -end - -return centerfair diff --git a/layout/centerhwork.lua b/layout/centerhwork.lua deleted file mode 100644 index 14b1b01..0000000 --- a/layout/centerhwork.lua +++ /dev/null @@ -1,136 +0,0 @@ - ---[[ - - Licensed under GNU General Public License v2 - * (c) 2015, Joerg Jaspert - * (c) 2014, projektile - * (c) 2013, Luke Bonham - * (c) 2010-2012, Peter Hofmann - ---]] - -local awful = require("awful") -local beautiful = require("beautiful") -local tonumber = tonumber - -local centerhwork = -{ - name = "centerhwork", - top_left = 0, - top_right = 1, - bottom_left = 2, - bottom_right = 3 -} - -function centerhwork.arrange(p) - -- A useless gap (like the dwm patch) can be defined with - -- beautiful.useless_gap_width . - local useless_gap = tonumber(beautiful.useless_gap_width) or 0 - - -- A global border can be defined with - -- beautiful.global_border_width - local global_border = tonumber(beautiful.global_border_width) or 0 - if global_border < 0 then global_border = 0 end - - -- Screen. - local wa = p.workarea - local cls = p.clients - - -- Borders are factored in. - wa.height = wa.height - (global_border * 2) - wa.width = wa.width - (global_border * 2) - wa.x = wa.x + global_border - wa.y = wa.y + global_border - - -- Width of main column? - local t = awful.tag.selected(p.screen) - local mwfact = awful.tag.getmwfact(t) - - if #cls > 0 - then - -- Main column, fixed width and height. - local c = cls[1] - local g = {} - local mainhei = math.floor(wa.height * mwfact) - local slaveLwid = math.floor(wa.width / 2 ) - local slaveRwid = wa.width - slaveLwid - local slavehei = wa.height - mainhei - local slaveThei = math.floor(slavehei / 2) - local slaveBhei = slavehei - slaveThei - local Lhalfgap = math.floor(useless_gap / 2) - local Rhalfgap = useless_gap - Lhalfgap - - g.height = mainhei - 2*c.border_width - g.width = wa.width - 2*useless_gap - 2*c.border_width - g.x = wa.x + useless_gap - g.y = wa.y + slaveThei - - if g.width < 1 then g.width = 1 end - if g.height < 1 then g.height = 1 end - c:geometry(g) - - -- Auxiliary windows. - if #cls > 1 - then - local at = 0 - for i = 2,#cls - do - -- It's all fixed. If there are more than 5 clients, - -- those additional clients will float. This is - -- intentional. - if at == 4 - then - break - end - - c = cls[i] - g = {} - - if i - 2 == centerhwork.top_left - then - -- top left - g.x = wa.x + useless_gap - g.y = wa.y + useless_gap - g.width = slaveLwid - useless_gap - Lhalfgap - 2*c.border_width - g.height = slaveThei - 2*useless_gap - 2*c.border_width - elseif i - 2 == centerhwork.top_right - then - -- top right - g.x = wa.x + slaveLwid + Rhalfgap - g.y = wa.y + useless_gap - g.width = slaveRwid - useless_gap - Rhalfgap - 2*c.border_width - g.height = slaveThei - 2*useless_gap - 2*c.border_width - elseif i - 2 == centerhwork.bottom_left - then - -- bottom left - g.x = wa.x + useless_gap - g.y = wa.y + mainhei + slaveThei + useless_gap - g.width = slaveLwid - useless_gap - Lhalfgap - 2*c.border_width - g.height = slaveBhei - 2*useless_gap - 2*c.border_width - elseif i - 2 == centerhwork.bottom_right - then - -- bottom right - g.x = wa.x + slaveLwid + Rhalfgap - g.y = wa.y + mainhei + slaveThei + useless_gap - g.width = slaveRwid - useless_gap - Rhalfgap - 2*c.border_width - g.height = slaveBhei - 2*useless_gap - 2*c.border_width - end - - if g.width < 1 then g.width = 1 end - if g.height < 1 then g.height = 1 end - c:geometry(g) - - at = at + 1 - end - - -- Set remaining clients to floating. - for i = (#cls - 1 - 4),1,-1 - do - c = cls[i] - awful.client.floating.set(c, true) - end - end - end -end - -return centerhwork diff --git a/layout/centerwork.lua b/layout/centerwork.lua index 954826e..ce3d9e8 100644 --- a/layout/centerwork.lua +++ b/layout/centerwork.lua @@ -2,135 +2,157 @@ --[[ Licensed under GNU General Public License v2 + * (c) 2016, Henrik Antonsson + * (c) 2015, Joerg Jaspert * (c) 2014, projektile * (c) 2013, Luke Bonham * (c) 2010-2012, Peter Hofmann --]] -local awful = require("awful") -local beautiful = require("beautiful") +local tag = require("awful.tag") local tonumber = tonumber local math = { floor = math.floor } -local centerwork = -{ +local centerwork = { name = "centerwork", - top_right = 0, - bottom_right = 1, - bottom_left = 2, - top_left = 3 + horizontal = { name = "centerworkh" } } -function centerwork.arrange(p) - -- A useless gap (like the dwm patch) can be defined with - -- beautiful.useless_gap_width . - local useless_gap = tonumber(beautiful.useless_gap_width) or 0 - - -- A global border can be defined with - -- beautiful.global_border_width - local global_border = tonumber(beautiful.global_border_width) or 0 - if global_border < 0 then global_border = 0 end - +local function do_centerwork(p, orientation) -- Screen. - local wa = p.workarea + local wa = p.workarea local cls = p.clients - -- Borders are factored in. - wa.height = wa.height - (global_border * 2) - wa.width = wa.width - (global_border * 2) - wa.x = wa.x + global_border - wa.y = wa.y + global_border + if #cls <= 0 then return end - -- Width of main column? - local t = awful.tag.selected(p.screen) - local mwfact = awful.tag.getmwfact(t) + -- Useless gaps. + local useless_gap = tag.gap or 0 - if #cls > 0 - then - -- Main column, fixed width and height. - local c = cls[1] - local g = {} - local mainwid = math.floor(wa.width * mwfact) - local slavewid = wa.width - mainwid - local slaveLwid = math.floor(slavewid / 2) - local slaveRwid = slavewid - slaveLwid - local slaveThei = math.floor(wa.height / 2) - local slaveBhei = wa.height - slaveThei - local Thalfgap = math.floor(useless_gap / 2) - local Bhalfgap = useless_gap - Thalfgap + local c = cls[1] + local g = {} + + -- Main column, fixed width and height. + local mwfact = tag.object.get_master_width_factor(t) + local mainhei = math.floor(wa.height * mwfact) + local mainwid = math.floor(wa.width * mwfact) + local slavewid = wa.width - mainwid + local slaveLwid = math.floor(slavewid / 2) + local slaveRwid = slavewid - slaveLwid + local slavehei = wa.height - mainhei + local slaveThei = math.floor(slavehei / 2) + local slaveBhei = slavehei - slaveThei + local nbrFirstSlaves = math.floor(#cls / 2) + local nbrSecondSlaves = math.floor((#cls - 1) / 2) + + local slaveFirstDim, slaveSecondDim = 0, 0 + + if orientation == "vertical" then + if nbrFirstSlaves > 0 then slaveFirstDim = math.floor(wa.height / nbrFirstSlaves) end + if nbrSecondSlaves > 0 then slaveSecondDim = math.floor(wa.height / nbrSecondSlaves) end g.height = wa.height - 2*useless_gap - 2*c.border_width - g.width = mainwid - 2*c.border_width + g.width = mainwid - 2*c.border_width + g.x = wa.x + slaveLwid g.y = wa.y + useless_gap + else + if nbrFirstSlaves > 0 then slaveFirstDim = math.floor(wa.width / nbrFirstSlaves) end + if nbrSecondSlaves > 0 then slaveSecondDim = math.floor(wa.width / nbrSecondSlaves) end - if g.width < 1 then g.width = 1 end - if g.height < 1 then g.height = 1 end - c:geometry(g) + g.height = mainhei - 2*c.border_width + g.width = wa.width - 2*useless_gap - 2*c.border_width - -- Auxiliary windows. - if #cls > 1 - then - local at = 0 - for i = 2,#cls - do - -- It's all fixed. If there are more than 5 clients, - -- those additional clients will float. This is - -- intentional. - if at == 4 - then - break + g.x = wa.x + useless_gap + g.y = wa.y + slaveThei + end + + if g.width < 1 then g.width = 1 end + if g.height < 1 then g.height = 1 end + + c:geometry(g) + + -- Auxiliary windows. + if #cls <= 1 then return end + for i = 2,#cls do + local c = cls[i] + local g = {} + + local rowIndex = math.floor(i/2) + + if orientation == "vertical" then + if i % 2 == 0 then + -- left slave + g.x = wa.x + useless_gap + g.y = wa.y + useless_gap + (rowIndex-1)*slaveFirstDim + + g.width = slaveLwid - 2*useless_gap - 2*c.border_width + + -- if last slave in left row use remaining space for that slave + if rowIndex == nbrFirstSlaves then + g.height = wa.y + wa.height - g.y - useless_gap - 2*c.border_width + else + g.height = slaveFirstDim - useless_gap - 2*c.border_width end + else + -- right slave + g.x = wa.x + slaveLwid + mainwid + useless_gap + g.y = wa.y + useless_gap + (rowIndex-1)*slaveSecondDim - c = cls[i] - g = {} + g.width = slaveRwid - 2*useless_gap - 2*c.border_width - if i - 2 == centerwork.top_left - then - -- top left - g.x = wa.x + useless_gap - g.y = wa.y + useless_gap - g.width = slaveLwid - 2*useless_gap - 2*c.border_width - g.height = slaveThei - useless_gap - Thalfgap - 2*c.border_width - elseif i - 2 == centerwork.top_right - then - -- top right - g.x = wa.x + slaveLwid + mainwid + useless_gap - g.y = wa.y + useless_gap - g.width = slaveRwid - 2*useless_gap - 2*c.border_width - g.height = slaveThei - useless_gap - Thalfgap - 2*c.border_width - elseif i - 2 == centerwork.bottom_left - then - -- bottom left - g.x = wa.x + useless_gap - g.y = wa.y + slaveThei + Bhalfgap - g.width = slaveLwid - 2*useless_gap - 2*c.border_width - g.height = slaveBhei - useless_gap - Bhalfgap - 2*c.border_width - elseif i - 2 == centerwork.bottom_right - then - -- bottom right - g.x = wa.x + slaveLwid + mainwid + useless_gap - g.y = wa.y + slaveThei + Bhalfgap - g.width = slaveRwid - 2*useless_gap - 2*c.border_width - g.height = slaveBhei - useless_gap - Bhalfgap - 2*c.border_width + -- if last slave in right row use remaining space for that slave + if rowIndex == nbrSecondSlaves then + g.height = wa.y + wa.height - g.y - useless_gap - 2*c.border_width + else + g.height = slaveSecondDim - useless_gap - 2*c.border_width end - - if g.width < 1 then g.width = 1 end - if g.height < 1 then g.height = 1 end - c:geometry(g) - - at = at + 1 end + else + if i % 2 == 0 then + -- top slave + g.x = wa.x + useless_gap + (rowIndex-1)*slaveFirstDim + g.y = wa.y + useless_gap + + g.height = slaveThei - 2*useless_gap - 2*c.border_width + + -- if last slave in top row use remaining space for that slave + if rowIndex == nbrFirstSlaves then + g.width = wa.x + wa.width - g.x - useless_gap - 2*c.border_width + else + g.width = slaveFirstDim - useless_gap - 2*c.border_width + end + else + -- bottom slave + g.x = wa.x + useless_gap + (rowIndex-1)*slaveFirstDim + g.y = wa.y + slaveThei + mainhei + useless_gap + + g.height = slaveBhei - 2*useless_gap - 2*c.border_width + + -- if last slave in bottom row use remaining space for that slave + if rowIndex == nbrSecondSlaves then + g.width = wa.x + wa.width - g.x - useless_gap - 2*c.border_width + else + g.width = slaveSecondDim - useless_gap - 2*c.border_width + end - -- Set remaining clients to floating. - for i = (#cls - 1 - 4),1,-1 - do - c = cls[i] - awful.client.floating.set(c, true) end end + + if g.width < 1 then g.width = 1 end + if g.height < 1 then g.height = 1 end + + c:geometry(g) end end + +function centerwork.horizontal.arrange(p) + return do_centerwork(p, "horizontal") +end + +function centerwork.arrange(p) + return do_centerwork(p, "vertical") +end + return centerwork diff --git a/layout/centerworkd.lua b/layout/centerworkd.lua deleted file mode 100644 index e66a15a..0000000 --- a/layout/centerworkd.lua +++ /dev/null @@ -1,123 +0,0 @@ - ---[[ - - Licensed under GNU General Public License v2 - * (c) 2016, Henrik Antonsson - * (c) 2014, projektile - * (c) 2013, Luke Bonham - * (c) 2010-2012, Peter Hofmann - - Based on centerwork.lua ---]] - -local awful = require("awful") -local beautiful = require("beautiful") -local tonumber = tonumber -local math = { floor = math.floor } - -local centerworkd = -{ - name = "centerworkd", -} - -function centerworkd.arrange(p) - -- A useless gap (like the dwm patch) can be defined with - -- beautiful.useless_gap_width . - local useless_gap = tonumber(beautiful.useless_gap_width) or 0 - - -- A global border can be defined with - -- beautiful.global_border_width - local global_border = tonumber(beautiful.global_border_width) or 0 - if global_border < 0 then global_border = 0 end - - -- Screen. - local wa = p.workarea - local cls = p.clients - - -- Borders are factored in. - wa.height = wa.height - (global_border * 2) - wa.width = wa.width - (global_border * 2) - wa.x = wa.x + global_border - wa.y = wa.y + global_border - - -- Width of main column? - local t = awful.tag.selected(p.screen) - local mwfact = awful.tag.getmwfact(t) - - if #cls > 0 - then - -- Main column, fixed width and height. - local c = cls[1] - local g = {} - local mainwid = math.floor(wa.width * mwfact) - local slavewid = wa.width - mainwid - local slaveLwid = math.floor(slavewid / 2) - local slaveRwid = slavewid - slaveLwid - local nbrLeftSlaves = math.floor(#cls / 2) - local nbrRightSlaves = math.floor((#cls - 1) / 2) - - local slaveLeftHeight = 0 - if nbrLeftSlaves > 0 then slaveLeftHeight = math.floor(wa.height / nbrLeftSlaves) end - if nbrRightSlaves > 0 then slaveRightHeight = math.floor(wa.height / nbrRightSlaves) end - - g.height = wa.height - 2*useless_gap - 2*c.border_width - g.width = mainwid - 2*c.border_width - g.x = wa.x + slaveLwid - g.y = wa.y + useless_gap - - if g.width < 1 then g.width = 1 end - if g.height < 1 then g.height = 1 end - c:geometry(g) - - -- Auxiliary windows. - if #cls > 1 - then - for i = 2,#cls - do - c = cls[i] - g = {} - - local rowIndex = math.floor(i/2) - - -- If i is even it should be placed on the left side - if i % 2 == 0 - then - -- left slave - g.x = wa.x + useless_gap - g.y = wa.y + useless_gap + (rowIndex-1)*slaveLeftHeight - - g.width = slaveLwid - 2*useless_gap - 2*c.border_width - - -- if last slave in left row use remaining space for that slave - if rowIndex == nbrLeftSlaves - then - g.height = wa.y + wa.height - g.y - useless_gap - 2*c.border_width - else - g.height = slaveLeftHeight - useless_gap - 2*c.border_width - end - else - -- right slave - g.x = wa.x + slaveLwid + mainwid + useless_gap - g.y = wa.y + useless_gap + (rowIndex-1)*slaveRightHeight - - g.width = slaveRwid - 2*useless_gap - 2*c.border_width - - -- if last slave in right row use remaining space for that slave - if rowIndex == nbrRightSlaves - then - g.height = wa.y + wa.height - g.y - useless_gap - 2*c.border_width - else - g.height = slaveRightHeight - useless_gap - 2*c.border_width - end - - end - - if g.width < 1 then g.width = 1 end - if g.height < 1 then g.height = 1 end - c:geometry(g) - end - end - end -end - -return centerworkd diff --git a/layout/termfair.lua b/layout/termfair.lua index 6aca99d..ec127e2 100644 --- a/layout/termfair.lua +++ b/layout/termfair.lua @@ -4,100 +4,89 @@ Licensed under GNU General Public License v2 * (c) 2014, projektile * (c) 2013, Luke Bonham + * (c) 2010, Nicolas Estibals * (c) 2010-2012, Peter Hofmann --]] local tag = require("awful.tag") -local beautiful = require("beautiful") local math = { ceil = math.ceil, floor = math.floor, max = math.max } local tonumber = tonumber local termfair = { name = "termfair" } +termfair.center = { name = "centerfair" } -function termfair.arrange(p) - -- Layout with fixed number of vertical columns (read from nmaster). - -- New windows align from left to right. When a row is full, a now - -- one above it is created. Like this: - - -- (1) (2) (3) - -- +---+---+---+ +---+---+---+ +---+---+---+ - -- | | | | | | | | | | | | - -- | 1 | | | -> | 2 | 1 | | -> | 3 | 2 | 1 | -> - -- | | | | | | | | | | | | - -- +---+---+---+ +---+---+---+ +---+---+---+ - - -- (4) (5) (6) - -- +---+---+---+ +---+---+---+ +---+---+---+ - -- | 4 | | | | 5 | 4 | | | 6 | 5 | 4 | - -- +---+---+---+ -> +---+---+---+ -> +---+---+---+ - -- | 3 | 2 | 1 | | 3 | 2 | 1 | | 3 | 2 | 1 | - -- +---+---+---+ +---+---+---+ +---+---+---+ - - -- A useless gap (like the dwm patch) can be defined with - -- beautiful.useless_gap_width. - local useless_gap = tonumber(beautiful.useless_gap_width) or 0 - if useless_gap < 0 then useless_gap = 0 end - - -- A global border can be defined with - -- beautiful.global_border_width - local global_border = tonumber(beautiful.global_border_width) or 0 - if global_border < 0 then global_border = 0 end - +local function do_fair(p, orientation) -- Screen. - local wa = p.workarea + local wa = p.workarea local cls = p.clients - -- Borders are factored in. - wa.height = wa.height - (global_border * 2) - wa.width = wa.width - (global_border * 2) - wa.x = wa.x + global_border - wa.y = wa.y + global_border + if #cls <= 0 then return end - -- How many vertical columns? - local t = tag.selected(p.screen) - local num_x = termfair.nmaster or tag.getnmaster(t) + -- Useless gaps. + local useless_gap = tag.gap or 0 - -- Do at least "desired_y" rows. - local desired_y = termfair.ncol or tag.getncol(t) + if orientation == "west" then + -- Layout with fixed number of vertical columns (read from nmaster). + -- New windows align from left to right. When a row is full, a now + -- one above it is created. Like this: - if #cls > 0 - then - local num_y = math.max(math.ceil(#cls / num_x), desired_y) - local cur_num_x = num_x - local at_x = 0 - local at_y = 0 - local remaining_clients = #cls + -- (1) (2) (3) + -- +---+---+---+ +---+---+---+ +---+---+---+ + -- | | | | | | | | | | | | + -- | 1 | | | -> | 2 | 1 | | -> | 3 | 2 | 1 | -> + -- | | | | | | | | | | | | + -- +---+---+---+ +---+---+---+ +---+---+---+ + + -- (4) (5) (6) + -- +---+---+---+ +---+---+---+ +---+---+---+ + -- | 4 | | | | 5 | 4 | | | 6 | 5 | 4 | + -- +---+---+---+ -> +---+---+---+ -> +---+---+---+ + -- | 3 | 2 | 1 | | 3 | 2 | 1 | | 3 | 2 | 1 | + -- +---+---+---+ +---+---+---+ +---+---+---+ + + if #cls <= 0 then return end + + -- How many vertical columns? Read from nmaster on the tag. + local num_x = tonumber(termfair.nmaster) or tag.master_count + local ncol = tonumber(termfair.ncol) or tag.column_count local width = math.floor((wa.width - (num_x + 1)*useless_gap) / num_x) - local height = math.floor((wa.height - (num_y + 1)*useless_gap) / num_y) + + if num_x <= 2 then num_x = 2 end + if ncol <= 1 then ncol = 1 end + + local num_y = math.max(math.ceil(#cls / num_x), ncol) + local height = math.floor((wa.height - (num_y + 1)*useless_gap) / num_y) + local cur_num_x = num_x + local at_x = 0 + local at_y = 0 + + local remaining_clients = #cls -- We start the first row. Left-align by limiting the number of -- available slots. - if remaining_clients < num_x - then + if remaining_clients < num_x then cur_num_x = remaining_clients end -- Iterate in reversed order. - for i = #cls,1,-1 - do + for i = #cls,1,-1 do -- Get x and y position. local c = cls[i] local this_x = cur_num_x - at_x - 1 local this_y = num_y - at_y - 1 - -- Calc geometry. + -- Calculate geometry. local g = {} - if this_x == (num_x - 1) - then + if this_x == (num_x - 1) then g.width = wa.width - (num_x - 1)*width - (num_x + 1)*useless_gap - 2*c.border_width else g.width = width - 2*c.border_width end - if this_y == (num_y - 1) - then + + if this_y == (num_y - 1) then g.height = wa.height - (num_y - 1)*height - (num_y + 1)*useless_gap - 2*c.border_width else g.height = height - 2*c.border_width @@ -106,34 +95,158 @@ function termfair.arrange(p) g.x = wa.x + this_x*width g.y = wa.y + this_y*height - if useless_gap > 0 - then + if useless_gap > 0 then -- All clients tile evenly. g.x = g.x + (this_x + 1)*useless_gap g.y = g.y + (this_y + 1)*useless_gap - end + if g.width < 1 then g.width = 1 end if g.height < 1 then g.height = 1 end + c:geometry(g) + remaining_clients = remaining_clients - 1 -- Next grid position. at_x = at_x + 1 - if at_x == num_x - then + if at_x == num_x then -- Row full, create a new one above it. at_x = 0 at_y = at_y + 1 -- We start a new row. Left-align. - if remaining_clients < num_x - then + if remaining_clients < num_x then cur_num_x = remaining_clients end end end + elseif orientation == "center" then + -- Layout with fixed number of vertical columns (read from nmaster). + -- Cols are centerded until there is nmaster columns, then windows + -- are stacked in the slave columns, with at most ncol clients per + -- column if possible. + + -- with nmaster=3 and ncol=1 you'll have + -- (1) (2) (3) + -- +---+---+---+ +-+---+---+-+ +---+---+---+ + -- | | | | | | | | | | | | | + -- | | 1 | | -> | | 1 | 2 | | -> | 1 | 2 | 3 | -> + -- | | | | | | | | | | | | | + -- +---+---+---+ +-+---+---+-+ +---+---+---+ + + -- (4) (5) + -- +---+---+---+ +---+---+---+ + -- | | | 3 | | | 2 | 4 | + -- + 1 + 2 +---+ -> + 1 +---+---+ + -- | | | 4 | | | 3 | 5 | + -- +---+---+---+ +---+---+---+ + + -- How many vertical columns? Read from nmaster on the tag. + local num_x = tonumber(termfair.center.nmaster) or tag.master_count + local ncol = tonumber(termfair.center.ncol) or tag.column_count + local width = math.floor((wa.width - (num_x + 1)*useless_gap) / num_x) + + if num_x <= 2 then num_x = 2 end + if ncol <= 1 then ncol = 1 end + + if #cls < num_x then + -- Less clients than the number of columns, let's center it! + local offset_x = wa.x + (wa.width - #cls*width - (#cls - 1)*useless_gap) / 2 + local g = {} + g.y = wa.y + useless_gap + for i = 1, #cls do + local c = cls[i] + g.width = width - 2*c.border_width + g.height = wa.height - 2*useless_gap - 2*c.border_width + if g.width < 1 then g.width = 1 end + if g.height < 1 then g.height = 1 end + g.x = offset_x + (i - 1) * (width + useless_gap) + c:geometry(g) + end + else + -- More clients than the number of columns, let's arrange it! + -- Master client deserves a special treatement + local c = cls[1] + local g = {} + g.width = wa.width - (num_x - 1)*width - (num_x + 1)*useless_gap - 2*c.border_width + g.height = wa.height - 2*useless_gap - 2*c.border_width + if g.width < 1 then g.width = 1 end + if g.height < 1 then g.height = 1 end + g.x = wa.x + useless_gap + g.y = wa.y + useless_gap + + c:geometry(g) + + -- Treat the other clients + + -- Compute distribution of clients among columns + local num_y ={} + do + local remaining_clients = #cls-1 + local ncol_min = math.ceil(remaining_clients/(num_x-1)) + if ncol >= ncol_min then + for i = (num_x-1), 1, -1 do + if (remaining_clients-i+1) < ncol then + num_y[i] = remaining_clients-i + 1 + else + num_y[i] = ncol + end + remaining_clients = remaining_clients - num_y[i] + end + else + local rem = remaining_clients % (num_x-1) + if rem == 0 then + for i = 1, num_x-1 do + num_y[i] = ncol_min + end + else + for i = 1, num_x-1 do + num_y[i] = ncol_min - 1 + end + for i = 0, rem-1 do + num_y[num_x-1-i] = num_y[num_x-1-i] + 1 + end + end + end + end + + -- Compute geometry of the other clients + local nclient = 2 -- we start with the 2nd client + g.x = g.x + g.width + useless_gap + 2*c.border_width + + for i = 1, (num_x-1) do + local height = math.floor((wa.height - (num_y[i] + 1)*useless_gap) / num_y[i]) + g.y = wa.y + useless_gap + for j = 0, (num_y[i]-2) do + local c = cls[nclient] + g.height = height - 2*c.border_width + g.width = width - 2*c.border_width + if g.width < 1 then g.width = 1 end + if g.height < 1 then g.height = 1 end + c:geometry(g) + nclient = nclient + 1 + g.y = g.y + height + useless_gap + end + local c = cls[nclient] + g.height = wa.height - (num_y[i] + 1)*useless_gap - (num_y[i] - 1)*height - 2*c.border_width + g.width = width - 2*c.border_width + if g.width < 1 then g.width = 1 end + if g.height < 1 then g.height = 1 end + c:geometry(g) + nclient = nclient + 1 + g.x = g.x + width + useless_gap + end + end end end +function termfair.center.arrange(p) + return do_fair(p, "center") +end + +function termfair.arrange(p) + return do_fair(p, "west") +end + return termfair diff --git a/wiki b/wiki index 006cb79..cf17caf 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 006cb79c302aef03dd064430dd2ceba2689dacc7 +Subproject commit cf17caf2b889d58d4f00a47cd168f53ae85b6d9f From 75b19142c160825b0f5ce25feea7eea9970844c6 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 18 Jan 2017 22:54:10 +0100 Subject: [PATCH 037/106] layout: fixed useless_gap retrieval --- helpers.lua | 2 +- layout/cascade.lua | 8 ++++---- layout/centerwork.lua | 8 ++++---- layout/termfair.lua | 12 ++++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/helpers.lua b/helpers.lua index 8eed10f..a10aa7a 100644 --- a/helpers.lua +++ b/helpers.lua @@ -9,7 +9,7 @@ local debug = require("debug") local assert = assert -local capi = { timer = require ("gears.timer") } +local capi = { timer = require("gears.timer") } local io = { open = io.open, lines = io.lines, popen = io.popen } diff --git a/layout/cascade.lua b/layout/cascade.lua index 2397a1d..9f159a5 100644 --- a/layout/cascade.lua +++ b/layout/cascade.lua @@ -8,14 +8,14 @@ --]] -local tag = require("awful.tag") -local tonumber = tonumber +local tag = require("awful.tag") +local tonumber = tonumber local cascade = { name = "cascade", nmaster = 0, offset_x = 32, - offset_y = 8, + offset_y = 8, tile = { name = "cascadetile", nmaster = 0, @@ -35,7 +35,7 @@ local function do_cascade(p, tiling) if #cls <= 0 then return end -- Useless gaps. - local useless_gap = tag.gap or 0 + local useless_gap = p.useless_gap or 0 if not tiling then -- Cascade windows. diff --git a/layout/centerwork.lua b/layout/centerwork.lua index ce3d9e8..8bcbf60 100644 --- a/layout/centerwork.lua +++ b/layout/centerwork.lua @@ -10,9 +10,9 @@ --]] -local tag = require("awful.tag") -local tonumber = tonumber -local math = { floor = math.floor } +local tag = require("awful.tag") +local tonumber = tonumber +local math = { floor = math.floor } local centerwork = { name = "centerwork", @@ -27,7 +27,7 @@ local function do_centerwork(p, orientation) if #cls <= 0 then return end -- Useless gaps. - local useless_gap = tag.gap or 0 + local useless_gap = p.useless_gap or 0 local c = cls[1] local g = {} diff --git a/layout/termfair.lua b/layout/termfair.lua index ec127e2..829f0bd 100644 --- a/layout/termfair.lua +++ b/layout/termfair.lua @@ -9,11 +9,11 @@ --]] -local tag = require("awful.tag") -local math = { ceil = math.ceil, - floor = math.floor, - max = math.max } -local tonumber = tonumber +local tag = require("awful.tag") +local math = { ceil = math.ceil, + floor = math.floor, + max = math.max } +local tonumber = tonumber local termfair = { name = "termfair" } termfair.center = { name = "centerfair" } @@ -26,7 +26,7 @@ local function do_fair(p, orientation) if #cls <= 0 then return end -- Useless gaps. - local useless_gap = tag.gap or 0 + local useless_gap = p.useless_gap or 0 if orientation == "west" then -- Layout with fixed number of vertical columns (read from nmaster). From 7e4175f7aaef5c690afca3bc987107e2193a58df Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 18 Jan 2017 22:57:26 +0100 Subject: [PATCH 038/106] layout: fixed spaces --- layout/cascade.lua | 4 ++-- layout/centerwork.lua | 6 +++--- layout/termfair.lua | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/layout/cascade.lua b/layout/cascade.lua index 9f159a5..cc3f50f 100644 --- a/layout/cascade.lua +++ b/layout/cascade.lua @@ -8,8 +8,8 @@ --]] -local tag = require("awful.tag") -local tonumber = tonumber +local tag = require("awful.tag") +local tonumber = tonumber local cascade = { name = "cascade", diff --git a/layout/centerwork.lua b/layout/centerwork.lua index 8bcbf60..a79314e 100644 --- a/layout/centerwork.lua +++ b/layout/centerwork.lua @@ -10,9 +10,9 @@ --]] -local tag = require("awful.tag") -local tonumber = tonumber -local math = { floor = math.floor } +local tag = require("awful.tag") +local tonumber = tonumber +local math = { floor = math.floor } local centerwork = { name = "centerwork", diff --git a/layout/termfair.lua b/layout/termfair.lua index 829f0bd..6d24460 100644 --- a/layout/termfair.lua +++ b/layout/termfair.lua @@ -9,11 +9,11 @@ --]] -local tag = require("awful.tag") -local math = { ceil = math.ceil, - floor = math.floor, - max = math.max } -local tonumber = tonumber +local tag = require("awful.tag") +local math = { ceil = math.ceil, + floor = math.floor, + max = math.max } +local tonumber = tonumber local termfair = { name = "termfair" } termfair.center = { name = "centerfair" } From 0279482eeb5867f49b4efc83d591393f9c3d0adb Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Fri, 20 Jan 2017 20:58:22 +0100 Subject: [PATCH 039/106] from asynchshell to awful.spawn.easy_async; started making every widget asynchronous --- asyncshell.lua | 79 ----------------- helpers.lua | 43 ++++----- widgets/abase.lua | 10 +-- widgets/alsa.lua | 37 +++----- widgets/alsabar.lua | 161 +++++++++++++--------------------- widgets/contrib/gpmdp.lua | 13 +-- widgets/contrib/kbdlayout.lua | 6 +- widgets/contrib/moc.lua | 86 ++++++++---------- widgets/contrib/task.lua | 1 - widgets/imap.lua | 12 +-- widgets/mpd.lua | 41 ++++----- widgets/weather.lua | 23 ++--- wiki | 2 +- 13 files changed, 181 insertions(+), 333 deletions(-) delete mode 100644 asyncshell.lua diff --git a/asyncshell.lua b/asyncshell.lua deleted file mode 100644 index 61336db..0000000 --- a/asyncshell.lua +++ /dev/null @@ -1,79 +0,0 @@ - ---[[ - - Licensed under GNU General Public License v2 - * (c) 2015, worron - * (c) 2013, Alexander Yakushev - ---]] - --- Asynchronous io.popen for Awesome WM. --- How to use: --- asyncshell.request('wscript -Kiev', function(output) wwidget.text = output end) - --- Grab environment -local awful = require('awful') - --- Avoid discrepancies across multiple shells -awful.util.shell = '/bin/sh' - --- Initialize tables for module -asyncshell = { request_table = {}, id_counter = 0 } - --- Request counter -local function next_id() - asyncshell.id_counter = (asyncshell.id_counter + 1) % 10000 - return asyncshell.id_counter -end - --- Remove given request -function asyncshell.clear(id) - if asyncshell.request_table[id] then - if asyncshell.request_table[id].timer then - asyncshell.request_table[id].timer:stop() - asyncshell.request_table[id].timer = nil - end - asyncshell.request_table[id] = nil - end -end - --- Sends an asynchronous request for an output of the shell command --- @param command Command to be executed and taken output from --- @param callback Function to be called when the command finishes --- @param timeout Maximum amount of time to wait for the result (optional) -function asyncshell.request(command, callback, timeout) - local id = next_id() - asyncshell.request_table[id] = { callback = callback } - - local formatted_command = string.gsub(command, '"','\"') - - local req = string.format( - "echo \"asyncshell.deliver(%s, [[\\\"$(%s)\\\"]])\" | awesome-client &", - id, formatted_command - ) - - if type(awful.spawn) == 'table' and awful.spawn.with_shell then - awful.spawn.with_shell(req) - else - awful.util.spawn_with_shell(req) - end - - if timeout then - asyncshell.request_table[id].timer = timer({ timeout = timeout }) - asyncshell.request_table[id].timer:connect_signal("timeout", function() asyncshell.clear(id) end) - asyncshell.request_table[id].timer:start() - end -end - --- Calls the remembered callback function on the output of the shell command --- @param id Request ID --- @param output Shell command output to be delievered -function asyncshell.deliver(id, output) - local output = string.sub(output, 2, -2) - if asyncshell.request_table[id] then - asyncshell.request_table[id].callback(output) - asyncshell.clear(id) - end -end - -return asyncshell diff --git a/helpers.lua b/helpers.lua index a10aa7a..9755dc0 100644 --- a/helpers.lua +++ b/helpers.lua @@ -6,17 +6,17 @@ --]] -local debug = require("debug") -local assert = assert -local capi = { timer = require("gears.timer") } -local io = { open = io.open, - lines = io.lines, - popen = io.popen } -local rawget = rawget -local table = { sort = table.sort } +local debug = require("debug") +local io = { lines = io.lines, + open = io.open, + popen = io.popen } +local rawget = rawget +local table = { sort = table.sort } -local wibox = require("wibox") +local easy_async = require("awful.spawn").easy_async +local timer = require("gears.timer") +local wibox = require("wibox") -- Lain helper functions for internal use -- lain.helpers @@ -95,7 +95,7 @@ helpers.timer_table = {} function helpers.newtimer(_name, timeout, fun, nostart) local name = timeout if not helpers.timer_table[name] then - helpers.timer_table[name] = capi.timer({ timeout = timeout }) + helpers.timer_table[name] = timer({ timeout = timeout }) helpers.timer_table[name]:start() end helpers.timer_table[name]:connect_signal("timeout", fun) @@ -108,22 +108,25 @@ end -- {{{ Pipe operations --- read the full output of a command output +-- return the full output of an input command (synchronous pipe) +-- @param cmd the input command +-- @return command output (string) function helpers.read_pipe(cmd) - local f = assert(io.popen(cmd)) + local f = io.popen(cmd) local output = f:read("*all") f:close() return output end --- return line iterator of a command output -function helpers.pipelines(...) - local f = assert(io.popen(...)) - return function () -- iterator - local data = f:read() - if data == nil then f:close() end - return data - end +-- run a command and execute a function on its output (asynchronous pipe) +-- @param cmd the input command +-- @param callback function to execute on cmd output +-- @return cmd PID +function helpers.async(cmd, callback) + return easy_async(cmd, + function (stdout, stderr, reason, exit_code) + callback(stdout) + end) end -- }}} diff --git a/widgets/abase.lua b/widgets/abase.lua index 60d86ab..a176cf1 100644 --- a/widgets/abase.lua +++ b/widgets/abase.lua @@ -6,10 +6,8 @@ --]] -local newtimer = require("lain.helpers").newtimer -local async = require("lain.asyncshell") +local helpers = require("lain.helpers") local wibox = require("wibox") - local setmetatable = setmetatable -- Basic template for custom widgets (asynchronous version) @@ -22,10 +20,10 @@ local function worker(args) local cmd = args.cmd or "" local settings = args.settings or function() end - abase.widget = wibox.widget.textbox('') + abase.widget = wibox.widget.textbox() function abase.update() - async.request(cmd, function(f) + helpers.async(cmd, function(f) output = f if output ~= abase.prev then widget = abase.widget @@ -35,7 +33,7 @@ local function worker(args) end) end - newtimer(cmd, timeout, abase.update) + helpers.newtimer(cmd, timeout, abase.update) return setmetatable(abase, { __index = abase.widget }) end diff --git a/widgets/alsa.lua b/widgets/alsa.lua index 670765a..7c853c9 100644 --- a/widgets/alsa.lua +++ b/widgets/alsa.lua @@ -8,13 +8,9 @@ --]] local helpers = require("lain.helpers") -local read_pipe = require("lain.helpers").read_pipe - local wibox = require("wibox") - local string = { match = string.match, format = string.format } - local setmetatable = setmetatable -- ALSA volume @@ -26,29 +22,20 @@ local function worker(args) local timeout = args.timeout or 5 local settings = args.settings or function() end - alsa.cmd = args.cmd or "amixer" - alsa.channel = args.channel or "Master" - alsa.togglechannel = args.togglechannel - alsa.last_level = "0" - alsa.last_status = "" + alsa.cmd = args.cmd or "amixer" + alsa.channel = args.channel or "Master" + alsa.last = {} function alsa.update() - mixer = read_pipe(string.format("%s get %s", alsa.cmd, alsa.channel)) - l, s = string.match(mixer, "([%d]+)%%.*%[([%l]*)") - - -- HDMIs can have a channel different from Master for toggling mute - if alsa.togglechannel then - s = string.match(read_pipe(string.format("%s get %s", alsa.cmd, alsa.togglechannel)), "%[(%a+)%]") - end - - if alsa.last_level ~= l or alsa.last_status ~= s then - volume_now = { level = l, status = s } - alsa.last_level = l - alsa.last_status = s - - widget = alsa.widget - settings() - end + helpers.async(alsa.cmd, function(mixer) + local l,s = string.match(mixer, "([%d]+)%%.*%[([%l]*)") + if alsa.last.level ~= l or alsa.last.status ~= s then + volume_now = { level = l, status = s } + widget = alsa.widget + settings() + alsa.last = volume_now + end + end) end timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel) diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index cdbefd2..9fe5339 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -7,8 +7,7 @@ --]] -local newtimer = require("lain.helpers").newtimer -local read_pipe = require("lain.helpers").read_pipe +local helpers = require("lain.helpers") local awful = require("awful") local beautiful = require("beautiful") @@ -35,9 +34,6 @@ local alsabar = { unmute = "#A4CE8A" }, - terminal = terminal or "xterm", - mixer = string.format("%s -e alsamixer", terminal), - notifications = { font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")), font_size = "11", @@ -49,46 +45,6 @@ local alsabar = { _muted = false } -function alsabar.notify() - alsabar.update() - - local preset = { - title = "", - text = "", - timeout = 5, - screen = alsabar.notifications.screen, - font = string.format("%s %s", alsabar.notifications.font, - alsabar.notifications.font_size), - fg = alsabar.notifications.color - } - - if alsabar._muted - then - preset.title = string.format("%s - Muted", alsabar.channel) - else - preset.title = string.format("%s - %s%%", alsabar.channel, alsabar._current_level) - end - - int = math.modf((alsabar._current_level / 100) * awful.screen.focused().mywibox.height) - preset.text = string.format("[%s%s]", string.rep("|", int), - string.rep(" ", awful.screen.focused().mywibox.height - int)) - - if alsabar.followtag then - preset.screen = awful.screen.focused() - end - - if alsabar._notify ~= nil then - alsabar._notify = naughty.notify ({ - replaces_id = alsabar._notify.id, - preset = preset, - }) - else - alsabar._notify = naughty.notify ({ - preset = preset, - }) - end -end - local function worker(args) local args = args or {} local timeout = args.timeout or 5 @@ -101,7 +57,6 @@ local function worker(args) alsabar.cmd = args.cmd or "amixer" alsabar.channel = args.channel or alsabar.channel - alsabar.togglechannel = args.togglechannel alsabar.step = args.step or alsabar.step alsabar.colors = args.colors or alsabar.colors alsabar.notifications = args.notifications or alsabar.notifications @@ -122,66 +77,72 @@ local function worker(args) alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } }) - function alsabar.update() - -- Get mixer control contents - local mixer = read_pipe(string.format("%s get %s", alsabar.cmd, alsabar.channel)) - - -- Capture mixer control state: [5%] ... ... [on] - local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)") - - -- HDMIs can have a channel different from Master for toggling mute - if alsabar.togglechannel then - mute = string.match(read_pipe(string.format("%s get %s", alsabar.cmd, alsabar.togglechannel)), "%[(%a+)%]") - end - - if (volu and tonumber(volu) ~= alsabar._current_level) or (mute and string.match(mute, "on") ~= alsabar._muted) - then - alsabar._current_level = tonumber(volu) or alsabar._current_level - alsabar.bar:set_value(alsabar._current_level / 100) - if (not mute and tonumber(volu) == 0) or mute == "off" + function alsabar.update(callback) + helpers.async(alsabar.cmd, function(mixer) + local volu,mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)") + if (volu and tonumber(volu) ~= alsabar._current_level) or (mute and string.match(mute, "on") ~= alsabar._muted) then - alsabar._muted = true - alsabar.tooltip:set_text ("[Muted]") - alsabar.bar.color = alsabar.colors.mute - else - alsabar._muted = false - alsabar.tooltip:set_text(string.format("%s: %s", alsabar.channel, volu)) - alsabar.bar.color = alsabar.colors.unmute + alsabar._current_level = tonumber(volu) or alsabar._current_level + alsabar.bar:set_value(alsabar._current_level / 100) + if (not mute and tonumber(volu) == 0) or mute == "off" + then + alsabar._muted = true + alsabar.tooltip:set_text ("[Muted]") + alsabar.bar.color = alsabar.colors.mute + else + alsabar._muted = false + alsabar.tooltip:set_text(string.format("%s: %s", alsabar.channel, volu)) + alsabar.bar.color = alsabar.colors.unmute + end + + volume_now = {} + volume_now.level = tonumber(volu) + volume_now.status = mute + + settings() + + if callback then callback() end end - - volume_now = {} - volume_now.level = tonumber(volu) - volume_now.status = mute - - settings() - end + end) end - alsabar.bar:buttons(awful.util.table.join ( - awful.button({}, 1, function() - awful.util.spawn(alsabar.mixer) - end), - awful.button({}, 2, function() - awful.util.spawn(string.format("%s set %s 100%%", alsabar.cmd, alsabar.channel)) - alsabar.update() - end), - awful.button({}, 3, function() - awful.util.spawn(string.format("%s set %s toggle", alsabar.cmd, alsabar.togglechannel or alsabar.channel)) - alsabar.update() - end), - awful.button({}, 4, function() - awful.util.spawn(string.format("%s set %s %s+", alsabar.cmd, alsabar.channel, alsabar.step)) - alsabar.update() - end), - awful.button({}, 5, function() - awful.util.spawn(string.format("%s set %s %s-", alsabar.cmd, alsabar.channel, alsabar.step)) - alsabar.update() - end) - )) + function alsabar.notify() + alsabar.update(function() + local preset = { + title = "", + text = "", + timeout = 5, + screen = alsabar.notifications.screen, + font = string.format("%s %s", alsabar.notifications.font, + alsabar.notifications.font_size), + fg = alsabar.notifications.color + } + + if alsabar._muted then + preset.title = string.format("%s - Muted", alsabar.channel) + else + preset.title = string.format("%s - %s%%", alsabar.channel, alsabar._current_level) + end + + int = math.modf((alsabar._current_level / 100) * awful.screen.focused().mywibox.height) + preset.text = string.format("[%s%s]", string.rep("|", int), + string.rep(" ", awful.screen.focused().mywibox.height - int)) + + if alsabar.followtag then preset.screen = awful.screen.focused() end + + if alsabar._notify then + alsabar._notify = naughty.notify ({ + replaces_id = alsabar._notify.id, + preset = preset, + }) + else + alsabar._notify = naughty.notify ({ preset = preset }) + end + end) + end timer_id = string.format("alsabar-%s-%s", alsabar.cmd, alsabar.channel) - - newtimer(timer_id, timeout, alsabar.update) + helpers.newtimer(timer_id, timeout, alsabar.update) return alsabar end diff --git a/widgets/contrib/gpmdp.lua b/widgets/contrib/gpmdp.lua index ee40a8d..de82b1e 100644 --- a/widgets/contrib/gpmdp.lua +++ b/widgets/contrib/gpmdp.lua @@ -44,8 +44,7 @@ local function worker(args) function gpmdp.update() local filelines = helpers.lines_from(file_location) - if not next(filelines) - then + if not next(filelines) then local gpm_now = { running = false, playing = false } else dict, pos, err = json.decode(table.concat(filelines), 1, nil) @@ -67,16 +66,12 @@ local function worker(args) widget = gpmdp.widget settings() - if gpm_now.playing - then - if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current") - then + if gpm_now.playing then + if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current") then helpers.set_map("gpmdp_current", gpm_now.title) os.execute(string.format("curl %d -o /tmp/gpmcover.png", gpm_now.cover_url)) - if followtag then - gpmdp_notification_preset.screen = focused() - end + if followtag then gpmdp_notification_preset.screen = focused() end gpmdp.id = naughty.notify({ preset = gpmdp_notification_preset, diff --git a/widgets/contrib/kbdlayout.lua b/widgets/contrib/kbdlayout.lua index 23dc6e3..f57d2da 100644 --- a/widgets/contrib/kbdlayout.lua +++ b/widgets/contrib/kbdlayout.lua @@ -38,8 +38,10 @@ local function worker(args) local function run_settings(layout, variant) widget = kbdlayout.widget - kbdlayout_now = { layout=string.match(layout, "[^,]+"), -- Make sure to match the primary layout only. - variant=variant } + kbdlayout_now = { + layout=string.match(layout, "[^,]+"), -- Make sure to match the primary layout only. + variant=variant + } settings() end diff --git a/widgets/contrib/moc.lua b/widgets/contrib/moc.lua index d4571e1..f19b0d3 100644 --- a/widgets/contrib/moc.lua +++ b/widgets/contrib/moc.lua @@ -6,52 +6,40 @@ --]] -local helpers = require("lain.helpers") -local async = require("lain.asyncshell") +local helpers = require("lain.helpers") -local focused = require("awful.screen").focused -local escape_f = require("awful.util").escape -local naughty = require("naughty") -local wibox = require("wibox") +local shell = require("awful.util").shell +local focused = require("awful.screen").focused +local escape_f = require("awful.util").escape +local naughty = require("naughty") +local wibox = require("wibox") -local io = { popen = io.popen } -local os = { execute = os.execute, - getenv = os.getenv } -local string = { format = string.format, - gmatch = string.gmatch } +local os = { getenv = os.getenv } +local string = { format = string.format, + gmatch = string.gmatch } local setmetatable = setmetatable -- MOC audio player -- lain.widgets.contrib.moc -local moc = {} +local moc = helpers.make_widget_textbox() local function worker(args) - local args = args or {} - local timeout = args.timeout or 2 - local music_dir = args.music_dir or os.getenv("HOME") .. "/Music" - local cover_size = args.cover_size or 100 - local default_art = args.default_art or "" - local followtag = args.followtag or false - local settings = args.settings or function() end + local args = args or {} + local timeout = args.timeout or 2 + local music_dir = args.music_dir or os.getenv("HOME") .. "/Music" + local cover_pattern = args.cover_pattern or "*\\.(jpg|jpeg|png|gif)$" + local cover_size = args.cover_size or 100 + local default_art = args.default_art or "" + local followtag = args.followtag or false + local settings = args.settings or function() end - local mpdcover = helpers.scripts_dir .. "mpdcover" - - moc.widget = wibox.widget.textbox('') - - moc_notification_preset = { - title = "Now playing", - timeout = 6 - } + moc_notification_preset = { title = "Now playing", timeout = 6 } helpers.set_map("current moc track", nil) function moc.update() - -- mocp -i will produce output like: - -- Artist: Travis - -- Album: The Man Who - -- etc. - async.request("mocp -i", function(f) + helpers.async("mocp -i", function(f) moc_now = { state = "N/A", file = "N/A", @@ -64,13 +52,13 @@ local function worker(args) for line in string.gmatch(f, "[^\n]+") do for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do - if k == "State" then moc_now.state = v - elseif k == "File" then moc_now.file = v - elseif k == "Artist" then moc_now.artist = escape_f(v) - elseif k == "SongTitle" then moc_now.title = escape_f(v) - elseif k == "Album" then moc_now.album = escape_f(v) + if k == "State" then moc_now.state = v + elseif k == "File" then moc_now.file = v + elseif k == "Artist" then moc_now.artist = escape_f(v) + elseif k == "SongTitle" then moc_now.title = escape_f(v) + elseif k == "Album" then moc_now.album = escape_f(v) elseif k == "CurrentTime" then moc_now.elapsed = escape_f(v) - elseif k == "TotalTime" then moc_now.total = escape_f(v) + elseif k == "TotalTime" then moc_now.total = escape_f(v) end end end @@ -83,18 +71,22 @@ local function worker(args) if moc_now.state == "PLAY" then if moc_now.title ~= helpers.get_map("current moc track") then helpers.set_map("current moc track", moc_now.title) - os.execute(string.format("%s %q %q %d %q", mpdcover, "", - moc_now.file, cover_size, default_art)) - if followtag then - moc_notification_preset.screen = focused() - end + if followtag then moc_notification_preset.screen = focused() end - moc.id = naughty.notify({ - preset = moc_notification_preset, - icon = "/tmp/mpdcover.png", + local common = { + preset = moc_notification_preset, + icon = default_art, + icon_size = cover_size, replaces_id = moc.id, - }).id + } + + local path = string.format("%s/%s", music_dir, string.match(moc_now.file, ".*/")) + local cover = string.format("%s -c \"find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'\"", shell, path, cover_pattern) + helpers.async(cover, function(current_icon) + common.icon = current_icon:gsub("\n", "") + moc.id = naughty.notify(common).id + end) end elseif moc_now.state ~= "PAUSE" then helpers.set_map("current moc track", nil) diff --git a/widgets/contrib/task.lua b/widgets/contrib/task.lua index 1b8f119..6c8c9cc 100644 --- a/widgets/contrib/task.lua +++ b/widgets/contrib/task.lua @@ -12,7 +12,6 @@ local awful = require("awful") local beautiful = require("beautiful") local naughty = require("naughty") -local mouse = mouse local io = io local string = { len = string.len } local tonumber = tonumber diff --git a/widgets/imap.lua b/widgets/imap.lua index 06b4245..3caf31a 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -7,7 +7,6 @@ --]] local helpers = require("lain.helpers") -local async = require("lain.asyncshell") local naughty = require("naughty") local wibox = require("wibox") @@ -59,24 +58,19 @@ local function worker(args) curl = string.format("%s --url imaps://%s:%s/INBOX -u %s:%q %s -k", head_command, server, port, mail, password, request) - async.request(curl, function(f) + helpers.async(curl, function(f) _, mailcount = string.gsub(f, "%d+", "") - _ = nil widget = imap.widget settings() - if mailcount >= 1 and mailcount > helpers.get_map(mail) - then + if mailcount >= 1 and mailcount > helpers.get_map(mail) then if mailcount == 1 then nt = mail .. " has one new message" else nt = mail .. " has " .. mailcount .. " new messages" end - naughty.notify({ - preset = mail_notification_preset, - text = nt - }) + naughty.notify({ preset = mail_notification_preset, text = nt }) end helpers.set_map(mail, mailcount) diff --git a/widgets/mpd.lua b/widgets/mpd.lua index ebdda98..defa710 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -7,9 +7,9 @@ --]] -local async = require("lain.asyncshell") local helpers = require("lain.helpers") +local shell = require("awful.util").shell local escape_f = require("awful.util").escape local focused = require("awful.screen").focused local naughty = require("naughty") @@ -29,7 +29,7 @@ local mpd = helpers.make_widget_textbox() local function worker(args) local args = args or {} local timeout = args.timeout or 2 - local password = args.password or "" + local password = (args.password and #args.password > 0 and string.format("password %s\\n", args.password)) or "" local host = args.host or "127.0.0.1" local port = args.port or "6600" local music_dir = args.music_dir or os.getenv("HOME") .. "/Music" @@ -38,21 +38,18 @@ local function worker(args) local default_art = args.default_art or "" local notify = args.notify or "on" local followtag = args.followtag or false - local echo_cmd = args.echo_cmd or "echo" local settings = args.settings or function() end local mpdh = string.format("telnet://%s:%s", host, port) - local echo = string.format("%s 'password %s\nstatus\ncurrentsong\nclose'", echo_cmd, password) + local echo = string.format("printf \"%sstatus\\ncurrentsong\\nclose\\n\"", password) + local cmd = string.format("%s -c '%s | curl --connect-timeout 1 -fsm 3 %s'", shell, echo, mpdh) - mpd_notification_preset = { - title = "Now playing", - timeout = 6 - } + mpd_notification_preset = { title = "Now playing", timeout = 6 } helpers.set_map("current mpd track", nil) function mpd.update() - async.request(string.format("%s | curl --connect-timeout 1 -fsm 3 %s", echo, mpdh), function (f) + helpers.async(cmd, function(f) mpd_now = { random_mode = false, single_mode = false, @@ -105,22 +102,26 @@ local function worker(args) if notify == "on" and mpd_now.title ~= helpers.get_map("current mpd track") then helpers.set_map("current mpd track", mpd_now.title) - local current icon = default_art + if followtag then mpd_notification_preset.screen = focused() end + + local common = { + preset = mpd_notification_preset, + icon = default_art, + icon_size = cover_size, + replaces_id = mpd.id, + } if not string.match(mpd_now.file, "http.*://") then -- local file instead of http stream local path = string.format("%s/%s", music_dir, string.match(mpd_now.file, ".*/")) - local cover = string.format("find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'", path, cover_pattern) - current_icon = helpers.read_pipe(cover):gsub("\n", "") + local cover = string.format("%s -c \"find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'\"", shell, path, cover_pattern) + helpers.async(cover, function(current_icon) + common.icon = current_icon:gsub("\n", "") + mpd.id = naughty.notify(common).id + end) + else + mpd.id = naughty.notify(common).id end - if followtag then mpd_notification_preset.screen = focused() end - - mpd.id = naughty.notify({ - preset = mpd_notification_preset, - icon = current_icon, - icon_size = cover_size, - replaces_id = mpd.id, - }).id end elseif mpd_now.state ~= "pause" then helpers.set_map("current mpd track", nil) diff --git a/widgets/weather.lua b/widgets/weather.lua index 015f43a..17b3d34 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -6,12 +6,10 @@ --]] +local async = require("lain.helpers").async local newtimer = require("lain.helpers").newtimer -local read_pipe = require("lain.helpers").read_pipe - -local async = require("lain.asyncshell") -local json = require("lain.util").dkjson local lain_icons = require("lain.helpers").icons_dir +local json = require("lain.util").dkjson local focused = require("awful.screen").focused local naughty = require("naughty") @@ -54,14 +52,14 @@ local function worker(args) local notification_preset = args.notification_preset or {} local notification_text_fun = args.notification_text_fun or function (wn) - local day = string.gsub(read_pipe(string.format(date_cmd, wn["dt"])), "\n", "") + local day = os.date("%a %d", wn["dt"]) local tmin = math.floor(wn["temp"]["min"]) local tmax = math.floor(wn["temp"]["max"]) local desc = wn["weather"][1]["description"] return string.format("%s: %s, %d - %d ", day, desc, tmin, tmax) end local weather_na_markup = args.weather_na_markup or " N/A " - local followtag = args.followtag or false + local followtag = args.followtag or false local settings = args.settings or function() end weather.widget = wibox.widget.textbox(weather_na_markup) @@ -105,7 +103,7 @@ local function worker(args) function weather.forecast_update() local cmd = string.format(forecast_call, city_id, units, lang, cnt, APPID) - async.request(cmd, function(f) + async(cmd, function(f) local pos, err weather_now, pos, err = json.decode(f, 1, nil) @@ -125,7 +123,7 @@ local function worker(args) function weather.update() local cmd = string.format(current_call, city_id, units, lang, APPID) - async.request(cmd, function(f) + async(cmd, function(f) local pos, err, icon weather_now, pos, err = json.decode(f, 1, nil) @@ -135,12 +133,9 @@ local function worker(args) local sunrise = tonumber(weather_now["sys"]["sunrise"]) local sunset = tonumber(weather_now["sys"]["sunset"]) local icon = weather_now["weather"][1]["icon"] - local utc_m = string.gsub(read_pipe(string.format("date -u -d 'today 00:00:00' +'%%s'")), "\n", "") - local loc_m = string.gsub(read_pipe(string.format("date -d 'today 00:00:00' +'%%s'")), "\n", "") - - loc_m = tonumber(loc_m) - utc_m = tonumber(utc_m) - offset = utc_offset() + local loc_m = os.time { year = os.date("%Y"), month = os.date("%m"), day = os.date("%d"), hour = 0 } + local offset = utc_offset() + local utc_m = loc_m + offset -- if we are 1 day after the GMT, return 1 day back, and viceversa if offset > 0 and loc_m >= utc_m then diff --git a/wiki b/wiki index cf17caf..fd36911 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit cf17caf2b889d58d4f00a47cd168f53ae85b6d9f +Subproject commit fd369119050a6674c7bb4ef3b2b1d6c6dbdecb83 From 4148ccdfcd5ed620163f9d78e6224c684a358ac7 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sat, 21 Jan 2017 00:09:54 +0100 Subject: [PATCH 040/106] fs: asynchronous --- widgets/fs.lua | 118 ++++++++++++++++++++------------------------ widgets/maildir.lua | 37 ++++++-------- wiki | 2 +- 3 files changed, 69 insertions(+), 88 deletions(-) diff --git a/widgets/fs.lua b/widgets/fs.lua index f578f8b..374d6eb 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -1,24 +1,20 @@ --[[ - - Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham - * (c) 2010, Adrian C. - * (c) 2009, Lucas de Vries - + + Licensed under GNU General Public License v2 + * (c) 2013, Luke Bonham + --]] local helpers = require("lain.helpers") +local shell = require("awful.util").shell local beautiful = require("beautiful") local focused = require("awful.screen").focused local wibox = require("wibox") local naughty = require("naughty") -local io = { popen = io.popen } -local pairs = pairs -local string = { match = string.match, - format = string.format } +local string = string local tonumber = tonumber local setmetatable = setmetatable @@ -26,14 +22,11 @@ local setmetatable = setmetatable -- File system disk space usage -- lain.widgets.fs local fs = {} -local fs_notification = nil -function fs.hide() - if fs_notification ~= nil then - naughty.destroy(fs_notification) - fs_notification = nil - end -end +-- Unit definitions +fs.unit = { ["mb"] = 1024, ["gb"] = 1024^2 } + +function fs.hide() naughty.destroy(fs.notification) end function fs.show(seconds, scr) fs.hide() @@ -47,16 +40,13 @@ function fs.show(seconds, scr) fs.notification_preset.screen = scr end - fs_notification = naughty.notify({ - preset = fs.notification_preset, - text = ws, - timeout = seconds or 5 + fs.notification = naughty.notify({ + preset = fs.notification_preset, + text = ws, + timeout = seconds or 5, }) end --- Unit definitions -local unit = { ["mb"] = 1024, ["gb"] = 1024^2 } - local function worker(args) local args = args or {} local timeout = args.timeout or 600 @@ -69,56 +59,54 @@ local function worker(args) fs.followtag = args.followtag or false fs.notification_preset = args.notification_preset or { fg = beautiful.fg_normal } - fs.widget = wibox.widget.textbox('') + fs.widget = wibox.widget.textbox() helpers.set_map(partition, false) + function update() - fs_info = {} - fs_now = {} - local f = assert(io.popen("LC_ALL=C df -kP")) + fs_info, fs_now = {}, {} + helpers.async(string.format("%s -c 'LC_ALL=C df -k --output=target,size,used,avail,pcent'", shell), 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 - for line in f:lines() do -- Match: (size) (used)(avail)(use%) (mount) - local s = string.match(line, "^.-[%s]([%d]+)") - local u,a,p = string.match(line, "([%d]+)[%D]+([%d]+)[%D]+([%d]+)%%") - local m = string.match(line, "%%[%s]([%p%w]+)") - - if u and m then -- Handle 1st line and broken regexp - fs_info[m .. " size_mb"] = string.format("%.1f", tonumber(s) / unit["mb"]) - fs_info[m .. " size_gb"] = string.format("%.1f", tonumber(s) / unit["gb"]) - fs_info[m .. " used_mb"] = string.format("%.1f", tonumber(u) / unit["mb"]) - fs_info[m .. " used_gb"] = string.format("%.1f", tonumber(u) / unit["gb"]) - fs_info[m .. " used_p"] = tonumber(p) - fs_info[m .. " avail_p"] = 100 - tonumber(p) + 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)) end - end - f:close() + 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" - fs_now.available = tonumber(fs_info[partition .. " avail_p"]) or 0 - fs_now.size_mb = tonumber(fs_info[partition .. " size_mb"]) or 0 - fs_now.size_gb = tonumber(fs_info[partition .. " size_gb"]) or 0 - fs_now.used = tonumber(fs_info[partition .. " used_p"]) or 0 - fs_now.used_mb = tonumber(fs_info[partition .. " used_mb"]) or 0 - fs_now.used_gb = tonumber(fs_info[partition .. " used_gb"]) or 0 + notification_preset = fs.notification_preset + widget = fs.widget + settings() - notification_preset = fs.notification_preset - widget = fs.widget - settings() - - if notify == "on" and fs_now.used >= 99 and not helpers.get_map(partition) - then - naughty.notify({ - title = "warning", - text = partition .. " ran out!\nmake some room", - timeout = 8, - fg = "#000000", - bg = "#FFFFFF", - }) - helpers.set_map(partition, true) - else - helpers.set_map(partition, false) - end + if notify == "on" and fs_now.used >= 99 and not helpers.get_map(partition) then + naughty.notify({ + title = "warning", + text = partition .. " is empty!", + timeout = 8, + fg = "#000000", + bg = "#FFFFFF" + }) + helpers.set_map(partition, true) + else + helpers.set_map(partition, false) + end + end) end if showpopup == "on" then diff --git a/widgets/maildir.lua b/widgets/maildir.lua index 7d4ca28..2f435b3 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -7,24 +7,18 @@ --]] -local spawn = require("awful").spawn -local wibox = require("wibox") +local awful = require("awful") +local wibox = require("wibox") +local helpers = require("lain.helpers") -local element_in_table = require("lain.helpers").element_in_table -local newtimer = require("lain.helpers").newtimer -local read_pipe = require("lain.helpers").read_pipe -local spairs = require("lain.helpers").spairs +local io = { popen = io.popen } +local os = { getenv = os.getenv } +local string = { format = string.format, + match = string.match } -local io = { popen = io.popen } -local os = { getenv = os.getenv } -local pairs = pairs -local string = { format = string.format, - len = string.len, - match = string.match } +local setmetatable = setmetatable -local setmetatable = setmetatable - --- Maildir check +-- Maildir check (synchronous) -- lain.widgets.maildir local maildir = {} @@ -36,7 +30,7 @@ local function worker(args) local settings = args.settings or function() end local ext_mail_cmd = args.external_mail_cmd - maildir.widget = wibox.widget.textbox('') + maildir.widget = wibox.widget.textbox() function update() if ext_mail_cmd then awful.spawn(ext_mail_cmd) end @@ -52,11 +46,11 @@ local function worker(args) -- match files that begin with a dot. -- Afterwards the length of this string is the number of -- new mails in that box. - local mailstring = read_pipe(string.format("find %s /new -mindepth 1 -type f -not -name '.*' -printf a", line)) + local mailstring = helpers.read_pipe(string.format("find %s /new -mindepth 1 -type f -not -name '.*' -printf a", line)) -- Strip off leading mailpath. local box = string.match(line, mailpath .. "/(.*)") - local nummails = string.len(mailstring) + local nummails = #mailstring if nummails > 0 then boxes[box] = nummails @@ -68,9 +62,9 @@ local function worker(args) local newmail = "no mail" local total = 0 - for box, number in spairs(boxes) do + for box, number in helpers.spairs(boxes) do -- Add this box only if it's not to be ignored. - if not util.element_in_table(box, ignore_boxes) then + if not helpers.element_in_table(box, ignore_boxes) then total = total + number if newmail == "no mail" then newmail = string.format("%s(%s)", box, number) @@ -81,11 +75,10 @@ local function worker(args) end widget = maildir.widget - settings() end - newtimer(mailpath, timeout, update, true) + helpers.newtimer(mailpath, timeout, update, true) return setmetatable(maildir, { __index = maildir.widget }) end diff --git a/wiki b/wiki index fd36911..3e32104 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit fd369119050a6674c7bb4ef3b2b1d6c6dbdecb83 +Subproject commit 3e321046961aed74ac3cbc02ace4d61b11a29ad1 From 6f988d8eb76326d5f93ed110b4f42c6e8946ddd8 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sat, 21 Jan 2017 00:20:17 +0100 Subject: [PATCH 041/106] fs: asynchronous: fs.show too --- widgets/base.lua | 2 +- widgets/fs.lua | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/widgets/base.lua b/widgets/base.lua index 642a858..af3d2c0 100644 --- a/widgets/base.lua +++ b/widgets/base.lua @@ -22,7 +22,7 @@ local function worker(args) local cmd = args.cmd or "" local settings = args.settings or function() end - base.widget = wibox.widget.textbox('') + base.widget = wibox.widget.textbox() function base.update() output = read_pipe(cmd) diff --git a/widgets/fs.lua b/widgets/fs.lua index 374d6eb..d5dd49a 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -26,25 +26,29 @@ local fs = {} -- Unit definitions fs.unit = { ["mb"] = 1024, ["gb"] = 1024^2 } -function fs.hide() naughty.destroy(fs.notification) end +function fs.hide() + naughty.destroy(fs.notification) + fs.notification = nil +end function fs.show(seconds, scr) fs.hide() - local cmd = (fs.options and string.format("dfs %s", fs.options)) or "dfs" - local ws = helpers.read_pipe(helpers.scripts_dir .. cmd):gsub("\n*$", "") - if fs.followtag then fs.notification_preset.screen = focused() elseif scr then fs.notification_preset.screen = scr end - fs.notification = naughty.notify({ - preset = fs.notification_preset, - text = ws, - timeout = seconds or 5, - }) + local cmd = (fs.options and string.format("dfs %s", fs.options)) or "dfs" + + helpers.async(helpers.scripts_dir .. cmd, function(ws) + fs.notification = naughty.notify({ + preset = fs.notification_preset, + text = ws:gsub("\n*$", ""), + timeout = seconds or 5, + }) + end) end local function worker(args) From 763805f5add904469b12167ef594e1890dc304dd Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sat, 21 Jan 2017 00:29:31 +0100 Subject: [PATCH 042/106] imap: asynchronous --- widgets/imap.lua | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/widgets/imap.lua b/widgets/imap.lua index 3caf31a..1e86738 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -20,31 +20,27 @@ local setmetatable = setmetatable -- Mail IMAP check -- lain.widgets.imap -local function worker(args) - local imap = {} - local args = args or {} +local function worker(args ) + local imap = helpers.make_widget_textbox() + local args = args or {} + local server = args.server + local mail = args.mail + local password = args.password + local port = args.port or 993 + local timeout = args.timeout or 60 + local is_plain = args.is_plain or false + local followtag = args.followtag or false + local settings = args.settings or function() end - local server = args.server - local mail = args.mail - local password = args.password - - local port = args.port or 993 - local timeout = args.timeout or 60 - local is_plain = args.is_plain or false - local followtag = args.followtag or false - local settings = args.settings or function() end - - local head_command = "curl --connect-timeout 3 -fsm 3" + local head_command = "curl --connect-timeout 3 -fsm 3" local request = "-X 'SEARCH (UNSEEN)'" helpers.set_map(mail, 0) if not is_plain then - password = helpers.read_pipe(password):gsub("\n", "") + helpers.async(password, function(f) password = f:gsub("\n", "") end) end - imap.widget = wibox.widget.textbox('') - function update() mail_notification_preset = { icon = helpers.icons_dir .. "mail.png", @@ -78,7 +74,7 @@ local function worker(args) end - helpers.newtimer(mail, timeout, update, true) + helpers.newtimer(mail, timeout, update) return setmetatable(imap, { __index = imap.widget }) end From 0b4193199b244e4f0aa365762314c0462a318014 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sat, 21 Jan 2017 00:36:41 +0100 Subject: [PATCH 043/106] imap: asynchronous: forgot shell --- widgets/imap.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/widgets/imap.lua b/widgets/imap.lua index 1e86738..60a5509 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -8,6 +8,7 @@ local helpers = require("lain.helpers") +local shell = require("awful.util").shell local naughty = require("naughty") local wibox = require("wibox") @@ -38,7 +39,9 @@ local function worker(args ) helpers.set_map(mail, 0) if not is_plain then - helpers.async(password, function(f) password = f:gsub("\n", "") end) + helpers.async(string.format("%s -s '%s'", shell, password), function(f) + password = f:gsub("\n", "") + end) end function update() @@ -51,8 +54,8 @@ local function worker(args ) mail_notification_preset.screen = awful.screen.focused() end - curl = string.format("%s --url imaps://%s:%s/INBOX -u %s:%q %s -k", - head_command, server, port, mail, password, request) + curl = string.format("%s -c '%s --url imaps://%s:%s/INBOX -u %s:%q %s -k'", + shell, head_command, server, port, mail, password, request) helpers.async(curl, function(f) _, mailcount = string.gsub(f, "%d+", "") From 444ffd03c128f45ac1227b33ceb951ae12506a70 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sat, 21 Jan 2017 01:30:39 +0100 Subject: [PATCH 044/106] fs/alsabar: small fixes --- widgets/alsabar.lua | 3 ++- widgets/fs.lua | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index 9fe5339..15ba311 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -19,6 +19,7 @@ local string = { format = string.format, match = string.match, rep = string.rep } local tonumber = tonumber +local type = type local setmetatable = setmetatable @@ -101,7 +102,7 @@ local function worker(args) settings() - if callback then callback() end + if type(callback) == "function" then callback() end end end) end diff --git a/widgets/fs.lua b/widgets/fs.lua index d5dd49a..f07ef98 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -98,7 +98,7 @@ local function worker(args) widget = fs.widget settings() - if notify == "on" and fs_now.used >= 99 and not helpers.get_map(partition) then + if notify == "on" and tonumber(fs_now.used) >= 99 and not helpers.get_map(partition) then naughty.notify({ title = "warning", text = partition .. " is empty!", From 9adaa9fa3290cc1f522bd85ba878de39c5fbde2a Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sat, 21 Jan 2017 14:43:38 +0100 Subject: [PATCH 045/106] net: asynchronous --- widgets/fs.lua | 1 + widgets/net.lua | 75 +++++++++++++++++++------------------------------ wiki | 2 +- 3 files changed, 31 insertions(+), 47 deletions(-) diff --git a/widgets/fs.lua b/widgets/fs.lua index f07ef98..b48fcd0 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -27,6 +27,7 @@ local fs = {} fs.unit = { ["mb"] = 1024, ["gb"] = 1024^2 } function fs.hide() + if not fs.notification then return end naughty.destroy(fs.notification) fs.notification = nil end diff --git a/widgets/net.lua b/widgets/net.lua index f0b3770..83ac6bf 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -11,8 +11,9 @@ local helpers = require("lain.helpers") local naughty = require("naughty") local wibox = require("wibox") +local shell = require("awful.util").shell + local string = { format = string.format, - gsub = string.gsub, match = string.match } local setmetatable = setmetatable @@ -26,40 +27,26 @@ local function worker(args) net.last_r = 0 net.devices = {} - function net.get_first_device() - local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9") - ws = ws:match("%w+: UP") or ws:match("ppp%w+: UNKNOWN") - if ws then return { ws:match("(%w+):") } - else return {} end - end - - 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 iface = args.iface or net.get_first_device() + 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 -- Compatibility with old API where iface was a string corresponding to 1 interface - if type(iface) == "string" then - iftable = {iface} - else - iftable = iface + net.iface = (args.iface and type(args.iface) == "string" and {args.iface}) or {} + + function net.get_device() + helpers.async(string.format("%s -c 'ip link show'", shell, device_cmd), function(ws) + ws = ws:match("(%w+): ") + net.iface = ws and { ws } or {} + end) end - -- Mark all devices as initially online/active - for i, dev in ipairs(iftable) do - helpers.set_map(dev, true) - end + if #net.iface == 0 then net.get_device() end function update() - -- This check is required to ensure we keep looking for one device if - -- none is found by net.get_first_device() at startup (i.e. iftable = {}) - if next(iftable) == nil then - iftable = net.get_first_device() - end - -- These are the totals over all specified interfaces net_now = { -- New api - Current state of requested devices @@ -73,15 +60,14 @@ local function worker(args) local total_t = 0 local total_r = 0 - for i, dev in ipairs(iftable) do - local dev_now = {} + for i, 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) + local now_r = tonumber(helpers.first_line(string.format("/sys/class/net/%s/statistics/rx_bytes", dev)) or 0) - dev_now.carrier = helpers.first_line(string.format('/sys/class/net/%s/carrier', dev)) or '0' - dev_now.state = helpers.first_line(string.format('/sys/class/net/%s/operstate', dev)) or 'down' - - local now_t = tonumber(helpers.first_line(string.format('/sys/class/net/%s/statistics/tx_bytes', dev)) or 0) - local now_r = tonumber(helpers.first_line(string.format('/sys/class/net/%s/statistics/rx_bytes', dev)) or 0) + dev_now.carrier = helpers.first_line(string.format("/sys/class/net/%s/carrier", dev)) or "0" + dev_now.state = helpers.first_line(string.format("/sys/class/net/%s/operstate", dev)) or "down" dev_now.sent = (now_t - dev_before.last_t) / timeout / units dev_now.received = (now_r - dev_before.last_r) / timeout / units @@ -89,8 +75,8 @@ local function worker(args) net_now.sent = net_now.sent + dev_now.sent net_now.received = net_now.received + dev_now.received - dev_now.sent = string.gsub(string.format('%.1f', dev_now.sent), ',', '.') - dev_now.received = string.gsub(string.format('%.1f', dev_now.received), ',', '.') + dev_now.sent = string.format('%.1f', dev_now.sent) + dev_now.received = string.format('%.1f', dev_now.received) dev_now.last_t = now_t dev_now.last_r = now_r @@ -121,23 +107,20 @@ local function worker(args) net_now.devices[dev] = dev_now -- With the new api new_now.sent and net_now.received will be the -- totals across all specified devices - end if total_t ~= net.last_t or total_r ~= net.last_r then - -- Convert to a string to round the digits after the float point - net_now.sent = string.gsub(string.format('%.1f', net_now.sent), ',', '.') - net_now.received = string.gsub(string.format('%.1f', net_now.received), ',', '.') - - net.last_t = total_t - net.last_r = total_r + net_now.sent = string.format('%.1f', net_now.sent) + net_now.received = string.format('%.1f', net_now.received) + net.last_t = total_t + net.last_r = total_r end widget = net.widget settings() end - helpers.newtimer(iface, timeout, update) + helpers.newtimer(net.iface, timeout, update) return net end diff --git a/wiki b/wiki index 3e32104..d975ff0 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 3e321046961aed74ac3cbc02ace4d61b11a29ad1 +Subproject commit d975ff04346986b5ab24e7bc16321e438d3425b8 From a89bbec6f39985515c33aa71dab1689f863b7851 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sat, 21 Jan 2017 18:09:07 +0100 Subject: [PATCH 046/106] quake: client maximized before awesome restart: after the restart, unmaximize and toggle to get normal geometry again --- util/quake.lua | 86 +++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 47 deletions(-) diff --git a/util/quake.lua b/util/quake.lua index c563695..0ec1081 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -8,15 +8,15 @@ --]] local awful = require("awful") -local capi = { client = client, - timer = require("gears.timer") } +local capi = { client = client } + local math = { floor = math.floor } -local string = string +local string = { format = string.format } local pairs = pairs local screen = screen + local setmetatable = setmetatable -local tostring = tostring -- Quake-like Dropdown application spawn local quake = {} @@ -57,21 +57,16 @@ function quake:display() cmd = string.format("%s %s %s", self.app, string.format(self.argname, self.name), self.extra) awful.spawn(cmd, { tag = self.screen.selected_tag }) - self.notexist = true return end - -- Resize + -- Set geometry client.floating = true client.border_width = self.border client.size_hints_honor = false - if self.notexist then - self:compute_size() - client:geometry(self.geometry) - self.notexist = false - end + client:geometry(self:compute_size()) - -- Not sticky and on top + -- Set not sticky and on top client.sticky = false client.ontop = true client.above = true @@ -97,23 +92,27 @@ function quake:display() end function quake:compute_size() - local geom - if not self.overlap then - geom = screen[self.screen].workarea - else - geom = screen[self.screen].geometry + -- skip if we already have a geometry for this screen + if not self.geometry[self.screen] then + local geom + if not self.overlap then + geom = screen[self.screen].workarea + else + geom = screen[self.screen].geometry + end + local width, height = self.width, self.height + if width <= 1 then width = math.floor(geom.width * width) - 2 * self.border end + if height <= 1 then height = math.floor(geom.height * height) end + local x, y + if self.horiz == "left" then x = geom.x + elseif self.horiz == "right" then x = geom.width + geom.x - width + else x = geom.x + (geom.width - width)/2 end + if self.vert == "top" then y = geom.y + elseif self.vert == "bottom" then y = geom.height + geom.y - height + else y = geom.y + (geom.height - height)/2 end + self.geometry[self.screen] = { x = x, y = y, width = width, height = height } end - local width, height = self.width, self.height - if width <= 1 then width = math.floor(geom.width * width) - 2 * self.border end - if height <= 1 then height = math.floor(geom.height * height) end - local x, y - if self.horiz == "left" then x = geom.x - elseif self.horiz == "right" then x = geom.width + geom.x - width - else x = geom.x + (geom.width - width)/2 end - if self.vert == "top" then y = geom.y - elseif self.vert == "bottom" then y = geom.height + geom.y - height - else y = geom.y + (geom.height - height)/2 end - self.geometry = { x = x, y = y, width = width, height = height } + return self.geometry[self.screen] end function quake:new(config) @@ -130,33 +129,26 @@ function quake:new(config) conf.screen = conf.screen or awful.screen.focused() -- If width or height <= 1 this is a proportion of the workspace - conf.height = conf.height or 0.25 -- height - conf.width = conf.width or 1 -- width - conf.vert = conf.vert or "top" -- top, bottom or center - conf.horiz = conf.horiz or "left" -- left, right or center + conf.height = conf.height or 0.25 -- height + conf.width = conf.width or 1 -- width + conf.vert = conf.vert or "top" -- top, bottom or center + conf.horiz = conf.horiz or "left" -- left, right or center + conf.geometry = {} -- internal use + + local dropdown = setmetatable(conf, { __index = quake }) - local console = setmetatable(conf, { __index = quake }) capi.client.connect_signal("manage", function(c) - if c.instance == console.name and c.screen == console.screen then - console:display() + if c.instance == dropdown.name and c.screen == dropdown.screen then + dropdown:display() end end) capi.client.connect_signal("unmanage", function(c) - if c.instance == console.name and c.screen == console.screen then - console.visible = false + if c.instance == dropdown.name and c.screen == dropdown.screen then + dropdown.visible = false end end) - -- "Reattach" currently running quake application. This is in case awesome is restarted. - local reattach = capi.timer { timeout = 0 } - reattach:connect_signal("timeout", function() - if self.followtag then self.screen = awful.screen.focused() end - reattach:stop() - console:display() - end) - reattach:start() - - return console + return dropdown end function quake:toggle() From ef6383061bbfefd09bbb28b8ce6e61e7074cce62 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sat, 21 Jan 2017 18:22:42 +0100 Subject: [PATCH 047/106] contrib.kbdlayout: asynchronous --- widgets/contrib/kbdlayout.lua | 41 +++++++++++++++++++---------------- wiki | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/widgets/contrib/kbdlayout.lua b/widgets/contrib/kbdlayout.lua index f57d2da..cd753f6 100644 --- a/widgets/contrib/kbdlayout.lua +++ b/widgets/contrib/kbdlayout.lua @@ -6,13 +6,14 @@ --]] -local newtimer = require("lain.helpers").newtimer -local read_pipe = require("lain.helpers").read_pipe +local helpers = require("lain.helpers") -local wibox = require("wibox") local awful = require("awful") +local wibox = require("wibox") -local string = { match = string.match } +local string = { format = string.format, + match = string.match } +local execute = os.execute local setmetatable = setmetatable @@ -20,9 +21,7 @@ local setmetatable = setmetatable -- lain.widgets.contrib.kblayout local function worker(args) - local kbdlayout = {} - kbdlayout.widget = wibox.widget.textbox('') - + local kbdlayout = {} local layouts = args.layouts local settings = args.settings or function () end local add_us_secondary = true @@ -31,40 +30,43 @@ local function worker(args) if args.add_us_secondary == false then add_us_secondary = false end + kbdlayout.widget = wibox.widget.textbox() + -- Mouse bindings kbdlayout.widget:buttons(awful.util.table.join( awful.button({ }, 1, function () kbdlayout.next() end), awful.button({ }, 3, function () kbdlayout.prev() end))) local function run_settings(layout, variant) - widget = kbdlayout.widget - kbdlayout_now = { - layout=string.match(layout, "[^,]+"), -- Make sure to match the primary layout only. - variant=variant + kbdlayout_now = { + layout = string.match(layout, "[^,]+"), -- Make sure to match the primary layout only. + variant = variant } + widget = kbdlayout.widget settings() end function kbdlayout.update() - local status = read_pipe('setxkbmap -query') - - run_settings(string.match(status, "layout:%s*([^\n]*)"), - string.match(status, "variant:%s*([^\n]*)")) + helpers.async(string.format("%s -c 'setxkbmap -query'", awful.util.shell), + function(status) + run_settings(string.match(status, "layout:%s*([^\n]*)"), + string.match(status, "variant:%s*([^\n]*)")) + end) end function kbdlayout.set(i) idx = ((i - 1) % #layouts) + 1 -- Make sure to wrap around as needed. - local to_execute = 'setxkbmap ' .. layouts[idx].layout + local to_execute = "setxkbmap " .. layouts[idx].layout if add_us_secondary and not string.match(layouts[idx].layout, ",?us,?") then to_execute = to_execute .. ",us" end if layouts[idx].variant then - to_execute = to_execute .. ' ' .. layouts[idx].variant + to_execute = to_execute .. " " .. layouts[idx].variant end - if os.execute(to_execute) then + if execute(to_execute) then run_settings(layouts[idx].layout, layouts[idx].variant) end end @@ -77,7 +79,8 @@ local function worker(args) kbdlayout.set(idx - 1) end - newtimer("kbdlayout", timeout, kbdlayout.update) + helpers.newtimer("kbdlayout", timeout, kbdlayout.update) + return setmetatable(kbdlayout, { __index = kbdlayout.widget }) end diff --git a/wiki b/wiki index d975ff0..bfdf6d2 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit d975ff04346986b5ab24e7bc16321e438d3425b8 +Subproject commit bfdf6d24310d0822bac3447c39bb93cb83a75f77 From 6cce5b6fe11fe8c69b08140d645c604fef59e42a Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sun, 22 Jan 2017 01:15:57 +0100 Subject: [PATCH 048/106] cal: asynchronous --- util/markup.lua | 58 ++++++++------------ widgets/alsabar.lua | 3 -- widgets/base.lua | 1 - widgets/bat.lua | 3 -- widgets/calendar.lua | 99 ++++++++++++++--------------------- widgets/contrib/gpmdp.lua | 4 +- widgets/contrib/kbdlayout.lua | 34 +++++------- widgets/contrib/moc.lua | 3 -- widgets/contrib/redshift.lua | 83 ++++++++++------------------- widgets/cpu.lua | 3 -- widgets/fs.lua | 5 +- widgets/imap.lua | 4 +- widgets/maildir.lua | 2 - widgets/mem.lua | 11 ++-- widgets/mpd.lua | 3 -- widgets/net.lua | 3 -- widgets/pulseaudio.lua | 4 +- widgets/pulsebar.lua | 3 -- widgets/sysload.lua | 5 +- widgets/temp.lua | 6 +-- widgets/weather.lua | 4 -- wiki | 2 +- 22 files changed, 114 insertions(+), 229 deletions(-) diff --git a/util/markup.lua b/util/markup.lua index d367bca..0fc6ef6 100644 --- a/util/markup.lua +++ b/util/markup.lua @@ -8,62 +8,46 @@ --]] -local beautiful = require("beautiful") -local tostring = tostring +local string = { format = string.format } local setmetatable = setmetatable -- Lain markup util submodule -- lain.util.markup local markup = {} -local fg = {} -local bg = {} - -- Convenience tags. -function markup.bold(text) return '' .. tostring(text) .. '' end -function markup.italic(text) return '' .. tostring(text) .. '' end -function markup.strike(text) return '' .. tostring(text) .. '' end -function markup.underline(text) return '' .. tostring(text) .. '' end -function markup.monospace(text) return '' .. tostring(text) .. '' end -function markup.big(text) return '' .. tostring(text) .. '' end -function markup.small(text) return '' .. tostring(text) .. '' end +function markup.bold(text) return '' .. text .. '' end +function markup.italic(text) return '' .. text .. '' end +function markup.strike(text) return '' .. text .. '' end +function markup.underline(text) return '' .. text .. '' end +function markup.monospace(text) return '' .. text .. '' end +function markup.big(text) return '' .. text .. '' end +function markup.small(text) return '' .. text .. '' end -- Set the font. function markup.font(font, text) - return '' .. tostring(text) ..'' + return '' .. text ..'' end -- Set the foreground. -function fg.color(color, text) - return '' .. tostring(text) .. '' +function markup.fgcolor(color, text) + return '' .. text .. '' end -- Set the background. -function bg.color(color, text) - return '' .. tostring(text) .. '' +function markup.bgcolor(color, text) + return '' .. text .. '' end --- Context: focus -function fg.focus(text) return fg.color(beautiful.fg_focus, text) end -function bg.focus(text) return bg.color(beautiful.bg_focus, text) end -function markup.focus(text) return bg.focus(fg.focus(text)) end +-- Set foreground and background. +function markup.color(fg, bg, text) + return string.format('%s', fg, bg, text) +end --- Context: normal -function fg.normal(text) return fg.color(beautiful.fg_normal, text) end -function bg.normal(text) return bg.color(beautiful.bg_normal, text) end -function markup.normal(text) return bg.normal(fg.normal(text)) end - --- Context: urgent -function fg.urgent(text) return fg.color(beautiful.fg_urgent, text) end -function bg.urgent(text) return bg.color(beautiful.bg_urgent, text) end -function markup.urgent(text) return bg.urgent(fg.urgent(text)) end - -markup.fg = fg -markup.bg = bg - --- link markup.{fg,bg}(...) calls to markup.{fg,bg}.color(...) -setmetatable(markup.fg, { __call = function(_, ...) return markup.fg.color(...) end }) -setmetatable(markup.bg, { __call = function(_, ...) return markup.bg.color(...) end }) +-- Set font, foreground and background. +function markup.fontcolor(font, fg, bg, text) + return string.format('%s', font, fg, bg, text) +end -- link markup(...) calls to markup.fg.color(...) return setmetatable(markup, { __call = function(_, ...) return markup.fg.color(...) end }) diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index 15ba311..f32e482 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -8,19 +8,16 @@ --]] local helpers = require("lain.helpers") - local awful = require("awful") local beautiful = require("beautiful") local naughty = require("naughty") local wibox = require("wibox") - local math = { modf = math.modf } local string = { format = string.format, match = string.match, rep = string.rep } local tonumber = tonumber local type = type - local setmetatable = setmetatable -- ALSA volume bar diff --git a/widgets/base.lua b/widgets/base.lua index af3d2c0..94ee58f 100644 --- a/widgets/base.lua +++ b/widgets/base.lua @@ -9,7 +9,6 @@ local newtimer = require("lain.helpers").newtimer local read_pipe = require("lain.helpers").read_pipe local wibox = require("wibox") - local setmetatable = setmetatable -- Basic template for custom widgets diff --git a/widgets/bat.lua b/widgets/bat.lua index 0b1bc0c..ea749d3 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -10,16 +10,13 @@ local first_line = require("lain.helpers").first_line local make_widget = require("lain.helpers").make_widget_textbox local newtimer = require("lain.helpers").newtimer - local naughty = require("naughty") local wibox = require("wibox") - local math = { abs = math.abs, floor = math.floor, log10 = math.log10, min = math.min } local string = { format = string.format } - local ipairs = ipairs local type = type local tonumber = tonumber diff --git a/widgets/calendar.lua b/widgets/calendar.lua index 76faca4..a00caba 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -6,53 +6,45 @@ --]] +local async = require("lain.helpers").async local icons_dir = require("lain.helpers").icons_dir - +local markup = require("lain.util.markup") local awful = require("awful") -local beautiful = require("beautiful") local naughty = require("naughty") - -local io = { popen = io.popen } -local os = { date = os.date } +local os = { date = os.date } local string = { format = string.format, - sub = string.sub, gsub = string.gsub } local tonumber = tonumber - local setmetatable = setmetatable -- Calendar notification -- lain.widgets.calendar -local calendar = {} -local cal_notification = nil +local calendar = { offset = 0 } function calendar.hide() - if cal_notification ~= nil then - naughty.destroy(cal_notification) - cal_notification = nil - end + if not calendar.notification then return end + naughty.destroy(calendar.notification) + calendar.notification = nil end function calendar.show(t_out, inc_offset, scr) calendar.hide() - local f, c_text - local offs = inc_offset or 0 - local tims = t_out or 0 - local today = tonumber(os.date('%d')) + local today = os.date("%d") + local offs = inc_offset or 0 + local f calendar.offset = calendar.offset + offs - if offs == 0 or calendar.offset == 0 - then -- current month showing, today highlighted + local current_month = (offs == 0 or calendar.offset == 0) + + if current_month then -- today highlighted calendar.offset = 0 calendar.notify_icon = string.format("%s%s.png", calendar.icons, today) - - -- bg and fg inverted to highlight today - f = io.popen(calendar.cal_format(today)) + f = calendar.cal else -- no current month showing, no day to highlight - local month = tonumber(os.date('%m')) - local year = tonumber(os.date('%Y')) + local month = tonumber(os.date("%m")) + local year = tonumber(os.date("%Y")) month = month + calendar.offset @@ -67,53 +59,40 @@ function calendar.show(t_out, inc_offset, scr) end calendar.notify_icon = nil - f = io.popen(string.format('%s %s %s', calendar.cal, month, year)) + f = string.format("%s %s %s", calendar.cal, month, year) end - c_text = "" - .. f:read() .. "\n\n" - .. f:read() .. "\n" - .. f:read("*all"):gsub("\n*$", "") - .. "" - f:close() - if calendar.followtag then - scrp = awful.screen.focused() + calendar.notification_preset.screen = awful.screen.focused() else - scrp = scr or calendar.scr_pos + calendar.notification_preset.screen = src or 1 end - cal_notification = naughty.notify({ - text = c_text, - icon = calendar.notify_icon, - position = calendar.position, - fg = calendar.fg, - bg = calendar.bg, - timeout = tims, - screen = scrp - }) + async(string.format("%s -c '%s'", awful.util.shell, f), function(ws) + fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg + ws = ws:gsub("%c%[7m%d+%c%[27m", markup.bold(markup.color(bg, fg, today))) + calendar.notification = naughty.notify({ + preset = calendar.notification_preset, + text = ws:gsub("\n*$", ""), + icon = calendar.notify_icon, + timeout = t_out or calendar.notification.preset.timeout or 5 + }) + end) end function calendar.attach(widget, args) - local args = args or {} + local args = args or {} + calendar.cal = args.cal or "/usr/bin/cal --color=always" + calendar.followtag = args.followtag or false + calendar.icons = args.icons or icons_dir .. "cal/white/" + calendar.notification_preset = args.notification_preset - calendar.cal = args.cal or "/usr/bin/cal" - calendar.cal_format = args.cal_format or function(today) - return string.format("%s | sed -r -e 's/_\\x08//g' -e '0,/(^| )%d($| )/ s/(^| )%d($| )/\\1%d<\\/span><\\/b>\\2/'", - calendar.cal, today, today, calendar.bg, calendar.fg, today) + if not calendar.notification_preset then + calendar.notification_preset = naughty.config.defaults + calendar.notification_preset.font = "Monospace 10" + calendar.notification_preset.fg = "#FFFFFF" + calendar.notification_preset.bg = "#000000" end - calendar.icons = args.icons or icons_dir .. "cal/white/" - calendar.font = args.font or beautiful.font:gsub(" %d.*", "") - calendar.font_size = tonumber(args.font_size) or 11 - calendar.fg = args.fg or beautiful.fg_normal or "#FFFFFF" - calendar.bg = args.bg or beautiful.bg_normal or "#000000" - calendar.position = args.position or "top_right" - calendar.scr_pos = args.scr_pos or 1 - calendar.followtag = args.followtag or false - - calendar.offset = 0 - calendar.notify_icon = nil widget:connect_signal("mouse::enter", function () calendar.show(0, 0, calendar.scr_pos) end) widget:connect_signal("mouse::leave", function () calendar.hide() end) diff --git a/widgets/contrib/gpmdp.lua b/widgets/contrib/gpmdp.lua index de82b1e..811d1f6 100644 --- a/widgets/contrib/gpmdp.lua +++ b/widgets/contrib/gpmdp.lua @@ -8,16 +8,14 @@ local helpers = require("lain.helpers") local json = require("lain.util.dkjson") - local focused = require("awful.screen").focused local pread = require("awful.util").pread local naughty = require("naughty") local wibox = require("wibox") - local next = next local os = { getenv = os.getenv } -local setmetatable = setmetatable local table = table +local setmetatable = setmetatable -- Google Play Music Desktop infos -- lain.widget.contrib.gpmdp diff --git a/widgets/contrib/kbdlayout.lua b/widgets/contrib/kbdlayout.lua index cd753f6..3b514c5 100644 --- a/widgets/contrib/kbdlayout.lua +++ b/widgets/contrib/kbdlayout.lua @@ -7,22 +7,20 @@ --]] local helpers = require("lain.helpers") - local awful = require("awful") local wibox = require("wibox") - local string = { format = string.format, match = string.match } local execute = os.execute - local setmetatable = setmetatable -- Keyboard layout switcher -- lain.widgets.contrib.kblayout +local kbdlayout = helpers.make_widget_textbox() local function worker(args) - local kbdlayout = {} - local layouts = args.layouts + local args = args or {} + local layouts = args.layouts or {} local settings = args.settings or function () end local add_us_secondary = true local timeout = args.timeout or 5 @@ -30,14 +28,7 @@ local function worker(args) if args.add_us_secondary == false then add_us_secondary = false end - kbdlayout.widget = wibox.widget.textbox() - - -- Mouse bindings - kbdlayout.widget:buttons(awful.util.table.join( - awful.button({ }, 1, function () kbdlayout.next() end), - awful.button({ }, 3, function () kbdlayout.prev() end))) - - local function run_settings(layout, variant) + local function kbd_run_settings(layout, variant) kbdlayout_now = { layout = string.match(layout, "[^,]+"), -- Make sure to match the primary layout only. variant = variant @@ -49,12 +40,13 @@ local function worker(args) function kbdlayout.update() helpers.async(string.format("%s -c 'setxkbmap -query'", awful.util.shell), function(status) - run_settings(string.match(status, "layout:%s*([^\n]*)"), + kbd_run_settings(string.match(status, "layout:%s*([^\n]*)"), string.match(status, "variant:%s*([^\n]*)")) end) end function kbdlayout.set(i) + if #layouts == 0 then return end idx = ((i - 1) % #layouts) + 1 -- Make sure to wrap around as needed. local to_execute = "setxkbmap " .. layouts[idx].layout @@ -67,17 +59,17 @@ local function worker(args) end if execute(to_execute) then - run_settings(layouts[idx].layout, layouts[idx].variant) + kbd_run_settings(layouts[idx].layout, layouts[idx].variant) end end - function kbdlayout.next() - kbdlayout.set(idx + 1) - end + function kbdlayout.next() kbdlayout.set(idx + 1) end + function kbdlayout.prev() kbdlayout.set(idx - 1) end - function kbdlayout.prev() - kbdlayout.set(idx - 1) - end + -- Mouse bindings + kbdlayout.widget:buttons(awful.util.table.join( + awful.button({ }, 1, function () kbdlayout.next() end), + awful.button({ }, 3, function () kbdlayout.prev() end))) helpers.newtimer("kbdlayout", timeout, kbdlayout.update) diff --git a/widgets/contrib/moc.lua b/widgets/contrib/moc.lua index f19b0d3..44f46a6 100644 --- a/widgets/contrib/moc.lua +++ b/widgets/contrib/moc.lua @@ -7,17 +7,14 @@ --]] local helpers = require("lain.helpers") - local shell = require("awful.util").shell local focused = require("awful.screen").focused local escape_f = require("awful.util").escape local naughty = require("naughty") local wibox = require("wibox") - local os = { getenv = os.getenv } local string = { format = string.format, gmatch = string.gmatch } - local setmetatable = setmetatable -- MOC audio player diff --git a/widgets/contrib/redshift.lua b/widgets/contrib/redshift.lua index 25ae023..8a768fb 100644 --- a/widgets/contrib/redshift.lua +++ b/widgets/contrib/redshift.lua @@ -6,72 +6,47 @@ --]] -local awful = require("awful") -local os = os - -local setmetatable = setmetatable +local async = require("lain.helpers").async +local awful = require("awful") +local execute = os.execute +local type = type -- Redshift -- lain.widgets.contrib.redshift -local redshift = {} +local redshift = { active = false, pid = nil } -local attached = false -- true if attached to a widget -local active = false -- true if redshift is active -local running = false -- true if redshift was initialized -local update_fnct = function() end -- Function that is run each time redshift is toggled. See redshift:attach(). - -local function init() - -- As there is no way to determine if redshift was previously - -- toggled off (i.e Awesome on-the-fly restart), kill redshift to make sure - os.execute("pkill redshift") - -- Remove existing color adjustment - awful.spawn.with_shell("redshift -x") - -- (Re)start redshift - awful.spawn.with_shell("redshift") - running = true - active = true +function redshift:start() + execute("pkill redshift") + awful.spawn.with_shell("redshift -x") -- clear adjustments + redshift.pid = awful.spawn.with_shell("redshift") + redshift.active = true + if type(redshift.update_fun) == "function" then + redshift.update_fun(redshift.active) + end end function redshift:toggle() - if running then - -- Sending -USR1 toggles redshift (See project website) - os.execute("pkill -USR1 redshift") - active = not active - else - init() - end - update_fnct() -end - -function redshift:off() - if running and active then - redshift:toggle() - end -end - -function redshift:on() - if not active then - redshift:toggle() - end -end - -function redshift:is_active() - return active + async(string.format("%s -c 'ps -p %d -o pid='", awful.util.shell, redshift.pid), function(f) + if f and #f > 0 then -- redshift is running + -- Sending -USR1 toggles redshift (See project website) + execute("pkill -USR1 redshift") + redshift.active = not redshift.active + else -- not started or killed, (re)start it + redshift:start() + end + redshift.update_fun(redshift.active) + end) end -- Attach to a widget -- Provides a button which toggles redshift on/off on click -- @param widget: Widget to attach to. --- @param fnct: Function to be run each time redshift is toggled (optional). +-- @param fun: Function to be run each time redshift is toggled (optional). -- Use it to update widget text or icons on status change. -function redshift:attach(widget, fnct) - update_fnct = fnct or function() end - if not attached then - init() - attached = true - update_fnct() - end - widget:buttons(awful.util.table.join( awful.button({}, 1, function () redshift:toggle() end) )) +function redshift:attach(widget, fun) + redshift.update_fun = fun or function() end + if not redshift.pid then redshift:start() end + widget:buttons(awful.util.table.join(awful.button({}, 1, function () redshift:toggle() end))) end -return setmetatable(redshift, { _call = function(_, ...) return create(...) end }) +return redshift diff --git a/widgets/cpu.lua b/widgets/cpu.lua index c33c7eb..c294566 100644 --- a/widgets/cpu.lua +++ b/widgets/cpu.lua @@ -9,14 +9,11 @@ local lines_match = require("lain.helpers").lines_match local newtimer = require("lain.helpers").newtimer - local wibox = require("wibox") - local math = { ceil = math.ceil } local string = { format = string.format, gmatch = string.gmatch } local tostring = tostring - local setmetatable = setmetatable -- CPU usage diff --git a/widgets/fs.lua b/widgets/fs.lua index b48fcd0..faa8038 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -9,7 +9,6 @@ local helpers = require("lain.helpers") local shell = require("awful.util").shell -local beautiful = require("beautiful") local focused = require("awful.screen").focused local wibox = require("wibox") local naughty = require("naughty") @@ -62,7 +61,7 @@ local function worker(args) fs.options = args.options fs.followtag = args.followtag or false - fs.notification_preset = args.notification_preset or { fg = beautiful.fg_normal } + fs.notification_preset = args.notification_preset or naughty.config.defaults fs.widget = wibox.widget.textbox() @@ -101,7 +100,7 @@ local function worker(args) if notify == "on" and tonumber(fs_now.used) >= 99 and not helpers.get_map(partition) then naughty.notify({ - title = "warning", + title = "Warning", text = partition .. " is empty!", timeout = 8, fg = "#000000", diff --git a/widgets/imap.lua b/widgets/imap.lua index 60a5509..0f8d994 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -7,15 +7,12 @@ --]] local helpers = require("lain.helpers") - local shell = require("awful.util").shell local naughty = require("naughty") local wibox = require("wibox") - local string = { format = string.format, gsub = string.gsub } local tonumber = tonumber - local setmetatable = setmetatable -- Mail IMAP check @@ -59,6 +56,7 @@ local function worker(args ) helpers.async(curl, function(f) _, mailcount = string.gsub(f, "%d+", "") + _ = nil widget = imap.widget settings() diff --git a/widgets/maildir.lua b/widgets/maildir.lua index 2f435b3..bef09f4 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -10,12 +10,10 @@ local awful = require("awful") local wibox = require("wibox") local helpers = require("lain.helpers") - local io = { popen = io.popen } local os = { getenv = os.getenv } local string = { format = string.format, match = string.match } - local setmetatable = setmetatable -- Maildir check (synchronous) diff --git a/widgets/mem.lua b/widgets/mem.lua index aede803..7f4f346 100644 --- a/widgets/mem.lua +++ b/widgets/mem.lua @@ -8,13 +8,10 @@ --]] local newtimer = require("lain.helpers").newtimer - local wibox = require("wibox") - local io = { lines = io.lines } local math = { floor = math.floor } local string = { gmatch = string.gmatch } - local setmetatable = setmetatable -- Memory usage (ignoring caches) @@ -26,14 +23,12 @@ local function worker(args) local timeout = args.timeout or 2 local settings = args.settings or function() end - mem.widget = wibox.widget.textbox('') + mem.widget = wibox.widget.textbox() function update() mem_now = {} - for line in io.lines("/proc/meminfo") - do - for k, v in string.gmatch(line, "([%a]+):[%s]+([%d]+).+") - do + for line in io.lines("/proc/meminfo") do + for k, v in string.gmatch(line, "([%a]+):[%s]+([%d]+).+") do if k == "MemTotal" then mem_now.total = math.floor(v / 1024) elseif k == "MemFree" then mem_now.free = math.floor(v / 1024) elseif k == "Buffers" then mem_now.buf = math.floor(v / 1024) diff --git a/widgets/mpd.lua b/widgets/mpd.lua index defa710..6011e03 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -8,18 +8,15 @@ --]] local helpers = require("lain.helpers") - local shell = require("awful.util").shell local escape_f = require("awful.util").escape local focused = require("awful.screen").focused local naughty = require("naughty") local wibox = require("wibox") - local os = { getenv = os.getenv } local string = { format = string.format, gmatch = string.gmatch, match = string.match } - local setmetatable = setmetatable -- MPD infos diff --git a/widgets/net.lua b/widgets/net.lua index 83ac6bf..ff16075 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -10,12 +10,9 @@ local helpers = require("lain.helpers") local naughty = require("naughty") local wibox = require("wibox") - local shell = require("awful.util").shell - local string = { format = string.format, match = string.match } - local setmetatable = setmetatable -- Network infos diff --git a/widgets/pulseaudio.lua b/widgets/pulseaudio.lua index 15bea8b..45981f3 100644 --- a/widgets/pulseaudio.lua +++ b/widgets/pulseaudio.lua @@ -9,11 +9,9 @@ local read_pipe = require("lain.helpers").read_pipe local newtimer = require("lain.helpers").newtimer local wibox = require("wibox") - local string = { gmatch = string.gmatch, match = string.match, format = string.format } - local setmetatable = setmetatable -- PulseAudio volume @@ -27,7 +25,7 @@ local function worker(args) local scallback = args.scallback pulseaudio.cmd = args.cmd or string.format("pacmd list-sinks | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'") - pulseaudio.widget = wibox.widget.textbox('') + pulseaudio.widget = wibox.widget.textbox() function pulseaudio.update() if scallback then pulseaudio.cmd = scallback() end diff --git a/widgets/pulsebar.lua b/widgets/pulsebar.lua index bacd969..b7fb1e9 100644 --- a/widgets/pulsebar.lua +++ b/widgets/pulsebar.lua @@ -9,19 +9,16 @@ local newtimer = require("lain.helpers").newtimer local read_pipe = require("lain.helpers").read_pipe - local awful = require("awful") local beautiful = require("beautiful") local naughty = require("naughty") local wibox = require("wibox") - local math = { modf = math.modf } local mouse = mouse local string = { format = string.format, match = string.match, rep = string.rep } local tonumber = tonumber - local setmetatable = setmetatable -- Pulseaudio volume bar diff --git a/widgets/sysload.lua b/widgets/sysload.lua index d8e4713..215fd62 100644 --- a/widgets/sysload.lua +++ b/widgets/sysload.lua @@ -8,12 +8,9 @@ --]] local newtimer = require("lain.helpers").newtimer - local wibox = require("wibox") - local io = { open = io.open } local string = { match = string.match } - local setmetatable = setmetatable -- System load @@ -25,7 +22,7 @@ local function worker(args) local timeout = args.timeout or 2 local settings = args.settings or function() end - sysload.widget = wibox.widget.textbox('') + sysload.widget = wibox.widget.textbox() function update() local f = io.open("/proc/loadavg") diff --git a/widgets/temp.lua b/widgets/temp.lua index a4ada52..9c82b8b 100644 --- a/widgets/temp.lua +++ b/widgets/temp.lua @@ -7,12 +7,9 @@ --]] local newtimer = require("lain.helpers").newtimer - local wibox = require("wibox") - local io = { open = io.open } local tonumber = tonumber - local setmetatable = setmetatable -- coretemp @@ -25,10 +22,11 @@ local function worker(args) local tempfile = args.tempfile or "/sys/class/thermal/thermal_zone0/temp" local settings = args.settings or function() end - temp.widget = wibox.widget.textbox('') + temp.widget = wibox.widget.textbox() function update() local f = io.open(tempfile) + local coretemp_now if f then coretemp_now = tonumber(f:read("*all")) / 1000 f:close() diff --git a/widgets/weather.lua b/widgets/weather.lua index 17b3d34..32e3065 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -10,19 +10,15 @@ local async = require("lain.helpers").async local newtimer = require("lain.helpers").newtimer local lain_icons = require("lain.helpers").icons_dir local json = require("lain.util").dkjson - local focused = require("awful.screen").focused local naughty = require("naughty") local wibox = require("wibox") - local math = { floor = math.floor } local os = { time = os.time, date = os.date, difftime = os.difftime } local string = { format = string.format, gsub = string.gsub } - -local mouse = mouse local tonumber = tonumber local setmetatable = setmetatable diff --git a/wiki b/wiki index bfdf6d2..eb533f6 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit bfdf6d24310d0822bac3447c39bb93cb83a75f77 +Subproject commit eb533f62754d1403e01048b7f2006ab2d8c94b11 From fadc722655b2ba4ebe98eece3498da3c88f8b6fc Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sun, 22 Jan 2017 01:27:24 +0100 Subject: [PATCH 049/106] revert fix coretemp --- util/markup.lua | 10 +++++++--- widgets/cpu.lua | 2 +- widgets/temp.lua | 1 - wiki | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/util/markup.lua b/util/markup.lua index 0fc6ef6..346cfe1 100644 --- a/util/markup.lua +++ b/util/markup.lua @@ -13,7 +13,7 @@ local setmetatable = setmetatable -- Lain markup util submodule -- lain.util.markup -local markup = {} +local markup = { fg = {}, bg = {} } -- Convenience tags. function markup.bold(text) return '' .. text .. '' end @@ -30,12 +30,12 @@ function markup.font(font, text) end -- Set the foreground. -function markup.fgcolor(color, text) +function markup.fg.color(color, text) return '' .. text .. '' end -- Set the background. -function markup.bgcolor(color, text) +function markup.bg.color(color, text) return '' .. text .. '' end @@ -49,5 +49,9 @@ function markup.fontcolor(font, fg, bg, text) return string.format('%s', font, fg, bg, text) end +-- link markup.{fg,bg}(...) calls to markup.{fg,bg}.color(...) +setmetatable(markup.fg, { __call = function(_, ...) return markup.fg.color(...) end }) +setmetatable(markup.bg, { __call = function(_, ...) return markup.bg.color(...) end }) + -- link markup(...) calls to markup.fg.color(...) return setmetatable(markup, { __call = function(_, ...) return markup.fg.color(...) end }) diff --git a/widgets/cpu.lua b/widgets/cpu.lua index c294566..8501388 100644 --- a/widgets/cpu.lua +++ b/widgets/cpu.lua @@ -25,7 +25,7 @@ local function worker(args) local timeout = args.timeout or 2 local settings = args.settings or function() end - cpu.widget = wibox.widget.textbox('') + cpu.widget = wibox.widget.textbox() function update() -- Read the amount of time the CPUs have spent performing diff --git a/widgets/temp.lua b/widgets/temp.lua index 9c82b8b..cdf3002 100644 --- a/widgets/temp.lua +++ b/widgets/temp.lua @@ -26,7 +26,6 @@ local function worker(args) function update() local f = io.open(tempfile) - local coretemp_now if f then coretemp_now = tonumber(f:read("*all")) / 1000 f:close() diff --git a/wiki b/wiki index eb533f6..2a2beda 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit eb533f62754d1403e01048b7f2006ab2d8c94b11 +Subproject commit 2a2beda916322177695fbd8b042b04001bc07509 From f82f0ed20542258833e866c8f33bc54c57c3b863 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sun, 22 Jan 2017 02:13:02 +0100 Subject: [PATCH 050/106] small fixes --- util/init.lua | 1 + util/separators.lua | 14 +++++++------- widgets/contrib/tpbat/init.lua | 22 ++++++++++------------ widgets/fs.lua | 9 ++++++++- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/util/init.lua b/util/init.lua index 5596afa..3db478d 100644 --- a/util/init.lua +++ b/util/init.lua @@ -166,6 +166,7 @@ end -- On the fly useless gaps change function util.useless_gaps_resize(thatmuch) + beautiful.useless_gap = beautiful.useless_gap or 0 beautiful.useless_gap = tonumber(beautiful.useless_gap) + thatmuch awful.layout.arrange(awful.screen.focused()) end diff --git a/util/separators.lua b/util/separators.lua index af3e3a8..abf57c4 100644 --- a/util/separators.lua +++ b/util/separators.lua @@ -8,15 +8,11 @@ --]] local wibox = require("wibox") -local beautiful = require("beautiful") local gears = require("gears") -- Lain Cairo separators util submodule -- lain.util.separators -local separators = {} - -local height = beautiful.separators_height or 0 -local width = beautiful.separators_width or 9 +local separators = { height = 0, width = 9 } -- [[ Arrow @@ -24,7 +20,9 @@ local width = beautiful.separators_width or 9 function separators.arrow_right(col1, col2) local widget = wibox.widget.base.make_widget() - widget.fit = function(m, w, h) return width, height end + widget.fit = function(m, w, h) + return separators.width, separators.height + end widget.draw = function(mycross, wibox, cr, width, height) if col2 ~= "alpha" then @@ -62,7 +60,9 @@ end function separators.arrow_left(col1, col2) local widget = wibox.widget.base.make_widget() - widget.fit = function(m, w, h) return width, height end + widget.fit = function(m, w, h) + return separators.width, separators.height + end widget.draw = function(mycross, wibox, cr, width, height) if col1 ~= "alpha" then diff --git a/widgets/contrib/tpbat/init.lua b/widgets/contrib/tpbat/init.lua index 0a22526..8b53a4b 100644 --- a/widgets/contrib/tpbat/init.lua +++ b/widgets/contrib/tpbat/init.lua @@ -34,22 +34,20 @@ local smapi = require("smapi") local tpbat = { } local tpbat_notification = nil -function tpbat:hide() - if tpbat_notification ~= nil - then - naughty.destroy(tpbat_notification) - tpbat_notification = nil - end +function tpbat.hide() + if not tpbat.notification then return end + naughty.destroy(tpbat.notification) + tpbat.notification = nil end -function tpbat:show(t_out) - tpbat:hide() +function tpbat.show(t_out) + tpbat.hide() local bat = self.bat - local t_out = t_out or 0 if bat == nil or not bat:installed() then return end + local t_out = t_out or 0 local mfgr = bat:get('manufacturer') or "no_mfgr" local model = bat:get('model') or "no_model" local chem = bat:get('chemistry') or "no_chem" @@ -73,7 +71,7 @@ function tpbat:show(t_out) .. string.format("\n%s \t\t\t %s", status:upper(), msg) tpbat_notification = naughty.notify({ - preset = { fg = beautiful.fg_normal }, + preset = naughty.config.defaults, text = str, timeout = t_out, screen = client.focus and client.focus.screen or 1 @@ -161,8 +159,8 @@ function tpbat.register(args) newtimer("tpbat-" .. bat.name, timeout, update) - widget:connect_signal('mouse::enter', function () tpbat:show() end) - widget:connect_signal('mouse::leave', function () tpbat:hide() end) + widget:connect_signal('mouse::enter', function () tpbat.show() end) + widget:connect_signal('mouse::leave', function () tpbat.hide() end) return tpbat.widget end diff --git a/widgets/fs.lua b/widgets/fs.lua index faa8038..391c260 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -61,7 +61,14 @@ local function worker(args) fs.options = args.options fs.followtag = args.followtag or false - fs.notification_preset = args.notification_preset or naughty.config.defaults + fs.notification_preset = args.notification_preset + + if not fs.notification_preset then + fs.notification_preset = naughty.config.defaults + fs.notification_preset.font = "Monospace 10" + fs.notification_preset.fg = "#FFFFFF" + fs.notification_preset.bg = "#000000" + end fs.widget = wibox.widget.textbox() From a58e36385cbd3f177134210386a6e6232d673a17 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sun, 22 Jan 2017 14:58:05 +0100 Subject: [PATCH 051/106] added issue_template --- ISSUE_TEMPLATE.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 ISSUE_TEMPLATE.md diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..e98373d --- /dev/null +++ b/ISSUE_TEMPLATE.md @@ -0,0 +1,7 @@ +**Please read the wiki and browse the Issues section first.** + +If you can't find a solution there, then go ahead and provide: + +* output of `awesome -v` and `lua -v` +* expected behavior and actual behavior +* steps to reproduce the problem From ba91548161e39d383fe909a7d10ee56d2a5e5183 Mon Sep 17 00:00:00 2001 From: ProfessorOptics Date: Mon, 23 Jan 2017 14:07:26 +0200 Subject: [PATCH 052/106] fixed spelling heigth > height; added support for mouse buttons 1 through 5; added togglechannel as per previous version using new api; small fixes to accomodate togglechannel feature --- widgets/alsabar.lua | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index f32e482..3ade35c 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -1,10 +1,7 @@ - --[[ - - Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham - * (c) 2013, Rman - + Licensed under GNU General Public License v2 + * (c) 2013, Luke Bonham + * (c) 2013, Rman --]] local helpers = require("lain.helpers") @@ -19,12 +16,14 @@ local string = { format = string.format, local tonumber = tonumber local type = type local setmetatable = setmetatable +local terminal = "urxvtc" or "xterm" -- ALSA volume bar -- lain.widgets.alsabar local alsabar = { channel = "Master", step = "1%", + mixer = "amixer", colors = { background = beautiful.bg_normal, @@ -48,17 +47,22 @@ local function worker(args) local timeout = args.timeout or 5 local settings = args.settings or function() end local width = args.width or 63 - local height = args.heigth or 1 + local height = args.height or 1 local ticks = args.ticks or false local ticks_size = args.ticks_size or 7 local vertical = args.vertical or false - alsabar.cmd = args.cmd or "amixer" + alsabar.mixer = args.mixer or alsabar.mixer alsabar.channel = args.channel or alsabar.channel + alsabar.togglechannel = args.togglechannel or alsabar.togglechannel + alsabar.cmd = args.cmd or {"bash", "-c", string.format("%s get %s", alsabar.mixer, alsabar.channel)} alsabar.step = args.step or alsabar.step alsabar.colors = args.colors or alsabar.colors alsabar.notifications = args.notifications or alsabar.notifications alsabar.followtag = args.followtag or false + if alsabar.togglechannel then + alsabar.cmd = args.cmd or { "bash", "-c", string.format("%s get %s; %s get %s", alsabar.mixer, alsabar.channel, alsabar.mixer, alsabar.togglechannel)} + end alsabar.bar = wibox.widget { forced_height = height, @@ -73,6 +77,27 @@ local function worker(args) layout = vertical and wibox.container.rotate } + alsabar.bar:buttons (awful.util.table.join( + awful.button({}, 1, function() + awful.spawn(string.format('%s -e alsamixer', terminal)) + end), + awful.button({}, 2, function() + awful.spawn(string.format("%s set %s 100%%", alsabar.mixer, alsabar.channel)) + alsabar.update() + end), + awful.button({}, 3, function() + awful.spawn(string.format("%s set %s toggle", alsabar.mixer, alsabar.togglechannel or alsabar.channel)) + alsabar.update() + end), + awful.button({}, 4, function() + awful.spawn(string.format("%s set %s %s+", alsabar.mixer, alsabar.channel, alsabar.step)) + alsabar.update() + end), + awful.button({}, 5, function() + awful.spawn(string.format("%s set %s %s-", alsabar.mixer, alsabar.channel, alsabar.step)) + alsabar.update() + end))) + alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } }) function alsabar.update(callback) From 23318f8eeafaedcb77d2ee1850dc4606dea7dcaf Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 23 Jan 2017 13:35:30 +0100 Subject: [PATCH 053/106] mem: math.floor->ceil and substract SReclaimable too from the total; closes #271 --- scripts/dfs | 2 +- util/init.lua | 1 - widgets/mem.lua | 25 +++++++++++++------------ wiki | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/dfs b/scripts/dfs index 1de819a..4697473 100755 --- a/scripts/dfs +++ b/scripts/dfs @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env sh # # Adapted from Eridan's "fs" (cleanup, enhancements and switch to bash/Linux) # JM, 10/12/2004 diff --git a/util/init.lua b/util/init.lua index 3db478d..c62f0da 100644 --- a/util/init.lua +++ b/util/init.lua @@ -89,7 +89,6 @@ function util.mc(c) c.floating = true local s = awful.screen.focused() local mg = s.geometry - local tag = s.selected_tag local mwfact = beautiful.master_width_factor or 0.5 local g = {} g.width = math.sqrt(mwfact) * mg.width diff --git a/widgets/mem.lua b/widgets/mem.lua index 7f4f346..763ac4b 100644 --- a/widgets/mem.lua +++ b/widgets/mem.lua @@ -9,9 +9,9 @@ local newtimer = require("lain.helpers").newtimer local wibox = require("wibox") -local io = { lines = io.lines } -local math = { floor = math.floor } -local string = { gmatch = string.gmatch } +local gmatch = string.gmatch +local lines = io.lines +local math = { ceil = math.ceil, floor = math.floor } local setmetatable = setmetatable -- Memory usage (ignoring caches) @@ -27,19 +27,20 @@ local function worker(args) function update() mem_now = {} - for line in io.lines("/proc/meminfo") do - for k, v in string.gmatch(line, "([%a]+):[%s]+([%d]+).+") do - if k == "MemTotal" then mem_now.total = math.floor(v / 1024) - elseif k == "MemFree" then mem_now.free = math.floor(v / 1024) - elseif k == "Buffers" then mem_now.buf = math.floor(v / 1024) - elseif k == "Cached" then mem_now.cache = math.floor(v / 1024) - elseif k == "SwapTotal" then mem_now.swap = math.floor(v / 1024) - elseif k == "SwapFree" then mem_now.swapf = math.floor(v / 1024) + for line in lines("/proc/meminfo") do + for k, v in gmatch(line, "([%a]+):[%s]+([%d]+).+") do + if k == "MemTotal" then mem_now.total = math.ceil(v / 1024) + elseif k == "MemFree" then mem_now.free = math.ceil(v / 1024) + elseif k == "Buffers" then mem_now.buf = math.ceil(v / 1024) + elseif k == "Cached" then mem_now.cache = math.ceil(v / 1024) + elseif k == "SwapTotal" then mem_now.swap = math.ceil(v / 1024) + elseif k == "SwapFree" then mem_now.swapf = math.ceil(v / 1024) + elseif k == "SReclaimable" then mem_now.srec = math.ceil(v / 1024) end end end - mem_now.used = mem_now.total - (mem_now.free + mem_now.buf + mem_now.cache) + mem_now.used = mem_now.total - mem_now.free - mem_now.buf - mem_now.cache - mem_now.srec mem_now.swapused = mem_now.swap - mem_now.swapf mem_now.perc = math.floor(mem_now.used / mem_now.total * 100) diff --git a/wiki b/wiki index 2a2beda..a1f6085 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 2a2beda916322177695fbd8b042b04001bc07509 +Subproject commit a1f6085dae8150248baf97bb12229c1c81387f24 From 7594da1b59e22cf16ced92d0b8c6facf09e30181 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 23 Jan 2017 15:11:49 +0100 Subject: [PATCH 054/106] alsabar: revert #275; remove buttons and beautiful deps --- widgets/alsabar.lua | 58 ++++++++++++++++----------------------------- wiki | 2 +- 2 files changed, 22 insertions(+), 38 deletions(-) diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index f32e482..20a678e 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -9,7 +9,6 @@ local helpers = require("lain.helpers") local awful = require("awful") -local beautiful = require("beautiful") local naughty = require("naughty") local wibox = require("wibox") local math = { modf = math.modf } @@ -23,22 +22,12 @@ local setmetatable = setmetatable -- ALSA volume bar -- lain.widgets.alsabar local alsabar = { - channel = "Master", - step = "1%", - colors = { - background = beautiful.bg_normal, + background = "#000000", mute = "#EB8F8F", unmute = "#A4CE8A" }, - notifications = { - font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")), - font_size = "11", - color = beautiful.fg_normal, - screen = 1 - }, - _current_level = 0, _muted = false } @@ -48,17 +37,22 @@ local function worker(args) local timeout = args.timeout or 5 local settings = args.settings or function() end local width = args.width or 63 - local height = args.heigth or 1 + local height = args.height or 1 local ticks = args.ticks or false local ticks_size = args.ticks_size or 7 local vertical = args.vertical or false - alsabar.cmd = args.cmd or "amixer" - alsabar.channel = args.channel or alsabar.channel - alsabar.step = args.step or alsabar.step - alsabar.colors = args.colors or alsabar.colors - alsabar.notifications = args.notifications or alsabar.notifications - alsabar.followtag = args.followtag or false + alsabar.cmd = args.cmd or "amixer" + alsabar.channel = args.channel or "Master" + alsabar.colors = args.colors or alsabar.colors + alsabar.followtag = args.followtag or false + alsabar._notify = args.notify or "on" + alsabar.notification_preset = args.notification_preset + + if not alsabar.notification_preset then + alsabar.notification_preset = naughty.config.defaults + alsabar.notification_preset.font = "Monospace 11" + end alsabar.bar = wibox.widget { forced_height = height, @@ -82,8 +76,7 @@ local function worker(args) then alsabar._current_level = tonumber(volu) or alsabar._current_level alsabar.bar:set_value(alsabar._current_level / 100) - if (not mute and tonumber(volu) == 0) or mute == "off" - then + if (not mute and tonumber(volu) == 0) or mute == "off" then alsabar._muted = true alsabar.tooltip:set_text ("[Muted]") alsabar.bar.color = alsabar.colors.mute @@ -106,15 +99,7 @@ local function worker(args) function alsabar.notify() alsabar.update(function() - local preset = { - title = "", - text = "", - timeout = 5, - screen = alsabar.notifications.screen, - font = string.format("%s %s", alsabar.notifications.font, - alsabar.notifications.font_size), - fg = alsabar.notifications.color - } + local preset = alsabar.notification_preset if alsabar._muted then preset.title = string.format("%s - Muted", alsabar.channel) @@ -128,18 +113,17 @@ local function worker(args) if alsabar.followtag then preset.screen = awful.screen.focused() end - if alsabar._notify then - alsabar._notify = naughty.notify ({ - replaces_id = alsabar._notify.id, - preset = preset, - }) - else - alsabar._notify = naughty.notify ({ preset = preset }) + if alsabar._notify == "on" then + alsabar.id = naughty.notify ({ + replaces_id = alsabar.id, + preset = preset + }).id end end) end timer_id = string.format("alsabar-%s-%s", alsabar.cmd, alsabar.channel) + helpers.newtimer(timer_id, timeout, alsabar.update) return alsabar diff --git a/wiki b/wiki index a1f6085..a361f62 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit a1f6085dae8150248baf97bb12229c1c81387f24 +Subproject commit a361f62a126fb7de921bc3c49db8a35bebad355a From 0180aa3bc348520c01479c40cdf6343e36ce3e59 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 23 Jan 2017 15:28:35 +0100 Subject: [PATCH 055/106] wiki updated --- widgets/alsabar.lua | 85 +++++++++++---------------------------------- wiki | 2 +- 2 files changed, 21 insertions(+), 66 deletions(-) diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index 430063b..6a03a10 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -1,7 +1,10 @@ + --[[ - Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham - * (c) 2013, Rman + + Licensed under GNU General Public License v2 + * (c) 2013, Luke Bonham + * (c) 2013, Rman + --]] local helpers = require("lain.helpers") @@ -13,20 +16,11 @@ local string = { format = string.format, match = string.match, rep = string.rep } local tonumber = tonumber -local type = type local setmetatable = setmetatable -local terminal = "urxvtc" or "xterm" -- ALSA volume bar -- lain.widgets.alsabar local alsabar = { -<<<<<<< HEAD -======= - channel = "Master", - step = "1%", - mixer = "amixer", - ->>>>>>> 09c0a3f27b6c0b61a55e7875b9a967e98cd3daf8 colors = { background = "#000000", mute = "#EB8F8F", @@ -38,16 +32,15 @@ local alsabar = { } local function worker(args) - local args = args or {} - local timeout = args.timeout or 5 - local settings = args.settings or function() end - local width = args.width or 63 - local height = args.height or 1 - local ticks = args.ticks or false - local ticks_size = args.ticks_size or 7 - local vertical = args.vertical or false + local args = args or {} + local timeout = args.timeout or 5 + local settings = args.settings or function() end + local width = args.width or 63 + local height = args.height or 1 + local ticks = args.ticks or false + local ticks_size = args.ticks_size or 7 + local vertical = args.vertical or false -<<<<<<< HEAD alsabar.cmd = args.cmd or "amixer" alsabar.channel = args.channel or "Master" alsabar.colors = args.colors or alsabar.colors @@ -58,18 +51,6 @@ local function worker(args) if not alsabar.notification_preset then alsabar.notification_preset = naughty.config.defaults alsabar.notification_preset.font = "Monospace 11" -======= - alsabar.mixer = args.mixer or alsabar.mixer - alsabar.channel = args.channel or alsabar.channel - alsabar.togglechannel = args.togglechannel or alsabar.togglechannel - alsabar.cmd = args.cmd or {"bash", "-c", string.format("%s get %s", alsabar.mixer, alsabar.channel)} - alsabar.step = args.step or alsabar.step - alsabar.colors = args.colors or alsabar.colors - alsabar.notifications = args.notifications or alsabar.notifications - alsabar.followtag = args.followtag or false - if alsabar.togglechannel then - alsabar.cmd = args.cmd or { "bash", "-c", string.format("%s get %s; %s get %s", alsabar.mixer, alsabar.channel, alsabar.mixer, alsabar.togglechannel)} ->>>>>>> 09c0a3f27b6c0b61a55e7875b9a967e98cd3daf8 end alsabar.bar = wibox.widget { @@ -85,34 +66,12 @@ local function worker(args) layout = vertical and wibox.container.rotate } - alsabar.bar:buttons (awful.util.table.join( - awful.button({}, 1, function() - awful.spawn(string.format('%s -e alsamixer', terminal)) - end), - awful.button({}, 2, function() - awful.spawn(string.format("%s set %s 100%%", alsabar.mixer, alsabar.channel)) - alsabar.update() - end), - awful.button({}, 3, function() - awful.spawn(string.format("%s set %s toggle", alsabar.mixer, alsabar.togglechannel or alsabar.channel)) - alsabar.update() - end), - awful.button({}, 4, function() - awful.spawn(string.format("%s set %s %s+", alsabar.mixer, alsabar.channel, alsabar.step)) - alsabar.update() - end), - awful.button({}, 5, function() - awful.spawn(string.format("%s set %s %s-", alsabar.mixer, alsabar.channel, alsabar.step)) - alsabar.update() - end))) - alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } }) - function alsabar.update(callback) + function alsabar.update() helpers.async(alsabar.cmd, function(mixer) local volu,mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)") - if (volu and tonumber(volu) ~= alsabar._current_level) or (mute and string.match(mute, "on") ~= alsabar._muted) - then + if (volu and tonumber(volu) ~= alsabar._current_level) or (mute and string.match(mute, "on") ~= alsabar._muted) then alsabar._current_level = tonumber(volu) or alsabar._current_level alsabar.bar:set_value(alsabar._current_level / 100) if (not mute and tonumber(volu) == 0) or mute == "off" then @@ -130,8 +89,6 @@ local function worker(args) volume_now.status = mute settings() - - if type(callback) == "function" then callback() end end end) end @@ -152,12 +109,10 @@ local function worker(args) if alsabar.followtag then preset.screen = awful.screen.focused() end - if alsabar._notify == "on" then - alsabar.id = naughty.notify ({ - replaces_id = alsabar.id, - preset = preset - }).id - end + alsabar.id = naughty.notify ({ + replaces_id = alsabar.id, + preset = preset + }).id end) end diff --git a/wiki b/wiki index a361f62..2e19b23 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit a361f62a126fb7de921bc3c49db8a35bebad355a +Subproject commit 2e19b23ba12894682699acdb70eeb130e51a9f3b From 5383f3db0dbb7e06f09a61e1db803a656abe252e Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 23 Jan 2017 15:46:33 +0100 Subject: [PATCH 056/106] quake: add settings function; closes #273 --- util/quake.lua | 4 ++++ wiki | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/util/quake.lua b/util/quake.lua index 0ec1081..4c42803 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -72,6 +72,9 @@ function quake:display() client.above = true client.skip_taskbar = true + -- Additional user settings + if self.settings then self.settings(client) end + -- Toggle display if self.visible then client.hidden = false @@ -127,6 +130,7 @@ function quake:new(config) conf.followtag = conf.followtag or false -- spawn on currently focused screen conf.overlap = conf.overlap or false -- overlap wibox conf.screen = conf.screen or awful.screen.focused() + conf.settings = conf.settings -- If width or height <= 1 this is a proportion of the workspace conf.height = conf.height or 0.25 -- height diff --git a/wiki b/wiki index 2e19b23..85fa41e 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 2e19b23ba12894682699acdb70eeb130e51a9f3b +Subproject commit 85fa41e74a7ed2923f6e289273e436ff187c6fdc From ff61857e157b8f32e861016a6f151a7d1ddcd2da Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 23 Jan 2017 15:52:26 +0100 Subject: [PATCH 057/106] alsabar: forgot callback --- widgets/alsabar.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index 6a03a10..bc8d8d3 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -15,6 +15,7 @@ local math = { modf = math.modf } local string = { format = string.format, match = string.match, rep = string.rep } +local type = type local tonumber = tonumber local setmetatable = setmetatable @@ -68,7 +69,7 @@ local function worker(args) alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } }) - function alsabar.update() + function alsabar.update(callback) helpers.async(alsabar.cmd, function(mixer) local volu,mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)") if (volu and tonumber(volu) ~= alsabar._current_level) or (mute and string.match(mute, "on") ~= alsabar._muted) then @@ -89,6 +90,8 @@ local function worker(args) volume_now.status = mute settings() + + if type(callback) == "function" then callback() end end end) end From 156515eb28c002300aaf06651f7c412ca2bc07f1 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 23 Jan 2017 17:58:35 +0100 Subject: [PATCH 058/106] alsa{bar}: add togglechannel back --- widgets/alsa.lua | 15 ++++++++++++--- widgets/alsabar.lua | 6 ++++++ wiki | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/widgets/alsa.lua b/widgets/alsa.lua index 7c853c9..c86db33 100644 --- a/widgets/alsa.lua +++ b/widgets/alsa.lua @@ -8,6 +8,7 @@ --]] local helpers = require("lain.helpers") +local shell = require("awful.util").shell local wibox = require("wibox") local string = { match = string.match, format = string.format } @@ -22,9 +23,16 @@ local function worker(args) local timeout = args.timeout or 5 local settings = args.settings or function() end - alsa.cmd = args.cmd or "amixer" - alsa.channel = args.channel or "Master" - alsa.last = {} + alsa.cmd = args.cmd or "amixer" + alsa.channel = args.channel or "Master" + alsa.togglechannel = args.togglechannel + + if alsa.togglechannel then + alsa.cmd = { shell, "-c", string.format("%s get %s; %s get %s", + alsa.cmd, alsa.channel, alsa.cmd, alsa.togglechannel) } + end + + alsa.last = {} function alsa.update() helpers.async(alsa.cmd, function(mixer) @@ -39,6 +47,7 @@ local function worker(args) end timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel) + helpers.newtimer(timer_id, timeout, alsa.update) return alsa diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index bc8d8d3..fde5eec 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -44,6 +44,7 @@ local function worker(args) alsabar.cmd = args.cmd or "amixer" alsabar.channel = args.channel or "Master" + alsabar.togglechannel = args.togglechannel alsabar.colors = args.colors or alsabar.colors alsabar.followtag = args.followtag or false alsabar._notify = args.notify or "on" @@ -54,6 +55,11 @@ local function worker(args) alsabar.notification_preset.font = "Monospace 11" end + if alsabar.togglechannel then + alsabar.cmd = { awful.util.shell, "-c", string.format("%s get %s; %s get %s", + alsabar.cmd, alsabar.channel, alsabar.cmd, alsabar.togglechannel) } + end + alsabar.bar = wibox.widget { forced_height = height, forced_width = width, diff --git a/wiki b/wiki index 85fa41e..66836bb 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 85fa41e74a7ed2923f6e289273e436ff187c6fdc +Subproject commit 66836bbf1ffc0dd3bd3aef4799fff78ded9df4ec From 099e23aac2372f11a6f2b9a8c0d62bdfd8ee85b6 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 23 Jan 2017 20:58:19 +0100 Subject: [PATCH 059/106] taskwarrior: asynchronous; #213 enhanced --- ISSUE_TEMPLATE.md | 2 +- icons/redshift/redshift_off.png | Bin 267 -> 0 bytes icons/redshift/redshift_on.png | Bin 253 -> 0 bytes .../{taskwarrior/task.png => taskwarrior.png} | Bin icons/taskwarrior/tasksmall.png | Bin 941 -> 0 bytes widgets/calendar.lua | 25 +-- widgets/contrib/redshift.lua | 4 +- widgets/contrib/task.lua | 171 ++++++------------ widgets/fs.lua | 11 +- wiki | 2 +- 10 files changed, 74 insertions(+), 141 deletions(-) delete mode 100644 icons/redshift/redshift_off.png delete mode 100644 icons/redshift/redshift_on.png rename icons/{taskwarrior/task.png => taskwarrior.png} (100%) delete mode 100755 icons/taskwarrior/tasksmall.png diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index e98373d..e024e8b 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,4 +1,4 @@ -**Please read the wiki and browse the Issues section first.** +**Please read the [wiki](https://github.com/copycat-killer/lain/wiki) and search the [Issues section](https://github.com/copycat-killer/lain/issues) first.** If you can't find a solution there, then go ahead and provide: diff --git a/icons/redshift/redshift_off.png b/icons/redshift/redshift_off.png deleted file mode 100644 index a92200fcde26a71dafbbc196264e9f3f7b720e93..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 267 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+1|-AI^@Rf|wj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&kwQRhpNT%Pxsc5-22_84^+AoS&PUnpXnkGB7w7r6!i7 zrYMwWmSiZnd-?{X=%um)#q&K~978NlCnrd3YY>cGkaV(skxAK+1zD*Fm+#o(BzpA9 zyT02!JFXZBW^?En?$K+?bSQVsY<>0r64%xLH)7f@yWSAFd^FqV$gZ{tGM*dT_%}?* zGQP+uB)Mm5pkv|050kBXRHR$9TNf{Xaq#t`gX|1Z0mk~9wjY%NxyjSj&t;ucLK6TD C<>&kwQRhpMg;@LNqNkAdl%#er@=ltB<)VvZPmw~~#C^fMp zHASI3vm`^o-P1Q9MK6^dD4yu);uvCaIypgNTZ3Tif~1r6i%iOnEXYbdxO~SJC()x< z-u2z?*>S~4Fq=cqa1YzV%MIRrol%Xx(aj%Nwe&1k?d)g`nce9(;lzWrJzQQqoc22p ndu(#t5oA%-CAUXUs)m8#$W~?T*MDd7fn4F~>gTe~DWM4fyunhR diff --git a/icons/taskwarrior/task.png b/icons/taskwarrior.png similarity index 100% rename from icons/taskwarrior/task.png rename to icons/taskwarrior.png diff --git a/icons/taskwarrior/tasksmall.png b/icons/taskwarrior/tasksmall.png deleted file mode 100755 index 2de6946550635bd442ee57f9b4db65e17168f8d0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 941 zcmV;e15*5nP)5>B4O(ZlrW$ z&7$Dazd+Z;l~#rLV^K;#3pUO>m!Mz_lDw~rnTez3$Gn+4Ne*0?_wIY=e($^Yob#Qb zBs46>$oY9;V8FkGj=k;nkdO8Q6Q?GW6*YX;CP zUIg?LiH`v;+?N0n00arI0RG~=`+3y>=6T$iWw--iONrNBNyQQG!@aTqvy!as%`*Hg zVROlK`ho0jp4-u`F&N{2JwRm!ULou*+~gkym!CXYw{q8 zAprXUi~!gTU@L%WKo0;u0B~2rqY&I=y;Pnhd8OvB<*!pqBhPc0<>ReBzt}L#$IVP- z-YF3ztV$e<(Jr)e?qam_62~M=x233CIj^-+$4h2*f_!ttx$VWuz@~bo%AWual7NKy zZlxJD<;BBN-^&>D;T7cBs8o4P>dU4&{!v!|k_ydNB>JUnB1SvE1h~s2Zq-!GJ2GQa zay2tG^=xCM(l@iz{M;M{wrz8HQ+GHD;MS5_rYJrSAv{gSV5QP~Xoc^1e|CPkN6Bm` zaV6n_baIOTG@4i}=)071i^MmHgM?ovZpRNL188QW=z^KWZ<7EdaYjN?JyYxO^g|MW z5>Iu5L5Zgm0mS#Ue3^#Dx*yj4b`CHEcT>`_MtsRmn4(Hs< zRq5)ycV~;D*aP74;" - .. awful.util.escape(f:read("*all"):gsub("\n*$", "")) - .. "" - f:close() - - task_notification = naughty.notify({ title = "[task next]", - text = c_text, - icon = task.notify_icon, - position = task.position, - fg = task.fg, - bg = task.bg, - timeout = task.timeout, - screen = scrp - }) + helpers.async(string.format("%s -c '%s'", awful.util.shell, task.cmd), + function(f) + task.notification = naughty.notify({ + preset = task_notification_preset, + title = task.cmd, + text = markup.font(task.notification_preset.font, + awful.util.escape(f:gsub("\n*$", ""))) + }) + end) end -function task.prompt_add() - awful.prompt.run({ prompt = "Add task: " }, - mypromptbox[awful.screen.focused()].widget, - function (...) - local f = io.popen("task add " .. ...) - c_text = "\n" - .. awful.util.escape(f:read("*all")) - .. "" - f:close() - - naughty.notify({ - text = c_text, - icon = task.notify_icon, - position = task.position, - fg = task.fg, - bg = task.bg, - timeout = task.timeout, - }) - end, - nil, - awful.util.getdir("cache") .. "/history_task_add") -end - -function task.prompt_search() - awful.prompt.run({ prompt = "Search task: " }, - mypromptbox[awful.screen.focused()].widget, - function (...) - local f = io.popen("task " .. ...) - c_text = f:read("*all"):gsub(" \n*$", "") - f:close() - - if string.len(c_text) == 0 - then - c_text = "No results found." - else - c_text = "" - .. awful.util.escape(c_text) - .. "" - end - - naughty.notify({ - title = "[task next " .. ... .. "]", - text = c_text, - icon = task.notify_icon, - position = task.position, - fg = task.fg, - bg = task.bg, - timeout = task.timeout, - screen = awful.screen.focused() - }) - end, - nil, - awful.util.getdir("cache") .. "/history_task") +function task.prompt() + awful.prompt.run { + prompt = task.prompt_text, + textbox = awful.screen.focused().mypromptbox.widget, + exe_callback = function(t) + helpers.async(string.format("%s -c '%s'", awful.util.shell, t), + function(f) + naughty.notify { + preset = task_notification_preset, + title = t, + text = markup.font(task.notification_preset.font, + awful.util.escape(f:gsub("\n*$", ""))) + } + end) + end, + history_path = awful.util.getdir("cache") .. "/history_task" + } end function task.attach(widget, args) - local args = args or {} + local args = args or {} + task.show_cmd = args.cmd or "task" + task.prompt_text = args.prompt_text or "Enter task command: " + task.followtag = args.followtag or false + task.notification_preset = args.notification_preset - task.font_size = tonumber(args.font_size) or 12 - task.font = args.font or beautiful.font:sub(beautiful.font:find(""), - findLast(beautiful.font, " ")) - task.fg = args.fg or beautiful.fg_normal or "#FFFFFF" - task.bg = args.bg or beautiful.bg_normal or "#FFFFFF" - task.position = args.position or "top_right" - task.timeout = args.timeout or 7 - task.scr_pos = args.scr_pos or 1 - task.followtag = args.followtag or false - task.cmdline = args.cmdline or "next" + if not task.notification_preset then + task.notification_preset = naughty.config.defaults + task.notification_preset.font = "Monospace 10" + task.notification_preset.icon = helpers.icons_dir .. "/taskwarrior.png" + end - task.notify_icon = icons_dir .. "/taskwarrior/task.png" - task.notify_icon_small = icons_dir .. "/taskwarrior/tasksmall.png" - - widget:connect_signal("mouse::enter", function () task.show(task.scr_pos) end) - widget:connect_signal("mouse::leave", function () task.hide() end) + if widget then + widget:connect_signal("mouse::enter", function () task.show() end) + widget:connect_signal("mouse::leave", function () task.hide() end) + end end -return setmetatable(task, { __call = function(_, ...) return create(...) end }) +return task diff --git a/widgets/fs.lua b/widgets/fs.lua index 391c260..3a97d4c 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -37,7 +37,7 @@ function fs.show(seconds, scr) if fs.followtag then fs.notification_preset.screen = focused() elseif scr then - fs.notification_preset.screen = scr + fs.notification_preset.screen = scr or 1 end local cmd = (fs.options and string.format("dfs %s", fs.options)) or "dfs" @@ -74,7 +74,6 @@ local function worker(args) helpers.set_map(partition, false) - function update() fs_info, fs_now = {}, {} helpers.async(string.format("%s -c 'LC_ALL=C df -k --output=target,size,used,avail,pcent'", shell), function(f) @@ -107,11 +106,9 @@ local function worker(args) if notify == "on" and tonumber(fs_now.used) >= 99 and not helpers.get_map(partition) then naughty.notify({ - title = "Warning", - text = partition .. " is empty!", - timeout = 8, - fg = "#000000", - bg = "#FFFFFF" + preset = naughty.config.presets.critical, + title = "Warning", + text = partition .. " is empty", }) helpers.set_map(partition, true) else diff --git a/wiki b/wiki index 66836bb..2f7c2a9 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 66836bbf1ffc0dd3bd3aef4799fff78ded9df4ec +Subproject commit 2f7c2a96a29a94829acf0b9e7fb614a7432a5092 From c0deea25035a845907210f2a913099343a16162e Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 23 Jan 2017 22:27:37 +0100 Subject: [PATCH 060/106] imap: fixed async call --- README.rst | 2 +- widgets/alsabar.lua | 1 - widgets/contrib/tpbat/init.lua | 1 - widgets/imap.lua | 11 +- widgets/pulseaudio.lua | 40 ++++---- widgets/pulsebar.lua | 179 ++++++++++++++------------------- wiki | 2 +- 7 files changed, 101 insertions(+), 135 deletions(-) diff --git a/README.rst b/README.rst index 2bb89a8..ec0abfd 100644 --- a/README.rst +++ b/README.rst @@ -18,7 +18,7 @@ If you still have to use branch 3.5.x, you can refer to the commit 301faf5_, but Description ----------- -Successor of awesome-vain_, this module provides new layouts, a set of widgets and utility functions, with the aim of improving Awesome_ usability and configurability. +Successor of awesome-vain_, this module provides new layouts, **asynchronous** widgets and utility functions, with the aim of improving Awesome_ usability and configurability. Read the wiki_ for all the info. diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index fde5eec..219ad96 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -47,7 +47,6 @@ local function worker(args) alsabar.togglechannel = args.togglechannel alsabar.colors = args.colors or alsabar.colors alsabar.followtag = args.followtag or false - alsabar._notify = args.notify or "on" alsabar.notification_preset = args.notification_preset if not alsabar.notification_preset then diff --git a/widgets/contrib/tpbat/init.lua b/widgets/contrib/tpbat/init.lua index 8b53a4b..380625f 100644 --- a/widgets/contrib/tpbat/init.lua +++ b/widgets/contrib/tpbat/init.lua @@ -17,7 +17,6 @@ local debug = { getinfo = debug.getinfo } local newtimer = require("lain.helpers").newtimer local first_line = require("lain.helpers").first_line -local beautiful = require("beautiful") local naughty = require("naughty") local wibox = require("wibox") diff --git a/widgets/imap.lua b/widgets/imap.lua index 0f8d994..e00be5b 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -7,7 +7,6 @@ --]] local helpers = require("lain.helpers") -local shell = require("awful.util").shell local naughty = require("naughty") local wibox = require("wibox") local string = { format = string.format, @@ -33,12 +32,12 @@ local function worker(args ) local head_command = "curl --connect-timeout 3 -fsm 3" local request = "-X 'SEARCH (UNSEEN)'" + if not server or not mail or not password then return end + helpers.set_map(mail, 0) if not is_plain then - helpers.async(string.format("%s -s '%s'", shell, password), function(f) - password = f:gsub("\n", "") - end) + helpers.async(password, function(f) password = f:gsub("\n", "") end) end function update() @@ -51,8 +50,8 @@ local function worker(args ) mail_notification_preset.screen = awful.screen.focused() end - curl = string.format("%s -c '%s --url imaps://%s:%s/INBOX -u %s:%q %s -k'", - shell, head_command, server, port, mail, password, request) + curl = string.format("%s --url imaps://%s:%s/INBOX -u %s:%q %s -k", + head_command, server, port, mail, password, request) helpers.async(curl, function(f) _, mailcount = string.gsub(f, "%d+", "") diff --git a/widgets/pulseaudio.lua b/widgets/pulseaudio.lua index 45981f3..f2d63d6 100644 --- a/widgets/pulseaudio.lua +++ b/widgets/pulseaudio.lua @@ -6,8 +6,8 @@ --]] -local read_pipe = require("lain.helpers").read_pipe -local newtimer = require("lain.helpers").newtimer +local helpers = require("lain.helpers") +local shell = require("awful.util").shell local wibox = require("wibox") local string = { gmatch = string.gmatch, match = string.match, @@ -24,33 +24,35 @@ local function worker(args) local settings = args.settings or function() end local scallback = args.scallback - pulseaudio.cmd = args.cmd or string.format("pacmd list-sinks | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'") + pulseaudio.cmd = args.cmd or "pacmd list-sinks | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'" pulseaudio.widget = wibox.widget.textbox() function pulseaudio.update() if scallback then pulseaudio.cmd = scallback() end - local s = read_pipe(pulseaudio.cmd) - volume_now = {} - volume_now.index = string.match(s, "index: (%S+)") or "N/A" - volume_now.sink = string.match(s, "device.string = \"(%S+)\"") or "N/A" - volume_now.muted = string.match(s, "muted: (%S+)") or "N/A" + helpers.async({ shell, "-c", pulseaudio.cmd }, function(s) + volume_now = { + index = string.match(s, "index: (%S+)") or "N/A", + sink = string.match(s, "device.string = \"(%S+)\"") or "N/A", + muted = string.match(s, "muted: (%S+)") or "N/A" + } - local ch = 1 - volume_now.channel = {} - for v in string.gmatch(s, ":.-(%d+)%%") do - volume_now.channel[ch] = v - ch = ch + 1 - end + local ch = 1 + volume_now.channel = {} + for v in string.gmatch(s, ":.-(%d+)%%") do + volume_now.channel[ch] = v + ch = ch + 1 + end - volume_now.left = volume_now.channel[1] or "N/A" - volume_now.right = volume_now.channel[2] or "N/A" + volume_now.left = volume_now.channel[1] or "N/A" + volume_now.right = volume_now.channel[2] or "N/A" - widget = pulseaudio.widget - settings() + widget = pulseaudio.widget + settings() + end) end - newtimer(string.format("pulseaudio-%s", timeout), timeout, pulseaudio.update) + helpers.newtimer(string.format("pulseaudio-%s", timeout), timeout, pulseaudio.update) return setmetatable(pulseaudio, { __index = pulseaudio.widget }) end diff --git a/widgets/pulsebar.lua b/widgets/pulsebar.lua index b7fb1e9..9380a34 100644 --- a/widgets/pulsebar.lua +++ b/widgets/pulsebar.lua @@ -7,83 +7,31 @@ --]] -local newtimer = require("lain.helpers").newtimer -local read_pipe = require("lain.helpers").read_pipe +local helpers = require("lain.helpers") local awful = require("awful") -local beautiful = require("beautiful") local naughty = require("naughty") local wibox = require("wibox") local math = { modf = math.modf } -local mouse = mouse local string = { format = string.format, match = string.match, rep = string.rep } +local type = type local tonumber = tonumber local setmetatable = setmetatable -- Pulseaudio volume bar -- lain.widgets.pulsebar local pulsebar = { - sink = 0, - step = "1%", - colors = { - background = beautiful.bg_normal, + background = "#000000", mute = "#EB8F8F", unmute = "#A4CE8A" }, - mixer = "pavucontrol", - - notifications = { - font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")), - font_size = "11", - color = beautiful.fg_normal - }, - _current_level = 0, _muted = false } -function pulsebar.notify() - pulsebar.update() - - local preset = { - title = "", - text = "", - timeout = 5, - font = string.format("%s %s", pulsebar.notifications.font, - pulsebar.notifications.font_size), - fg = pulsebar.notifications.color - } - - if pulsebar._muted - then - preset.title = string.format("Sink %s - Muted", pulsebar.sink) - else - preset.title = string.format("%s - %s%%", pulsebar.sink, pulsebar._current_level) - end - - int = math.modf((pulsebar._current_level / 100) * awful.screen.focused().mywibox.height) - preset.text = string.format("[%s%s]", string.rep("|", int), - string.rep(" ", awful.screen.focused().mywibox.height - int)) - - if pulsebar.followtag then - preset.screen = awful.screen.focused() - end - - if pulsebar._notify ~= nil then - pulsebar._notify = naughty.notify ({ - replaces_id = pulsebar._notify.id, - preset = preset, - }) - else - pulsebar._notify = naughty.notify ({ - preset = preset, - }) - end -end - local function worker(args) local args = args or {} local timeout = args.timeout or 5 @@ -95,12 +43,16 @@ local function worker(args) local vertical = args.vertical or false local scallback = args.scallback - pulsebar.cmd = args.cmd or string.format("pacmd list-sinks | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p'") - pulsebar.colors = args.colors or pulsebar.colors - pulsebar.notifications = args.notifications or pulsebar.notifications + pulsebar.cmd = args.cmd or "pacmd list-sinks | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'" pulsebar.sink = args.sink or 0 - pulsebar.step = args.step or pulsebar.step - pulsebar.followtag = args.followtag or false + pulsebar.colors = args.colors or pulsebar.colors + pulsebar.followtag = args.followtag or false + pulsebar.notifications = args.notification_preset + + if not pulsebar.notification_preset then + pulsebar.notification_preset = naughty.config.defaults + pulsebar.notification_preset.font = "Monospace 11" + end pulsebar.bar = wibox.widget { forced_height = height, @@ -117,61 +69,76 @@ local function worker(args) pulsebar.tooltip = awful.tooltip({ objects = { pulsebar.bar } }) - function pulsebar.update() + function pulsebar.update(callback) if scallback then pulseaudio.cmd = scallback() end - local s = read_pipe(pulsebar.cmd) - volume_now = {} - volume_now.left = tonumber(string.match(s, ":.-(%d+)%%")) - volume_now.right = tonumber(string.match(s, ":.-(%d+)%%")) - volume_now.muted = string.match(s, "muted: (%S+)") + helpers.async({ awful.util.shell, "-c", pulsebar.cmd }, function(s) + volume_now = { + index = string.match(s, "index: (%S+)") or "N/A", + sink = string.match(s, "device.string = \"(%S+)\"") or "N/A", + muted = string.match(s, "muted: (%S+)") or "N/A" + } - local volu = volume_now.left - local mute = volume_now.muted - - if (volu and volu ~= pulsebar._current_level) or (mute and mute ~= pulsebar._muted) - then - pulsebar._current_level = volu - pulsebar.bar:set_value(pulsebar._current_level / 100) - if (not mute and volu == 0) or mute == "yes" - then - pulsebar._muted = true - pulsebar.tooltip:set_text ("[Muted]") - pulsebar.bar.color = pulsebar.colors.mute - else - pulsebar._muted = false - pulsebar.tooltip:set_text(string.format("%s: %s", pulsebar.sink, volu)) - pulsebar.bar.color = pulsebar.colors.unmute + local ch = 1 + volume_now.channel = {} + for v in string.gmatch(s, ":.-(%d+)%%") do + volume_now.channel[ch] = v + ch = ch + 1 end - settings() - end + + volume_now.left = volume_now.channel[1] or "N/A" + volume_now.right = volume_now.channel[2] or "N/A" + + local volu = volume_now.left + local mute = volume_now.muted + + if (volu and volu ~= pulsebar._current_level) or (mute and mute ~= pulsebar._muted) then + pulsebar._current_level = volu + pulsebar.bar:set_value(pulsebar._current_level / 100) + if (not mute and volu == 0) or mute == "yes" then + pulsebar._muted = true + pulsebar.tooltip:set_text ("[Muted]") + pulsebar.bar.color = pulsebar.colors.mute + else + pulsebar._muted = false + pulsebar.tooltip:set_text(string.format("%s: %s", pulsebar.sink, volu)) + pulsebar.bar.color = pulsebar.colors.unmute + end + + settings() + + if type(callback) == "function" then callback() end + end + end) + end + + function pulsebar.notify() + pulsebar.update(function() + local preset = pulsebar.notification_preset + + if pulsebar._muted then + preset.title = string.format("Sink %s - Muted", pulsebar.sink) + else + preset.title = string.format("%s - %s%%", pulsebar.sink, pulsebar._current_level) + end + + int = math.modf((pulsebar._current_level / 100) * awful.screen.focused().mywibox.height) + preset.text = string.format("[%s%s]", string.rep("|", int), + string.rep(" ", awful.screen.focused().mywibox.height - int)) + + if pulsebar.followtag then preset.screen = awful.screen.focused() end + + pulsebar.id = naughty.notify ({ + replaces_id = pulsebar.id, + preset = preset + }).id + end) end - pulsebar.bar:buttons(awful.util.table.join ( - awful.button({}, 1, function() - awful.util.spawn(pulsebar.mixer) - end), - awful.button({}, 2, function() - awful.util.spawn(string.format("pactl set-sink-volume %d 100%%", pulsebar.sink)) - pulsebar.update() - end), - awful.button({}, 3, function() - awful.util.spawn(string.format("pactl set-sink-mute %d toggle", pulsebar.sink)) - pulsebar.update() - end), - awful.button({}, 4, function() - awful.util.spawn(string.format("pactl set-sink-volume %d +%s", pulsebar.sink, pulsebar.step)) - pulsebar.update() - end), - awful.button({}, 5, function() - awful.util.spawn(string.format("pactl set-sink-volume %d -%s", pulsebar.sink, pulsebar.step)) - pulsebar.update() - end) - )) timer_id = string.format("pulsebar-%s", pulsebar.sink) - newtimer(timer_id, timeout, pulsebar.update) + helpers.newtimer(timer_id, timeout, pulsebar.update) return pulsebar end diff --git a/wiki b/wiki index 2f7c2a9..3d8de07 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 2f7c2a96a29a94829acf0b9e7fb614a7432a5092 +Subproject commit 3d8de07f057bcc4cb16bb1244e53276ea11ecff4 From d836fcd6255b34dc19713d9e7b0b737fee738b59 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 23 Jan 2017 23:03:13 +0100 Subject: [PATCH 061/106] lain is now as asynchronous as possible --- widgets/calendar.lua | 4 ++-- widgets/contrib/kbdlayout.lua | 3 +-- widgets/contrib/moc.lua | 4 ++-- widgets/contrib/redshift.lua | 2 +- widgets/contrib/task.lua | 12 +++++------- widgets/fs.lua | 2 +- widgets/mpd.lua | 8 ++++---- widgets/net.lua | 3 +-- wiki | 2 +- 9 files changed, 18 insertions(+), 22 deletions(-) diff --git a/widgets/calendar.lua b/widgets/calendar.lua index e4216e4..7988ba2 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -67,7 +67,7 @@ function calendar.show(t_out, inc_offset, scr) calendar.notification_preset.screen = src or 1 end - async(string.format("%s -c '%s'", awful.util.shell, f), function(ws) + async(f, function(ws) fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg ws = ws:gsub("%c%[7m%d+%c%[27m", markup.bold(markup.color(bg, fg, today))) calendar.notification = naughty.notify({ @@ -94,7 +94,7 @@ function calendar.attach(widget, args) end if widget then - widget:connect_signal("mouse::enter", function () calendar.show() end) + widget:connect_signal("mouse::enter", function () calendar.show(0) end) widget:connect_signal("mouse::leave", function () calendar.hide() end) widget:buttons(awful.util.table.join(awful.button({ }, 1, function () calendar.show(0, -1, calendar.scr_pos) end), diff --git a/widgets/contrib/kbdlayout.lua b/widgets/contrib/kbdlayout.lua index 3b514c5..da3084c 100644 --- a/widgets/contrib/kbdlayout.lua +++ b/widgets/contrib/kbdlayout.lua @@ -38,8 +38,7 @@ local function worker(args) end function kbdlayout.update() - helpers.async(string.format("%s -c 'setxkbmap -query'", awful.util.shell), - function(status) + helpers.async("setxkbmap -query", function(status) kbd_run_settings(string.match(status, "layout:%s*([^\n]*)"), string.match(status, "variant:%s*([^\n]*)")) end) diff --git a/widgets/contrib/moc.lua b/widgets/contrib/moc.lua index 44f46a6..d2f544f 100644 --- a/widgets/contrib/moc.lua +++ b/widgets/contrib/moc.lua @@ -79,8 +79,8 @@ local function worker(args) } local path = string.format("%s/%s", music_dir, string.match(moc_now.file, ".*/")) - local cover = string.format("%s -c \"find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'\"", shell, path, cover_pattern) - helpers.async(cover, function(current_icon) + local cover = string.format("find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'", path, cover_pattern) + helpers.async({ shell, "-c", cover }, function(current_icon) common.icon = current_icon:gsub("\n", "") moc.id = naughty.notify(common).id end) diff --git a/widgets/contrib/redshift.lua b/widgets/contrib/redshift.lua index fdda61f..73cc100 100644 --- a/widgets/contrib/redshift.lua +++ b/widgets/contrib/redshift.lua @@ -26,7 +26,7 @@ function redshift:start() end function redshift:toggle() - async(string.format("%s -c 'ps -p %d -o pid='", awful.util.shell, redshift.pid), function(f) + async({ awful.util.shell, "-c", string.format("ps -p %d -o pid=", redshift.pid) }, function(f) if f and #f > 0 then -- redshift is running -- Sending -USR1 toggles redshift (See project website) execute("pkill -USR1 redshift") diff --git a/widgets/contrib/task.lua b/widgets/contrib/task.lua index 2f57317..4325437 100644 --- a/widgets/contrib/task.lua +++ b/widgets/contrib/task.lua @@ -30,11 +30,10 @@ function task.show(scr) task.notification_preset.screen = scr end - helpers.async(string.format("%s -c '%s'", awful.util.shell, task.cmd), - function(f) + helpers.async(task.show_cmd, function(f) task.notification = naughty.notify({ preset = task_notification_preset, - title = task.cmd, + title = task.show_cmd, text = markup.font(task.notification_preset.font, awful.util.escape(f:gsub("\n*$", ""))) }) @@ -46,10 +45,9 @@ function task.prompt() prompt = task.prompt_text, textbox = awful.screen.focused().mypromptbox.widget, exe_callback = function(t) - helpers.async(string.format("%s -c '%s'", awful.util.shell, t), - function(f) + helpers.async(t, function(f) naughty.notify { - preset = task_notification_preset, + preset = task.notification_preset, title = t, text = markup.font(task.notification_preset.font, awful.util.escape(f:gsub("\n*$", ""))) @@ -62,7 +60,7 @@ end function task.attach(widget, args) local args = args or {} - task.show_cmd = args.cmd or "task" + task.show_cmd = args.show_cmd or "task next" task.prompt_text = args.prompt_text or "Enter task command: " task.followtag = args.followtag or false task.notification_preset = args.notification_preset diff --git a/widgets/fs.lua b/widgets/fs.lua index 3a97d4c..eda3ffc 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -76,7 +76,7 @@ local function worker(args) function update() fs_info, fs_now = {}, {} - helpers.async(string.format("%s -c 'LC_ALL=C df -k --output=target,size,used,avail,pcent'", shell), function(f) + helpers.async({ shell, "-c", "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 diff --git a/widgets/mpd.lua b/widgets/mpd.lua index 6011e03..02b5680 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -39,14 +39,14 @@ local function worker(args) local mpdh = string.format("telnet://%s:%s", host, port) local echo = string.format("printf \"%sstatus\\ncurrentsong\\nclose\\n\"", password) - local cmd = string.format("%s -c '%s | curl --connect-timeout 1 -fsm 3 %s'", shell, echo, mpdh) + local cmd = string.format("%s | curl --connect-timeout 1 -fsm 3 %s", echo, mpdh) mpd_notification_preset = { title = "Now playing", timeout = 6 } helpers.set_map("current mpd track", nil) function mpd.update() - helpers.async(cmd, function(f) + helpers.async({ shell, "-c", cmd }, function(f) mpd_now = { random_mode = false, single_mode = false, @@ -110,8 +110,8 @@ local function worker(args) if not string.match(mpd_now.file, "http.*://") then -- local file instead of http stream local path = string.format("%s/%s", music_dir, string.match(mpd_now.file, ".*/")) - local cover = string.format("%s -c \"find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'\"", shell, path, cover_pattern) - helpers.async(cover, function(current_icon) + local cover = string.format("find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'", path, cover_pattern) + helpers.async({ shell, "-c", cover }, function(current_icon) common.icon = current_icon:gsub("\n", "") mpd.id = naughty.notify(common).id end) diff --git a/widgets/net.lua b/widgets/net.lua index ff16075..983ec7a 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -10,7 +10,6 @@ local helpers = require("lain.helpers") local naughty = require("naughty") local wibox = require("wibox") -local shell = require("awful.util").shell local string = { format = string.format, match = string.match } local setmetatable = setmetatable @@ -35,7 +34,7 @@ local function worker(args) net.iface = (args.iface and type(args.iface) == "string" and {args.iface}) or {} function net.get_device() - helpers.async(string.format("%s -c 'ip link show'", shell, device_cmd), function(ws) + helpers.async(string.format("ip link show", device_cmd), function(ws) ws = ws:match("(%w+): ") net.iface = ws and { ws } or {} end) diff --git a/wiki b/wiki index 3d8de07..991e3bb 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 3d8de07f057bcc4cb16bb1244e53276ea11ecff4 +Subproject commit 991e3bb813a650a6d6bcd27a9563a746fe489716 From 272844030a05df1807406245b84930ea4740e61b Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Mon, 23 Jan 2017 23:11:52 +0100 Subject: [PATCH 062/106] centerworkh default icons added --- icons/layout/default/centerworkh.png | Bin 0 -> 248 bytes icons/layout/default/centerworkhw.png | Bin 0 -> 267 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 icons/layout/default/centerworkh.png create mode 100644 icons/layout/default/centerworkhw.png diff --git a/icons/layout/default/centerworkh.png b/icons/layout/default/centerworkh.png new file mode 100644 index 0000000000000000000000000000000000000000..4fb4fdd38e9e30d30537434d963a192b30ba154d GIT binary patch literal 248 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPtqqrEC(lxiBy+EN>PZ!6Kid%1Q8FC#^;Bg4l-TQy) z<9nV96`k(gx9aRy;F4Wj`T4VK>udL;yZpa%R+y_le*Y*zEBJb@JtI&%7?>ZNJUgl^ zk?G2F%b0!n?Fko)f6QXOW($+XLND+(|0kcoq~bXVh^E|Nl8EDsOE8S}1}XJ)^>bP0 Hl+XkKIzvbz literal 0 HcmV?d00001 diff --git a/icons/layout/default/centerworkhw.png b/icons/layout/default/centerworkhw.png new file mode 100644 index 0000000000000000000000000000000000000000..fd27766ca2b2b7ded2f59c82901f4ce9defecde5 GIT binary patch literal 267 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPtqqrCs-;;TEaX_INo-U3d6}R5r+Rb&?fT!(Z{L=UT zPrbUN=&j!^+k9?&s*uc-1m{T)uYO&)yZZHqRaNJGC*89(_msPA{@|x~hU Date: Tue, 24 Jan 2017 00:14:02 -0200 Subject: [PATCH 063/106] Fix regression in net.lua widget The iface argument parsing was logically incorrect and ignoring table argument such as {"eth0", "eth1"}. --- widgets/net.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/widgets/net.lua b/widgets/net.lua index 983ec7a..e8583e0 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -31,7 +31,8 @@ local function worker(args) 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 {} + 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) From 17fa506422e4eeee0de14a9989817af73bb0694f Mon Sep 17 00:00:00 2001 From: Alan D Moore Date: Mon, 23 Jan 2017 23:05:36 -0600 Subject: [PATCH 064/106] Fix regression in pulsebar.lua Added gmatch back to aliased string library --- widgets/pulsebar.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/widgets/pulsebar.lua b/widgets/pulsebar.lua index 9380a34..284b886 100644 --- a/widgets/pulsebar.lua +++ b/widgets/pulsebar.lua @@ -13,6 +13,7 @@ local naughty = require("naughty") local wibox = require("wibox") local math = { modf = math.modf } local string = { format = string.format, + gmatch = string.gmatch, match = string.match, rep = string.rep } local type = type From 958cf60e6fbb5958d4d4505b044370a6028d683a Mon Sep 17 00:00:00 2001 From: 2009 Date: Tue, 24 Jan 2017 19:55:27 +1000 Subject: [PATCH 065/106] Fix bug where net widget would not get the device name This happens because my output from ```ip link show``` doesn't have anything additional betweeen MULTICAST and UP. ``` 2: enp2s0: ``` --- widgets/net.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/net.lua b/widgets/net.lua index 983ec7a..2457748 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -35,7 +35,7 @@ local function worker(args) function net.get_device() helpers.async(string.format("ip link show", device_cmd), function(ws) - ws = ws:match("(%w+): ") + ws = ws:match("(%w+): ") net.iface = ws and { ws } or {} end) end From a00417d8011690d977cbdab1f1378ec369e5f355 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 24 Jan 2017 16:15:40 +0100 Subject: [PATCH 066/106] helpers.newtimer: added stoppable option --- helpers.lua | 10 ++++++---- widgets/abase.lua | 16 ++++++++-------- widgets/base.lua | 19 ++++++++++--------- widgets/contrib/gpmdp.lua | 19 ++++++++++--------- widgets/contrib/moc.lua | 2 +- widgets/contrib/tpbat/smapi.lua | 6 ++---- widgets/imap.lua | 2 +- widgets/maildir.lua | 4 ++-- widgets/mpd.lua | 2 +- widgets/net.lua | 3 ++- widgets/weather.lua | 4 ++-- wiki | 2 +- 12 files changed, 46 insertions(+), 43 deletions(-) diff --git a/helpers.lua b/helpers.lua index 9755dc0..7c44648 100644 --- a/helpers.lua +++ b/helpers.lua @@ -92,8 +92,9 @@ end helpers.timer_table = {} -function helpers.newtimer(_name, timeout, fun, nostart) - local name = timeout +function helpers.newtimer(name, timeout, fun, nostart, stoppable) + if not name or #name == 0 then return end + name = (stoppable and name) or timeout if not helpers.timer_table[name] then helpers.timer_table[name] = timer({ timeout = timeout }) helpers.timer_table[name]:start() @@ -102,6 +103,7 @@ function helpers.newtimer(_name, timeout, fun, nostart) if not nostart then helpers.timer_table[name]:emit_signal("timeout") end + return stoppable and helpers.timer_table[name] end -- }}} @@ -175,9 +177,9 @@ function helpers.spairs(t) end end --- create a lain textbox widget +-- create a textbox with no spacing issues function helpers.make_widget_textbox() - local w = wibox.widget.textbox('') + local w = wibox.widget.textbox() local t = wibox.widget.base.make_widget(w) t.widget = w return t diff --git a/widgets/abase.lua b/widgets/abase.lua index a176cf1..7eef754 100644 --- a/widgets/abase.lua +++ b/widgets/abase.lua @@ -14,13 +14,13 @@ local setmetatable = setmetatable -- lain.widgets.abase local function worker(args) - local abase = {} - local args = args or {} - local timeout = args.timeout or 5 - local cmd = args.cmd or "" - local settings = args.settings or function() end - - abase.widget = wibox.widget.textbox() + local abase = helpers.make_widget_textbox() + local args = args or {} + local timeout = args.timeout or 5 + local nostart = args.nostart or false + local stoppable = args.stoppable or false + local cmd = args.cmd or "" + local settings = args.settings or function() end function abase.update() helpers.async(cmd, function(f) @@ -33,7 +33,7 @@ local function worker(args) end) end - helpers.newtimer(cmd, timeout, abase.update) + abase.timer = helpers.newtimer(cmd, timeout, abase.update, nostart, stoppable) return setmetatable(abase, { __index = abase.widget }) end diff --git a/widgets/base.lua b/widgets/base.lua index 94ee58f..87b0c85 100644 --- a/widgets/base.lua +++ b/widgets/base.lua @@ -6,8 +6,7 @@ --]] -local newtimer = require("lain.helpers").newtimer -local read_pipe = require("lain.helpers").read_pipe +local helpers = require("lain.helpers") local wibox = require("wibox") local setmetatable = setmetatable @@ -15,16 +14,18 @@ local setmetatable = setmetatable -- lain.widgets.base local function worker(args) - local base = {} - local args = args or {} - local timeout = args.timeout or 5 - local cmd = args.cmd or "" - local settings = args.settings or function() end + local base = helpers.make_widget_textbox() + local args = args or {} + local timeout = args.timeout or 5 + local nostart = args.nostart or false + local stoppable = args.stoppable or false + local cmd = args.cmd or "" + local settings = args.settings or function() end base.widget = wibox.widget.textbox() function base.update() - output = read_pipe(cmd) + output = helpers.read_pipe(cmd) if output ~= base.prev then widget = base.widget settings() @@ -32,7 +33,7 @@ local function worker(args) end end - newtimer(cmd, timeout, base.update) + base.timer = helpers.newtimer(cmd, timeout, base.update, nostart, stoppable) return setmetatable(base, { __index = base.widget }) end diff --git a/widgets/contrib/gpmdp.lua b/widgets/contrib/gpmdp.lua index 811d1f6..21776ac 100644 --- a/widgets/contrib/gpmdp.lua +++ b/widgets/contrib/gpmdp.lua @@ -67,23 +67,24 @@ local function worker(args) if gpm_now.playing then if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current") then helpers.set_map("gpmdp_current", gpm_now.title) - os.execute(string.format("curl %d -o /tmp/gpmcover.png", gpm_now.cover_url)) if followtag then gpmdp_notification_preset.screen = focused() end - gpmdp.id = naughty.notify({ - preset = gpmdp_notification_preset, - icon = "/tmp/gpmcover.png", - replaces_id = gpmdp.id, - }).id + helpers.async(string.format("curl %d -o /tmp/gpmcover.png", gpm_now.cover_url), + function(f) + gpmdp.id = naughty.notify({ + preset = gpmdp_notification_preset, + icon = "/tmp/gpmcover.png", + replaces_id = gpmdp.id + }).id + end) end - elseif not gpm_now.running - then + elseif not gpm_now.running then helpers.set_map("gpmdp_current", nil) end end - helpers.newtimer("gpmdp", timeout, gpmdp.update) + gpmdp.timer = helpers.newtimer("gpmdp", timeout, gpmdp.update, true, true) return setmetatable(gpmdp, { __index = gpmdp.widget }) end diff --git a/widgets/contrib/moc.lua b/widgets/contrib/moc.lua index d2f544f..6190f5f 100644 --- a/widgets/contrib/moc.lua +++ b/widgets/contrib/moc.lua @@ -91,7 +91,7 @@ local function worker(args) end) end - helpers.newtimer("moc", timeout, moc.update) + moc.timer = helpers.newtimer("moc", timeout, moc.update, true, true) return setmetatable(moc, { __index = moc.widget }) end diff --git a/widgets/contrib/tpbat/smapi.lua b/widgets/contrib/tpbat/smapi.lua index 271d9c2..9002585 100644 --- a/widgets/contrib/tpbat/smapi.lua +++ b/widgets/contrib/tpbat/smapi.lua @@ -81,13 +81,11 @@ function smapi:battery(name) local time_val = bat_now.status == 'discharging' and 'remaining_running_time' or 'remaining_charging_time' local mins_left = self:get(time_val) - if mins_left:find("^%d+") == nil - then - return "N/A" - end + if not mins_left:find("^%d+") then return "N/A" end local hrs = math.floor(mins_left / 60) local min = mins_left % 60 + return string.format("%02d:%02d", hrs, min) end diff --git a/widgets/imap.lua b/widgets/imap.lua index e00be5b..5896ae1 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -74,7 +74,7 @@ local function worker(args ) end - helpers.newtimer(mail, timeout, update) + imap.timer = helpers.newtimer(mail, timeout, update, true, true) return setmetatable(imap, { __index = imap.widget }) end diff --git a/widgets/maildir.lua b/widgets/maildir.lua index bef09f4..1f4cd45 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -30,7 +30,7 @@ local function worker(args) maildir.widget = wibox.widget.textbox() - function update() + function maildir.update() if ext_mail_cmd then awful.spawn(ext_mail_cmd) end -- Find pathes to mailboxes. @@ -76,7 +76,7 @@ local function worker(args) settings() end - helpers.newtimer(mailpath, timeout, update, true) + maildir.timer = helpers.newtimer(mailpath, timeout, maildir.update, true, true) return setmetatable(maildir, { __index = maildir.widget }) end diff --git a/widgets/mpd.lua b/widgets/mpd.lua index 02b5680..ac4fd5f 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -126,7 +126,7 @@ local function worker(args) end) end - helpers.newtimer("mpd", timeout, mpd.update) + mpd.timer = helpers.newtimer("mpd", timeout, mpd.update, true, true) return mpd end diff --git a/widgets/net.lua b/widgets/net.lua index 983ec7a..a6cb3b6 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -12,6 +12,7 @@ local naughty = require("naughty") local wibox = require("wibox") local string = { format = string.format, match = string.match } +local tostring = tostring local setmetatable = setmetatable -- Network infos @@ -116,7 +117,7 @@ local function worker(args) settings() end - helpers.newtimer(net.iface, timeout, update) + helpers.newtimer("net-" .. tostring(net.iface), timeout, update) return net end diff --git a/widgets/weather.lua b/widgets/weather.lua index 32e3065..ff86d7e 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -160,8 +160,8 @@ local function worker(args) weather.attach(weather.widget) - newtimer("weather-" .. city_id, timeout, weather.update) - newtimer("weather_forecast-" .. city_id, timeout, weather.forecast_update) + weather.timer = newtimer("weather-" .. city_id, timeout, weather.update, false, true) + weather.timer_forecast = newtimer("weather_forecast-" .. city_id, timeout, weather.forecast_update, false, true) return setmetatable(weather, { __index = weather.widget }) end diff --git a/wiki b/wiki index 991e3bb..df5dd68 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 991e3bb813a650a6d6bcd27a9563a746fe489716 +Subproject commit df5dd684ec35c1fc8e044fb5fd0bdb76f7f568fa From ea4e4f41b35b37fc6b529c625d956c11d108a403 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 24 Jan 2017 16:38:28 +0100 Subject: [PATCH 067/106] mem: adjusted calculation; #271 --- widgets/mem.lua | 16 ++++++++-------- widgets/net.lua | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/widgets/mem.lua b/widgets/mem.lua index 763ac4b..443047c 100644 --- a/widgets/mem.lua +++ b/widgets/mem.lua @@ -11,7 +11,7 @@ local newtimer = require("lain.helpers").newtimer local wibox = require("wibox") local gmatch = string.gmatch local lines = io.lines -local math = { ceil = math.ceil, floor = math.floor } +local floor = math.floor local setmetatable = setmetatable -- Memory usage (ignoring caches) @@ -29,13 +29,13 @@ local function worker(args) mem_now = {} for line in lines("/proc/meminfo") do for k, v in gmatch(line, "([%a]+):[%s]+([%d]+).+") do - if k == "MemTotal" then mem_now.total = math.ceil(v / 1024) - elseif k == "MemFree" then mem_now.free = math.ceil(v / 1024) - elseif k == "Buffers" then mem_now.buf = math.ceil(v / 1024) - elseif k == "Cached" then mem_now.cache = math.ceil(v / 1024) - elseif k == "SwapTotal" then mem_now.swap = math.ceil(v / 1024) - elseif k == "SwapFree" then mem_now.swapf = math.ceil(v / 1024) - elseif k == "SReclaimable" then mem_now.srec = math.ceil(v / 1024) + if k == "MemTotal" then mem_now.total = floor(v / 1024 + 0.5) + elseif k == "MemFree" then mem_now.free = floor(v / 1024 + 0.5) + elseif k == "Buffers" then mem_now.buf = floor(v / 1024 + 0.5) + elseif k == "Cached" then mem_now.cache = floor(v / 1024 + 0.5) + elseif k == "SwapTotal" then mem_now.swap = floor(v / 1024 + 0.5) + elseif k == "SwapFree" then mem_now.swapf = floor(v / 1024 + 0.5) + elseif k == "SReclaimable" then mem_now.srec = floor(v / 1024 + 0.5) end end end diff --git a/widgets/net.lua b/widgets/net.lua index 922e5e1..81345fc 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -32,8 +32,8 @@ local function worker(args) 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 {} - + 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) From 312947f46eea9273279e1be9f1b80a1d66cc545a Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 24 Jan 2017 16:38:49 +0100 Subject: [PATCH 068/106] readme updated --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index ec0abfd..d9e78b2 100644 --- a/README.rst +++ b/README.rst @@ -18,7 +18,7 @@ If you still have to use branch 3.5.x, you can refer to the commit 301faf5_, but Description ----------- -Successor of awesome-vain_, this module provides new layouts, **asynchronous** widgets and utility functions, with the aim of improving Awesome_ usability and configurability. +Successor of awesome-vain_, this module provides new layouts, asynchronous widgets and utility functions, with the aim of improving Awesome_ usability and configurability. Read the wiki_ for all the info. From d9877c4bedca550478507f268f43e137e4454c24 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 24 Jan 2017 18:19:15 +0100 Subject: [PATCH 069/106] #250 missing file patch --- widgets/alsa.lua | 6 ++---- widgets/alsabar.lua | 4 +--- widgets/bat.lua | 40 ++++++++++++++++++++++------------------ widgets/cpu.lua | 2 +- widgets/mem.lua | 2 +- widgets/mpd.lua | 2 +- widgets/net.lua | 5 ++--- widgets/pulseaudio.lua | 2 +- widgets/pulsebar.lua | 5 +---- widgets/sysload.lua | 3 ++- widgets/temp.lua | 2 +- wiki | 2 +- 12 files changed, 36 insertions(+), 39 deletions(-) diff --git a/widgets/alsa.lua b/widgets/alsa.lua index c86db33..96f30b3 100644 --- a/widgets/alsa.lua +++ b/widgets/alsa.lua @@ -46,11 +46,9 @@ local function worker(args) end) end - timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel) + helpers.newtimer(string.format("alsa-%s-%s", alsa.cmd, alsa.channel), timeout, alsa.update) - helpers.newtimer(timer_id, timeout, alsa.update) - - return alsa + return setmetatable(alsa, { __index = alsa.widget }) end return setmetatable(alsa, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index 219ad96..a4c63ea 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -124,9 +124,7 @@ local function worker(args) end) end - timer_id = string.format("alsabar-%s-%s", alsabar.cmd, alsabar.channel) - - helpers.newtimer(timer_id, timeout, alsabar.update) + helpers.newtimer(string.format("alsabar-%s-%s", alsabar.cmd, alsabar.channel), timeout, alsabar.update) return alsabar end diff --git a/widgets/bat.lua b/widgets/bat.lua index ea749d3..8b62790 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -120,31 +120,35 @@ local function worker(args) bat_now.ac_status = tonumber(first_line(string.format("%s%s/online", pspath, ac))) or "N/A" if bat_now.status ~= "N/A" then + if bat_now.status ~= "Full" and sum_rate_power == 0 and bat_now.ac_status == 1 then + bat_now.perc = math.floor(math.min(100, (sum_energy_now / sum_energy_full) * 100)) + bat_now.time = "00:00" + bat_now.watt = 0 + -- update {perc,time,watt} iff battery not full and rate > 0 - if bat_now.status ~= "Full" and (sum_rate_power > 0 or sum_rate_current > 0) then + elseif bat_now.status ~= "Full" then local rate_time = 0 - local div = (sum_rate_power > 0 and sum_rate_power) or sum_rate_current + -- Calculate time and watt if rates are greater then 0 + if (sum_rate_power > 0 or sum_rate_current > 0) then + local div = (sum_rate_power > 0 and sum_rate_power) or sum_rate_current - if bat_now.status == "Charging" then - rate_time = (sum_energy_full - sum_energy_now) / div - else -- Discharging - rate_time = sum_energy_now / div - end + if bat_now.status == "Charging" then + rate_time = (sum_energy_full - sum_energy_now) / div + else -- Discharging + rate_time = sum_energy_now / div + end - if 0 < rate_time and rate_time < 0.01 then -- check for magnitude discrepancies (#199) - rate_time_magnitude = math.abs(math.floor(math.log10(rate_time))) - rate_time = rate_time * 10^(rate_time_magnitude - 2) - end + if 0 < rate_time and rate_time < 0.01 then -- check for magnitude discrepancies (#199) + rate_time_magnitude = math.abs(math.floor(math.log10(rate_time))) + rate_time = rate_time * 10^(rate_time_magnitude - 2) + end + end local hours = math.floor(rate_time) local minutes = math.floor((rate_time - hours) * 60) bat_now.perc = math.floor(math.min(100, (sum_energy_now / sum_energy_full) * 100)) bat_now.time = string.format("%02d:%02d", hours, minutes) bat_now.watt = tonumber(string.format("%.2f", sum_rate_energy / 1e6)) - elseif bat_now.status ~= "Full" and sum_rate_power == 0 and bat_now.ac_status == 1 then - bat_now.perc = math.floor(math.min(100, (sum_energy_now / sum_energy_full) * 100)) - bat_now.time = "00:00" - bat_now.watt = 0 elseif bat_now.status == "Full" then bat_now.perc = 100 bat_now.time = "00:00" @@ -171,9 +175,9 @@ local function worker(args) end end - newtimer(battery, timeout, bat.update) - - return bat + newtimer("batteries", timeout, bat.update) + + return setmetatable(bat, { __index = bat.widget }) end return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/cpu.lua b/widgets/cpu.lua index 8501388..f7fb087 100644 --- a/widgets/cpu.lua +++ b/widgets/cpu.lua @@ -77,7 +77,7 @@ local function worker(args) newtimer("cpu", timeout, update) - return cpu.widget + return setmetatable(cpu, { __index = cpu.widget }) end return setmetatable(cpu, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/mem.lua b/widgets/mem.lua index 443047c..e96dc1b 100644 --- a/widgets/mem.lua +++ b/widgets/mem.lua @@ -50,7 +50,7 @@ local function worker(args) newtimer("mem", timeout, update) - return mem.widget + return setmetatable(mem, { __index = mem.widget }) end return setmetatable(mem, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/mpd.lua b/widgets/mpd.lua index ac4fd5f..df26422 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -128,7 +128,7 @@ local function worker(args) mpd.timer = helpers.newtimer("mpd", timeout, mpd.update, true, true) - return mpd + return setmetatable(mpd, { __index = imap.widget }) end return setmetatable(mpd, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/net.lua b/widgets/net.lua index 81345fc..0b19f0b 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -12,7 +12,6 @@ local naughty = require("naughty") local wibox = require("wibox") local string = { format = string.format, match = string.match } -local tostring = tostring local setmetatable = setmetatable -- Network infos @@ -118,9 +117,9 @@ local function worker(args) settings() end - helpers.newtimer("net-" .. tostring(net.iface), timeout, update) + helpers.newtimer("network", timeout, update) - return net + return setmetatable(net, { __index = net.widget }) end return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/pulseaudio.lua b/widgets/pulseaudio.lua index f2d63d6..3178dcf 100644 --- a/widgets/pulseaudio.lua +++ b/widgets/pulseaudio.lua @@ -52,7 +52,7 @@ local function worker(args) end) end - helpers.newtimer(string.format("pulseaudio-%s", timeout), timeout, pulseaudio.update) + helpers.newtimer("pulseaudio", timeout, pulseaudio.update) return setmetatable(pulseaudio, { __index = pulseaudio.widget }) end diff --git a/widgets/pulsebar.lua b/widgets/pulsebar.lua index 284b886..8cf8566 100644 --- a/widgets/pulsebar.lua +++ b/widgets/pulsebar.lua @@ -136,10 +136,7 @@ local function worker(args) end) end - - timer_id = string.format("pulsebar-%s", pulsebar.sink) - - helpers.newtimer(timer_id, timeout, pulsebar.update) + helpers.newtimer(string.format("pulsebar-%s", pulsebar.sink), timeout, pulsebar.update) return pulsebar end diff --git a/widgets/sysload.lua b/widgets/sysload.lua index 215fd62..041feb1 100644 --- a/widgets/sysload.lua +++ b/widgets/sysload.lua @@ -36,7 +36,8 @@ local function worker(args) end newtimer("sysload", timeout, update) - return sysload.widget + + return setmetatable(sysload, { __index = sysload.widget }) end return setmetatable(sysload, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/temp.lua b/widgets/temp.lua index cdf3002..e769b25 100644 --- a/widgets/temp.lua +++ b/widgets/temp.lua @@ -39,7 +39,7 @@ local function worker(args) newtimer("coretemp", timeout, update) - return temp.widget + return setmetatable(temp, { __index = temp.widget }) end return setmetatable(temp, { __call = function(_, ...) return worker(...) end }) diff --git a/wiki b/wiki index df5dd68..7e48658 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit df5dd684ec35c1fc8e044fb5fd0bdb76f7f568fa +Subproject commit 7e4865822c669a86007d88bf6ae846a95c5eed5f From 1134630a54d403d1c50b6ed487e9bb5d67319954 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 24 Jan 2017 18:23:11 +0100 Subject: [PATCH 070/106] fixed typo --- widgets/mpd.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/mpd.lua b/widgets/mpd.lua index df26422..7996aeb 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -128,7 +128,7 @@ local function worker(args) mpd.timer = helpers.newtimer("mpd", timeout, mpd.update, true, true) - return setmetatable(mpd, { __index = imap.widget }) + return setmetatable(mpd, { __index = mpd.widget }) end return setmetatable(mpd, { __call = function(_, ...) return worker(...) end }) From 8ba5f4a7ef8c86c58a90433fa781dda2f444f47c Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 24 Jan 2017 18:42:44 +0100 Subject: [PATCH 071/106] fix #280 --- widgets/fs.lua | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/widgets/fs.lua b/widgets/fs.lua index eda3ffc..4e9f04b 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -20,7 +20,7 @@ local setmetatable = setmetatable -- File system disk space usage -- lain.widgets.fs -local fs = {} +local fs = helpers.make_widget_textbox() -- Unit definitions fs.unit = { ["mb"] = 1024, ["gb"] = 1024^2 } @@ -32,6 +32,8 @@ function fs.hide() end function fs.show(seconds, scr) + fs.update() + fs.hide() if fs.followtag then @@ -40,15 +42,10 @@ function fs.show(seconds, scr) fs.notification_preset.screen = scr or 1 end - local cmd = (fs.options and string.format("dfs %s", fs.options)) or "dfs" - - helpers.async(helpers.scripts_dir .. cmd, function(ws) - fs.notification = naughty.notify({ - preset = fs.notification_preset, - text = ws:gsub("\n*$", ""), - timeout = seconds or 5, - }) - end) + fs.notification = naughty.notify({ + preset = fs.notification_preset, + timeout = seconds or 5 + }) end local function worker(args) @@ -70,11 +67,9 @@ local function worker(args) fs.notification_preset.bg = "#000000" end - fs.widget = wibox.widget.textbox() - helpers.set_map(partition, false) - function update() + function fs.update() fs_info, fs_now = {}, {} helpers.async({ shell, "-c", "LC_ALL=C df -k --output=target,size,used,avail,pcent" }, function(f) for line in string.gmatch(f, "\n[^\n]+") do @@ -115,6 +110,11 @@ local function worker(args) helpers.set_map(partition, false) 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) end if showpopup == "on" then @@ -122,7 +122,7 @@ local function worker(args) fs.widget:connect_signal('mouse::leave', function () fs.hide() end) end - helpers.newtimer(partition, timeout, update) + helpers.newtimer(partition, timeout, fs.update) return setmetatable(fs, { __index = fs.widget }) end From dd9d9b8076428c4d869043e54b1cd67424020a11 Mon Sep 17 00:00:00 2001 From: BarbUk Date: Tue, 24 Jan 2017 22:45:51 +0400 Subject: [PATCH 072/106] fix 'attempt to index a nil value (global self)' --- widgets/contrib/tpbat/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/contrib/tpbat/init.lua b/widgets/contrib/tpbat/init.lua index 380625f..d96c2d8 100644 --- a/widgets/contrib/tpbat/init.lua +++ b/widgets/contrib/tpbat/init.lua @@ -42,7 +42,7 @@ end function tpbat.show(t_out) tpbat.hide() - local bat = self.bat + local bat = tpbat.bat if bat == nil or not bat:installed() then return end From 57da210b43ed4b0e555f3f7e7a9c4cd9e281eb43 Mon Sep 17 00:00:00 2001 From: aajjbb Date: Tue, 24 Jan 2017 17:44:27 -0200 Subject: [PATCH 073/106] Make amixer get information only from the selected channel --- widgets/alsa.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/alsa.lua b/widgets/alsa.lua index 96f30b3..cb7ba49 100644 --- a/widgets/alsa.lua +++ b/widgets/alsa.lua @@ -23,8 +23,8 @@ local function worker(args) local timeout = args.timeout or 5 local settings = args.settings or function() end - alsa.cmd = args.cmd or "amixer" alsa.channel = args.channel or "Master" + alsa.cmd = args.cmd or "amixer sget " .. alsa.channel alsa.togglechannel = args.togglechannel if alsa.togglechannel then From 03fdf984e93d81ed95945db51c83baf6c23e89e8 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 24 Jan 2017 21:33:16 +0100 Subject: [PATCH 074/106] fix and complete pull #286 --- widgets/alsa.lua | 8 +++++--- widgets/alsabar.lua | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/widgets/alsa.lua b/widgets/alsa.lua index cb7ba49..93c74cc 100644 --- a/widgets/alsa.lua +++ b/widgets/alsa.lua @@ -23,19 +23,21 @@ local function worker(args) local timeout = args.timeout or 5 local settings = args.settings or function() end + alsa.cmd = args.cmd or "amixer" alsa.channel = args.channel or "Master" - alsa.cmd = args.cmd or "amixer sget " .. alsa.channel alsa.togglechannel = args.togglechannel + local format_cmd = string.format("%s get %s", alsa.cmd, alsa.channel) + if alsa.togglechannel then - alsa.cmd = { shell, "-c", string.format("%s get %s; %s get %s", + format_cmd = { shell, "-c", string.format("%s get %s; %s get %s", alsa.cmd, alsa.channel, alsa.cmd, alsa.togglechannel) } end alsa.last = {} function alsa.update() - helpers.async(alsa.cmd, function(mixer) + helpers.async(format_cmd, function(mixer) local l,s = string.match(mixer, "([%d]+)%%.*%[([%l]*)") if alsa.last.level ~= l or alsa.last.status ~= s then volume_now = { level = l, status = s } diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index a4c63ea..c3e3d9d 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -54,8 +54,10 @@ local function worker(args) alsabar.notification_preset.font = "Monospace 11" end + local format_cmd = string.format("%s get %s", alsabar.cmd, alsabar.channel) + if alsabar.togglechannel then - alsabar.cmd = { awful.util.shell, "-c", string.format("%s get %s; %s get %s", + format_cmd = { awful.util.shell, "-c", string.format("%s get %s; %s get %s", alsabar.cmd, alsabar.channel, alsabar.cmd, alsabar.togglechannel) } end @@ -75,7 +77,7 @@ local function worker(args) alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } }) function alsabar.update(callback) - helpers.async(alsabar.cmd, function(mixer) + helpers.async(format_cmd, function(mixer) local volu,mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)") if (volu and tonumber(volu) ~= alsabar._current_level) or (mute and string.match(mute, "on") ~= alsabar._muted) then alsabar._current_level = tonumber(volu) or alsabar._current_level From 32eddd514f8ccc35eeaa128a441f6a47708e6a04 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 24 Jan 2017 22:03:48 +0100 Subject: [PATCH 075/106] cal: terminal-colors.d independent highlight matching pattern --- widgets/calendar.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/calendar.lua b/widgets/calendar.lua index 7988ba2..76284f5 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -69,7 +69,7 @@ function calendar.show(t_out, inc_offset, scr) async(f, function(ws) fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg - ws = ws:gsub("%c%[7m%d+%c%[27m", markup.bold(markup.color(bg, fg, today))) + ws = ws:gsub("%c%[%d+[m]?%d+%c%[%d+[m]?", markup.bold(markup.color(bg, fg, today))) calendar.notification = naughty.notify({ preset = calendar.notification_preset, text = ws:gsub("\n*$", ""), From 8c2e1df0c3f648ed70e52fab38a176e2f924407b Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 25 Jan 2017 14:40:57 +0100 Subject: [PATCH 076/106] mpd: missing icon fix --- widgets/mpd.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/widgets/mpd.lua b/widgets/mpd.lua index 7996aeb..aad4dc8 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -32,7 +32,7 @@ local function worker(args) local music_dir = args.music_dir or os.getenv("HOME") .. "/Music" local cover_pattern = args.cover_pattern or "*\\.(jpg|jpeg|png|gif)$" local cover_size = args.cover_size or 100 - local default_art = args.default_art or "" + local default_art = args.default_art local notify = args.notify or "on" local followtag = args.followtag or false local settings = args.settings or function() end @@ -105,7 +105,7 @@ local function worker(args) preset = mpd_notification_preset, icon = default_art, icon_size = cover_size, - replaces_id = mpd.id, + replaces_id = mpd.id } if not string.match(mpd_now.file, "http.*://") then -- local file instead of http stream @@ -113,6 +113,7 @@ local function worker(args) local cover = string.format("find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'", path, cover_pattern) helpers.async({ shell, "-c", cover }, function(current_icon) common.icon = current_icon:gsub("\n", "") + if #common.icon == 0 then common.icon = nil end mpd.id = naughty.notify(common).id end) else From ddbf283f0ebbc6772d485fe76c5dccf338d3b837 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 25 Jan 2017 17:13:14 +0100 Subject: [PATCH 077/106] fix #288 --- widgets/abase.lua | 2 +- widgets/alsa.lua | 2 +- widgets/base.lua | 4 +--- widgets/bat.lua | 2 +- widgets/contrib/gpmdp.lua | 6 ++---- widgets/contrib/kbdlayout.lua | 2 +- widgets/contrib/moc.lua | 2 +- widgets/contrib/tpbat/init.lua | 7 ++----- widgets/cpu.lua | 13 ++++++------- widgets/fs.lua | 2 +- widgets/imap.lua | 4 ++-- widgets/maildir.lua | 10 ++++------ widgets/mem.lua | 10 ++++------ widgets/mpd.lua | 2 +- widgets/net.lua | 2 +- widgets/pulseaudio.lua | 5 ++--- widgets/sysload.lua | 14 ++++++-------- widgets/temp.lua | 10 ++++------ widgets/weather.lua | 22 ++++++++++------------ wiki | 2 +- 20 files changed, 52 insertions(+), 71 deletions(-) diff --git a/widgets/abase.lua b/widgets/abase.lua index 7eef754..1214151 100644 --- a/widgets/abase.lua +++ b/widgets/abase.lua @@ -35,7 +35,7 @@ local function worker(args) abase.timer = helpers.newtimer(cmd, timeout, abase.update, nostart, stoppable) - return setmetatable(abase, { __index = abase.widget }) + return abase end return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/alsa.lua b/widgets/alsa.lua index 93c74cc..8139d42 100644 --- a/widgets/alsa.lua +++ b/widgets/alsa.lua @@ -50,7 +50,7 @@ local function worker(args) helpers.newtimer(string.format("alsa-%s-%s", alsa.cmd, alsa.channel), timeout, alsa.update) - return setmetatable(alsa, { __index = alsa.widget }) + return alsa end return setmetatable(alsa, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/base.lua b/widgets/base.lua index 87b0c85..9d7b710 100644 --- a/widgets/base.lua +++ b/widgets/base.lua @@ -22,8 +22,6 @@ local function worker(args) local cmd = args.cmd or "" local settings = args.settings or function() end - base.widget = wibox.widget.textbox() - function base.update() output = helpers.read_pipe(cmd) if output ~= base.prev then @@ -35,7 +33,7 @@ local function worker(args) base.timer = helpers.newtimer(cmd, timeout, base.update, nostart, stoppable) - return setmetatable(base, { __index = base.widget }) + return base end return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/bat.lua b/widgets/bat.lua index 8b62790..503c56e 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -177,7 +177,7 @@ local function worker(args) newtimer("batteries", timeout, bat.update) - return setmetatable(bat, { __index = bat.widget }) + return bat end return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/contrib/gpmdp.lua b/widgets/contrib/gpmdp.lua index 21776ac..37da43d 100644 --- a/widgets/contrib/gpmdp.lua +++ b/widgets/contrib/gpmdp.lua @@ -19,7 +19,7 @@ local setmetatable = setmetatable -- Google Play Music Desktop infos -- lain.widget.contrib.gpmdp -local gpmdp = {} +local gpmdp = helpers.make_widget_textbox() local function worker(args) local args = args or {} @@ -30,8 +30,6 @@ local function worker(args) os.getenv("HOME") .. "/.config/Google Play Music Desktop Player/json_store/playback.json" local settings = args.settings or function() end - gpmdp.widget = wibox.widget.textbox('') - gpmdp_notification_preset = { title = "Now playing", timeout = 6 @@ -86,7 +84,7 @@ local function worker(args) gpmdp.timer = helpers.newtimer("gpmdp", timeout, gpmdp.update, true, true) - return setmetatable(gpmdp, { __index = gpmdp.widget }) + return gpmdp end return setmetatable(gpmdp, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/contrib/kbdlayout.lua b/widgets/contrib/kbdlayout.lua index da3084c..8132c77 100644 --- a/widgets/contrib/kbdlayout.lua +++ b/widgets/contrib/kbdlayout.lua @@ -72,7 +72,7 @@ local function worker(args) helpers.newtimer("kbdlayout", timeout, kbdlayout.update) - return setmetatable(kbdlayout, { __index = kbdlayout.widget }) + return kbdlayout end return setmetatable({}, { __call = function (_, ...) return worker(...) end }) diff --git a/widgets/contrib/moc.lua b/widgets/contrib/moc.lua index 6190f5f..3566985 100644 --- a/widgets/contrib/moc.lua +++ b/widgets/contrib/moc.lua @@ -93,7 +93,7 @@ local function worker(args) moc.timer = helpers.newtimer("moc", timeout, moc.update, true, true) - return setmetatable(moc, { __index = moc.widget }) + return moc end return setmetatable(moc, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/contrib/tpbat/init.lua b/widgets/contrib/tpbat/init.lua index d96c2d8..3342e02 100644 --- a/widgets/contrib/tpbat/init.lua +++ b/widgets/contrib/tpbat/init.lua @@ -19,19 +19,16 @@ local newtimer = require("lain.helpers").newtimer local first_line = require("lain.helpers").first_line local naughty = require("naughty") local wibox = require("wibox") - local string = { format = string.format } local math = { floor = math.floor } local tostring = tostring local setmetatable = setmetatable - package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .. "?.lua;" .. package.path local smapi = require("smapi") -- ThinkPad SMAPI-enabled battery info widget -- lain.widgets.contrib.tpbat local tpbat = { } -local tpbat_notification = nil function tpbat.hide() if not tpbat.notification then return end @@ -69,7 +66,7 @@ function tpbat.show(t_out) local str = string.format("%s : %s %s (%s)\n", bat.name, mfgr, model, chem) .. string.format("\n%s \t\t\t %s", status:upper(), msg) - tpbat_notification = naughty.notify({ + tpbat.notification = naughty.notify({ preset = naughty.config.defaults, text = str, timeout = t_out, @@ -86,7 +83,7 @@ function tpbat.register(args) tpbat.bat = smapi:battery(battery) -- Create a new battery local bat = tpbat.bat - tpbat.widget = wibox.widget.textbox('') + tpbat.widget = wibox.widget.textbox() bat_notification_low_preset = { title = "Battery low", diff --git a/widgets/cpu.lua b/widgets/cpu.lua index f7fb087..f61e2cc 100644 --- a/widgets/cpu.lua +++ b/widgets/cpu.lua @@ -7,8 +7,7 @@ --]] -local lines_match = require("lain.helpers").lines_match -local newtimer = require("lain.helpers").newtimer +local helpers = require("lain.helpers") local wibox = require("wibox") local math = { ceil = math.ceil } local string = { format = string.format, @@ -18,20 +17,20 @@ local setmetatable = setmetatable -- CPU usage -- lain.widgets.cpu -local cpu = { core = {} } +local cpu = helpers.make_widget_textbox() local function worker(args) local args = args or {} local timeout = args.timeout or 2 local settings = args.settings or function() end - cpu.widget = wibox.widget.textbox() + cpu.core = {} function update() -- Read the amount of time the CPUs have spent performing -- different kinds of work. Read the first line of /proc/stat -- which is the sum of all CPUs. - local times = lines_match("cpu","/proc/stat") + local times = helpers.lines_match("cpu","/proc/stat") for index,time in pairs(times) do local coreid = index - 1 @@ -75,9 +74,9 @@ local function worker(args) settings() end - newtimer("cpu", timeout, update) + helpers.newtimer("cpu", timeout, update) - return setmetatable(cpu, { __index = cpu.widget }) + return cpu end return setmetatable(cpu, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/fs.lua b/widgets/fs.lua index 4e9f04b..e01aab8 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -124,7 +124,7 @@ local function worker(args) helpers.newtimer(partition, timeout, fs.update) - return setmetatable(fs, { __index = fs.widget }) + return fs end return setmetatable(fs, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/imap.lua b/widgets/imap.lua index 5896ae1..4be63dd 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -17,7 +17,7 @@ local setmetatable = setmetatable -- Mail IMAP check -- lain.widgets.imap -local function worker(args ) +local function worker(args) local imap = helpers.make_widget_textbox() local args = args or {} local server = args.server @@ -76,7 +76,7 @@ local function worker(args ) imap.timer = helpers.newtimer(mail, timeout, update, true, true) - return setmetatable(imap, { __index = imap.widget }) + return imap end return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/maildir.lua b/widgets/maildir.lua index 1f4cd45..7e7b246 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -18,7 +18,7 @@ local setmetatable = setmetatable -- Maildir check (synchronous) -- lain.widgets.maildir -local maildir = {} +local maildir = helpers.make_widget_textbox() local function worker(args) local args = args or {} @@ -26,12 +26,10 @@ local function worker(args) local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail" local ignore_boxes = args.ignore_boxes or {} local settings = args.settings or function() end - local ext_mail_cmd = args.external_mail_cmd - - maildir.widget = wibox.widget.textbox() + local cmd = args.cmd function maildir.update() - if ext_mail_cmd then awful.spawn(ext_mail_cmd) end + if cmd then helpers.async({ awful.util.shell, "-c", cmd }, function() end) end -- Find pathes to mailboxes. local p = io.popen(string.format("find %s -mindepth 1 -maxdepth 2 -type d -not -name .git", mailpath)) @@ -78,7 +76,7 @@ local function worker(args) maildir.timer = helpers.newtimer(mailpath, timeout, maildir.update, true, true) - return setmetatable(maildir, { __index = maildir.widget }) + return maildir end return setmetatable(maildir, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/mem.lua b/widgets/mem.lua index e96dc1b..ff5816c 100644 --- a/widgets/mem.lua +++ b/widgets/mem.lua @@ -7,7 +7,7 @@ --]] -local newtimer = require("lain.helpers").newtimer +local helpers = require("lain.helpers") local wibox = require("wibox") local gmatch = string.gmatch local lines = io.lines @@ -16,15 +16,13 @@ local setmetatable = setmetatable -- Memory usage (ignoring caches) -- lain.widgets.mem -local mem = {} +local mem = helpers.make_widget_textbox() local function worker(args) local args = args or {} local timeout = args.timeout or 2 local settings = args.settings or function() end - mem.widget = wibox.widget.textbox() - function update() mem_now = {} for line in lines("/proc/meminfo") do @@ -48,9 +46,9 @@ local function worker(args) settings() end - newtimer("mem", timeout, update) + helpers.newtimer("mem", timeout, update) - return setmetatable(mem, { __index = mem.widget }) + return mem end return setmetatable(mem, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/mpd.lua b/widgets/mpd.lua index aad4dc8..d92c78f 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -129,7 +129,7 @@ local function worker(args) mpd.timer = helpers.newtimer("mpd", timeout, mpd.update, true, true) - return setmetatable(mpd, { __index = mpd.widget }) + return mpd end return setmetatable(mpd, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/net.lua b/widgets/net.lua index 0b19f0b..302559a 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -119,7 +119,7 @@ local function worker(args) helpers.newtimer("network", timeout, update) - return setmetatable(net, { __index = net.widget }) + return net end return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/pulseaudio.lua b/widgets/pulseaudio.lua index 3178dcf..8e89ffd 100644 --- a/widgets/pulseaudio.lua +++ b/widgets/pulseaudio.lua @@ -16,7 +16,7 @@ local setmetatable = setmetatable -- PulseAudio volume -- lain.widgets.pulseaudio -local pulseaudio = {} +local pulseaudio = helpers.make_widget_textbox() local function worker(args) local args = args or {} @@ -25,7 +25,6 @@ local function worker(args) local scallback = args.scallback pulseaudio.cmd = args.cmd or "pacmd list-sinks | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'" - pulseaudio.widget = wibox.widget.textbox() function pulseaudio.update() if scallback then pulseaudio.cmd = scallback() end @@ -54,7 +53,7 @@ local function worker(args) helpers.newtimer("pulseaudio", timeout, pulseaudio.update) - return setmetatable(pulseaudio, { __index = pulseaudio.widget }) + return pulseaudio end return setmetatable(pulseaudio, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/sysload.lua b/widgets/sysload.lua index 041feb1..148319d 100644 --- a/widgets/sysload.lua +++ b/widgets/sysload.lua @@ -7,7 +7,7 @@ --]] -local newtimer = require("lain.helpers").newtimer +local helpers = require("lain.helpers") local wibox = require("wibox") local io = { open = io.open } local string = { match = string.match } @@ -15,15 +15,13 @@ local setmetatable = setmetatable -- System load -- lain.widgets.sysload -local sysload = {} +local sysload = helpers.make_widget_textbox() local function worker(args) - local args = args or {} - local timeout = args.timeout or 2 + local args = args or {} + local timeout = args.timeout or 2 local settings = args.settings or function() end - sysload.widget = wibox.widget.textbox() - function update() local f = io.open("/proc/loadavg") local ret = f:read("*all") @@ -35,9 +33,9 @@ local function worker(args) settings() end - newtimer("sysload", timeout, update) + helpers.newtimer("sysload", timeout, update) - return setmetatable(sysload, { __index = sysload.widget }) + return sysload end return setmetatable(sysload, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/temp.lua b/widgets/temp.lua index e769b25..4d8a727 100644 --- a/widgets/temp.lua +++ b/widgets/temp.lua @@ -6,7 +6,7 @@ --]] -local newtimer = require("lain.helpers").newtimer +local helpers = require("lain.helpers") local wibox = require("wibox") local io = { open = io.open } local tonumber = tonumber @@ -14,7 +14,7 @@ local setmetatable = setmetatable -- coretemp -- lain.widgets.temp -local temp = {} +local temp = helpers.make_widget_textbox() local function worker(args) local args = args or {} @@ -22,8 +22,6 @@ local function worker(args) local tempfile = args.tempfile or "/sys/class/thermal/thermal_zone0/temp" local settings = args.settings or function() end - temp.widget = wibox.widget.textbox() - function update() local f = io.open(tempfile) if f then @@ -37,9 +35,9 @@ local function worker(args) settings() end - newtimer("coretemp", timeout, update) + helpers.newtimer("coretemp", timeout, update) - return setmetatable(temp, { __index = temp.widget }) + return temp end return setmetatable(temp, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/weather.lua b/widgets/weather.lua index ff86d7e..9f83dc8 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -6,9 +6,7 @@ --]] -local async = require("lain.helpers").async -local newtimer = require("lain.helpers").newtimer -local lain_icons = require("lain.helpers").icons_dir +local helpers = require("lain.helpers") local json = require("lain.util").dkjson local focused = require("awful.screen").focused local naughty = require("naughty") @@ -27,7 +25,7 @@ local setmetatable = setmetatable -- lain.widgets.weather local function worker(args) - local weather = {} + local weather = helpers.make_widget_textbox() local args = args or {} local APPID = args.APPID or "3e321f9414eaedbfab34983bda77a66e" -- lain default local timeout = args.timeout or 900 -- 15 min @@ -44,7 +42,7 @@ local function worker(args) local lang = args.lang or "en" local cnt = args.cnt or 5 local date_cmd = args.date_cmd or "date -u -d @%d +'%%a %%d'" - local icons_path = args.icons_path or lain_icons .. "openweathermap/" + local icons_path = args.icons_path or helpers.icons_dir .. "openweathermap/" local notification_preset = args.notification_preset or {} local notification_text_fun = args.notification_text_fun or function (wn) @@ -58,9 +56,9 @@ local function worker(args) local followtag = args.followtag or false local settings = args.settings or function() end - weather.widget = wibox.widget.textbox(weather_na_markup) + weather.widget:set_markup(weather_na_markup) weather.icon_path = icons_path .. "na.png" - weather.icon = wibox.widget.imagebox(weather.icon_path) + weather.icon = wibox.widget.imagebox(weather.icon_path) function weather.show(t_out) weather.hide() @@ -99,7 +97,7 @@ local function worker(args) function weather.forecast_update() local cmd = string.format(forecast_call, city_id, units, lang, cnt, APPID) - async(cmd, function(f) + helpers.async(cmd, function(f) local pos, err weather_now, pos, err = json.decode(f, 1, nil) @@ -119,7 +117,7 @@ local function worker(args) function weather.update() local cmd = string.format(current_call, city_id, units, lang, APPID) - async(cmd, function(f) + helpers.async(cmd, function(f) local pos, err, icon weather_now, pos, err = json.decode(f, 1, nil) @@ -160,10 +158,10 @@ local function worker(args) weather.attach(weather.widget) - weather.timer = newtimer("weather-" .. city_id, timeout, weather.update, false, true) - weather.timer_forecast = newtimer("weather_forecast-" .. city_id, timeout, weather.forecast_update, false, true) + weather.timer = helpers.newtimer("weather-" .. city_id, timeout, weather.update, false, true) + weather.timer_forecast = helpers.newtimer("weather_forecast-" .. city_id, timeout, weather.forecast_update, false, true) - return setmetatable(weather, { __index = weather.widget }) + return weather end return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/wiki b/wiki index 7e48658..6d6fb0e 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 7e4865822c669a86007d88bf6ae846a95c5eed5f +Subproject commit 6d6fb0eb073e204c154e4d94b60472d858fc870d From 49a4df385e953156e6d1e2ee0bcfd07d8501d0f4 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 25 Jan 2017 17:28:37 +0100 Subject: [PATCH 078/106] no need to set naughty.config.defaults as preset, because it's implicit; closes #290 --- helpers.lua | 15 +++++++++++++++ widgets/alsabar.lua | 4 ++-- widgets/calendar.lua | 16 ++++++++-------- widgets/contrib/task.lua | 7 ++++--- widgets/contrib/tpbat/init.lua | 12 +++++------- widgets/fs.lua | 9 +++++---- widgets/pulsebar.lua | 4 ++-- 7 files changed, 41 insertions(+), 26 deletions(-) diff --git a/helpers.lua b/helpers.lua index 7c44648..b1a195c 100644 --- a/helpers.lua +++ b/helpers.lua @@ -185,6 +185,21 @@ function helpers.make_widget_textbox() return t end +-- shallow copy a table +function helpers.table_shallowcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in pairs(orig) do + copy[orig_key] = orig_value + end + else -- number, string, boolean, etc + copy = orig + end + return copy +end + -- }}} return helpers diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index c3e3d9d..ba1216c 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -50,8 +50,8 @@ local function worker(args) alsabar.notification_preset = args.notification_preset if not alsabar.notification_preset then - alsabar.notification_preset = naughty.config.defaults - alsabar.notification_preset.font = "Monospace 11" + alsabar.notification_preset = {} + alsabar.notification_preset.font = "Monospace 10" end local format_cmd = string.format("%s get %s", alsabar.cmd, alsabar.channel) diff --git a/widgets/calendar.lua b/widgets/calendar.lua index 76284f5..3ad3498 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -6,8 +6,7 @@ --]] -local async = require("lain.helpers").async -local icons_dir = require("lain.helpers").icons_dir +local helpers = require("lain.helpers") local markup = require("lain.util.markup") local awful = require("awful") local naughty = require("naughty") @@ -67,7 +66,7 @@ function calendar.show(t_out, inc_offset, scr) calendar.notification_preset.screen = src or 1 end - async(f, function(ws) + helpers.async(f, function(ws) fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg ws = ws:gsub("%c%[%d+[m]?%d+%c%[%d+[m]?", markup.bold(markup.color(bg, fg, today))) calendar.notification = naughty.notify({ @@ -83,14 +82,15 @@ function calendar.attach(widget, args) local args = args or {} calendar.cal = args.cal or "/usr/bin/cal --color=always" calendar.followtag = args.followtag or false - calendar.icons = args.icons or icons_dir .. "cal/white/" + calendar.icons = args.icons or helpers.icons_dir .. "cal/white/" calendar.notification_preset = args.notification_preset if not calendar.notification_preset then - calendar.notification_preset = naughty.config.defaults - calendar.notification_preset.font = "Monospace 10" - calendar.notification_preset.fg = "#FFFFFF" - calendar.notification_preset.bg = "#000000" + calendar.notification_preset = { + font = "Monospace 10", + fg = "#FFFFFF", + bg = "#000000" + } end if widget then diff --git a/widgets/contrib/task.lua b/widgets/contrib/task.lua index 4325437..afc9f93 100644 --- a/widgets/contrib/task.lua +++ b/widgets/contrib/task.lua @@ -66,9 +66,10 @@ function task.attach(widget, args) task.notification_preset = args.notification_preset if not task.notification_preset then - task.notification_preset = naughty.config.defaults - task.notification_preset.font = "Monospace 10" - task.notification_preset.icon = helpers.icons_dir .. "/taskwarrior.png" + task.notification_preset = { + font = "Monospace 10", + icon = helpers.icons_dir .. "/taskwarrior.png" + } end if widget then diff --git a/widgets/contrib/tpbat/init.lua b/widgets/contrib/tpbat/init.lua index 3342e02..32a2527 100644 --- a/widgets/contrib/tpbat/init.lua +++ b/widgets/contrib/tpbat/init.lua @@ -51,10 +51,8 @@ function tpbat.show(t_out) local time = bat:remaining_time() local msg = "\t" - if status ~= "idle" and status ~= "nil" - then - if time == "N/A" - then + if status ~= "idle" and status ~= "nil" then + if time == "N/A" then msg = "...Calculating time remaining..." else msg = time .. (status == "charging" and " until charged" or " remaining") @@ -67,10 +65,9 @@ function tpbat.show(t_out) .. string.format("\n%s \t\t\t %s", status:upper(), msg) tpbat.notification = naughty.notify({ - preset = naughty.config.defaults, - text = str, + text = str, timeout = t_out, - screen = client.focus and client.focus.screen or 1 + screen = client.focus and client.focus.screen or 1 }) end @@ -150,6 +147,7 @@ function tpbat.register(args) end widget = tpbat.widget + settings() end diff --git a/widgets/fs.lua b/widgets/fs.lua index e01aab8..312a5e3 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -61,10 +61,11 @@ local function worker(args) fs.notification_preset = args.notification_preset if not fs.notification_preset then - fs.notification_preset = naughty.config.defaults - fs.notification_preset.font = "Monospace 10" - fs.notification_preset.fg = "#FFFFFF" - fs.notification_preset.bg = "#000000" + fs.notification_preset = { + font = "Monospace 10", + fg = "#FFFFFF", + bg = "#000000" + } end helpers.set_map(partition, false) diff --git a/widgets/pulsebar.lua b/widgets/pulsebar.lua index 8cf8566..db03b24 100644 --- a/widgets/pulsebar.lua +++ b/widgets/pulsebar.lua @@ -51,8 +51,8 @@ local function worker(args) pulsebar.notifications = args.notification_preset if not pulsebar.notification_preset then - pulsebar.notification_preset = naughty.config.defaults - pulsebar.notification_preset.font = "Monospace 11" + pulsebar.notification_preset = {} + pulsebar.notification_preset.font = "Monospace 10" end pulsebar.bar = wibox.widget { From 43cd98510a33e9f2d50d315a9bfc31ff8d3062c9 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 25 Jan 2017 18:35:30 +0100 Subject: [PATCH 079/106] calendar: fix async hanging notifications; closes #289 --- helpers.lua | 15 --------------- widgets/alsabar.lua | 13 +++++++++---- widgets/calendar.lua | 19 ++++++++----------- widgets/fs.lua | 11 +++++------ widgets/pulsebar.lua | 13 +++++++++---- 5 files changed, 31 insertions(+), 40 deletions(-) diff --git a/helpers.lua b/helpers.lua index b1a195c..7c44648 100644 --- a/helpers.lua +++ b/helpers.lua @@ -185,21 +185,6 @@ function helpers.make_widget_textbox() return t end --- shallow copy a table -function helpers.table_shallowcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in pairs(orig) do - copy[orig_key] = orig_value - end - else -- number, string, boolean, etc - copy = orig - end - return copy -end - -- }}} return helpers diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index ba1216c..90c60b4 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -119,10 +119,15 @@ local function worker(args) if alsabar.followtag then preset.screen = awful.screen.focused() end - alsabar.id = naughty.notify ({ - replaces_id = alsabar.id, - preset = preset - }).id + if not alsabar.notification then + alsabar.notification = naughty.notify { + preset = preset, + destroy = function() alsabar.notification = nil end + } + else + naughty.replace_text(alsabar.notification, preset.title, preset.text) + naughty.reset_timeout(alsabar.notification, preset.timeout) + end end) end diff --git a/widgets/calendar.lua b/widgets/calendar.lua index 3ad3498..892d954 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -20,14 +20,10 @@ local tonumber = tonumber local calendar = { offset = 0 } function calendar.hide() - if not calendar.notification then return end - naughty.destroy(calendar.notification) - calendar.notification = nil + naughty.destroy(naughty.getById(calendar.id)) end function calendar.show(t_out, inc_offset, scr) - calendar.hide() - local today = os.date("%d") local offs = inc_offset or 0 local f @@ -69,12 +65,13 @@ function calendar.show(t_out, inc_offset, scr) helpers.async(f, function(ws) fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg ws = ws:gsub("%c%[%d+[m]?%d+%c%[%d+[m]?", markup.bold(markup.color(bg, fg, today))) - calendar.notification = naughty.notify({ - preset = calendar.notification_preset, - text = ws:gsub("\n*$", ""), - icon = calendar.notify_icon, - timeout = t_out or calendar.notification.preset.timeout or 5 - }) + calendar.id = naughty.notify({ + replaces_id = calendar.id, + preset = calendar.notification_preset, + text = ws:gsub("\n*$", ""), + icon = calendar.notify_icon, + timeout = t_out or calendar.notification.preset.timeout or 5 + }).id end) end diff --git a/widgets/fs.lua b/widgets/fs.lua index 312a5e3..4e9f04b 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -61,11 +61,10 @@ local function worker(args) fs.notification_preset = args.notification_preset if not fs.notification_preset then - fs.notification_preset = { - font = "Monospace 10", - fg = "#FFFFFF", - bg = "#000000" - } + fs.notification_preset = naughty.config.defaults + fs.notification_preset.font = "Monospace 10" + fs.notification_preset.fg = "#FFFFFF" + fs.notification_preset.bg = "#000000" end helpers.set_map(partition, false) @@ -125,7 +124,7 @@ local function worker(args) helpers.newtimer(partition, timeout, fs.update) - return fs + return setmetatable(fs, { __index = fs.widget }) end return setmetatable(fs, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/pulsebar.lua b/widgets/pulsebar.lua index db03b24..5453b1f 100644 --- a/widgets/pulsebar.lua +++ b/widgets/pulsebar.lua @@ -129,10 +129,15 @@ local function worker(args) if pulsebar.followtag then preset.screen = awful.screen.focused() end - pulsebar.id = naughty.notify ({ - replaces_id = pulsebar.id, - preset = preset - }).id + if not pulsebar.notification then + pulsebar.notification = naughty.notify { + preset = preset, + destroy = function() pulsebar.notification = nil end + } + else + naughty.replace_text(pulsebar.notification, preset.title, preset.text) + naughty.reset_timeout(pulsebar.notification, preset.timeout) + end end) end From 5d7c6078d11a697c4ea2a72300355d18ffd47d84 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 25 Jan 2017 18:38:50 +0100 Subject: [PATCH 080/106] #290 forgot fs --- widgets/fs.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/widgets/fs.lua b/widgets/fs.lua index 4e9f04b..efd31fb 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -61,10 +61,11 @@ local function worker(args) fs.notification_preset = args.notification_preset if not fs.notification_preset then - fs.notification_preset = naughty.config.defaults - fs.notification_preset.font = "Monospace 10" - fs.notification_preset.fg = "#FFFFFF" - fs.notification_preset.bg = "#000000" + fs.notification_preset = { + font = "Monospace 10", + fg = "#FFFFFF", + bg = "#000000" + } end helpers.set_map(partition, false) From 5318966270d86d52a2b9d7244b9336544a946d85 Mon Sep 17 00:00:00 2001 From: Kevin Zander Date: Wed, 25 Jan 2017 12:27:49 -0600 Subject: [PATCH 081/106] Fix bugs with v4 API update --- layout/cascade.lua | 13 ++++++++----- layout/centerwork.lua | 7 +++++-- layout/termfair.lua | 18 +++++++++++------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/layout/cascade.lua b/layout/cascade.lua index cc3f50f..2b02c00 100644 --- a/layout/cascade.lua +++ b/layout/cascade.lua @@ -8,7 +8,7 @@ --]] -local tag = require("awful.tag") +local scr = require("awful.screen") local tonumber = tonumber local cascade = { @@ -31,6 +31,9 @@ local function do_cascade(p, tiling) -- Screen. local wa = p.workarea local cls = p.clients + local ta = scr.focused().selected_tag + + if not ta then return end if #cls <= 0 then return end @@ -44,7 +47,7 @@ local function do_cascade(p, tiling) if cascade.nmaster > 0 then num_c = cascade.nmaster else - num_c = tag.master_count + num_c = ta.master_count end -- Opening a new window will usually force all existing windows to @@ -89,7 +92,7 @@ local function do_cascade(p, tiling) if cascade.tile.mwfact > 0 then mwfact = cascade.tile.mwfact else - mwfact = tag.getmwfact(t) + mwfact = ta.master_width_factor end -- Make slave windows overlap main window? Do this if ncol is 1. @@ -97,7 +100,7 @@ local function do_cascade(p, tiling) if cascade.tile.ncol > 0 then overlap_main = cascade.tile.ncol else - overlap_main = tag.column_count + overlap_main = ta.column_count end -- Minimum space for slave windows? See cascade.tile.lua. @@ -105,7 +108,7 @@ local function do_cascade(p, tiling) if cascade.tile.nmaster > 0 then num_c = cascade.tile.nmaster else - num_c = tag.master_count + num_c = ta.master_count end local how_many = (#cls - 1 >= num_c and (#cls - 1)) or num_c diff --git a/layout/centerwork.lua b/layout/centerwork.lua index a79314e..a8d9a96 100644 --- a/layout/centerwork.lua +++ b/layout/centerwork.lua @@ -10,9 +10,9 @@ --]] -local tag = require("awful.tag") local tonumber = tonumber local math = { floor = math.floor } +local scr = require("awful.screen") local centerwork = { name = "centerwork", @@ -23,6 +23,9 @@ local function do_centerwork(p, orientation) -- Screen. local wa = p.workarea local cls = p.clients + local ta = scr.focused().selected_tag + + if not ta then return end if #cls <= 0 then return end @@ -33,7 +36,7 @@ local function do_centerwork(p, orientation) local g = {} -- Main column, fixed width and height. - local mwfact = tag.object.get_master_width_factor(t) + local mwfact = ta.master_width_factor local mainhei = math.floor(wa.height * mwfact) local mainwid = math.floor(wa.width * mwfact) local slavewid = wa.width - mainwid diff --git a/layout/termfair.lua b/layout/termfair.lua index 6d24460..26a7130 100644 --- a/layout/termfair.lua +++ b/layout/termfair.lua @@ -9,7 +9,7 @@ --]] -local tag = require("awful.tag") +local scr = require("awful.screen") local math = { ceil = math.ceil, floor = math.floor, max = math.max } @@ -22,6 +22,9 @@ local function do_fair(p, orientation) -- Screen. local wa = p.workarea local cls = p.clients + local ta = scr.focused().selected_tag + + if not ta then return end if #cls <= 0 then return end @@ -50,12 +53,12 @@ local function do_fair(p, orientation) if #cls <= 0 then return end -- How many vertical columns? Read from nmaster on the tag. - local num_x = tonumber(termfair.nmaster) or tag.master_count - local ncol = tonumber(termfair.ncol) or tag.column_count - local width = math.floor((wa.width - (num_x + 1)*useless_gap) / num_x) + local num_x = tonumber(termfair.nmaster) or ta.master_count + local ncol = tonumber(termfair.ncol) or ta.column_count if num_x <= 2 then num_x = 2 end if ncol <= 1 then ncol = 1 end + local width = math.floor((wa.width - (num_x + 1)*useless_gap) / num_x) local num_y = math.max(math.ceil(#cls / num_x), ncol) local height = math.floor((wa.height - (num_y + 1)*useless_gap) / num_y) @@ -143,13 +146,14 @@ local function do_fair(p, orientation) -- +---+---+---+ +---+---+---+ -- How many vertical columns? Read from nmaster on the tag. - local num_x = tonumber(termfair.center.nmaster) or tag.master_count - local ncol = tonumber(termfair.center.ncol) or tag.column_count - local width = math.floor((wa.width - (num_x + 1)*useless_gap) / num_x) + local num_x = tonumber(termfair.center.nmaster) or ta.master_count + local ncol = tonumber(termfair.center.ncol) or ta.column_count if num_x <= 2 then num_x = 2 end if ncol <= 1 then ncol = 1 end + local width = math.floor((wa.width - (num_x + 1)*useless_gap) / num_x) + if #cls < num_x then -- Less clients than the number of columns, let's center it! local offset_x = wa.x + (wa.width - #cls*width - (#cls - 1)*useless_gap) / 2 From 2d35d4e102074ae449ec1f4d261517fe06c5a01d Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 25 Jan 2017 19:34:18 +0100 Subject: [PATCH 082/106] #288 trying metatables --- helpers.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/helpers.lua b/helpers.lua index 7c44648..106978f 100644 --- a/helpers.lua +++ b/helpers.lua @@ -180,9 +180,10 @@ end -- create a textbox with no spacing issues function helpers.make_widget_textbox() local w = wibox.widget.textbox() - local t = wibox.widget.base.make_widget(w) - t.widget = w - return t + --local t = wibox.widget.base.make_widget(w) + --t.widget = w + --return t + return setmetatable({ widget = w }, { __index = w }) end -- }}} From 434d5f32aa3a19763bf6bb2eed40f881fd918309 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 25 Jan 2017 19:38:05 +0100 Subject: [PATCH 083/106] {alsa,pulse}bar: remove reset_timeout due to (timer already started) issue --- widgets/alsabar.lua | 1 - widgets/pulsebar.lua | 1 - 2 files changed, 2 deletions(-) diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index 90c60b4..628e838 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -126,7 +126,6 @@ local function worker(args) } else naughty.replace_text(alsabar.notification, preset.title, preset.text) - naughty.reset_timeout(alsabar.notification, preset.timeout) end end) end diff --git a/widgets/pulsebar.lua b/widgets/pulsebar.lua index 5453b1f..c75ad4a 100644 --- a/widgets/pulsebar.lua +++ b/widgets/pulsebar.lua @@ -136,7 +136,6 @@ local function worker(args) } else naughty.replace_text(pulsebar.notification, preset.title, preset.text) - naughty.reset_timeout(pulsebar.notification, preset.timeout) end end) end From 58b2a122dd20cc4d1d15a29a27e618c9c88050cc Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 25 Jan 2017 19:50:08 +0100 Subject: [PATCH 084/106] wiki updated --- helpers.lua | 3 --- wiki | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/helpers.lua b/helpers.lua index 106978f..e65e3fb 100644 --- a/helpers.lua +++ b/helpers.lua @@ -180,9 +180,6 @@ end -- create a textbox with no spacing issues function helpers.make_widget_textbox() local w = wibox.widget.textbox() - --local t = wibox.widget.base.make_widget(w) - --t.widget = w - --return t return setmetatable({ widget = w }, { __index = w }) end diff --git a/wiki b/wiki index 6d6fb0e..f086b95 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 6d6fb0eb073e204c154e4d94b60472d858fc870d +Subproject commit f086b95e51c31b6fc1fda4591aa8eaf587cc064f From bf3a9ba5efb874ad6370a3083afd409361e2912a Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 25 Jan 2017 21:06:20 +0100 Subject: [PATCH 085/106] imap: password can now be a string, a table or a function to execute --- helpers.lua | 6 +++--- widgets/imap.lua | 7 ++++++- wiki | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/helpers.lua b/helpers.lua index e65e3fb..0305722 100644 --- a/helpers.lua +++ b/helpers.lua @@ -177,10 +177,10 @@ function helpers.spairs(t) end end --- create a textbox with no spacing issues +-- create a lain textbox function helpers.make_widget_textbox() - local w = wibox.widget.textbox() - return setmetatable({ widget = w }, { __index = w }) + local w = { widget = wibox.widget.textbox() } + return setmetatable(w, { __index = w.widget }) end -- }}} diff --git a/widgets/imap.lua b/widgets/imap.lua index 4be63dd..770a1bc 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -11,6 +11,7 @@ local naughty = require("naughty") local wibox = require("wibox") local string = { format = string.format, gsub = string.gsub } +local type = type local tonumber = tonumber local setmetatable = setmetatable @@ -37,7 +38,11 @@ local function worker(args) helpers.set_map(mail, 0) if not is_plain then - helpers.async(password, function(f) password = f:gsub("\n", "") end) + if type(password) == "string" or type(password) == "table" then + helpers.async(password, function(f) password = f:gsub("\n", "") end) + elseif type(password) == "function" then + local p = password() + end end function update() diff --git a/wiki b/wiki index f086b95..0af22b8 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit f086b95e51c31b6fc1fda4591aa8eaf587cc064f +Subproject commit 0af22b80f8dda896a0c8fefd5c7e52413294967d From 752ba7fa3d8928dfc19c59dbf3c6d167c4ae3bc9 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Thu, 26 Jan 2017 19:28:41 +0100 Subject: [PATCH 086/106] layouts: geometry computation aligned to v4.0 API; fixes #267 --- layout/cascade.lua | 85 +++++++++-------------- layout/centerwork.lua | 97 +++++++++++++-------------- layout/termfair.lua | 152 +++++++++++++++++++----------------------- 3 files changed, 144 insertions(+), 190 deletions(-) diff --git a/layout/cascade.lua b/layout/cascade.lua index 2b02c00..204ce40 100644 --- a/layout/cascade.lua +++ b/layout/cascade.lua @@ -8,8 +8,8 @@ --]] -local scr = require("awful.screen") -local tonumber = tonumber +local floor = math.floor +local screen = screen local cascade = { name = "cascade", @@ -28,17 +28,11 @@ local cascade = { } local function do_cascade(p, tiling) - -- Screen. - local wa = p.workarea + local t = p.tag or screen[p.screen].selected_tag + local wa = p.workarea local cls = p.clients - local ta = scr.focused().selected_tag - if not ta then return end - - if #cls <= 0 then return end - - -- Useless gaps. - local useless_gap = p.useless_gap or 0 + if #cls == 0 then return end if not tiling then -- Cascade windows. @@ -47,7 +41,7 @@ local function do_cascade(p, tiling) if cascade.nmaster > 0 then num_c = cascade.nmaster else - num_c = ta.master_count + num_c = t.master_count end -- Opening a new window will usually force all existing windows to @@ -66,13 +60,13 @@ local function do_cascade(p, tiling) g.x = wa.x + (how_many - i) * cascade.offset_x g.y = wa.y + (i - 1) * cascade.offset_y - g.width = wa.width - current_offset_x - 2*c.border_width - g.height = wa.height - current_offset_y - 2*c.border_width + g.width = wa.width - current_offset_x + g.height = wa.height - current_offset_y if g.width < 1 then g.width = 1 end if g.height < 1 then g.height = 1 end - c:geometry(g) + p.geometries[c] = g end else -- Layout with one fixed column meant for a master window. Its @@ -92,7 +86,7 @@ local function do_cascade(p, tiling) if cascade.tile.mwfact > 0 then mwfact = cascade.tile.mwfact else - mwfact = ta.master_width_factor + mwfact = t.master_width_factor end -- Make slave windows overlap main window? Do this if ncol is 1. @@ -100,7 +94,7 @@ local function do_cascade(p, tiling) if cascade.tile.ncol > 0 then overlap_main = cascade.tile.ncol else - overlap_main = ta.column_count + overlap_main = t.column_count end -- Minimum space for slave windows? See cascade.tile.lua. @@ -108,7 +102,7 @@ local function do_cascade(p, tiling) if cascade.tile.nmaster > 0 then num_c = cascade.tile.nmaster else - num_c = ta.master_count + num_c = t.master_count end local how_many = (#cls - 1 >= num_c and (#cls - 1)) or num_c @@ -121,15 +115,13 @@ local function do_cascade(p, tiling) -- Main column, fixed width and height. local c = cls[1] local g = {} - -- Subtracting the useless_gap width from the work area width here - -- makes this mwfact calculation work the same as in uselesstile. -- Rounding is necessary to prevent the rendered size of slavewid -- from being 1 pixel off when the result is not an integer. - local mainwid = math.floor((wa.width - useless_gap) * mwfact) + local mainwid = floor(wa.width * mwfact) local slavewid = wa.width - mainwid if overlap_main == 1 then - g.width = wa.width - 2*c.border_width + g.width = wa.width -- The size of the main window may be reduced a little bit. -- This allows you to see if there are any windows below the @@ -138,49 +130,34 @@ local function do_cascade(p, tiling) -- overlapping everything else. g.width = g.width - cascade.tile.extra_padding else - g.width = mainwid - 2*c.border_width + g.width = mainwid end - g.height = wa.height - 2*c.border_width + g.height = wa.height g.x = wa.x g.y = wa.y - if useless_gap > 0 then - -- Reduce width once and move window to the right. - -- Reduce height twice, however. - g.width = g.width - useless_gap - g.height = g.height - 2 * useless_gap - g.x = g.x + useless_gap - g.y = g.y + useless_gap - -- When there's no window to the right, add an additional gap. - if overlap_main == 1 then g.width = g.width - useless_gap end - end - if g.width < 1 then g.width = 1 end + if g.width < 1 then g.width = 1 end if g.height < 1 then g.height = 1 end - c:geometry(g) + + p.geometries[c] = g -- Remaining clients stacked in slave column, new ones on top. - if #cls > 1 then - for i = 2,#cls do - c = cls[i] - g = {} - g.width = slavewid - current_offset_x - 2*c.border_width - g.height = wa.height - current_offset_y - 2*c.border_width - g.x = wa.x + mainwid + (how_many - (i - 1)) * cascade.tile.offset_x - g.y = wa.y + (i - 2) * cascade.tile.offset_y + if #cls <= 1 then return end + for i = 2,#cls do + c = cls[i] + g = {} - if useless_gap > 0 then - g.width = g.width - 2 * useless_gap - g.height = g.height - 2 * useless_gap - g.x = g.x + useless_gap - g.y = g.y + useless_gap - end + g.width = slavewid - current_offset_x + g.height = wa.height - current_offset_y - if g.width < 1 then g.width = 1 end - if g.height < 1 then g.height = 1 end + g.x = wa.x + mainwid + (how_many - (i - 1)) * cascade.tile.offset_x + g.y = wa.y + (i - 2) * cascade.tile.offset_y - c:geometry(g) - end + if g.width < 1 then g.width = 1 end + if g.height < 1 then g.height = 1 end + + p.geometries[c] = g end end end diff --git a/layout/centerwork.lua b/layout/centerwork.lua index a8d9a96..eafab78 100644 --- a/layout/centerwork.lua +++ b/layout/centerwork.lua @@ -10,9 +10,8 @@ --]] -local tonumber = tonumber -local math = { floor = math.floor } -local scr = require("awful.screen") +local floor = math.floor +local screen = screen local centerwork = { name = "centerwork", @@ -20,60 +19,54 @@ local centerwork = { } local function do_centerwork(p, orientation) - -- Screen. - local wa = p.workarea + local t = p.tag or screen[p.screen].selected_tag + local wa = p.workarea local cls = p.clients - local ta = scr.focused().selected_tag - if not ta then return end - - if #cls <= 0 then return end - - -- Useless gaps. - local useless_gap = p.useless_gap or 0 + if #cls == 0 then return end local c = cls[1] local g = {} -- Main column, fixed width and height. - local mwfact = ta.master_width_factor - local mainhei = math.floor(wa.height * mwfact) - local mainwid = math.floor(wa.width * mwfact) + local mwfact = t.master_width_factor + local mainhei = floor(wa.height * mwfact) + local mainwid = floor(wa.width * mwfact) local slavewid = wa.width - mainwid - local slaveLwid = math.floor(slavewid / 2) + local slaveLwid = floor(slavewid / 2) local slaveRwid = slavewid - slaveLwid local slavehei = wa.height - mainhei - local slaveThei = math.floor(slavehei / 2) + local slaveThei = floor(slavehei / 2) local slaveBhei = slavehei - slaveThei - local nbrFirstSlaves = math.floor(#cls / 2) - local nbrSecondSlaves = math.floor((#cls - 1) / 2) + local nbrFirstSlaves = floor(#cls / 2) + local nbrSecondSlaves = floor((#cls - 1) / 2) local slaveFirstDim, slaveSecondDim = 0, 0 if orientation == "vertical" then - if nbrFirstSlaves > 0 then slaveFirstDim = math.floor(wa.height / nbrFirstSlaves) end - if nbrSecondSlaves > 0 then slaveSecondDim = math.floor(wa.height / nbrSecondSlaves) end + if nbrFirstSlaves > 0 then slaveFirstDim = floor(wa.height / nbrFirstSlaves) end + if nbrSecondSlaves > 0 then slaveSecondDim = floor(wa.height / nbrSecondSlaves) end - g.height = wa.height - 2*useless_gap - 2*c.border_width - g.width = mainwid - 2*c.border_width + g.height = wa.height + g.width = mainwid g.x = wa.x + slaveLwid - g.y = wa.y + useless_gap + g.y = wa.y else - if nbrFirstSlaves > 0 then slaveFirstDim = math.floor(wa.width / nbrFirstSlaves) end - if nbrSecondSlaves > 0 then slaveSecondDim = math.floor(wa.width / nbrSecondSlaves) end + if nbrFirstSlaves > 0 then slaveFirstDim = floor(wa.width / nbrFirstSlaves) end + if nbrSecondSlaves > 0 then slaveSecondDim = floor(wa.width / nbrSecondSlaves) end - g.height = mainhei - 2*c.border_width - g.width = wa.width - 2*useless_gap - 2*c.border_width + g.height = mainhei + g.width = wa.width - g.x = wa.x + useless_gap + g.x = wa.x g.y = wa.y + slaveThei end if g.width < 1 then g.width = 1 end if g.height < 1 then g.height = 1 end - c:geometry(g) + p.geometries[c] = g -- Auxiliary windows. if #cls <= 1 then return end @@ -81,62 +74,62 @@ local function do_centerwork(p, orientation) local c = cls[i] local g = {} - local rowIndex = math.floor(i/2) + local rowIndex = floor(i/2) if orientation == "vertical" then if i % 2 == 0 then -- left slave - g.x = wa.x + useless_gap - g.y = wa.y + useless_gap + (rowIndex-1)*slaveFirstDim + g.x = wa.x + g.y = wa.y + (rowIndex-1)*slaveFirstDim - g.width = slaveLwid - 2*useless_gap - 2*c.border_width + 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 - useless_gap - 2*c.border_width + g.height = wa.y + wa.height - g.y else - g.height = slaveFirstDim - useless_gap - 2*c.border_width + g.height = slaveFirstDim end else -- right slave - g.x = wa.x + slaveLwid + mainwid + useless_gap - g.y = wa.y + useless_gap + (rowIndex-1)*slaveSecondDim + g.x = wa.x + slaveLwid + mainwid + g.y = wa.y + (rowIndex-1)*slaveSecondDim - g.width = slaveRwid - 2*useless_gap - 2*c.border_width + 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 - useless_gap - 2*c.border_width + g.height = wa.y + wa.height - g.y else - g.height = slaveSecondDim - useless_gap - 2*c.border_width + g.height = slaveSecondDim end end else if i % 2 == 0 then -- top slave - g.x = wa.x + useless_gap + (rowIndex-1)*slaveFirstDim - g.y = wa.y + useless_gap + g.x = wa.x + (rowIndex-1)*slaveFirstDim + g.y = wa.y - g.height = slaveThei - 2*useless_gap - 2*c.border_width + 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 - useless_gap - 2*c.border_width + g.width = wa.x + wa.width - g.x else - g.width = slaveFirstDim - useless_gap - 2*c.border_width + g.width = slaveFirstDim end else -- bottom slave - g.x = wa.x + useless_gap + (rowIndex-1)*slaveFirstDim - g.y = wa.y + slaveThei + mainhei + useless_gap + g.x = wa.x + (rowIndex-1)*slaveSecondDim + g.y = wa.y + slaveThei + mainhei - g.height = slaveBhei - 2*useless_gap - 2*c.border_width + 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 - useless_gap - 2*c.border_width + g.width = wa.x + wa.width - g.x else - g.width = slaveSecondDim - useless_gap - 2*c.border_width + g.width = slaveSecondDim end end @@ -145,7 +138,7 @@ local function do_centerwork(p, orientation) if g.width < 1 then g.width = 1 end if g.height < 1 then g.height = 1 end - c:geometry(g) + p.geometries[c] = g end end diff --git a/layout/termfair.lua b/layout/termfair.lua index 26a7130..33b7ffc 100644 --- a/layout/termfair.lua +++ b/layout/termfair.lua @@ -9,27 +9,21 @@ --]] -local scr = require("awful.screen") local math = { ceil = math.ceil, floor = math.floor, max = math.max } +local screen = screen local tonumber = tonumber local termfair = { name = "termfair" } termfair.center = { name = "centerfair" } local function do_fair(p, orientation) - -- Screen. - local wa = p.workarea + local t = p.tag or screen[p.screen].selected_tag + local wa = p.workarea local cls = p.clients - local ta = scr.focused().selected_tag - if not ta then return end - - if #cls <= 0 then return end - - -- Useless gaps. - local useless_gap = p.useless_gap or 0 + if #cls == 0 then return end if orientation == "west" then -- Layout with fixed number of vertical columns (read from nmaster). @@ -50,18 +44,16 @@ local function do_fair(p, orientation) -- | 3 | 2 | 1 | | 3 | 2 | 1 | | 3 | 2 | 1 | -- +---+---+---+ +---+---+---+ +---+---+---+ - if #cls <= 0 then return end - -- How many vertical columns? Read from nmaster on the tag. - local num_x = tonumber(termfair.nmaster) or ta.master_count - local ncol = tonumber(termfair.ncol) or ta.column_count + local num_x = tonumber(termfair.nmaster) or t.master_count + local ncol = tonumber(termfair.ncol) or t.column_count if num_x <= 2 then num_x = 2 end if ncol <= 1 then ncol = 1 end - local width = math.floor((wa.width - (num_x + 1)*useless_gap) / num_x) + local width = math.floor(wa.width/num_x) local num_y = math.max(math.ceil(#cls / num_x), ncol) - local height = math.floor((wa.height - (num_y + 1)*useless_gap) / num_y) + local height = math.floor(wa.height/num_y) local cur_num_x = num_x local at_x = 0 local at_y = 0 @@ -84,30 +76,24 @@ local function do_fair(p, orientation) -- Calculate geometry. local g = {} if this_x == (num_x - 1) then - g.width = wa.width - (num_x - 1)*width - (num_x + 1)*useless_gap - 2*c.border_width + g.width = wa.width - (num_x - 1)*width else - g.width = width - 2*c.border_width + g.width = width end if this_y == (num_y - 1) then - g.height = wa.height - (num_y - 1)*height - (num_y + 1)*useless_gap - 2*c.border_width + g.height = wa.height - (num_y - 1)*height else - g.height = height - 2*c.border_width + g.height = height end g.x = wa.x + this_x*width g.y = wa.y + this_y*height - if useless_gap > 0 then - -- All clients tile evenly. - g.x = g.x + (this_x + 1)*useless_gap - g.y = g.y + (this_y + 1)*useless_gap - end - - if g.width < 1 then g.width = 1 end + if g.width < 1 then g.width = 1 end if g.height < 1 then g.height = 1 end - c:geometry(g) + p.geometries[c] = g remaining_clients = remaining_clients - 1 @@ -146,100 +132,98 @@ local function do_fair(p, orientation) -- +---+---+---+ +---+---+---+ -- How many vertical columns? Read from nmaster on the tag. - local num_x = tonumber(termfair.center.nmaster) or ta.master_count - local ncol = tonumber(termfair.center.ncol) or ta.column_count + local num_x = tonumber(termfair.center.nmaster) or t.master_count + local ncol = tonumber(termfair.center.ncol) or t.column_count if num_x <= 2 then num_x = 2 end if ncol <= 1 then ncol = 1 end - local width = math.floor((wa.width - (num_x + 1)*useless_gap) / num_x) + local width = math.floor(wa.width / num_x) if #cls < num_x then -- Less clients than the number of columns, let's center it! - local offset_x = wa.x + (wa.width - #cls*width - (#cls - 1)*useless_gap) / 2 - local g = {} - g.y = wa.y + useless_gap + local offset_x = wa.x + (wa.width - #cls*width) / 2 for i = 1, #cls do - local c = cls[i] - g.width = width - 2*c.border_width - g.height = wa.height - 2*useless_gap - 2*c.border_width + local g = { y = wa.y } + g.width = width + g.height = wa.height if g.width < 1 then g.width = 1 end if g.height < 1 then g.height = 1 end - g.x = offset_x + (i - 1) * (width + useless_gap) - c:geometry(g) + g.x = offset_x + (i - 1) * width + p.geometries[cls[i]] = g end else -- More clients than the number of columns, let's arrange it! -- Master client deserves a special treatement - local c = cls[1] local g = {} - g.width = wa.width - (num_x - 1)*width - (num_x + 1)*useless_gap - 2*c.border_width - g.height = wa.height - 2*useless_gap - 2*c.border_width + g.width = wa.width - (num_x - 1)*width + g.height = wa.height if g.width < 1 then g.width = 1 end if g.height < 1 then g.height = 1 end - g.x = wa.x + useless_gap - g.y = wa.y + useless_gap - - c:geometry(g) + g.x = wa.x + g.y = wa.y + p.geometries[cls[1]] = g -- Treat the other clients -- Compute distribution of clients among columns - local num_y ={} - do - local remaining_clients = #cls-1 - local ncol_min = math.ceil(remaining_clients/(num_x-1)) - if ncol >= ncol_min then - for i = (num_x-1), 1, -1 do - if (remaining_clients-i+1) < ncol then - num_y[i] = remaining_clients-i + 1 - else - num_y[i] = ncol - end - remaining_clients = remaining_clients - num_y[i] + local num_y = {} + local remaining_clients = #cls-1 + local ncol_min = math.ceil(remaining_clients/(num_x-1)) + + if ncol >= ncol_min then + for i = (num_x-1), 1, -1 do + if (remaining_clients-i+1) < ncol then + num_y[i] = remaining_clients-i + 1 + else + num_y[i] = ncol + end + remaining_clients = remaining_clients - num_y[i] + end + else + local rem = remaining_clients % (num_x-1) + if rem == 0 then + for i = 1, num_x-1 do + num_y[i] = ncol_min end else - local rem = remaining_clients % (num_x-1) - if rem == 0 then - for i = 1, num_x-1 do - num_y[i] = ncol_min - end - else - for i = 1, num_x-1 do - num_y[i] = ncol_min - 1 - end - for i = 0, rem-1 do - num_y[num_x-1-i] = num_y[num_x-1-i] + 1 - end + for i = 1, num_x-1 do + num_y[i] = ncol_min - 1 + end + for i = 0, rem-1 do + num_y[num_x-1-i] = num_y[num_x-1-i] + 1 end end end -- Compute geometry of the other clients local nclient = 2 -- we start with the 2nd client - g.x = g.x + g.width + useless_gap + 2*c.border_width - + local wx = g.x + g.width for i = 1, (num_x-1) do - local height = math.floor((wa.height - (num_y[i] + 1)*useless_gap) / num_y[i]) - g.y = wa.y + useless_gap + local height = math.floor(wa.height / num_y[i]) + local wy = wa.y for j = 0, (num_y[i]-2) do - local c = cls[nclient] - g.height = height - 2*c.border_width - g.width = width - 2*c.border_width + local g = {} + g.x = wx + g.y = wy + g.height = height + g.width = width if g.width < 1 then g.width = 1 end if g.height < 1 then g.height = 1 end - c:geometry(g) + p.geometries[cls[nclient]] = g nclient = nclient + 1 - g.y = g.y + height + useless_gap + wy = wy + height end - local c = cls[nclient] - g.height = wa.height - (num_y[i] + 1)*useless_gap - (num_y[i] - 1)*height - 2*c.border_width - g.width = width - 2*c.border_width + local g = {} + g.x = wx + g.y = wy + g.height = wa.height - (num_y[i] - 1)*height + g.width = width if g.width < 1 then g.width = 1 end if g.height < 1 then g.height = 1 end - c:geometry(g) + p.geometries[cls[nclient]] = g nclient = nclient + 1 - g.x = g.x + width + useless_gap + wx = wx + width end end end From 229d2545dd399b52c6128a823657c6266fbbe8a9 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Thu, 26 Jan 2017 20:53:55 +0100 Subject: [PATCH 087/106] #293: eradicate proxy widget --- helpers.lua | 12 ++---------- widgets/abase.lua | 6 ++++-- widgets/alsa.lua | 4 ++-- widgets/base.lua | 4 ++-- widgets/bat.lua | 5 ++--- widgets/calendar.lua | 2 ++ widgets/contrib/gpmdp.lua | 4 +++- widgets/contrib/kbdlayout.lua | 4 +++- widgets/contrib/moc.lua | 4 +++- widgets/contrib/tpbat/init.lua | 4 ++-- widgets/cpu.lua | 6 +++--- widgets/fs.lua | 9 ++++----- widgets/imap.lua | 2 +- widgets/maildir.lua | 4 +++- widgets/mem.lua | 4 +++- widgets/mpd.lua | 4 +++- widgets/net.lua | 2 +- widgets/pulseaudio.lua | 4 +++- widgets/sysload.lua | 4 +++- widgets/temp.lua | 4 +++- widgets/weather.lua | 2 +- wiki | 2 +- 22 files changed, 54 insertions(+), 42 deletions(-) diff --git a/helpers.lua b/helpers.lua index 0305722..f32c4ad 100644 --- a/helpers.lua +++ b/helpers.lua @@ -7,6 +7,8 @@ --]] +local easy_async = require("awful.spawn").easy_async +local timer = require("gears.timer") local debug = require("debug") local io = { lines = io.lines, open = io.open, @@ -14,10 +16,6 @@ local io = { lines = io.lines, local rawget = rawget local table = { sort = table.sort } -local easy_async = require("awful.spawn").easy_async -local timer = require("gears.timer") -local wibox = require("wibox") - -- Lain helper functions for internal use -- lain.helpers local helpers = {} @@ -177,12 +175,6 @@ function helpers.spairs(t) end end --- create a lain textbox -function helpers.make_widget_textbox() - local w = { widget = wibox.widget.textbox() } - return setmetatable(w, { __index = w.widget }) -end - -- }}} return helpers diff --git a/widgets/abase.lua b/widgets/abase.lua index 1214151..409495b 100644 --- a/widgets/abase.lua +++ b/widgets/abase.lua @@ -14,14 +14,16 @@ local setmetatable = setmetatable -- lain.widgets.abase local function worker(args) - local abase = helpers.make_widget_textbox() + local abase = { widget = wibox.widget.textbox() } local args = args or {} local timeout = args.timeout or 5 local nostart = args.nostart or false local stoppable = args.stoppable or false - local cmd = args.cmd or "" + local cmd = args.cmd local settings = args.settings or function() end + abase.widget = wibox.widget.textbox() + function abase.update() helpers.async(cmd, function(f) output = f diff --git a/widgets/alsa.lua b/widgets/alsa.lua index 8139d42..f73194b 100644 --- a/widgets/alsa.lua +++ b/widgets/alsa.lua @@ -16,9 +16,9 @@ local setmetatable = setmetatable -- ALSA volume -- lain.widgets.alsa -local alsa = helpers.make_widget_textbox() local function worker(args) + local alsa = { widget = wibox.widget.textbox() } local args = args or {} local timeout = args.timeout or 5 local settings = args.settings or function() end @@ -53,4 +53,4 @@ local function worker(args) return alsa end -return setmetatable(alsa, { __call = function(_, ...) return worker(...) end }) +return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/base.lua b/widgets/base.lua index 9d7b710..2a8f507 100644 --- a/widgets/base.lua +++ b/widgets/base.lua @@ -14,12 +14,12 @@ local setmetatable = setmetatable -- lain.widgets.base local function worker(args) - local base = helpers.make_widget_textbox() + local base = { widget = wibox.widget.textbox() } local args = args or {} local timeout = args.timeout or 5 local nostart = args.nostart or false local stoppable = args.stoppable or false - local cmd = args.cmd or "" + local cmd = args.cmd local settings = args.settings or function() end function base.update() diff --git a/widgets/bat.lua b/widgets/bat.lua index 503c56e..e479fd9 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -8,7 +8,6 @@ --]] local first_line = require("lain.helpers").first_line -local make_widget = require("lain.helpers").make_widget_textbox local newtimer = require("lain.helpers").newtimer local naughty = require("naughty") local wibox = require("wibox") @@ -26,7 +25,7 @@ local setmetatable = setmetatable -- lain.widgets.bat local function worker(args) - local bat = make_widget() + local bat = { widget = wibox.widget.textbox() } local args = args or {} local timeout = args.timeout or 30 local batteries = args.batteries or (args.battery and {args.battery}) or {"BAT0"} @@ -176,7 +175,7 @@ local function worker(args) end newtimer("batteries", timeout, bat.update) - + return bat end diff --git a/widgets/calendar.lua b/widgets/calendar.lua index 892d954..032b1fb 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -24,6 +24,8 @@ function calendar.hide() end function calendar.show(t_out, inc_offset, scr) + calendar.hide() + local today = os.date("%d") local offs = inc_offset or 0 local f diff --git a/widgets/contrib/gpmdp.lua b/widgets/contrib/gpmdp.lua index 37da43d..94076c8 100644 --- a/widgets/contrib/gpmdp.lua +++ b/widgets/contrib/gpmdp.lua @@ -19,7 +19,7 @@ local setmetatable = setmetatable -- Google Play Music Desktop infos -- lain.widget.contrib.gpmdp -local gpmdp = helpers.make_widget_textbox() +local gpmdp = {} local function worker(args) local args = args or {} @@ -30,6 +30,8 @@ local function worker(args) os.getenv("HOME") .. "/.config/Google Play Music Desktop Player/json_store/playback.json" local settings = args.settings or function() end + gpmdp.widget = wibox.widget.textbox() + gpmdp_notification_preset = { title = "Now playing", timeout = 6 diff --git a/widgets/contrib/kbdlayout.lua b/widgets/contrib/kbdlayout.lua index 8132c77..08e7bd0 100644 --- a/widgets/contrib/kbdlayout.lua +++ b/widgets/contrib/kbdlayout.lua @@ -16,7 +16,7 @@ local setmetatable = setmetatable -- Keyboard layout switcher -- lain.widgets.contrib.kblayout -local kbdlayout = helpers.make_widget_textbox() +local kbdlayout = {} local function worker(args) local args = args or {} @@ -28,6 +28,8 @@ local function worker(args) if args.add_us_secondary == false then add_us_secondary = false end + kbdlayout.widget = wibox.widget.textbox() + local function kbd_run_settings(layout, variant) kbdlayout_now = { layout = string.match(layout, "[^,]+"), -- Make sure to match the primary layout only. diff --git a/widgets/contrib/moc.lua b/widgets/contrib/moc.lua index 3566985..6fe96a1 100644 --- a/widgets/contrib/moc.lua +++ b/widgets/contrib/moc.lua @@ -19,7 +19,7 @@ local setmetatable = setmetatable -- MOC audio player -- lain.widgets.contrib.moc -local moc = helpers.make_widget_textbox() +local moc = {} local function worker(args) local args = args or {} @@ -31,6 +31,8 @@ local function worker(args) local followtag = args.followtag or false local settings = args.settings or function() end + moc.widget = wibox.widget.textbox() + moc_notification_preset = { title = "Now playing", timeout = 6 } helpers.set_map("current moc track", nil) diff --git a/widgets/contrib/tpbat/init.lua b/widgets/contrib/tpbat/init.lua index 32a2527..e65cde8 100644 --- a/widgets/contrib/tpbat/init.lua +++ b/widgets/contrib/tpbat/init.lua @@ -28,7 +28,7 @@ local smapi = require("smapi") -- ThinkPad SMAPI-enabled battery info widget -- lain.widgets.contrib.tpbat -local tpbat = { } +local tpbat = {} function tpbat.hide() if not tpbat.notification then return end @@ -39,7 +39,7 @@ end function tpbat.show(t_out) tpbat.hide() - local bat = tpbat.bat + local bat = tpbat.bat if bat == nil or not bat:installed() then return end diff --git a/widgets/cpu.lua b/widgets/cpu.lua index f61e2cc..79f99af 100644 --- a/widgets/cpu.lua +++ b/widgets/cpu.lua @@ -17,14 +17,14 @@ local setmetatable = setmetatable -- CPU usage -- lain.widgets.cpu -local cpu = helpers.make_widget_textbox() +local cpu = { core = {} } local function worker(args) local args = args or {} local timeout = args.timeout or 2 local settings = args.settings or function() end - cpu.core = {} + cpu.widget = wibox.widget.textbox() function update() -- Read the amount of time the CPUs have spent performing @@ -67,9 +67,9 @@ local function worker(args) end end - widget = cpu.widget cpu_now = cpu.core cpu_now.usage = cpu_now[0].usage + widget = cpu.widget settings() end diff --git a/widgets/fs.lua b/widgets/fs.lua index efd31fb..c78b6cb 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -20,10 +20,7 @@ local setmetatable = setmetatable -- File system disk space usage -- lain.widgets.fs -local fs = helpers.make_widget_textbox() - --- Unit definitions -fs.unit = { ["mb"] = 1024, ["gb"] = 1024^2 } +local fs = { unit = { ["mb"] = 1024, ["gb"] = 1024^2 } } function fs.hide() if not fs.notification then return end @@ -68,6 +65,8 @@ local function worker(args) } end + fs.widget = wibox.widget.textbox() + helpers.set_map(partition, false) function fs.update() @@ -125,7 +124,7 @@ local function worker(args) helpers.newtimer(partition, timeout, fs.update) - return setmetatable(fs, { __index = fs.widget }) + return fs end return setmetatable(fs, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/imap.lua b/widgets/imap.lua index 770a1bc..95d35fd 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -19,7 +19,7 @@ local setmetatable = setmetatable -- lain.widgets.imap local function worker(args) - local imap = helpers.make_widget_textbox() + local imap = { widget = wibox.widget.textbox() } local args = args or {} local server = args.server local mail = args.mail diff --git a/widgets/maildir.lua b/widgets/maildir.lua index 7e7b246..f7dfd28 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -18,7 +18,7 @@ local setmetatable = setmetatable -- Maildir check (synchronous) -- lain.widgets.maildir -local maildir = helpers.make_widget_textbox() +local maildir = {} local function worker(args) local args = args or {} @@ -28,6 +28,8 @@ local function worker(args) local settings = args.settings or function() end local cmd = args.cmd + maildir.widget = wibox.widget.textbox() + function maildir.update() if cmd then helpers.async({ awful.util.shell, "-c", cmd }, function() end) end diff --git a/widgets/mem.lua b/widgets/mem.lua index ff5816c..2b414ef 100644 --- a/widgets/mem.lua +++ b/widgets/mem.lua @@ -16,13 +16,15 @@ local setmetatable = setmetatable -- Memory usage (ignoring caches) -- lain.widgets.mem -local mem = helpers.make_widget_textbox() +local mem = {} local function worker(args) local args = args or {} local timeout = args.timeout or 2 local settings = args.settings or function() end + mem.widget = wibox.widget.textbox() + function update() mem_now = {} for line in lines("/proc/meminfo") do diff --git a/widgets/mpd.lua b/widgets/mpd.lua index d92c78f..c4c4691 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -21,7 +21,7 @@ local setmetatable = setmetatable -- MPD infos -- lain.widgets.mpd -local mpd = helpers.make_widget_textbox() +local mpd = {} local function worker(args) local args = args or {} @@ -41,6 +41,8 @@ local function worker(args) local echo = string.format("printf \"%sstatus\\ncurrentsong\\nclose\\n\"", password) local cmd = string.format("%s | curl --connect-timeout 1 -fsm 3 %s", echo, mpdh) + mpd.widget = wibox.widget.textbox() + mpd_notification_preset = { title = "Now playing", timeout = 6 } helpers.set_map("current mpd track", nil) diff --git a/widgets/net.lua b/widgets/net.lua index 302559a..1dfef43 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -18,7 +18,7 @@ local setmetatable = setmetatable -- lain.widgets.net local function worker(args) - local net = helpers.make_widget_textbox() + local net = { widget = wibox.widget.textbox() } net.last_t = 0 net.last_r = 0 net.devices = {} diff --git a/widgets/pulseaudio.lua b/widgets/pulseaudio.lua index 8e89ffd..68d3066 100644 --- a/widgets/pulseaudio.lua +++ b/widgets/pulseaudio.lua @@ -16,7 +16,7 @@ local setmetatable = setmetatable -- PulseAudio volume -- lain.widgets.pulseaudio -local pulseaudio = helpers.make_widget_textbox() +local pulseaudio = {} local function worker(args) local args = args or {} @@ -26,6 +26,8 @@ local function worker(args) pulseaudio.cmd = args.cmd or "pacmd list-sinks | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'" + pulseaudio.widget = wibox.widget.textbox() + function pulseaudio.update() if scallback then pulseaudio.cmd = scallback() end diff --git a/widgets/sysload.lua b/widgets/sysload.lua index 148319d..49f640c 100644 --- a/widgets/sysload.lua +++ b/widgets/sysload.lua @@ -15,13 +15,15 @@ local setmetatable = setmetatable -- System load -- lain.widgets.sysload -local sysload = helpers.make_widget_textbox() +local sysload = {} local function worker(args) local args = args or {} local timeout = args.timeout or 2 local settings = args.settings or function() end + sysload.widget = wibox.widget.textbox() + function update() local f = io.open("/proc/loadavg") local ret = f:read("*all") diff --git a/widgets/temp.lua b/widgets/temp.lua index 4d8a727..9f41fdb 100644 --- a/widgets/temp.lua +++ b/widgets/temp.lua @@ -14,7 +14,7 @@ local setmetatable = setmetatable -- coretemp -- lain.widgets.temp -local temp = helpers.make_widget_textbox() +local temp = {} local function worker(args) local args = args or {} @@ -22,6 +22,8 @@ local function worker(args) local tempfile = args.tempfile or "/sys/class/thermal/thermal_zone0/temp" local settings = args.settings or function() end + temp.widget = wibox.widget.textbox() + function update() local f = io.open(tempfile) if f then diff --git a/widgets/weather.lua b/widgets/weather.lua index 9f83dc8..febd73b 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -25,7 +25,7 @@ local setmetatable = setmetatable -- lain.widgets.weather local function worker(args) - local weather = helpers.make_widget_textbox() + local weather = { widget = wibox.widget.textbox() } local args = args or {} local APPID = args.APPID or "3e321f9414eaedbfab34983bda77a66e" -- lain default local timeout = args.timeout or 900 -- 15 min diff --git a/wiki b/wiki index 0af22b8..ed824be 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 0af22b80f8dda896a0c8fefd5c7e52413294967d +Subproject commit ed824beb75262f9f78e49baa6e1a591220ca5249 From ae4b9b272802c0690b711644508d63a538a3e1cd Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Fri, 27 Jan 2017 14:35:27 +0100 Subject: [PATCH 088/106] wiki enhanced --- widgets/contrib/tpbat/init.lua | 6 +++--- widgets/cpu.lua | 4 ++-- widgets/mem.lua | 4 ++-- widgets/net.lua | 4 +--- widgets/sysload.lua | 4 ++-- widgets/temp.lua | 4 ++-- wiki | 2 +- 7 files changed, 13 insertions(+), 15 deletions(-) diff --git a/widgets/contrib/tpbat/init.lua b/widgets/contrib/tpbat/init.lua index e65cde8..20a10f4 100644 --- a/widgets/contrib/tpbat/init.lua +++ b/widgets/contrib/tpbat/init.lua @@ -108,7 +108,7 @@ function tpbat.register(args) }) end - function update() + function tpbat.update() bat_now = { status = "Not present", perc = "N/A", @@ -151,12 +151,12 @@ function tpbat.register(args) settings() end - newtimer("tpbat-" .. bat.name, timeout, update) + newtimer("tpbat-" .. bat.name, timeout, tpbat.update) widget:connect_signal('mouse::enter', function () tpbat.show() end) widget:connect_signal('mouse::leave', function () tpbat.hide() end) - return tpbat.widget + return tpbat end return setmetatable(tpbat, { __call = function(_, ...) return tpbat.register(...) end }) diff --git a/widgets/cpu.lua b/widgets/cpu.lua index 79f99af..076b692 100644 --- a/widgets/cpu.lua +++ b/widgets/cpu.lua @@ -26,7 +26,7 @@ local function worker(args) cpu.widget = wibox.widget.textbox() - function update() + function cpu.update() -- Read the amount of time the CPUs have spent performing -- different kinds of work. Read the first line of /proc/stat -- which is the sum of all CPUs. @@ -74,7 +74,7 @@ local function worker(args) settings() end - helpers.newtimer("cpu", timeout, update) + helpers.newtimer("cpu", timeout, cpu.update) return cpu end diff --git a/widgets/mem.lua b/widgets/mem.lua index 2b414ef..7b717ef 100644 --- a/widgets/mem.lua +++ b/widgets/mem.lua @@ -25,7 +25,7 @@ local function worker(args) mem.widget = wibox.widget.textbox() - function update() + function mem.update() mem_now = {} for line in lines("/proc/meminfo") do for k, v in gmatch(line, "([%a]+):[%s]+([%d]+).+") do @@ -48,7 +48,7 @@ local function worker(args) settings() end - helpers.newtimer("mem", timeout, update) + helpers.newtimer("mem", timeout, mem.update) return mem end diff --git a/widgets/net.lua b/widgets/net.lua index 1dfef43..223f3af 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -97,12 +97,10 @@ local function worker(args) helpers.set_map(dev, true) end - -- Old api compatibility net_now.carrier = dev_now.carrier net_now.state = dev_now.state - -- And new api net_now.devices[dev] = dev_now - -- With the new api new_now.sent and net_now.received will be the + -- new_now.sent and net_now.received will be the -- totals across all specified devices end diff --git a/widgets/sysload.lua b/widgets/sysload.lua index 49f640c..df9dbea 100644 --- a/widgets/sysload.lua +++ b/widgets/sysload.lua @@ -24,7 +24,7 @@ local function worker(args) sysload.widget = wibox.widget.textbox() - function update() + function sysload.update() local f = io.open("/proc/loadavg") local ret = f:read("*all") f:close() @@ -35,7 +35,7 @@ local function worker(args) settings() end - helpers.newtimer("sysload", timeout, update) + helpers.newtimer("sysload", timeout, sysload.update) return sysload end diff --git a/widgets/temp.lua b/widgets/temp.lua index 9f41fdb..1c7e86c 100644 --- a/widgets/temp.lua +++ b/widgets/temp.lua @@ -24,7 +24,7 @@ local function worker(args) temp.widget = wibox.widget.textbox() - function update() + function temp.update() local f = io.open(tempfile) if f then coretemp_now = tonumber(f:read("*all")) / 1000 @@ -37,7 +37,7 @@ local function worker(args) settings() end - helpers.newtimer("coretemp", timeout, update) + helpers.newtimer("coretemp", timeout, temp.update) return temp end diff --git a/wiki b/wiki index ed824be..425169b 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit ed824beb75262f9f78e49baa6e1a591220ca5249 +Subproject commit 425169b35b105e5a240997ff8f5aa12bec6099cb From 83b96b3c3ada021e47d6ef1ad48c03710f0dc24a Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Fri, 27 Jan 2017 14:59:31 +0100 Subject: [PATCH 089/106] wipe away beautiful reference --- util/init.lua | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/util/init.lua b/util/init.lua index c62f0da..2f9e14a 100644 --- a/util/init.lua +++ b/util/init.lua @@ -13,14 +13,10 @@ --]] local awful = require("awful") -local beautiful = require("beautiful") -local math = { sqrt = math.sqrt } +local sqrt = math.sqrt local pairs = pairs -local string = { gsub = string.gsub } local client = client -local screen = screen local tonumber = tonumber - local wrequire = require("lain.helpers").wrequire local setmetatable = setmetatable @@ -89,10 +85,10 @@ function util.mc(c) c.floating = true local s = awful.screen.focused() local mg = s.geometry - local mwfact = beautiful.master_width_factor or 0.5 + local mwfact = s.selected_tag.master_width_factor or 0.5 local g = {} - g.width = math.sqrt(mwfact) * mg.width - g.height = math.sqrt(mwfact) * mg.height + g.width = sqrt(mwfact) * mg.width + g.height = sqrt(mwfact) * mg.height g.x = mg.x + (mg.width - g.width) / 2 g.y = mg.y + (mg.height - g.height) / 2 @@ -165,9 +161,9 @@ end -- On the fly useless gaps change function util.useless_gaps_resize(thatmuch) - beautiful.useless_gap = beautiful.useless_gap or 0 - beautiful.useless_gap = tonumber(beautiful.useless_gap) + thatmuch - awful.layout.arrange(awful.screen.focused()) + local scr = awful.screen.focused() + scr.selected_tag.gap = scr.selected_tag.gap + thatmuch + awful.layout.arrange(scr) end return setmetatable(util, { __index = wrequire }) From 555b872d16393774089df3b3453000571a73a3dd Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Fri, 27 Jan 2017 22:01:48 +0100 Subject: [PATCH 090/106] maildir: turned into an abase example --- util/init.lua | 2 +- widgets/maildir.lua | 84 --------------------------------------------- wiki | 2 +- 3 files changed, 2 insertions(+), 86 deletions(-) delete mode 100644 widgets/maildir.lua diff --git a/util/init.lua b/util/init.lua index 2f9e14a..25470e4 100644 --- a/util/init.lua +++ b/util/init.lua @@ -162,7 +162,7 @@ end -- On the fly useless gaps change function util.useless_gaps_resize(thatmuch) local scr = awful.screen.focused() - scr.selected_tag.gap = scr.selected_tag.gap + thatmuch + scr.selected_tag.gap = scr.selected_tag.gap + tonumber(thatmuch) awful.layout.arrange(scr) end diff --git a/widgets/maildir.lua b/widgets/maildir.lua deleted file mode 100644 index f7dfd28..0000000 --- a/widgets/maildir.lua +++ /dev/null @@ -1,84 +0,0 @@ - ---[[ - - Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham - * (c) 2010-2012, Peter Hofmann - ---]] - -local awful = require("awful") -local wibox = require("wibox") -local helpers = require("lain.helpers") -local io = { popen = io.popen } -local os = { getenv = os.getenv } -local string = { format = string.format, - match = string.match } -local setmetatable = setmetatable - --- Maildir check (synchronous) --- lain.widgets.maildir -local maildir = {} - -local function worker(args) - local args = args or {} - local timeout = args.timeout or 60 - local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail" - local ignore_boxes = args.ignore_boxes or {} - local settings = args.settings or function() end - local cmd = args.cmd - - maildir.widget = wibox.widget.textbox() - - function maildir.update() - if cmd then helpers.async({ awful.util.shell, "-c", cmd }, function() end) end - - -- Find pathes to mailboxes. - local p = io.popen(string.format("find %s -mindepth 1 -maxdepth 2 -type d -not -name .git", mailpath)) - local boxes = {} - repeat - line = p:read("*l") - if line then - -- Find all files in the "new" subdirectory. For each - -- file, print a single character (no newline). Don't - -- match files that begin with a dot. - -- Afterwards the length of this string is the number of - -- new mails in that box. - local mailstring = helpers.read_pipe(string.format("find %s /new -mindepth 1 -type f -not -name '.*' -printf a", line)) - - -- Strip off leading mailpath. - local box = string.match(line, mailpath .. "/(.*)") - local nummails = #mailstring - - if nummails > 0 then - boxes[box] = nummails - end - end - until not line - p:close() - - local newmail = "no mail" - local total = 0 - - for box, number in helpers.spairs(boxes) do - -- Add this box only if it's not to be ignored. - if not helpers.element_in_table(box, ignore_boxes) then - total = total + number - if newmail == "no mail" then - newmail = string.format("%s(%s)", box, number) - else - newmail = string.format("%s, %s(%s)", newmail, box, number) - end - end - end - - widget = maildir.widget - settings() - end - - maildir.timer = helpers.newtimer(mailpath, timeout, maildir.update, true, true) - - return maildir -end - -return setmetatable(maildir, { __call = function(_, ...) return worker(...) end }) diff --git a/wiki b/wiki index 425169b..2fb160f 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 425169b35b105e5a240997ff8f5aa12bec6099cb +Subproject commit 2fb160f6c19483150110cb6fa2d6567cc3581a85 From 1b428513fdede06ef54679edbfd267534f49659e Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sat, 28 Jan 2017 15:40:19 +0100 Subject: [PATCH 091/106] calendar: separate args from attach; closes #294 --- widgets/calendar.lua | 36 ++++++++++++++++++++---------------- wiki | 2 +- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/widgets/calendar.lua b/widgets/calendar.lua index 032b1fb..fbf8194 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -13,7 +13,9 @@ local naughty = require("naughty") local os = { date = os.date } local string = { format = string.format, gsub = string.gsub } +local ipairs = ipairs local tonumber = tonumber +local setmetatable = setmetatable -- Calendar notification -- lain.widgets.calendar @@ -24,8 +26,6 @@ function calendar.hide() end function calendar.show(t_out, inc_offset, scr) - calendar.hide() - local today = os.date("%d") local offs = inc_offset or 0 local f @@ -67,6 +67,7 @@ function calendar.show(t_out, inc_offset, scr) helpers.async(f, function(ws) fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg ws = ws:gsub("%c%[%d+[m]?%d+%c%[%d+[m]?", markup.bold(markup.color(bg, fg, today))) + calendar.hide() calendar.id = naughty.notify({ replaces_id = calendar.id, preset = calendar.notification_preset, @@ -77,9 +78,23 @@ function calendar.show(t_out, inc_offset, scr) end) end -function calendar.attach(widget, args) +function calendar.attach(widget) + widget:connect_signal("mouse::enter", function () calendar.show(0) end) + widget:connect_signal("mouse::leave", function () calendar.hide() end) + widget:buttons(awful.util.table.join(awful.button({ }, 1, function () + calendar.show(0, -1, calendar.scr_pos) end), + awful.button({ }, 3, function () + calendar.show(0, 1, calendar.scr_pos) end), + awful.button({ }, 4, function () + calendar.show(0, -1, calendar.scr_pos) end), + awful.button({ }, 5, function () + calendar.show(0, 1, calendar.scr_pos) end))) +end + +local function worker(args) local args = args or {} calendar.cal = args.cal or "/usr/bin/cal --color=always" + calendar.attach_to = args.attach_to or {} calendar.followtag = args.followtag or false calendar.icons = args.icons or helpers.icons_dir .. "cal/white/" calendar.notification_preset = args.notification_preset @@ -92,18 +107,7 @@ function calendar.attach(widget, args) } end - if widget then - widget:connect_signal("mouse::enter", function () calendar.show(0) end) - widget:connect_signal("mouse::leave", function () calendar.hide() end) - widget:buttons(awful.util.table.join(awful.button({ }, 1, function () - calendar.show(0, -1, calendar.scr_pos) end), - awful.button({ }, 3, function () - calendar.show(0, 1, calendar.scr_pos) end), - awful.button({ }, 4, function () - calendar.show(0, -1, calendar.scr_pos) end), - awful.button({ }, 5, function () - calendar.show(0, 1, calendar.scr_pos) end))) - end + for i, widget in ipairs(calendar.attach_to) do calendar.attach(widget) end end -return calendar +return setmetatable(calendar, { __call = function(_, ...) return worker(...) end }) diff --git a/wiki b/wiki index 2fb160f..b7585bf 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 2fb160f6c19483150110cb6fa2d6567cc3581a85 +Subproject commit b7585bf6af0c68ed17ec35e880d963ba4e307620 From 08b9a76662135b39da0f8aed35aa78932e1b43da Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sat, 28 Jan 2017 21:21:34 +0100 Subject: [PATCH 092/106] wiki updated --- wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiki b/wiki index b7585bf..3216fb7 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit b7585bf6af0c68ed17ec35e880d963ba4e307620 +Subproject commit 3216fb787a4cb3fbefd8549b2e1323f9412e788e From 19a7003b34b82423760f9187dad9e4675995ac57 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sat, 28 Jan 2017 23:35:27 +0100 Subject: [PATCH 093/106] markup: added fontfg and fontbg --- util/markup.lua | 10 ++++++++++ wiki | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/util/markup.lua b/util/markup.lua index 346cfe1..0d3b17a 100644 --- a/util/markup.lua +++ b/util/markup.lua @@ -44,6 +44,16 @@ function markup.color(fg, bg, text) return string.format('%s', fg, bg, text) end +-- Set font and foreground. +function markup.fontfg(font, fg, text) + return string.format('%s', font, fg, text) +end + +-- Set font and background. +function markup.fontbg(font, bg, text) + return string.format('%s', font, bg, text) +end + -- Set font, foreground and background. function markup.fontcolor(font, fg, bg, text) return string.format('%s', font, fg, bg, text) diff --git a/wiki b/wiki index 3216fb7..52bb0c1 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 3216fb787a4cb3fbefd8549b2e1323f9412e788e +Subproject commit 52bb0c1757addd08ca4de6b7c02444b32a9497ef From 2e5d0fbabcdaaeff9937c06e1db095569327957b Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sun, 29 Jan 2017 13:48:25 +0100 Subject: [PATCH 094/106] #289 fix attempt --- widgets/calendar.lua | 11 ++++++----- wiki | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/widgets/calendar.lua b/widgets/calendar.lua index fbf8194..0793bc0 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -22,7 +22,9 @@ local setmetatable = setmetatable local calendar = { offset = 0 } function calendar.hide() - naughty.destroy(naughty.getById(calendar.id)) + if not calendar.notification then return end + naughty.destroy(calendar.notification) + calendar.notification = nil end function calendar.show(t_out, inc_offset, scr) @@ -68,13 +70,12 @@ function calendar.show(t_out, inc_offset, scr) fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg ws = ws:gsub("%c%[%d+[m]?%d+%c%[%d+[m]?", markup.bold(markup.color(bg, fg, today))) calendar.hide() - calendar.id = naughty.notify({ - replaces_id = calendar.id, + calendar.notification = naughty.notify({ preset = calendar.notification_preset, text = ws:gsub("\n*$", ""), icon = calendar.notify_icon, - timeout = t_out or calendar.notification.preset.timeout or 5 - }).id + timeout = t_out or calendar.notification_preset.timeout or 5 + }) end) end diff --git a/wiki b/wiki index 52bb0c1..eb6bd5b 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 52bb0c1757addd08ca4de6b7c02444b32a9497ef +Subproject commit eb6bd5b9ca0b333864322bcb585b53dc6b026199 From f914e6411e53186843ad628e321d6ada2f128466 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sun, 29 Jan 2017 14:45:15 +0100 Subject: [PATCH 095/106] base: removed --- helpers.lua | 13 +------------ widgets/abase.lua | 10 +++++----- widgets/base.lua | 39 --------------------------------------- wiki | 2 +- 4 files changed, 7 insertions(+), 57 deletions(-) delete mode 100644 widgets/base.lua diff --git a/helpers.lua b/helpers.lua index f32c4ad..4e5ce1f 100644 --- a/helpers.lua +++ b/helpers.lua @@ -11,8 +11,7 @@ local easy_async = require("awful.spawn").easy_async local timer = require("gears.timer") local debug = require("debug") local io = { lines = io.lines, - open = io.open, - popen = io.popen } + open = io.open } local rawget = rawget local table = { sort = table.sort } @@ -108,16 +107,6 @@ end -- {{{ Pipe operations --- return the full output of an input command (synchronous pipe) --- @param cmd the input command --- @return command output (string) -function helpers.read_pipe(cmd) - local f = io.popen(cmd) - local output = f:read("*all") - f:close() - return output -end - -- run a command and execute a function on its output (asynchronous pipe) -- @param cmd the input command -- @param callback function to execute on cmd output diff --git a/widgets/abase.lua b/widgets/abase.lua index 409495b..300cc1b 100644 --- a/widgets/abase.lua +++ b/widgets/abase.lua @@ -7,22 +7,22 @@ --]] local helpers = require("lain.helpers") -local wibox = require("wibox") +local textbox = require("wibox.widget.textbox") local setmetatable = setmetatable --- Basic template for custom widgets (asynchronous version) +-- Template for custom asynchronous widgets -- lain.widgets.abase local function worker(args) - local abase = { widget = wibox.widget.textbox() } + local abase = {} local args = args or {} local timeout = args.timeout or 5 local nostart = args.nostart or false local stoppable = args.stoppable or false local cmd = args.cmd - local settings = args.settings or function() end + local settings = args.settings or function() widget:set_text(output) end - abase.widget = wibox.widget.textbox() + abase.widget = args.widget or textbox() function abase.update() helpers.async(cmd, function(f) diff --git a/widgets/base.lua b/widgets/base.lua deleted file mode 100644 index 2a8f507..0000000 --- a/widgets/base.lua +++ /dev/null @@ -1,39 +0,0 @@ - ---[[ - - Licensed under GNU General Public License v2 - * (c) 2014, Luke Bonham - ---]] - -local helpers = require("lain.helpers") -local wibox = require("wibox") -local setmetatable = setmetatable - --- Basic template for custom widgets --- lain.widgets.base - -local function worker(args) - local base = { widget = wibox.widget.textbox() } - local args = args or {} - local timeout = args.timeout or 5 - local nostart = args.nostart or false - local stoppable = args.stoppable or false - local cmd = args.cmd - local settings = args.settings or function() end - - function base.update() - output = helpers.read_pipe(cmd) - if output ~= base.prev then - widget = base.widget - settings() - base.prev = output - end - end - - base.timer = helpers.newtimer(cmd, timeout, base.update, nostart, stoppable) - - return base -end - -return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/wiki b/wiki index eb6bd5b..33fae84 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit eb6bd5b9ca0b333864322bcb585b53dc6b026199 +Subproject commit 33fae84ccc501b01b3a8e170eacc87a50364ea56 From 87a32771d6f16b190d268338c265aa5c53e8856d Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sun, 29 Jan 2017 14:46:54 +0100 Subject: [PATCH 096/106] wiki updated --- wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiki b/wiki index 33fae84..4985854 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 33fae84ccc501b01b3a8e170eacc87a50364ea56 +Subproject commit 4985854c1f705ef7144008cad046af122c5e9a71 From a297ea530f31a0b7824e1ab630d31786de6ab22f Mon Sep 17 00:00:00 2001 From: 2009 Date: Mon, 30 Jan 2017 20:38:04 +1000 Subject: [PATCH 097/106] Bugfix markup was not defined --- widgets/contrib/task.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/widgets/contrib/task.lua b/widgets/contrib/task.lua index afc9f93..ce4c49f 100644 --- a/widgets/contrib/task.lua +++ b/widgets/contrib/task.lua @@ -7,6 +7,7 @@ --]] local helpers = require("lain.helpers") +local markup = require("lain.util").markup local awful = require("awful") local naughty = require("naughty") local string = { format = string.format, gsub = string.gsub } From 9a8cfdb7d13ac9e38ccd7f613dd55ee529eb1ce3 Mon Sep 17 00:00:00 2001 From: 2009 Date: Mon, 30 Jan 2017 20:55:45 +1000 Subject: [PATCH 098/106] Fix typo so notification_preset can be overidden --- widgets/contrib/task.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/contrib/task.lua b/widgets/contrib/task.lua index afc9f93..fedfffb 100644 --- a/widgets/contrib/task.lua +++ b/widgets/contrib/task.lua @@ -32,7 +32,7 @@ function task.show(scr) helpers.async(task.show_cmd, function(f) task.notification = naughty.notify({ - preset = task_notification_preset, + preset = task.notification_preset, title = task.show_cmd, text = markup.font(task.notification_preset.font, awful.util.escape(f:gsub("\n*$", ""))) From b1a089633c0f1ac951c754b2e67b194b7f733413 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 31 Jan 2017 17:31:12 +0100 Subject: [PATCH 099/106] fix #298 --- util/init.lua | 5 ++--- widgets/fs.lua | 4 ++-- wiki | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/util/init.lua b/util/init.lua index 25470e4..9c4dc06 100644 --- a/util/init.lua +++ b/util/init.lua @@ -141,11 +141,10 @@ end -- pos in {-1, 1} <-> {previous, next} tag position function util.move_tag(pos) local tag = awful.screen.focused().selected_tag - local idx = awful.tag.getidx(tag) if tonumber(pos) <= -1 then - awful.tag.move(idx - 1, tag) + awful.tag.move(tag.index - 1, tag) else - awful.tag.move(idx + 1, tag) + awful.tag.move(tag.index + 1, tag) end end diff --git a/widgets/fs.lua b/widgets/fs.lua index c78b6cb..ec87191 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -71,7 +71,7 @@ local function worker(args) function fs.update() fs_info, fs_now = {}, {} - helpers.async({ shell, "-c", "LC_ALL=C df -k --output=target,size,used,avail,pcent" }, function(f) + 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 @@ -99,7 +99,7 @@ local function worker(args) widget = fs.widget settings() - if notify == "on" and tonumber(fs_now.used) >= 99 and not helpers.get_map(partition) then + if notify == "on" and #fs_now.used > 0 and tonumber(fs_now.used) >= 99 and not helpers.get_map(partition) then naughty.notify({ preset = naughty.config.presets.critical, title = "Warning", diff --git a/wiki b/wiki index 4985854..68d3942 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 4985854c1f705ef7144008cad046af122c5e9a71 +Subproject commit 68d3942ccfa41feb7496655e548ee46984b9ea5b From b14eff9b1e5558b3d3ea47d5e6ac9d6db3d265de Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Tue, 31 Jan 2017 17:42:29 +0100 Subject: [PATCH 100/106] cal: remove os-dependent flag; #299 #300 --- widgets/calendar.lua | 2 +- wiki | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/widgets/calendar.lua b/widgets/calendar.lua index 0793bc0..17fc45d 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -94,7 +94,7 @@ end local function worker(args) local args = args or {} - calendar.cal = args.cal or "/usr/bin/cal --color=always" + calendar.cal = args.cal or "/usr/bin/cal" calendar.attach_to = args.attach_to or {} calendar.followtag = args.followtag or false calendar.icons = args.icons or helpers.icons_dir .. "cal/white/" diff --git a/wiki b/wiki index 68d3942..6261aca 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 68d3942ccfa41feb7496655e548ee46984b9ea5b +Subproject commit 6261aca684a439466c763902833d169401462a5b From 91569eb5b4ffb200f3f68baaabcd42af32d13674 Mon Sep 17 00:00:00 2001 From: 2009 Date: Wed, 1 Feb 2017 19:08:55 +1000 Subject: [PATCH 101/106] Fix calender widget not highlighting date - os.date was returning the day as 01 which meant the calendar icon was looking for 01.png instead of 1.png - looks like the cal command pads the singe didgets which the gsub didn't account for --- widgets/calendar.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/widgets/calendar.lua b/widgets/calendar.lua index 17fc45d..ef6c5e7 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -38,7 +38,7 @@ function calendar.show(t_out, inc_offset, scr) if current_month then -- today highlighted calendar.offset = 0 - calendar.notify_icon = string.format("%s%s.png", calendar.icons, today) + calendar.notify_icon = string.format("%s%s.png", calendar.icons, tonumber(today)) f = calendar.cal else -- no current month showing, no day to highlight local month = tonumber(os.date("%m")) @@ -68,7 +68,7 @@ function calendar.show(t_out, inc_offset, scr) helpers.async(f, function(ws) fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg - ws = ws:gsub("%c%[%d+[m]?%d+%c%[%d+[m]?", markup.bold(markup.color(bg, fg, today))) + ws = ws:gsub("%c%[+%d+[m]?%s?%d+%c%[+%d+[m]?", markup.bold(markup.color(bg, fg, today:gsub("^0", " ")))) calendar.hide() calendar.notification = naughty.notify({ preset = calendar.notification_preset, From 1555e239eb42953d6d16b04f09d4d19083fa5119 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 1 Feb 2017 12:18:11 +0100 Subject: [PATCH 102/106] fix #300 --- widgets/calendar.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/widgets/calendar.lua b/widgets/calendar.lua index ef6c5e7..02f34ce 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -28,7 +28,7 @@ function calendar.hide() end function calendar.show(t_out, inc_offset, scr) - local today = os.date("%d") + local today = os.date("%e") local offs = inc_offset or 0 local f @@ -68,7 +68,7 @@ function calendar.show(t_out, inc_offset, scr) helpers.async(f, function(ws) fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg - ws = ws:gsub("%c%[+%d+[m]?%s?%d+%c%[+%d+[m]?", markup.bold(markup.color(bg, fg, today:gsub("^0", " ")))) + ws = ws:gsub("%c%[+%d+[m]?%s?%d+%c%[+%d+[m]?", markup.bold(markup.color(bg, fg, today))) calendar.hide() calendar.notification = naughty.notify({ preset = calendar.notification_preset, From a1ba90261b31ccce1ac2ecb7ca7aedbc20eca441 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 1 Feb 2017 21:58:40 +0100 Subject: [PATCH 103/106] wiki updated --- widgets/calendar.lua | 2 +- wiki | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/widgets/calendar.lua b/widgets/calendar.lua index 02f34ce..b8aeabd 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -68,7 +68,7 @@ function calendar.show(t_out, inc_offset, scr) helpers.async(f, function(ws) fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg - ws = ws:gsub("%c%[+%d+[m]?%s?%d+%c%[+%d+[m]?", markup.bold(markup.color(bg, fg, today))) + ws = ws:gsub("%c%[%d+[m]?" .. today .. "%c%[%d+[m]?", markup.bold(markup.color(bg, fg, today))) calendar.hide() calendar.notification = naughty.notify({ preset = calendar.notification_preset, diff --git a/wiki b/wiki index 6261aca..0868101 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 6261aca684a439466c763902833d169401462a5b +Subproject commit 0868101cb7cd8d8947e6b36cd9a7e36c91cc3a99 From 9ec9f475c886a8fba0532cb3d1b47190c01352fa Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Fri, 3 Feb 2017 21:00:00 +0100 Subject: [PATCH 104/106] #300 cal: revert highlight command; #308 mpd: escape quotes in cover path; weather: refresh widget when refreshing notification --- widgets/calendar.lua | 2 +- widgets/mpd.lua | 2 +- widgets/weather.lua | 1 + wiki | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/widgets/calendar.lua b/widgets/calendar.lua index b8aeabd..f351356 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -68,7 +68,7 @@ function calendar.show(t_out, inc_offset, scr) helpers.async(f, function(ws) fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg - ws = ws:gsub("%c%[%d+[m]?" .. today .. "%c%[%d+[m]?", markup.bold(markup.color(bg, fg, today))) + ws = ws:gsub("%c%[%d+[m]?%s?%d+%c%[%d+[m]?", markup.bold(markup.color(bg, fg, today))) calendar.hide() calendar.notification = naughty.notify({ preset = calendar.notification_preset, diff --git a/widgets/mpd.lua b/widgets/mpd.lua index c4c4691..58e8303 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -112,7 +112,7 @@ local function worker(args) if not string.match(mpd_now.file, "http.*://") then -- local file instead of http stream local path = string.format("%s/%s", music_dir, string.match(mpd_now.file, ".*/")) - local cover = string.format("find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'", path, cover_pattern) + local cover = string.format("find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'", path:gsub("'", "\'"):gsub('"', '\"'), cover_pattern) helpers.async({ shell, "-c", cover }, function(current_icon) common.icon = current_icon:gsub("\n", "") if #common.icon == 0 then common.icon = nil end diff --git a/widgets/weather.lua b/widgets/weather.lua index febd73b..1e398cc 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -68,6 +68,7 @@ local function worker(args) end if not weather.notification_text then + weather.update() weather.forecast_update() end diff --git a/wiki b/wiki index 0868101..e2ce961 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 0868101cb7cd8d8947e6b36cd9a7e36c91cc3a99 +Subproject commit e2ce961ae4ba86f373d26b79b7e7b4891e1a9aa9 From a274576cfd89c1475aa6b9149ad25fdd5cda1060 Mon Sep 17 00:00:00 2001 From: Calvin Timmer Date: Thu, 2 Feb 2017 14:37:43 +0100 Subject: [PATCH 105/106] Allow multiple instances of the pulseaudio widget Enable switching between default sink or source in pulseaudio widget --- widgets/pulseaudio.lua | 61 +++++++++++++++++++++--------------------- wiki | 2 +- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/widgets/pulseaudio.lua b/widgets/pulseaudio.lua index 68d3066..590bd0f 100644 --- a/widgets/pulseaudio.lua +++ b/widgets/pulseaudio.lua @@ -16,46 +16,47 @@ local setmetatable = setmetatable -- PulseAudio volume -- lain.widgets.pulseaudio -local pulseaudio = {} local function worker(args) - local args = args or {} - local timeout = args.timeout or 5 - local settings = args.settings or function() end - local scallback = args.scallback + local pulseaudio = { wibox.widget.textbox() } + local args = args or {} + local devicetype = args.devicetype or "sink" + local timeout = args.timeout or 5 + local settings = args.settings or function() end + local scallback = args.scallback - pulseaudio.cmd = args.cmd or "pacmd list-sinks | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'" + pulseaudio.cmd = args.cmd or "pacmd list-" .. devicetype .. "s | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'" - pulseaudio.widget = wibox.widget.textbox() + function pulseaudio.update() + if scallback then pulseaudio.cmd = scallback() end - function pulseaudio.update() - if scallback then pulseaudio.cmd = scallback() end + helpers.async({ shell, "-c", pulseaudio.cmd }, function(s) + volume_now = { + index = string.match(s, "index: (%S+)") or "N/A", + device = string.match(s, "device.string = \"(%S+)\"") or "N/A", + sink = device, -- legacy API + muted = string.match(s, "muted: (%S+)") or "N/A" + } - helpers.async({ shell, "-c", pulseaudio.cmd }, function(s) - volume_now = { - index = string.match(s, "index: (%S+)") or "N/A", - sink = string.match(s, "device.string = \"(%S+)\"") or "N/A", - muted = string.match(s, "muted: (%S+)") or "N/A" - } + local ch = 1 + volume_now.channel = {} + for v in string.gmatch(s, ":.-(%d+)%%") do + volume_now.channel[ch] = v + ch = ch + 1 + end - local ch = 1 - volume_now.channel = {} - for v in string.gmatch(s, ":.-(%d+)%%") do - volume_now.channel[ch] = v - ch = ch + 1 - end + volume_now.left = volume_now.channel[1] or "N/A" + volume_now.right = volume_now.channel[2] or "N/A" - volume_now.left = volume_now.channel[1] or "N/A" - volume_now.right = volume_now.channel[2] or "N/A" + widget = pulseaudio.widget - widget = pulseaudio.widget - settings() - end) - end + settings() + end) + end - helpers.newtimer("pulseaudio", timeout, pulseaudio.update) + helpers.newtimer("pulseaudio", timeout, pulseaudio.update) - return pulseaudio + return pulseaudio end -return setmetatable(pulseaudio, { __call = function(_, ...) return worker(...) end }) +return setmetatable({}, { __call = function(_, ...) return worker(...) end }) diff --git a/wiki b/wiki index e2ce961..af671ad 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit e2ce961ae4ba86f373d26b79b7e7b4891e1a9aa9 +Subproject commit af671ad9bb1ce9c7bb74a75f489a3b5d0a934558 From 133fe63b85978ac1f21658c5decd66e269261e60 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sat, 4 Feb 2017 14:40:21 +0100 Subject: [PATCH 106/106] #308 fix --- widgets/mpd.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/mpd.lua b/widgets/mpd.lua index 58e8303..ddedf24 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -112,7 +112,7 @@ local function worker(args) if not string.match(mpd_now.file, "http.*://") then -- local file instead of http stream local path = string.format("%s/%s", music_dir, string.match(mpd_now.file, ".*/")) - local cover = string.format("find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'", path:gsub("'", "\'"):gsub('"', '\"'), cover_pattern) + local cover = string.format("find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'", path:gsub("'", "'\\''"), cover_pattern) helpers.async({ shell, "-c", cover }, function(current_icon) common.icon = current_icon:gsub("\n", "") if #common.icon == 0 then common.icon = nil end