local awful = require "awful" local beautiful = require "beautiful" -- local cairo = require "lgi".cairo local gears = require "gears" local xresources = require "beautiful.xresources" local dpi = xresources.apply_dpi local wibox = require "wibox" client.connect_signal("property::name", function(c) if not c then return end -- Sometimes c is nil for some reason 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("property::urgent", function(c) if c.class ~= "kitty" then c:activate({ switch_to_tag = true }) c.urgent = false end end) client.connect_signal("request::manage", function (c) local parent = c.transient_for if parent then c:move_to_tag(parent.first_tag) end if not c.pid then return end awful.spawn.easy_async({ "readlink", "/proc/" .. c.pid .. "/exe" }, function(name) c.name = string.lower(name:match("[^\\/]+$") or name) end) -- Forcefully set the correct icon for a client -- Taken from https://discord.com/channels/702548301299580939/893586726885425163/947173452073287722 (Author: Orlando#0171) and modified a little bit -- local icon_cache = Get_icon(beautiful.get().icon_theme, c) -- if type(icon_cache) ~= "userdata" then -- local s = gears.surface(icon_cache) -- local img = cairo.ImageSurface.create(cairo.Format.ARGB32, s:get_width(), s:get_height()) -- local cr = cairo.Context(img) -- cr:set_source_surface(s, 0, 0) -- cr:paint() -- c.icon = img._native -- end end) client.connect_signal("property::maximized", function(c) c.border_width = beautiful.border_width end) client.connect_signal("request::titlebars", function(c) local buttons = gears.table.join( awful.button({ }, 1, function() c:emit_signal("request::activate", "titlebar", {raise = true}) awful.mouse.client.move(c) end), awful.button({ }, 3, function() c:emit_signal("request::activate", "titlebar", {raise = true}) awful.mouse.client.resize(c) end) ) awful.titlebar.enable_tooltip = false awful.titlebar(c) : setup { -- { -- widget = wibox.container.margin, -- left = dpi(8), -- awful.titlebar.widget.titlewidget(c), -- buttons = buttons -- }, nil, { widget = wibox.widget.base.empty_widget(), buttons = buttons }, { { awful.titlebar.widget.maximizedbutton (c), awful.titlebar.widget.minimizebutton (c), awful.titlebar.widget.closebutton (c), spacing = dpi(4), layout = wibox.layout.fixed.horizontal }, margins = dpi(5), widget = wibox.container.margin, }, layout = wibox.layout.align.horizontal } end)