You are not logged in.
@ S11
Tank's .
I think i have found the start-script . it have no problems
Start desktop 1 load the to loading conkys & goto to desktop 3, many seconds later to desktop 2 & after other seconds return to desktop 1 without any bugs .
Last edited by loutch (2017-01-08 17:00:55)
Linuxmint 22.1 Xia xfce & mageia 9 XFCE on ssd hp pavilion g7
Xubuntu 18.04 lts & 24.04 lts on ASUS Rog STRIX
Online
^ OH that kind of help.
Here's my script very similar and cleaned up a little:
#!/bin/bash
killall conky
# Start with low sleep on highest desktop
# Increase sleep as desktop lowers to insure the conky is running before changing desktops.
# Commencez par un faible sommeil sur le bureau le plus élevé
# Augmenter le sommeil pendant que le bureau diminue pour s'assurer que le conky est en marche avant de changer de bureau.
# on desktop 4 only | not sticky
###############################
# Use: wmctrl -s 3 <<< wnctrl starts at 0
# (sleep 0 && wmctrl -s 3 && conky -c /media/5/Conky/The_Clock_2-s11.conky) &
# (sleep 0 && wmctrl -s 3 && conky -c /media/5/Conky/The_Clock_2.conky) &
# (sleep 0 && wmctrl -s 3 && conky -c /media/5/Conky/The_Clock_2-Teo.conky) &
(sleep 0 && wmctrl -s 3 && conky -c /media/5/Conky/S12/S12_time_tm.conky) &
(sleep 0 && wmctrl -s 3 && conky -c /media/5/Conky/S12/S12_time_L.conky) &
(sleep 0 && wmctrl -s 3 && conky -c /media/5/Conky/S12/S12_time_R.conky) &
# on desktop 3 only | not sticky
###############################
### (sleep 5 && wmctrl -s 2 && conky -c /media/5/Conky/Stargate/stargate.conky) &
# (sleep 5 && wmctrl -s 2 && conky -c /media/5/Conky/4_Moon/test-moon.conky) &
# (sleep 5 && wmctrl -s 2 && conky -c /media/5/Conky/The_Clock_3-9day_2.conky) &
### (sleep 5 && wmctrl -s 2 && conky -c ~/1_accuweather/S11-Clock-9day-Moon-15.conky) &
### (sleep 5 && wmctrl -s 2 && conky -c ~/1_accuweather/S11-Clock-9day-Moon-16.conky) &
# on desktop 2 only | not sticky
###############################
### (sleep 7 && wmctrl -s 1 && conky -c /media/5/Conky/S11_Rem_Cal.conky) &
### (sleep 7 && wmctrl -s 1 && conky -c /media/5/Conky/S11_Dates.conky) &
# on desktop 1 only | not sticky
###############################
# (sleep 8 && wmctrl -s 0 && conky -c /media/5/Conky/S11_Star_Clock_2.conky) &
# (sleep 8 && wmctrl -s 0 && conky -c ~/1_accuweather/S11_accu_tm_BAR.conky) &
# (sleep 8 && wmctrl -s 0 && conky -c ~/1_accuweather/S11_accu_tm_BAR_2.conky) &
# (sleep 8 && wmctrl -s 0 && conky -c ~/1_accuweather/S11_accu_tm_BAR_2016.conky) &
# (sleep 8 && wmctrl -s 0 && conky -c ~/1_accuweather/S11_accu_bm_BAR.conky) &
# (sleep 8 && wmctrl -s 0 && conky -c ~/1_accuweather/S11_accu_bm_BAR_2.conky) &
(sleep 8 && wmctrl -s 0 && conky -c ~/1_accuweather/S11_accu_tm_BAR_2016-full.conky) &
(sleep 8 && wmctrl -s 0 && conky -c /media/5/Conky/S11_thin_r2_side.conky) &
(sleep 8 && wmctrl -s 0 && conky -c /media/5/Conky/S11_thin_l2_side.conky) &
(sleep 8 && wmctrl -s 0 && conky -c /media/5/Conky/S11_Rem_Today.conky) &
#### (sleep 8 && wmctrl -s 0 && conky -c /media/5/Conky/S11_VRX.conky) &
#### (sleep 8 && wmctrl -s 0 && conky -c /media/5/Conky/S11_9_month_cal.conky) &
#### (sleep 8 && wmctrl -s 0 && conky -c /media/5/Conky/S11_OJO.conky) &
# (sleep 8 && wmctrl -s 0 && conky -c /media/5/Conky/S11_VNSTAT_2.conky) &
# on all desktops | sticky
##########################
# (sleep 8 && wmctrl -s 0 && conky -c /media/5/Conky/S11_MD_Cal-br.conky) &
# (sleep 8 && wmctrl -s 0 && conky -c /media/5/Conky/S11_BAR.conky) &
# (sleep 8 && wmctrl -s 0 && conky -c /media/5/Conky/S11_UVI.conky) &
(sleep 8 && wmctrl -s 0 && conky -c /media/5/Conky/Eagle.conky) &
(sleep 8 && wmctrl -s 0 && conky -c /media/5/Conky/S11_DateTime_br.conky) &
(sleep 8 && wmctrl -s 0 && conky -c /media/5/Conky/S11_Email_01.conky) &
# (sleep 6 && wmctrl -s 0 && conky -c /media/5/Conky/S11-Bottom.conky) &
exit 0
But it is complete and now my active script - because I cleaned it up.
Some of your 'timings' were off.
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
I have cleaned up the dinaj.lua script a bit. Also, the permission came through from the original creator. Here is the updated script.
dinaj.lua
--[[
dinaj.lua
lua script for Do I need a Jacket Conky
easysid
Thursday, 05 January 2017 13:22 IST
Based on the dinaj Rainmeter skin by FlyingHyrax
Credits:
* FlyingHyrax (http://flyinghyrax.deviantart.com)
* https://doineedajacket.com/
* mrpeachy, for the out() function
Updated:
Tuesday, 10 January 2017 16:28 IST
--]]
require 'cairo'
-- replace with your accuweather url. Be sure to use the current-weather url
local url = "http://www.accuweather.com/en/in/delhi/202396/current-weather/202396"
-- update frequency (in conky cycles)
local update_time = 600
-- testing flag. Prints fetched temperature onto the console.
local testing = 1
-- settings table. customize as per your liking
-- default ranges are in degrees Celcius
local t = {
-- temperature settings
JacketThreshold = 15, -- minimum temperature to require a jacket
CoatThreshold = 3, -- minimum temperature to require a coat
unit = "C", -- degrees Celcius
-- text settings
font = "sans", -- font face for the text
color = {0xf0f0f0, 1}, -- {hex, alpha}
-- line 1 - Do you need a jacket
l1 = {
font_size = 35, -- font size
x = 10, -- x position of text
y = 30
},
-- line 2 - outside conditions
l2 = {
font_size = 23, -- font size
x = 20, -- x position of text
y = 70
},
} -- end settings table
--[[ You should not need to edit below this line ]]
local Constants = {
RANGE_MIN = -30,
RANGE_MAX = 50,
ADJECTIVES = {
"damn cold",
"darn cold",
"bone chilling",
"glacial",
"frigid",
"freezing",
"frosty",
"pretty cold",
"chilly",
"brisk",
"cool",
"quite temperate",
"rather mild",
"pretty nice",
"positively balmy",
"extra warm",
"kinda hot",
"roasting",
"scorching",
"oven-like",
"like your hair is on FIRE",
}
}
local first_run = 1
-- main function.
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)
cr = cairo_create(cs)
local updates = tonumber(conky_parse('${updates}'))
local timer = updates % update_time
-- time the fetch data
if timer == 0 or first_run == 1 then
first_run = nil
temperature = fetchData()
if testing then
print("\nTesting Mode. Current temperature", temperature)
end
end
doINeedAJacket(temperature)
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end
-- fetch the webpage, and get the current temperature
function fetchData()
-- use the current weather url
url = string.gsub(url, "weather%-forecast", "current-weather")
local regex = '"small.temp"><em>RealFeel.*</em>%s(-?%d+).-</span>'
local temp = nil
local f = io.popen(string.format("curl --max-time 60 '%s'", url))
local data = f:read("*a")
f:close()
temp = string.match(data, regex)
return tonumber(temp)
end
function doINeedAJacket(temp)
if temp then
local s1 = getMainString(temp)
local s2 = getSubString(temp, t.unit)
out({x=t.l1.x, y=t.l1.y, fs=t.l1.font_size, f=t.font, c=t.color, txt=s1})
out({x=t.l2.x, y=t.l2.y, fs=t.l2.font_size, f=t.font, c=t.color, txt=s2})
else
out({x=10,y=10,txt="Failed to get current weather information"})
end
end
-- Keeps a value inside the given range
function clamp(value, min, max)
local clamped = value
if value < min then
clamped = min
elseif value > max then
clamped = max
end
return clamped
end
-- Adjusts a value and its defined range if the value is negative
function normalize(value, min, max)
local excess = min < 0 and 0 - min or 0
return value + excess, min + excess, max + excess
end
-- Return a value as a percentage of its range
function percentOfRange(value, min, max)
-- normalize
local value, min, max = normalize(value, min, max)
-- maths
local percent = (value / max - min)
-- clamping
return clamp(percent, 0.0, 1.0)
end
-- Convert a number from celsius to fahrenheit
function c2f(celsius)
return (((celsius * 9) / 5) + 32)
end
-- Return a descriptor for the given temperature and scale
function getTempWord(temp, unit)
-- convert our range bounds to fahrenheit if necessary
local unit = unit or 'C'
local tmin = unit == 'C' and Constants.RANGE_MIN or c2f(Constants.RANGE_MIN)
local tmax = unit == 'C' and Constants.RANGE_MAX or c2f(Constants.RANGE_MAX)
-- percentage of our temperature range
local tempPer = percentOfRange(temp, tmin, tmax)
-- index in array of descriptors, based on that percentage
local index = math.ceil(#Constants.ADJECTIVES * tempPer)
-- if temp is 0% of our range, index will be off by one
if index < 1 then index = 1 end
-- return that word
return Constants.ADJECTIVES[index]
end
-- Answer the question
function getMainString(temp)
local negation = (temp > t.JacketThreshold) and " don't" or ""
local outerwear = (temp < t.CoatThreshold) and "coat" or "jacket"
return string.format("You%s need a %s", negation, outerwear)
end
-- Return the appropriate secondary string
function getSubString(temp, unit)
return string.format("It's %s outside", getTempWord(temp, unit))
end
function out(txj)
-- Taken from mrpeachy's wun.lua
-- args: c,a,f,fs,face,x,y,txt,hj,vj,ro,sxo,syo,sfs,sface,sc,sa
local extents=cairo_text_extents_t:create()
tolua.takeownership(extents)
local function justify(jtxt,x,hj,y,vj,f,face,fs)
if face=="normal" then
face={f,CAIRO_FONT_SLANT_NORMAL,CAIRO_FONT_WEIGHT_NORMAL}
elseif face=="bold" then
face={f,CAIRO_FONT_SLANT_NORMAL,CAIRO_FONT_WEIGHT_BOLD}
elseif face=="italic" then
face={f,CAIRO_FONT_SLANT_ITALIC,CAIRO_FONT_WEIGHT_NORMAL}
elseif face=="bolditalic" then
face={f,CAIRO_FONT_SLANT_ITALIC,CAIRO_FONT_WEIGHT_BOLD}
else
print ('face not set correctly - "normal","bold","italic","bolditalic"')
end
cairo_select_font_face (cr,face[1],face[2],face[3])
cairo_set_font_size(cr,fs)
cairo_text_extents(cr,jtxt,extents)
local wx=extents.x_advance
local wd=extents.width
local hy=extents.height
local bx=extents.x_bearing
local by=extents.y_bearing+hy
local tx=x
local ty=y
--set horizontal alignment - l, c, r
if hj=="l" then
x=x-bx
elseif hj=="c" then
x=x-((wx-bx)/2)-bx
elseif hj=="r" then
x=x-wx
else
print ("hj not set correctly - l, c, r")
end
--vj. n=normal, nb=normal-ybearing, m=middle, mb=middle-ybearing, t=top
if vj=="n" then
y=y
elseif vj=="nb" then
y=y-by
elseif vj=="m" then
y=y+((hy-by)/2)
elseif vj=="mb" then
y=y+(hy/2)-by
elseif vj=="t" then
y=y+hy-by
else
print ("vj not set correctly - n, nb, m, mb, t")
end
return face,fs,x,y,rad,rad2,tx,ty
end--justify local function #################
--set variables
local c=txj.c or {0xffffff, 1}
local a=txj.a or 1
local f=txj.f or "monospace"
local fs=txj.fs or 12
local x=txj.x or 100
local y=txj.y or 100
local txt=txj.txt or "text"
local hj=txj.hj or "l"
local vj=txj.vj or "n"
local face=txj.face or "normal"
--print text ################################
local face,fs,x,y=justify(txt,x,hj,y,vj,f,face,fs)
cairo_select_font_face (cr,face[1],face[2],face[3])
cairo_set_font_size(cr,fs)
cairo_move_to (cr,x,y)
cairo_set_source_rgba (cr,rgba_to_r_g_b_a(c))
cairo_show_text (cr,txt)
cairo_stroke (cr)
return nx
end--function out
function rgba_to_r_g_b_a(tcolor)
local color,alpha=tcolor[1],tcolor[2]
return ((color / 0x10000) % 0x100) / 255.,
((color / 0x100) % 0x100) / 255., (color % 0x100) / 255., alpha
end --end rgba
-- Log the descriptor which is returned for various temperatures
local function selftest()
for i = -30, 55, 4 do
-- print(string.format("t=%d, s=%s", i, getTempWord(i)))
print(string.format("\nt=%d:\n%s\n%s\n", i,
getMainString(i), getSubString(i, t.unit)))
end
end
If anyone is interested, it shouldn't be too hard to provide translations for it, as long as the grammar allows simple negation (You do/don't need a jacket).
Last edited by easysid (2017-01-10 11:00:54)
Offline
So ...
S12 says:
Hey, you'll make a conky for anyone and everyone. I want one, a Tower Defence Clock, with a different tower on each hour
So the search for towers started, them I mashed them up with GIMP (don't look damo) and used a blank clock face to position them (it will disappear), added a white circle (LUA - may disappear as well). Next come LUA clock hands and some other 'stuff' in the [TOP SECRET] file.
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
I don't believe this ... {sigh}. She liked nothing, didn't like my choice of towers and while she wanted a tower in the "centre" would not commit to one ... you choose - no not that one, nope, no that's ugly. Well which one - you choose ... GRRRRRRRRRRRRRRRRRRRRRRRR!
So this is what she has and she says "I must like if" I'm always changing it ... doesn't dawn on her because she didn't like this that blah blah ...
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
^ Sits back with beer and popcorn and waits with interest!
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
What are you waiting for ... it's done
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
A simple conky to display album art from deadbeef music player. It polls deadbeef for the current song every few seconds, and looks for folder.jpg file in the directory of current song. If it finds one, it displays it as the cover art, else displays a placeholder.
albumart.lua
--[[
albumart.lua
lua script to display now playing info from deadbeef
easysid
Wednesday, 18 January 2017 19:19 IST
]]--
--[[
A simple lua script to display the album art for deadbeef.
All this lua jugglery is needed because conky won't accept spaces in a filename,
and I can't get covergloobus to work
The script polls deadbeef every (few) seconds for the nowplaying information.
It then looks for folder.jpg (change it in filename option) file in the directory
of the current song. If it doesn't find one, it uses a default image as a
placeholder. There are a lot of shortcomings in this approach, but it works quite
well for a well organized music collection (Artist/Album/songs).
The text and progressbar are anchored to the albumart image horizontally, which
is to say that their x coordinate is calculated from the image dimensions. It helps
to keep things aligned. The progressbar is also anchored vertically.
That's about it.
]]--
require 'cairo'
require 'imlib2'
-- placeholder cover
local default_cover = "notfound.jpg"
-- default file to look for
local filename = "folder.jpg"
-- how often to update (in conky cycles)
local timer = 2
local settings_t = {
-- text settings
pad = 10, -- the x offset from image. We use this to align everything
color = {0xcccccc, 1},
font = 'Blacksword',
-- title
y1 = 40,
size1 = 30,
-- artist
y2 = 80,
size2 = 20,
-- image
img_x = 0,
img_y = 0,
img_size = 120, -- square
-- progress bar
bar_h = 5,
bar_w = 350,
bar_base = {0xa0a0a0, 0.2},
} -- end settings
-- ###### should not need to edit below this line ###### --
local fields = {artist = "", title = "", cover = "", perc = ""}
local oldpath = nil
local have_info = nil
local first_run = true
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)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
if (updates % timer == 0) or first_run then
first_run = nil
have_info = fetch_data()
end
if have_info then
drawEverything(settings_t)
end
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr = nil
end --end main()
function fetch_data()
local command = [[ deadbeef --nowplaying-tf \
'%artist%^%title%^%path%^%playback_time_seconds%^%length_seconds%' \
2> /dev/null
]]
local f = io.popen(command)
local data = f:read("*a")
f:close()
local t = {}
for i in string.gmatch(data, "([^%^]+)") do
t[#t + 1] = i
end
if #t ~= 5 then return nil end
local coverpath = t[3]:match("(.*/)")
if coverpath ~= oldpath then
print("New directory")
oldpath = coverpath
-- see if cover exists
art = coverpath..filename
local f = io.open(art, "r")
if f == nil then art = default_cover end
end
local p = tonumber(t[4])/tonumber(t[5])
fields.artist = t[1]
fields.title = t[2]
fields.cover = art
fields.perc = p
return true
end
function drawEverything(t)
local x1 = t.img_x + t.img_size + t.pad
local bar_y = t.img_y + t.img_size - 2*t.bar_h
-- album art
draw_image(fields.cover, t.img_x, t.img_y, t.img_size)
-- title
out(fields.title, x1, t.y1, t.color, t.font, t.size1)
-- artist
out(fields.artist, x1, t.y2, t.color, t.font, t.size2)
-- progress bar
draw_bars(x1, bar_y, t.bar_w, t.bar_h, t.color, t.bar_base, fields.perc)
end
function draw_image(file, x, y, size)
local image = imlib_load_image(file)
if image == nil then return end
imlib_context_set_image(image)
local scaled = imlib_create_cropped_scaled_image(0,0,
imlib_image_get_width(), imlib_image_get_height(),
size, size)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(x, y)
imlib_free_image()
image = nil
end
function out(text, x, y, color, font, size)
cairo_select_font_face(cr, font, 0, 0)
cairo_set_font_size(cr, size)
cairo_set_source_rgba (cr, rgba_to_r_g_b_a(color))
cairo_move_to(cr, x, y)
cairo_show_text(cr, text)
cairo_stroke(cr)
end
function draw_bars(x, y, width, height, col, bcol, perc )
-- draw base rectangle
cairo_set_line_width(cr, 1)
cairo_set_source_rgba (cr, rgba_to_r_g_b_a(bcol))
cairo_rectangle(cr, x, y, width, height)
cairo_fill(cr)
-- draw overlay rectangle
cairo_set_source_rgba (cr, rgba_to_r_g_b_a(col))
cairo_rectangle(cr, x, y, perc*width, height)
cairo_fill(cr)
end -- end draw_bars()
function rgba_to_r_g_b_a(tcolor)
local color,alpha=tcolor[1],tcolor[2]
return ((color / 0x10000) % 0x100) / 255.,
((color / 0x100) % 0x100) / 255., (color % 0x100) / 255., alpha
end
Offline
I don't listen to music on my computer, but I do like a nice conky. And that font gives this conky "style". Nicely done!
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
OK, damo, sitting comphy with your beer and popcorn?
Renamed it and made this because S12 said leave mine alone.
So now there is an S11 version:
The meat of it all:
update_interval 1
# CLOCK LUA
lua_load /media/5/Conky/S12_TDClock/S12_TDClock.lua
lua_draw_hook_pre main
lua_load /media/5/Conky/S12_TDClock/S12-TDC-overlay.lua
lua_draw_hook_post start
lua_load /media/5/Conky/LUA/draw-bg.lua
# 1 = 20 corner_radius
# 2 = 0 x_position l|r
# 3 = 0 y_position u|d
# 4 = 0 width
# 5 = 0 height
# 6 = 0x000000 color
# 7 = 0.4 alpha
TEXT
${lua conky_draw_bg 065 420 015 130 130 0x000000 0.4}\
${lua conky_draw_bg 065 212 075 130 130 0x000000 0.4}\
${lua conky_draw_bg 065 615 075 130 130 0x000000 0.4}\
${lua conky_draw_bg 065 075 220 130 130 0x000000 0.4}\
${lua conky_draw_bg 065 755 220 130 130 0x000000 0.4}\
${lua conky_draw_bg 065 025 410 130 130 0x000000 0.4}\
${lua conky_draw_bg 125 360 365 250 250 0x000000 0.4}\
${lua conky_draw_bg 065 815 410 130 130 0xffffff 0.4}\
${lua conky_draw_bg 065 075 620 130 130 0xffffff 0.4}\
${lua conky_draw_bg 065 760 620 130 130 0xffffff 0.4}\
${lua conky_draw_bg 065 220 750 130 130 0xffffff 0.4}\
${lua conky_draw_bg 065 618 750 130 130 0xffffff 0.4}\
${lua conky_draw_bg 065 420 810 130 130 0xffffff 0.4}\
${image /media/5/Conky/S12_TDClock/images/12.png -p 450,20}\
${image /media/5/Conky/S12_TDClock/images/1.png -p 645,80}\
${image /media/5/Conky/S12_TDClock/images/2.png -p 780,225}\
${image /media/5/Conky/S12_TDClock/images/3.png -p 840,410}\
${image /media/5/Conky/S12_TDClock/images/4.png -p 790,620}\
${image /media/5/Conky/S12_TDClock/images/5.png -p 650,760}\
${image /media/5/Conky/S12_TDClock/images/6.png -p 445,820}\
${image /media/5/Conky/S12_TDClock/images/7.png -p 250,760}\
${image /media/5/Conky/S12_TDClock/images/8.png -p 110,630}\
${image /media/5/Conky/S12_TDClock/images/9.png -p 40,410}\
${image /media/5/Conky/S12_TDClock/images/10.png -p 107,220}\
${image /media/5/Conky/S12_TDClock/images/11.png -p 240,80}
... and that's it!
Well not quite. Going to try to hook it up to sunrise sunset times.
If the sun is up, 12 light circles, if it's down 12 dark circles.
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
Sweet
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
@easysid,
very noble.
Offline
Running three LUA scripts and I could not get it working in conky v1.10.
Tonight - after sundown - I'll post this again. The circles will be "black" ( Xing fingers )
I watched a test conky go from "Sun is DOWN" (with black circles) which displayed between 'sunset and midnight', and "Sun is down" (with black circles), which displayed on the stroke of midnight - before "sunrise". This morning the sun was up when I got up and the test conky had white circles and the text read: Sun is up.
Yup, at sundown it did it's thing. Circles went into dark mode.
====================
A copy of my wife's TD Clock - she is really hooked on Tower Defence games (an AndGag Tablet)
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
colorfill.lua
--[[
colorfill.lua
easysid
Monday, 23 January 2017 13:44 IST
]]--
require 'cairo'
-- common
local base = {0x404040, 1} -- {base fill color, alpha}
local font_face = 'champagne & limousines'
local settings_t = {
{
label = "CPU",
arg = "cpu cpu0",
max = 100,
x = 20,
y = 280,
color = {0x912d2d, 1},
font = font_face,
size = 80,
},
{
label = "RAM",
arg = "memperc",
max = 100,
x = 210,
y = 280,
color = {0x721d61, 1},
font = font_face,
size = 80,
},
{
label = "BAT",
arg = "battery_percent BAT0",
max = 100,
x = 400,
y = 280,
color = {0x1d7235, 1},
font = font_face,
size = 80,
},
{
label = nil,
arg = "time %H",
max = 24,
x = 80,
y = 160,
color = {0xd07036, 1},
font = font_face,
size = 120
},
{
label = nil,
arg = "time %M",
max = 60,
x = 240,
y = 160,
color = {0x3f75d7, 1},
font = font_face,
size = 105,
},
{
label = nil,
arg = "time %S",
max = 60,
x = 380,
y = 160,
color = {0xbfb622, 1},
font = font_face,
size = 90
}
}
-- ###### should not need to edit below this line ###### --
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)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
if updates > 3 then
for i in ipairs(settings_t) do
drawText(settings_t[i])
end -- for
end
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr = nil
end --end main()
function drawText(t)
local text = conky_parse(string.format("${%s}", t.arg))
local value = tonumber(text)
if t.label then text = t.label end
local x = t.x or 100
local y = t.y or 100
local font = t.font or "sans"
local size = t.size or 50
local col = t.color or {0xFFFFFF, 1}
local max = t.max or 100
local perc = 1 - value/max
local extents=cairo_text_extents_t:create()
tolua.takeownership(extents)
cairo_select_font_face(cr, font, 0, 0)
cairo_set_font_size(cr, size)
cairo_text_extents(cr, text, extents)
local w = extents.width
local h = extents.height
local pat = cairo_pattern_create_linear(x, y-h, x, y)
cairo_pattern_add_color_stop_rgba(pat, perc, rgba_to_r_g_b_a(base))
cairo_pattern_add_color_stop_rgba(pat, perc, rgba_to_r_g_b_a(col))
cairo_set_source(cr, pat)
cairo_move_to(cr, x, y)
cairo_show_text(cr, text)
cairo_stroke(cr)
end
function rgba_to_r_g_b_a(tcolor)
local color,alpha=tcolor[1],tcolor[2]
return ((color / 0x10000) % 0x100) / 255.,
((color / 0x100) % 0x100) / 255., (color % 0x100) / 255., alpha
end
Offline
@ easysid - consider it "borrowed" - I like it.
A nice companion to Wlourf's "Text Widget" script. My version:
--[[TEXT WIDGET v1.42 by Wlourf 07 Feb. 2011
This widget can drawn texts set in the "text_settings" table with some parameters
http://u-scripts.blogspot.com/2010/06/text-widget.html
To call the script in a conky, use, before TEXT
lua_load /path/to/the/script/graph.lua
lua_draw_hook_pre main_graph
and add one line (blank or not) after TEXT
The parameters (all optionals) are :
text - text to display, default = "Conky is good for you"
it can be used with conky variables, i.e. text="my cpu1 is ${cpu cpu1} %")
- coordinates below are relative to top left corner of the conky window
x - x coordinate of first letter (bottom-left), default = center of conky window
y - y coordinate of first letter (bottom-left), default = center of conky window
h_align - horizontal alignement of text relative to point (x,y), default="l"
available values are "l": left, "c" : center, "r" : right
v_align - vertical alignment of text relative to point (x,y), default="b"
available values "t" : top, "m" : middle, "b" : bottom
font_name - name of font to use, default = Free Sans
font_size - size of font to use, default = 14
italic - display text in italic (true/false), default=false
oblique - display text in oblique (true/false), default=false (I don' see the difference with italic!)
bold - display text in bold (true/false), default=false
angle - rotation of text in degrees, default = 0 (horizontal)
colour - table of colours for text, default = plain white {{1,0xFFFFFF,1}}
this table contains one or more tables with format {P,C,A}
P=position of gradient (0 = beginning of text, 1= end of text)
C=hexadecimal colour
A=alpha (opacity) of color (0=invisible,1=opacity 100%)
Examples :
for a plain color {{1,0x00FF00,0.5}}
for a gradient with two colours {{0,0x00FF00,0.5},{1,0x000033,1}}
or {{0.5,0x00FF00,1},{1,0x000033,1}} -with this one, gradient will start in the middle of the text
for a gradient with three colours {{0,0x00FF00,0.5},{0.5,0x000033,1},{1,0x440033,1}}
and so on ...
orientation - in case of gradient, "orientation" defines the starting point of the gradient, default="ww"
there are 8 available starting points : "nw","nn","ne","ee","se","ss","sw","ww"
(n for north, w for west ...)
theses 8 points are the 4 corners + the 4 middles of text's outline
so a gradient "nn" will go from "nn" to "ss" (top to bottom, parallele to text)
a gradient "nw" will go from "nw" to "se" (left-top corner to right-bottom corner)
radial - define a radial gradient (if present at the same time as "orientation", "orientation" will have no effect)
this parameter is a table with 6 numbers : {xa,ya,ra,xb,yb,rb}
they define two circle for the gradient :
xa, ya, xb and yb are relative to x and y values above
reflection_alpha - add a reflection effect (values from 0 to 1) default = 0 = no reflection
other values = starting opacity
reflection_scale - scale of the reflection (default = 1 = height of text)
reflection_length - length of reflection, define where the opacity will be set to zero
calues from 0 to 1, default =1
skew_x,skew_y - skew text around x or y axis
draw_me - if set to false, text is not drawn (default = true or 1)
it can be used with a conky string, if the string returns 1, the text is drawn :
example : "${if_empty ${wireless_essid wlan0}}${else}1$endif",
v1.0 07/06/2010, Original release
v1.1 10/06/2010 Add "orientation" parameter
v1.2 15/06/2010 Add "h_align", "v_align" and "radial" parameters
v1.3 25/06/2010 Add "reflection_alpha", "reflection_length", "reflection_scale",
"skew_x" et "skew_y"
v1.4 07/01/2011 Add draw_me parameter and correct memory leaks, thanks to "Creamy Goodness"
text is parsed inside the function, not in the array of settings
v1.41 26/01/2011 Correct bug for h_align="c"
v1.42 09/02/2011 Correct bug for orientation="ee"
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation version 3 (GPLv3)
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-- MA 02110-1301, USA.
]]
require 'cairo'
function conky_draw_text()
--BEGIN OF PARAMETRES
local ts=os.date("*t")
local text_settings={
--== TIME ==-- ========================================
{
text=conky_parse("${time %T}"),
font_name="Digital Dream",
font_size=102,
bold=true,
x=20,
y=100,
--reflection_alpha=0.7,
--reflection_length=0.7,
colour={{0,0x3D3DFD,1},{1,0xD04BFF,1}},
radial={0,-550,500,00,-4995,5000},
},
}
--------------END OF PARAMETERES----------------
if conky_window == nil then return end
if tonumber(conky_parse("$updates"))<3 then return end
local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
for i,v in pairs(text_settings) do
cr = cairo_create (cs)
display_text(v)
cairo_destroy(cr)
cr = nil
end
cairo_surface_destroy(cs)
end
function rgb_to_r_g_b2(tcolour)
local colour,alpha=tcolour[2],tcolour[3]
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end
function display_text(t)
if t.draw_me==true then t.draw_me = nil end
if t.draw_me~=nil and conky_parse(tostring(t.draw_me)) ~= "1" then return end
local function set_pattern(te)
--this function set the pattern
if #t.colour==1 then
cairo_set_source_rgba(cr,rgb_to_r_g_b2(t.colour[1]))
else
local pat
if t.radial==nil then
local pts=linear_orientation(t,te)
pat = cairo_pattern_create_linear (pts[1],pts[2],pts[3],pts[4])
else
pat = cairo_pattern_create_radial (t.radial[1],t.radial[2],t.radial[3],t.radial[4],t.radial[5],t.radial[6])
end
for i=1, #t.colour do
cairo_pattern_add_color_stop_rgba (pat, t.colour[i][1], rgb_to_r_g_b2(t.colour[i]))
end
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
end
end
--set default values if needed
if t.text==nil then t.text="Conky is good for you !" end
if t.x==nil then t.x = conky_window.width/2 end
if t.y==nil then t.y = conky_window.height/2 end
if t.colour==nil then t.colour={{1,0xFFFFFF,1}} end
if t.font_name==nil then t.font_name="Arial" end
if t.font_size==nil then t.font_size=14 end
if t.angle==nil then t.angle=0 end
if t.italic==nil then t.italic=false end
if t.oblique==nil then t.oblique=false end
if t.bold==nil then t.bold=false end
if t.radial ~= nil then
if #t.radial~=6 then
print ("error in radial table")
t.radial=nil
end
end
if t.orientation==nil then t.orientation="ww" end
if t.h_align==nil then t.h_align="l" end
if t.v_align==nil then t.v_align="b" end
if t.reflection_alpha == nil then t.reflection_alpha=0 end
if t.reflection_length == nil then t.reflection_length=1 end
if t.reflection_scale == nil then t.reflection_scale=1 end
if t.skew_x==nil then t.skew_x=0 end
if t.skew_y==nil then t.skew_y=0 end
cairo_translate(cr,t.x,t.y)
cairo_rotate(cr,t.angle*math.pi/180)
cairo_save(cr)
local slant = CAIRO_FONT_SLANT_NORMAL
local weight = CAIRO_FONT_WEIGHT_NORMAL
if t.italic then slant = CAIRO_FONT_SLANT_ITALIC end
if t.oblique then slant = CAIRO_FONT_SLANT_OBLIQUE end
if t.bold then weight = CAIRO_FONT_WEIGHT_BOLD end
cairo_select_font_face(cr, t.font_name, slant,weight)
for i=1, #t.colour do
if #t.colour[i]~=3 then
print ("error in color table")
t.colour[i]={1,0xFFFFFF,1}
end
end
local matrix0 = cairo_matrix_t:create()
tolua.takeownership(matrix0)
local skew_x,skew_y=t.skew_x/t.font_size,t.skew_y/t.font_size
cairo_matrix_init (matrix0, 1,skew_y,skew_x,1,0,0)
cairo_transform(cr,matrix0)
cairo_set_font_size(cr,t.font_size)
local te=cairo_text_extents_t:create()
tolua.takeownership(te)
local text=conky_parse(t.text)
if text~="" then t.text = text end
cairo_text_extents (cr,t.text,te)
set_pattern(te)
local mx,my=0,0
if t.h_align=="c" then
mx=-te.width/2-te.x_bearing
elseif t.h_align=="r" then
mx=-te.width
end
if t.v_align=="m" then
my=-te.height/2-te.y_bearing
elseif t.v_align=="t" then
my=-te.y_bearing
end
cairo_move_to(cr,mx,my)
cairo_show_text(cr,t.text)
if t.reflection_alpha ~= 0 then
local matrix1 = cairo_matrix_t:create()
tolua.takeownership(matrix1)
cairo_set_font_size(cr,t.font_size)
cairo_matrix_init (matrix1,1,0,0,-1*t.reflection_scale,0,(te.height+te.y_bearing+my)*(1+t.reflection_scale))
cairo_set_font_size(cr,t.font_size)
te=nil
local te=cairo_text_extents_t:create()
tolua.takeownership(te)
cairo_text_extents (cr,t.text,te)
cairo_transform(cr,matrix1)
set_pattern(te)
cairo_move_to(cr,mx,my)
cairo_show_text(cr,t.text)
local pat2 = cairo_pattern_create_linear (0,
(te.y_bearing+te.height+my),
0,
te.y_bearing+my)
cairo_pattern_add_color_stop_rgba (pat2, 0,1,0,0,1-t.reflection_alpha)
cairo_pattern_add_color_stop_rgba (pat2, t.reflection_length,0,0,0,1)
--line is not drawn but with a size of zero, the mask won't be nice
cairo_set_line_width(cr,1)
local dy=te.x_bearing
if dy<0 then dy=dy*(-1) end
cairo_rectangle(cr,mx+te.x_bearing,te.y_bearing+te.height+my,te.width+dy,-te.height*1.05)
cairo_clip_preserve(cr)
cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR)
--cairo_stroke(cr)
cairo_mask(cr,pat2)
cairo_pattern_destroy(pat2)
cairo_set_operator(cr,CAIRO_OPERATOR_OVER)
te=nil
end
end
function linear_orientation(t,te)
local w,h=te.width,te.height
local xb,yb=te.x_bearing,te.y_bearing
if t.h_align=="c" then
xb=xb-w/2
elseif t.h_align=="r" then
xb=xb-w
end
if t.v_align=="m" then
yb=-h/2
elseif t.v_align=="t" then
yb=0
end
local p=0
if t.orientation=="nn" then
p={xb+w/2,yb,xb+w/2,yb+h}
elseif t.orientation=="ne" then
p={xb+w,yb,xb,yb+h}
elseif t.orientation=="ww" then
p={xb,h/2,xb+w,h/2}
elseif vorientation=="se" then
p={xb+w,yb+h,xb,yb}
elseif t.orientation=="ss" then
p={xb+w/2,yb+h,xb+w/2,yb}
elseif t.orientation=="ee" then
p={xb+w,h/2,xb,h/2}
elseif t.orientation=="sw" then
p={xb,yb+h,xb+w,yb}
elseif t.orientation=="nw" then
p={xb,yb,xb+w,yb+h}
end
return p
end
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
Offline
@easysid,
I get in the terminal once this error:
$ Conky: forked to background, pid is 5964
Conky: desktop window (2c0000a) is subwindow of root window (4a5)
Conky: window type - normal
Conky: drawing to created window (0x5000002)
Conky: drawing to double buffer
Conky: llua_do_call: function conky_main execution failed: ...PC/Conky/derivantArt/easysid/farbenUhr/colorfill.lua:105: attempt to perform arithmetic on local 'value' (a nil value)
Conky: llua_do_call: function conky_main execution failed: ...PC/Conky/derivantArt/easysid/farbenUhr/colorfill.lua:105: attempt to perform arithmetic on local 'value' (a nil value)
snip<
label = "DAT",
arg = "fs_used_perc /media/Distris",
max = 100,
x = 400,
y = 280,
color = {0x1d7235, 1},
font = font_face,
size = 80,
>snip
Offline
^Can you show the line above and the line below that code?
It works perfect here (modified for my system:
},
-- Test stuff here
{
label = "M/5",
arg = "fs_used_perc /media/5",
max = 100,
x = 20,
y = 300,
color = {0x1d7235, 1},
font = font_face,
size = 80,
},
{
label = "M/10",
arg = "fs_used_perc /media/10",
max = 100,
x = 200,
y = 300,
color = {0x1d7235, 1},
font = font_face,
size = 80,
},
}
-- ###### should not need to edit below this line ###### --
Terminal:
23 Jan 17 @ 17:44:50 ~
$ pkill -xf "conky -c /media/5/Conky/test.conky" &
[1] 13829
[1]+ Exit 1 pkill -xf "conky -c /media/5/Conky/test.conky"
23 Jan 17 @ 18:02:52 ~
$ conky -c /media/5/Conky/test.conky &
[1] 13855
23 Jan 17 @ 18:03:01 ~
$ Conky: desktop window (265) is root window
Conky: window type - normal
Conky: drawing to created window (0x3c00001)
Conky: drawing to double buffer
23 Jan 17 @ 18:03:05 ~
$
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
@ easysid ... I LIKE IT! It's now the one conky on Desktop #5
https://cdn.scrot.moe/images/2017/01/23/2017-01-23_145338_Scrot11.th.png
I have a triple core AMD so CPU 0 is perfect:-- CPU C=1 P=2 U=3 0=Total/Average
and it's a desktop - no battery. Thanks for another nice script - KUDOS!
Thanks for the kind words.
Full disclosure - I am not a creative person. The conky is based on this rainmeter skin I came across
http://injust29.deviantart.com/art/LIM-T-1-2-344112531
I thought it'd make a nice conky, and wasn't aware if it had been done before. Porting rainmeter skins to conky by just a screenshot is probably fair use. (Right? Right?)
I'll add an option to display day and month in words. It'd make config slightly complicated, but nothing too difficult for us I imagine.
Offline