aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/components/signals/client.lua
blob: 0b44d62ec11782df76ce47e537b1d80a7441c29d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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)