From f2fb4f6fdadc1b09877e5ef6bd75e06a668a4080 Mon Sep 17 00:00:00 2001 From: luke bonham Date: Tue, 5 Aug 2014 12:59:19 +0200 Subject: [PATCH 01/16] IMAP wiget is now asynchronous --- asyncshell.lua | 80 ++++++++++++++++++++++++++++++++++++++++++++ widgets/alsa.lua | 2 +- widgets/alsabar.lua | 2 +- widgets/base.lua | 2 +- widgets/calendar.lua | 2 +- widgets/cpu.lua | 2 +- widgets/fs.lua | 2 +- widgets/imap.lua | 53 +++++++++++++++-------------- widgets/maildir.lua | 2 +- widgets/net.lua | 2 +- widgets/sysload.lua | 2 +- widgets/temp.lua | 2 +- 12 files changed, 118 insertions(+), 35 deletions(-) create mode 100644 asyncshell.lua diff --git a/asyncshell.lua b/asyncshell.lua new file mode 100644 index 0000000..c05fb6b --- /dev/null +++ b/asyncshell.lua @@ -0,0 +1,80 @@ + +--[[ + + Licensed under GNU General Public License v2 + * (c) 2013, Alexander Yakushev + +--]] + +-- Asynchronous io.popen for Awesome WM. +-- How to use... +-- ...asynchronously: +-- asyncshell.request('wscript -Kiev', function(f) wwidget.text = f:read("*l") end) +-- ...synchronously +-- wwidget.text = asyncshell.demand('wscript -Kiev', 5):read("*l") or "Error" + +local spawn = require('awful.util').spawn + +asyncshell = {} +asyncshell.request_table = {} +asyncshell.id_counter = 0 +asyncshell.folder = "/tmp/asyncshell" +asyncshell.file_template = asyncshell.folder .. '/req' + +-- Create a directory for asynchell response files +os.execute("mkdir -p " .. asyncshell.folder) + +-- Returns next tag - unique identifier of the request +local function next_id() + asyncshell.id_counter = (asyncshell.id_counter + 1) % 100000 + return asyncshell.id_counter +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 +-- @return Request ID +function asyncshell.request(command, callback) + local id = next_id() + local tmpfname = asyncshell.file_template .. id + asyncshell.request_table[id] = {callback = callback} + local req = + string.format("bash -c '%s > %s; " .. + 'echo "asyncshell.deliver(%s)" | ' .. + "awesome-client' 2> /dev/null", + string.gsub(command, "'", "'\\''"), tmpfname, + id, tmpfname) + spawn(req, false) + return id +end + +-- Calls the remembered callback function on the output of the shell +-- command. +-- @param id Request ID +-- @param output The output file of the shell command to be delievered +function asyncshell.deliver(id) + if asyncshell.request_table[id] and + asyncshell.request_table[id].callback then + local output = io.open(asyncshell.file_template .. id, 'r') + asyncshell.request_table[id].callback(output) + end +end + +-- Sends a synchronous request for an output of the command. Waits for +-- the output, but if the given timeout expires returns nil. +-- @param command Command to be executed and taken output from +-- @param timeout Maximum amount of time to wait for the result +-- @return File handler on success, nil otherwise +function asyncshell.demand(command, timeout) + local id = next_id() + local tmpfname = asyncshell.file_template .. id + local f = io.popen(string.format("(%s > %s; echo asyncshell_done) & " .. + "(sleep %s; echo asynchell_timeout)", + command, tmpfname, timeout)) + local result = f:read("*line") + if result == "asyncshell_done" then + return io.open(tmpfname) + end +end + +return asyncshell diff --git a/widgets/alsa.lua b/widgets/alsa.lua index 4ed4f9c..f62a150 100644 --- a/widgets/alsa.lua +++ b/widgets/alsa.lua @@ -30,7 +30,7 @@ local function worker(args) function alsa.update() local f = assert(io.popen('amixer -M get ' .. channel)) - local mixer = f:read("*all") + local mixer = f:read("*a") f:close() volume_now = {} diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index e185c76..8675cb5 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -116,7 +116,7 @@ local function worker(args) function alsabar.update() -- Get mixer control contents local f = io.popen("amixer -M get " .. alsabar.channel) - local mixer = f:read("*all") + local mixer = f:read("*a") f:close() -- Capture mixer control state: [5%] ... ... [on] diff --git a/widgets/base.lua b/widgets/base.lua index 4f28e07..6b808b7 100644 --- a/widgets/base.lua +++ b/widgets/base.lua @@ -26,7 +26,7 @@ local function worker(args) function base.update() local f = assert(io.popen(cmd)) - output = f:read("*all") + output = f:read("*a") f:close() widget = base.widget settings() diff --git a/widgets/calendar.lua b/widgets/calendar.lua index 4e6eda7..c690e3f 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -88,7 +88,7 @@ function calendar:show(t_out, inc_offset) .. calendar.font_size .. "'>" .. f:read() .. "\n\n" .. f:read() .. "\n" - .. f:read("*all"):gsub("\n*$", "") + .. f:read("*a"):gsub("\n*$", "") .. "" f:close() diff --git a/widgets/cpu.lua b/widgets/cpu.lua index 7c1ecb0..96e0d3b 100644 --- a/widgets/cpu.lua +++ b/widgets/cpu.lua @@ -58,7 +58,7 @@ local function worker(args) local dactive = active - cpu.last_active local dtotal = total - cpu.last_total - cpu_now = {} + cpu_noj = {} cpu_now.usage = tostring(math.ceil((dactive / dtotal) * 100)) widget = cpu.widget diff --git a/widgets/fs.lua b/widgets/fs.lua index 867ce3f..8127c28 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -40,7 +40,7 @@ function fs:show(t_out) fs:hide() local f = io.popen(helpers.scripts_dir .. "dfs") - ws = f:read("*all"):gsub("\n*$", "") + ws = f:read("*a"):gsub("\n*$", "") f:close() notification = naughty.notify({ diff --git a/widgets/imap.lua b/widgets/imap.lua index c404032..1dca87c 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -7,11 +7,11 @@ --]] local helpers = require("lain.helpers") +local async = require("lain.asyncshell") local naughty = require("naughty") local wibox = require("wibox") -local io = { popen = io.popen } local string = { format = string.format, gsub = string.gsub } local tonumber = tonumber @@ -42,7 +42,7 @@ local function worker(args) if not is_plain then local f = io.popen(password) - password = f:read("*all"):gsub("\n", "") + password = f:read("*a"):gsub("\n", "") f:close() end @@ -57,34 +57,37 @@ local function worker(args) curl = string.format("%s --url imaps://%s:%s/INBOX -u %s:%s %s -k", head_command, server, port, mail, password, request) - f = io.popen(curl) - ws = f:read("*all") - f:close() - - _, mailcount = string.gsub(ws, "%d+", "") - _ = nil + async.request(curl, function(f) + ws = f:read("*a") + f:close() + + _, mailcount = string.gsub(ws, "%d+", "") + _ = nil + + widget = imap.widget + settings() + + 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, + screen = client.focus and client.focus.screen or 1 + }) + end - widget = imap.widget - settings() + helpers.set_map(mail, mailcount) + end) - 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, - screen = client.focus and client.focus.screen or 1 - }) - end - - helpers.set_map(mail, mailcount) end helpers.newtimer(mail, timeout, update, true) + return setmetatable(imap, { __index = imap.widget }) end diff --git a/widgets/maildir.lua b/widgets/maildir.lua index 8fe097e..bd79221 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -53,7 +53,7 @@ local function worker(args) local np = io.popen("find " .. line .. "/new -mindepth 1 -type f " .. "-not -name '.*' -printf a") - local mailstring = np:read("*all") + local mailstring = np:read("*a") -- Strip off leading mailpath. local box = string.match(line, mailpath .. "/*([^/]+)") diff --git a/widgets/net.lua b/widgets/net.lua index 1e59731..7851d5a 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -29,7 +29,7 @@ local net = { function net.get_device() f = io.popen("ip link show | cut -d' ' -f2,9") - ws = f:read("*all") + ws = f:read("*a") f:close() ws = ws:match("%w+: UP") if ws ~= nil then diff --git a/widgets/sysload.lua b/widgets/sysload.lua index 2abac33..b15b1bf 100644 --- a/widgets/sysload.lua +++ b/widgets/sysload.lua @@ -30,7 +30,7 @@ local function worker(args) function update() local f = io.open("/proc/loadavg") - local ret = f:read("*all") + local ret = f:read("*a") f:close() load_1, load_5, load_15 = string.match(ret, "([^%s]+) ([^%s]+) ([^%s]+)") diff --git a/widgets/temp.lua b/widgets/temp.lua index 61a9aa5..4ae1c04 100644 --- a/widgets/temp.lua +++ b/widgets/temp.lua @@ -31,7 +31,7 @@ local function worker(args) local f = io.open(tempfile) if f ~= nil then - coretemp_now = tonumber(f:read("*all")) / 1000 + coretemp_now = tonumber(f:read("*a")) / 1000 f:close() else coretemp_now = "N/A" -- 2.39.5 From 4903782e553dd8d16ae0ff5eab6c60886a52b673 Mon Sep 17 00:00:00 2001 From: luke bonham Date: Thu, 7 Aug 2014 12:21:02 +0200 Subject: [PATCH 02/16] small fixes --- widgets/yawn/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/yawn/init.lua b/widgets/yawn/init.lua index da2b856..148f547 100644 --- a/widgets/yawn/init.lua +++ b/widgets/yawn/init.lua @@ -48,7 +48,7 @@ yawn_notification_preset = {} local function fetch_weather() local url = api_url .. units_set .. city_id local f = io.popen("curl --connect-timeout 1 -fsm 3 '" .. url .. "'" ) - local text = f:read("*all") + local text = f:read("*a") f:close() -- In case of no connection or invalid city ID -- 2.39.5 From 823659d83d1262bbd94821e8460822c0130fff56 Mon Sep 17 00:00:00 2001 From: luke bonham Date: Thu, 7 Aug 2014 12:21:30 +0200 Subject: [PATCH 03/16] small fixes --- asyncshell.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asyncshell.lua b/asyncshell.lua index c05fb6b..4eb8d2e 100644 --- a/asyncshell.lua +++ b/asyncshell.lua @@ -39,7 +39,7 @@ function asyncshell.request(command, callback) local tmpfname = asyncshell.file_template .. id asyncshell.request_table[id] = {callback = callback} local req = - string.format("bash -c '%s > %s; " .. + string.format("sh -c '%s > %s; " .. 'echo "asyncshell.deliver(%s)" | ' .. "awesome-client' 2> /dev/null", string.gsub(command, "'", "'\\''"), tmpfname, -- 2.39.5 From 6714db710a53b3c13d4526dcd922e1333ca6c1af Mon Sep 17 00:00:00 2001 From: luke bonham Date: Thu, 7 Aug 2014 13:37:24 +0200 Subject: [PATCH 04/16] mpd and yawn widget are now asynchronous --- asyncshell.lua | 2 + widgets/mpd.lua | 87 +++++++++++----------- widgets/yawn/init.lua | 164 +++++++++++++++++++++--------------------- 3 files changed, 129 insertions(+), 124 deletions(-) diff --git a/asyncshell.lua b/asyncshell.lua index 4eb8d2e..51885e8 100644 --- a/asyncshell.lua +++ b/asyncshell.lua @@ -13,6 +13,8 @@ -- ...synchronously -- wwidget.text = asyncshell.demand('wscript -Kiev', 5):read("*l") or "Error" +-- This makes things faster, but puts weight on sysload and is more cpu demanding. + local spawn = require('awful.util').spawn asyncshell = {} diff --git a/widgets/mpd.lua b/widgets/mpd.lua index 73efebb..385b5bb 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -8,6 +8,7 @@ --]] local helpers = require("lain.helpers") +local async = require("lain.asyncshell") local escape_f = require("awful.util").escape local naughty = require("naughty") @@ -50,56 +51,54 @@ local function worker(args) helpers.set_map("current mpd track", nil) function mpd.update() - mpd_now = { - state = "N/A", - file = "N/A", - artist = "N/A", - title = "N/A", - album = "N/A", - date = "N/A" - } - - local f = io.popen(echo .. " | curl --connect-timeout 1 -fsm 3 " .. mpdh) - - for line in f:lines() do - for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do - if k == "state" then mpd_now.state = v - elseif k == "file" then mpd_now.file = v - 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 == "Date" then mpd_now.date = escape_f(v) + async.request(echo .. " | curl --connect-timeout 1 -fsm 3 " .. mpdh, function (f) + mpd_now = { + state = "N/A", + file = "N/A", + artist = "N/A", + title = "N/A", + album = "N/A", + date = "N/A" + } + + for line in f:lines() do + for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do + if k == "state" then mpd_now.state = v + elseif k == "file" then mpd_now.file = v + 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 == "Date" then mpd_now.date = escape_f(v) + end end end - end - f:close() + mpd_notification_preset.text = string.format("%s (%s) - %s\n%s", mpd_now.artist, + mpd_now.album, mpd_now.date, mpd_now.title) + widget = mpd.widget + settings() - mpd_notification_preset.text = string.format("%s (%s) - %s\n%s", mpd_now.artist, - mpd_now.album, mpd_now.date, mpd_now.title) - widget = mpd.widget - settings() - - if mpd_now.state == "play" - then - if mpd_now.title ~= helpers.get_map("current mpd track") + if mpd_now.state == "play" then - helpers.set_map("current mpd track", mpd_now.title) - - os.execute(string.format("%s %q %q %d %q", mpdcover, music_dir, - mpd_now.file, cover_size, default_art)) - - mpd.id = naughty.notify({ - preset = mpd_notification_preset, - icon = "/tmp/mpdcover.png", - replaces_id = mpd.id, - screen = client.focus and client.focus.screen or 1 - }).id + if mpd_now.title ~= helpers.get_map("current mpd track") + then + helpers.set_map("current mpd track", mpd_now.title) + + os.execute(string.format("%s %q %q %d %q", mpdcover, music_dir, + mpd_now.file, cover_size, default_art)) + + mpd.id = naughty.notify({ + preset = mpd_notification_preset, + icon = "/tmp/mpdcover.png", + replaces_id = mpd.id, + screen = client.focus and client.focus.screen or 1 + }).id + end + elseif mpd_now.state ~= "pause" + then + helpers.set_map("current mpd track", nil) end - elseif mpd_now.state ~= "pause" - then - helpers.set_map("current mpd track", nil) - end + end) end helpers.newtimer("mpd", timeout, mpd.update) diff --git a/widgets/yawn/init.lua b/widgets/yawn/init.lua index 148f547..033254e 100644 --- a/widgets/yawn/init.lua +++ b/widgets/yawn/init.lua @@ -7,6 +7,7 @@ --]] local newtimer = require("lain.helpers").newtimer +local async = require("lain.asyncshell") local naughty = require("naughty") local wibox = require("wibox") @@ -47,99 +48,102 @@ yawn_notification_preset = {} local function fetch_weather() local url = api_url .. units_set .. city_id - local f = io.popen("curl --connect-timeout 1 -fsm 3 '" .. url .. "'" ) - local text = f:read("*a") - f:close() + local cmd = "curl --connect-timeout 1 -fsm 3 '" .. url .. "'" - -- In case of no connection or invalid city ID - -- widgets won't display - if text == "" or text:match("City not found") - then - yawn.icon:set_image(icon_path .. "na.png") - if text == "" then - weather_data = "Service not available at the moment." - yawn.widget:set_text(" N/A ") - else - weather_data = "City not found!\n" .. - "Are you sure " .. city_id .. - " is your Yahoo city ID?" - yawn.widget:set_text(" ? ") + async.request(cmd, function(f) + local text = f:read("*a") + f:close() + + -- In case of no connection or invalid city ID + -- widgets won't display + if text == "" or text:match("City not found") + then + yawn.icon:set_image(icon_path .. "na.png") + if text == "" then + weather_data = "Service not available at the moment." + yawn.widget:set_text(" N/A ") + else + weather_data = "City not found!\n" .. + "Are you sure " .. city_id .. + " is your Yahoo city ID?" + yawn.widget:set_text(" ? ") + end + return end - return - end - -- Processing raw data - weather_data = text:gsub("<.->", "") - weather_data = weather_data:match("Current Conditions:.-Full") or "" + -- Processing raw data + weather_data = text:gsub("<.->", "") + weather_data = weather_data:match("Current Conditions:.-Full") or "" - -- may still happens in case of bad connectivity - if weather_data == "" then - yawn.icon:set_image(icon_path .. "na.png") - yawn.widget:set_text(" ? ") - return - end + -- may still happens in case of bad connectivity + if weather_data == "" then + yawn.icon:set_image(icon_path .. "na.png") + yawn.widget:set_text(" ? ") + return + end - weather_data = weather_data:gsub("Current Conditions:.-\n", "Now: ") - weather_data = weather_data:gsub("Forecast:.-\n", "") - weather_data = weather_data:gsub("\nFull", "") - weather_data = weather_data:gsub("[\n]$", "") - weather_data = weather_data:gsub(" [-] " , ": ") - weather_data = weather_data:gsub("[.]", ",") - weather_data = weather_data:gsub("High: ", "") - weather_data = weather_data:gsub(" Low: ", " - ") - - -- Getting info for text widget - local now = weather_data:sub(weather_data:find("Now:")+5, - weather_data:find("\n")-1) - forecast = now:sub(1, now:find(",")-1) - units = now:sub(now:find(",")+2, -2) - - -- Day/Night icon change - local hour = tonumber(os.date("%H")) - sky = icon_path - - if forecast == "Clear" or - forecast == "Fair" or - forecast == "Partly Cloudy" or - forecast == "Mostly Cloudy" - then - if hour >= 6 and hour <= 18 + weather_data = weather_data:gsub("Current Conditions:.-\n", "Now: ") + weather_data = weather_data:gsub("Forecast:.-\n", "") + weather_data = weather_data:gsub("\nFull", "") + weather_data = weather_data:gsub("[\n]$", "") + weather_data = weather_data:gsub(" [-] " , ": ") + weather_data = weather_data:gsub("[.]", ",") + weather_data = weather_data:gsub("High: ", "") + weather_data = weather_data:gsub(" Low: ", " - ") + + -- Getting info for text widget + local now = weather_data:sub(weather_data:find("Now:")+5, + weather_data:find("\n")-1) + forecast = now:sub(1, now:find(",")-1) + units = now:sub(now:find(",")+2, -2) + + -- Day/Night icon change + local hour = tonumber(os.date("%H")) + sky = icon_path + + if forecast == "Clear" or + forecast == "Fair" or + forecast == "Partly Cloudy" or + forecast == "Mostly Cloudy" then - sky = sky .. "Day" - else - sky = sky .. "Night" - end - end + if hour >= 6 and hour <= 18 + then + sky = sky .. "Day" + else + sky = sky .. "Night" + end + end - sky = sky .. forecast:gsub(" ", ""):gsub("/", "") .. ".png" + sky = sky .. forecast:gsub(" ", ""):gsub("/", "") .. ".png" - -- In case there's no defined icon for current forecast - if io.open(sky) == nil then - sky = icon_path .. "na.png" - end + -- In case there's no defined icon for current forecast + if io.open(sky) == nil then + sky = icon_path .. "na.png" + end - -- Localization - local f = io.open(localizations_path .. language, "r") - if language:find("en_") == nil and f ~= nil - then - f:close() - for line in io.lines(localizations_path .. language) - do - word = string.sub(line, 1, line:find("|")-1) - translation = string.sub(line, line:find("|")+1) - weather_data = string.gsub(weather_data, word, translation) + -- Localization + local f = io.open(localizations_path .. language, "r") + if language:find("en_") == nil and f ~= nil + then + f:close() + for line in io.lines(localizations_path .. language) + do + word = string.sub(line, 1, line:find("|")-1) + translation = string.sub(line, line:find("|")+1) + weather_data = string.gsub(weather_data, word, translation) + end end - end - -- Finally setting infos - yawn.icon:set_image(sky) - widget = yawn.widget + -- Finally setting infos + yawn.icon:set_image(sky) + widget = yawn.widget - _data = weather_data:match(": %S.-,") or weather_data - forecast = _data:gsub(": ", ""):gsub(",", "") - units = units:gsub(" ", "") + _data = weather_data:match(": %S.-,") or weather_data + forecast = _data:gsub(": ", ""):gsub(",", "") + units = units:gsub(" ", "") - settings() + settings() + end) end function yawn.hide() -- 2.39.5 From bb7fbebf1f880683950bcd1f897951529775724f Mon Sep 17 00:00:00 2001 From: Chris Morin Date: Thu, 7 Aug 2014 17:13:32 -0400 Subject: [PATCH 05/16] fix typo --- widgets/cpu.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/cpu.lua b/widgets/cpu.lua index 96e0d3b..7c1ecb0 100644 --- a/widgets/cpu.lua +++ b/widgets/cpu.lua @@ -58,7 +58,7 @@ local function worker(args) local dactive = active - cpu.last_active local dtotal = total - cpu.last_total - cpu_noj = {} + cpu_now = {} cpu_now.usage = tostring(math.ceil((dactive / dtotal) * 100)) widget = cpu.widget -- 2.39.5 From 0d5c25ffd4ed4d5c1a06b1f0b731b1cb6db79b8b Mon Sep 17 00:00:00 2001 From: luke bonham Date: Fri, 8 Aug 2014 14:10:25 +0200 Subject: [PATCH 06/16] abase widget added --- widgets/abase.lua | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 widgets/abase.lua diff --git a/widgets/abase.lua b/widgets/abase.lua new file mode 100644 index 0000000..20cc955 --- /dev/null +++ b/widgets/abase.lua @@ -0,0 +1,43 @@ + +--[[ + + Licensed under GNU General Public License v2 + * (c) 2014, Luke Bonham + +--]] + +local newtimer = require("lain.helpers").newtimer +local async = require("lain.asyncshell") +local wibox = require("wibox") + +local io = io +local setmetatable = setmetatable + +-- Basic template for custom widgets +-- Asynchronous version +-- 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('') + + function abase.update() + async.request(cmd, function(f) + output = f:read("*a") + f:close() + widget = abase.widget + settings() + end) + end + + newtimer(cmd, timeout, abase.update) + + return setmetatable(abase, { __index = abase.widget }) +end + +return setmetatable({}, { __call = function(_, ...) return worker(...) end }) -- 2.39.5 From f37a31878edfb59d56c2b0fde04ae80c46a8809e Mon Sep 17 00:00:00 2001 From: luke bonham Date: Fri, 8 Aug 2014 14:25:21 +0200 Subject: [PATCH 07/16] widget module loads optimization --- helpers.lua | 2 +- widgets/abase.lua | 1 - widgets/base.lua | 4 ++-- widgets/borderbox.lua | 1 + widgets/calendar.lua | 2 +- widgets/fs.lua | 2 +- widgets/imap.lua | 2 +- widgets/maildir.lua | 2 +- widgets/net.lua | 2 +- widgets/temp.lua | 2 +- widgets/yawn/init.lua | 3 ++- 11 files changed, 12 insertions(+), 11 deletions(-) diff --git a/helpers.lua b/helpers.lua index 863bb87..1dfb09b 100644 --- a/helpers.lua +++ b/helpers.lua @@ -2,7 +2,7 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2013, Luke Bonham --]] diff --git a/widgets/abase.lua b/widgets/abase.lua index 20cc955..075d615 100644 --- a/widgets/abase.lua +++ b/widgets/abase.lua @@ -10,7 +10,6 @@ local newtimer = require("lain.helpers").newtimer local async = require("lain.asyncshell") local wibox = require("wibox") -local io = io local setmetatable = setmetatable -- Basic template for custom widgets diff --git a/widgets/base.lua b/widgets/base.lua index 6b808b7..39b0863 100644 --- a/widgets/base.lua +++ b/widgets/base.lua @@ -9,10 +9,10 @@ local newtimer = require("lain.helpers").newtimer local wibox = require("wibox") -local io = io +local io = { popen = io.popen } local setmetatable = setmetatable --- Basic template for custom widgets +-- Basic template for custom widgets -- lain.widgets.base local function worker(args) diff --git a/widgets/borderbox.lua b/widgets/borderbox.lua index c251ea8..cce8517 100644 --- a/widgets/borderbox.lua +++ b/widgets/borderbox.lua @@ -8,6 +8,7 @@ --]] local wibox = require("awful.wibox") + local setmetatable = setmetatable -- Creates a thin wibox at a position relative to another wibox diff --git a/widgets/calendar.lua b/widgets/calendar.lua index c690e3f..d07a5b4 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -12,7 +12,7 @@ local awful = require("awful") local beautiful = require("beautiful") local naughty = require("naughty") -local io = io +local io = { popen = io.popen } local os = { date = os.date } local tonumber = tonumber diff --git a/widgets/fs.lua b/widgets/fs.lua index 8127c28..f78cfe0 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -14,7 +14,7 @@ local beautiful = require("beautiful") local wibox = require("wibox") local naughty = require("naughty") -local io = io +local io = { popen = io.popen } local pairs = pairs local string = { match = string.match, format = string.format } diff --git a/widgets/imap.lua b/widgets/imap.lua index 1dca87c..65c425e 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -57,7 +57,7 @@ local function worker(args) curl = string.format("%s --url imaps://%s:%s/INBOX -u %s:%s %s -k", head_command, server, port, mail, password, request) - async.request(curl, function(f) + async.request(curl, function(f) ws = f:read("*a") f:close() diff --git a/widgets/maildir.lua b/widgets/maildir.lua index bd79221..246341f 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -13,7 +13,7 @@ local wibox = require("wibox") local util = require("lain.util") -local io = io +local io = { popen = io.popen } local os = { getenv = os.getenv } local pairs = pairs local string = { len = string.len, diff --git a/widgets/net.lua b/widgets/net.lua index 7851d5a..9575000 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -13,7 +13,7 @@ local notify_fg = require("beautiful").fg_focus local naughty = require("naughty") local wibox = require("wibox") -local io = io +local io = { popen = io.popen } local tostring = tostring local string = { format = string.format, gsub = string.gsub } diff --git a/widgets/temp.lua b/widgets/temp.lua index 4ae1c04..5994f59 100644 --- a/widgets/temp.lua +++ b/widgets/temp.lua @@ -10,7 +10,7 @@ local newtimer = require("lain.helpers").newtimer local wibox = require("wibox") -local io = io +local io = { open = io.open } local tonumber = tonumber local setmetatable = setmetatable diff --git a/widgets/yawn/init.lua b/widgets/yawn/init.lua index 033254e..aa58ed1 100644 --- a/widgets/yawn/init.lua +++ b/widgets/yawn/init.lua @@ -13,7 +13,8 @@ local naughty = require("naughty") local wibox = require("wibox") local debug = { getinfo = debug.getinfo } -local io = io +local io = { lines = io.lines, + open = io.open } local os = { date = os.date, getenv = os.getenv } local string = { find = string.find, -- 2.39.5 From 24ac1f98e6a5a92a61e5935b2ed4d03ed79ec6b0 Mon Sep 17 00:00:00 2001 From: luke bonham Date: Mon, 8 Sep 2014 18:51:48 +0200 Subject: [PATCH 08/16] imap: increased curl connect-timeout --- widgets/imap.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/imap.lua b/widgets/imap.lua index 65c425e..3a6da8d 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -34,7 +34,7 @@ local function worker(args) local is_plain = args.is_plain or false local settings = args.settings or function() end - local head_command = "curl --connect-timeout 1 -fsm 3" + local head_command = "curl --connect-timeout 3 -fsm 3" local request = "-X 'SEARCH (UNSEEN)'" helpers.set_map(mail, 0) -- 2.39.5 From 55e72b9aa480779b83129776658c41ccef28d599 Mon Sep 17 00:00:00 2001 From: luke bonham Date: Thu, 11 Sep 2014 16:10:22 +0200 Subject: [PATCH 09/16] yawn: new words localized --- widgets/yawn/localizations/fr_FR | 3 ++- widgets/yawn/localizations/it_IT | 1 + widgets/yawn/localizations/localization_template | 1 + widgets/yawn/localizations/zh_CN | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/widgets/yawn/localizations/fr_FR b/widgets/yawn/localizations/fr_FR index 444b02c..18a35bb 100644 --- a/widgets/yawn/localizations/fr_FR +++ b/widgets/yawn/localizations/fr_FR @@ -57,4 +57,5 @@ Hail|Grêle Fog|Brouillard Foggy|Brumeux Haze|Brume -Light|Clair \ No newline at end of file +Light|Clair +With|Avec diff --git a/widgets/yawn/localizations/it_IT b/widgets/yawn/localizations/it_IT index 70b0eef..44d010e 100644 --- a/widgets/yawn/localizations/it_IT +++ b/widgets/yawn/localizations/it_IT @@ -58,3 +58,4 @@ Fog|Nebbia Foggy|Nebbioso Haze|Nebbia Light|Leggere +With|Con diff --git a/widgets/yawn/localizations/localization_template b/widgets/yawn/localizations/localization_template index 453807e..2fbf066 100644 --- a/widgets/yawn/localizations/localization_template +++ b/widgets/yawn/localizations/localization_template @@ -58,3 +58,4 @@ Fog| Foggy| Haze| Light| +With| diff --git a/widgets/yawn/localizations/zh_CN b/widgets/yawn/localizations/zh_CN index 53b0219..61e98a4 100644 --- a/widgets/yawn/localizations/zh_CN +++ b/widgets/yawn/localizations/zh_CN @@ -58,3 +58,4 @@ Fog|雾 Foggy|有雾 Haze|霾 Light|小 +With|與 -- 2.39.5 From 0ffc8fe4e5f1ef79c4d22e5bcbcd1bf7234df539 Mon Sep 17 00:00:00 2001 From: projektile Date: Mon, 22 Sep 2014 11:25:27 -0400 Subject: [PATCH 10/16] save arezzo files --- layout/cascade.lua | 17 +++++++++++++- layout/cascadetile.lua | 38 +++++++++++++++++++++----------- layout/centerfair.lua | 46 +++++++++++++++++++++++++------------- layout/centerwork.lua | 37 +++++++++++++++++++++---------- layout/termfair.lua | 49 +++++++++++++++++++---------------------- layout/uselessfair.lua | 48 ++++++++++++++++++++-------------------- layout/uselesspiral.lua | 46 ++++++++++++++++++++++++-------------- layout/uselesstile.lua | 44 +++++++++++++++++++++++------------- 8 files changed, 203 insertions(+), 122 deletions(-) diff --git a/layout/cascade.lua b/layout/cascade.lua index cabacef..999c599 100644 --- a/layout/cascade.lua +++ b/layout/cascade.lua @@ -2,12 +2,14 @@ --[[ 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 tag = require("awful.tag") +local beautiful = require("beautiful") local cascade = { @@ -21,10 +23,23 @@ 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 + + -- Themes border width requires an offset. + local bw = tonumber(beautiful.border_width) or 0 + -- Screen. local wa = p.workarea local cls = p.clients + wa.height = wa.height - ((global_border * 2) + (bw * 2)) + wa.width = wa.width - ((global_border * 2) + (bw * 2)) + wa.x = wa.x + global_border + wa.y = wa.y + global_border + -- 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 diff --git a/layout/cascadetile.lua b/layout/cascadetile.lua index 98821e3..e9b9425 100644 --- a/layout/cascadetile.lua +++ b/layout/cascadetile.lua @@ -2,6 +2,7 @@ --[[ Licensed under GNU General Public License v2 + * (c) 2014, projektile * (c) 2013, Luke Bonham * (c) 2010-2012, Peter Hofmann @@ -30,25 +31,36 @@ function cascadetile.arrange(p) -- It's a bit hard to demonstrate the behaviour with ASCII-images... -- - -- (1) (2) (3) (4) - -- +-----+---+ +-----+---+ +-----+---+ +-----+---+ - -- | | | | | | | | | | | 4 | - -- | | | | | 2 | | | 3 | | | | - -- | 1 | | -> | 1 | | -> | 1 | | -> | 1 +---+ - -- | | | | +---+ | +---+ | | 3 | - -- | | | | | | | | 2 | | |---| - -- | | | | | | | |---| | | 2 | - -- | | | | | | | | | | |---| - -- +-----+---+ +-----+---+ +-----+---+ +-----+---+ + -- (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 + + -- Themes border width requires an offset + local bw = tonumber(beautiful.border_width) or 0 -- Screen. local wa = p.workarea local cls = p.clients + -- Borders are factored in. + wa.height = wa.height - ((global_border * 2) + (bw * 2)) + wa.width = wa.width - ((global_border * 2) + (bw * 2)) + -- Width of main column? local t = tag.selected(p.screen) local mwfact @@ -108,8 +120,8 @@ function cascadetile.arrange(p) end g.height = wa.height - g.x = wa.x - g.y = wa.y + g.x = wa.x + global_border + g.y = wa.y + global_border if useless_gap > 0 then -- Reduce width once and move window to the right. Reduce @@ -138,7 +150,7 @@ function cascadetile.arrange(p) g.width = slavewid - current_offset_x g.height = wa.height - current_offset_y g.x = wa.x + mainwid + (how_many - i) * cascadetile.offset_x - g.y = wa.y + (i - 1) * cascadetile.offset_y + g.y = wa.y + (i - 1) * cascadetile.offset_y + global_border if useless_gap > 0 then g.width = g.width - 2 * useless_gap diff --git a/layout/centerfair.lua b/layout/centerfair.lua index 49b4a14..01a2fe0 100644 --- a/layout/centerfair.lua +++ b/layout/centerfair.lua @@ -1,11 +1,12 @@ --[[ - - Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham - * (c) 2010, Nicolas Estibals - * (c) 2010-2012, Peter Hofmann - + + 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") @@ -41,15 +42,30 @@ function centerfair.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 + 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 -- Screen. local wa = p.workarea local cls = p.clients + -- Borders are factored in. + wa.height = wa.height - ((global_border * 2) + (bw * 2)) + wa.width = wa.width - ((global_border * 2) + (bw * 2)) + -- 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 + if num_x > #cls then num_x = #cls end local width = math.floor((wa.width-(num_x+1)*useless_gap) / num_x) @@ -61,24 +77,24 @@ function centerfair.arrange(p) local g = {} g.width = width g.height = wa.height - 2*useless_gap - 2 - g.y = offset_y + g.y = offset_y + global_border for i = 1, #cls do - g.x = offset_x + (i - 1) * (width + useless_gap + 2) + g.x = offset_x + (i - 1) * (width + useless_gap + 2) + global_border cls[i]:geometry(g) end else -- More clients than the number of columns, let's arrange it! - local offset_x = wa.x + local offset_x = wa.x if useless_gap > 0 then - offset_x = offset_x + offset_x = offset_x end -- Master client deserves a special treatement local g = {} - g.width = wa.width - (num_x-1)*width -num_x*useless_gap - 2 + g.width = wa.width - (num_x - 1) * width - num_x * useless_gap g.height = wa.height - 2*useless_gap - 2 - g.x = offset_x + useless_gap - g.y = offset_y + g.x = offset_x + useless_gap + global_border + g.y = offset_y + global_border cls[1]:geometry(g) -- Treat the other clients @@ -128,8 +144,8 @@ function centerfair.arrange(p) for i = 1, (num_x-1) do to_remove = 2 - g.height = math.floor((wa.height-useless_gap)/num_y[i]) - g.y = offset_y + g.height = math.floor((wa.height - (num_y[i] * useless_gap)) / num_y[i]) + g.y = offset_y + global_border for j = 0, (num_y[i]-2) do cls[nclient]:geometry(g) nclient = nclient + 1 diff --git a/layout/centerwork.lua b/layout/centerwork.lua index 939f18c..61f4907 100644 --- a/layout/centerwork.lua +++ b/layout/centerwork.lua @@ -2,6 +2,7 @@ --[[ Licensed under GNU General Public License v2 + * (c) 2014, projektile * (c) 2013, Luke Bonham * (c) 2010-2012, Peter Hofmann @@ -26,10 +27,22 @@ function centerwork.arrange(p) -- 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 + + -- Themes border width requires an offset + local bw = tonumber(beautiful.border_width) or 0 + -- Screen. local wa = p.workarea local cls = p.clients + -- Borders are factored in. + wa.height = wa.height - ((global_border * 2) + (bw * 2)) + wa.width = wa.width - ((global_border * 2) + (bw * 2)) + -- Width of main column? local t = awful.tag.selected(p.screen) local mwfact = awful.tag.getmwfact(t) @@ -37,7 +50,7 @@ function centerwork.arrange(p) if #cls > 0 then -- Main column, fixed width and height. - local c = cls[1] + local c = cls[#cls] local g = {} local mainwid = math.floor(wa.width * mwfact) local slavewid = wa.width - mainwid @@ -48,8 +61,8 @@ function centerwork.arrange(p) g.height = wa.height - 2 * useless_gap g.width = mainwid - g.x = wa.x + slaveLwid - g.y = wa.y + useless_gap + g.x = wa.x + slaveLwid + global_border + g.y = wa.y + useless_gap + global_border c:geometry(g) @@ -57,7 +70,7 @@ function centerwork.arrange(p) if #cls > 1 then local at = 0 - for i = (#cls),2,-1 + for i = (#cls - 1),1,-1 do -- It's all fixed. If there are more than 5 clients, -- those additional clients will float. This is @@ -73,29 +86,29 @@ function centerwork.arrange(p) if at == centerwork.top_left then -- top left - g.x = wa.x + useless_gap - g.y = wa.y + useless_gap + g.x = wa.x + useless_gap + global_border + g.y = wa.y + useless_gap + global_border g.width = slaveLwid - 2 * useless_gap g.height = slaveThei - useless_gap elseif at == centerwork.top_right then -- top right - g.x = wa.x + slaveLwid + mainwid + useless_gap - g.y = wa.y + useless_gap + g.x = wa.x + slaveLwid + mainwid + useless_gap + global_border + g.y = wa.y + useless_gap + global_border g.width = slaveRwid - 2 * useless_gap g.height = slaveThei - useless_gap elseif at == centerwork.bottom_left then -- bottom left - g.x = wa.x + useless_gap - g.y = wa.y + slaveThei + useless_gap + g.x = wa.x + useless_gap + global_border + g.y = wa.y + slaveThei + useless_gap + global_border g.width = slaveLwid - 2 * useless_gap g.height = slaveBhei - 2 * useless_gap elseif at == centerwork.bottom_right then -- bottom right - g.x = wa.x + slaveLwid + mainwid + useless_gap - g.y = wa.y + slaveThei + useless_gap + g.x = wa.x + slaveLwid + mainwid + useless_gap + global_border + g.y = wa.y + slaveThei + useless_gap + global_border g.width = slaveRwid - 2 * useless_gap g.height = slaveBhei - 2 * useless_gap end diff --git a/layout/termfair.lua b/layout/termfair.lua index 89a44bb..4e45eec 100644 --- a/layout/termfair.lua +++ b/layout/termfair.lua @@ -2,6 +2,7 @@ --[[ Licensed under GNU General Public License v2 + * (c) 2014, projektile * (c) 2013, Luke Bonham * (c) 2010-2012, Peter Hofmann @@ -38,11 +39,24 @@ function termfair.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 + 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 -- Screen. local wa = p.workarea local cls = p.clients + -- Borders are factored in. + wa.height = wa.height - ((global_border * 2) + (bw * 2)) + wa.width = wa.width - ((global_border * 2) + (bw * 2)) + -- How many vertical columns? local t = tag.selected(p.screen) local num_x = termfair.nmaster or tag.getnmaster(t) @@ -79,43 +93,26 @@ function termfair.arrange(p) local g = {} if this_x == (num_x - 1) then - g.width = wa.width - (num_x - 1) * width + g.width = wa.width - (num_x - 1) * width - useless_gap else - g.width = width + g.width = width - useless_gap end if this_y == (num_y - 1) then - g.height = wa.height - (num_y - 1) * height + g.height = wa.height - (num_y - 1) * height - useless_gap else - g.height = height + g.height = height - useless_gap end - g.x = wa.x + this_x * width - g.y = wa.y + this_y * height + g.x = wa.x + this_x * width + global_border + g.y = wa.y + this_y * height + global_border 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. - - gap_factor = (useless_gap / 100) * 2 - - if this_x == 0 - then - g.width = g.width - (2 + gap_factor) * useless_gap - g.x = g.x + useless_gap - else - g.width = g.width - (1 + gap_factor) * useless_gap - end + -- All clients tile evenly. + g.x = g.x + (useless_gap / 2) + g.y = g.y + (useless_gap / 2) - if this_y == 0 - then - g.height = g.height - (2 + gap_factor) * useless_gap - g.y = g.y + useless_gap - else - g.height = g.height - (1 + gap_factor) * useless_gap - end end c:geometry(g) remaining_clients = remaining_clients - 1 diff --git a/layout/uselessfair.lua b/layout/uselessfair.lua index 6aa6666..6a386c3 100644 --- a/layout/uselessfair.lua +++ b/layout/uselessfair.lua @@ -2,6 +2,7 @@ --[[ Licensed under GNU General Public License v2 + * (c) 2014, projektile * (c) 2013, Luke Bonham * (c) 2012, Josh Komoroske * (c) 2010-2012, Peter Hofmann @@ -19,10 +20,23 @@ local function fair(p, orientation) -- 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 + wa.height = wa.height - ((global_border * 2) + (bw * 2)) + wa.width = wa.width - ((global_border * 2) + (bw * 2)) + if #cls > 0 then local cells = math.ceil(math.sqrt(#cls)) local strips = math.ceil(#cls / cells) @@ -47,8 +61,8 @@ local function fair(p, orientation) this_x = cell this_y = strip - g.x = wa.x + cell * g.width - g.y = wa.y + strip * g.height + g.x = wa.x + cell * g.width + global_border + g.y = wa.y + strip * g.height + global_border else if #cls < (strips * cells) and strip == strips - 1 then @@ -61,34 +75,20 @@ local function fair(p, orientation) this_x = strip this_y = cell - g.x = wa.x + strip * g.width - g.y = wa.y + cell * g.height + g.x = wa.x + strip * g.width + global_border + g.y = wa.y + cell * g.height + global_border + end -- 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. - - gap_factor = (useless_gap / 100) * 2 + -- All clients tile evenly. + g.width = g.width - useless_gap + g.x = g.x + (useless_gap / 2) + g.height = g.height - useless_gap + g.y = g.y + (useless_gap / 2) - if this_x == 0 - then - g.width = g.width - (2 + gap_factor) * useless_gap - g.x = g.x + useless_gap - else - g.width = g.width - (1 + gap_factor) * useless_gap - end - - if this_y == 0 - then - g.height = g.height - (2 + gap_factor) * useless_gap - g.y = g.y + useless_gap - else - g.height = g.height - (1 + gap_factor) * useless_gap - end end -- End of useless gap. diff --git a/layout/uselesspiral.lua b/layout/uselesspiral.lua index 3164c75..7c72912 100644 --- a/layout/uselesspiral.lua +++ b/layout/uselesspiral.lua @@ -2,7 +2,8 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2014 projektile + * (c) 2013 Luke Bonham * (c) 2009 Uli Schlachter * (c) 2008 Julien Danjolu @@ -11,6 +12,8 @@ local beautiful = require("beautiful") local ipairs = ipairs local tonumber = tonumber +local math = require("math") +local naughty = require("naughty") local uselesspiral = {} @@ -18,19 +21,32 @@ 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 + 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 + wa.height = (wa.height / 2) else - wa.width = wa.width / 2 + wa.width = (wa.width / 2) end end @@ -49,10 +65,10 @@ local function spiral(p, spiral) end local wa2 = {} - wa2.x = wa.x - wa2.y = wa.y - wa2.height = wa.height - wa2.width = wa.width + 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 @@ -64,8 +80,6 @@ local function spiral(p, spiral) top = false left = false - gap_factor = (useless_gap / 100) * 2 - if wa2.y == static_wa.y then top = true end @@ -75,17 +89,17 @@ local function spiral(p, spiral) end if top then - wa2.height = wa2.height - (2 + gap_factor) * useless_gap - wa2.y = wa2.y + useless_gap + wa2.height = wa2.height - useless_gap + wa2.y = wa2.y - (useless_gap / 2) else - wa2.height = wa2.height - (1 + gap_factor) * useless_gap + wa2.height = wa2.height - (useless_gap / 2) end if left then - wa2.width = wa2.width - (2 + gap_factor) * useless_gap - wa2.x = wa2.x + useless_gap + wa2.width = wa2.width - useless_gap + wa2.x = wa2.x - (useless_gap / 2) else - wa2.width = wa2.width - (1 + gap_factor) * useless_gap + wa2.width = wa2.width - (useless_gap / 2) end end -- End of useless gap. diff --git a/layout/uselesstile.lua b/layout/uselesstile.lua index e496500..47aa4a4 100644 --- a/layout/uselesstile.lua +++ b/layout/uselesstile.lua @@ -2,12 +2,14 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham + * (c) 2014 projektile + * (c) 2013 Luke Bonham * (c) 2009 Donald Ephraim Curtis * (c) 2008 Julien Danjolu --]] +local naughty = require("naughty") local tag = require("awful.tag") local beautiful = require("beautiful") local ipairs = ipairs @@ -22,6 +24,14 @@ local function tile_group(cls, wa, orientation, fact, group) -- 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 + global_border = tonumber(beautiful.global_border_width) or 0 + if global_border < 0 then global_border = 0 end + + -- BW!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1 -- get our orientation right local height = "height" @@ -36,7 +46,8 @@ local function tile_group(cls, wa, orientation, fact, group) end -- make this more generic (not just width) - available = wa[width] - (group.coord - wa[x]) + --if for top + available = wa[width] - (group.coord - wa[x]) -- it's truly not here -- find our total values local total_fact = 0 @@ -58,20 +69,19 @@ local function tile_group(cls, wa, orientation, fact, group) end total_fact = total_fact + fact[i] end - size = math.min(size, available) - + size = math.min(size, (available - global_border)) local coord = wa[y] local geom = {} local used_size = 0 - local unused = wa[height] + local unused = wa[height] - (global_border * 2) local stat_coord = wa[x] --stat_coord = size for c = group.first,group.last do local i = c - group.first +1 - geom[width] = size + geom[width] = size - global_border geom[height] = math.floor(unused * fact[i] / total_fact) - geom[x] = group.coord - geom[y] = coord + geom[x] = group.coord + global_border + (useless_gap / 2) + geom[y] = coord + global_border + (useless_gap / 2) coord = coord + geom[height] unused = unused - geom[height] @@ -88,8 +98,6 @@ local function tile_group(cls, wa, orientation, fact, group) top = false left = false - gap_factor = (useless_gap / 100) * 2 - if geom[y] == wa[y] then top = true end @@ -99,17 +107,17 @@ local function tile_group(cls, wa, orientation, fact, group) end if top then - geom[height] = geom[height] - (2 + gap_factor) * useless_gap + geom[height] = geom[height] - (2 * useless_gap) geom[y] = geom[y] + useless_gap else - geom[height] = geom[height] - (1 + gap_factor) * useless_gap + geom[height] = geom[height] - useless_gap end if left then - geom[width] = geom[width] - (2 + gap_factor) * useless_gap + geom[width] = geom[width] - (2 * useless_gap) geom[x] = geom[x] + useless_gap else - geom[width] = geom[width] - (1 + gap_factor) * useless_gap + geom[width] = geom[width] - useless_gap end end -- End of useless gap. @@ -136,6 +144,11 @@ local function tile(param, orientation) y = "x" end + -- A global border can be defined with + -- beautiful.global_border_width + global_border = tonumber(beautiful.global_border_width) or 0 + if global_border < 0 then global_border = 0 end + local cls = param.clients local nmaster = math.min(tag.getnmaster(t), #cls) local nother = math.max(#cls - nmaster,0) @@ -181,7 +194,7 @@ local function tile(param, orientation) end for i = 1,ncol do -- Try to get equal width among remaining columns - local size = math.min( (wasize - (coord - wa[x])) / (ncol - i + 1) ) + local size = math.min((wasize - (coord - wa[x])) / (ncol - i + 1)) --+ (global_border/(ncol))/(ncol+i^2) local first = last + 1 last = last + math.floor((#cls - last)/(ncol - i + 1)) -- tile the column and update our current x coordinate @@ -228,3 +241,4 @@ uselesstile.arrange = uselesstile.right.arrange uselesstile.name = uselesstile.right.name return uselesstile + -- 2.39.5 From 274a5f43c92b4b1285bebbc9f72b432fab1c19d4 Mon Sep 17 00:00:00 2001 From: projektile Date: Mon, 22 Sep 2014 11:29:46 -0400 Subject: [PATCH 11/16] set card --- widgets/alsa.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/widgets/alsa.lua b/widgets/alsa.lua index f62a150..114e2b2 100644 --- a/widgets/alsa.lua +++ b/widgets/alsa.lua @@ -23,14 +23,14 @@ local alsa = {} local function worker(args) local args = args or {} local timeout = args.timeout or 5 - local channel = args.channel or "Master" + local channel = args.channel or "Master -c 1" local settings = args.settings or function() end alsa.widget = wibox.widget.textbox('') function alsa.update() - local f = assert(io.popen('amixer -M get ' .. channel)) - local mixer = f:read("*a") + local f = assert(io.popen('amixer get ' .. channel)) + local mixer = f:read("*all") f:close() volume_now = {} -- 2.39.5 From 4919f4ada59a938432d8a385a6ef29a704cea3da Mon Sep 17 00:00:00 2001 From: projektile Date: Mon, 22 Sep 2014 11:36:50 -0400 Subject: [PATCH 12/16] fix border offset --- layout/uselesstile.lua | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/layout/uselesstile.lua b/layout/uselesstile.lua index 47aa4a4..dfbaf68 100644 --- a/layout/uselesstile.lua +++ b/layout/uselesstile.lua @@ -28,10 +28,11 @@ local function tile_group(cls, wa, orientation, fact, group) -- A global border can be defined with -- beautiful.global_border_width - global_border = tonumber(beautiful.global_border_width) or 0 + local global_border = tonumber(beautiful.global_border_width) or 0 if global_border < 0 then global_border = 0 end - -- BW!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1 + -- Themes border width requires an offset + local bw = tonumber(beautiful.border_width) or 0 -- get our orientation right local height = "height" @@ -78,8 +79,8 @@ local function tile_group(cls, wa, orientation, fact, group) --stat_coord = size for c = group.first,group.last do local i = c - group.first +1 - geom[width] = size - global_border - geom[height] = math.floor(unused * fact[i] / total_fact) + geom[width] = size - global_border - (bw * 2) + geom[height] = math.floor(unused * fact[i] / total_fact) - (bw * 2) geom[x] = group.coord + global_border + (useless_gap / 2) geom[y] = coord + global_border + (useless_gap / 2) @@ -144,11 +145,6 @@ local function tile(param, orientation) y = "x" end - -- A global border can be defined with - -- beautiful.global_border_width - global_border = tonumber(beautiful.global_border_width) or 0 - if global_border < 0 then global_border = 0 end - local cls = param.clients local nmaster = math.min(tag.getnmaster(t), #cls) local nother = math.max(#cls - nmaster,0) -- 2.39.5 From 229d0d3860126bfbf190c54d8edad18174fe017a Mon Sep 17 00:00:00 2001 From: projektile Date: Mon, 22 Sep 2014 11:54:03 -0400 Subject: [PATCH 13/16] remove naughty --- layout/uselesspiral.lua | 1 - layout/uselesstile.lua | 1 - 2 files changed, 2 deletions(-) diff --git a/layout/uselesspiral.lua b/layout/uselesspiral.lua index 7c72912..ba63bca 100644 --- a/layout/uselesspiral.lua +++ b/layout/uselesspiral.lua @@ -13,7 +13,6 @@ local beautiful = require("beautiful") local ipairs = ipairs local tonumber = tonumber local math = require("math") -local naughty = require("naughty") local uselesspiral = {} diff --git a/layout/uselesstile.lua b/layout/uselesstile.lua index dfbaf68..eccfdad 100644 --- a/layout/uselesstile.lua +++ b/layout/uselesstile.lua @@ -9,7 +9,6 @@ --]] -local naughty = require("naughty") local tag = require("awful.tag") local beautiful = require("beautiful") local ipairs = ipairs -- 2.39.5 From 96d23431f249efc4103b2a9d6e8e98775ce2d917 Mon Sep 17 00:00:00 2001 From: Dainese Hsiao Date: Thu, 25 Sep 2014 13:15:39 +0800 Subject: [PATCH 14/16] Add yawn localization zh_TW --- widgets/yawn/localizations/zh_TW | 61 ++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 widgets/yawn/localizations/zh_TW diff --git a/widgets/yawn/localizations/zh_TW b/widgets/yawn/localizations/zh_TW new file mode 100644 index 0000000..03644c1 --- /dev/null +++ b/widgets/yawn/localizations/zh_TW @@ -0,0 +1,61 @@ +Now:|現在: +Sun:|週日: +Mon:|週一: +Tue:|週二: +Wed:|週三: +Thu:|週四: +Fri:|週五: +Sat:|週六: +Mostly Sunny|晴時多雲 +Sunny|大太陽 +Sun|太陽 +Rain/Thunder|雨時有雷 +Isolated Thunderstorms|局部雷雨 +Scattered Thunderstorms|零星雷雨 +Thundershowers|雷陣雨 +Thunderstorms|雷雨 +Thunder in the Vicinity|局部性雷雨 +Thunder|雷嗚 +AM|上午 +PM|下午 +Early|早 +Late|晚有 +Few|短暫 +Severe|惡劣 +Clear|晴朗 +Fair|晴 +Partly|局部 +Mostly|大部 +Cloudy|多雲 +Clouds|有雲 +Scattered Showers|零星陣雨 +Light Snow Showers|小陣雪 +Snow Showers|陣雪 +Heavy Snow|大雪 +Scattered Snow Showers|零星陣雪 +Mixed Rain And Snow|雨夾雪 +Mixed Rain And Sleet|雨時雨夾雪 +Mixed Snow And Sleet|雪時雨夾雪 +Mixed Rain And Hail|雨夾冰雹 +Snow Flurries|陣雪 +Blowing Snow|風吹雪 +Blowing Rain|風吹雨 +Heavy Rain|大雨 +Freezing Rain|凍雨 +Showers|陣雨 +Light Rain|小雨 +Heavy|大 +Rain|雨 +Windy|有風 +Wind|風 +Snow|雪 +Sleet|冰珠 +Freezing Drizzle|凍毛毛雨 +Light Drizzle|細雨 +Drizzle|毛毛雨 +Hail|冰雹 +Fog|霧 +Foggy|有霧 +Haze|霾 +Light|小 +With|與 -- 2.39.5 From c4c149d2dfd5e9434dc357b66da6f9d1747258f2 Mon Sep 17 00:00:00 2001 From: luke bonham Date: Fri, 26 Sep 2014 12:41:35 +0200 Subject: [PATCH 15/16] undo 'set card' from projektile/master --- widgets/alsa.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/widgets/alsa.lua b/widgets/alsa.lua index 114e2b2..f62a150 100644 --- a/widgets/alsa.lua +++ b/widgets/alsa.lua @@ -23,14 +23,14 @@ local alsa = {} local function worker(args) local args = args or {} local timeout = args.timeout or 5 - local channel = args.channel or "Master -c 1" + local channel = args.channel or "Master" local settings = args.settings or function() end alsa.widget = wibox.widget.textbox('') function alsa.update() - local f = assert(io.popen('amixer get ' .. channel)) - local mixer = f:read("*all") + local f = assert(io.popen('amixer -M get ' .. channel)) + local mixer = f:read("*a") f:close() volume_now = {} -- 2.39.5 From 99db3d7ac26154bc6a87f68cb5922010fce7aa04 Mon Sep 17 00:00:00 2001 From: luke bonham Date: Sat, 11 Oct 2014 14:17:05 +0200 Subject: [PATCH 16/16] #66 removed hardcoded screen def in widgets notification --- widgets/alsabar.lua | 2 -- widgets/bat.lua | 2 -- widgets/calendar.lua | 1 - widgets/contrib/init.lua | 1 - widgets/contrib/task.lua | 6 +----- widgets/fs.lua | 2 -- widgets/imap.lua | 1 - widgets/mpd.lua | 1 - widgets/net.lua | 1 - widgets/yawn/init.lua | 1 - 10 files changed, 1 insertion(+), 17 deletions(-) diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index 8675cb5..96d57b0 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -77,12 +77,10 @@ function alsabar.notify() alsabar._notify = naughty.notify ({ replaces_id = alsabar._notify.id, preset = preset, - screen = client.focus and client.focus.screen or 1 }) else alsabar._notify = naughty.notify ({ preset = preset, - screen = client.focus and client.focus.screen or 1 }) end end diff --git a/widgets/bat.lua b/widgets/bat.lua index 2ace758..572d099 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -130,14 +130,12 @@ local function worker(args) bat.id = naughty.notify({ preset = bat_notification_critical_preset, replaces_id = bat.id, - screen = client.focus and client.focus.screen or 1 }).id elseif nperc <= 15 then bat.id = naughty.notify({ preset = bat_notification_low_preset, replaces_id = bat.id, - screen = client.focus and client.focus.screen or 1 }).id end end diff --git a/widgets/calendar.lua b/widgets/calendar.lua index d07a5b4..f9aed39 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -99,7 +99,6 @@ function calendar:show(t_out, inc_offset) fg = calendar.fg, bg = calendar.bg, timeout = tims, - screen = client.focus and client.focus.screen or 1 }) end diff --git a/widgets/contrib/init.lua b/widgets/contrib/init.lua index 9a9fa63..ccaed82 100644 --- a/widgets/contrib/init.lua +++ b/widgets/contrib/init.lua @@ -8,7 +8,6 @@ Licensed under GNU General Public License v2 * (c) 2013, Luke Bonham - * (c) 2010-2012, Peter Hofmann --]] diff --git a/widgets/contrib/task.lua b/widgets/contrib/task.lua index 6e6ebae..2e30cdc 100644 --- a/widgets/contrib/task.lua +++ b/widgets/contrib/task.lua @@ -2,7 +2,6 @@ --[[ Licensed under GNU General Public License v2 - * (c) 2013, Luke Bonham * (c) 2013, Jan Xie --]] @@ -20,7 +19,7 @@ local tonumber = tonumber local setmetatable = setmetatable -- Taskwarrior notification --- lain.widgets.task +-- lain.widgets.contrib.task local task = {} local task_notification = nil @@ -52,7 +51,6 @@ function task:show() fg = task.fg, bg = task.bg, timeout = task.timeout, - screen = client.focus and client.focus.screen or 1 }) end @@ -75,7 +73,6 @@ function task:prompt_add() fg = task.fg, bg = task.bg, timeout = task.timeout, - screen = client.focus and client.focus.screen or 1 }) end, nil, @@ -109,7 +106,6 @@ function task:prompt_search() fg = task.fg, bg = task.bg, timeout = task.timeout, - screen = client.focus and client.focus.screen or 1 }) end, nil, diff --git a/widgets/fs.lua b/widgets/fs.lua index f78cfe0..3b99cba 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -47,7 +47,6 @@ function fs:show(t_out) preset = fs_notification_preset, text = ws, timeout = t_out, - screen = client.focus and client.focus.screen or 1 }) end @@ -100,7 +99,6 @@ local function worker(args) timeout = 8, fg = "#000000", bg = "#FFFFFF", - screen = client.focus and client.focus.screen or 1 }) helpers.set_map("fs", true) else diff --git a/widgets/imap.lua b/widgets/imap.lua index 3a6da8d..d4b4cba 100644 --- a/widgets/imap.lua +++ b/widgets/imap.lua @@ -77,7 +77,6 @@ local function worker(args) naughty.notify({ preset = mail_notification_preset, text = nt, - screen = client.focus and client.focus.screen or 1 }) end diff --git a/widgets/mpd.lua b/widgets/mpd.lua index 385b5bb..7fd611d 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -91,7 +91,6 @@ local function worker(args) preset = mpd_notification_preset, icon = "/tmp/mpdcover.png", replaces_id = mpd.id, - screen = client.focus and client.focus.screen or 1 }).id end elseif mpd_now.state ~= "pause" diff --git a/widgets/net.lua b/widgets/net.lua index 9575000..2bfd375 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -88,7 +88,6 @@ local function worker(args) position = "top_left", icon = helpers.icons_dir .. "no_net.png", fg = notify_fg or "#FFFFFF", - screen = client.focus and client.focus.screen or 1 }) helpers.set_map(iface, false) end diff --git a/widgets/yawn/init.lua b/widgets/yawn/init.lua index aa58ed1..b034395 100644 --- a/widgets/yawn/init.lua +++ b/widgets/yawn/init.lua @@ -167,7 +167,6 @@ function yawn.show(t_out) text = weather_data, icon = sky, timeout = t_out, - screen = client.focus and client.focus.screen or 1 }) end -- 2.39.5