From 52deb6911957f840a0191f73c8a9626bd9ff5086 Mon Sep 17 00:00:00 2001 From: luke bonham Date: Wed, 29 Jul 2015 13:21:59 +0200 Subject: [PATCH] #126 extended to every supported widget --- widgets/alsabar.lua | 6 +++++ widgets/calendar.lua | 51 +++++++++++++++++++++++----------------- widgets/contrib/moc.lua | 5 ++++ widgets/contrib/task.lua | 32 +++++++++++++++---------- widgets/fs.lua | 22 ++++++++++------- widgets/imap.lua | 24 ++++++++++++------- widgets/mpd.lua | 6 +++++ widgets/weather.lua | 37 +++++++++++++++++------------ wiki | 2 +- 9 files changed, 118 insertions(+), 67 deletions(-) diff --git a/widgets/alsabar.lua b/widgets/alsabar.lua index 5fe74c4..f504cc0 100644 --- a/widgets/alsabar.lua +++ b/widgets/alsabar.lua @@ -15,6 +15,7 @@ local naughty = require("naughty") local io = { popen = io.popen } local math = { modf = math.modf } +local mouse = mouse local string = { format = string.format, match = string.match, rep = string.rep } @@ -75,6 +76,10 @@ function alsabar.notify() .. string.rep(" ", alsabar.notifications.bar_size - int) .. "]" + if alsabar.followmouse then + preset.screen = mouse.screen + end + if alsabar._notify ~= nil then alsabar._notify = naughty.notify ({ replaces_id = alsabar._notify.id, @@ -102,6 +107,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.bar = awful.widget.progressbar() diff --git a/widgets/calendar.lua b/widgets/calendar.lua index a03503e..2ed26a0 100644 --- a/widgets/calendar.lua +++ b/widgets/calendar.lua @@ -14,6 +14,7 @@ local naughty = require("naughty") local io = { popen = io.popen } local os = { date = os.date } +local mouse = mouse local tonumber = tonumber local setmetatable = setmetatable @@ -89,6 +90,12 @@ function calendar:show(t_out, inc_offset, scr) .. "" f:close() + if calendar.followmouse then + local scrp = mouse.screen + else + local scrp = scr or calendar.scr_pos + end + cal_notification = naughty.notify({ text = c_text, icon = calendar.notify_icon, @@ -96,36 +103,38 @@ function calendar:show(t_out, inc_offset, scr) fg = calendar.fg, bg = calendar.bg, timeout = tims, - screen = scr or 1 + screen = scrp }) end function calendar:attach(widget, args) local args = args or {} - calendar.cal = args.cal or "/usr/bin/cal" - calendar.post_cal = args.post_cal or "" - calendar.icons = args.icons or icons_dir .. "cal/white/" - calendar.font = args.font or beautiful.font:sub(beautiful.font:find(""), - beautiful.font:find(" ")) - 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 "#FFFFFF" - calendar.position = args.position or "top_right" - calendar.scr_pos = args.scr_pos or mouse.screen - - calendar.offset = 0 + + calendar.cal = args.cal or "/usr/bin/cal" + calendar.post_cal = args.post_cal or "" + calendar.icons = args.icons or icons_dir .. "cal/white/" + calendar.font = args.font or beautiful.font:sub(beautiful.font:find(""), + beautiful.font:find(" ")) + 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 "#FFFFFF" + calendar.position = args.position or "top_right" + calendar.scr_pos = args.scr_pos or 1 + calendar.followmouse = args.followmouse 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) - 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))) + 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 return setmetatable(calendar, { __call = function(_, ...) return create(...) end }) diff --git a/widgets/contrib/moc.lua b/widgets/contrib/moc.lua index cfdbec7..bd25ffb 100644 --- a/widgets/contrib/moc.lua +++ b/widgets/contrib/moc.lua @@ -29,6 +29,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 settings = args.settings or function() end local mpdcover = helpers.scripts_dir .. "mpdcover" @@ -82,6 +83,10 @@ 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 + end + moc.id = naughty.notify({ preset = moc_notification_preset, icon = "/tmp/mpdcover.png", diff --git a/widgets/contrib/task.lua b/widgets/contrib/task.lua index 3b8039f..6f131e2 100644 --- a/widgets/contrib/task.lua +++ b/widgets/contrib/task.lua @@ -12,6 +12,7 @@ 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 @@ -36,6 +37,12 @@ function task:show(scr_pos) local f, c_text + if task.followmouse then + local scrp = mouse.screen + else + local scrp = scr_pos or task.scr_pos + end + f = io.popen('task') c_text = "