Last active
February 26, 2023 00:46
-
-
Save rdschmidt/6fe5a1fcdbf2d667593fc650cf3d0c04 to your computer and use it in GitHub Desktop.
Conky LUA Calendar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
2023 Bleys | |
Screenshot ist im ersten Kommentar. | |
Änderungen des Font (Ubuntu Mono) und/oder der Schriftgröße erfordern auch eine Anpassung der Berechnung der Hintergrund Berechnung! | |
Das sollte man nur machen wenn man weis was man tut... | |
Screenshot in first Comment | |
Changing the font (Ubuntu Mono) and font size also requires an adjustment of the background calculation for the current day! | |
Only change if you know what you are doing! | |
mainx, mainy innerhalb der Funktion calendar bestimmen die Position des Kalenders. | |
mainx, mainy within the calendar function determine the position of the calendar. | |
-- color=0xffffff --weiß / white | |
-- color=0x000000 --schwarz / black | |
-- color=0x0000ff --blau / blue | |
-- color=0xffff00 --gelb / yellow | |
-- color=0xff0000 --rot / red | |
-- color=0x00ff00 --grün / green | |
]] | |
require 'cairo' | |
require "math" | |
function rgb_to_rgba(color,alpha) | |
return ((color / 0x10000) % 0x100) / 255., ((color / 0x100) % 0x100) / 255., (color % 0x100) / 255., alpha | |
end | |
function draw_day(cr,xx,yy,bcolor,balpha) -- zeichne Hintergrund für aktuellen Tag / draw current Day Background | |
local corner_r=2 | |
local bg_color=0xff0000 --rot / red (Farbe/Color)) | |
local bg_alpha=0.5 | |
local w=15 | |
local h=12 | |
local x=xx | |
local y=yy | |
cairo_set_source_rgba(cr,rgb_to_rgba(bcolor,balpha)) | |
cairo_move_to(cr,x,y) | |
cairo_line_to(cr,x+w,y) | |
cairo_line_to(cr,x+w,y+h) | |
cairo_line_to(cr,x,y+h) | |
cairo_line_to(cr,x,y) | |
cairo_close_path(cr) | |
-- cairo_stroke(cr) | |
-- cairo_set_source_rgba(cr,rgb_to_rgba(bg_color,bg_alpha)) | |
cairo_fill(cr) | |
end | |
function draw_bg(cr,color,alpha,typ) -- zeichne Hintergrund Conky Fenster / draw Conky Area Background | |
local corner_r=20 | |
local bg_color=color | |
local bg_alpha=alpha | |
local w=conky_window.width | |
local h=conky_window.height | |
cairo_set_source_rgba(cr,rgb_to_rgba(bg_color,bg_alpha)) | |
cairo_move_to(cr,corner_r,0) | |
cairo_line_to(cr,w-corner_r,0) | |
cairo_curve_to(cr,w,0,w,0,w,corner_r) | |
cairo_line_to(cr,w,h-corner_r) | |
cairo_curve_to(cr,w,h,w,h,w-corner_r,h) | |
cairo_line_to(cr,corner_r,h) | |
cairo_curve_to(cr,0,h,0,h,0,h-corner_r) | |
cairo_line_to(cr,0,corner_r) | |
cairo_curve_to(cr,0,0,0,0,corner_r,0) | |
cairo_close_path(cr) | |
if typ==1 then | |
cairo_fill(cr) | |
else | |
cairo_stroke(cr) | |
end | |
end | |
function write_text(cr, x, y, text, f) | |
--write_text(cr, x, y, text, {}) | |
--font attributes (Schriftattribute zuweisen oder default Werte annehmen) | |
local font=f.font or "Noto Sans" | |
local size=f.size or 10 | |
local align=f.align or 'l' | |
local bold=f.bold or false | |
local ital=f.italic or false | |
local color=f.color or "0xffffff" | |
local slant=CAIRO_FONT_SLANT_NORMAL | |
if ital then slant=CAIRO_FONT_SLANT_ITALIC end | |
local weight=CAIRO_FONT_WEIGHT_NORMAL | |
if bold then weight=CAIRO_FONT_WEIGHT_BOLD end | |
--Text Size (Textgröße für die Plazierung bestimmen.) | |
local x_a=0 | |
local y_a=0 | |
local te = cairo_text_extents_t:create() | |
tolua.takeownership(te) | |
cairo_select_font_face (cr, font, slant, weight) | |
cairo_set_font_size (cr, size) | |
cairo_text_extents (cr, text, te) | |
--Text Position | |
if align=='c' then | |
x_a = -(te.width/2+te.x_bearing) | |
y_a = -(te.height/2+te.y_bearing) | |
end | |
if align=='r' then | |
x_a = -(te.width+te.x_bearing) | |
--y_a = -(te.height+te.y_bearing) | |
end | |
--Schadow 1 Pixel (Schatten für den Text um 1 Pixel versetzt) | |
cairo_set_source_rgba(cr, rgb_to_rgba(0x000000,1)) | |
cairo_move_to (cr, x+1+x_a, y+1+y_a) | |
cairo_show_text (cr, text) | |
cairo_stroke(cr) | |
-- Now Text on Top (nun den Text oben drauf) | |
cairo_set_source_rgba(cr, rgb_to_rgba(color,1)) | |
cairo_move_to (cr, x+x_a, y+y_a) | |
cairo_show_text (cr, text) | |
cairo_stroke(cr) | |
end | |
function calendar(cr) | |
-- x, y Koordinaten für den Kalender (oben, links) / x, y coordinates for the calendar (top, left) | |
local mainx=10 | |
local mainy=16 | |
-- End(e) x,y | |
-- Parameter Grid Berechnung Monat / Parameters grid calculation month | |
local time=os.time{year=os.date("%Y"), month=os.date("%m"), day=1} | |
local weekday=os.date("%w", time) | |
local mon=tonumber(os.date("%m"))+1 | |
local time=os.time{year=os.date("%Y"), month=mon, day=0} | |
local lastday=tonumber(os.date("%d", time)) | |
local day=tonumber(os.date("%d")) | |
local weekday=tonumber(weekday) | |
local start=1 | |
local posabsbg=0 | |
if weekday == 0 then | |
start=-5 | |
posabsbg=day+6 | |
else | |
start=(weekday-2)*-1 | |
posabsbg=day+weekday-1 | |
end | |
local count=0 | |
local week=1 | |
local wd={} | |
local we={} | |
local workdays="" | |
local weekend="" | |
local bcolor=0xff0000 -- Farbe aktueller Tag / Color current Day | |
local balpha=0.5 -- Alpha aktueller Tag /Alpha current Day | |
-- Ende Berechnung / end Calculation | |
-- Berechnung aktueller Tag Hintergrund / calculate current day Background | |
local yposbg=math.floor(((posabsbg-posabsbg%7)/7)*12+mainy+20) | |
if math.floor(posabsbg%7)==0 then yposbg=math.floor(((posabsbg-posabsbg%7)/7-1)*12+mainy+20) end | |
local xposbg=math.floor((posabsbg%7)*18+mainx-13) | |
if math.floor(posabsbg%7)==0 then xposbg=math.floor((posabsbg%7+7)*18+mainx-13) end | |
draw_day(cr,xposbg,yposbg,bcolor,balpha) -- Funktion Hintergrund aktueller Tag / Function Highlight current Day | |
-- Ende Berechnung aktueller Tag Hintergrund / calculate today Background | |
-- Monatsübersicht zusammenstellen / Compile monthly overview | |
for i=start,lastday do | |
if i<1 then -- old Month | |
if (start==-5 and i==0) then -- Weekend | |
weekend=weekend.." " | |
else -- Work Days | |
workdays=workdays.." " | |
end | |
else | |
if i<10 then | |
if count<5 then | |
workdays=workdays.." "..i | |
else | |
weekend=weekend.." "..i | |
end | |
else | |
if count<5 then | |
workdays=workdays.." "..i | |
else | |
weekend=weekend.." "..i | |
end | |
end | |
end | |
count=count+1 | |
if ( count == 7 or i == lastday ) then | |
wd[week]=workdays | |
we[week]=weekend | |
week=week+1 | |
workdays="" | |
weekend="" | |
count=0 | |
end | |
end | |
-- Ende Monatsübersicht zusammenstellen / End Compile monthly overview | |
-- Schreiben... / write... | |
write_text(cr, mainx+66, mainy, os.date("%B").." "..os.date("%Y"), {font="Dyuthi", size=14, align="c"}) | |
write_text(cr, mainx+1, mainy+17, " Mo Di Mi Do Fr ", {font="Ubuntu Mono", size=12, bold=true, align="l"}) | |
write_text(cr, mainx+91, mainy+17, " Sa So", {font="Ubuntu Mono", size=12, bold=true, color="0x0ab1ff", align="l"}) | |
for w=1,week do | |
wy=mainy+30+((w-1)*12) | |
wx=mainx+90 | |
write_text(cr, mainx, wy, wd[w], {font="Ubuntu Mono", size=12, align="l"}) | |
write_text(cr, wx, wy, we[w], {font="Ubuntu Mono", size=12, align="l", color="0x1e90ff"}) -- Farbe/Color WE | |
end | |
-- Ende Schreiben / End write | |
end | |
function conky_main() | |
if conky_window==nil then return end | |
local cs=cairo_xlib_surface_create(conky_window.display,conky_window.drawable,conky_window.visual, conky_window.width,conky_window.height) | |
local cr=cairo_create(cs) | |
local updates=conky_parse('${updates}') | |
update_num=tonumber(updates) | |
if update_num>5 then | |
color=0xffffff alpha=0.1 typ=1 | |
draw_bg(cr,color,alpha,typ) -- Funktion Hintergrund Conky Bereich / Function Backgrounds Conky Area | |
color=0xffffff alpha=0.8 typ=2 | |
draw_bg(cr,color,alpha,typ) --zeichne Linie um den Bereich / Draw line around Conky Area | |
calendar(cr) -- Hauptfunktion erzeuge / Main | |
end | |
cairo_surface_destroy(cs) | |
cairo_destroy(cr) | |
end |
Author
rdschmidt
commented
Feb 24, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment