Code: Select all
--[[
2023 Bleys
Screenshot ist im ersten Kommentar. (gist.github)
Ä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=20
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) -- Markierung "Heute" durch Umrandung / Marking today by border
cairo_fill(cr) -- Markierung "Heute" durch Hintergrund / Marking today by background
end
function draw_bg(cr,color,alpha,typ) -- zeichne Hintergrund Conky Fenster / draw Conky Area Background
local corner_r=0
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,monat,xPos,yPos)
local monoffset=tonumber(monat)
local c_year=tonumber(os.date("%Y"))
local c_mon=tonumber(os.date("%m"))
local c_day=os.date("%d")
if (monoffset<0 and c_mon==1) then
c_year=c_year-1
c_mon=12
elseif (monoffset>0 and c_mon==12) then
c_year=c_year+1
c_mon=1
else
c_mon=c_mon+monoffset
end
-- x, y Koordinaten für den Kalender (oben, links) / x, y coordinates for the calendar (top, left)
local mainx=xPos --10
local mainy=yPos --32
-- End(e) x,y
-- Parameter Grid Berechnung Monat / Parameters grid calculation month
local time=os.time{year=c_year, month=c_mon, day=1} --unixzeit 1. des Monats
local monname=os.date("%B",time)
local weekday=os.date("%w", time) --Wochentag des 1.
local mon=c_mon+1 --Folgemonat
local time=os.time{year=c_year, month=mon, day=0} --unixzeit letzter Tag aktueller monat
local lastday=tonumber(os.date("%d", time)) --letzter Tag des Monats (28,29,30,31)
local day=tonumber(os.date("%d")) -- aktueller Tag
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
if monat==0 then
draw_day(cr,xposbg,yposbg,bcolor,balpha) -- Funktion Hintergrund aktueller Tag / Function Highlight current Day
end
-- 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-16, monname.." "..c_year, {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,-1,10,32) -- Hauptfunktion erzeuge / Main
calendar(cr,0,140,32) -- Hauptfunktion erzeuge / Main
calendar(cr,1,270,32) -- Hauptfunktion erzeuge / Main
end
cairo_surface_destroy(cs)
cairo_destroy(cr)
end