Originally Posted by
Mk32
Love that desktop image, where did you get it from?
Mr Google gave it to me; can't remember how I asked him for it, so here it is...
Originally Posted by
Mk32
Would you also mind posting your conkyrc?
I'd be happy to post my conkyrc, but keep in mind it really doesn't port well to other computers without a lot of work. The music player section requires Pithos to be installed (along with a php script), the mail has to be configured for your accounts, the storage has to have cut points changed depending on your system, and the fancy ///// bar graphs will crash a standard installation of Conky (which is the real bugger).
I think half the fun is trying to figure out how to get Conky to do the things I want; its like a puzzle. But if you want still want my conkyrc, here it is in its full glory...
conkyrc
Code:
############################################################################################
# #
# conkyrc (version 3.2) #
# #
# Written by Petro Dawg (aka Greg): #
# Last updated on 9/1/13 (version 3.2) #
# > Added USB Port 3 which also doubles as Andriod Phone info when plugged in #
# > Added System Volume output when Music Player is on #
# > Theme changed to Robot #
# Updated on 8/22/13 (version 3.1.1) #
# > Mail now included in main conky #
# > Changed layout, fixed length, unused items grey out instead of dissapearing #
# > Launcher only opens and closes main and opens config files #
# Updated on 8/18/13 (version 3.0) #
# > Each Conky Window Launchable/Killable through a Desktop Icon "Conky.desktop" #
# > Mail indicator as seperate conky "conkyemailrc" #
# - includes text files "gmailcount" and "utulsacount" as variable placeholders #
# ] requires conkycal.sh script -no longer used- #
# > Added DVD Drive info #
# > Private IP addresses for wireless and wired connections added #
# > Theme changed to Tux Super Hero #
# Updated on 5/28/13 (version 2.0.1) #
# > Added some trivial system info to a scrolling section at top of conky #
# > Simplified custom bar code to make color control much easier and help stability #
# > Added background image files to handle semi-transparent background #
# > Calendar separated into seperate conky "conkycalrc" #
# Updated on 5/5/13 (version 2.0) #
# > Replaced bar graphs with my own design #
# > Added bar graph for upload and download speeds #
# > Reduced number of font switches to prevent crash #
# Updated on 4/16/13 (version 1.10) #
# > Added Pithos music player information #
# ] System updates only display if updates are available -now displays 0 if none- #
# Updated on 4/2/13 (version 1.09) #
# ] Added calendar -later removed- #
# Updated on 4/1/13 (version 1.08) #
# > Ported to my XCFE system #
# - Changed USB check location to begin at sdc1 (was sdb1) #
# - Deleted CPU2 info (now 1 core system) #
# - Deleted Temp info (sensors not compatible) #
# > Changed color scheme to Blue and White #
# > Limited system update checking to once per hour due to high resource cost of #
# apt-check process #
# > Edited to correct some text alignment issues #
# Updated on 1/4/13 (version 1.07) #
# > Added available sytem update fields #
# ] Added router name and signal strength field (deleted to make room for better bars) #
# > Changed most of the grep commands to awk #
# Updated on 12/30/12 (version 1.06) #
# ] Changed to grey and orange color scheme -later changed- #
# > revamped fonts, reverted many changes made in last version #
# ] Added date field -later removed/replace by calendar- #
# Updated on 12/24/12 (version 1.05) #
# > Changed color scheme to neon -later changed- #
# ] Added fonts for Ubuntu symbol and CPU bar numbers -no longer used- #
# Updated on 9/14/12 (version 1.04) #
# ] Added MAC and Public IP addresses to output -now deactivated but still in code- #
# > USB output will disappear from Conky when USB drive is ejected #
# Updated on 9/2/12 (version 1.03) #
# > Made USB file system output read any USB drive reguardless of name. Supports up to #
# three USB drives. Displays names of each USB drive and memory_used/memory_total #
# > Added more color control #
# > Changed override_utf8_locale value from 'no' to 'yes' (stopped 12.04-3D flashing) #
# > Changed font Ubuntu:bold:size=11 to xftfont Ubuntu:bold:size=11 #
# > Changed no_buffers value from 'no' to 'yes' (fixed ram graph output) #
# > Added degree symbol to temperature output -no longer used- #
# Updated on 8/31/12 (version 1.02) #
# > Deleted redundant outputs and adjusted format to make the display more concise. #
# Updated on 8/26/12 (version 1.01) #
# > Based on source code from http://lonelymachines.org/2012/08/16/simple-conky-config/ #
# > This version has been significately modified to meet my needs and reorganized to #
# add clarity for anyone wanting to modify the code further to meet their own needs. #
# #
# Displays the following PC information on the Desktop within an embedded window: #
# > Operating System details #
# > Number of available system updates #
# > CPU operating speed #
# > Individual core usage #
# > Top 3 processes using CPU resources #
# > Total RAM #
# > Active RAM amount #
# > Top 3 processes using RAM resources #
# > Root folder size and memory used #
# > Home folder size and memory used #
# > USB drive size and memory used (when attached) #
# > Private IP Addresses #
# > Download speed and data Received #
# > Upload speed and data Sent #
# > DVD drive Disk Title #
# > Pithos Music Title, Artist, Album #
# > Monthly Calendar (through another script) #
# > Email count (through another script) #
# > Sytem Volume when music player is on #
# #
# Requires installation of: #
# > conky (available in software center) #
# ] lm-sensors (available in software center) -not needed in current version- #
# > Pithos (http://kevinmehall.net/p/pithos/) #
# > php5-cli (sudo apt-get install php5-cli) #
# > notify-send (pre-installed notifier program in Ubuntu 12.04) #
# #
# Additional information and resources: #
# > To run conky at startup, create an empty file in your home folder, name it #
# ".conky-startup.sh" and copy the following 2 lines in it: #
# !/bin/bash #
# sleep 15 && conky ; #
# Add the path to the .conky-startup.sh file within Startup Applications. #
# > http://conky.sourceforge.net/ #
# > http://www.graphviz.org/doc/info/colors.html #
# > http://www.december.com/html/spec/colorhex.html #
# > alfios, monofonto (for calendar) fonts required #
# > Save fonts to .fonts folder in home screen #
# > To load fonts into Conky after font installation run the following in terminal: #
# fc-cache -fv #
# then reboot system if needed #
# > Conky will crash with this configuraton unless the Fonts.C file is modified #
# #
############################################################################################
#conky performance settings
update_interval 3
total_run_times 0
cpu_avg_samples 4
no_buffers yes
double_buffer yes
override_utf8_locale yes
max_specials 2000 #a little high, but keeps me from having to worry about it
#text_buffer_size 2048 #might be needed to prevent crashes
#max_user_text 65000 #probably never needed, but here if crashes start occuring
#overall position of conky window
alignment br
gap_x 5
gap_y 0
minimum_size 185 200
maximum_width 185
#overall appearance of conky window
own_window yes
own_window_type override
own_window_transparent yes
#own_window_hints undecorated,above,sticky,skip_taskbar,skip_pager
draw_borders no
#own_window_argb_visual yes
#own_window_argb_value 100
#default text apperance
use_xft yes
xftalpha 1
xftfont Alfios:size=12
default_color FFFFFF
draw_shades true
draw_outline no
default_shade_color black
default_outline_color black
uppercase no
#border around graphs
draw_graph_borders no
#colors
color1 33EE99 #FFFF00 #color 1 - 8 is for gradual color change bars
color2 33DD99 #FFDD00
color3 33CC99 #FFBB00
color4 33BB99 #FF9900
color5 33AA99 #FF7700
color6 339999 #FF5500
color7 338899 #FF3300
color8 337799 #FF1100
color9 2B3856 #445566 #grey unused bar segments use 444444 or 666666
color0 33FFEE #FF99FF #orange #green #red #FF9900 #highlighed text (main sections)
TEXT
############################################################################################
# #
# Images loaded into Conky and Header Displayed #
# #
############################################################################################
###
## two sizes of backgound images are used, a longer one if pithos is running
## set to "_light" for dark wallpapers, "_dark" for light wallpapers, and "_medium" for in between
#
${voffset 25}${image ~/.conky/Main/main_light.png -p -5,33 -s 200x876}\
${if_running pithos}${else}${image ~/.conky/Main/grey-music-note-md.png -p 65,823 -s 60x60}${endif}
${image ~/.conky/Main/robot2.png -p 12,40 -s 55x72}\
${color0}${font Alfios:bold:size=12}${goto 76}${execi 1800 lsb_release -a | awk '/Description/ {print $2, $3}'}${color}${font}
###
## the scrolling information below will have to be formated differently if using other
## fonts or if your system outputs are longer than 16 characters long
## scroll (length of display) (step of display) (information to display)
#
${goto 76}${scroll 16 16 ${color}Conky 1.9.1 ${kernel}CPU ${freq_g}GHz RAM ${memmax} Updates ${execi 900 /usr/lib/update-notifier/apt-check --human-readable | awk '/can/ {print $1}'}}
############################################################################################
# #
# CPU Information with Custom Color Changing Bars #
# #
############################################################################################
${voffset -3}${color8}${hr 1}${color}
${color8}${hr 1}${color}
${voffset -28}${color1}${alignc}RESOURCES${color}
${voffset 7}${color0}CPU${voffset 1}${goto 45}${font Impact:size=10}${color9}/////////////////////${goto 45}\
${if_match ${cpu cpu0} > 0}${color1}/\
${if_match ${cpu cpu0} > 5}${color1}/\
${if_match ${cpu cpu0} > 10}${color2}/\
${if_match ${cpu cpu0} > 15}${color2}/\
${if_match ${cpu cpu0} > 20}${color3}/\
${if_match ${cpu cpu0} > 25}${color3}/\
${if_match ${cpu cpu0} > 30}${color3}/\
${if_match ${cpu cpu0} > 35}${color4}/\
${if_match ${cpu cpu0} > 40}${color4}/\
${if_match ${cpu cpu0} > 45}${color4}/\
${if_match ${cpu cpu0} > 50}${color5}/\
${if_match ${cpu cpu0} > 55}${color5}/\
${if_match ${cpu cpu0} > 60}${color5}/\
${if_match ${cpu cpu0} > 65}${color6}/\
${if_match ${cpu cpu0} > 70}${color6}/\
${if_match ${cpu cpu0} > 75}${color6}/\
${if_match ${cpu cpu0} > 80}${color7}/\
${if_match ${cpu cpu0} > 85}${color7}/\
${if_match ${cpu cpu0} > 90}${color7}/\
${if_match ${cpu cpu0} > 95}${color8}/\
${if_match ${cpu cpu0} == 100}${color8}/\
${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}\
${color}${font}${voffset -1}${alignr}${cpu cpu0}%
###
## Top 3 CPU using processes
#
${voffset 2}${goto 15}${color}${top name 1}${color}${alignr}${top cpu 1}
${goto 15}${color}${top name 2}${color}${alignr}${top cpu 2}
${goto 15}${color}${top name 3}${color}${alignr}${top cpu 3}
############################################################################################
# #
# RAM Information with Custom Color Changing Bars #
# #
############################################################################################
${color0}RAM${voffset 1}${goto 45}${font Impact:size=10}${color9}/////////////////////${goto 45}\
${if_match ${memperc} > 0}${color1}/\
${if_match ${memperc} > 5}${color1}/\
${if_match ${memperc} > 10}${color2}/\
${if_match ${memperc} > 15}${color2}/\
${if_match ${memperc} > 20}${color3}/\
${if_match ${memperc} > 25}${color3}/\
${if_match ${memperc} > 30}${color3}/\
${if_match ${memperc} > 35}${color4}/\
${if_match ${memperc} > 40}${color4}/\
${if_match ${memperc} > 45}${color4}/\
${if_match ${memperc} > 50}${color5}/\
${if_match ${memperc} > 55}${color5}/\
${if_match ${memperc} > 60}${color5}/\
${if_match ${memperc} > 65}${color6}/\
${if_match ${memperc} > 70}${color6}/\
${if_match ${memperc} > 75}${color6}/\
${if_match ${memperc} > 80}${color7}/\
${if_match ${memperc} > 85}${color7}/\
${if_match ${memperc} > 90}${color7}/\
${if_match ${memperc} > 95}${color8}/\
${if_match ${memperc} == 100}${color8}/\
${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}\
${color}${font}${voffset -1}${alignr}${memperc}%
###
## Top 3 RAM using processes
#
${voffset 2}${goto 15}${color}${top_mem name 1}${color}${alignr}${top_mem mem 1}
${goto 15}${color}${top_mem name 2}${color}${alignr}${top_mem mem 2}
${goto 15}${color}${top_mem name 3}${color}${alignr}${top_mem mem 3}
###
## Amount of Swap Memory Used
#
${color0}SWAP ${color}${alignr}$swap / $swapmax
############################################################################################
# #
# Storage Media Information #
# #
############################################################################################
###
## Hard-drive information
#
${voffset -3}${color8}${hr 1}${color}
${color8}${hr 1}${color}
${voffset -28}${color1}${alignc}STORAGE${color}
${voffset 7}${color0}Linux ${color}${alignr}${execp df -H | awk '/sda1/ {print $3, "/", $2}'}
${if_empty ${execp df -H | awk '/sdb1/ {print $3, "/", $2}'}}${color9}WinXP${alignr}Not Mounted${color}${else}${color0}WinXP${color}${alignr}${execp df -H | awk '/sdb1/ {print $3, "/", $2}'}${endif}
###
## Displays DVD and USB drive info when plugged in (3 ports)
## Cut points and mount location may need to be adjusted depending on your system
#
${if_empty ${execp df -H | grep 'sr0' | cut -c46-66}}${color9}DVD/CD${alignr}Empty${color}${else}${color0}${execp df -H | grep 'sr0' | cut -c46-66}${color}${alignr}${execp df -H | awk '/sr0/ {print $3, "/", $2}'}${endif}
${if_existing /dev/sdc1}${color0}${execp df -H | grep 'sdc' | cut -c46-58}${color}${alignr}${execp df -H | awk '/sdc1/ {print $3, "/", $2}'}${else}${color9}USB Port 1${alignr}Empty${color}${endif}
${if_existing /dev/sdd1}${color0}${execp df -H | grep 'sdd' | cut -c46-58}${color}${alignr}${execp df -H | awk '/sdd1/ {print $3, "/", $2}'}${else}${color9}USB Port 2${alignr}Empty${color}${endif}
${if_existing /dev/sde1}${color0}${execp df -H | grep 'sde' | cut -c46-58}${color}${alignr}${execp df -H | awk '/sde1/ {print $3, "/", $2}'}${else}${if_existing /media/18DC-5C04}${color0}Andriod${color}${alignr}${execp df -H | awk '/sdc/ {print $3, "/", $2}'}${else}${color9}USB Port 3${alignr}Empty${color}${endif}${endif}
############################################################################################
# #
# Network Information #
# #
############################################################################################
${voffset -3}${color8}${hr 1}${color}
${color8}${hr 1}${color}
${voffset -28}${color1}${alignc}NETWORK${color}
${voffset 7}${color0}Wired${color}${alignr}${addr eth0}
###
## Download speed information, range varies depending on your ISP provided speed
## Bar values will have to be adjusted to reflect your max speed
#
${goto 15}DLS${voffset 1}${goto 50}${font Impact:size=10}${color9}///////////${goto 50}\
${if_match ${downspeedf eth0} > 1}${color1}/\
${if_match ${downspeedf eth0} > 1.7}${color1}/\
${if_match ${downspeedf eth0} > 2.9}${color2}/\
${if_match ${downspeedf eth0} > 4.8}${color2}/\
${if_match ${downspeedf eth0} > 8.2}${color3}/\
${if_match ${downspeedf eth0} > 14}${color3}/\
${if_match ${downspeedf eth0} > 23}${color4}/\
${if_match ${downspeedf eth0} > 40}${color5}/\
${if_match ${downspeedf eth0} > 67}${color6}/\
${if_match ${downspeedf eth0} > 114}${color7}/\
${if_match ${downspeedf eth0} >= 192}${color8}/\
${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}\
${color}${font}${color}${voffset -1}${alignr}${totaldown eth0}
###
## Upload speed information, range varies depending on your ISP provided speed
## Bar values will have to be adjusted to reflect your max speed
#
${goto 15}ULS${voffset 1}${goto 50}${font Impact:size=10}${color9}///////////${goto 50}\
${if_match ${upspeedf eth0} > 1}${color1}/\
${if_match ${upspeedf eth0} > 1.5}${color1}/\
${if_match ${upspeedf eth0} > 2.2}${color2}/\
${if_match ${upspeedf eth0} > 3.2}${color2}/\
${if_match ${upspeedf eth0} > 4.7}${color3}/\
${if_match ${upspeedf eth0} > 6.9}${color3}/\
${if_match ${upspeedf eth0} > 10}${color4}/\
${if_match ${upspeedf eth0} > 15}${color5}/\
${if_match ${upspeedf eth0} > 22}${color6}/\
${if_match ${upspeedf eth0} > 33}${color7}/\
${if_match ${upspeedf eth0} >= 48}${color8}/\
${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}\
${color}${font}${color}${voffset -1}${alignr}${totalup eth0}
${color0}${wireless_essid wlan0}${color} ${wireless_link_qual_perc wlan0}%${alignr}${addr wlan0}
###
## Download speed information, range varies depending on your ISP provided speed
## Bar values will have to be adjusted to reflect your max speed
#
${goto 15}DLS${voffset 1}${goto 50}${font Impact:size=10}${color9}///////////${goto 50}\
${if_match ${downspeedf wlan0} > 1}${color1}/\
${if_match ${downspeedf wlan0} > 1.7}${color1}/\
${if_match ${downspeedf wlan0} > 2.9}${color2}/\
${if_match ${downspeedf wlan0} > 4.8}${color2}/\
${if_match ${downspeedf wlan0} > 8.2}${color3}/\
${if_match ${downspeedf wlan0} > 14}${color3}/\
${if_match ${downspeedf wlan0} > 23}${color4}/\
${if_match ${downspeedf wlan0} > 40}${color5}/\
${if_match ${downspeedf wlan0} > 67}${color6}/\
${if_match ${downspeedf wlan0} > 114}${color7}/\
${if_match ${downspeedf wlan0} >= 192}${color8}/\
${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}\
${color}${font}${color}${voffset -1}${alignr}${totaldown wlan0}
###
## Upload speed information, range varies depending on your ISP provided speed
## Bar values will have to be adjusted to reflect your max speed
#
${goto 15}ULS${voffset 1}${goto 50}${font Impact:size=10}${color9}///////////${goto 50}\
${if_match ${upspeedf wlan0} > 1}${color1}/\
${if_match ${upspeedf wlan0} > 1.5}${color1}/\
${if_match ${upspeedf wlan0} > 2.2}${color2}/\
${if_match ${upspeedf wlan0} > 3.2}${color2}/\
${if_match ${upspeedf wlan0} > 4.7}${color3}/\
${if_match ${upspeedf wlan0} > 6.9}${color3}/\
${if_match ${upspeedf wlan0} > 10}${color4}/\
${if_match ${upspeedf wlan0} > 15}${color5}/\
${if_match ${upspeedf wlan0} > 22}${color6}/\
${if_match ${upspeedf wlan0} > 33}${color7}/\
${if_match ${upspeedf wlan0} >= 48}${color8}/\
${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}${endif}\
${color}${font}${color}${voffset -1}${alignr}${totalup wlan0}
############################################################################################
# #
# E-mail Notification #
# -> Requires installation of conkyEmail #
# sudo add-apt-repository ppa:conky-companions/ppa #
# sudo apt-get update && sudo apt-get install conkyemail #
# #
############################################################################################
${voffset -3}${color8}${hr 1}${color}
${color8}${hr 1}${color}
${voffset -28}${color1}${alignc}E-MAIL${color}
${voffset 7}${color0}U-Tulsa${color}${alignr}${execi 300 conkyEmail -m IMAP -s imap.googlemail.com -o 993 --ssl -u USERNAME_ACCOUNT1_HERE -p PASSWORD_HERE} \
${if_match ${execi 300 conkyEmail -m IMAP -s imap.googlemail.com -o 993 --ssl -u USERNAME_ACCOUNT1_HERE -p PASSWORD_HERE} > ${execi 300 cat ~/.conky/Main/utulsacount.txt}}${execi 300 notify-send -i MailBox " New E-Mail in U-Tulsa"}${endif}\
${execi 300 echo $(conkyEmail -m IMAP -s imap.googlemail.com -o 993 --ssl -u USERNAME_ACCOUNT1_HERE -p PASSWORD_HERE) > ~/.conky/Main/utulsacount.txt}
${color0}G-Mail${color}${alignr}${execi 300 conkyEmail -m IMAP -s imap.googlemail.com -o 993 --ssl -u USERNAME_ACCOUNT2_HERE -p PASSWORD_HERE} \
${if_match ${execi 300 conkyEmail -m IMAP -s imap.googlemail.com -o 993 --ssl -u USERNAME_ACCOUNT2_HERE -p PASSWORD_HERE} > ${execi 300 cat ~/.conky/Main/gmailcount.txt}}${execi 300 notify-send -i MailBox " New E-Mail in G-Mail"}${endif}\
${execi 300 echo $(conkyEmail -m IMAP -s imap.googlemail.com -o 993 --ssl -u USERNAME_ACCOUNT2_HERE -p PASSWORD_HERE) > ~/.conky/Main/gmailcount.txt}
############################################################################################
# #
# Music info from Pithos #
# -> Requires installation of pithos and php5-cli to run a php script #
# http://kevinmehall.net/p/pithos/ #
# sudo apt-get install php5-cli #
# #
############################################################################################
${voffset -3}${color8}${hr 1}${color}
${color8}${hr 1}${color}
${voffset -28}${color1}${alignc}MUSIC PLAYER${color}
${voffset 7}${if_running pithos}${color0}Pithos${color}${alignr}${if_match "${execp amixer get Master | awk '/Front Right:/ {print $7}'}" == "[off]"}Mute${else}\
Volume ${execp amixer get Master | awk '/Front Right:/ {gsub(/[:[]/,"");gsub(/[]]/,"");print $5}'}${endif}\
${else}${alignr}${color9}OFF${color}${endif}
${if_running pithos}${goto 15}${execp php ~/.conky/Main/pithos.php 'title'}
${goto 15}${execp php ~/.conky/Main/pithos.php 'artist'}
${goto 15}${execp php ~/.conky/Main/pithos.php 'album'}
${else}
${endif}
Originally Posted by
Mk32
Initially I had the memory allocation % thingy but as you can see 10.04LTS has yet to even use 1GB of RAM and with 6GB installed I doubt it would need it. In fact I haven't seen the swap space volume increment by one byte yet.
Lucky you. All my computers are old Pentium4s (or Celerons) donated to me from work (they were headed to the dumpster) that I had to clean, rebuild, and upgrade. I have 2 Gig RAM and tend to hover around 20% - 30%. My max swap gets used around 170K - 200K. Eventually (once I finish my degree), I'll build an ungodly powerful PC that will be a borderline Supercomputer, which will probably be out of date in a matter of months . Till then I'll live with my dumpster diving treasures with RAM and Swap on my Conky.
Also, hasn't 10.04LTS reached its end of life yet? Assuming you are not running a Pentium III Xeon or something, don't let your 6 Gig of RAM go to waste. You (or somebody) paid for that RAM, might as well put it to use with the latest and greatest or at least the current 12.04LTS (which will probably still use no more than a Gig).
Originally Posted by
Mk32
I noticed the other day that the traffic downspeed and upspeed wasn't being calculated right.
How did you check it? Is it too high, or too low? We need details man .
Originally Posted by
Mk32
Love those slant // things for your bar graphs.
Yup so do I; of course you have to download the Conky source code, edit the fonts.c file, compile, and install to get them to work (well, work without eventually crashing anyways). If you are actually interested in doing that, the modified fonts.c file is given below.
fonts.c
Code:
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
* vim: ts=4 sw=4 noet ai cindent syntax=c
*
* Conky, a system monitor, based on torsmo
*
* Any original torsmo code is licensed under the BSD license
*
* All code written since the fork of torsmo is licensed under the GPL
*
* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
* Copyright (c) 2005-2012 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
* 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, either version 3 of the License, or
* (at your option) any later version.
*
* 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "conky.h"
#include "fonts.h"
#include "logging.h"
int selected_font = 0;
int font_count = -1;
struct font_list *fonts = NULL;
char fontloaded = 0;
void set_font(void)
{
#ifdef XFT
if (use_xft) return;
#endif /* XFT */
if (font_count > -1 && fonts[selected_font].font) {
XSetFont(display, window.gc, fonts[selected_font].font->fid);
}
}
void setup_fonts(void)
{
if ((output_methods & TO_X) == 0) {
return;
}
#ifdef XFT
if (use_xft) {
if (window.xftdraw) {
XftDrawDestroy(window.xftdraw);
window.xftdraw = 0;
}
window.xftdraw = XftDrawCreate(display, window.drawable,
window.visual, window.colourmap);
}
#endif /* XFT */
set_font();
}
int add_font(const char *data_in)
{
if ((output_methods & TO_X) == 0) {
return 0;
}
/* This code fixes a bug just for my Conky, stops font_count from reaching max and crashing */
if (font_count > 200) {
font_count--;
}
if (font_count < 200) {
font_count++;
}
/*end of my changes*/
if (font_count == 0) {
if (fonts != NULL) {
free(fonts);
}
if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
== NULL) {
CRIT_ERR(NULL, NULL, "malloc");
}
memset(fonts, 0, sizeof(struct font_list));
}
fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1)));
memset(&fonts[font_count], 0, sizeof(struct font_list));
if (fonts == NULL) {
CRIT_ERR(NULL, NULL, "realloc in add_font");
}
// must account for null terminator
if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) {
strncpy(fonts[font_count].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
#ifdef XFT
fonts[font_count].font_alpha = 0xffff;
#endif
} else {
CRIT_ERR(NULL, NULL, "Oops...looks like something overflowed in add_font().");
}
return font_count;
}
void set_first_font(const char *data_in)
{
if ((output_methods & TO_X) == 0) {
return;
}
if (font_count < 0) {
if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
== NULL) {
CRIT_ERR(NULL, NULL, "malloc");
}
memset(fonts, 0, sizeof(struct font_list));
font_count++;
}
if (strlen(data_in) > 1) {
strncpy(fonts[0].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
#ifdef XFT
fonts[0].font_alpha = 0xffff;
#endif
}
}
void free_fonts(void)
{
int i;
if ((output_methods & TO_X) == 0) {
return;
}
if(fontloaded == 0) {
free(fonts);
return;
}
for (i = 0; i <= font_count; i++) {
#ifdef XFT
if (use_xft) {
/*
* Do we not need to close fonts with Xft? Unsure. Not freeing the
* fonts seems to incur a slight memory leak, but it also prevents
* a crash.
*
* XftFontClose(display, fonts[i].xftfont);
*/
fonts[i].xftfont = 0;
} else
#endif /* XFT */
{
XFreeFont(display, fonts[i].font);
fonts[i].font = 0;
}
}
free(fonts);
fonts = 0;
font_count = -1;
selected_font = 0;
#ifdef XFT
if (window.xftdraw) {
XftDrawDestroy(window.xftdraw);
window.xftdraw = 0;
}
#endif /* XFT */
}
void load_fonts(void)
{
int i;
if ((output_methods & TO_X) == 0)
return;
for (i = 0; i <= font_count; i++) {
#ifdef XFT
/* load Xft font */
if (use_xft && fonts[i].xftfont) {
continue;
} else if (use_xft) {
fonts[i].xftfont = XftFontOpenName(display, screen,
fonts[i].name);
if (fonts[i].xftfont) {
continue;
}
NORM_ERR("can't load Xft font '%s'", fonts[i].name);
if ((fonts[i].xftfont = XftFontOpenName(display, screen,
"courier-12")) != NULL) {
continue;
}
NORM_ERR("can't load Xft font '%s'", "courier-12");
if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
CRIT_ERR(NULL, NULL, "can't load font '%s'", "fixed");
}
use_xft = 0;
continue;
}
#endif
/* load normal font */
if (!fonts[i].font && (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
NORM_ERR("can't load font '%s'", fonts[i].name);
if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
CRIT_ERR(NULL, NULL, "can't load font '%s'", "fixed");
}
}
}
fontloaded = 1;
}
Bookmarks