Hi,
Usually on the Mac when you close a window it simply hides itself, and get back on when you click on the dock.
To reproduce this behaviour on our PB apps, we'd need an event that tells us that the user clicked on our icon on the dock - or rightclicked and chose "Show all window".
Could that be possible?
Mac: Show all window event
Re: Mac: Show all window event
Code: Select all
EnableExplicit
ImportC ""
CollapseWindow(WindowRef.L, Collapse.L)
EndImport
#kAEReopenApplication = 'rapp'
#kCoreEventClass = 'aevt'
#kEventClassWindow = 'wind'
#kEventWindowClose = 72
#kWindowCollapseBoxAttribute = 1 << 3
Structure EventTypeSpec
EventClass.L
EventKind.L
EndStructure
ProcedureC WindowCloseHandler(*NextEventHandler, Event.L, UserData.L)
ChangeWindowAttributes_(WindowID(0), #kWindowCollapseBoxAttribute, 0)
CollapseWindow(WindowID(0), #True)
EndProcedure
ProcedureC DockClickHandler()
CollapseWindow(WindowID(0), #False)
ChangeWindowAttributes_(WindowID(0), 0, #kWindowCollapseBoxAttribute)
EndProcedure
Dim EventTypes.EventTypeSpec(0)
OpenWindow(0, 270, 100, 300, 120, "On WindowClose minimize to dock")
; ----- Intercept closing of window
EventTypes(0)\EventClass = #kEventClassWindow
EventTypes(0)\EventKind = #kEventWindowClose
InstallEventHandler_(GetWindowEventTarget_(WindowID(0)), @WindowCloseHandler(), 1, @EventTypes(), WindowID(0), 0)
; ----- Intercept click on icon in dock
AEInstallEventHandler_(#kCoreEventClass, #kAEReopenApplication, @DockClickHandler(), 0, #False)
Repeat
If WaitWindowEvent() = #PB_Event_Menu
If EventMenu() = -1
Break
EndIf
EndIf
ForEver
Re: Mac: Show all window event
That's one thing that has annoyed me about Mac. Why on earth would you use the close event as a minimize event?
www.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
Re: Mac: Show all window event
I agree with you (being a new Mac user coming from Windows and Linux).J. Baker wrote:That's one thing that has annoyed me about Mac. Why on earth would you use the close event as a minimize event?
Therefore try this much shorter version which terminates the application
on clicking the red close symbol and minimizes the window to the dock
on clicking the yellow symbol. Nevertheless you only need to click the
dock icon once to restore the window to its previous expanded position.
Without the Apple Event Handler you would have to do a right click onto
the dock icon to open the context menu and have to do a second click
onto the window title to restore the window...

Code: Select all
EnableExplicit
ImportC ""
CollapseWindow(WindowRef.L, Collapse.L)
EndImport
#kAEReopenApplication = 'rapp'
#kCoreEventClass = 'aevt'
Structure EventTypeSpec
EventClass.L
EventKind.L
EndStructure
ProcedureC DockClickHandler()
CollapseWindow(WindowID(0), #False)
EndProcedure
OpenWindow(0, 270, 100, 320, 120, "Click on dock icon to restore window", #PB_Window_MinimizeGadget)
; ----- Intercept click on icon in dock
AEInstallEventHandler_(#kCoreEventClass, #kAEReopenApplication, @DockClickHandler(), 0, #False)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: Mac: Show all window event
That's the idea of closing the window doesnt mean closing the app. Not sure I like it but well, it's the way it works on Mac and I want my app to behave like it should!J. Baker wrote:That's one thing that has annoyed me about Mac. Why on earth would you use the close event as a minimize event?
Shardik, your code sample doesn't behave like other Mac apps, it should hide the window, not minimise it in the dock

Re: Mac: Show all window event
Gaetan, now you have the proof that I am still a Mac noob...Polo wrote:That's the idea of closing the window doesnt mean closing the app. Not sure I like it but well, it's the way it works on Mac and I want my app to behave like it should!J. Baker wrote:That's one thing that has annoyed me about Mac. Why on earth would you use the close event as a minimize event?
Shardik, your code sample doesn't behave like other Mac apps, it should hide the window, not minimise it in the dock

You are right in that on closing a normal app via the red closing button the
app is hidden. I interpreted the small dot under the app's dock icon in the
way that it has been minimized. But on a right click on the dock icon we
receive two different context menus depending whether the app has been
closed or minimized...

But my example from my first posting has already all you need: you only have
to change the CollapseWindow() against PB's HideWindow() and your app hides
on closing the window and is becoming visible on a click onto the app's dock
icon:
Code: Select all
EnableExplicit
#kAEReopenApplication = 'rapp'
#kCoreEventClass = 'aevt'
#kEventClassWindow = 'wind'
#kEventWindowClose = 72
Structure EventTypeSpec
EventClass.L
EventKind.L
EndStructure
ProcedureC WindowCloseHandler(*NextEventHandler, Event.L, UserData.L)
HideWindow(0, #True)
EndProcedure
ProcedureC DockClickHandler()
HideWindow(0, #False)
EndProcedure
Dim EventTypes.EventTypeSpec(0)
OpenWindow(0, 270, 100, 300, 120, "On WindowClose hide window")
; ----- Intercept closing of window
EventTypes(0)\EventClass = #kEventClassWindow
EventTypes(0)\EventKind = #kEventWindowClose
InstallEventHandler_(GetWindowEventTarget_(WindowID(0)), @WindowCloseHandler(), 1, @EventTypes(), WindowID(0), 0)
; ----- Intercept click on icon in dock
AEInstallEventHandler_(#kCoreEventClass, #kAEReopenApplication, @DockClickHandler(), 0, #False)
Repeat
If WaitWindowEvent() = #PB_Event_Menu
If EventMenu() = -1
Break
EndIf
EndIf
ForEver
Re: Mac: Show all window event
You just proved you weren't with your last example, EXACTLY what I was looking for! I hope there'll be a native way to do this in PB, as even if this is specific to MacOS, I think it's really important in order to make a native fell appShardik wrote:Gaetan, now you have the proof that I am still a Mac noob...Polo wrote:That's the idea of closing the window doesnt mean closing the app. Not sure I like it but well, it's the way it works on Mac and I want my app to behave like it should!J. Baker wrote:That's one thing that has annoyed me about Mac. Why on earth would you use the close event as a minimize event?
Shardik, your code sample doesn't behave like other Mac apps, it should hide the window, not minimise it in the dock
