Made the mailbox widget update properly

This commit is contained in:
Yessiest 2022-03-21 12:56:53 +00:00
parent db4839b716
commit 5a78139515
2 changed files with 19 additions and 52 deletions

View File

@ -6,8 +6,7 @@ local wibox = require("wibox")
local naughty = require("naughty") local naughty = require("naughty")
local awmtk_status,awmtk = pcall(require,"awmtk") local awmtk_status,awmtk = pcall(require,"awmtk")
local dbus_config = require("naughty.dbus") local dbus_config = require("naughty.dbus")
local widget = {} return function(args)
local function worker(args)
local args = args or {} local args = args or {}
-- Set up style variables -- Set up style variables
style = awmtk.style(awmtk.defaults,args.style or {},"mailbox_") style = awmtk.style(awmtk.defaults,args.style or {},"mailbox_")
@ -15,30 +14,24 @@ local function worker(args)
style.mailbox_button_height = style.mailbox_button_heihgt or 40 style.mailbox_button_height = style.mailbox_button_heihgt or 40
args.mail_limit = args.mail_limit or 8 args.mail_limit = args.mail_limit or 8
-- Create a notifications list -- Create a notifications list
notifications_list = { local notifications_list = wibox.widget {
spacing = style.mailbox_container_spacing_vertical, spacing = style.mailbox_container_spacing_vertical,
layout = wibox.layout.fixed.vertical, layout = wibox.layout.fixed.vertical,
} }
-- Function to regenerate the popup local notification_popup = awful.popup(style.container(
local gen_popup = function() {
return awful.popup(style.container(
{ {
{ text = "Notifications: ",
text = "This widget will store your notification", widget = wibox.widget.textbox
widget = wibox.widget.textbox },
}, notifications_list,
notifications_list, layout = wibox.layout.fixed.vertical,
layout = wibox.layout.fixed.vertical, forced_width = style.mailbox_container_width
forced_width = style.mailbox_container_width },{
},{ visible = false,
visible = false, ontop = true,
ontop = true, }
} ))
))
end
-- Initialize the popup
local notification_popup = gen_popup()
-- Create a mailbox button -- Create a mailbox button
args.screen.notify_widget = style.icon ( args.screen.notify_widget = style.icon (
@ -60,10 +53,8 @@ local function worker(args)
end end
} }
) )
local notify_widget = args.screen.notify_widget naughty.config.notify_callback = function(update_args)
local update_notifications = function(update_args) notifications_list:add(style.button(
if notification_popup.visible then notification_popup.visible = false end
table.insert(notifications_list,1,style.button(
{ {
(update_args.icon and { (update_args.icon and {
image = update_args.icon, image = update_args.icon,
@ -93,21 +84,10 @@ local function worker(args)
end end
} }
)) ))
if #notifications_list >= args.mail_limit then
table.remove(notifications_list,args.mail_limit)
end
notification_popup = gen_popup()
for s in screen do for s in screen do
s.notify_widget:emit_signal("notification::arrived") s.notify_widget.bg = style.mailbox_button_bg_focus
end end
return update_args return update_args
end end
args.screen.notify_widget:connect_signal("notification::arrived",function() return args.screen.notify_widget
args.screen.notify_widget.bg = style.mailbox_button_bg_focus
end)
naughty.config.notify_callback = update_notifications
widget = notify_widget
return notify_widget
end end
return setmetatable(widget, { __call = function(_, ...) return worker(...) end })

View File

@ -96,25 +96,12 @@ local function worker(args)
},{},{ },{},{
function() function()
if popup.visible then if popup.visible then
--rows = nil
popup.visible = not popup.visible popup.visible = not popup.visible
else else
--init_popup()
popup:move_next_to(mouse.current_widget_geometry) popup:move_next_to(mouse.current_widget_geometry)
end end
end end
}) })
widget = clip_widget
root.keys(gears.table.join(
root.keys(),
awful.key({global.modkey,"Control"},"b",function()
pager:next()
end),
awful.key({global.modkey,"Control"},"v",function()
pager:prev()
end)
))
return clip_widget return clip_widget
end end