├── dzen2.png ├── gadgets ├── README.textwidth ├── README.kittscanner ├── noisyalert.sh ├── config.mk ├── dbar.h ├── README.gcpubar ├── README.gdbar ├── kittscanner.sh ├── Makefile ├── README.dbar ├── gdbar.c ├── dbar-main.c ├── textwidth.c ├── gcpubar.c └── dbar.c ├── bitmaps ├── alert.xbm ├── battery.xbm ├── envelope.xbm ├── play.xbm ├── volume.xbm ├── music.xbm ├── pause.xbm └── ball.xbm ├── help ├── TODO ├── INSTALL ├── CREDITS ├── README.md ├── LICENSE ├── util.c ├── Makefile ├── action.h ├── config.mk ├── dzen.h ├── action.c ├── README.dzen ├── draw.c └── main.c /dzen2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/minos-org/dzen2/HEAD/dzen2.png -------------------------------------------------------------------------------- /gadgets/README.textwidth: -------------------------------------------------------------------------------- 1 | =================================== 2 | textwidth, (c) 2007 by Robert Manea 3 | =================================== 4 | 5 | Simple utility to calculate the width in pixels of text with a given 6 | font. 7 | 8 | Usage: textwidth 9 | 10 | -------------------------------------------------------------------------------- /bitmaps/alert.xbm: -------------------------------------------------------------------------------- 1 | #define alert_width 16 2 | #define alert_height 16 3 | static unsigned char alert_bits[] = { 4 | 0xff, 0xff, 0x01, 0xf8, 0xf1, 0xf9, 0xe1, 0xc1, 0xe1, 0xc1, 0xe1, 0xc1, 5 | 0xe1, 0xc1, 0xe1, 0xc1, 0xe1, 0xc1, 0xe1, 0xc1, 0x01, 0xc0, 0xe1, 0xc1, 6 | 0xe1, 0xc1, 0x01, 0xc0, 0xff, 0xff, 0xff, 0xff}; 7 | -------------------------------------------------------------------------------- /bitmaps/battery.xbm: -------------------------------------------------------------------------------- 1 | #define battery_width 15 2 | #define battery_height 15 3 | static unsigned char battery_bits[] = { 4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 5 | 0xfc, 0x08, 0xfc, 0x38, 0xfc, 0x38, 0xfc, 0x08, 0xfc, 0x0f, 0x00, 0x00, 6 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 7 | -------------------------------------------------------------------------------- /bitmaps/envelope.xbm: -------------------------------------------------------------------------------- 1 | #define envelope_width 15 2 | #define envelope_height 15 3 | static unsigned char envelope_bits[] = { 4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x1f, 0x0c, 0x18, 0x1c, 0x1c, 5 | 0x34, 0x16, 0xc4, 0x11, 0x84, 0x10, 0x04, 0x10, 0xfc, 0x1f, 0x00, 0x00, 6 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 7 | -------------------------------------------------------------------------------- /bitmaps/play.xbm: -------------------------------------------------------------------------------- 1 | #define play_width 16 2 | #define play_height 16 3 | static unsigned char play_bits[] = { 4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x78, 0x00, 0xf8, 0x01, 5 | 0xf8, 0x07, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x07, 0xf8, 0x01, 0x78, 0x00, 6 | 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 7 | 8 | -------------------------------------------------------------------------------- /bitmaps/volume.xbm: -------------------------------------------------------------------------------- 1 | #define volume_width 16 2 | #define volume_height 16 3 | static unsigned char volume_bits[] = { 4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x1b, 0x60, 0x1b, 0x60, 0x1b, 5 | 0x6c, 0x1b, 0x6c, 0x1b, 0x6c, 0x1b, 0x60, 0x1b, 0x60, 0x1b, 0x00, 0x1b, 6 | 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 7 | -------------------------------------------------------------------------------- /bitmaps/music.xbm: -------------------------------------------------------------------------------- 1 | #define music_width 16 2 | #define music_height 16 3 | static unsigned char music_bits[] = { 4 | 0x00, 0x00, 0xe0, 0x00, 0xe0, 0x03, 0x20, 0x1f, 0x20, 0x1c, 0x20, 0x10, 5 | 0x20, 0x10, 0x20, 0x10, 0x20, 0x10, 0x2c, 0x10, 0x3e, 0x10, 0x1e, 0x16, 6 | 0x0c, 0x1f, 0x00, 0x0f, 0x00, 0x06, 0x00, 0x00 }; 7 | 8 | -------------------------------------------------------------------------------- /bitmaps/pause.xbm: -------------------------------------------------------------------------------- 1 | #define pause_width 16 2 | #define pause_height 16 3 | static unsigned char pause_bits[] = { 4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x1e, 0x78, 0x1e, 0x78, 0x1e, 5 | 0x78, 0x1e, 0x78, 0x1e, 0x78, 0x1e, 0x78, 0x1e, 0x78, 0x1e, 0x78, 0x1e, 6 | 0x78, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 7 | 8 | -------------------------------------------------------------------------------- /bitmaps/ball.xbm: -------------------------------------------------------------------------------- 1 | #define ball_width 19 2 | #define ball_height 19 3 | static unsigned char ball_bits[] = { 4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0f, 0x00, 0xe0, 0x3f, 0x00, 5 | 0xf0, 0x7f, 0x00, 0x78, 0xfc, 0x00, 0x38, 0xf8, 0x00, 0x7c, 0xfe, 0x01, 6 | 0xfc, 0xff, 0x01, 0xfc, 0xff, 0x01, 0xfc, 0xff, 0x01, 0xfc, 0xff, 0x01, 7 | 0xf8, 0xff, 0x00, 0xf8, 0xff, 0x00, 0xf0, 0x7f, 0x00, 0xe0, 0x3f, 0x00, 8 | 0x80, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; 9 | -------------------------------------------------------------------------------- /gadgets/README.kittscanner: -------------------------------------------------------------------------------- 1 | ======================================== 2 | kitt-scanner, (c) 2007 by Robert Manea 3 | ======================================== 4 | 5 | This is just a fun gadget and wants to show what can be done with dzen 6 | other than just displaying text ;). 7 | 8 | It implements sort of a KITT (Knight Rider, TV series) scanner in shell 9 | script. 10 | 11 | There are some settings that you can tweak to your likings, see 12 | "kittscanner.sh" for further details. 13 | 14 | 15 | -------------------------------------------------------------------------------- /gadgets/noisyalert.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # (c) 2007 by Robert Manea 4 | # 5 | # A noisy alert for dzen 6 | # 7 | # Syntax noisyalert.sh [Message] [TIMEOUT in seconds] | dzen2 8 | 9 | ALERTMSG=${1:-"Alert"} 10 | ALERTSEC=${2:-10} 11 | 12 | RECTW=10 13 | RECTH=10 14 | 15 | 16 | while [ $ALERTSEC -ne 0 ]; do 17 | 18 | if [ `expr $ALERTSEC % 2` -eq 0 ]; then 19 | echo "^r(${RECTW}x${RECTH}) $ALERTMSG" 20 | else 21 | echo "^ro(${RECTW}x${RECTH}) $ALERTMSG" 22 | fi 23 | 24 | ALERTSEC=`expr $ALERTSEC - 1` 25 | sleep 1 26 | done 27 | 28 | -------------------------------------------------------------------------------- /help: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # (c) 2007, by Robert Manea 4 | 5 | OPTS='-bg #111111 -fg grey70 -p -l 30 -e onstart=uncollapse,scrollhome;button5=scrolldown;key_Down=scrolldown;button4=scrollup;key_Up=scrollup;key_Page_Down=scrolldown:30;key_Page_Up=scrollup:30;key_Escape=exit;button3=exit;entertitle=grabkeys;enterslave=grabkeys;leaveslave=ungrabkeys' 6 | 7 | if test -x ./dzen2 ; then 8 | (echo "^fg(#323232)^bg(#5FBF77) Documentation (use: scrollwheel, arrow keys, PgUP/PgDown to scroll. Escape or right mouse button to quit) "; cat README.dzen) | ./dzen2 $OPTS 9 | else 10 | echo "Please type 'make' to build dzen and rerun help" 11 | fi 12 | -------------------------------------------------------------------------------- /gadgets/config.mk: -------------------------------------------------------------------------------- 1 | # Customize below to fit your system 2 | 3 | # DPKG build flags: 4 | CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS) 5 | CFLAGS:=$(shell dpkg-buildflags --get CFLAGS) 6 | CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS) 7 | LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS) 8 | CFLAGS+=$(CPPFLAGS) 9 | 10 | # paths 11 | PREFIX = /usr 12 | MANPREFIX = ${PREFIX}/share/man 13 | 14 | X11INC = /usr/X11R6/include 15 | INCS = -I. -I/usr/include -I${X11INC} 16 | 17 | X11LIB = /usr/X11R6/lib 18 | LIBS = -L/usr/lib 19 | 20 | CFLAGS += -Os ${INCS} 21 | LDFLAGS += ${LIBS} 22 | 23 | # compiler and linker 24 | CC = gcc 25 | LD = ${CC} 26 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | # documentation 2 | 3 | o `-dock' and `-geometry' options are undocumented 4 | 5 | 6 | # X related 7 | 8 | o XRandR support (MEDIUM PRIORITY) 9 | o cache XPM files in order to improve drawing 10 | performace (HIGH PRIORITY, done in svn trunk) 11 | 12 | 13 | # extend available actions 14 | 15 | o set font action (LOW PRIORITY) 16 | o any other useful action (LOW PRIORITY) 17 | 18 | 19 | # user interface 20 | 21 | o improve in-text command to draw 22 | to the title window (MEDIUM PRIORITY, done in svn trunk) 23 | o auto fit window width to 24 | text length (MEDIUM PRIORITY, done in svn trunk) 25 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | ================================== 2 | dzen, (c) 2007 by Robert Manea 3 | ================================== 4 | 5 | 6 | Edit config.mk to match your local setup (dzen is installed into 7 | the /usr/local namespace by default). 8 | 9 | Afterwards enter the following command to build and install dzen (if 10 | necessary as root): 11 | 12 | make clean install 13 | 14 | 15 | Optionally if you want to use dzen's gadgets: 16 | 17 | cd gadgets 18 | make clean install 19 | 20 | 21 | Note: By default dzen will not be compiled with Xinerama and XPM support. 22 | Uncomment the respective lines in config.mk to change this. 23 | 24 | 25 | Use "./help" to view a nicely formated version of the documentation. 26 | -------------------------------------------------------------------------------- /gadgets/dbar.h: -------------------------------------------------------------------------------- 1 | #ifndef __DBAR_H 2 | #define __DBAR_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define MAX_GRAPH_VALS 1024 10 | 11 | typedef struct { 12 | const char *bg; 13 | const char *fg; 14 | const char *label; 15 | char sym; 16 | double val; 17 | double minval; 18 | double maxval; 19 | int mode; 20 | int style; 21 | int width; 22 | int height; 23 | int segw; 24 | int segh; 25 | int segb; 26 | int gs; 27 | int gw; 28 | int gc; 29 | char gb[MAX_GRAPH_VALS]; 30 | int pnl; 31 | } Dbar; 32 | 33 | enum mode { textual, graphical }; 34 | enum style { norm, outlined, vertical, graph, pie }; 35 | 36 | void fdbar(Dbar *dbar, FILE *stream); 37 | void dbardefaults(Dbar *dbar, int mode); 38 | 39 | #endif /* __DBAR_H */ 40 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | ================================== 2 | dzen, (c) 2007 by Robert Manea 3 | ================================== 4 | 5 | 6 | The following people have contributed especially to dzen: 7 | 8 | 9 | Cyrille Bagard 10 | * patch allowing to use EWMH for docking dzen. 11 | 12 | Jason Creighton 13 | * XINERAMA support 14 | * _NET_WM_STRUT_PARTIAL support 15 | 16 | Adam Langley 17 | * patch to add optional timeout to '-p' 18 | 19 | Mauke 20 | * Code clean ups to remove compiler warnings 21 | 22 | Alexander V. Inyukhin 23 | * fix to action handling 24 | 25 | Valery V. Vorotyntsev 26 | * patch to correctly handle the -geometry and -y options for 27 | dzen at the bottom of the screen 28 | * cosmetic code clean ups 29 | 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## dzen2 2 | 3 | [dzen2](https://github.com/minos-org/dzen2/) is a general purpose messaging, notification and menuing program for X11. This is a custom + freeze version, refer to [robm](https://github.com/robm/dzen) for the original one. 4 | 5 |

