From 7750058808e665e2dff282159c412742e8c03641 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sat, 14 Mar 2015 07:11:35 +0100 Subject: add calendar --- ni/theme.lua | 2 + rc.lua | 2 + widgets/cal.lua | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 widgets/cal.lua diff --git a/ni/theme.lua b/ni/theme.lua index 976246c..a0d2c27 100644 --- a/ni/theme.lua +++ b/ni/theme.lua @@ -34,6 +34,8 @@ theme.border_marked = "#91231c" -- mouse_finder_[color|timeout|animate_timeout|radius|factor] -- Example: --theme.taglist_bg_focus = "#ff0000" +theme.tooltip_fg_color = theme.fg_normal +theme.tooltip_bg_color = theme.bg_normal -- Display the taglist squares theme.taglist_squares_sel = "/usr/share/awesome/themes/default/taglist/squarefw.png" diff --git a/rc.lua b/rc.lua index 10b0197..ff34978 100644 --- a/rc.lua +++ b/rc.lua @@ -12,6 +12,7 @@ require("debian.menu") -- Load my modules require("widgets.volume") +require("widgets.cal") -- {{{ Variable definitions -- Themes define colours, icons, and wallpapers @@ -80,6 +81,7 @@ mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon), -- {{{ Wibox -- Create a textclock widget mytextclock = awful.widget.textclock({ align = "right" }) +widgets.cal.register(mytextclock) -- Create a systray mysystray = widget({ type = "systray" }) diff --git a/widgets/cal.lua b/widgets/cal.lua new file mode 100644 index 0000000..24c9755 --- /dev/null +++ b/widgets/cal.lua @@ -0,0 +1,130 @@ +-- original code made by Bzed and published on http://awesome.naquadah.org/wiki/Calendar_widget +-- modified by Marc Dequènes (Duck) (2009-12-29), under the same licence, +-- and with the following changes: +-- + transformed to module +-- + the current day formating is customizable +-- modified by Jörg Thalheim (Mic92) (2011), under the same licence, +-- and with the following changes: +-- + use tooltip instead of naughty.notify +-- + rename it to cal +-- +-- # How to Install # +-- 1. Download the code and move it into your config directory +-- wget --no-check-certificate https://github.com/Mic92/awesome-dotfiles/raw/master/cal.lua -O $XDG_CONFIG_HOME/awesome/cal.lua +-- 2. require it in your rc.lua +-- require("cal") +-- 3. attach the calendar to a widget of your choice (ex mytextclock) +-- cal.register(mytextclock) +-- If you don't like the default current day formating you can change it as following +-- cal.register(mytextclock, "%s") -- now the current day is bold instead of underlined +-- +-- # How to Use # +-- Just hover with your mouse over the widget, you register and the calendar popup. +-- On clicking or by using the mouse wheel the displayed month changes. +-- Pressing Shift + Mouse click change the year. + +local string = {format = string.format} +local os = {date = os.date, time = os.time} +local awful = require("awful") + +module("widgets.cal") + +local tooltip +local state = {} +local current_day_format = "%s" + +function displayMonth(month,year,weekStart) + local t,wkSt=os.time{year=year, month=month+1, day=0},weekStart or 1 + local d=os.date("*t",t) + local mthDays,stDay=d.day,(d.wday-d.day-wkSt+1)%7 + + local lines = " " + + for x=0,6 do + lines = lines .. os.date("%a ",os.time{year=2006,month=1,day=x+wkSt}) + end + + lines = lines .. "\n" .. os.date(" %V",os.time{year=year,month=month,day=1}) + + local writeLine = 1 + while writeLine < (stDay + 1) do + lines = lines .. " " + writeLine = writeLine + 1 + end + + for d=1,mthDays do + local x = d + local t = os.time{year=year,month=month,day=d} + if writeLine == 8 then + writeLine = 1 + lines = lines .. "\n" .. os.date(" %V",t) + end + if os.date("%Y-%m-%d") == os.date("%Y-%m-%d", t) then + x = string.format(current_day_format, d) + end + if d < 10 then + x = " " .. x + end + lines = lines .. " " .. x + writeLine = writeLine + 1 + end + if stDay + mthDays < 36 then + lines = lines .. "\n" + end + if stDay + mthDays < 29 then + lines = lines .. "\n" + end + local header = os.date("%B %Y\n",os.time{year=year,month=month,day=1}) + + return header .. "\n" .. lines +end + + +function register(mywidget, custom_current_day_format) + if custom_current_day_format then current_day_format = custom_current_day_format end + + if not tooltip then + tooltip = awful.tooltip({}) + function tooltip:update() + local month, year = os.date('%m'), os.date('%Y') + state = {month, year} + tooltip:set_text(string.format('%s', displayMonth(month, year, 2))) + end + tooltip:update() + end + tooltip:add_to_object(mywidget) + + mywidget:add_signal("mouse::enter",tooltip.update) + + mywidget:buttons(awful.util.table.join( + awful.button({ }, 1, function() + switchMonth(-1) + end), + awful.button({ }, 3, function() + switchMonth(1) + end), + awful.button({ }, 4, function() + switchMonth(-1) + end), + awful.button({ }, 5, function() + switchMonth(1) + end), + awful.button({ 'Shift' }, 1, function() + switchMonth(-12) + end), + awful.button({ 'Shift' }, 3, function() + switchMonth(12) + end), + awful.button({ 'Shift' }, 4, function() + switchMonth(-12) + end), + awful.button({ 'Shift' }, 5, function() + switchMonth(12) + end))) +end + +function switchMonth(delta) + state[1] = state[1] + (delta or 1) + local text = string.format('%s', displayMonth(state[1], state[2], 2)) + tooltip:set_text(text) +end -- cgit v1.2.3