diff --git a/util/quake.lua b/util/quake.lua index 01891b0..d2a49d3 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -60,6 +60,8 @@ function quake:display() client.floating = true client.border_width = self.border client.size_hints_honor = false + local maximized = client.maximized + local fullscreen = client.fullscreen client:geometry(self.geometry[self.screen.index] or self:compute_size()) -- Set not sticky and on top @@ -74,11 +76,17 @@ function quake:display() -- Toggle display if self.visible then client.hidden = false + client.maximized = self.maximized + client.fullscreen = self.fullscreen client:raise() self.last_tag = self.screen.selected_tag client:tags({self.screen.selected_tag}) capi.client.focus = client - else + else + self.maximized = maximized + self.fullscreen = fullscreen + client.maximized = false + client.fullscreen = false client.hidden = true local ctags = client:tags() for i, t in pairs(ctags) do @@ -135,6 +143,9 @@ function quake:new(config) conf.horiz = conf.horiz or "left" -- left, right or center conf.geometry = {} -- internal use + conf.maximized = false + conf.fullscreen = false + local dropdown = setmetatable(conf, { __index = quake }) capi.client.connect_signal("manage", function(c) diff --git a/widget/alsa.lua b/widget/alsa.lua index 3b6c6d6..49b2cf0 100644 --- a/widget/alsa.lua +++ b/widget/alsa.lua @@ -15,8 +15,8 @@ local string = string -- lain.widget.alsa local function factory(args) - local alsa = { widget = wibox.widget.textbox() } local args = args or {} + local alsa = { widget = args.widget or wibox.widget.textbox() } local timeout = args.timeout or 5 local settings = args.settings or function() end diff --git a/widget/bat.lua b/widget/bat.lua index 3cb801c..7e69e1f 100644 --- a/widget/bat.lua +++ b/widget/bat.lua @@ -26,8 +26,8 @@ local function factory(args) return end - local bat = { widget = wibox.widget.textbox() } local args = args or {} + local bat = { widget = args.widget or wibox.widget.textbox() } local timeout = args.timeout or 30 local notify = args.notify or "on" local full_notify = args.full_notify or notify @@ -136,7 +136,7 @@ local function factory(args) -- "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] + bat_now.status = bat_now.n_status[1] or "N/A" for _,status in ipairs(bat_now.n_status) do if status == "Discharging" or status == "Charging" then bat_now.status = status diff --git a/widget/cal.lua b/widget/cal.lua index 928a7bd..1f6df2b 100644 --- a/widget/cal.lua +++ b/widget/cal.lua @@ -126,14 +126,14 @@ local function factory(args) end function cal.show(seconds, month, year, scr) - cal.notification_preset.text = tconcat(cal.build(month, year)) + local text = tconcat(cal.build(month, year)) if cal.three then local current_month, current_year = cal.month, cal.year local prev_month, prev_year = cal.getdate(cal.month, cal.year, -1) local next_month, next_year = cal.getdate(cal.month, cal.year, 1) - cal.notification_preset.text = string.format("%s\n\n%s\n\n%s", - tconcat(cal.build(prev_month, prev_year)), cal.notification_preset.text, + text = string.format("%s\n\n%s\n\n%s", + tconcat(cal.build(prev_month, prev_year)), text, tconcat(cal.build(next_month, next_year))) cal.month, cal.year = current_month, current_year end @@ -143,7 +143,8 @@ local function factory(args) preset = cal.notification_preset, screen = cal.followtag and awful.screen.focused() or scr or 1, icon = cal.icon, - timeout = type(seconds) == "number" and seconds or cal.notification_preset.timeout or 5 + timeout = type(seconds) == "number" and seconds or cal.notification_preset.timeout or 5, + text = text } end diff --git a/widget/contrib/moc.lua b/widget/contrib/moc.lua index f429c77..e9a7dfe 100644 --- a/widget/contrib/moc.lua +++ b/widget/contrib/moc.lua @@ -18,8 +18,8 @@ local string = string -- lain.widget.contrib.moc local function factory(args) - local moc = { widget = wibox.widget.textbox() } local args = args or {} + local moc = { widget = args.widget or wibox.widget.textbox() } 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)$" diff --git a/widget/cpu.lua b/widget/cpu.lua index f4cce73..b823a5f 100644 --- a/widget/cpu.lua +++ b/widget/cpu.lua @@ -16,8 +16,8 @@ local tostring = tostring -- lain.widget.cpu local function factory(args) - local cpu = { core = {}, widget = wibox.widget.textbox() } local args = args or {} + local cpu = { core = {}, widget = args.widget or wibox.widget.textbox() } local timeout = args.timeout or 2 local settings = args.settings or function() end diff --git a/widget/fs.lua b/widget/fs.lua index 58fbf93..53eac66 100644 --- a/widget/fs.lua +++ b/widget/fs.lua @@ -26,8 +26,9 @@ local query = query_size .. "," .. query_free .. "," .. query_used -- lain.widget.fs local function factory(args) + local args = args or {} local fs = { - widget = wibox.widget.textbox(), + widget = args.widget or wibox.widget.textbox(), units = { [1] = "Kb", [2] = "Mb", [3] = "Gb", [4] = "Tb", [5] = "Pb", [6] = "Eb", @@ -50,7 +51,6 @@ local function factory(args) } end - local args = args or {} local timeout = args.timeout or 600 local partition = args.partition local threshold = args.threshold or 99 @@ -69,11 +69,10 @@ local function factory(args) end function fs.update() - local notifytable = { [1] = string.format("%-10s %4s\t%6s\t%6s\t\n", "path", "used", "free", "size") } local pathlen = 10 - local maxpathidx = 1 fs_now = {} + local notifypaths = {} for _, mount in ipairs(Gio.unix_mounts_get()) do local path = Gio.unix_mount_get_mount_path(mount) local root = Gio.File.new_for_path(path) @@ -90,19 +89,16 @@ local function factory(args) fs_now[path] = { units = fs.units[units], percentage = math.floor(100 * used / size), -- used percentage - size = size / math.pow(1024, math.floor(units)), - used = used / math.pow(1024, math.floor(units)), - free = free / math.pow(1024, math.floor(units)) + size = size / math.pow(1024, units), + used = used / math.pow(1024, units), + free = free / math.pow(1024, units) } if fs_now[path].percentage > 0 then -- don't notify unused file systems - notifytable[#notifytable+1] = string.format("\n%-10s %3s%%\t%6.2f\t%6.2f\t%s", path, - math.floor(fs_now[path].percentage), fs_now[path].free, fs_now[path].size, - fs_now[path].units) + notifypaths[#notifypaths+1] = path if #path > pathlen then pathlen = #path - maxpathidx = #notifytable end end end @@ -125,14 +121,11 @@ local function factory(args) end end - if pathlen > 10 then -- if are there paths longer than 10 chars, reformat first column accordingly - local pathspaces - for i = 1, #notifytable do - pathspaces = notifytable[i]:match("[ ]+") - if i ~= maxpathidx and pathspaces then - notifytable[i] = notifytable[i]:gsub(pathspaces, pathspaces .. string.rep(" ", pathlen - 10)) - end - end + local fmt = "%-" .. tostring(pathlen) .. "s %4s\t%6s\t%6s\n" + local notifytable = { [1] = string.format(fmt, "path", "used", "free", "size") } + fmt = "\n%-" .. tostring(pathlen) .. "s %3s%%\t%6.2f\t%6.2f %s" + for _, path in ipairs(notifypaths) do + notifytable[#notifytable+1] = string.format(fmt, path, fs_now[path].percentage, fs_now[path].free, fs_now[path].size, fs_now[path].units) end fs.notification_preset.text = tconcat(notifytable) diff --git a/widget/imap.lua b/widget/imap.lua index b3d9dc7..c8eb2c9 100644 --- a/widget/imap.lua +++ b/widget/imap.lua @@ -17,8 +17,8 @@ local tonumber = tonumber -- lain.widget.imap local function factory(args) - local imap = { widget = wibox.widget.textbox() } local args = args or {} + local imap = { widget = args.widget or wibox.widget.textbox() } local server = args.server local mail = args.mail local password = args.password diff --git a/widget/mem.lua b/widget/mem.lua index 3dcae2b..90933b6 100644 --- a/widget/mem.lua +++ b/widget/mem.lua @@ -14,8 +14,8 @@ local gmatch, lines, floor = string.gmatch, io.lines, math.floor -- lain.widget.mem local function factory(args) - local mem = { widget = wibox.widget.textbox() } local args = args or {} + local mem = { widget = args.widget or wibox.widget.textbox() } local timeout = args.timeout or 2 local settings = args.settings or function() end diff --git a/widget/mpd.lua b/widget/mpd.lua index 01f28e6..13994bd 100644 --- a/widget/mpd.lua +++ b/widget/mpd.lua @@ -19,8 +19,8 @@ local string = string -- lain.widget.mpd local function factory(args) - local mpd = { widget = wibox.widget.textbox() } local args = args or {} + local mpd = { widget = args.widget or wibox.widget.textbox() } local timeout = args.timeout or 2 local password = (args.password and #args.password > 0 and string.format("password %s\\n", args.password)) or "" local host = args.host or os.getenv("MPD_HOST") or "127.0.0.1" diff --git a/widget/net.lua b/widget/net.lua index 805b577..ea2510c 100644 --- a/widget/net.lua +++ b/widget/net.lua @@ -15,8 +15,8 @@ local string = string -- lain.widget.net local function factory(args) - local net = { widget = wibox.widget.textbox(), devices = {} } local args = args or {} + local net = { widget = args.widget or wibox.widget.textbox(), devices = {} } local timeout = args.timeout or 2 local units = args.units or 1024 -- KB local notify = args.notify or "on" @@ -29,13 +29,14 @@ local function factory(args) 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() + function net.get_devices() + net.iface = {} -- reset at every call helpers.line_callback("ip link", function(line) net.iface[#net.iface + 1] = not string.match(line, "LOOPBACK") and string.match(line, "(%w+): <") or nil end) end - if #net.iface == 0 then net.get_device() end + if #net.iface == 0 then net.get_devices() end function net.update() -- These are the totals over all specified interfaces @@ -67,13 +68,19 @@ local function factory(args) dev_now.last_t = now_t dev_now.last_r = now_r - if wifi_state == "on" and helpers.first_line(string.format("/sys/class/net/%s/uevent", dev)) == "DEVTYPE=wlan" and string.match(dev_now.carrier, "1") then + if wifi_state == "on" and helpers.first_line(string.format("/sys/class/net/%s/uevent", dev)) == "DEVTYPE=wlan" then dev_now.wifi = true - dev_now.signal = tonumber(string.match(helpers.lines_from("/proc/net/wireless")[3], "(%-%d+%.)")) or nil + if string.match(dev_now.carrier, "1") then + dev_now.signal = tonumber(string.match(helpers.lines_from("/proc/net/wireless")[3], "(%-%d+%.)")) or nil + end + else + dev_now.wifi = false end - if eth_state == "on" and helpers.first_line(string.format("/sys/class/net/%s/uevent", dev)) ~= "DEVTYPE=wlan" and string.match(dev_now.carrier, "1") then + if eth_state == "on" and helpers.first_line(string.format("/sys/class/net/%s/uevent", dev)) ~= "DEVTYPE=wlan" then dev_now.ethernet = true + else + dev_now.ethernet = false end net.devices[dev] = dev_now diff --git a/widget/pulse.lua b/widget/pulse.lua index f63fe55..5a6fb0b 100644 --- a/widget/pulse.lua +++ b/widget/pulse.lua @@ -15,8 +15,8 @@ local type = type -- lain.widget.pulse local function factory(args) - local pulse = { widget = wibox.widget.textbox(), device = "N/A" } local args = args or {} + local pulse = { widget = args.widget or wibox.widget.textbox(), device = "N/A" } local timeout = args.timeout or 5 local settings = args.settings or function() end diff --git a/widget/sysload.lua b/widget/sysload.lua index adf3e03..38cdd9d 100644 --- a/widget/sysload.lua +++ b/widget/sysload.lua @@ -14,8 +14,8 @@ local open, match = io.open, string.match -- lain.widget.sysload local function factory(args) - local sysload = { widget = wibox.widget.textbox() } local args = args or {} + local sysload = { widget = args.widget or wibox.widget.textbox() } local timeout = args.timeout or 2 local settings = args.settings or function() end diff --git a/widget/temp.lua b/widget/temp.lua index e909b32..8b646a0 100644 --- a/widget/temp.lua +++ b/widget/temp.lua @@ -13,8 +13,8 @@ local tonumber = tonumber -- lain.widget.temp local function factory(args) - local temp = { widget = wibox.widget.textbox() } local args = args or {} + local temp = { widget = args.widget or wibox.widget.textbox() } local timeout = args.timeout or 30 local tempfile = args.tempfile or "/sys/devices/virtual/thermal/thermal_zone0/temp" local settings = args.settings or function() end diff --git a/widget/weather.lua b/widget/weather.lua index 9c1e797..3cf5102 100644 --- a/widget/weather.lua +++ b/widget/weather.lua @@ -21,13 +21,13 @@ local tonumber = tonumber -- lain.widget.weather local function factory(args) - local weather = { widget = wibox.widget.textbox() } local args = args or {} + local weather = { widget = args.widget or wibox.widget.textbox() } local APPID = args.APPID or "3e321f9414eaedbfab34983bda77a66e" -- lain's default local timeout = args.timeout or 60 * 15 -- 15 min local timeout_forecast = args.timeout or 60 * 60 * 24 -- 24 hrs - local current_call = args.current_call or "curl -s 'http://api.openweathermap.org/data/2.5/weather?id=%s&units=%s&lang=%s&APPID=%s'" - local forecast_call = args.forecast_call or "curl -s 'http://api.openweathermap.org/data/2.5/forecast/daily?id=%s&units=%s&lang=%s&cnt=%s&APPID=%s'" + local current_call = args.current_call or "curl -s 'https://api.openweathermap.org/data/2.5/weather?id=%s&units=%s&lang=%s&APPID=%s'" + local forecast_call = args.forecast_call or "curl -s 'https://api.openweathermap.org/data/2.5/forecast/daily?id=%s&units=%s&lang=%s&cnt=%s&APPID=%s'" local city_id = args.city_id or 0 -- placeholder local units = args.units or "metric" local lang = args.lang or "en"