luca-awesome-dotfiles/home/.config/awesome/ui/sidebar/init.lua
2022-11-23 03:44:40 +01:00

157 lines
3.5 KiB
Lua

-- ## Sidebar ##
-- ~~~~~~~~~~~~~
-- requirements
-- ~~~~~~~~~~~~
local awful = require("awful")
local gears = require("gears")
local wibox = require("wibox")
local beautiful = require ("beautiful")
local dpi = beautiful.xresources.apply_dpi
local rubato = require("lib.rubato")
-- Var
--------
local width = dpi(420)
local height = awful.screen.focused().geometry.height - dpi(60)
-- Helper
-----------
local function round_widget(radius)
return function(cr,w,h)
gears.shape.rounded_rect(cr,w,h,radius)
end
end
local function center_widget(widgets)
return wibox.widget {
nil,
{
nil,
widgets,
expand = 'none',
layout = wibox.layout.align.horizontal,
},
expand = 'none',
layout = wibox.layout.align.vertical,
}
end
local function box_widget(widgets, width, height)
return wibox.widget {
{
{
widgets,
margins = dpi(16),
widget = wibox.container.margin,
},
forced_width = dpi(width),
forced_height = dpi(height),
shape = round_widget(8),
bg = colors.brightblack,
widget = wibox.container.background,
},
margins = {left = dpi(20), right = dpi(20)},
widget = wibox.container.margin,
}
end
local aa = wibox.widget.textbox()
-- Get widgets
local profile_widget = require("ui.sidebar.profile")
local player_widget = require("ui.sidebar.player")
local sliders_widget = require("ui.sidebar.sliders")
local weather_widget = require("ui.sidebar.weather")
local calendar_widget = require("ui.sidebar.calendar")
-- Combine some widgets
local profile = box_widget(profile_widget, 380, 150)
local sliders = box_widget(sliders_widget, 380, 120)
local player = box_widget(player_widget, 380, 80)
local weather = box_widget(weather_widget, 380, 180)
local calendar = box_widget(calendar_widget, 380, 330)
-- Spacing
local space = function(height)
return wibox.widget {
forced_height = dpi(height),
layout = wibox.layout.align.horizontal
}
end
-- Sidebar
local sidebar = wibox {
visible = false,
ontop = true,
width = width,
height = height,
y = dpi(15),
screen = s,
bg = theme.bg,
--bg = colors.transparent,
shape = round_widget(18),
}
-- Sidebar widget setup
sidebar : setup {
{
profile,
sliders,
weather,
calendar,
spacing = dpi(20),
layout = wibox.layout.fixed.vertical,
},
margins = { top = dpi(20), bottom = dpi(20)},
widget = wibox.container.margin,
}
-- Slide animation
local slide = rubato.timed {
pos = awful.screen.focused().geometry.x - sidebar.width,
rate = 60,
intro = 0.2,
duration = 0.4,
subscribed = function(pos)
sidebar.x = awful.screen.focused().geometry.x + pos
end
}
-- Timer of sidebar's death
sidebar.timer = gears.timer {
timeout = 0.5,
single_shot = true,
callback = function()
sidebar.visible = not sidebar.visible
end
}
-- Toggle function
sidebar.toggle = function(s)
if sidebar.visible then
--slide.target = awful.screen.focused().geometry.x - sidebar.width
slide.target = awful.screen.focused().geometry.x + sidebar.width
sidebar.timer:start()
else
--slide.target = awful.screen.focused().geometry.x + dpi(10)
slide.target = awful.screen.focused().geometry.x - dpi(195)
sidebar.visible = not sidebar.visible
end
end
--awful.mouse.append_global_mousebindings({
-- awful.button({ }, 1, function () sidebar.toggle() end)
--})
--awful.keyboard.append_global_keybindings({
-- awful.key({alt}, "c", function() awesome.emit_signal("sidebar::toggle") end), -- Sidebar
--})
-- Get signal to execute the function (if that makes sense)
awesome.connect_signal("sidebar::toggle", function(s)
sidebar.toggle()
end)
return sidebar