[PB4.40b6] SysTray and Events

Mac OSX specific forum
jamirokwai
Addict
Addict
Posts: 801
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

[PB4.40b6] SysTray and Events

Post by jamirokwai »

Dear Fred,

I was playing around with the SysTray-Thing on Mac OS X. Looks really promising. However, I fell into a little trap...

The following code opens a window, sets up the SysTrayIcon and a Menu, and waits for the user to click. There are two options in the Menu. Works as expected.

If you bring Finder to front and click again on the SysTrayIcon, the Menu appears. But when selecting a line with left mouse button, the #PB_Event_Menu-part won't be executed. As you can see, I added BringToFront_ and SetActiveWindow, which didn't do the trick :(

Any ideas?

Code: Select all

OpenWindow(0,50,50,50,50,"systraytest")
 CreatePopupMenu(0)
  MenuItem(1,"Test")
  MenuItem(2,"Quit")
 CreateImage(0,40,16,32) 
 StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_AlphaChannel|#PB_2DDrawing_Transparent)
  Box(0, 0, 40, 16, RGBA(0,0,0,0))
  DrawText(1,1,"TEST",RGBA(0,0,0,255))
 StopDrawing()
 
 AddSysTrayIcon (0, WindowID(0), ImageID(0))
 
Repeat
 Select WaitWindowEvent()
  Case #PB_Event_SysTray
   Select EventType()
    Case #PB_EventType_LeftClick
; this won't help
;      BringToFront_(WindowID(0))
;      SetActiveWindow(0)
     DisplayPopupMenu(0, WindowID(0))
   EndSelect
   
   ; this won't be executed, when the program is set to background
  Case #PB_Event_Menu
   Select EventMenu()
    Case 1 : MessageRequester("!", "works")
    Case 2 : Exit = 1
  EndSelect
 EndSelect
Until Exit = 1
EDIT: I think, It is the same question (or answer) as in http://www.purebasic.fr/english/viewtop ... 24&t=39861
Regards,
JamiroKwai
Niffo
Enthusiast
Enthusiast
Posts: 504
Joined: Tue Jan 31, 2006 9:43 am
Location: France

Re: [PB4.40b6] SysTray and Events

Post by Niffo »

+1
Niffo
WilliamL
Addict
Addict
Posts: 1256
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: [PB4.40b6] SysTray and Events

Post by WilliamL »

It appears that Toolbars also work if you use ToolBarImageButton.
MacBook Pro-M1 (2021), Tahoe 26.2, PB 6.30b5
Post Reply