naughty: Add 2 levels of fallback when the `widget_template` fails.
* First, it will try the default widget template * If that fails, the `request::fallback` handler will use the legacy popup. Ref #2829
This commit is contained in:
parent
c0ef0c8802
commit
dcd034dcac
|
@ -17,6 +17,7 @@ local popup = require("awful.popup")
|
||||||
local awcommon = require("awful.widget.common")
|
local awcommon = require("awful.widget.common")
|
||||||
local placement = require("awful.placement")
|
local placement = require("awful.placement")
|
||||||
local abutton = require("awful.button")
|
local abutton = require("awful.button")
|
||||||
|
local gpcall = require("gears.protected_call")
|
||||||
local dpi = require("beautiful").xresources.apply_dpi
|
local dpi = require("beautiful").xresources.apply_dpi
|
||||||
|
|
||||||
local default_widget = require("naughty.widget._default")
|
local default_widget = require("naughty.widget._default")
|
||||||
|
@ -136,10 +137,25 @@ end
|
||||||
-- @param widget
|
-- @param widget
|
||||||
|
|
||||||
local function generate_widget(args, n)
|
local function generate_widget(args, n)
|
||||||
local w = wibox.widget.base.make_widget_from_value(
|
local w = gpcall(wibox.widget.base.make_widget_from_value,
|
||||||
args.widget_template or (n and n.widget_template) or default_widget
|
args.widget_template or (n and n.widget_template) or default_widget
|
||||||
)
|
)
|
||||||
|
|
||||||
|
-- This will happen if the user-provided widget_template is invalid and/or
|
||||||
|
-- got unexpected notifications.
|
||||||
|
if not w then
|
||||||
|
w = gpcall(wibox.widget.base.make_widget_from_value, default_widget)
|
||||||
|
|
||||||
|
-- In case this happens in an error message itself, make sure the
|
||||||
|
-- private error popup code knowns it and can revert to the fallback
|
||||||
|
-- popup.
|
||||||
|
if not w then
|
||||||
|
n._private.widget_template_failed = true
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
if w.set_width then
|
if w.set_width then
|
||||||
w:set_width(n.max_width or beautiful.notification_max_width or dpi(500))
|
w:set_width(n.max_width or beautiful.notification_max_width or dpi(500))
|
||||||
end
|
end
|
||||||
|
@ -231,6 +247,9 @@ local function new(args)
|
||||||
-- Generate the box before the popup is created to avoid the size changing
|
-- Generate the box before the popup is created to avoid the size changing
|
||||||
new_args.widget = generate_widget(new_args, new_args.notification)
|
new_args.widget = generate_widget(new_args, new_args.notification)
|
||||||
|
|
||||||
|
-- It failed, request::fallback will be used, there is nothing left to do.
|
||||||
|
if not new_args.widget then return nil end
|
||||||
|
|
||||||
local ret = popup(new_args)
|
local ret = popup(new_args)
|
||||||
ret._private.args = new_args
|
ret._private.args = new_args
|
||||||
|
|
||||||
|
|
|
@ -308,7 +308,9 @@ end
|
||||||
function naughty.default_notification_handler(notification, args)
|
function naughty.default_notification_handler(notification, args)
|
||||||
-- This is a fallback for users whose config doesn't have the newer
|
-- This is a fallback for users whose config doesn't have the newer
|
||||||
-- `request::display` section.
|
-- `request::display` section.
|
||||||
if naughty.has_display_handler then return end
|
if naughty.has_display_handler and not notification._private.widget_template_failed then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- If request::display is called more than once, simply make sure the wibox
|
-- If request::display is called more than once, simply make sure the wibox
|
||||||
-- is visible.
|
-- is visible.
|
||||||
|
|
Loading…
Reference in New Issue