From bcd37ae4ae4f0e5d11ab6d8f6a9580e840447327 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Fri, 6 Jan 2017 11:21:19 +0100 Subject: [PATCH] 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