#!/usr/dt/bin/dtksh # # xworldclock - Print world times in an X11 window. # This is also a demo of the Desktop Korn Shell's X11 features (dtksh). # So far tested on Solaris. ver 0.7 # # Written for a 24-bit colour display. On non-Solaris, check the path of your # dtksh (may not be "/usr/dt/bin/dtksh"); and you also may have different # named timezones than the ones Solaris uses - check the code below. # # # USAGE: ./xworldclock [-ch] [-x pixels] [-y pixels][-fg colour] [-bg colour] # # -c compact mode # -h help # -x width (pixels) # -y height (pixels) # -fg text colour # -bg background colour # eg, # ./xworldclock # defaults # ./xworldclock -x # compact mode # ./xworldclock -fg DarkBlue -bg SkyBlue # nice colours # ./xworldclock -fg Green -bg Black # oddly familiar # # Valid colours may include unusual options such as SkyBlue, MidnightBlue, # AntiqueWhite, LightSeaGreen, MediumAquamarine, etc.. # On Solaris the file to read is, /usr/openwin/lib/X11/rgb.txt # # # COPYRIGHT: Copyright (c) 2004 Brendan Gregg. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # (http://www.gnu.org/copyleft/gpl.html) # # 01-Apr-2004 Brendan Gregg Created this # # --- Default Variables --- # max_x=440 # window size x max_y=300 # window size y colour_bg=White # background colour colour_fg=Black # text colour delay=10000 # delay between refreshes (ms) datestr="+%H:%M %d-%b-%y %Z" # date format compact=0 # compact mode tz[0]="Europe/London" tz[1]="Europe/Paris" tz[2]="Europe/Berlin" tz[3]="Africa/Cairo" tz[4]="Europe/Moscow" tz[5]="Asia/Calcutta" tz[6]="Asia/Hong_Kong" tz[7]="Asia/Tokyo" tz[8]="Australia/West" tz[9]="Australia/North" tz[10]="Australia/NSW" tz[11]="Pacific/Auckland" tz[12]="US/Pacific" tz[13]="US/Mountain" tz[14]="US/Central" tz[15]="US/Eastern" tz[16]="Brazil/East" notes[0]="UK" notes[1]="France" notes[2]="Germany" notes[3]="Egypt" notes[4]="Russia" notes[5]="India" notes[6]="China" notes[7]="Japan" notes[8]="Perth" notes[9]="Darwin" notes[10]="Sydney" notes[11]="New Zealand" notes[12]="Los Angeles" notes[13]="Denver" notes[14]="Houston" notes[15]="New York" notes[16]="Rio de Janeiro" num=${#tz[*]} # # --- Parse Options --- # while (( $# != 0 )) do case "$1" in -h|--help) print -nu2 "USAGE: $0 [-ch] [-x pixels] [-y pixels]" print -u2 "[-fg colour] [-bg colour]" print -u2 " -c compact mode" print -u2 " -h help" print -u2 " -x width (pixels)" print -u2 " -y height (pixels)" print -u2 " -fg text colour" print -u2 " -bg background colour\n" exit 0 ;; -c) max_x=180 compact=1 datestr="+%H:%M" ;; -x) max_x=$2 if (( max_x < 150 )); then print -u2 "ERROR: Width $max_x is too small\n" exit 1 fi shift ;; -y) max_y=$2 if (( max_y < 250 )); then print -u2 "ERROR: Height $max_y is too small\n" exit 1 fi shift ;; -fg) colour_fg=$2 shift ;; -bg) colour_bg=$2 shift ;; esac shift done # # --- Scalable variables --- # (( y_inc = (max_y - 30) / num )) # # --- Create X11 window --- # XtInitialize TOP worldclock Worldclock $0 XtCreateManagedWidget FORM form XmForm $TOP \ resizePolicy:RESIZE_NONE \ height:$max_y width:$max_x x:0 y:0 \ background:$colour_bg # # --- Create date displays --- # i=0 while (( i < num )); do (( y = i * y_inc )) XtCreateManagedWidget LABEL$i label$i XmLabel $FORM x:5 y:$y \ background:$colour_bg foreground:$colour_fg \ labelString:"${tz[$i]}" XtCreateManagedWidget TIME$i time$i XmLabel $FORM x:135 y:$y \ background:$colour_bg foreground:$colour_fg \ labelString:"`TZ=${tz[$i]} date \"$datestr\"`" if (( compact == 0 )); then XtCreateManagedWidget NOTES$i notes$i XmLabel $FORM \ x:300 y:$y background:$colour_bg \ foreground:$colour_fg labelString:"${notes[$i]}" fi (( i++ )) done set -A TIMES $TIME0 $TIME1 $TIME2 $TIME3 $TIME4 $TIME5 $TIME6 $TIME7 \ $TIME8 $TIME9 $TIME10 $TIME11 $TIME12 $TIME13 $TIME14 $TIME15 $TIME16 # # --- Create buttons --- # (( y = max_y - 33 )) XtCreateManagedWidget EXIT exit XmPushButton $FORM \ background:$colour_bg \ foreground:$colour_fg \ labelString:"Exit"\ height:30 width:70 x:3 y:$y shadowThickness:3 XtAddCallback $EXIT activateCallback exit if (( compact == 0 )); then XtCreateManagedWidget LOCAL local XmPushButton $FORM \ background:$colour_bg \ foreground:$colour_fg \ labelString:"`date`"\ height:30 x:80 y:$y shadowThickness:3 XtAddCallback $LOCAL activateCallback localdate fi XtDisplay DISPLAY $FORM XSync $DISPLAY true XtRealizeWidget $TOP # # --- Update times function --- # function update { ### Draw times i=0 while (( i < num )); do XtSetValues ${TIMES[$i]} \ labelString:"`TZ=${tz[$i]} date \"$datestr\"`" (( i++ )) done XtSetValues $LOCAL labelString:"`date`" XtSetValues $LOCAL height:30 ### Trigger next update XtAddTimeOut ID $delay update } # # --- Local date upadte --- # function localdate { XtSetValues $LOCAL labelString:"`date`" XtSetValues $LOCAL height:30 } # # --- Main --- # XtAddTimeOut ID $delay update XtMainLoop