nord theme for calendar widget + mouse support
This commit is contained in:
parent
f6c76d7a51
commit
7dd6fe0aff
|
@ -1,8 +1,8 @@
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
-- Jira Widget for Awesome Window Manager
|
-- Calendar Widget for Awesome Window Manager
|
||||||
-- Shows the number of currently assigned issues
|
-- Shows the current month and supports scroll up/down to switch month
|
||||||
-- More details could be found here:
|
-- More details could be found here:
|
||||||
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/jira-widget
|
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/calendar-widget
|
||||||
|
|
||||||
-- @author Pavel Makhov
|
-- @author Pavel Makhov
|
||||||
-- @copyright 2019 Pavel Makhov
|
-- @copyright 2019 Pavel Makhov
|
||||||
|
@ -21,108 +21,147 @@ local gs = require("gears.string")
|
||||||
|
|
||||||
local calendar_widget = {}
|
local calendar_widget = {}
|
||||||
|
|
||||||
local function worker(args)
|
local styles = {}
|
||||||
|
local function rounded_shape(size, partial)
|
||||||
local styles = {}
|
if partial then
|
||||||
local function rounded_shape(size, partial)
|
return function(cr, width, height)
|
||||||
if partial then
|
gears.shape.partially_rounded_rect(cr, width, height,
|
||||||
return function(cr, width, height)
|
false, true, false, true, 5)
|
||||||
gears.shape.partially_rounded_rect(cr, width, height,
|
end
|
||||||
false, true, false, true, 5)
|
else
|
||||||
end
|
return function(cr, width, height)
|
||||||
else
|
gears.shape.rounded_rect(cr, width, height, size)
|
||||||
return function(cr, width, height)
|
|
||||||
gears.shape.rounded_rect(cr, width, height, size)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
styles.month = { padding = 4,
|
end
|
||||||
bg_color = '#3B4252',
|
styles.month = { padding = 4,
|
||||||
border_width = 2,
|
bg_color = '#3B4252',
|
||||||
--shape = rounded_shape(10)
|
border_width = 0,
|
||||||
}
|
}
|
||||||
styles.normal = { shape = rounded_shape(4) }
|
styles.normal = {
|
||||||
styles.focus = { fg_color = '#000000',
|
markup = function(t) return t end,
|
||||||
bg_color = '#88C0D0',
|
shape = rounded_shape(4)
|
||||||
markup = function(t) return '<b>' .. t .. '</b>' end,
|
}
|
||||||
shape = rounded_shape(4)
|
styles.focus = { fg_color = '#000000',
|
||||||
}
|
bg_color = '#88C0D0',
|
||||||
styles.header = { fg_color = '#8FBCBB',
|
markup = function(t) return '<b>' .. t .. '</b>' end,
|
||||||
markup = function(t) return '<b>' .. t .. '</b>' end,
|
shape = rounded_shape(4)
|
||||||
--shape = rounded_shape(10)
|
}
|
||||||
bg_color = '#3B4252'
|
styles.header = { fg_color = '#8FBCBB',
|
||||||
}
|
markup = function(t) return '<b>' .. t .. '</b>' end,
|
||||||
styles.weekday = { fg_color = '#88C0D0',
|
--shape = rounded_shape(10)
|
||||||
markup = function(t) return '<b>' .. t .. '</b>' end,
|
bg_color = '#3B4252'
|
||||||
bg_color = '#3B4252',
|
}
|
||||||
--shape = rounded_shape(4)
|
styles.weekday = { fg_color = '#88C0D0',
|
||||||
}
|
markup = function(t) return '<b>' .. t .. '</b>' end,
|
||||||
local function decorate_cell(widget, flag, date)
|
bg_color = '#3B4252',
|
||||||
if flag=='monthheader' and not styles.monthheader then
|
--shape = rounded_shape(4)
|
||||||
flag = 'header'
|
}
|
||||||
|
|
||||||
|
local function decorate_cell(widget, flag, date)
|
||||||
|
if flag=='monthheader' and not styles.monthheader then
|
||||||
|
flag = 'header'
|
||||||
|
end
|
||||||
|
|
||||||
|
if flag == 'focus' then
|
||||||
|
local a = os.date('*t')
|
||||||
|
if a.month ~= date.month then
|
||||||
|
flag = 'normal'
|
||||||
end
|
end
|
||||||
local props = styles[flag] or {}
|
end
|
||||||
if props.markup and widget.get_text and widget.set_markup then
|
|
||||||
widget:set_markup(props.markup(widget:get_text()))
|
local props = styles[flag] or {}
|
||||||
end
|
if props.markup and widget.get_text and widget.set_markup then
|
||||||
-- Change bg color for weekends
|
widget:set_markup(props.markup(widget:get_text()))
|
||||||
local d = {year=date.year, month=(date.month or 1), day=(date.day or 1)}
|
end
|
||||||
local weekday = tonumber(os.date('%w', os.time(d)))
|
-- Change bg color for weekends
|
||||||
local default_bg = (weekday==0 or weekday==6) and '#2E3440' or '#3B4252'
|
local d = {year=date.year, month=(date.month or 1), day=(date.day or 1)}
|
||||||
local ret = wibox.widget {
|
local weekday = tonumber(os.date('%w', os.time(d)))
|
||||||
|
local default_bg = (weekday==0 or weekday==6) and '#2E3440' or '#3B4252'
|
||||||
|
local ret = wibox.widget {
|
||||||
|
{
|
||||||
{
|
{
|
||||||
{
|
widget,
|
||||||
widget,
|
halign = 'center',
|
||||||
halign = 'center',
|
widget = wibox.container.place
|
||||||
widget = wibox.container.place
|
|
||||||
},
|
|
||||||
margins = (props.padding or 2) + (props.border_width or 0),
|
|
||||||
widget = wibox.container.margin
|
|
||||||
},
|
},
|
||||||
shape = props.shape,
|
margins = (props.padding or 2) + (props.border_width or 0),
|
||||||
shape_border_color = props.border_color or '#b9214f',
|
widget = wibox.container.margin
|
||||||
shape_border_width = props.border_width or 0,
|
},
|
||||||
fg = props.fg_color or '#D8DEE9',
|
shape = props.shape,
|
||||||
bg = props.bg_color or default_bg,
|
shape_border_color = props.border_color or '#b9214f',
|
||||||
widget = wibox.container.background
|
shape_border_width = props.border_width or 0,
|
||||||
}
|
fg = props.fg_color or '#D8DEE9',
|
||||||
return ret
|
bg = props.bg_color or default_bg,
|
||||||
end
|
widget = wibox.container.background
|
||||||
|
|
||||||
local popup = awful.popup{
|
|
||||||
visible = true,
|
|
||||||
ontop = true,
|
|
||||||
visible = false,
|
|
||||||
shape = gears.shape.rounded_rect,
|
|
||||||
border_width = 1,
|
|
||||||
border_color = beautiful.bg_focus,
|
|
||||||
maximum_width = 400,
|
|
||||||
preferred_positions = top,
|
|
||||||
offset = { y = 5 },
|
|
||||||
widget = wibox.widget {
|
|
||||||
date = os.date('*t'),
|
|
||||||
fn_embed = decorate_cell,
|
|
||||||
widget = wibox.widget.calendar.month,
|
|
||||||
long_weekdays = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
calendar_widget = wibox.widget.textbox()
|
-- ret:connect_signal("mouse::enter", function(c) naughty.notify{text = 'asd ' .. flag} end)
|
||||||
calendar_widget:set_text('calendar')
|
|
||||||
|
|
||||||
calendar_widget:buttons(
|
return ret
|
||||||
awful.util.table.join(
|
|
||||||
awful.button({}, 1, function()
|
|
||||||
if popup.visible then
|
|
||||||
popup.visible = not popup.visible
|
|
||||||
else
|
|
||||||
popup:move_next_to(mouse.current_widget_geometry)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return calendar_widget
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(calendar_widget, { __call = function(_, ...) return worker(...) end })
|
local cal = wibox.widget {
|
||||||
|
date = os.date('*t'),
|
||||||
|
font = 'Play 9',
|
||||||
|
fn_embed = decorate_cell,
|
||||||
|
long_weekdays = true,
|
||||||
|
widget = wibox.widget.calendar.month
|
||||||
|
}
|
||||||
|
|
||||||
|
local popup = awful.popup{
|
||||||
|
ontop = true,
|
||||||
|
visible = false,
|
||||||
|
shape = gears.shape.rounded_rect,
|
||||||
|
preferred_positions = top,
|
||||||
|
offset = { y = 5 },
|
||||||
|
widget = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
popup:buttons(
|
||||||
|
awful.util.table.join(
|
||||||
|
awful.button({}, 4, function()
|
||||||
|
local a = cal:get_date()
|
||||||
|
a.month = a.month + 1
|
||||||
|
cal:set_date(nil)
|
||||||
|
cal:set_date(a)
|
||||||
|
popup:set_widget(cal)
|
||||||
|
end),
|
||||||
|
awful.button({}, 5, function()
|
||||||
|
local a = cal:get_date()
|
||||||
|
a.month = a.month - 1
|
||||||
|
cal:set_date(nil)
|
||||||
|
cal:set_date(a)
|
||||||
|
popup:set_widget(cal)
|
||||||
|
end)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
calendar_widget = wibox.widget.textbox()
|
||||||
|
calendar_widget:set_text('calendar')
|
||||||
|
|
||||||
|
function calendar_widget.toggle()
|
||||||
|
if popup.visible then
|
||||||
|
cal:set_date(nil)
|
||||||
|
popup.visible = not popup.visible
|
||||||
|
else
|
||||||
|
cal:set_date(nil)
|
||||||
|
cal:set_date(os.date('*t'))
|
||||||
|
popup:set_widget(cal)
|
||||||
|
popup:move_next_to(mouse.current_widget_geometry)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function toggle()
|
||||||
|
calendar_widget.toggle()
|
||||||
|
end
|
||||||
|
|
||||||
|
calendar_widget:buttons(
|
||||||
|
awful.util.table.join(
|
||||||
|
awful.button({}, 1, function()
|
||||||
|
toggle()
|
||||||
|
end)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return calendar_widget
|
||||||
|
|
Loading…
Reference in New Issue