aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/ui/osd/init.lua
blob: 85cb1d7deddc862e7b8881f8c040d74395399c41 (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
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 qdebug = require "quarrel.debug"
local gshape = require "gears.shape"
local qanim = require "quarrel.animation"
local qvars = require "quarrel.vars"
local rubato = require "lib.rubato"
local wibox = require "wibox"
-- local mpris_widget = require "ui.osd.mpris"

local MAX_HEIGHT = qui.BIG_PADDING * 2 + qui.CHAR_HEIGHT

local M = {
    _toggled = false
}

local geo = awful.screen.focused().geometry

M._w_popup = qui.animateable_shape(qui.popup {
    ontop = true,
    visible = true,
    shape = function(cr, w, h)
        gshape.partially_rounded_rect(cr, w, h, true, true, false, false, qui.BORDER_RADIUS)
    end,
    placement = function (d)
        return (awful.placement.bottom + awful.placement.center_horizontal)(d, {
            offset = {
                y = qui.BORDER_WIDTH + 1 -- Needs one more pixel to fully occlude the bottom border for some reason
            }
        })
    end,
    -- placement = function(d)
    --     awful.placement.bottom(d, {
    --         margins = {
    --             top = beautiful.useless_gap * 2,
    --         },
    --     })
    -- end,
    -- x = geo.width / 2,
    -- y = geo.height - 10,
    minimum_height = qui.CHAR_HEIGHT,
    widget = {
        widget = wibox.widget.textbox,
        text = "blah"
    }
    -- widget = mpris_widget
    -- minimum_width = awful.screen.focused().geometry.width / 2,
    -- widget = {
    --     {
    --         widget = wibox.container.place,
    --
    --         qui.icon {
    --             icon = phosphor.speaker_simple_none_fill,
    --             widget = {
    --                 forced_height = qui.CHAR_HEIGHT * 1.2,
    --                 forced_width = qui.CHAR_HEIGHT * 1.2,
    --                 id = "icon",
    --             },
    --         },
    --     },
    --     {
    --         widget = wibox.container.place,
    --         {
    --             widget = wibox.widget.progressbar,
    --             max_value = 100,
    --             value = 20,
    --             forced_height = qui.CHAR_HEIGHT / 1.5,
    --             forced_width = qvars.expanded_bar_size
    --                 - (qui.BIG_PADDING + qui.BIG_PADDING * 2 + qui.PADDING * 2)
    --                 - (qui.CHAR_HEIGHT / 1.25 + qui.PADDING) * 3,
    --             color = qcolor.palette.yellow(),
    --             background_color = qcolor.palette.border.variant,
    --             shape = qui.shape,
    --             id = "progress",
    --         },
    --     },
    --
    --     {
    --         widget = wibox.widget.textbox,
    --         text = "20%",
    --         font = qui.font(1.2),
    --         id = "percentage",
    --     },
    --     layout = wibox.layout.fixed.horizontal,
    --     spacing = qui.BIG_PADDING,
    -- },
})

M._t_height = qanim:new {
    duration = qvars.anim_duration,
    pos = 0,
    easing = qvars.easing,
    subscribed = function(pos)
        M._w_popup.shape_height = pos
    end,
}

-- TODO: optimize the search algo to be more efficient and not require making fresnel invisible
M._t_opacity = rubato.timed {
    duration = qvars.anim_duration,
    pos = 0,
    subscribed = function(pos)
        M._w_popup.opacity = pos

        if pos == 0 then
            M._w_popup.visible = false
        else
            M._w_popup.visible = true
        end
    end,
}

M._t_height:set(qui.BIG_PADDING * 2 + qui.CHAR_HEIGHT)
M._t_opacity.target = 1

function M:show()
    self._toggled = true
    self._t_opacity.target = 1
    self._t_height:set(MAX_HEIGHT)
end

function M:hide()
    self._toggled = false
    self._t_opacity.target = 0
    self._t_height:set(0)
end

function M:toggle()
    if self._toggled then
        self:hide()
    else
        self:show()
    end
end

-- local timer
--
-- local anim = rubato.timed {
--     duration = qvars.anim_duration,
--     intro = qvars.anim_intro,
--     pos = 1,
--     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 M.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 M