Page 1 of 1
Mac: Show all window event
Posted: Fri Oct 14, 2011 3:29 pm
by Polo
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?
Re: Mac: Show all window event
Posted: Fri Oct 14, 2011 9:32 pm
by Shardik
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
Posted: Fri Oct 14, 2011 9:35 pm
by J. Baker
That's one thing that has annoyed me about Mac. Why on earth would you use the close event as a minimize event?
Re: Mac: Show all window event
Posted: Fri Oct 14, 2011 10:42 pm
by Shardik
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?
I agree with you (being a new Mac user coming from Windows and Linux).
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
Posted: Fri Oct 14, 2011 11:33 pm
by Polo
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?
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!
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
Posted: Sat Oct 15, 2011 12:10 pm
by Shardik
Polo wrote: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?
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!
Shardik, your code sample doesn't behave like other Mac apps, it should hide the window, not minimise it in the dock

Gaetan, now you have the proof that I am still a Mac noob...
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
Posted: Sat Oct 15, 2011 1:04 pm
by Polo
Shardik wrote:Polo wrote: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?
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!
Shardik, your code sample doesn't behave like other Mac apps, it should hide the window, not minimise it in the dock

Gaetan, now you have the proof that I am still a Mac noob...

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 app
