Add calendar, no submodules
This commit is contained in:
parent
0286358d51
commit
0060372b9a
|
@ -0,0 +1,47 @@
|
||||||
|
## awesome-calendar
|
||||||
|
|
||||||
|
Small calendar popup for awesome window manager.
|
||||||
|
|
||||||
|
![Screenshot](/screenshot.png?raw=true "Screenshot")
|
||||||
|
|
||||||
|
This is a polished up and improved module based on the `calendar2.lua` module
|
||||||
|
by Bernd Zeimetz and Marc Dequènes.
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
Drop the script into your awesome config folder. Suggestion:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd ~/.config/awesome
|
||||||
|
git clone https://github.com/deficient/calendar.git
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
In your `rc.lua`:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- load the widget code
|
||||||
|
local calendar = require("calendar")
|
||||||
|
|
||||||
|
-- attach it as popup to your text clock widget:
|
||||||
|
calendar({}):attach(mytextclock)
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also add some options to customize the widget's display. For instance:
|
||||||
|
|
||||||
|
```
|
||||||
|
local calendar = require("calendar")
|
||||||
|
calendar_widget = calendar({
|
||||||
|
fdow = 7, -- Set Sunday as first day of the week (default is
|
||||||
|
-- 1 = Monday)
|
||||||
|
position = "bottom_right", -- Useful if you prefer your wibox at the bottomn
|
||||||
|
-- of the screen
|
||||||
|
})
|
||||||
|
calendar_widget:attach(mytextclock)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Requirements
|
||||||
|
|
||||||
|
* [awesome 4.0](http://awesome.naquadah.org/). May work on 3.5 with minor changes.
|
|
@ -0,0 +1,24 @@
|
||||||
|
This is free and unencumbered software released into the public domain.
|
||||||
|
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||||
|
distribute this software, either in source code form or as a compiled
|
||||||
|
binary, for any purpose, commercial or non-commercial, and by any
|
||||||
|
means.
|
||||||
|
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors
|
||||||
|
of this software dedicate any and all copyright interest in the
|
||||||
|
software to the public domain. We make this dedication for the benefit
|
||||||
|
of the public at large and to the detriment of our heirs and
|
||||||
|
successors. We intend this dedication to be an overt act of
|
||||||
|
relinquishment in perpetuity of all present and future rights to this
|
||||||
|
software under copyright law.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
For more information, please refer to <http://unlicense.org/>
|
|
@ -0,0 +1,175 @@
|
||||||
|
-- original code made by Bzed and published on http://awesome.naquadah.org/wiki/Calendar_widget
|
||||||
|
-- modified by Marc Dequènes (Duck) <Duck@DuckCorp.org> (2009-12-29), under the same licence,
|
||||||
|
-- and with the following changes:
|
||||||
|
-- + transformed to module
|
||||||
|
-- + the current day formating is customizable
|
||||||
|
-- also modified by tforgione for it to work in french
|
||||||
|
|
||||||
|
-- captures
|
||||||
|
local os = os
|
||||||
|
local capi = {
|
||||||
|
mouse = mouse,
|
||||||
|
screen = screen,
|
||||||
|
}
|
||||||
|
local awful = require("awful")
|
||||||
|
local naughty = require("naughty")
|
||||||
|
|
||||||
|
local version_major, version_minor = awesome.version:match("(%d+)%.(%d+)")
|
||||||
|
version_major = tonumber(version_major)
|
||||||
|
version_minor = tonumber(version_minor)
|
||||||
|
local can_update_size = version_major and version_minor and version_major >= 4 and version_minor >= 2
|
||||||
|
|
||||||
|
------------------------------------------
|
||||||
|
-- utility functions
|
||||||
|
------------------------------------------
|
||||||
|
|
||||||
|
local function format_date(format, date)
|
||||||
|
return os.date(format, os.time(date))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
------------------------------------------
|
||||||
|
-- calendar popup widget
|
||||||
|
------------------------------------------
|
||||||
|
|
||||||
|
local calendar = {}
|
||||||
|
|
||||||
|
function calendar:new(args)
|
||||||
|
return setmetatable({}, {__index = self}):init(args)
|
||||||
|
end
|
||||||
|
|
||||||
|
function calendar:init(args)
|
||||||
|
self.num_lines = 0
|
||||||
|
self.today_color = args.today_color or "#00ff00"
|
||||||
|
-- first day of week: monday=1, …, sunday=7
|
||||||
|
self.fdow = args.fdow or 1
|
||||||
|
-- notification area:
|
||||||
|
self.html = args.html or '<span font_desc="monospace">\n%s</span>'
|
||||||
|
-- highlight current date:
|
||||||
|
self.today = args.today or '<b><span color="' .. self.today_color .. '">%2i</span></b>'
|
||||||
|
self.anyday = args.anyday or '%2i'
|
||||||
|
self.page_title = args.page_title or '%B %Y' -- month year
|
||||||
|
self.col_title = args.col_title or '%a ' -- weekday
|
||||||
|
-- Date equality check is based on day_id. We deliberately ignore the year
|
||||||
|
-- to highlight the same day in different years:
|
||||||
|
self.day_id = args.day_id or '%m-%d'
|
||||||
|
self.empty_sep = args.empty_sep or " -"
|
||||||
|
self.week_col = args.week_col or " %V"
|
||||||
|
self.days_style = args.days_style or {}
|
||||||
|
self.position = args.position or naughty.config.defaults.position
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function calendar:day_style(day_of_week)
|
||||||
|
return self.days_style[day_of_week] or '%s'
|
||||||
|
end
|
||||||
|
|
||||||
|
function calendar:page(month, year)
|
||||||
|
|
||||||
|
local today = format_date(self.day_id)
|
||||||
|
|
||||||
|
-- 2001 started with a monday:
|
||||||
|
local d0 = format_date("*t", {year=2001, month=1, day=self.fdow })
|
||||||
|
local dA = format_date("*t", {year=year, month=month, day=1 })
|
||||||
|
local dB = format_date("*t", {year=year, month=month+1, day=0 })
|
||||||
|
local tA = {year=year, month=month, day=1 }
|
||||||
|
local colA = (dA.wday - d0.wday) % 7
|
||||||
|
|
||||||
|
local page_title = format_date(self.page_title, tA)
|
||||||
|
|
||||||
|
-- print column titles (weekday)
|
||||||
|
local page = " "
|
||||||
|
for d = 0, 6 do
|
||||||
|
page = page .. self:day_style(d+1):format(format_date(self.col_title, {
|
||||||
|
year = d0.year,
|
||||||
|
month = d0.month,
|
||||||
|
day = d0.day + d,
|
||||||
|
}))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- print empty space before first day
|
||||||
|
page = page .. "\n" .. format_date(self.week_col, tA)
|
||||||
|
for column = 1, colA do
|
||||||
|
page = page .. self.empty_sep
|
||||||
|
end
|
||||||
|
|
||||||
|
-- iterate all days of the month
|
||||||
|
local nLines = 1
|
||||||
|
local column = colA
|
||||||
|
for day = 1, dB.day do
|
||||||
|
if column == 7 then
|
||||||
|
column = 0
|
||||||
|
nLines = nLines + 1
|
||||||
|
page = page .. "\n" .. format_date(self.week_col, {year=year, month=month, day=day})
|
||||||
|
end
|
||||||
|
if today == format_date(self.day_id, {day=day, month=month, year=year}) then
|
||||||
|
page = page .. " " .. self.today:format(day)
|
||||||
|
else
|
||||||
|
page = page .. " " .. self:day_style(column+1):format(self.anyday:format(day))
|
||||||
|
end
|
||||||
|
column = column + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
for column = column, 6 do
|
||||||
|
page = page .. self.empty_sep
|
||||||
|
end
|
||||||
|
|
||||||
|
return page_title, self.html:format(page)
|
||||||
|
end
|
||||||
|
|
||||||
|
function calendar:switch(months)
|
||||||
|
self:show(self.year, self.month+months)
|
||||||
|
end
|
||||||
|
|
||||||
|
function calendar:show(year, month)
|
||||||
|
local today = os.time()
|
||||||
|
self.month = month or os.date('%m', today)
|
||||||
|
self.year = year or os.date('%Y', today)
|
||||||
|
local title, text = self:page(self.month, self.year)
|
||||||
|
|
||||||
|
-- NOTE: `naughty.replace_text` does not update bounds and can therefore
|
||||||
|
-- not be used when the size increases (before #1756 was merged):
|
||||||
|
local num_lines = select(2, text:gsub('\n', ''))
|
||||||
|
local will_fit = can_update_size or num_lines <= self.num_lines
|
||||||
|
if naughty.replace_text and self.notification and will_fit then
|
||||||
|
naughty.replace_text(self.notification, title, text)
|
||||||
|
else
|
||||||
|
self:hide()
|
||||||
|
self.notification = naughty.notify({
|
||||||
|
title = title,
|
||||||
|
text = text,
|
||||||
|
timeout = 0,
|
||||||
|
hover_timeout = 0.5,
|
||||||
|
screen = capi.mouse.screen,
|
||||||
|
position = self.position,
|
||||||
|
})
|
||||||
|
self.num_lines = num_lines
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function calendar:hide()
|
||||||
|
if self.notification then
|
||||||
|
naughty.destroy(self.notification)
|
||||||
|
self.notification = nil
|
||||||
|
self.num_lines = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function calendar:attach(widget)
|
||||||
|
widget:connect_signal('mouse::enter', function() self:show() end)
|
||||||
|
widget:connect_signal('mouse::leave', function() self:hide() end)
|
||||||
|
widget:buttons(awful.util.table.join(
|
||||||
|
awful.button({ }, 1, function() self:switch( -1) end),
|
||||||
|
awful.button({ }, 3, function() self:switch( 1) end),
|
||||||
|
awful.button({ }, 4, function() self:switch( -1) end),
|
||||||
|
awful.button({ }, 5, function() self:switch( 1) end),
|
||||||
|
awful.button({ 'Shift' }, 1, function() self:switch(-12) end),
|
||||||
|
awful.button({ 'Shift' }, 3, function() self:switch( 12) end),
|
||||||
|
awful.button({ 'Shift' }, 4, function() self:switch(-12) end),
|
||||||
|
awful.button({ 'Shift' }, 5, function() self:switch( 12) end)
|
||||||
|
))
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(calendar, {
|
||||||
|
__call = calendar.new,
|
||||||
|
})
|
|
@ -0,0 +1 @@
|
||||||
|
calendar.lua
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
Loading…
Reference in New Issue