From 3b1918496ea4b20ec61287ffbb9e1573e950fdcc Mon Sep 17 00:00:00 2001 From: gotmor Date: Wed, 1 Aug 2007 19:15:37 +0000 Subject: release 0.7.5 fixed memory leak added in-text commands: ^tw() ^c() ^p() added gadgets: kittscanner gdbar gcpubar git-svn-id: http://dzen.googlecode.com/svn/trunk@149 f2baff5b-bf2c-0410-a398-912abdc3d8b2 --- INSTALL | 25 ++++++ Makefile | 4 +- README | 30 +++++-- README.dzen | 211 ++++++++++++++++++++++++--------------------- TODO | 3 +- bitmaps/music.xbm | 7 ++ bitmaps/pause.xbm | 7 ++ bitmaps/play.xbm | 7 ++ config.mk | 2 +- draw.c | 140 +++++++++++++++++++++--------- dzen.h | 11 +-- gadgets/Makefile | 22 ++++- gadgets/README.gcpubar | 29 +++++++ gadgets/README.gdbar | 29 +++++++ gadgets/README.kittscanner | 14 +++ gadgets/gcpubar.c | 182 ++++++++++++++++++++++++++++++++++++++ gadgets/gdbar.c | 154 +++++++++++++++++++++++++++++++++ gadgets/kittscanner.sh | 70 +++++++++++++++ help | 2 +- main.c | 100 ++++++++++++--------- 20 files changed, 847 insertions(+), 202 deletions(-) create mode 100644 INSTALL create mode 100644 bitmaps/music.xbm create mode 100644 bitmaps/pause.xbm create mode 100644 bitmaps/play.xbm create mode 100644 gadgets/README.gcpubar create mode 100644 gadgets/README.gdbar create mode 100644 gadgets/README.kittscanner create mode 100644 gadgets/gcpubar.c create mode 100644 gadgets/gdbar.c create mode 100755 gadgets/kittscanner.sh diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..9038f5c --- /dev/null +++ b/INSTALL @@ -0,0 +1,25 @@ +================================== + dzen, (c) 2007 by Robert Manea +================================== + + +Edit config.mk to match your local setup (dzen is installed into +the /usr/local namespace by default). + +Afterwards enter the following command to build and install dzen (if +necessary as root): + + make clean install + + +Optionally if you want to use dzen's gadgets: + + cd gadgets + make clean install + + +Note: By default dzen will not be compiled with Xinerama support. + Uncomment the respective lines in config.mk to change this. + + +Use "./help" to view a nicely formated version of the documentation. diff --git a/Makefile b/Makefile index 6b8266e..33d48c1 100644 --- a/Makefile +++ b/Makefile @@ -37,8 +37,8 @@ dist: clean @mkdir -p dzen2-${VERSION}/gadgets @mkdir -p dzen2-${VERSION}/bitmaps @cp -R LICENSE Makefile README.dzen README help config.mk action.h dzen.h ${SRC} dzen2-${VERSION} - @cp -R gadgets/Makefile gadgets/config.mk gadgets/README.dbar gadgets/textwidth.c gadgets/README.textwidth gadgets/dbar.c dzen2-${VERSION}/gadgets - @cp -R bitmaps/alert.xbm bitmaps/ball.xbm bitmaps/battery.xbm bitmaps/envelope.xbm bitmaps/volume.xbm dzen2-${VERSION}/bitmaps + @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 dzen2-${VERSION}/gadgets + @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 @tar -cf dzen2-${VERSION}.tar dzen2-${VERSION} @gzip dzen2-${VERSION}.tar @rm -rf dzen2-${VERSION} diff --git a/README b/README index 2b17ad4..9630f18 100644 --- a/README +++ b/README @@ -12,6 +12,8 @@ Script archive with a collection of interesting ideas: http://gotmor.googlepages.com/dzenscriptarchive +Use "./help" to view a nicely formated version of the documentation. + Features -------- @@ -114,7 +116,9 @@ Dzen's window layout is as follows: `------------------------------------------´ The first line you provide to dzen always goes to the title window, -all other consecutive lines will be drawn to the slave window. +all other consecutive lines will be drawn to the slave window unless +you explicitly overide this with the (5) In-text formating language +command ^tw(). QA: @@ -143,7 +147,9 @@ A3: There are 2 different approaches dzen uses to terminate itself, Q4: Ok, the title and slave thing works, can I update the contents of both windows at the same time? -A4: Sure, see "(4) Simultaneous updates". +A4: Sure, see "(4) Simultaneous updates" or use the in-text + command "^tw()" to explicitly draw to the title windwow. + See section (5) for further details Q5: Can i chnage color of my input at runtime? @@ -209,7 +215,7 @@ The command line syntax is as follows: -e 'event1=action1:option1:...option,...,action;...;event' Every event can take any number of actions and every action can take any number -of options. (Currently limited to 64 each, easily changable in action.h) +of options. (By default limited to 64 each, easily changable in action.h) An example: -e 'button1=exec:xterm:firefox;entertitle=uncollapse,unhide;button3=exit' @@ -384,7 +390,15 @@ Currently the following commands are supported: ^bg(color) set background color ^i(path) draw icon specified by path ^r(WIDTHxHEIGHT) draw a rectangle with the dimensions - WIDTH and HEIGHT + WIDTH and HEIGHT + ^c(RADIUS) draw a circel with size RADIUS pixels + ^p(PIXEL) increment momentary position by PIXEL + ^tw() draw to title window + This command has some annoyances, as only + the input after the command will be drawn + to the title window, so it is best used + only once and as first command per line. + Subject to be improved in the future. These commands can appear anywhere and in any combination in dzen's input. @@ -425,6 +439,9 @@ Some examples: 6x4 rectangle ^r(6x4) ^fg(red)12x8 ^r(12x8) ^fg(yellow)and finally 100x15 ^r(100x15) + Input for relative positioning: + Some text^p(100)^fg(yellow)100 pixels to the right^p(50)^fg(red)50 more pixels to the right + @@ -446,9 +463,8 @@ Examples: * Display header and a message with multiple lines: (echo Header; cal; sleep 20) | dzen2 -l 8 - Displays "Header" in the main alert window and - the output of cal in the 8 lines high slave - window. + Displays "Header" in the title window and the output of cal in the 8 + lines high slave window. * Display updating messages: diff --git a/README.dzen b/README.dzen index bc002c4..d2d4eaa 100644 --- a/README.dzen +++ b/README.dzen @@ -1,5 +1,5 @@ ^fg(lightgreen)================================== -^fg(green) dzen, (c) 2007 by Robert Manea +^fg(#6fbf47) dzen, (c) 2007 by Robert Manea ^fg(lightgreen)================================== A general purpose messaging, notification and menu program @@ -13,8 +13,8 @@ Script archive with a collection of interesting ideas: -^fg(green)Features -^fg(green)-------- +^fg(#6fbf47)Features +^fg(#6fbf47)-------- * scriptable in any language @@ -35,40 +35,40 @@ Script archive with a collection of interesting ideas: * Xinerama support -^fg(green)Requirements -^fg(green)------------ +^fg(#6fbf47)Requirements +^fg(#6fbf47)------------ In order to build dzen you need the Xlib header files. -^fg(green)Installation -^fg(green)------------ +^fg(#6fbf47)Installation +^fg(#6fbf47)------------ Edit config.mk to match your local setup (dzen is installed into the /usr/local namespace by default). Afterwards enter the following command to build and install dzen (if necessary as root): - ^fg(grey70)make clean install + ^fg(grey85)make clean install Optionally if you want to use dzen's gadgets: - ^fg(grey70)cd gadgets - ^fg(grey70)make clean install + ^fg(grey85)cd gadgets + ^fg(grey85)make clean install -^fg(Khaki)Note: By default dzen will not be compiled with Xinerama support. +^fg(Khaki)Note: By default dzen will ^fg(red)not^fg(Khaki) be compiled with Xinerama support. ^fg(Khaki)Uncomment the respective lines in config.mk to change this. -^fg(green)Contact: -^fg(green)-------- +^fg(#6fbf47)Contact: +^fg(#6fbf47)-------- Feature requests, patches or anything else related to dzen can be send -to: rob dot manea at gmail dot com +to: ^fg(Khaki)rob dot manea at gmail dot com -^fg(green)Running dzen -^fg(green)------------ +^fg(#6fbf47)Running dzen +^fg(#6fbf47)------------ dzen accepts a couple of options: -fg foreground color @@ -78,11 +78,11 @@ dzen accepts a couple of options: l(eft), c(center), r(ight) -tw title window width -sa alignment of slave window, see "-ta" - -l lines, see (1) - -e events and actions, ^fg(green)see (2) - -m menu mode, ^fg(green)see (3) + -l lines, ^fg(#6fbf47)see (1) + -e events and actions, ^fg(#6fbf47)see (2) + -m menu mode, ^fg(#6fbf47)see (3) -u update contents of title and - slave window simultaneously, ^fg(green)see (4) + slave window simultaneously, ^fg(#6fbf47)see (4) -p persist EOF (optional timeout in seconds) -x x position -y y position @@ -90,35 +90,37 @@ dzen accepts a couple of options: -xs number of Xinerama screen -v version information - ^fg(green)see (5)^fg(#5FBF77) for the in-text formating language. + ^fg(#6fbf47)see (5)^fg(grey70), for the in-text formating language. -^fg(green)Window layout -^fg(green)------------- +^fg(#6fbf47)Window layout +^fg(#6fbf47)------------- Dzen's window layout is as follows: - ------------------------------------------ - | Title window, single line | - `------------------------------------------´ - | | - | scrollable | - | Slave window | - | multiple lines | - | lines to display simultaneously | - | controlled with the | - | '-l' option | - | | - | | - `------------------------------------------´ +^fg(red) ------------------------------------------ +^fg(red) | Title window, single line | +^fg(red) `------------------------------------------´ +^fg(#6fbf47) | | +^fg(#6fbf47) | scrollable | +^fg(#6fbf47) | Slave window | +^fg(#6fbf47) | multiple lines | +^fg(#6fbf47) | lines to display simultaneously | +^fg(#6fbf47) | controlled with the | +^fg(#6fbf47) | '-l' option | +^fg(#6fbf47) | | +^fg(#6fbf47) | | +^fg(#6fbf47) `------------------------------------------´ The first line you provide to dzen always goes to the title window, -all other consecutive lines will be drawn to the slave window. +all other consecutive lines will be drawn to the slave window unless +you explicitly overide this with the ^fg(#6fbf47)(5) In-text formating language +^fg(grey70)command ^^tw(). -^fg(green)QA: -^fg(green)--- +^fg(#6fbf47)QA: +^fg(#6fbf47)--- Q1: I don't want a slave window, what to do? @@ -130,38 +132,39 @@ Q2: I used the '-l' option but no slave window appears. A2: With the default event/action handling the slave window will only be displayed if you hoover with the mouse over the title - window. See "(2) Events and actions" if you'd like to change + window. See ^fg(#6fbf47)(2) Events and actions ^fg(grey70)if you'd like to change this. Q3: If I echo some text or cat a file dzen closes itself imediatelly. A3: There are 2 different approaches dzen uses to terminate itself, - see next section "Termination". + see next section ^fg(#6fbf47)Termination^fg(grey70). Q4: Ok, the title and slave thing works, can I update the contents of both windows at the same time? -A4: Sure, see "(4) Simultaneous updates". - +A4: Sure, see ^fg(#6fbf47)(4) Simultaneous updates ^fg(grey70)or use the in-text + command ^^tw() to explicitly draw to the title windwow. + See ^fg(#6fbf47)(5) In-Text formating language ^fg(grey70)for further details Q5: Can i chnage color of my input at runtime? A5: Yes, you can change both background and foreground colors and - much more See "(5) In-Text formating language" + much more See ^fg(#6fbf47)(5) In-Text formating language^fg(grey70). Q6: Can I use dzen as a menu? A6: Yes, both vertical and horizontal menus are supported. - See "(3) Menu" for further details. + See ^fg(#6fbf47)(3) Menu ^fg(grey70)for further details. -^fg(green)Termination: -^fg(green)------------ +^fg(#6fbf47)Termination: +^fg(#6fbf47)------------ dzen uses two different approaches to terminate itself: * Timed termination: if EOF is received -> terminate @@ -170,21 +173,21 @@ dzen uses two different approaches to terminate itself: · '-p' with argument n persist for n seconds * Interactive termination: if mouse button3 is clicked -> terminate - - this is the default behaviour, see (2) - - in some modes the Escape key terminates too, see (2) + - this is the default behaviour, ^fg(#6fbf47)see (2) + - in some modes the Escape key terminates too, ^fg(#6fbf47)see (2) -^fg(green)Return values: -^fg(green)-------------- +^fg(#6fbf47)Return values: +^fg(#6fbf47)-------------- 0 - dzen received EOF 1 - some error occured, inspect the error message -user defined - set with 'exit:retval' action, see (2) +user defined - set with 'exit:retval' action, ^fg(#6fbf47)see (2) -^fg(green)(1) Option "-l": Slave window -^fg(green)-------------------------------- +^fg(#6fbf47)(1) Option "-l": Slave window +^fg(#6fbf47)-------------------------------- Enables support for displaying multiple lines. The parameter to "-l" specifies the number of lines to be displayed. @@ -200,8 +203,8 @@ and down if the content exceeds the window height (default action). -^fg(green)(2) Option '-e': Events and actions -^fg(green)----------------------------------- +^fg(#6fbf47)(2) Option '-e': Events and actions +^fg(#6fbf47)----------------------------------- dzen allows the user to associate actions to events. @@ -209,7 +212,7 @@ The command line syntax is as follows: -e 'event1=action1:option1:...option,...,action;...;event' Every event can take any number of actions and every action can take any number -of options. (Currently limited to 64 each, easily changable in action.h) +of options. (By default limited to 64 each, easily changable in action.h) An example: ^fg(grey70) -e 'button1=exec:xterm:firefox;entertitle=uncollapse,unhide;button3=exit' @@ -229,8 +232,8 @@ An example: on button3 event exit dzen -^fg(green)Supported events: -^fg(green)----------------- +^fg(#6fbf47)Supported events: +^fg(#6fbf47)----------------- onstart Perform actions right after startup onexit Perform actions just before exiting @@ -249,8 +252,8 @@ An example: key_KEYNAME Keyboard events (*) - ^fg(green)(*) Keyboard events: - ^fg(green)-------------------- + ^fg(#6fbf47)(*) Keyboard events: + ^fg(#6fbf47)-------------------- Every key can be bound to an action (see below). The format is: key_KEYNAME where KEYNAME is the name of the key as defined in @@ -259,8 +262,8 @@ An example: -^fg(green)Supported actions: -^fg(green)------------------ +^fg(#6fbf47)Supported actions: +^fg(#6fbf47)------------------ exec:command1:..:n execute all given options menuexec executes selected menu entry @@ -288,14 +291,14 @@ An example: ^fg(Khaki)Note: If no events/actions are specified dzen defaults to: - ^fg(green)Title only mode: - ^fg(green)---------------- + ^fg(#6fbf47)Title only mode: + ^fg(#6fbf47)---------------- -e 'button3=exit:13' - ^fg(green)Multiple lines and vertical menu mode: - ^fg(green)-------------------------------------- + ^fg(#6fbf47)Multiple lines and vertical menu mode: + ^fg(#6fbf47)-------------------------------------- -e 'entertitle=uncollapse,grabkeys; enterslave=grabkeys;leaveslave=collapse,ungrabkeys; @@ -304,8 +307,8 @@ An example: key_Escape=ungrabkeys,exit' - ^fg(green)Horizontal menu mode: - ^fg(green)--------------------- + ^fg(#6fbf47)Horizontal menu mode: + ^fg(#6fbf47)--------------------- -e 'enterslave=grabkeys;leaveslave=ungrabkeys; button4=scrollup;button5=scrolldown; @@ -320,11 +323,11 @@ An example: -^fg(green)(3) Option '-m', Menu -^fg(green)--------------------- +^fg(#6fbf47)(3) Option '-m', Menu +^fg(#6fbf47)--------------------- Dzen provides two menu modes, vertical and horizontal menus. You can -access these modes by adding 'v'(ertical) or 'h'(horizontal) to the +access these modes by adding 'v'(ertical) or 'h'(orizontal) to the '-m' option. If nothing is specified dzen defaults to vertical menus. Vertical menu, both invocations are equivalent: @@ -345,8 +348,8 @@ All actions beginning with "menu" work on the selected menu entry. -^fg(green)(4) Option '-u', Simultaneous updates -^fg(green)------------------------------------- +^fg(#6fbf47)(4) Option '-u', Simultaneous updates +^fg(#6fbf47)------------------------------------- This option provides facilities to update the title and slave window at the same time. @@ -371,8 +374,8 @@ of lines to the slave window as defined by the parameter to '-l'. -^fg(green)(5) In-text formating language: -^fg(green)------------------------------- +^fg(#6fbf47)(5) In-text formating language: +^fg(#6fbf47)------------------------------- This feature allows to dynamically (at runtime) format the text dzen displays. @@ -384,7 +387,15 @@ Currently the following commands are supported: ^^bg(color) set background color ^^i(path) draw icon specified by path ^^r(WIDTHxHEIGHT) draw a rectangle with the dimensions - WIDTH and HEIGHT + WIDTH and HEIGHT + ^^c(RADIUS) draw a circel with size RADIUS pixels + ^^p(PIXEL) increment momentary position by PIXEL + ^^tw() draw to title window + This command has some annoyances, as only + the input after the command will be drawn + to the title window, so it is best used + only once and as first command per line + Subject to be improved in the future. These commands can appear anywhere and in any combination in dzen's input. @@ -425,12 +436,14 @@ Some examples: Resulting in: ^fg(grey70)Some text containing ^^ characters + Input for icons: ^^i(bitmaps/envelope.xbm) I am an envelope ^^fg(yellow)and ^^i(bitmaps/battery.xbm) I'm a baterry. Resulting in: ^i(bitmaps/envelope.xbm) I am an envelope ^fg(yellow)and ^i(bitmaps/battery.xbm) I'm a baterry. + Input for rectangles: 6x4 rectangle ^^r(6x4) ^^fg(red)12x8 ^^r(12x8) ^^fg(yellow)and finally 100x15 ^^r(100x15) @@ -438,65 +451,71 @@ Some examples: 6x4 rectangle ^r(6x4) ^fg(red)12x8 ^r(12x8) ^fg(yellow)and finally 100x15 ^r(100x15) + Input for relative positioning: + Some text^^p(100)^^fg(yellow)100 pixels to the right^^p(50)^^fg(red)50 more pixels to the right + + Resulting in: + Some text^p(100)^fg(yellow)100 pixels to the right^p(50)^fg(red)50 more pixels to the right + + -^fg(green)Examples: -^fg(green)--------- +^fg(#6fbf47)Examples: +^fg(#6fbf47)--------- * Display message and timeout after 10 seconds: -^fg(grey70) (echo "This is a message"; sleep 10) | dzen2 -bg darkred -fg grey80 -fn fixed +^fg(grey85) (echo "This is a message"; sleep 10) | dzen2 -bg darkred -fg grey85 -fn fixed * Display message and never timeout: -^fg(grey70) echo "This is a message"| dzen2 -p +^fg(grey85) echo "This is a message"| dzen2 -p * Display updating single line message: -^fg(grey70) for i in $(seq 1 20); do A=${A}'='; print $A; sleep 1; done | dzen2 +^fg(grey85) for i in $(seq 1 20); do A=${A}'='; print $A; sleep 1; done | dzen2 * Display header and a message with multiple lines: -^fg(grey70) (echo Header; cal; sleep 20) | dzen2 -l 8 +^fg(grey85) (echo Header; cal; sleep 20) | dzen2 -l 8 - Displays "Header" in the main alert window and - the output of cal in the 8 lines high slave - window. + Displays "Header" in the title window and the output of cal in the + 8 lines high slave window. * Display updating messages: -^fg(grey70) (echo Header; while true; do echo test$((i++)); sleep 1; done) | dzen2 -l 12 +^fg(grey85) (echo Header; while true; do echo test$((i++)); sleep 1; done) | dzen2 -l 12 The slave window will update contents if new input has arrived. * Display log files: -^fg(grey70) (su -c "echo LOGFILENAME; tail -f /var/log/messages") | dzen2 -l 20 -x 100 -y 300 -w 500 +^fg(grey85) (su -c "echo LOGFILENAME; tail -f /var/log/messages") | dzen2 -l 20 -x 100 -y 300 -w 500 * Monthly schedule with remind: -^fg(grey70) (echo Monthly Schedule; remind -c1 -m) | dzen2 -l 52 -w 410 -p -fn lime -bg '#e0e8ea' -fg black -x 635 +^fg(grey85) (echo Monthly Schedule; remind -c1 -m) | dzen2 -l 52 -w 410 -p -fn lime -bg '#e0e8ea' -fg black -x 635 * Simple menu: -^fg(grey70) echo "Applications" | dzen2 -l 4 -p -m < menufile +^fg(grey85) echo "Applications" | dzen2 -l 4 -p -m < menufile * Horizontal menu without any files: -^fg(grey70) {echo Menu; echo -e "xterm\nxclock\nxeyes\nxfontsel"} | dzen2 -l 4 -m h -p +^fg(grey85) {echo Menu; echo -e "xterm\nxclock\nxeyes\nxfontsel"} | dzen2 -l 4 -m h -p * Extract PIDs from the process table: -^fg(grey70) {echo Procs; ps -a} | dzen2 -m -l 12 -p \ -^fg(grey70) -e 'button1=menuprint;button3=exit;button4=scrollup:3;button5=scrolldown:3;entertitle=uncollapse;leaveslave=collapse' \ -^fg(grey70) | awk '{print $1}' +^fg(grey85) {echo Procs; ps -a} | dzen2 -m -l 12 -p \ +^fg(grey85) -e 'button1=menuprint;button3=exit;button4=scrollup:3;button5=scrolldown:3;entertitle=uncollapse;leaveslave=collapse' \ +^fg(grey85) | awk '{print $1}' * Dzen as xmonad (see http://xmonad.org) statusbar: -^fg(grey70) status.sh | dzen2 -ta r -fn '-*-profont-*-*-*-*-11-*-*-*-*-*-iso8859' -bg '#aecf96' -fg black \ -^fg(grey70) -p -e 'sigusr1=raise;sigusr2=lower;onquit=exec:rm /tmp/dzen2-pid;button3=exit' & echo $! > /tmp/dzen2-pid +^fg(grey85) status.sh | dzen2 -ta r -fn '-*-profont-*-*-*-*-11-*-*-*-*-*-iso8859' -bg '#aecf96' -fg black \ +^fg(grey85) -p -e 'sigusr1=raise;sigusr2=lower;onquit=exec:rm /tmp/dzen2-pid;button3=exit' & echo $! > /tmp/dzen2-pid diff --git a/TODO b/TODO index c5dd243..765cad7 100644 --- a/TODO +++ b/TODO @@ -11,5 +11,4 @@ # user interface - o dynamic coloring partial text - o support icons + o in-text command to draw to the title window diff --git a/bitmaps/music.xbm b/bitmaps/music.xbm new file mode 100644 index 0000000..86e32b5 --- /dev/null +++ b/bitmaps/music.xbm @@ -0,0 +1,7 @@ +#define music_width 16 +#define music_height 16 +static unsigned char music_bits[] = { + 0x00, 0x00, 0xe0, 0x00, 0xe0, 0x03, 0x20, 0x1f, 0x20, 0x1c, 0x20, 0x10, + 0x20, 0x10, 0x20, 0x10, 0x20, 0x10, 0x2c, 0x10, 0x3e, 0x10, 0x1e, 0x16, + 0x0c, 0x1f, 0x00, 0x0f, 0x00, 0x06, 0x00, 0x00 }; + diff --git a/bitmaps/pause.xbm b/bitmaps/pause.xbm new file mode 100644 index 0000000..9d4e9a7 --- /dev/null +++ b/bitmaps/pause.xbm @@ -0,0 +1,7 @@ +#define pause_width 16 +#define pause_height 16 +static unsigned char pause_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x1e, 0x78, 0x1e, 0x78, 0x1e, + 0x78, 0x1e, 0x78, 0x1e, 0x78, 0x1e, 0x78, 0x1e, 0x78, 0x1e, 0x78, 0x1e, + 0x78, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + diff --git a/bitmaps/play.xbm b/bitmaps/play.xbm new file mode 100644 index 0000000..46455df --- /dev/null +++ b/bitmaps/play.xbm @@ -0,0 +1,7 @@ +#define play_width 16 +#define play_height 16 +static unsigned char play_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x78, 0x00, 0xf8, 0x01, + 0xf8, 0x07, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x07, 0xf8, 0x01, 0x78, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + diff --git a/config.mk b/config.mk index bac3aa2..859b406 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # dzen version -VERSION = 0.7.0 +VERSION = 0.7.5 # Customize below to fit your system diff --git a/draw.c b/draw.c index b26d378..7513a40 100644 --- a/draw.c +++ b/draw.c @@ -7,10 +7,11 @@ #include "dzen.h" #include +#include #include -/* command types for the in text parser */ -enum ctype {bg, fg, icon, rect}; +/* command types for the in-text parser */ +enum ctype {bg, fg, icon, rect, circle, pos, titlewin}; int get_tokval(const char* line, char **retdata); int get_token(const char* line, int * t, char **tval); @@ -44,10 +45,7 @@ drawtext(const char *text, int reverse, int line, int align) { XSetForeground(dzen.dpy, dzen.rgc, dzen.norm[ColBG]); } - if(dzen.font.set) - parse_line(text, line, align, reverse, 0); - else - parse_line(text, line, align, reverse, 0); + parse_line(text, line, align, reverse, 0); } long @@ -127,30 +125,48 @@ get_token(const char *line, int * t, char **tval) { return 0; line++; - /* ^bg(#rrggbb) */ + /* ^bg(#rrggbb) background color, type: bg */ if( (*line == 'b') && (*(line+1) == 'g') && (*(line+2) == '(')) { off = 3; next_pos = get_tokval(line+off, &tokval); *t = bg; } - /* ^fg(#rrggbb) */ + /* ^fg(#rrggbb) foreground color, type: fg */ if((*line == 'f') && (*(line+1) == 'g') && (*(line+2) == '(')) { off=3; next_pos = get_tokval(line+off, &tokval); *t = fg; } - /* ^i(iconname) */ + /* ^tw() draw to title window, type: titlewin */ + if((*line == 't') && (*(line+1) == 'w') && (*(line+2) == '(')) { + off=3; + next_pos = get_tokval(line+off, &tokval); + *t = titlewin; + } + /* ^i(iconname) bitmap icon, type: icon */ if((*line == 'i') && (*(line+1) == '(')) { off = 2; next_pos = get_tokval(line+off, &tokval); *t = icon; } - /* ^r(widthxheight) */ + /* ^r(widthxheight) filled rectangle, type: rect */ if((*line == 'r') && (*(line+1) == '(')) { off = 2; next_pos = get_tokval(line+off, &tokval); *t = rect; } + /* ^p(widthxheight) relative position, type: pos */ + if((*line == 'p') && (*(line+1) == '(')) { + off = 2; + next_pos = get_tokval(line+off, &tokval); + *t = pos; + } + /* circle */ + if((*line == 'c') && (*(line+1) == '(')) { + off = 2; + next_pos = get_tokval(line+off, &tokval); + *t = circle; + } *tval = tokval; return next_pos+off; @@ -189,14 +205,15 @@ get_rect_vals(char *s, int *w, int *h) { char * parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { - unsigned int bm_w, bm_h, bm_xh, bm_yh; - int rectw, recth; + unsigned int bm_w, bm_h; + int bm_xh, bm_yh; + int rectw, recth, n_pos, recty; int i, next_pos=0, j=0, px=0, py=0, xorig, h=0, tw, ow; char lbuf[MAX_LINE_LEN], *rbuf = NULL; int t=-1; char *tval=NULL; XGCValues gcv; - Drawable pm, bm; + Drawable pm=0, bm; XRectangle r = { dzen.x, dzen.y, dzen.w, dzen.h}; /* parse line and return the text without control commands*/ @@ -206,7 +223,7 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { if( (lnr + dzen.slave_win.first_line_vis) >= dzen.slave_win.tcnt) line = NULL; else - line = dzen.slave_win.tbuf[dzen.slave_win.first_line_vis+lnr].text; + line = dzen.slave_win.tbuf[dzen.slave_win.first_line_vis+lnr]; } /* parse line and render text */ @@ -268,29 +285,41 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { strcat(rbuf, lbuf); } else { - if(t != -1 && tval){ + if(t != -1 && tval) { if(t == icon) { - if(t == icon) { - if(XReadBitmapFile(dzen.dpy, pm, tval, &bm_w, - &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess - && (h/2 + px + bm_w < dzen.w)) { - XCopyPlane(dzen.dpy, bm, pm, dzen.tgc, - 0, 0, bm_w, bm_h, px, - dzen.line_height >= bm_h ? (dzen.line_height - bm_h)/2 : 0, 1); - XFreePixmap(dzen.dpy, bm); - px += bm_w; - } + if(XReadBitmapFile(dzen.dpy, pm, tval, &bm_w, + &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess + && (h/2 + px + (signed)bm_w < dzen.w)) { + XCopyPlane(dzen.dpy, bm, pm, dzen.tgc, + 0, 0, bm_w, bm_h, px, + dzen.line_height >= (signed)bm_h ? (dzen.line_height - bm_h)/2 : 0, 1); + XFreePixmap(dzen.dpy, bm); + px += bm_w; } } - else if(t == rect) { - get_rect_vals(tval, &rectw, &recth); - rectw = rectw+px > dzen.w ? dzen.w-px : rectw; - recth = recth > dzen.line_height ? dzen.line_height : recth; - XFillRectangle(dzen.dpy, pm, dzen.tgc, px, (dzen.line_height - recth)/2, rectw, recth); - px += rectw; - } + else if(t == rect) { + get_rect_vals(tval, &rectw, &recth); + rectw = rectw+px > dzen.w ? dzen.w-px : rectw; + recth = recth > dzen.line_height ? dzen.line_height : recth; + recty = (dzen.line_height - recth)/2; + XFillRectangle(dzen.dpy, pm, dzen.tgc, px, (int)recty, rectw, recth); + + px += rectw; + } + else if(t == circle) { + rectw = recth = atoi(tval); + XFillArc(dzen.dpy, pm, dzen.tgc, px, (dzen.line_height - recth)/2, rectw, recth, 2880, 23040); + px += rectw; + } + else if(t == pos) { + if((n_pos = atoi(tval)) < 0) + n_pos *= -1; + px += n_pos; + } else set_opts(t, tval, reverse); + + free(tval); } /* check if text is longer than window's width */ @@ -338,10 +367,10 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { if(t == icon) { if(XReadBitmapFile(dzen.dpy, pm, tval, &bm_w, &bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess - && (h/2 + px + bm_w < dzen.w)) { + && (h/2 + px + (signed)bm_w < dzen.w)) { XCopyPlane(dzen.dpy, bm, pm, dzen.tgc, 0, 0, bm_w, bm_h, px, - dzen.line_height > bm_h ? (dzen.line_height - bm_h)/2 : 0, 1); + dzen.line_height > (signed)bm_h ? (dzen.line_height - bm_h)/2 : 0, 1); XFreePixmap(dzen.dpy, bm); px += bm_w; } @@ -350,11 +379,24 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) { get_rect_vals(tval, &rectw, &recth); rectw = rectw+px > dzen.w ? dzen.w-px : rectw; recth = recth > dzen.line_height ? dzen.line_height : recth; - XFillRectangle(dzen.dpy, pm, dzen.tgc, px, (dzen.line_height - recth)/2, rectw, recth); + recty = (dzen.line_height - recth)/2; + XFillRectangle(dzen.dpy, pm, dzen.tgc, px, (int)recty, rectw, recth); px += rectw; } + else if(t == circle) { + rectw = recth = atoi(tval); + XFillArc(dzen.dpy, pm, dzen.tgc, px, (dzen.line_height - recth)/2, rectw, recth, 2880, 23040); + px += rectw; + } + else if(t == pos) { + if((n_pos = atoi(tval)) < 0) + n_pos *= -1; + px += n_pos; + } else set_opts(t, tval, reverse); + + free(tval); } /* check if text is longer than window's width */ @@ -417,10 +459,8 @@ drawheader(const char * text) { dzen.w = dzen.title_win.width; dzen.h = dzen.line_height; - if(text) { - XSetForeground(dzen.dpy, dzen.gc, dzen.norm[ColBG]); - XFillRectangles(dzen.dpy, dzen.title_win.drawable, dzen.gc, &r, 1); - XSetForeground(dzen.dpy, dzen.gc, dzen.norm[ColFG]); + if(text){ + XFillRectangles(dzen.dpy, dzen.title_win.drawable, dzen.rgc, &r, 1); parse_line(text, -1, dzen.title_win.alignment, 0, 0); } @@ -430,10 +470,30 @@ drawheader(const char * text) { void drawbody(char * text) { + char *ec; + + /* draw to title window + this routine should be better integrated into + the actual parsing process + */ + if((ec = strstr(text, "^tw()")) && (*(ec-1) != '^')) { + dzen.x = 0; + dzen.y = 0; + dzen.w = dzen.title_win.width; + dzen.h = dzen.line_height; + XRectangle r = { dzen.x, dzen.y, dzen.w, dzen.h}; + + XFillRectangles(dzen.dpy, dzen.title_win.drawable, dzen.rgc, &r, 1); + parse_line(ec+5, -1, dzen.title_win.alignment, 0, 0); + XCopyArea(dzen.dpy, dzen.title_win.drawable, dzen.title_win.win, + dzen.gc, 0, 0, dzen.title_win.width, dzen.line_height, 0, 0); + return; + } + if(dzen.slave_win.tcnt == dzen.slave_win.tsize) free_buffer(); if(dzen.slave_win.tcnt < dzen.slave_win.tsize) { - dzen.slave_win.tbuf[dzen.slave_win.tcnt].text = estrdup(text); + dzen.slave_win.tbuf[dzen.slave_win.tcnt] = estrdup(text); dzen.slave_win.tcnt++; } } diff --git a/dzen.h b/dzen.h index 911dcab..9dec364 100644 --- a/dzen.h +++ b/dzen.h @@ -18,7 +18,7 @@ #define ALIGNLEFT 1 #define ALIGNRIGHT 2 -#define MIN_BUF_SIZE 512 +#define MIN_BUF_SIZE 524 #define MAX_LINE_LEN 512 /* gui data structures */ @@ -38,12 +38,6 @@ struct Fnt { int height; }; -struct _Sline { - unsigned long fg; - unsigned long bg; - char * text; -}; - /* title window */ struct TW { int x, y, width, height; @@ -63,8 +57,7 @@ struct SW { Drawable *drawable; /* input buffer */ - /* char **tbuf; */ - Sline *tbuf; + char **tbuf; int tsize; int tcnt; /* line fg colors */ diff --git a/gadgets/Makefile b/gadgets/Makefile index 36081bc..6ea8d3e 100644 --- a/gadgets/Makefile +++ b/gadgets/Makefile @@ -3,10 +3,10 @@ include config.mk -SRC = dbar.c textwidth.c +SRC = dbar.c gdbar.c gcpubar.c textwidth.c OBJ = ${SRC:.c=.o} -all: options dbar textwidth +all: options dbar gdbar gcpubar textwidth options: @echo dzen2 gadgets build options: @@ -26,6 +26,16 @@ dbar: ${OBJ} @${LD} -o $@ dbar.o ${LDFLAGS} @strip $@ +gdbar: ${OBJ} + @echo LD $@ + @${LD} -o $@ gdbar.o ${LDFLAGS} -L${X11LIB} -lX11 + @strip $@ + +gcpubar: ${OBJ} + @echo LD $@ + @${LD} -o $@ gcpubar.o ${LDFLAGS} -L${X11LIB} + @strip $@ + textwidth: ${OBJ} @echo LD $@ @${LD} -o $@ textwidth.o ${LDFLAGS} -L${X11LIB} -lX11 @@ -34,6 +44,8 @@ textwidth: ${OBJ} clean: @echo cleaning @rm -f ${OBJ} dbar + @rm -f ${OBJ} gdbar + @rm -f ${OBJ} gcpubar @rm -f ${OBJ} textwidth install: all @@ -41,12 +53,18 @@ install: all @mkdir -p ${DESTDIR}${PREFIX}/bin @cp -f dbar ${DESTDIR}${PREFIX}/bin @chmod 755 ${DESTDIR}${PREFIX}/bin/dbar + @cp -f gdbar ${DESTDIR}${PREFIX}/bin + @chmod 755 ${DESTDIR}${PREFIX}/bin/gdbar + @cp -f gcpubar ${DESTDIR}${PREFIX}/bin + @chmod 755 ${DESTDIR}${PREFIX}/bin/gcpubar @cp -f textwidth ${DESTDIR}${PREFIX}/bin @chmod 755 ${DESTDIR}${PREFIX}/bin/textwidth uninstall: @echo removing executable file from ${DESTDIR}${PREFIX}/bin @rm -f ${DESTDIR}${PREFIX}/bin/dbar + @rm -f ${DESTDIR}${PREFIX}/bin/gdbar + @rm -f ${DESTDIR}${PREFIX}/bin/gcpubar @rm -f ${DESTDIR}${PREFIX}/bin/textwidth .PHONY: all options clean install uninstall diff --git a/gadgets/README.gcpubar b/gadgets/README.gcpubar new file mode 100644 index 0000000..e8f86aa --- /dev/null +++ b/gadgets/README.gcpubar @@ -0,0 +1,29 @@ +==================================== + gcpubar, (c) 20007 by Robert Manea +==================================== + +gcpubar is a CPU utilization meter for Linux. It relies on the existence +of the "/proc/stat" file and generateѕ fully graphical meters viewable with +dzen >= 0.7.0. + +Command line options: +--------------------- + + + -i : Update interval in seconds (default: 1) + You can use positive values + less than 1 for intervals + shorter than a second + + -c : Terminate after diplaying (default: infite) + argument to '-c' values + + -w : Width of the meter in pixels (default: 100) + + -h : Height of the meter in pixels (default: 10) + + -fg : Meter foreground color (default: white) + + -bg : Meter background color (default: darkgrey) + + diff --git a/gadgets/README.gdbar b/gadgets/README.gdbar new file mode 100644 index 0000000..d3374b8 --- /dev/null +++ b/gadgets/README.gdbar @@ -0,0 +1,29 @@ +================================= + gdbar, (c) 2007 by Robert Manea +================================= + +gdbar is an application that generates fully graphical progress meters, +from some values you supply to it. + +It has the same input semantics as dbar (see README.dbar). In contrast +to dbar, gdbar draws fully graphical meters which are only useful in +combination with dzen >= 0.7.0. + +Options: +-------- + + -fg : foreground color of the meter (default: white) + -bg : background color of the meter (default: darkgrey) + -max : Value to be considered 100% (default: 100) + -min : Value to be considered 0% (default: 0 ) + -w : Size in pixels to be + considered 100% in the meter (default: 80 ) + -h : bar height + -l : label to be prepended to + the bar (default: '' ) + -nonl: no new line, don't put + '\n' at the end of the bar (default: do print '\n') + + +See README.dbar for further details! + diff --git a/gadgets/README.kittscanner b/gadgets/README.kittscanner new file mode 100644 index 0000000..37da5bc --- /dev/null +++ b/gadgets/README.kittscanner @@ -0,0 +1,14 @@ +======================================== + kitt-scanner, (c) 2007 by Robert Manea +======================================== + +This is just a fun gadget and wants to show what can be done with dzen +other than just displaying text ;). + +It implements sort of a KITT (Knight Rider, TV series) scanner in shell +script. + +There are some setting that you can tweak to your likings, see +"kitt-scanner.sh" for further details. + + diff --git a/gadgets/gcpubar.c b/gadgets/gcpubar.c new file mode 100644 index 0000000..f65569c --- /dev/null +++ b/gadgets/gcpubar.c @@ -0,0 +1,182 @@ +/* + gcpubar - graphical cpu usage bar, to be used with dzen + + Copyright (C) 2007 by Robert Manea, + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include +#include +#include +#include + +/* critical % value */ +#define CPUCRIT 75 +/* bar color for critical values */ +#define CRITCOL "red" + +static void pbar (double, int, int); + +struct cpu_info { + unsigned long long user; + unsigned long long sys; + unsigned long long idle; + unsigned long long iowait; +} ncpu, ocpu; + +char *bg, *fg; + +static void +pbar(double perc, int maxc, int height) { + int i, rp; + double l; + + l = perc * ((double)maxc / 100); + if((int)(l + 0.5) >= (int)l) + l = l + 0.5; + + if((int)(perc + 0.5) >= (int)perc) + rp = (int)(perc + 0.5); + else + rp = (int)perc; + + printf("CPU: %3d%% ^fg(%s)^r(%dx%d)^fg(%s)^r(%dx%d)\n", rp, + (rp>=CPUCRIT) ? CRITCOL : fg, (int)l, height, + bg, maxc-(int)l, height); + + fflush(stdout); +} + +int +main(int argc, char *argv[]) +{ + int i, t; + double total; + struct cpu_info mcpu; + FILE *statfp; + char buf[256], *ep; + + /* defaults */ + double ival=1.0; + int counts = 0; + int barwidth=100; + int barheight=10; + char *myfont = NULL; + + for(i=1; i < argc; i++) { + if(!strncmp(argv[i], "-i", 3)) { + if(i+1 < argc) { + ival = strtod(argv[i+1], &ep); + if(*ep) { + fprintf(stderr, "%s: '-i' Invalid interval value\n", argv[0]); + return EXIT_FAILURE; + } + else + i++; + } + } + else if(!strncmp(argv[i], "-c", 3)) { + if(++i < argc) + counts = atoi(argv[i]); + } + else if(!strncmp(argv[i], "-w", 3)) { + if(++i < argc) + barwidth = atoi(argv[i]); + } + else if(!strncmp(argv[i], "-h", 3)) { + if(++i < argc) + barheight = atoi(argv[i]); + } + else if(!strncmp(argv[i], "-fg", 4)) { + if(++i < argc) + fg = argv[i]; + else { + fg = malloc(6); + strcpy(fg, "white"); + } + } + else if(!strncmp(argv[i], "-bg", 4)) { + if(++i < argc) + bg = argv[i]; + else { + bg = malloc(9); + strcpy(bg, "darkgrey"); + } + } + else { + printf("usage: %s [-i ] [-c ] [-fg ] [-bg ] [-w ] [-h ]\n", argv[0]); + return EXIT_FAILURE; + } + } + + if(!fg) { + fg = malloc(6); + strcpy(fg, "white"); + } + if(!bg) { + bg = malloc(9); + strcpy(bg, "darkgrey"); + } + + if(!(statfp = fopen("/proc/stat", "r"))) { + printf("%s: error opening '/proc/stat'\n", argv[0]); + return EXIT_FAILURE; + } + + t = counts > 0 ? counts : 1; + while(t) { + rewind(statfp); + while(fgets(buf, sizeof buf, statfp)) { + if(!strncmp(buf, "cpu ", 4)) { + unsigned long long unice; + double myload; + /* linux >= 2.6 */ + if((sscanf(buf, "cpu %llu %llu %llu %llu %llu", + &ncpu.user, &unice, &ncpu.sys, &ncpu.idle, &ncpu.iowait)) < 5) { + printf("%s: wrong field count in /proc/stat\n", argv[0]); + return EXIT_FAILURE; + } + ncpu.user += unice; + + mcpu.user = ncpu.user - ocpu.user; + mcpu.sys = ncpu.sys - ocpu.sys; + mcpu.idle = ncpu.idle - ocpu.idle; + mcpu.iowait = ncpu.iowait - ocpu.iowait; + + total = (mcpu.user + mcpu.sys + mcpu.idle + mcpu.iowait) / 100.0; + myload = (mcpu.user + mcpu.sys + mcpu.iowait) / total; + + pbar(myload, barwidth, barheight); + ocpu = ncpu; + } + } + if((counts > 0) && (t-1 > 0)) { + --t; + usleep((unsigned long)(ival * 1000000.0)); + } + else if((counts == 0) && (t == 1)) + usleep((unsigned long)(ival * 1000000.0)); + else + break; + } + + return EXIT_SUCCESS; +} + diff --git a/gadgets/gdbar.c b/gadgets/gdbar.c new file mode 100644 index 0000000..4138770 --- /dev/null +++ b/gadgets/gdbar.c @@ -0,0 +1,154 @@ +/* + gdbar - graphical percentage meter, to be used with dzen + + Copyright (c) 2007 by Robert Manea + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include +#include +#include +#include +#include + +#define MAXLEN 512 + +static void pbar (const char *, double, int, int, int); + +char *bg, *fg; + + +static void +pbar(const char* label, double perc, int maxc, int height, int pnl) { + int i, rp; + double l; + + + l = perc * ((double)maxc / 100); + if((int)(l + 0.5) >= (int)l) + l = l + 0.5; + + if((int)(perc + 0.5) >= (int)perc) + rp = (int)(perc + 0.5); + else + rp = (int)perc; + + printf("%s %3d%% ^fg(%s)^r(%dx%d)^fg(%s)^r(%dx%d)%s", + label ? label : "", rp, + fg, (int)l, height, + bg, maxc-(int)l, height, + pnl ? "\n" : ""); +} + + int +main(int argc, char *argv[]) +{ + int i, nv; + double val; + char aval[MAXLEN], *endptr; + + /* defaults */ + int barwidth = 80; + int barheight = 10; + double minval = 0; + double maxval = 100.0; + int print_nl = 1; + const char *label = NULL; + + + for(i=1; i < argc; i++) { + if(!strncmp(argv[i], "-w", 3)) { + if(++i < argc) + barwidth = atoi(argv[i]); + } + else if(!strncmp(argv[i], "-h", 3)) { + if(++i < argc) + barheight = atoi(argv[i]); + } + else if(!strncmp(argv[i], "-fg", 4)) { + if(++i < argc) + fg = argv[i]; + else { + fg = malloc(6); + strcpy(fg, "white"); + } + } + else if(!strncmp(argv[i], "-bg", 4)) { + if(++i < argc) + bg = argv[i]; + else { + bg = malloc(9); + strcpy(bg, "darkgrey"); + } + } + else if(!strncmp(argv[i], "-max", 5)) { + if(++i < argc) { + maxval = strtod(argv[i], &endptr); + if(*endptr) { + fprintf(stderr, "dbar: '%s' incorrect number format", argv[i]); + return EXIT_FAILURE; + } + } + } + else if(!strncmp(argv[i], "-min", 5)) { + if(++i < argc) { + minval = strtod(argv[i], &endptr); + if(*endptr) { + fprintf(stderr, "dbar: '%s' incorrect number format", argv[i]); + return EXIT_FAILURE; + } + } + } + else if(!strncmp(argv[i], "-l", 3)) { + if(++i < argc) + label = argv[i]; + } + else if(!strncmp(argv[i], "-nonl", 6)) { + print_nl = 0; + } + else { + fprintf(stderr, "usage: dbar [-w ] [-h ] [-fg ] [-bg ] [-min ] [-max ] [-l ] [-nonl]\n"); + return EXIT_FAILURE; + } + } + + if(!fg) { + fg = malloc(6); + strcpy(fg, "white"); + } + if(!bg) { + bg = malloc(9); + strcpy(bg, "darkgrey"); + } + + while(fgets(aval, MAXLEN, stdin)) { + nv = sscanf(aval, "%lf %lf %lf", &val, &minval, &maxval); + if(nv == 2) { + maxval = minval; + minval = 0; + } + + pbar(label, (100*(val-minval))/(maxval-minval), barwidth, barheight, print_nl); + } + + return EXIT_SUCCESS; +} + diff --git a/gadgets/kittscanner.sh b/gadgets/kittscanner.sh new file mode 100755 index 0000000..0a99e64 --- /dev/null +++ b/gadgets/kittscanner.sh @@ -0,0 +1,70 @@ +#!/bin/sh +# +# (c) 2007 by Robert Manea +# +# KITT Scanner for dzen - a man, a car, a dzen +# + + +#---[ KITT configuration ]---------------------------------------------- + +SCANNER_LEDS=17 +LED_SPACING=3 +LED_WIDTH=25 +LED_HEIGHT=10 + +INACTIVE_LED_COLOR=darkred +ACTIVE_LED_COLOR=red +BG=black + +SLEEP=0.1 + +DZEN=/usr/local/bin/dzen2 +DZENOPTS="-bg $BG -fg $INACTIVE_LED_COLOR" + +#----------------------------------------------------------------------- + +DFG="^fg(${INACTIVE_LED_COLOR})" +LFG="^fg(${ACTIVE_LED_COLOR})" + +RECT="^r(${LED_WIDTH}x${LED_HEIGHT})" + +i=; j=1; SIGN='+' + +nr_list_leds() { + l=1 + lnr=$1 + + while [ $l -le $lnr ]; do + NRLIST=${NRLIST}' '${l} + l=`expr $l + 1` + done + + echo $NRLIST +} + +while :; do + for i in `nr_list_leds $SCANNER_LEDS`; do + if [ "$i" -eq "$j" ]; then + KBAR=${KBAR}"^p(${LED_SPACING})"${LFG}${RECT}${DFG} + else + KBAR=${KBAR}"^p(${LED_SPACING})"${RECT} + fi + + done + + echo $KBAR; KBAR= + + if [ $SIGN = '+' ] && [ $j -ge $SCANNER_LEDS ]; then + j=$SCANNER_LEDS + SIGN='-' + fi + if [ $SIGN = '-' ] && [ $j -eq 1 ]; then + j=1 + SIGN='+' + fi + + j=`expr $j $SIGN 1` + + sleep $SLEEP; +done | $DZEN $DZENOPTS diff --git a/help b/help index 6d01d41..336e3c3 100755 --- a/help +++ b/help @@ -2,7 +2,7 @@ # # (c) 2007, by Robert Manea -OPTS='-bg #323232 -fg #5FBF77 -p -l 20 -e onstart=uncollapse,scrollhome;button5=scrolldown;key_Down=scrolldown;button4=scrollup;key_Up=scrollup;key_Page_Down=scrolldown:20;key_Page_Up=scrollup:20;key_Escape=exit;button3=exit;entertitle=grabkeys;enterslave=grabkeys;leaveslave=ungrabkeys' +OPTS='-bg #323232 -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' if test -x ./dzen2 ; then (echo "^fg(#323232)^bg(#5FBF77)Documentation (use: scrollwheel, arrow keys, \ diff --git a/main.c b/main.c index 0db79fc..4b51313 100644 --- a/main.c +++ b/main.c @@ -126,10 +126,8 @@ void free_buffer(void) { int i; for(i=0; i