diff options
-rw-r--r-- | doc/systray.n | 5 | ||||
-rw-r--r-- | library/systray.tcl | 12 | ||||
-rw-r--r-- | macosx/tkMacOSXSysTray.c | 53 |
3 files changed, 41 insertions, 29 deletions
diff --git a/doc/systray.n b/doc/systray.n index 192cf2d..00371cd 100644 --- a/doc/systray.n +++ b/doc/systray.n @@ -45,8 +45,9 @@ Here is an example of modifying the \fBtk systray\fP icon: The \fBtk systray\fP destroy command removes the icon from display and deallocates it. .PP -From a user-interface standpoint, only one icon per interpreter -should be displayed, although it can be modified with different images and +From a user-interface standpoint, only one icon per interpreter is +supported; attempts to create additional icons will return an error. The +existing tray icon can be modified with different images and strings to indicate app state. Loading additional interpreters into a running instance of Wish will allow additional icons to be displayed. .SH PLATFORM NOTES diff --git a/library/systray.tcl b/library/systray.tcl index 1ebbd2b..ed14a49 100644 --- a/library/systray.tcl +++ b/library/systray.tcl @@ -175,10 +175,18 @@ proc systray {args} { set cb [lindex $args 3] switch -- [tk windowingsystem] { "win32" { + if [info exists "ico#1"] { + error "Only one system tray \ + icon supported per interpeter" + } set _ico [_systray createfrom $img] _systray taskbar add $_ico -text $txt -callback [list _win_callback %m %i $cb] } "x11" { + if [winfo exists ._tray] { + error "Only one system tray \ + icon supported per interpeter" + } _systray ._tray -image $img -visible true _balloon ._tray $txt bind ._tray <Button-1> $cb @@ -278,6 +286,6 @@ proc sysnotify {title message} { #Add these commands to the tk command ensemble: tk systray, tk sysnotify #Thanks to Christian Gollwitzer for the guidance here set map [namespace ensemble configure tk -map] -dict set map systray ::systray -dict set map sysnotify ::sysnotify +dict set map systray ::tk::systray +dict set map sysnotify ::tk::sysnotify namespace ensemble configure tk -map $map diff --git a/macosx/tkMacOSXSysTray.c b/macosx/tkMacOSXSysTray.c index 923276e..63e9b6c 100644 --- a/macosx/tkMacOSXSysTray.c +++ b/macosx/tkMacOSXSysTray.c @@ -212,27 +212,30 @@ MacSystrayObjCmd( Tcl_Obj *const *objv) { Tk_Image tk_image; - TrayInfo *info = (TrayInfo *)clientData; - int result, idx; - static const char *options[] = - {"create", "modify", "destroy", NULL}; + TrayInfo *info = (TrayInfo *)clientData; + int result, idx; + static const char *options[] = + {"create", "modify", "destroy", NULL}; typedef enum {TRAY_CREATE, TRAY_MODIFY, TRAY_DESTROY} optionsEnum; static const char *modifyOptions[] = - {"image", "text", "callback", NULL}; + {"image", "text", "callback", NULL}; typedef enum {TRAY_IMAGE, TRAY_TEXT, TRAY_CALLBACK} modifyOptionsEnum; if (info->tk_item == NULL) { info->tk_item = [[TkStatusItem alloc] init: interp]; + } else { + Tcl_AppendResult(interp, "Only one system tray icon supported per interpeter", NULL); + return TCL_ERROR; } - if (objc < 2) { - Tcl_WrongNumArgs(interp, 1, objv, "create | modify | destroy"); - return TCL_ERROR; - } + if (objc < 2) { + Tcl_WrongNumArgs(interp, 1, objv, "create | modify | destroy"); + return TCL_ERROR; + } - result = Tcl_GetIndexFromObjStruct(interp, objv[1], options, - sizeof(char *), "command", 0, &idx); + result = Tcl_GetIndexFromObjStruct(interp, objv[1], options, + sizeof(char *), "command", 0, &idx); if (result != TCL_OK) { return TCL_ERROR; @@ -287,7 +290,7 @@ MacSystrayObjCmd( [info->tk_item setCallback : objv[4]]; break; - } + } case TRAY_MODIFY: { if (objc < 4) { Tcl_WrongNumArgs(interp, 1, objv, "modify object item"); @@ -299,11 +302,11 @@ MacSystrayObjCmd( */ result = Tcl_GetIndexFromObjStruct(interp, objv[2], modifyOptions, - sizeof(char *), "option", 0, &idx); + sizeof(char *), "option", 0, &idx); - if (result != TCL_OK) { - return TCL_ERROR; - } + if (result != TCL_OK) { + return TCL_ERROR; + } switch ((modifyOptionsEnum)idx) { case TRAY_IMAGE: { Tk_Window tkwin = Tk_MainWindow(interp); @@ -325,14 +328,14 @@ MacSystrayObjCmd( [info->tk_item setImagewithImage: icon]; } Tk_FreeImage(tk_image); - break; + break; } - /* - * Modify the text for the tooltip. - */ + /* + * Modify the text for the tooltip. + */ - case TRAY_TEXT: { + case TRAY_TEXT: { NSString *tooltip = [NSString stringWithUTF8String:Tcl_GetString(objv[3])]; if (tooltip == nil) { Tcl_AppendResult(interp, "unable to set tooltip for systray icon", NULL); @@ -343,14 +346,14 @@ MacSystrayObjCmd( break; } - /* - * Modify the proc for the callback. - */ + /* + * Modify the proc for the callback. + */ case TRAY_CALLBACK: { [info->tk_item setCallback : objv[3]]; } - break; + break; } break; } |