summaryrefslogtreecommitdiffstats
path: root/programs
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2023-09-24 10:07:04 -0400
committerJon Santmyer <jon@jonsantmyer.com>2023-09-24 10:07:04 -0400
commit9cffa9b6eb594983b3f4fab4bceca42091a531e5 (patch)
tree6872490a084c8fedcbd2fb0b9fcf0a5ad323b3c8 /programs
parent0395c7beb1e35d252d607c9e047a3037daa09832 (diff)
downloadnix-config-9cffa9b6eb594983b3f4fab4bceca42091a531e5.tar.gz
nix-config-9cffa9b6eb594983b3f4fab4bceca42091a531e5.tar.bz2
nix-config-9cffa9b6eb594983b3f4fab4bceca42091a531e5.zip
add calendar widget to awesome
Diffstat (limited to 'programs')
-rw-r--r--programs/dotfiles/awesome/calendar.lua115
-rw-r--r--programs/dotfiles/awesome/rc.lua98
2 files changed, 174 insertions, 39 deletions
diff --git a/programs/dotfiles/awesome/calendar.lua b/programs/dotfiles/awesome/calendar.lua
new file mode 100644
index 0000000..6e791b3
--- /dev/null
+++ b/programs/dotfiles/awesome/calendar.lua
@@ -0,0 +1,115 @@
+local awful = require("awful")
+local beautiful = require("beautiful")
+local wibox = require("wibox")
+local gears = require("gears")
+
+local calendar_widget = {}
+
+local function worker(user_args)
+ local args = user_args or {}
+
+ local style = {}
+
+ style.month = {
+ padding = 4,
+ bg_color = beautiful.bg_normal,
+ border_width = 0
+ }
+
+ style.normal = {
+ markup = function(t) return t end,
+ shape = function(cr, width, height) gears.shape.rounded_rect(cr, width, height, 4) end,
+ }
+
+ style.focused = {
+ bg_color = beautiful.bg_focus,
+ fg_color = beautiful.fg_focus,
+ markup = function(t) return '<b>' .. t .. '</b>' end,
+ shape = function(cr, width, height) gears.shape.rounded_rect(cr, width, height, 4) end,
+ }
+
+ style.header = {
+ bg_color = beautiful.bg_focus,
+ fg_color = beautiful.fg_focus,
+ markup = function(t) return '<b>'..t..'</b>' end,
+ }
+
+ style.weekday = {
+ bg_color = beautiful.bg_focus,
+ fg_color = beautiful.fg_focus,
+ markup = function(t) return '<b>'..t..'</b>' end,
+ }
+
+ local function decorate(widget, flag, date)
+ if flag == 'monthheader' then flag = 'header' end
+ if flag == 'focus' then
+ local today = os.date('*t')
+ if not today.month == date.month and today.year == date.year then
+ flag = 'normal'
+ end
+ end
+ local properties = style[flag] or {}
+ if properties.markup and widget.get_text and widget.set_markup then
+ widget:set_markup(properties.markup(widget:get_text()))
+ end
+ local thisdate = { 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 beautiful.bg_focused
+ or beautiful.bg_normal
+ return wibox.widget {
+ {
+ {
+ widget,
+ halign = 'center',
+ widget = wibox.container.place
+ },
+ margins = (properties.padding or 2) + (properties.border_width or 0),
+ widget = wibox.container.margin
+ },
+ shape = properties.shape,
+ shape_border_color = properties.border_color or '#00000000',
+ shape_border_width = properties.border_width or 0,
+ fg = properties.fg_color or beautiful.fg_normal,
+ bg = properties.bg_color or beautiful.bg_normal,
+ widget = wibox.container.background
+ }
+ end
+
+ local cal = wibox.widget {
+ date = os.date('*t'),
+ font = beautiful.get_font(),
+ fn_embed = decorate,
+ long_weekdays = true,
+ start_sunday = true,
+ widget = wibox.widget.calendar.month
+ }
+
+ local popup = awful.popup {
+ ontop = true,
+ visible = false,
+ shape = gears.shape.rounded_rect,
+ offset = { y = 5 },
+ border_width = 2,
+ border_color = beautiful.fg_minimize,
+ widget = cal
+ }
+
+ function calendar_widget.toggle()
+ if popup.visible then
+ cal:set_date(nil)
+ cal:set_date(os.date('*t'))
+ popup:set_widget(nil)
+ popup:set_widget(cal)
+ popup.visible = not popup.visible
+ else
+ awful.placement.top_right(popup, { margins = { top = 30, right = 10 }, parent = awful.screen.focused() })
+ popup.visible = true
+ end
+ end
+ return calendar_widget
+end
+
+return setmetatable(calendar_widget, { __call = function(_, ...)
+ return worker(...)
+end})
diff --git a/programs/dotfiles/awesome/rc.lua b/programs/dotfiles/awesome/rc.lua
index ccd1d1a..065eda3 100644
--- a/programs/dotfiles/awesome/rc.lua
+++ b/programs/dotfiles/awesome/rc.lua
@@ -127,14 +127,23 @@ menubar.utils.terminal = terminal -- Set the terminal for applications that requ
-- {{{ Wibar
-- Create a textclock widget
-toptextclock = wibox.widget {
- {
- widget = wibox.widget.textclock
- },
- bg = beautiful.bg_normal,
- widget = wibox.container.background,
- shape = gears.shape.rounded_rect
-}
+toptextclock = wibox.widget.textclock()
+--toptextclock = wibox.widget {
+-- {
+-- widget = wibox.widget.textclock
+-- },
+-- bg = beautiful.bg_normal,
+-- widget = wibox.container.background,
+-- shape = gears.shape.rounded_rect
+--}
+
+local calendar_widget = require("calendar")
+local topcalendar = calendar_widget()
+
+toptextclock:connect_signal("button::press",
+function(_, _, _, button)
+ if button == 1 then topcalendar.toggle() end
+end)
-- Create a wibox for each screen and add it
local taglist_buttons = gears.table.join(
@@ -227,6 +236,8 @@ awful.screen.connect_for_each_screen(function(s)
},
id = "shape_role",
bg = beautiful.bg_normal,
+ shape_border_width = 2,
+ shape_border_color = beautiful.fg_minimize,
shape = gears.shape.circle,
widget = wibox.container.background,
},
@@ -274,40 +285,31 @@ awful.screen.connect_for_each_screen(function(s)
spacing = 4,
layout = wibox.layout.flex.horizontal
},
- widget_template = {
+ widget_template =
+ {
+ layout = wibox.layout.fixed.vertical,
+ {
+ wibox.widget.base.make_widget(),
+ id = 'background_role',
+ forced_height = 4,
+ widget = wibox.container.background
+ },
{
- {
- wibox.widget.base.make_widget(),
- id = 'background_role',
- forced_height = 4,
- widget = wibox.container.background,
- },
{
{
- {
- {
- id = 'icon_role',
- widget = wibox.widget.imagebox,
- },
- margins = 2,
- widget = wibox.container.margin,
- },
- {
- id = 'text_role',
- widget = wibox.widget.textbox
- },
- layout = wibox.layout.fixed.horizontal
+ id = 'icon_role',
+ widget = wibox.widget.imagebox,
},
- left = 4,
- right = 4,
- bottom = 4,
+ margins = 2,
widget = wibox.container.margin,
},
- layout = wibox.layout.fixed.vertical
+ {
+ id = 'text_role',
+ widget = wibox.widget.textbox
+ },
+ layout = wibox.layout.fixed.horizontal
},
- nil,
- widget = wibox.container.background,
- },
+ }
}
-- Create the wibox
@@ -327,10 +329,28 @@ awful.screen.connect_for_each_screen(function(s)
},
s.mytasklist, -- Middle widget
{ -- Right widgets
- layout = wibox.layout.fixed.horizontal,
- wibox.container.margin(s.systray, 0, 0, 4, 4),
- toptextclock,
- s.mylayoutbox,
+ {
+ {
+ layout = wibox.layout.fixed.horizontal,
+ {
+ {
+ widget = s.systray,
+ },
+ widget = wibox.container.margin,
+ left = 8,
+ top = 4,
+ bottom = 4
+ },
+ toptextclock,
+ wibox.container.margin(s.mylayoutbox, 4, 4, 4, 4),
+ },
+ widget = wibox.container.background,
+ shape = gears.shape.rounded_rect,
+ shape_border_width = 1,
+ shape_border_color = beautiful.fg_minimize,
+ bg = beautiful.bg_normal,
+ },
+ layout = wibox.layout.fixed.horizontal
},
}
end)