reno/widgets/notifications.lua

102 lines
4.2 KiB
Lua
Raw Normal View History

2022-08-31 12:20:58 +00:00
-- This file is part of Reno desktop.
--
-- Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
--
-- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
-- Notifications pager
2022-08-30 07:00:35 +00:00
local awful = require("awful")
local pager = require("pager")
local beautiful = require("beautiful")
local gears = require("gears")
local wibox = require("wibox")
local awmtk2 = require("awmtk2")
local naughty = require("naughty")
return function(args)
2022-09-05 21:54:11 +00:00
local style = awmtk2.create_style("notifications",
awmtk2.generic.iconified_widget,args.style)
2022-08-30 07:00:35 +00:00
local templates = awmtk2.create_template_lib("notifications",awmtk2.templates,args.templates)
local t = awmtk2.build_templates(templates,style)
local layout = wibox.widget({
layout = wibox.layout.fixed.vertical,
spacing = style.base.spacing
})
2022-08-31 12:20:58 +00:00
local pager = pager(layout,{},args.max_notifications or 8)
2022-08-30 07:00:35 +00:00
local test_xclip = os.execute("xclip -version")
2022-08-31 12:20:58 +00:00
local result = test_xclip
if _VERSION:match("5.1") then
result = (test_xclip == 0)
end
local count = 0
2022-08-30 07:00:35 +00:00
local popup = awful.popup(t.popup({
t.textbox({
markup = "Click to copy text"
}),
((not result) and t.textbox({
markup = "(xclip is not installed)"
})),
t.container(layout),
2022-08-31 12:20:58 +00:00
t.textbox({
id = "page_id",
markup = "Page 0/0"
}),
2022-08-30 07:00:35 +00:00
layout = wibox.layout.fixed.vertical
},{
visible = false
}))
naughty.config.notify_callback = function(update_args)
2022-08-31 12:20:58 +00:00
count = count + 1
2022-08-30 07:00:35 +00:00
local w = wibox.widget(t.button(t.article({
icon = update_args.icon,
title = update_args.title or "(No title)",
description = update_args.text
}),{
forced_height = style.button.height,
forced_width = style.button.width
}))
2022-08-31 12:20:58 +00:00
local page_index = popup.widget:get_children_by_id("page_id")[1]
page_index:set_markup("Page "..tostring(pager.index+1).."/"..
tostring(math.ceil(count/(args.max_notifications or 8))))
2022-08-30 07:00:35 +00:00
w:connect_signal("button::press",style.button.onpress)
w:connect_signal("button::release",style.button.onrelease)
2022-08-31 12:20:58 +00:00
w:connect_signal("button::press",function(self,x,y,button)
if button == 1 then
clip = io.open("/tmp/clip","w")
clip:write(update_args.text)
clip:close()
awful.spawn.with_shell("cat /tmp/clip | xclip -selection clipboard")
elseif button == 4 then
pager:prev()
page_index:set_markup("Page "..tostring(pager.index+1).."/"..
tostring(math.ceil(count/(args.max_notifications or 8))))
elseif button == 5 then
pager:next()
page_index:set_markup("Page "..tostring(pager.index+1).."/"..
tostring(math.ceil(count/(args.max_notifications or 8))))
end
2022-08-30 07:00:35 +00:00
end)
2022-08-31 12:20:58 +00:00
table.insert(pager.list,1,w)
pager:update()
2022-08-30 07:00:35 +00:00
return update_args
end
-- create popup button
local clip_widget = wibox.widget(t.button({
image = beautiful["notifications-area-symbolic"],
resize = true,
widget = wibox.widget.imagebox,
}))
clip_widget:connect_signal("button::press",style.button.onpress)
clip_widget:connect_signal("button::release",style.button.onrelease)
clip_widget:connect_signal("button::press",function(self,x,y,button)
if button == 1 then
popup.visible = (not popup.visible)
if popup.visible then
popup:move_next_to(mouse.current_widget_geometry)
end
end
end)
return clip_widget
end