6 | dzen2 7 |

8 | 9 | ## Quick start 10 | 11 | ### On Ubuntu (only LTS releases) 12 | 13 | 1. Set up the minos archive: 14 | 15 | ``` 16 | $ sudo add-apt-repository ppa:minos-archive/main 17 | ``` 18 | 19 | 2. Install: 20 | 21 | ``` 22 | $ sudo apt-get update && sudo apt-get install dzen2 23 | ``` 24 | 25 | 3. Enjoy ☺! 26 | 27 | ### On other Linux distributions 28 | 29 | 1. Edit config.mk to match your local setup (dzen is installed into the /usr/ namespace by default). 30 | 31 | 2. Type `sudo make clean install` 32 | 33 | ### Requirements 34 | 35 | * libx11-dev 36 | * libxinerama-dev 37 | * libxpm-dev 38 | * libxft-dev 39 | 40 | ## Differences 41 | 42 | * XFT support by default 43 | * XINERAMA support by default 44 | * Configurable docking option -dock b (bottom), -dock t (top) (top) 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT/X Consortium License 2 | 3 | (C)opyright MMVII Robert Manea 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a 6 | copy of this software and associated documentation files (the "Software"), 7 | to deal in the Software without restriction, including without limitation 8 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | and/or sell copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /gadgets/README.gcpubar: -------------------------------------------------------------------------------- 1 | ==================================== 2 | gcpubar, (c) 20007 by Robert Manea 3 | ==================================== 4 | 5 | gcpubar is a CPU utilization meter for Linux. It relies on the existence 6 | of the "/proc/stat" file and generateѕ fully graphical meters viewable with 7 | dzen >= 0.7.0. 8 | 9 | Command line options: 10 | --------------------- 11 | 12 | 13 | -i : Update interval in seconds (default: 1) 14 | You can use positive values 15 | less than 1 for intervals 16 | shorter than a second 17 | 18 | -c : Number of times to display (default: infinite) 19 | the meter 20 | 21 | -w : Width of the meter in pixels (default: 100) 22 | 23 | -h : Height of the meter in pixels (default: 10) 24 | 25 | -fg : Meter foreground color (default: white) 26 | 27 | -bg : Meter background color (default: darkgrey) 28 | 29 | -s : Style, can be either o(utlined) 30 | v(ertical), g(raph) or the default 31 | gauge if no parameter is specified 32 | 33 | -gw : Width of the graph elements (default: 1) 34 | 35 | -gs : Space between the graph 36 | elemements (default: 0) 37 | 38 | -nonl: no new line, don't put 39 | '\n' at the end of the bar (default: do print '\n') 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /gadgets/README.gdbar: -------------------------------------------------------------------------------- 1 | ================================= 2 | gdbar, (c) 2007 by Robert Manea 3 | ================================= 4 | 5 | gdbar is an application that generates fully graphical progress meters, 6 | from some values you supply to it. 7 | 8 | It has the same input semantics as dbar (see README.dbar). In contrast 9 | to dbar, gdbar draws fully graphical meters which are only useful in 10 | combination with dzen >= 0.7.0. 11 | 12 | Options: 13 | -------- 14 | 15 | -fg : foreground color of the meter (default: white) 16 | -bg : background color of the meter (default: darkgrey) 17 | -s : Style, can be either o(utlined), v(ertical), 18 | or the default gauge if no parameter is specified 19 | -sw : Width of the segments 20 | -sh : Height of the vertical segments 21 | -ss : Space between the segments 22 | -max : Value to be considered 100% (default: 100) 23 | -min : Value to be considered 0% (default: 0 ) 24 | -w : Size in pixels to be 25 | considered 100% in the meter (default: 80 ) 26 | -h : bar height 27 | -l : label to be prepended to 28 | the bar (default: '' ) 29 | -o : Draw conky style meters 30 | -nonl: no new line, don't put 31 | '\n' at the end of the bar (default: do print '\n') 32 | 33 | 34 | See README.dbar for further details! 35 | 36 | -------------------------------------------------------------------------------- /util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (C)opyright MMVI-MMVII Anselm R. Garbe 3 | * (C)opyright MMVII Robert Manea 4 | * See LICENSE file for license details. 5 | * 6 | */ 7 | 8 | #include "dzen.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define ONEMASK ((size_t)(-1) / 0xFF) 17 | 18 | void * 19 | emalloc(unsigned int size) { 20 | void *res = malloc(size); 21 | 22 | if(!res) 23 | eprint("fatal: could not malloc() %u bytes\n", size); 24 | return res; 25 | } 26 | 27 | void 28 | eprint(const char *errstr, ...) { 29 | va_list ap; 30 | 31 | va_start(ap, errstr); 32 | vfprintf(stderr, errstr, ap); 33 | va_end(ap); 34 | exit(EXIT_FAILURE); 35 | } 36 | 37 | char * 38 | estrdup(const char *str) { 39 | void *res = strdup(str); 40 | 41 | if(!res) 42 | eprint("fatal: could not malloc() %u bytes\n", strlen(str)); 43 | return res; 44 | } 45 | void 46 | spawn(const char *arg) { 47 | static const char *shell = NULL; 48 | 49 | if(!shell && !(shell = getenv("SHELL"))) 50 | shell = "/bin/sh"; 51 | if(!arg) 52 | return; 53 | /* The double-fork construct avoids zombie processes and keeps the code 54 | * clean from stupid signal handlers. */ 55 | if(fork() == 0) { 56 | if(fork() == 0) { 57 | setsid(); 58 | execl(shell, shell, "-c", arg, (char *)NULL); 59 | fprintf(stderr, "dzen: execl '%s -c %s'", shell, arg); 60 | perror(" failed"); 61 | } 62 | exit(0); 63 | } 64 | wait(0); 65 | } 66 | 67 | -------------------------------------------------------------------------------- /gadgets/kittscanner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # (c) 2007 by Robert Manea 4 | # 5 | # KITT Scanner for dzen - a man, a car, a dzen 6 | # 7 | 8 | 9 | #---[ KITT configuration ]---------------------------------------------- 10 | 11 | SCANNER_LEDS=17 12 | LED_SPACING=3 13 | LED_WIDTH=25 14 | LED_HEIGHT=10 15 | 16 | INACTIVE_LED_COLOR=darkred 17 | ACTIVE_LED_COLOR=red 18 | BG=black 19 | 20 | SLEEP=0.1 21 | 22 | DZEN=dzen2 23 | DZENOPTS="-bg $BG -fg $INACTIVE_LED_COLOR" 24 | 25 | #----------------------------------------------------------------------- 26 | 27 | DFG="^fg(${INACTIVE_LED_COLOR})" 28 | LFG="^fg(${ACTIVE_LED_COLOR})" 29 | 30 | RECT="^r(${LED_WIDTH}x${LED_HEIGHT})" 31 | 32 | i=; j=1; SIGN='+' 33 | 34 | # build a number list "1 2 ... $SCANNER_LEDS" 35 | nr_list_leds() { 36 | l=1 37 | lnr=$1 38 | 39 | while [ $l -le $lnr ]; do 40 | NRLIST=${NRLIST}' '${l} 41 | l=`expr $l + 1` 42 | done 43 | 44 | echo $NRLIST 45 | } 46 | LED_LIST=`nr_list_leds $SCANNER_LEDS` 47 | 48 | while :; do 49 | for i in $LED_LIST; do 50 | if [ "$i" -eq "$j" ]; then 51 | KBAR=${KBAR}"^p(${LED_SPACING})"${LFG}${RECT}${DFG} 52 | else 53 | KBAR=${KBAR}"^p(${LED_SPACING})"${RECT} 54 | fi 55 | 56 | done 57 | 58 | echo $KBAR; KBAR= 59 | 60 | if [ $SIGN = '+' ] && [ $j -ge $SCANNER_LEDS ]; then 61 | j=$SCANNER_LEDS 62 | SIGN='-' 63 | elif [ $SIGN = '-' ] && [ $j -eq 1 ]; then 64 | j=1 65 | SIGN='+' 66 | fi 67 | 68 | j=`expr $j $SIGN 1` 69 | 70 | sleep $SLEEP; 71 | done | $DZEN $DZENOPTS -h `expr $LED_HEIGHT + 4` 72 | -------------------------------------------------------------------------------- /gadgets/Makefile: -------------------------------------------------------------------------------- 1 | # dzen2 gadgets 2 | # (c) 2007 Robert Manea 3 | 4 | include config.mk 5 | 6 | SRC = dbar.c dbar-main.c gdbar.c gcpubar.c textwidth.c 7 | OBJ = ${SRC:.c=.o} 8 | PROGS = dbar gdbar gcpubar textwidth 9 | 10 | all: options $(PROGS) 11 | 12 | options: 13 | @echo dzen2 gadgets build options: 14 | @echo "CFLAGS = ${CFLAGS}" 15 | @echo "LDFLAGS = ${LDFLAGS}" 16 | @echo "CC = ${CC}" 17 | @echo "LD = ${LD}" 18 | 19 | .c.o: 20 | @echo CC $< 21 | @${CC} -c ${CFLAGS} $< 22 | 23 | ${OBJ}: dbar.h config.mk 24 | 25 | dbar: ${OBJ} 26 | @echo LD $@ 27 | @${LD} -o $@ dbar-main.o dbar.o ${LDFLAGS} 28 | @strip $@ 29 | 30 | gdbar: ${OBJ} 31 | @echo LD $@ 32 | # @${LD} -o $@ gdbar.o dbar.o ${LDFLAGS} -L${X11LIB} -lX11 33 | @${LD} -o $@ gdbar.o dbar.o ${LDFLAGS} 34 | @strip $@ 35 | 36 | gcpubar: ${OBJ} 37 | @echo LD $@ 38 | # @${LD} -o $@ gcpubar.o dbar.o ${LDFLAGS} -L${X11LIB} 39 | @${LD} -o $@ gcpubar.o dbar.o ${LDFLAGS} 40 | @strip $@ 41 | 42 | textwidth: ${OBJ} 43 | @echo LD $@ 44 | @${LD} -o $@ textwidth.o ${LDFLAGS} -L${X11LIB} -lX11 45 | @strip $@ 46 | 47 | clean: 48 | @echo cleaning 49 | @rm -f ${OBJ} dbar 50 | @rm -f ${OBJ} gdbar 51 | @rm -f ${OBJ} gcpubar 52 | @rm -f ${OBJ} textwidth 53 | 54 | install: all 55 | @echo installing executable file to ${DESTDIR}${PREFIX}/bin 56 | @mkdir -p ${DESTDIR}${PREFIX}/bin 57 | for prog in $(PROGS); do \ 58 | cp -f $${prog} ${DESTDIR}${PREFIX}/bin/dzen2-$${prog} && \ 59 | chmod 755 ${DESTDIR}${PREFIX}/bin/dzen2-$${prog}; \ 60 | done 61 | 62 | uninstall: 63 | @echo removing executable file from ${DESTDIR}${PREFIX}/bin 64 | @rm -f ${DESTDIR}${PREFIX}/bin/dbar 65 | @rm -f ${DESTDIR}${PREFIX}/bin/gdbar 66 | @rm -f ${DESTDIR}${PREFIX}/bin/gcpubar 67 | @rm -f ${DESTDIR}${PREFIX}/bin/textwidth 68 | 69 | .PHONY: all options clean install uninstall 70 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # dzen2 2 | # (C)opyright MMVII Robert Manea 3 | 4 | include config.mk 5 | 6 | SRC = draw.c main.c util.c action.c 7 | OBJ = ${SRC:.c=.o} 8 | 9 | all: options dzen2 10 | 11 | options: 12 | @echo dzen2 build options: 13 | @echo "CFLAGS = ${CFLAGS}" 14 | @echo "LDFLAGS = ${LDFLAGS}" 15 | @echo "CC = ${CC}" 16 | @echo "LD = ${LD}" 17 | 18 | .c.o: 19 | @echo CC $< 20 | @${CC} -c ${CFLAGS} $< 21 | 22 | ${OBJ}: dzen.h action.h config.mk 23 | 24 | dzen2: ${OBJ} 25 | @echo LD $@ 26 | @${LD} -o $@ ${OBJ} ${LDFLAGS} 27 | @strip $@ 28 | @echo "Run ./help for documentation" 29 | 30 | clean: 31 | @echo cleaning 32 | @rm -f dzen2 ${OBJ} dzen2-${VERSION}.tar.gz 33 | 34 | dist: clean 35 | @echo creating dist tarball 36 | @mkdir -p dzen2-${VERSION} 37 | @mkdir -p dzen2-${VERSION}/gadgets 38 | @mkdir -p dzen2-${VERSION}/bitmaps 39 | @cp -R CREDITS LICENSE Makefile INSTALL README.dzen README help config.mk action.h dzen.h ${SRC} dzen2-${VERSION} 40 | @cp -R gadgets/Makefile gadgets/config.mk gadgets/README.dbar gadgets/textwidth.c gadgets/README.textwidth gadgets/dbar.c gadgets/gdbar.c gadgets/README.gdbar gadgets/gcpubar.c gadgets/README.gcpubar gadgets/kittscanner.sh gadgets/README.kittscanner gadgets/noisyalert.sh dzen2-${VERSION}/gadgets 41 | @cp -R bitmaps/alert.xbm bitmaps/ball.xbm bitmaps/battery.xbm bitmaps/envelope.xbm bitmaps/volume.xbm bitmaps/pause.xbm bitmaps/play.xbm bitmaps/music.xbm dzen2-${VERSION}/bitmaps 42 | @tar -cf dzen2-${VERSION}.tar dzen2-${VERSION} 43 | @gzip dzen2-${VERSION}.tar 44 | @rm -rf dzen2-${VERSION} 45 | 46 | install: all 47 | @echo installing executable file to ${DESTDIR}${PREFIX}/bin 48 | @mkdir -p ${DESTDIR}${PREFIX}/bin 49 | @cp -f dzen2 ${DESTDIR}${PREFIX}/bin 50 | @chmod 755 ${DESTDIR}${PREFIX}/bin/dzen2 51 | 52 | uninstall: 53 | @echo removing executable file from ${DESTDIR}${PREFIX}/bin 54 | @rm -f ${DESTDIR}${PREFIX}/bin/dzen2 55 | 56 | .PHONY: all options clean dist install uninstall 57 | -------------------------------------------------------------------------------- /action.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (C)opyright 2007-2009 Robert Manea 3 | * See LICENSE file for license details. 4 | * 5 | */ 6 | 7 | #define MAXACTIONS 64 8 | #define MAXOPTIONS 64 9 | 10 | /* Event, Action data structures */ 11 | typedef struct AS As; 12 | typedef struct _ev_list ev_list; 13 | typedef int handlerf(char **); 14 | 15 | enum ev_id { 16 | /* startup, exit, input */ 17 | onstart, onexit, onnewinput, 18 | /* mouse buttons */ 19 | button1, button2, button3, button4, button5, button6, button7, 20 | /* entering/leaving windows */ 21 | entertitle, leavetitle, enterslave, leaveslave, 22 | /* external signals */ 23 | sigusr1, sigusr2, 24 | /* key event marker 25 | * must always be the last entry 26 | */ 27 | keymarker 28 | }; 29 | 30 | struct _ev_list { 31 | long id; 32 | As *action[MAXACTIONS]; 33 | ev_list *next; 34 | }; 35 | 36 | struct event_lookup { 37 | const char *name; 38 | long id; 39 | }; 40 | 41 | struct action_lookup { 42 | const char *name; 43 | int (*handler)(char **); 44 | }; 45 | 46 | struct AS { 47 | char *options[MAXOPTIONS]; 48 | int (*handler)(char **); 49 | }; 50 | 51 | 52 | /* utility functions */ 53 | void do_action(long); 54 | int get_ev_id(const char *); 55 | handlerf *get_action_handler(const char *); 56 | void fill_ev_table(char *); 57 | void free_event_list(void); 58 | int find_event(long); 59 | 60 | /* action handlers */ 61 | int a_print(char **); 62 | int a_exit(char **); 63 | int a_exec(char **); 64 | int a_collapse(char **); 65 | int a_uncollapse(char **); 66 | int a_togglecollapse(char **); 67 | int a_stick(char **); 68 | int a_unstick(char **); 69 | int a_togglestick(char **); 70 | int a_scrollup(char **); 71 | int a_scrolldown(char **); 72 | int a_hide(char **); 73 | int a_unhide(char **); 74 | int a_togglehide(char **); 75 | int a_menuprint(char **); 76 | int a_menuprint_noparse(char **); 77 | int a_menuexec(char **); 78 | int a_raise(char **); 79 | int a_lower(char **); 80 | int a_scrollhome(char **); 81 | int a_scrollend(char **); 82 | int a_grabkeys(char **); 83 | int a_ungrabkeys(char **); 84 | int a_grabmouse(char **); 85 | int a_ungrabmouse(char **); 86 | 87 | -------------------------------------------------------------------------------- /gadgets/README.dbar: -------------------------------------------------------------------------------- 1 | ============================== 2 | dbar, (c) 2007 by Robert Manea 3 | ============================== 4 | 5 | dbar is an application that generates semi graphical progress meters, 6 | from some values you supply to it. 7 | 8 | See the usage examples for a description of the expected input format. 9 | 10 | Options: 11 | -------- 12 | 13 | -max : Value to be considered 100% (default: 100) 14 | -min : Value to be considered 0% (default: 0 ) 15 | -w : Number of charcaters to be 16 | considered 100% in the meter (default: 25 ) 17 | -s : Symbol represeting the 18 | percentage value in the meter (default: = ) 19 | -l : label to be prepended to 20 | the bar (default: '' ) 21 | -nonl: no new line, don't put 22 | '\n' at the end of the bar (default: do print '\n') 23 | 24 | dbar lets you define static 0% and 100% marks with the '-min' and '-max' 25 | options or you can provide these marks dynamically at runtime. Static 26 | and dynamic marks can be mixed, in this case the value specified at 27 | runtime will override the comandline value. 28 | 29 | You can specify ranges of numbers, negative, positive or ranges with a 30 | negative min value and positive max value. 31 | 32 | All numbers are treated as double precision floating point, i.e. the 33 | input is NOT limited to integers. 34 | 35 | 36 | Usage examples: 37 | 38 | 1) Static 0% and 100% mark or single value input: 39 | 40 | echo 25 | dbar -m 100 -l Sometext 41 | 42 | Output: Sometext 25% [====== ] 43 | 44 | 2) If your 100% mark changes dynamically or 2-values input: 45 | 46 | echo "50 150" | dbar 47 | ^ ^ 48 | | |__ max. value 49 | | 50 | |__ value to display 51 | 52 | Output: 33% [======== ] 53 | 54 | 3) If your value range is not between [0, maxval] or 3-values input: 55 | 56 | echo "50 -25 150" | dbar 57 | ^ ^ ^ 58 | | | |__ max. value 100% mark 59 | | | 60 | | |_____ min. value 0% mark 61 | | 62 | |________ value to display 63 | 64 | Output: 43% [=========== ] 65 | 66 | 67 | 4) Multiple runs: 68 | 69 | for i in 2 20 50 75 80; do echo $i; sleep 1; done | dbar | dzen2 70 | 71 | Output: Find out yourself. 72 | 73 | -------------------------------------------------------------------------------- /gadgets/gdbar.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dbar.h" 3 | 4 | #define MAXLEN 1024 5 | 6 | int main(int argc, char *argv[]) { 7 | int i, nv; 8 | char aval[MAXLEN], *endptr; 9 | Dbar dbar; 10 | 11 | dbardefaults(&dbar, graphical); 12 | 13 | for(i=1; i < argc; i++) { 14 | if(!strncmp(argv[i], "-w", 3)) { 15 | if(++i < argc) 16 | dbar.width = atoi(argv[i]); 17 | } 18 | else if(!strncmp(argv[i], "-h", 3)) { 19 | if(++i < argc) 20 | dbar.height = atoi(argv[i]); 21 | } 22 | else if(!strncmp(argv[i], "-sw", 4)) { 23 | if(++i < argc) 24 | dbar.segw = atoi(argv[i]); 25 | } 26 | else if(!strncmp(argv[i], "-sh", 4)) { 27 | if(++i < argc) 28 | dbar.segh = atoi(argv[i]); 29 | } 30 | else if(!strncmp(argv[i], "-ss", 4)) { 31 | if(++i < argc) 32 | dbar.segb = atoi(argv[i]); 33 | } 34 | else if(!strncmp(argv[i], "-s", 3)) { 35 | if(++i < argc) { 36 | switch(argv[i][0]) { 37 | case 'o': 38 | dbar.style = outlined; 39 | break; 40 | case 'v': 41 | dbar.style = vertical; 42 | break; 43 | case 'p': 44 | dbar.style = pie; 45 | break; 46 | default: 47 | dbar.style = norm; 48 | break; 49 | } 50 | } 51 | } 52 | else if(!strncmp(argv[i], "-fg", 4)) { 53 | if(++i < argc) 54 | dbar.fg = argv[i]; 55 | } 56 | else if(!strncmp(argv[i], "-bg", 4)) { 57 | if(++i < argc) 58 | dbar.bg = argv[i]; 59 | } 60 | else if(!strncmp(argv[i], "-max", 5)) { 61 | if(++i < argc) { 62 | dbar.maxval = strtod(argv[i], &endptr); 63 | if(*endptr) { 64 | fprintf(stderr, "gdbar: '%s' incorrect number format", argv[i]); 65 | return EXIT_FAILURE; 66 | } 67 | } 68 | } 69 | else if(!strncmp(argv[i], "-min", 5)) { 70 | if(++i < argc) { 71 | dbar.minval = strtod(argv[i], &endptr); 72 | if(*endptr) { 73 | fprintf(stderr, "gdbar: '%s' incorrect number format", argv[i]); 74 | return EXIT_FAILURE; 75 | } 76 | } 77 | } 78 | else if(!strncmp(argv[i], "-l", 3)) { 79 | if(++i < argc) 80 | dbar.label = argv[i]; 81 | } 82 | else if(!strncmp(argv[i], "-nonl", 6)) { 83 | dbar.pnl = 0; 84 | } 85 | else { 86 | fprintf(stderr, "usage: gdbar [-s ] [-w ] [-h ] [-sw ] [-ss ] [-sw ] [-fg ] [-bg ] [-min ] [-max ] [-l ] [-nonl] \n"); 87 | return EXIT_FAILURE; 88 | } 89 | } 90 | 91 | while(fgets(aval, MAXLEN, stdin)) { 92 | nv = sscanf(aval, "%lf %lf %lf", &dbar.val, &dbar.minval, &dbar.maxval); 93 | if(nv == 2) { 94 | dbar.maxval = dbar.minval; 95 | dbar.minval = 0; 96 | } 97 | fdbar(&dbar, stdout); 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /config.mk: -------------------------------------------------------------------------------- 1 | # dzen version 2 | VERSION = 0.9.5-svn 3 | 4 | # DPKG build flags: 5 | CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS) 6 | CFLAGS:=$(shell dpkg-buildflags --get CFLAGS) 7 | CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS) 8 | LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS) 9 | CFLAGS+=$(CPPFLAGS) 10 | 11 | # Customize below to fit your system 12 | 13 | # paths 14 | PREFIX = /usr 15 | MANPREFIX = ${PREFIX}/share/man 16 | 17 | X11INC = /usr/X11R6/include 18 | X11LIB = /usr/X11R6/lib 19 | INCS = -I. -I/usr/include -I${X11INC} 20 | 21 | # Configure the features you want to be supported 22 | # Only one of the following options has to be uncommented, 23 | # all others must be commented! 24 | # 25 | # Uncomment: Remove # from the beginning of respective lines 26 | # Comment : Add # to the beginning of the respective lines 27 | 28 | ## Option 1: No Xinerama no XPM no XFT 29 | #LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 30 | #CFLAGS = -Wall -Os ${INCS} -DVERSION=\"${VERSION}\" 31 | 32 | 33 | ## Option 2: No Xinerama with XPM 34 | #LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXpm 35 | #CFLAGS = -Wall -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XPM 36 | 37 | 38 | # Option 3: With Xinerama no XPM 39 | #LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXinerama 40 | #CFLAGS = -Wall -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XINERAMA 41 | 42 | 43 | ## Option 4: With Xinerama and XPM 44 | #LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXinerama -lXpm 45 | #CFLAGS = -Wall -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XINERAMA -DDZEN_XPM 46 | 47 | 48 | ## Option 5: With XFT 49 | #LIBS += -L/usr/lib -lc -L${X11LIB} -lX11 `pkg-config --libs xft` 50 | #CFLAGS += -Wall -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XFT `pkg-config --cflags xft` 51 | 52 | 53 | ## Option 6: With XPM and XFT 54 | #LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXpm `pkg-config --libs xft` 55 | #CFLAGS = -Wall -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XPM -DDZEN_XFT `pkg-config --cflags xft` 56 | 57 | 58 | ## Option 7: With Xinerama and XPM and XFT 59 | LIBS += -L/usr/lib -lc -L${X11LIB} -lX11 -lXinerama -lXpm `pkg-config --libs xft` 60 | CFLAGS += -Wall -Os ${INCS} -DVERSION=\"${VERSION}\" -DDZEN_XINERAMA -DDZEN_XPM -DDZEN_XFT `pkg-config --cflags xft` 61 | 62 | 63 | 64 | # END of feature configuration 65 | 66 | 67 | LDFLAGS += ${LIBS} 68 | 69 | # Solaris, uncomment for Solaris 70 | #CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" 71 | #LDFLAGS = ${LIBS} 72 | #CFLAGS += -xtarget=ultra 73 | 74 | # Debugging 75 | #CFLAGS = ${INCS} -DVERSION=\"${VERSION}\" -std=gnu89 -pedantic -Wall -W -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -O2 -pipe -DDZEN_XFT `pkg-config --cflags xft` 76 | #LDFLAGS = ${LIBS} 77 | 78 | # compiler and linker 79 | CC = gcc 80 | LD = ${CC} 81 | -------------------------------------------------------------------------------- /gadgets/dbar-main.c: -------------------------------------------------------------------------------- 1 | /* 2 | dbar - ascii percentage meter 3 | 4 | Copyright (c) 2007 by Robert Manea 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | 26 | #include 27 | #include "dbar.h" 28 | 29 | #define MAXLEN 512 30 | 31 | int main(int argc, char *argv[]) { 32 | int i, nv; 33 | char aval[MAXLEN], *endptr; 34 | Dbar dbar; 35 | 36 | dbardefaults(&dbar, textual); 37 | 38 | for(i=1; i < argc; i++) { 39 | if(!strncmp(argv[i], "-w", 3)) { 40 | if(++i < argc) 41 | dbar.width = atoi(argv[i]); 42 | } 43 | else if(!strncmp(argv[i], "-s", 3)) { 44 | if(++i < argc) 45 | dbar.sym = argv[i][0]; 46 | } 47 | else if(!strncmp(argv[i], "-max", 5)) { 48 | if(++i < argc) { 49 | dbar.maxval = strtod(argv[i], &endptr); 50 | if(*endptr) { 51 | fprintf(stderr, "dbar: '%s' incorrect number format", argv[i]); 52 | return EXIT_FAILURE; 53 | } 54 | } 55 | } 56 | else if(!strncmp(argv[i], "-min", 5)) { 57 | if(++i < argc) { 58 | dbar.minval = strtod(argv[i], &endptr); 59 | if(*endptr) { 60 | fprintf(stderr, "dbar: '%s' incorrect number format", argv[i]); 61 | return EXIT_FAILURE; 62 | } 63 | } 64 | } 65 | else if(!strncmp(argv[i], "-l", 3)) { 66 | if(++i < argc) 67 | dbar.label = argv[i]; 68 | } 69 | else if(!strncmp(argv[i], "-nonl", 6)) { 70 | dbar.pnl = 0; 71 | } 72 | else { 73 | fprintf(stderr, "usage: dbar [-w ] [-s ] [-min ] [-max ] [-l ] [-nonl]\n"); 74 | return EXIT_FAILURE; 75 | } 76 | } 77 | 78 | while(fgets(aval, MAXLEN, stdin)) { 79 | nv = sscanf(aval, "%lf %lf %lf", &dbar.val, &dbar.minval, &dbar.maxval); 80 | if(nv == 2) { 81 | dbar.maxval = dbar.minval; 82 | dbar.minval = 0; 83 | } 84 | fdbar(&dbar, stdout); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /gadgets/textwidth.c: -------------------------------------------------------------------------------- 1 | /* 2 | textwidth - calculate width in pixels of text with a given font 3 | 4 | Copyright (C) 2007 by Robert Manea 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | typedef struct _Fnt { 32 | XFontStruct *xfont; 33 | XFontSet set; 34 | int ascent; 35 | int descent; 36 | int height; 37 | } Fnt; 38 | 39 | Fnt font; 40 | Display *dpy; 41 | 42 | unsigned int 43 | textw(const char *text, unsigned int len) { 44 | XRectangle r; 45 | 46 | if(font.set) { 47 | XmbTextExtents(font.set, text, len, NULL, &r); 48 | return r.width; 49 | } 50 | return XTextWidth(font.xfont, text, len); 51 | } 52 | 53 | void 54 | setfont(const char *fontstr) { 55 | char *def, **missing; 56 | int i, n; 57 | 58 | missing = NULL; 59 | if(font.set) 60 | XFreeFontSet(dpy, font.set); 61 | font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); 62 | if(missing) 63 | XFreeStringList(missing); 64 | if(font.set) { 65 | XFontSetExtents *font_extents; 66 | XFontStruct **xfonts; 67 | char **font_names; 68 | font.ascent = font.descent = 0; 69 | font_extents = XExtentsOfFontSet(font.set); 70 | n = XFontsOfFontSet(font.set, &xfonts, &font_names); 71 | for(i = 0, font.ascent = 0, font.descent = 0; i < n; i++) { 72 | if(font.ascent < (*xfonts)->ascent) 73 | font.ascent = (*xfonts)->ascent; 74 | if(font.descent < (*xfonts)->descent) 75 | font.descent = (*xfonts)->descent; 76 | xfonts++; 77 | } 78 | } 79 | else { 80 | if(font.xfont) 81 | XFreeFont(dpy, font.xfont); 82 | font.xfont = NULL; 83 | if(!(font.xfont = XLoadQueryFont(dpy, fontstr))) { 84 | fprintf(stderr, "error, cannot load font: '%s'\n", fontstr); 85 | exit(EXIT_FAILURE); 86 | } 87 | font.ascent = font.xfont->ascent; 88 | font.descent = font.xfont->descent; 89 | } 90 | font.height = font.ascent + font.descent; 91 | } 92 | 93 | int 94 | main(int argc, char *argv[]) 95 | { 96 | char *myfont, *text; 97 | 98 | if(argc < 3) { 99 | fprintf(stderr, "usage: %s \n", argv[0]); 100 | return EXIT_FAILURE; 101 | } 102 | 103 | myfont = argv[1]; 104 | text = argv[2]; 105 | 106 | dpy = XOpenDisplay(0); 107 | if(!dpy) { 108 | fprintf(stderr, "cannot open display\n"); 109 | return EXIT_FAILURE; 110 | } 111 | 112 | setfont(myfont); 113 | printf("%u\n", textw(text, strlen(text))); 114 | 115 | return EXIT_SUCCESS; 116 | } 117 | 118 | -------------------------------------------------------------------------------- /dzen.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (C)opyright 2007-2009 Robert Manea 3 | * See LICENSE file for license details. 4 | * 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #ifdef DZEN_XINERAMA 11 | #include 12 | #endif 13 | #ifdef DZEN_XFT 14 | #include 15 | #endif 16 | 17 | #define FONT "-*-fixed-*-*-*-*-*-*-*-*-*-*-*-*" 18 | #define BGCOLOR "#111111" 19 | #define FGCOLOR "grey70" 20 | #define ESC_CHAR '^' 21 | 22 | #define ALIGNCENTER 0 23 | #define ALIGNLEFT 1 24 | #define ALIGNRIGHT 2 25 | 26 | #define DOCK_NONE 0 27 | #define DOCK_BOTTOM 1 28 | #define DOCK_TOP 2 29 | 30 | #define MIN_BUF_SIZE 1024 31 | #define MAX_LINE_LEN 8192 32 | 33 | #define MAX_CLICKABLE_AREAS 256 34 | 35 | #ifndef Button6 36 | # define Button6 6 37 | #endif 38 | 39 | #ifndef Button7 40 | # define Button7 7 41 | #endif 42 | 43 | enum { ColFG, ColBG, ColLast }; 44 | 45 | /* exapansion directions */ 46 | enum { noexpand, left, right, both }; 47 | 48 | typedef struct DZEN Dzen; 49 | typedef struct Fnt Fnt; 50 | typedef struct TW TWIN; 51 | typedef struct SW SWIN; 52 | typedef struct _Sline Sline; 53 | 54 | struct Fnt { 55 | XFontStruct *xfont; 56 | XFontSet set; 57 | int ascent; 58 | int descent; 59 | int height; 60 | #ifdef DZEN_XFT 61 | XftFont *xftfont; 62 | XGlyphInfo *extents; 63 | int width; 64 | #endif 65 | }; 66 | 67 | /* clickable areas */ 68 | typedef struct _CLICK_A { 69 | int active; 70 | int button; 71 | int start_x; 72 | int end_x; 73 | int start_y; 74 | int end_y; 75 | char cmd[1024]; 76 | } click_a; 77 | extern click_a sens_areas[MAX_CLICKABLE_AREAS]; 78 | extern int sens_areas_cnt; 79 | extern int xorig; 80 | 81 | 82 | /* title window */ 83 | struct TW { 84 | int x, y, width, height; 85 | 86 | char *name; 87 | Window win; 88 | Drawable drawable; 89 | char alignment; 90 | int expand; 91 | int x_right_corner; 92 | Bool ishidden; 93 | }; 94 | 95 | /* slave window */ 96 | struct SW { 97 | int x, y, width, height; 98 | 99 | char *name; 100 | Window win; 101 | Window *line; 102 | Drawable *drawable; 103 | 104 | /* input buffer */ 105 | char **tbuf; 106 | int tsize; 107 | int tcnt; 108 | /* line fg colors */ 109 | unsigned long *tcol; 110 | 111 | int max_lines; 112 | int first_line_vis; 113 | int last_line_vis; 114 | int sel_line; 115 | 116 | char alignment; 117 | Bool ismenu; 118 | Bool ishmenu; 119 | Bool issticky; 120 | Bool ismapped; 121 | }; 122 | 123 | struct DZEN { 124 | int x, y, w, h; 125 | Bool running; 126 | unsigned long norm[ColLast]; 127 | 128 | TWIN title_win; 129 | SWIN slave_win; 130 | 131 | /* sensitive areas */ 132 | Window sa_win; 133 | 134 | const char *fnt; 135 | const char *bg; 136 | const char *fg; 137 | int line_height; 138 | 139 | Display *dpy; 140 | int screen; 141 | unsigned int depth; 142 | 143 | Visual *visual; 144 | GC gc, rgc, tgc; 145 | Fnt font; 146 | Fnt fnpl[64]; 147 | 148 | Bool ispersistent; 149 | Bool tsupdate; 150 | Bool colorize; 151 | unsigned long timeout; 152 | long cur_line; 153 | int ret_val; 154 | 155 | /* should always be 0 if DZEN_XINERAMA not defined */ 156 | int xinescreen; 157 | }; 158 | 159 | extern Dzen dzen; 160 | 161 | void free_buffer(void); 162 | void x_draw_body(void); 163 | 164 | /* draw.c */ 165 | extern void drawtext(const char *text, 166 | int reverse, 167 | int line, 168 | int align); 169 | extern char * parse_line(const char * text, 170 | int linenr, 171 | int align, 172 | int reverse, 173 | int nodraw); 174 | extern long getcolor(const char *colstr); /* returns color of colstr */ 175 | extern void setfont(const char *fontstr); /* sets global font */ 176 | extern unsigned int textw(const char *text); /* returns width of text in px */ 177 | extern void drawheader(const char *text); 178 | extern void drawbody(char *text); 179 | 180 | /* util.c */ 181 | extern void *emalloc(unsigned int size); /* allocates memory, exits on error */ 182 | extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */ 183 | extern char *estrdup(const char *str); /* duplicates str, exits on allocation error */ 184 | extern void spawn(const char *arg); /* execute arg */ 185 | -------------------------------------------------------------------------------- /gadgets/gcpubar.c: -------------------------------------------------------------------------------- 1 | /* 2 | gcpubar - graphical cpu usage bar, to be used with dzen 3 | 4 | Copyright (C) 2007 by Robert Manea, 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | #include "dbar.h" 26 | 27 | /* critical % value, color */ 28 | #define CPUCRIT 75 29 | #define CRITCOL "#D56F6C" 30 | /* medium % value, color */ 31 | #define CPUMED 50 32 | #define MEDCOL "#EBA178" 33 | 34 | struct cpu_info { 35 | unsigned long long user; 36 | unsigned long long sys; 37 | unsigned long long idle; 38 | unsigned long long iowait; 39 | } ncpu, ocpu; 40 | 41 | int main(int argc, char *argv[]) { 42 | int i, t; 43 | double total; 44 | struct cpu_info mcpu; 45 | FILE *statfp; 46 | char buf[256], *ep; 47 | Dbar dbar; 48 | 49 | int counts = 0; 50 | double ival = 1.0; 51 | 52 | dbardefaults(&dbar, graphical); 53 | dbar.mode = graphical; 54 | 55 | for(i=1; i < argc; i++) { 56 | if(!strncmp(argv[i], "-i", 3)) { 57 | if(i+1 < argc) { 58 | ival = strtod(argv[i+1], &ep); 59 | if(*ep) { 60 | fprintf(stderr, "%s: '-i' Invalid interval value\n", argv[0]); 61 | return EXIT_FAILURE; 62 | } 63 | else 64 | i++; 65 | } 66 | } 67 | else if(!strncmp(argv[i], "-s", 3)) { 68 | if(++i < argc) { 69 | switch(argv[i][0]) { 70 | case 'o': 71 | dbar.style = outlined; 72 | break; 73 | case 'g': 74 | dbar.style = graph; 75 | break; 76 | case 'v': 77 | dbar.style = vertical; 78 | break; 79 | case 'p': 80 | dbar.style = pie; 81 | break; 82 | default: 83 | dbar.style = norm; 84 | break; 85 | } 86 | } 87 | } 88 | else if(!strncmp(argv[i], "-c", 3)) { 89 | if(++i < argc) 90 | counts = atoi(argv[i]); 91 | } 92 | else if(!strncmp(argv[i], "-gs", 4)) { 93 | if(++i < argc) 94 | dbar.gs = atoi(argv[i]); 95 | } 96 | else if(!strncmp(argv[i], "-gw", 4)) { 97 | if(++i < argc) 98 | dbar.gw = atoi(argv[i]); 99 | } 100 | else if(!strncmp(argv[i], "-w", 3)) { 101 | if(++i < argc) 102 | dbar.width = atoi(argv[i]); 103 | } 104 | else if(!strncmp(argv[i], "-h", 3)) { 105 | if(++i < argc) 106 | dbar.height = atoi(argv[i]); 107 | } 108 | else if(!strncmp(argv[i], "-sw", 4)) { 109 | if(++i < argc) 110 | dbar.segw = atoi(argv[i]); 111 | } 112 | else if(!strncmp(argv[i], "-sh", 4)) { 113 | if(++i < argc) 114 | dbar.segh = atoi(argv[i]); 115 | } 116 | else if(!strncmp(argv[i], "-ss", 4)) { 117 | if(++i < argc) 118 | dbar.segb = atoi(argv[i]); 119 | } 120 | else if(!strncmp(argv[i], "-fg", 4)) { 121 | if(++i < argc) 122 | dbar.fg = argv[i]; 123 | } 124 | else if(!strncmp(argv[i], "-bg", 4)) { 125 | if(++i < argc) 126 | dbar.bg = argv[i]; 127 | } 128 | else if(!strncmp(argv[i], "-l", 3)) { 129 | if(++i < argc) 130 | dbar.label = argv[i]; 131 | } 132 | else if(!strncmp(argv[i], "-nonl", 6)) { 133 | dbar.pnl = 0; 134 | } 135 | else { 136 | printf("usage: %s [-l