]> gitweb.factorcode.org Git - factor.git/commitdiff
windows: Add some code to put something in the tray.
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 30 Jan 2021 19:54:18 +0000 (13:54 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Sat, 30 Jan 2021 19:54:18 +0000 (13:54 -0600)
basis/ui/backend/windows/windows.factor
basis/windows/shell32/shell32.factor

index 0cc51099cd21e0a6fb15a7da224c83e96f054c7f..90da2b30d426632f0f1323861578585fee98b95a 100644 (file)
@@ -1,16 +1,17 @@
 ! Copyright (C) 2005, 2006 Doug Coleman.
 ! Portions copyright (C) 2007, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.data alien.strings arrays ascii assocs
-calendar classes classes.struct colors combinators continuations fry
-io io.crlf io.encodings.utf16n kernel libc literals locals make math
-math.bitwise namespaces sequences sets specialized-arrays strings
-threads ui ui.backend ui.clipboards ui.event-loop ui.gadgets
-ui.gadgets.private ui.gadgets.worlds ui.gestures ui.pixel-formats
-ui.private windows.dwmapi windows.errors windows.gdi32
-windows.kernel32 windows.messages windows.offscreen windows.opengl32
-windows.types windows.user32 assocs.extras byte-arrays
-io.encodings.string ;
+USING: accessors alien alien.c-types alien.data alien.strings
+arrays ascii assocs assocs.extras byte-arrays calendar classes
+classes.struct colors combinators continuations io io.crlf
+io.encodings.string io.encodings.utf16n io.encodings.utf8 kernel
+libc literals make math math.bitwise namespaces sequences sets
+specialized-arrays strings threads ui ui.backend ui.clipboards
+ui.event-loop ui.gadgets ui.gadgets.private ui.gadgets.worlds
+ui.gestures ui.pixel-formats ui.private windows.dwmapi
+windows.errors windows.gdi32 windows.kernel32 windows.messages
+windows.offscreen windows.opengl32 windows.shell32 windows.types
+windows.user32 ;
 FROM: unicode => upper-surrogate? under-surrogate? ;
 SPECIALIZED-ARRAY: POINT
 QUALIFIED-WITH: alien.c-types c
@@ -799,6 +800,27 @@ CONSTANT: fullscreen-flags flags{ WS_CAPTION WS_BORDER WS_THICKFRAME }
         [ drop SW_RESTORE ShowWindow win32-error=0/f ]
     } 2cleave ;
 
+: ensure-null-terminated ( str -- str' )
+    dup ?last 0 = [ "\0" append ] unless ; inline
+
+: add-tray-icon ( title -- )
+    NIM_ADD
+    NOTIFYICONDATA <struct>
+        NOTIFYICONDATA heap-size >>cbSize
+        NOTIFYICON_VERSION_4 over timeout-version>> uVersion<<
+        NIF_TIP NIF_ICON bitor >>uFlags
+        world get handle>> hWnd>> >>hWnd
+        f GetModuleHandle "APPICON" native-string>alien LoadIcon >>hIcon
+        rot ensure-null-terminated utf8 encode >>szTip
+        Shell_NotifyIcon win32-error=0/f ;
+
+: remove-tray-icon ( -- )
+    NIM_DELETE
+    NOTIFYICONDATA <struct>
+        NOTIFYICONDATA heap-size >>cbSize
+        world get handle>> hWnd>> >>hWnd
+    Shell_NotifyIcon win32-error=0/f ;
+
 M: windows-ui-backend (set-fullscreen)
     [ enter-fullscreen ] [ exit-fullscreen ] if ;
 
index 1dbd9254638596071f6b0339df8292e4e4522d89..89dd6a89caa251d1d0e7b5f68ba4bbe9ebdf145d 100644 (file)
@@ -369,6 +369,7 @@ CONSTANT: NIN_BALLOONHIDE $[ WM_USER 3 + ]
 CONSTANT: NIN_BALLOONTIMEOUT $[ WM_USER 4 + ]
 CONSTANT: NIN_BALLOONUSERCLICK $[ WM_USER 5 + ]
 
+UNION-STRUCT: timeout-version-union { uTimeout UINT } { uVersion UINT } ;
 STRUCT: NOTIFYICONDATA
     { cbSize DWORD }
     { hWnd HWND }
@@ -380,7 +381,7 @@ STRUCT: NOTIFYICONDATA
     { dwState DWORD }
     { dwStateMask DWORD }
     { szInfo TCHAR[256] }
-    { uTimeout UINT } ! { uVersion UINT } ! c-union here1
+    { timeout-version timeout-version-union } ! { uVersion UINT } ! c-union here1
     { szInfoTitle TCHAR[64] }
     { dwInfoFlags DWORD }
     { guidItem GUID }