From 6e50ee2a41507ce5bc166ff2b837b99eee7f9fd2 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 12 Mar 2019 14:25:23 -0400 Subject: [PATCH] naughty: Add a shared default widget_template for the notifications. This will be shared by the notifications stored in a wibox/wibar and the ones using a popup. It extends the constraint and margins container to take care of some boilerplate code. While other widgets have their own public API, those 2 are private since they are not different enough to warrent a new public module. --- lib/naughty/widget/_default.lua | 85 +++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 lib/naughty/widget/_default.lua diff --git a/lib/naughty/widget/_default.lua b/lib/naughty/widget/_default.lua new file mode 100644 index 000000000..c964d9da6 --- /dev/null +++ b/lib/naughty/widget/_default.lua @@ -0,0 +1,85 @@ +---------------------------------------------------------------------------- +--- The default widget template for the notifications. +-- +-- @author Emmanuel Lepage Vallee <elv1313@gmail.com> +-- @copyright 2019 Emmanuel Lepage Vallee +-- @classmod naughty.widget._default +---------------------------------------------------------------------------- + +local wibox = require("wibox") +local actionlist = require("naughty.list.actions") +local wtitle = require("naughty.widget.title") +local wmessage = require("naughty.widget.message") +local wicon = require("naughty.widget.icon") +local wbg = require("naughty.container.background") +local beautiful = require("beautiful") +local dpi = require("beautiful").xresources.apply_dpi + +-- It is not worth doing a special widget for this. +local function notif_size() + local constraint = wibox.container.constraint() + constraint:set_strategy("max") + constraint:set_width(beautiful.notification_max_width or dpi(500)) + + rawset(constraint, "set_notification", function(_, notif) + constraint._private.notification = notif + local s = false + + if notif.width and notif.width ~= beautiful.notification_max_width then + constraint.width = notif.width + s = true + end + if notif.height then + constraint.height = notif.height + s = true + end + + constraint.strategy = s and "exact" or "max" + end) + + return constraint +end + +-- It is not worth doing a special widget for this either. +local function notif_margins() + local margins = wibox.container.margin() + margins:set_margins(beautiful.notification_margin or 4) + + rawset(margins, "set_notification", function(_, notif) + if notif.margin then + margins:set_margins(notif.margin) + end + end) + + return margins +end + +-- Used as a fallback when no widget_template is provided, emulate the legacy +-- widget. +return { + { + { + { + { + wicon, + { + wtitle, + wmessage, + spacing = 4, + layout = wibox.layout.fixed.vertical, + }, + fill_space = true, + spacing = 4, + layout = wibox.layout.fixed.horizontal, + }, + actionlist, + spacing = 10, + layout = wibox.layout.fixed.vertical, + }, + widget = notif_margins, + }, + id = "background_role", + widget = wbg, + }, + widget = notif_size, +}