On this page:
24.1 Creating a Tray
make-tray
tray?
tray-ptr
tray-destroy!
set-tray-icon!
set-tray-tooltip!
24.2 Menus
make-tray-menu
get-tray-menu
tray-menu?
tray-menu-ptr
24.3 Menu Entries
insert-tray-entry!
remove-tray-entry!
tray-entry?
tray-entry-ptr
tray-entries
24.4 Entry Properties
tray-entry-label
set-tray-entry-label!
tray-entry-checked?
set-tray-entry-checked!
tray-entry-enabled?
set-tray-entry-enabled!
24.5 Entry Callbacks
set-tray-entry-callback!
click-tray-entry!
24.6 Submenus
make-tray-submenu
tray-submenu
tray-menu-parent-entry
tray-menu-parent-tray
tray-entry-parent
24.7 Updates
update-trays!
9.0.0.11

24 System Tray🔗ℹ

This section covers system tray icon support.

24.1 Creating a Tray🔗ℹ

procedure

(make-tray [icon tooltip #:custodian cust])  tray?

  icon : (or/c surface? #f) = #f
  tooltip : (or/c string? #f) = #f
  cust : custodian? = (current-custodian)
Creates a system tray icon.

icon is an optional surface to use as the tray icon. tooltip is optional tooltip text.

(define tray (make-tray))
(set-tray-tooltip! tray "My Application")

procedure

(tray? v)  boolean?

  v : any/c
Returns #t if v is a tray.

procedure

(tray-ptr tr)  cpointer?

  tr : tray?
Returns the underlying SDL tray pointer.

procedure

(tray-destroy! tr)  void?

  tr : tray?
Destroys a tray.

Note: Trays are automatically destroyed when their custodian shuts down.

procedure

(set-tray-icon! tr icon)  void?

  tr : tray?
  icon : (or/c surface? #f)
Sets the tray icon.

procedure

(set-tray-tooltip! tr tooltip)  void?

  tr : tray?
  tooltip : (or/c string? #f)
Sets the tray tooltip text.

24.2 Menus🔗ℹ

procedure

(make-tray-menu tr)  tray-menu?

  tr : tray?
Creates the root menu for a tray.

procedure

(get-tray-menu tr)  (or/c tray-menu? #f)

  tr : tray?
Gets the existing root menu for a tray.

procedure

(tray-menu? v)  boolean?

  v : any/c
Returns #t if v is a tray menu.

procedure

(tray-menu-ptr menu)  cpointer?

  menu : tray-menu?
Returns the underlying SDL tray menu pointer.

24.3 Menu Entries🔗ℹ

procedure

(insert-tray-entry! menu    
  label    
  [#:position pos    
  #:type type    
  #:checked? checked?    
  #:disabled? disabled?])  tray-entry?
  menu : tray-menu?
  label : string?
  pos : exact-integer? = -1
  type : (or/c 'button 'checkbox 'submenu) = 'button
  checked? : boolean? = #f
  disabled? : boolean? = #f
Inserts an entry into a menu.

pos is the position (-1 = end).

type determines the entry type:
  • 'button A clickable item

  • 'checkbox A toggleable item

  • 'submenu An item that opens a submenu

(define menu (make-tray-menu tray))
(define quit-entry (insert-tray-entry! menu "Quit"))
(set-tray-entry-callback! quit-entry
  (lambda (entry)
    (exit)))

procedure

(remove-tray-entry! entry)  void?

  entry : tray-entry?
Removes an entry from its menu.

procedure

(tray-entry? v)  boolean?

  v : any/c
Returns #t if v is a tray entry.

procedure

(tray-entry-ptr entry)  cpointer?

  entry : tray-entry?
Returns the underlying SDL tray entry pointer.

procedure

(tray-entries menu)  (listof tray-entry?)

  menu : tray-menu?
Returns all entries in a menu.

24.4 Entry Properties🔗ℹ

procedure

(tray-entry-label entry)  (or/c string? #f)

  entry : tray-entry?
Returns the entry’s label.

procedure

(set-tray-entry-label! entry label)  void?

  entry : tray-entry?
  label : string?
Sets the entry’s label.

procedure

(tray-entry-checked? entry)  boolean?

  entry : tray-entry?
Returns #t if the entry is checked (for checkbox entries).

procedure

(set-tray-entry-checked! entry checked?)  void?

  entry : tray-entry?
  checked? : boolean?
Sets whether the entry is checked.

procedure

(tray-entry-enabled? entry)  boolean?

  entry : tray-entry?
Returns #t if the entry is enabled.

procedure

(set-tray-entry-enabled! entry enabled?)  void?

  entry : tray-entry?
  enabled? : boolean?
Sets whether the entry is enabled.

24.5 Entry Callbacks🔗ℹ

procedure

(set-tray-entry-callback! entry    
  proc    
  [#:userdata userdata])  void?
  entry : tray-entry?
  proc : (or/c procedure? #f)
  userdata : any/c = #f
Sets the callback for when the entry is clicked.

The callback can accept 1 or 2 arguments:
  • 1 arg: (entry)

  • 2 args: (entry userdata)

Pass #f to remove the callback.

(set-tray-entry-callback! entry
  (lambda (e)
    (printf "Entry clicked: ~a~n" (tray-entry-label e))))

procedure

(click-tray-entry! entry)  void?

  entry : tray-entry?
Programmatically clicks an entry.

24.6 Submenus🔗ℹ

procedure

(make-tray-submenu entry)  tray-menu?

  entry : tray-entry?
Creates a submenu for a submenu-type entry.

procedure

(tray-submenu entry)  (or/c tray-menu? #f)

  entry : tray-entry?
Gets the existing submenu for an entry.

procedure

(tray-menu-parent-entry menu)  (or/c tray-entry? #f)

  menu : tray-menu?
Returns the parent entry of a submenu.

procedure

(tray-menu-parent-tray menu)  (or/c cpointer? #f)

  menu : tray-menu?
Returns the parent tray of a root menu.

procedure

(tray-entry-parent entry)  (or/c tray-menu? #f)

  entry : tray-entry?
Returns the parent menu of an entry.

24.7 Updates🔗ℹ

procedure

(update-trays!)  void?

Updates all trays.

Call this periodically to ensure tray changes are reflected.