aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/ui/osd.lua
blob: fc74ed9e115aede62dbc8aed9be7f7d72b9151ef (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
--- Heavy inspiration from a design made by https://github.com/tsukki9696

local awful = require "awful"
local beautiful = require "beautiful"
local gtimer = require "gears.timer"
local phosphor = require "assets.phosphor"
local qmath = require "quarrel.math"
local qui = require "quarrel.ui"
local qvars = require "quarrel.vars"
local rubato = require "lib.rubato"
local wibox = require "wibox"

local osd = {}

local widget = qui.popup {
    ontop = true,
    visible = false,
    placement = function(d)
        awful.placement.top(d, {
            margins = {
                top = beautiful.useless_gap * 2,
            },
        })
    end,
    minimum_height = qvars.char_height * 2,
    -- minimum_width = awful.screen.focused().geometry.width / 2,
    widget = {
        {
            widget = wibox.container.place,

            qui.icon {
                icon = phosphor.speaker_simple_none_fill,
                widget = {
                    forced_height = qvars.char_height * 1.2,
                    forced_width = qvars.char_height * 1.2,
                    id = "icon",
                },
            },
        },
        {
            widget = wibox.container.place,
            {
                widget = wibox.widget.progressbar,
                max_value = 100,
                value = 20,
                forced_height = qvars.char_height / 1.5,
                forced_width = qvars.expanded_bar_size
                    - (qvars.big_padding + qvars.big_padding * 2 + qvars.padding * 2)
                    - (qvars.char_height / 1.25 + qvars.padding) * 3,
                color = qvars.colors.yellow,
                background_color = qvars.colors.black,
                shape = qvars.shape,
                id = "progress",
            },
        },

        {
            widget = wibox.widget.textbox,
            text = "20%",
            font = qui.font(1.2),
            id = "percentage",
        },
        layout = wibox.layout.fixed.horizontal,
        spacing = qvars.big_padding,
    },
}

local timer

local anim = rubato.timed {
    duration = qvars.anim_duration,
    intro = qvars.anim_intro,
    pos = 0,
    subscribed = function(pos)
        widget.opacity = pos
        if pos == 0 then
            widget.visible = false
        elseif not widget.visible then
            widget.visible = true
        elseif pos == 1 then
            timer:start()
        end
    end,
}

timer = gtimer {
    timeout = 1,
    callback = function()
        anim.target = 0
    end,
    single_shot = true,
}

function osd.notify(icon, value, max)
    anim.target = 1
    widget:get_children_by_id("icon")[1].image = icon
    widget:get_children_by_id("progress")[1].value = value
    widget:get_children_by_id("progress")[1].max_value = max
    widget:get_children_by_id("percentage")[1].text = tostring(qmath.percentage(value, max)) .. "%"
end

return osd