diff options
author | delta <darkussdelta@gmail.com> | 2024-03-05 14:48:59 +0100 |
---|---|---|
committer | delta <darkussdelta@gmail.com> | 2024-03-05 14:48:59 +0100 |
commit | 510ef8e178929cf5e0c7fd5a5120fecf5f1b79f2 (patch) | |
tree | 3582e5cd7d000335ca94f2a009f3aed57bd86919 /.config/awesome/signals | |
parent | 95ba8030f722a616cff06c122dcfb2f63e25cf45 (diff) |
idk anymore
Diffstat (limited to '.config/awesome/signals')
-rw-r--r-- | .config/awesome/signals/awesome.lua | 20 | ||||
-rw-r--r-- | .config/awesome/signals/client.lua | 18 | ||||
-rw-r--r-- | .config/awesome/signals/init.lua | 1 | ||||
-rw-r--r-- | .config/awesome/signals/naughty.lua | 292 | ||||
-rw-r--r-- | .config/awesome/signals/screen.lua | 9 |
5 files changed, 269 insertions, 71 deletions
diff --git a/.config/awesome/signals/awesome.lua b/.config/awesome/signals/awesome.lua index 37b9bdb..4ed3d32 100644 --- a/.config/awesome/signals/awesome.lua +++ b/.config/awesome/signals/awesome.lua @@ -1,27 +1,31 @@ -- Taken from https://www.reddit.com/r/awesomewm/comments/syjolb/comment/hy0xy35/ -awesome.connect_signal('exit', function(reason_restart) - if not reason_restart then return end +awesome.connect_signal("exit", function(reason_restart) + if not reason_restart then + return + end - local file = io.open('/tmp/awesomewm-last-selected-tags', 'w+') + local file = io.open("/tmp/awesomewm-last-selected-tags", "w+") for s in screen do - file:write(s.selected_tag.index, '\n') + file:write(s.selected_tag.index, "\n") end file:close() end) -awesome.connect_signal('startup', function() - local file = io.open('/tmp/awesomewm-last-selected-tags', 'r') - if not file then return end +awesome.connect_signal("startup", function() + local file = io.open("/tmp/awesomewm-last-selected-tags", "r") + if not file then + return + end local selected_tags = {} for line in file:lines() do table.insert(selected_tags, tonumber(line)) end - + for s in screen do local i = selected_tags[s.index] local t = s.tags[i] diff --git a/.config/awesome/signals/client.lua b/.config/awesome/signals/client.lua index 31f3d9c..8788735 100644 --- a/.config/awesome/signals/client.lua +++ b/.config/awesome/signals/client.lua @@ -1,23 +1,15 @@ local qvars = require "quarrel.vars" -local rectangle = require "gears.shape".rectangle +local rectangle = require("gears.shape").rectangle +local conductor = require "ui.conductor" --- io.popen spams logs, don't use --- client.connect_signal("property::name", function(c) --- if not c.pid then return end --- local out = io.popen("readlink /proc/" .. c.pid .. "/exe") --- local name = c.name --- if out ~= nil then --- name = out:read("*a"):sub(0, -2):match("[^\\/]+$") or name --- end --- c.name = string.lower(name) --- end) - -client.connect_signal("request::manage", function (c) +client.connect_signal("request::manage", function(c) c.shape = qvars.shape if c.maximized then c.maximized = false c.maximized = true end + + -- conductor.update() end) local function handle_corners(c) diff --git a/.config/awesome/signals/init.lua b/.config/awesome/signals/init.lua index 5641a96..a18290e 100644 --- a/.config/awesome/signals/init.lua +++ b/.config/awesome/signals/init.lua @@ -2,4 +2,3 @@ require "signals.naughty" require "signals.awesome" require "signals.screen" require "signals.client" - diff --git a/.config/awesome/signals/naughty.lua b/.config/awesome/signals/naughty.lua index 90594c1..cc096e7 100644 --- a/.config/awesome/signals/naughty.lua +++ b/.config/awesome/signals/naughty.lua @@ -1,54 +1,254 @@ -local awful = require "awful" -local beautiful = require "beautiful" +local gdebug = require "gears.debug" local naughty = require "naughty" -local qvars = require "quarrel.vars" -local wibox = require "wibox" - -naughty.connect_signal("request::display", function(n) - naughty.layout.box { - notification = n, - placement = function(d) - return awful.placement.right(d, { - margins = beautiful.useless_gap * 2 - }) - end, - widget_template = { - widget = wibox.container.margin, - margins = qvars.big_padding, - { - { - widget = naughty.widget.icon, - notification = n - }, - { - widget = wibox.container.place, - valign = "center", - halign = "center", - { - { - widget = naughty.widget.title, - notification = n - }, - { - widget = naughty.widget.message, - notification = n - }, - -- spacing = 4, - layout = wibox.layout.fixed.vertical, - } - }, - fill_space = true, - spacing = n.icon and qvars.big_padding or 0, - layout = wibox.layout.fixed.horizontal - } - } +local ndbus = require "naughty.dbus" +local qdelegate = require "quarrel.delegate" +local wicked = require "ui.wicked" + +---@diagnostic disable-next-line:redundant-parameter +ndbus._notif_methods.Notify = qdelegate(function(env, sender, object_path, interface, method, parameters, invocation) + local appname, replaces_id, app_icon, title, text, actions, hints, expire = env.unpack(parameters.value) + + local args = {} + if text ~= "" then + args.message = text + if title ~= "" then + args.title = title + end + else + if title ~= "" then + args.message = title + else + -- FIXME: We have to reply *something* to the DBus invocation. + -- Right now this leads to a memory leak, I think. + return + end + end + + if appname ~= "" then + args.appname = appname --TODO v6 Remove this. + args.app_name = appname + end + + local preset = args.preset or env.cst.config.defaults + local notification + if actions then + args.actions = {} + + for i = 1, #actions, 2 do + local action_id = actions[i] + local action_text = actions[i + 1] + + if action_id == "default" then + args.run = function() + env.sendActionInvoked(notification.id, "default") + notification:destroy(env.cst.notification_closed_reason.dismissed_by_user) + end + elseif action_id ~= nil and action_text ~= nil then + local a = env.naction { + name = action_text, + id = action_id, + position = (i - 1) / 2 + 1, + } + + -- Right now `gears` doesn't have a great icon implementation + -- and `naughty` doesn't depend on `menubar`, so delegate the + -- icon "somewhere" using a request. + if hints["action-icons"] and action_id ~= "" then + naughty.emit_signal("request::action_icon", a, "dbus", { id = action_id }) + end + + a:connect_signal("invoked", function() + env.sendActionInvoked(notification.id, action_id) + + if not notification.resident then + notification:destroy(env.cst.notification_closed_reason.dismissed_by_user) + end + end) + + table.insert(args.actions, a) + end + end + end + args.destroy = function(reason) + env.sendNotificationClosed(notification.id, reason) + end + local legacy_data = { -- This data used to be generated by AwesomeWM's C code + type = "method_call", + interface = interface, + path = object_path, + member = method, + sender = sender, + bus = "session", } -end) + if + not preset.callback + or ( + type(preset.callback) == "function" + and preset.callback(legacy_data, appname, replaces_id, app_icon, title, text, actions, hints, expire) + ) + then + if app_icon ~= "" then + args.app_icon = app_icon + end + + if hints.icon_data or hints.image_data or hints["image-data"] then + -- Icon data is a bit complex and hence needs special care: + -- .value breaks with the array of bytes (ay) that we get here. + -- So, bypass it and look up the needed value differently + local icon_condidates = {} + for k, v in parameters:get_child_value(7 - 1):pairs() do + if k == "image-data" then + icon_condidates[1] = v -- not deprecated + break + elseif k == "image_data" then -- deprecated + icon_condidates[2] = v + elseif k == "icon_data" then -- deprecated + icon_condidates[3] = v + end + end + + -- The order is mandated by the spec. + local icon_data = icon_condidates[1] or icon_condidates[2] or icon_condidates[3] + + -- icon_data is an array: + -- 1 -> width + -- 2 -> height + -- 3 -> rowstride + -- 4 -> has alpha + -- 5 -> bits per sample + -- 6 -> channels + -- 7 -> data + + -- Get the value as a GVariant and then use LGI's special + -- GVariant.data to get that as an LGI byte buffer. That one can + -- then by converted to a string via its __tostring metamethod. + local data = tostring(icon_data:get_child_value(7 - 1).data) + args.image = env.convert_icon(icon_data[1], icon_data[2], icon_data[3], icon_data[6], data) + + -- Convert all animation frames. + if naughty.image_animations_enabled then + args.images = { args.image } + + if #icon_data > 7 then + for frame = 8, #icon_data do + data = tostring(icon_data:get_child_value(frame - 1).data) + + table.insert( + args.images, + env.convert_icon(icon_data[1], icon_data[2], icon_data[3], icon_data[6], data) + ) + end + end + end + end + + -- Alternate ways to set the icon. The specs recommends to allow both + -- the icon and image to co-exist since they serve different purpose. + -- However in case the icon isn't specified, use the image. + args.image = args.image + or hints["image-path"] -- not deprecated + or hints["image_path"] -- deprecated + + if naughty.image_animations_enabled then + args.images = args.images or {} + end + + if replaces_id and replaces_id ~= "" and replaces_id ~= 0 then + args.replaces_id = replaces_id + end + if expire and expire > -1 then + args.timeout = expire / 1000 + end + + args.freedesktop_hints = hints + + -- Not very pretty, but given the current format is documented in the + -- public API... well, whatever... + if hints and hints.urgency then + for name, key in pairs(env.urgency) do + local b = string.char(hints.urgency) + if key == b then + args.urgency = name + end + end + end + + args.urgency = args.urgency or "normal" + + -- Try to update existing objects when possible + notification = naughty.get_by_id(replaces_id) + + if notification then + if not notification._private._unique_sender then + -- If this happens, the notification is either trying to + -- highjack content created within AwesomeWM or it is garbage + -- to begin with. + gdebug.print_warning( + "A notification has been received, but tried to update " + .. "the content of a notification it does not own." + ) + elseif notification._private._unique_sender ~= sender then + -- Nothing says you cannot and some scripts may do it + -- accidentally, but this is rather unexpected. + gdebug.print_warning( + "Notification " + .. notification.title + .. " is being updated" + .. "by a different DBus connection (" + .. sender + .. "), this is " + .. "suspicious. The original connection was " + .. notification._private._unique_sender + ) + end + + for k, v in pairs(args) do + if k == "destroy" then + k = "destroy_cb" + end + notification[k] = v + end + + -- Update the icon if necessary. + if app_icon ~= notification._private.app_icon then + notification._private.app_icon = app_icon + + naughty._emit_signal_if("request::icon", function() + if notification._private.icon then + return true + end + end, notification, "dbus_clear", {}) + end + + -- Even if no property changed, restart the timeout. + notification:reset_timeout() + else + -- Only set the sender for new notifications. + args._unique_sender = sender + args._foreign = true + + notification = env.nnotif(args) + + notification:connect_signal("destroyed", function(_, r) + args.destroy(r) + end) + end + + invocation:return_value(env.GLib.Variant("(u)", { notification.id })) + return + end + + invocation:return_value(env.GLib.Variant("(u)", { env.nnotif._gen_next_id() })) +end, ndbus._notif_methods.Notify) + +naughty.connect_signal("request::display", wicked) naughty.connect_signal("request::display_error", function(message, startup) naughty.notification { urgency = "critical", - title = "Oops, an error happened"..(startup and " during startup!" or "!"), - message = message + title = "Oops, an error happened" .. (startup and " during startup!" or "!"), + message = message, } + + gdebug.print_error("[Error" .. (startup and "during startup" or "") .. "]: " .. message) end) diff --git a/.config/awesome/signals/screen.lua b/.config/awesome/signals/screen.lua index 706bf56..57f4f98 100644 --- a/.config/awesome/signals/screen.lua +++ b/.config/awesome/signals/screen.lua @@ -4,8 +4,11 @@ local gtable = require "gears.table" screen.connect_signal("request::desktop_decoration", function(s) for i, tag in ipairs(cfg.tags) do - awful.tag.add(tostring(i), gtable.crush({ - screen = s - }, tag)) + awful.tag.add( + tostring(i), + gtable.crush({ + screen = s, + }, tag) + ) end end) |