aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/ui/wicked/init.lua
blob: ddbf9127158cdbb11ca3554ecbf10510e5648cf2 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
local awful = require "awful"
local beautiful = require "beautiful"
local gshape = require "gears.shape"
local naughty = require "naughty"
local qui = require "quarrel.ui"
local qvars = require "quarrel.vars"
local wibox = require "wibox"
local rtimed = require("lib.rubato").timed
local easing = require("lib.rubato").easing
local gtimer = require "gears.timer"
local qmarkup = require "quarrel.markup"

return function(n)
    local intertext_margin = (n.title ~= "" or n.message ~= "") and qvars.padding or 0
    local title_height = n.title ~= "" and qvars.char_height or 0
    local message_height = n.message ~= "" and qvars.char_height or 0
    -- local app_name_height = n.app_name ~= "" and
    local app_name
    if n.app_name == "" then
        app_name = n._private._foreign and "Unknown" or "Awesome"
    else
        app_name = n.app_name
    end

    local notif = naughty.layout.box {
        notification = n,
        placement = function(d)
            return awful.placement.right(d, {
                margins = beautiful.useless_gap * 2,
            })
        end,
        bg = qvars.colors.transparent,
        border_width = 0,
        shape = gshape.rectangle,
        widget_template = {
            widget = wibox.container.constraint,
            height = qvars.big_padding * 2
                + qvars.char_height
                + qvars.border_width
                + qvars.big_padding * 2
                -- + title_height
                -- + message_height
                -- + intertext_margin,
                + (
                    n.icon and qvars.char_height * 2 + qvars.padding
                    or (title_height + message_height + intertext_margin)
                ),

            strategy = "exact",
            {
                qui.styled {
                    widget = wibox.container.background,
                    point = function(geo, args)
                        return {
                            x = args.parent.width,
                            y = args.parent.height - geo.height,
                        }
                    end,
                    {
                        {
                            widget = wibox.container.margin,
                            margins = qvars.big_padding,
                            {
                                {
                                    widget = wibox.widget.textbox,
                                    markup = qmarkup(app_name, { bold = true }),
                                },
                                nil,
                                {

                                    widget = wibox.container.radialprogressbar,
                                    max_value = qvars.notif_timeout,
                                    border_color = qvars.colors.black,
                                    color = qvars.colors.yellow,
                                    border_width = qvars.border_width,
                                    forced_height = qvars.char_height,
                                    forced_width = qvars.char_height,
                                    id = "progress",
                                },
                                layout = wibox.layout.align.horizontal,
                            },
                        },
                        {
                            widget = wibox.container.constraint,
                            height = qvars.border_width,
                            width = beautiful.notification_max_width,
                            strategy = "exact",
                            {
                                widget = wibox.container.background,
                                bg = qvars.colors.bright.black,
                            },
                        },
                        {
                            widget = wibox.container.margin,
                            margins = qvars.big_padding,
                            {
                                widget = wibox.container.constraint,
                                height = n.icon and qvars.char_height * 2 + qvars.padding
                                    or (title_height + message_height + intertext_margin),
                                strategy = "exact",
                                {
                                    {
                                        widget = wibox.container.background,
                                        {
                                            widget = naughty.widget.icon,
                                            shape = qvars.shape,
                                            notification = n,
                                        },
                                    },
                                    {
                                        {
                                            widget = wibox.container.constraint,
                                            height = title_height,
                                            strategy = "exact",
                                            {
                                                widget = wibox.widget.textbox,
                                                text = n.title or "",
                                            },
                                        },
                                        {
                                            widget = wibox.container.constraint,
                                            height = message_height,
                                            strategy = "exact",
                                            {
                                                widget = wibox.widget.textbox,
                                                text = n.message or "",
                                            },
                                        },
                                        spacing = intertext_margin,
                                        layout = wibox.layout.fixed.vertical,
                                    },
                                    fill_space = true,
                                    spacing = n.icon and qvars.big_padding or nil,
                                    layout = wibox.layout.fixed.horizontal,
                                },
                            },
                        },
                        layout = wibox.layout.fixed.vertical,
                    },
                    id = "bg",
                },
                layout = wibox.layout.manual,
                id = "manual",
            },
        },
    }

    local hiding = false
    local old_destroy = notif._private.destroy_callback

    local progress = rtimed {
        duration = n.timeout,
        pos = 0,
        easing = easing.none,
        clamp_position = true,
        subscribed = function(pos)
            notif.widget:get_children_by_id("progress")[1].value = pos
        end,
    }

    local position = rtimed {
        duration = qvars.anim_duration * 2,
        intro = qvars.anim_intro * 2,
        pos = 0,
        easing = easing.quadratic,
        clamp_position = true,
        subscribed = function(pos)
            gtimer.delayed_call(function()
                notif.widget.widget:move(1, function(geo, args)
                    if pos == 0 and hiding then
                        old_destroy()
                    end
                    return {
                        x = args.parent.width - pos,
                        y = args.parent.height - geo.height,
                    }
                end)
            end)
        end,
    }
    local opacity = rtimed {
        duration = qvars.anim_duration * 2,
        intro = qvars.anim_intro * 2,
        easing = easing.quadratic,
        pos = 0,
        clamp_position = true,
        subscribed = function(pos)
            notif.opacity = pos
        end,
    }

    n:disconnect_signal("destroyed", notif._private.destroy_callback)
    function notif._private.destroy_callback()
        opacity.target = 0
        position.target = 0
        hiding = true
    end
    n:weak_connect_signal("destroyed", notif._private.destroy_callback)

    opacity.target = 1
    position.target = qvars.char_width * 48
    progress.target = qvars.notif_timeout
end