themes for calendar widget

This commit is contained in:
streetturtle 2019-12-15 22:10:22 -05:00
parent 93d6581b70
commit 0e5ae300fb
5 changed files with 197 additions and 136 deletions

View File

@ -1,28 +1,54 @@
# Calendar Widget
Calendar widget for Awesome WM - slightly improved version of the `wibox.widget.calendar`. Also supports mouse scroll up/down in order ot switch month - scroll up - shows next month, scroll down - previous.
Calendar widget for Awesome WM - slightly improved version of the `wibox.widget.calendar`.
Top center placement:
## Features
- mouse support: scroll up - shows next month, scroll down - previous
- themes:
nord (default):
![nord_theme](./nord.png)
outrun:
![outrun_theme](./outrun.png)
- setup widget placement
top center - in case you clock is centered:
![calendar_top](./calendar_top.png)
Top right placement:
top right - for default awesome config:
![calendar_top_right](./calendar_top_right.png)
The placement is setup in theme.lua by `calendar_placement` variable, currently supported `top` (default), `top_right`, `bottom_right`.
bottom right - in case your wibar at the bottom:
# How to use
![calendar_bottom_right](./calendar_bottom_right.png)
## How to use
This widget needs an 'anchor' - another widget which triggers visibility of the calendar. Default `mytextclock` is the perfect candidate!
```lua
local calendar_widget = require("awesome-wm-widgets.calendar-widget.calendar")
-- ...
-- {{{ Wibar
-- Create a textclock widget
mytextclock = wibox.widget.textclock()
-- default
cw = calendar_widget()
-- or customized
cw = calendar_widget({
theme = 'outrun',
placement = 'bottom_right'
})
mytextclock:connect_signal("button::press",
function(_, _, _, button)
if button == 1 then calendar_widget.toggle() end
if button == 1 then cw.toggle() end
end)
```

View File

@ -15,6 +15,37 @@ local gears = require("gears")
local calendar_widget = {}
local function worker(args)
local calendar_themes = {
nord = {
bg = '#2E3440',
fg = '#D8DEE9',
focus_date_bg = '#88C0D0',
focus_date_fg = '#000000',
weekend_day_bg = '#3B4252',
weekday_fg = '#88C0D0',
header_fg = '#E5E9F0',
border = '#4C566A'
},
outrun = {
bg = '#0d0221',
fg = '#D8DEE9',
focus_date_bg = '#650d89',
focus_date_fg = '#2de6e2',
weekend_day_bg = '#261447',
weekday_fg = '#2de6e2',
header_fg = '#f6019d',
border = '#261447'
}
}
local args = args or {}
local theme = args.theme or 'nord'
local placement = args.placement or 'top'
local styles = {}
local function rounded_shape(size)
return function(cr, width, height)
@ -24,7 +55,7 @@ end
styles.month = {
padding = 4,
bg_color = '#2E3440',
bg_color = calendar_themes[theme].bg,
border_width = 0,
}
@ -34,22 +65,22 @@ styles.normal = {
}
styles.focus = {
fg_color = '#000000',
bg_color = '#88C0D0',
fg_color = calendar_themes[theme].focus_date_fg,
bg_color = calendar_themes[theme].focus_date_bg,
markup = function(t) return '<b>' .. t .. '</b>' end,
shape = rounded_shape(4)
}
styles.header = {
fg_color = '#E5E9F0',
markup = function(t) return '<b>' .. t .. '</b>' end,
bg_color = '#2E3440'
fg_color = calendar_themes[theme].header_fg,
bg_color = calendar_themes[theme].bg,
markup = function(t) return '<b>' .. t .. '</b>' end
}
styles.weekday = {
fg_color = '#88C0D0',
fg_color = calendar_themes[theme].weekday_fg,
bg_color = calendar_themes[theme].bg,
markup = function(t) return '<b>' .. t .. '</b>' end,
bg_color = '#2E3440',
}
local function decorate_cell(widget, flag, date)
@ -72,7 +103,7 @@ local function decorate_cell(widget, flag, date)
-- Change bg color for weekends
local d = { year = date.year, month = (date.month or 1), day = (date.day or 1) }
local weekday = tonumber(os.date('%w', os.time(d)))
local default_bg = (weekday == 0 or weekday == 6) and '#3B4252' or '#2E3440'
local default_bg = (weekday == 0 or weekday == 6) and calendar_themes[theme].weekend_day_bg or calendar_themes[theme].bg
local ret = wibox.widget {
{
{
@ -84,9 +115,9 @@ local function decorate_cell(widget, flag, date)
widget = wibox.container.margin
},
shape = props.shape,
shape_border_color = props.border_color or '#b9214f',
shape_border_color = props.border_color or '#000000',
shape_border_width = props.border_width or 0,
fg = props.fg_color or '#D8DEE9',
fg = props.fg_color or calendar_themes[theme].fg,
bg = props.bg_color or default_bg,
widget = wibox.container.background
}
@ -109,7 +140,7 @@ local popup = awful.popup {
preferred_positions = top,
offset = { y = 5 },
border_width = 1,
border_color = '#4C566A',
border_color = calendar_themes[theme].border,
widget = cal
}
@ -142,14 +173,12 @@ function calendar_widget.toggle()
popup:set_widget(cal)
popup.visible = not popup.visible
else
if not beautiful.calendar_placement then
if placement == 'top' then
awful.placement.top(popup, { margins = { top = 30 }, parent = awful.screen.focused() })
elseif beautiful.calendar_placement == 'top' then
awful.placement.top(popup, { margins = { top = 30 }, parent = awful.screen.focused() })
elseif beautiful.calendar_placement == 'top_right' then
elseif placement == 'top_right' then
awful.placement.top_right(popup, { margins = { top = 30, right = 10}, parent = awful.screen.focused() })
elseif beautiful.calendar_placement == 'bottom_right' then
awful.placement.bottom_right(popup, { margins = { bottom = 20, right = 10}, parent = awful.screen.focused() })
elseif placement == 'bottom_right' then
awful.placement.bottom_right(popup, { margins = { bottom = 30, right = 10}, parent = awful.screen.focused() })
else
awful.placement.top(popup, { margins = { top = 30 }, parent = awful.screen.focused() })
end
@ -160,3 +189,9 @@ function calendar_widget.toggle()
end
return calendar_widget
end
return setmetatable(calendar_widget, { __call = function(_, ...)
return worker(...)
end })

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

BIN
calendar-widget/nord.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
calendar-widget/outrun.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB