[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-openjfx-dev
Subject:    Re: Provide Quit handler for system menu bar
From:       Florian Kirmaier <florian.kirmaier () gmail ! com>
Date:       2022-09-21 11:59:40
Message-ID: CA+4mSqZ6e2whAOSgVsuZ6UJtFDqtRSkOjYn8okSaSAgDYjOnLA () mail ! gmail ! com
[Download RAW message or body]

Yes, a custom "about menu" handling would be very similar and could be
implemented at the same time.

It's worth mentioning, that we cannot use the methods java.awt.Desktop
setAboutHandler and setQuitHandler methods,
because they only work, if the menu is from Swing. They don't work when the
menu bar is from JavaFX.

For that reason, it might be the case, that more of the methods, provided
in awt.Desktop are required in some cases.

So how could this look?

I think it would make sense, to make the API very similar to the existing
API in Swing.
This would make it easier for Developers to get used to the API, or to
switch form the Swing call to the new JavaFX call, if someone is migrating
from Swing to JavaFX.
```
javafx.application.Desktop {
boolean isSupported(Feature)
void setQuitHandler(Supplier<Boolean>)
}
```
Would this meet the expectation, of how this could look?
Alternatively, these methods could be added to the Platform class, but I
think it would make sense to create a new class for this.

On Tue, 20 Sept 2022 at 19:57, Philip Race <philip.race@oracle.com> wrote:

> All of these requests seem to map to what we added to AWT in JDK 9.
> We did this because there'd been Apple specific APIs that came in via the
> Apple port but were very iffy in terms of what was supported and it was
> not a good idea to formally export them from the new desktop module.
>
> The java.awt.Desktop class was enhanced by the java.awt.desktop package
> and all of these things are provided in a platform neutral way.
> You just query whether the support is available.
>
> These can even be used in a mixed AWT/FX application if you want a
> solution now,
> but FX could have its own version of these.
>
> Nothing that mentions a platform (please!).
>
> -phil
>
> On 9/20/22 6:38 AM, Scott Palmer wrote:
>
> I always understood Alt+F4 as simply being a keyboard shortcut on Windows
> for closing the window of the active application.  The same as clicking the
> close widget.  I don't think there is anything special about it.  As far as
> being an equivalent to the macOS Quit action, I don't think it is quite the
> same. Does an application even know the difference between a window closed
> with the widget vs. Alt+F4? CTRL+F4 closes the current document window or
> tab - similar to Command-W on macOS.
>
> I'm not aware of any special handlers being called on Windows for these
> shortcuts other than what is called when the equivalent close widget is
> pressed. If I'm wrong about that, then sure, a quit handler for JavaFX
> could be wired in to the same mechanism automatically.  Maybe Linux has an
> equivalent as well, I don't know.
>
> While we are at it, custom handling for the ‘About' menu item in the
> application menu is also needed, is it not?
>
> For now I'm currently using Jan Gassen's port of NSMenuFX to hook into
> this stuff. https://github.com/0x4a616e/NSMenuFX
>
>
> Scott
>
> On Sep 20, 2022, at 5:55 AM, John Hendrikx <john.hendrikx@gmail.com>
> <john.hendrikx@gmail.com> wrote:
>
> 
>
> What about Alt + F4 and Ctrl + F4 on Windows?  Alt + F4 closes the
> application (which works with JavaFX already) and Ctrl + F4 is supposed to
> close a single window, but that doesn't work for JavaFX.
>
> Also very much in favor of Keeping the API platform neutral, that's just
> how Java has worked since its inception.
>
> --John
> On 20/09/2022 06:25, Scott Palmer wrote:
>
> Windows applications often have an "Exit" menu item, but since it isn't
> standardized like it is on macOS, calling a quit handler for it would need
> to be a manual step - but the exact same method for the quit handler could
> be called, leaving it up to the programmer to continue or not with the
> application exit depending on the return value. This manual coding isn't a
> big deal since you would also need to have some app-specific handling to
> avoid making an Exit menu item on macOS, where it would look out of place.
>
>
> You could add a standard "requestExit()" method to Platform that you could
> manually bind to an Exit menu item on Windows or Linux, but it would be
> automatically called via an internal macOS Quit handler implementation.
> The implementation of Platform.requestExit() on *all* platforms would call
> a boolean method if one was registered and then conditionally call
> Platform.exit() depending on the return value, the default being to always
> exit if nothing was registered. On macOS it would pass on the value to veto
> the native Quit handler as needed.  I haven't checked, does
> Application.stop() get called on macOS if you exit via the Quit menu or
> Command-Q? If it doesn't, that's another benefit.  This idea should
> probably be opt-in via some API or system property, I suppose it would have
> to be if it changes behaviour of having Application.stop() called in some
> circumstances. Or you can just make the setting of the handler function the
> "opt-in".
>
> Btw, this reminds me of the long-standing request for system tray
> support, along with with various other features that have equivalents
> across multiple OS', like showing progress on the dock icon, or a numbered
> badge (for notifications, or unread msgs, etc).  I think there are already
> issues in Jira for these, maybe just as a general request to support some
> features that AWT/Swing has that JFX is still missing. Most of these
> features are available on both Mac and Windows, possibly Linux.  It would
> be irritating to code to different APIs for each if it can be avoided, so I
> agree with going for a platform-neutral way.
>
> Cheers,
>
> Scott
>
> On Sep 19, 2022, at 8:11 PM, Kevin Rushforth <kevin.rushforth@oracle.com>
> <kevin.rushforth@oracle.com> wrote:
>
>  I don't see us adding 100s of OS-specific API calls, but even if we did,
> going down the path of exposing them as Mac APIs or Windows APIs, doesn't
> really seem like the direction we want to go. Whatever we do needs to
> balance the desire to integrate with, e.g., the macOS or Windows platform
> with a desire to leave the door open for it to later be implemented on the
> other platform(s). And the most cross-platform way to do that from an API
> point of view is by defining API that delivers the desired functionality in
> as platform-neutral a way as possible. It also needs to fit cleanly into
> the existing API.
>
> So in the specific case of a quit handler, we could define a platform API
> that an app could call to register a handler that gets called if the
> platform quit menu is selected and is able to cancel the Quit
> action(basically, that's what is being proposed). We could decide to
> provide some way for an app to query whether it is supported, but maybe we
> just don't need to worry about it in this specific case. We could just
> document that it will get called when the platform quit action is called,
> if there is such an action on that platform. Other than maybe mentioning in
> the docs that the macOS system menu "quit" action is an example of an
> action that would invoke this, it doesn't need to be platform-specific. One
> question to answer is whether we should just put this in the Platform class
> (where we have other similar "global" application state), the Application
> class (which has the life-cycle APIs), or somewhere else (which might make
> sense if we wanted to define an analog to the AWT Desktop class, although
> the existing Platform class already has some APIs like this).
>
> -- Kevin
>
>
> On 9/19/2022 1:46 PM, Andy Goryachev wrote:
>
> Thank you, Kevin.  Your insightful feedback always pulls the discussion in
> the right direction.
>
>
>
> The initial problem we are facing is access to Mac menu in general and
> additional API specifically.  I can see a possibility of extending the list
> of APIs that app devs would want on Mac growing, so there should be a
> better way to add them.  Using hacks like com.apple.eawt, or system
> properties is probably not the best solution.  Ideally, there should be
> away that does not require creative linking of stub classes on non-Mac
> platforms, i.e. we should be able to use a single code base for all the
> platforms.
>
>
>
> ConditionalFeature might work well internally for openjfx, but I don't
> think it is a good solution for actually exposing the platform APIs to the
> user.
>
>
>
> So, in order to provide platform-specific API in such a way that still
> allows for a single code base for multiple platform, and one that
> potentially scales to tens or hundreds of API calls, I see two solutions:
>
>
>
> 1. one start starts with a single entry point, like PlatformAPI, described
> earlier.
>
>
>
> 2. a lookup-based approach, where the client code requests a (possibly
> fine-grained and narrowly defined) implementation from the system.  For
> example:
>
>
>
> IMacMenu impl = PlatformAPI.lookup(IMacMenu.class);
>
>
>
> (where IMacMenu is an interface that, in this example, provides access to
> Mac menu, adding shutdown listeners, and so forth).
>
>
>
> if we are on windows, this method either returns null or throws an
> exception, if we are on Mac, we get a working instance (a singleton or a
> new instance each time, depending on the circumstances).
>
>
>
> This way we are free to extend or version the APIs without modifying the
> core classes.
>
>
>
> PlatformAPI.isSupported(IMacMenu.class) might provide a way to see whether
> the capability is present.
>
>
>
> The platform-specific interfaces like IMacMenu might in turn extend some
> base interface that provides introspection into common properties, such as
> version, description, possibly a list of other similar capabilities that
> the platform supports (may be a number of earlier versions?) and so forth.
>
>
>
> What do you think?
>
>
>
> -andy
>
>
>
>
>
> *From: *openjfx-dev <openjfx-dev-retn@openjdk.org>
> <openjfx-dev-retn@openjdk.org> on behalf of Kevin Rushforth
> <kevin.rushforth@oracle.com> <kevin.rushforth@oracle.com>
> *Date: *Monday, 2022/09/19 at 09:33
> *To: *openjfx-dev@openjdk.org <openjfx-dev@openjdk.org>
> <openjfx-dev@openjdk.org>
> *Subject: *Re: Provide Quit handler for system menu bar
>
> I like the idea of looking at this holistically, even if we do end up
> adding such features one at a time.
>
> As for how to expose such an API, I don't much like the idea of exposing
> the underlying platform explicitly unless there is no viable alternative. A
> better approach is one where a feature is optional based on whether the
> platform you are running on supports that feature. Especially given, as you
> pointed out, that features that are only available in one platform today
> might make their way into other platforms tomorrow. As for how to let an
> application know whether they can use a particular API, we already have
> ConditionalFeature, so adding to that would be a reasonable thing to
> consider.
>
> -- Kevin
>
> On 9/19/2022 9:06 AM, Andy Goryachev wrote:
>
> Greetings!
>
>
>
> Thank you for proposing a solution, Florian.  I wonder if we should
> extrapolate the problem further.  Given the fact that app developers always
> need access to platform specific APIs, be it integration with Mac menu,
> perhaps we should consider a way to do so in such a way that does not
> require various tricks.
>
>
>
> For example, we might invent a way to query whether we are running on a
> certain platform and get the corresponding APIs.  Let's say the class is
> PlatformAPI:
>
>
>
> These methods allow for querying whether the specific platform APIs are
> available
>
>
>
> PlatformAPI.isWindows();
>
> PlatformAPI.isMacOS();
>
> PlatformAPI.isLinux(); // isUnix()? isPosix() ?
>
>
>
>
>
> and these will actually return a service object that provides access to
> the APIs, or throws some kind of exception:
>
>
>
> IWindowsAPI PlatformAPI.getWindowsAPI();
>
> IMacOSAPI PlatformAPI.getMacOSAPI();
>
>
>
> the service object returned by one of these methods might provide further
> information about the platform version, as well as access to
> platform-specific APIs.
>
>
>
>
>
> Another thought is perhaps we ought to think about expanding functionality
> that became available on every platform in the XXI century (example: going
> to sleep/hibernate).  Possibly external shutdown via Mac menu or a signal
> discussed by the OP would be considered as platform-independent.
>
>
>
> What do you think?
>
>
>
> -andy
>
>
>
>
>
>
>
>
>
> *From: *openjfx-dev <openjfx-dev-retn@openjdk.org>
> <openjfx-dev-retn@openjdk.org> on behalf of Florian Kirmaier
> <florian.kirmaier@gmail.com> <florian.kirmaier@gmail.com>
> *Date: *Tuesday, 2022/09/13 at 08:11
> *To: *openjfx-dev@openjdk.java.net <openjfx-dev@openjdk.java.net>
> <openjfx-dev@openjdk.java.net>
> *Subject: *Provide Quit handler for system menu bar
>
> Hi Everyone,
>
>
> In one project, we have to handle the quit-logic for MacOS ourselves,
> when the <quit app> menu entry is used.
> As background information - this menu entry is set in the
> class com.sun.glass.ui.mac.MacApplication.
> It's basically hard coded. Currently, in this project, the menu entry
> doesn't work in some cases.
>
> My Solution would be:
>
> Provide a method "Platform.setQuiteHandler(Supplier<Boolean>)"
> This handler is called when quit <appname> from the menu is called.
> If the handler returns true, all windows are closed. Otherwise, nothing
> happens.
>
> It would look like the following:
> ```
> /**
>  * Sets the handler to be called when the application is about to quit.
>  * Currently, this can only happen on MacOS.
>  *
>  * This handler is called, when the user selects
>  * the "Quit <appname>" from the application menu.
>  * When the provided handler returns true,
>  * the application will close all windows.
>  * If the handler returns false, the application will not quit.
>  *
>  * @param The new quit handler.
>  */
> public static void setQuitHandler(Supplier x) {
>     ...
> }
> ```
> I've created a ticket for this topic.
> https://bugs.openjdk.org/browse/JDK-8293700
>
>
> I've got a working version for this change.
>
> According to Kevin Rushforth this need a prior dicussion on the mailing
> list.
>
> Any opinion regarding this?
>
> I could provide a pullrequest, if someone is interested.
>
> Florian Kirmaier
>
>
>
>
>
>

[Attachment #3 (text/html)]

<div dir="ltr">Yes, a custom &quot;about menu&quot; handling would be very similar \
and could be implemented at the same time.<br><br>It&#39;s worth mentioning, that we \
cannot use the methods java.awt.Desktop setAboutHandler and setQuitHandler methods, \
<br>because they only work, if the menu is from Swing. They don&#39;t work when the \
menu bar is from JavaFX.<br><br>For that reason, it might be the case, that more of \
the methods, provided in awt.Desktop are required in some cases.<br><br>So how could \
this look?<br><br>I think it would make sense, to make the API very similar to the \
existing API in Swing.<br>This would make it easier for Developers to get used to the \
API, or to switch form the Swing call to the new JavaFX call, if someone is migrating \
from Swing to JavaFX.<br>```<br>javafx.application.Desktop {<br>	boolean \
isSupported(Feature)<br>	void \
setQuitHandler(Supplier&lt;Boolean&gt;)<br>}<br>```<br>Would this meet the \
expectation, of how this could look?<br>Alternatively, these methods could be added \
to the Platform class, but I think it would make sense to create a new class for \
this.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 20 \
Sept 2022 at 19:57, Philip Race &lt;<a \
href="mailto:philip.race@oracle.com">philip.race@oracle.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

  
  <div>
    All of these requests seem to map to what we added to AWT in JDK 9.<br>
    We did this because there&#39;d been Apple specific APIs that came in
    via the<br>
    Apple port but were very iffy in terms of what was supported and it
    was<br>
    not a good idea to formally export them from the new desktop module.<br>
    <br>
    The java.awt.Desktop class was enhanced by the java.awt.desktop
    package<br>
    and all of these things are provided in a platform neutral way.<br>
    You just query whether the support is available.<br>
    <br>
    These can even be used in a mixed AWT/FX application if you want a
    solution now,<br>
    but FX could have its own version of these.<br>
    <br>
    Nothing that mentions a platform (please!).<br>
    <br>
    -phil<br>
    <br>
    <div>On 9/20/22 6:38 AM, Scott Palmer wrote:<br>
    </div>
    <blockquote type="cite">
      
      I always understood Alt+F4 as simply being a keyboard shortcut on
      Windows for closing the window of the active application.   The
      same as clicking the close widget.   I don't think there is
      anything special about it.   As far as being an equivalent to the
      macOS Quit action, I don't think it is quite the same. Does an
      application even know the difference between a window closed with
      the widget vs. Alt+F4?  <span style="color:rgb(0,0,0)">CTRL+F4 closes the \
current document window  or tab - similar to Command-W on macOS.  </span>
      <div><span style="color:rgb(0,0,0)"><br>
        </span></div>
      <div><span style="color:rgb(0,0,0)">I'm
          not aware of any special handlers being called on Windows for
          these shortcuts other than what is called when the equivalent
          close widget is pressed. If I'm wrong about that, then sure, a
          quit handler for JavaFX could be wired in to the same
          mechanism automatically.   Maybe Linux has an equivalent as
          well, I don't know.</span></div>
      <div><font color="#000000"><span><br>
          </span></font></div>
      <div><font color="#000000"><span>While we are at it, custom handling for the \
‘About'  menu item in the application menu is also needed, is it not?
              </span></font></div>
      <div><font color="#000000"><span><br>
          </span></font></div>
      <div><font color="#000000"><span>For now I'm currently using Jan Gassen's port \
of  NSMenuFX to hook into this stuff.  </span></font><a \
href="https://github.com/0x4a616e/NSMenuFX" \
target="_blank">https://github.com/0x4a616e/NSMenuFX</a><font \
color="#000000"><span><br>  </span></font>
        <div><font color="#000000"><br>
          </font>
          <div><br>
            <div dir="ltr">Scott</div>
          </div>
        </div>
      </div>
      <div dir="ltr"><br>
        <blockquote type="cite">On Sep 20, 2022, at 5:55 AM, John
          Hendrikx <a href="mailto:john.hendrikx@gmail.com" \
target="_blank">&lt;john.hendrikx@gmail.com&gt;</a> wrote:<br>  <br>
        </blockquote>
      </div>
      <blockquote type="cite">
        <div dir="ltr">
          <p>What about Alt + F4 and Ctrl + F4 on Windows?   Alt + F4
            closes the application (which works with JavaFX already) and
            Ctrl + F4 is supposed to close a single window, but that
            doesn&#39;t work for JavaFX.</p>
          <p>Also very much in favor of Keeping the API platform
            neutral, that&#39;s just how Java has worked since its
            inception.<br>
          </p>
          <p>--John<br>
          </p>
          <div>On 20/09/2022 06:25, Scott Palmer
            wrote:<br>
          </div>
          <blockquote type="cite">
            Windows applications often have an "Exit" menu item, but
            since it isn't standardized like it is on macOS, calling a
            quit handler for it would need to be a manual step - but the
            exact same method for the quit handler could be called,
            leaving it up to the programmer to continue or not with the
            application exit depending on the return value. This manual
            coding isn't a big deal since you would also need to have
            some app-specific handling to avoid making an Exit menu item
            on macOS, where it would look out of place.   
            <div><br>
            </div>
            <div>You could add a standard "requestExit()" method to
              Platform that you could manually bind to an Exit menu item
              on Windows or Linux, but it would be automatically called
              via an internal macOS Quit handler implementation.   The
              implementation of Platform.requestExit() on *all*
              platforms would call a boolean method if one was
              registered and then conditionally call Platform.exit()
              depending on the return value, the default being to always
              exit if nothing was registered. On macOS it would pass on
              the value to veto the native Quit handler as needed.   <font \
color="#000000"><span>I  haven't checked, does Application.stop() get called on
                  macOS if you exit via the Quit menu or Command-Q? If
                  it doesn't, that's another benefit.   This idea should
                  probably be opt-in via some API or system property, I
                  suppose it would have to be if it changes behaviour of
                  having Application.stop() called in some
                  circumstances. Or you can just make the setting of the
                  handler function the "opt-in".</span></font></div>
            <div><font color="#000000"><span><br>
                </span></font>
              <div>Btw, t<span style="color:rgb(0,0,0)">his reminds me of the \
long-standing  request for system tray support, along with with
                  various other features that have equivalents across
                  multiple OS', like showing progress on the dock icon,
                  or a numbered badge (for notifications, or unread
                  msgs, etc).   I think there are already issues in Jira
                  for these, maybe just as a general request to support
                  some features that AWT/Swing has that JFX is still
                  missing. Most of these features are available on both
                  Mac and Windows, possibly Linux.   It would be
                  irritating to code to different APIs for each if it
                  can be avoided, so I agree with going for a
                  platform-neutral way.</span></div>
              <div><font color="#000000"><span><br>
                  </span></font></div>
              <div><font color="#000000"><span>Cheers,  </span></font></div>
              <div><font color="#000000"><span><br>
                  </span></font>
                <div dir="ltr">Scott</div>
                <div dir="ltr"><br>
                  <blockquote type="cite">On Sep 19, 2022, at 8:11 PM,
                    Kevin Rushforth <a href="mailto:kevin.rushforth@oracle.com" \
target="_blank">&lt;kevin.rushforth@oracle.com&gt;</a>  wrote:<br>
                    <br>
                  </blockquote>
                </div>
                <blockquote type="cite">
                  <div dir="ltr"> I don&#39;t see us adding 100s of
                    OS-specific API calls, but even if we did, going
                    down the path of exposing them as Mac APIs or
                    Windows APIs, doesn&#39;t really seem like the direction
                    we want to go. Whatever we do needs to balance the
                    desire to integrate with, e.g., the macOS or Windows
                    platform with a desire to leave the door open for it
                    to later be implemented on the other platform(s).
                    And the most cross-platform way to do that from an
                    API point of view is by defining API that delivers
                    the desired functionality in as platform-neutral a
                    way as possible. It also needs to fit cleanly into
                    the existing API.<br>
                    <br>
                    So in the specific case of a quit handler, we could
                    define a platform API that an app could call to
                    register a handler that gets called if the platform
                    quit menu is selected and is able to cancel the Quit
                    action(basically, that&#39;s what is being proposed). We
                    could decide to provide some way for an app to query
                    whether it is supported, but maybe we just don&#39;t
                    need to worry about it in this specific case. We
                    could just document that it will get called when the
                    platform quit action is called, if there is such an
                    action on that platform. Other than maybe mentioning
                    in the docs that the macOS system menu &quot;quit&quot; action
                    is an example of an action that would invoke this,
                    it doesn&#39;t need to be platform-specific. One
                    question to answer is whether we should just put
                    this in the Platform class (where we have other
                    similar &quot;global&quot; application state), the Application
                    class (which has the life-cycle APIs), or somewhere
                    else (which might make sense if we wanted to define
                    an analog to the AWT Desktop class, although the
                    existing Platform class already has some APIs like
                    this).<br>
                    <br>
                    -- Kevin<br>
                    <br>
                    <br>
                    <div>On 9/19/2022 1:46 PM,
                      Andy Goryachev wrote:<br>
                    </div>
                    <blockquote type="cite">
                      
                      
                      <div>
                        <p class="MsoNormal"><span>Thank you, Kevin.   Your
                            insightful feedback always pulls the
                            discussion in the right \
                direction.<u></u><u></u></span></p>
                        <p class="MsoNormal"><span><u></u>  <u></u></span></p>
                        <p class="MsoNormal"><span>The initial problem we are
                            facing is access to Mac menu in general and
                            additional API specifically.   I can see a
                            possibility of extending the list of APIs
                            that app devs would want on Mac growing, so
                            there should be a better way to add them.  
                            Using hacks like com.apple.eawt, or system
                            properties is probably not the best
                            solution.   Ideally, there should be away
                            that does not require creative linking of
                            stub classes on non-Mac platforms, i.e. we
                            should be able to use a single code base for
                            all the platforms.<u></u><u></u></span></p>
                        <p class="MsoNormal"><span><u></u>  <u></u></span></p>
                        <p class="MsoNormal"><span>ConditionalFeature might
                            work well internally for openjfx, but I
                            don&#39;t think it is a good solution for
                            actually exposing the platform APIs to the
                            user.<u></u><u></u></span></p>
                        <p class="MsoNormal"><span><u></u>  <u></u></span></p>
                        <p class="MsoNormal"><span>So, in order to provide
                            platform-specific API in such a way that
                            still allows for a single code base for
                            multiple platform, and one that potentially
                            scales to tens or hundreds of API calls, I
                            see two solutions:<u></u><u></u></span></p>
                        <p class="MsoNormal"><span><u></u>  <u></u></span></p>
                        <p class="MsoNormal"><span>1. one start starts with a
                            single entry point, like PlatformAPI,
                            described earlier.<u></u><u></u></span></p>
                        <p class="MsoNormal"><span><u></u>  <u></u></span></p>
                        <p class="MsoNormal"><span>2. a lookup-based approach,
                            where the client code requests a (possibly
                            fine-grained and narrowly defined)
                            implementation from the system.   For
                            example:<u></u><u></u></span></p>
                        <p class="MsoNormal"><span><u></u>  <u></u></span></p>
                        <p class="MsoNormal"><span>IMacMenu impl =
                            \
                PlatformAPI.lookup(IMacMenu.class);<u></u><u></u></span></p>
                        <p class="MsoNormal"><span><u></u>  <u></u></span></p>
                        <p class="MsoNormal"><span>(where IMacMenu is an
                            interface that, in this example, provides
                            access to Mac menu, adding shutdown
                            listeners, and so forth).<u></u><u></u></span></p>
                        <p class="MsoNormal"><span><u></u>  <u></u></span></p>
                        <p class="MsoNormal"><span>if we are on windows, this
                            method either returns null or throws an
                            exception, if we are on Mac, we get a
                            working instance (a singleton or a new
                            instance each time, depending on the
                            circumstances).<u></u><u></u></span></p>
                        <p class="MsoNormal"><span><u></u>  <u></u></span></p>
                        <p class="MsoNormal"><span>This way we are free to
                            extend or version the APIs without modifying
                            the core classes.<u></u><u></u></span></p>
                        <p class="MsoNormal"><span><u></u>  <u></u></span></p>
                        <p \
class="MsoNormal"><span>PlatformAPI.isSupported(IMacMenu.class)  might provide a way \
                to see whether the
                            capability is present.<u></u><u></u></span></p>
                        <p class="MsoNormal"><span><u></u>  <u></u></span></p>
                        <p class="MsoNormal"><span>The platform-specific
                            interfaces like IMacMenu might in turn
                            extend some base interface that provides
                            introspection into common properties, such
                            as version, description, possibly a list of
                            other similar capabilities that the platform
                            supports (may be a number of earlier
                            versions?) and so forth.<u></u><u></u></span></p>
                        <p class="MsoNormal"><span><u></u>  <u></u></span></p>
                        <p class="MsoNormal"><span>What do you \
                think?<u></u><u></u></span></p>
                        <p class="MsoNormal"><span><u></u>  <u></u></span></p>
                        <p class="MsoNormal"><span>-andy<u></u><u></u></span></p>
                        <p class="MsoNormal"><span><u></u>  <u></u></span></p>
                        <p class="MsoNormal"><span><u></u>  <u></u></span></p>
                        <div \
style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid \
                rgb(181,196,223);padding:3pt 0in 0in">
                          <p class="MsoNormal" style="margin-bottom:12pt"><b><span \
                style="font-size:12pt;color:black">From:
                              </span></b><span \
                style="font-size:12pt;color:black">openjfx-dev
                              <a href="mailto:openjfx-dev-retn@openjdk.org" \
                target="_blank">&lt;openjfx-dev-retn@openjdk.org&gt;</a>
                              on behalf of Kevin Rushforth <a \
href="mailto:kevin.rushforth@oracle.com" \
target="_blank">&lt;kevin.rushforth@oracle.com&gt;</a><br>  <b>Date: </b>Monday, \
                2022/09/19 at 09:33<br>
                              <b>To: </b><a href="mailto:openjfx-dev@openjdk.org" \
                target="_blank">openjfx-dev@openjdk.org</a>
                              <a href="mailto:openjfx-dev@openjdk.org" \
target="_blank">&lt;openjfx-dev@openjdk.org&gt;</a><br>  <b>Subject: </b>Re: Provide \
Quit handler  for system menu bar<u></u><u></u></span></p>
                        </div>
                        <p class="MsoNormal" style="margin-bottom:12pt"><span \
style="font-size:11pt">I like the idea of  looking at this holistically, even if we \
do  end up adding such features one at a time.<br>
                            <br>
                            As for how to expose such an API, I don&#39;t
                            much like the idea of exposing the
                            underlying platform explicitly unless there
                            is no viable alternative. A better approach
                            is one where a feature is optional based on
                            whether the platform you are running on
                            supports that feature. Especially given, as
                            you pointed out, that features that are only
                            available in one platform today might make
                            their way into other platforms tomorrow. As
                            for how to let an application know whether
                            they can use a particular API, we already
                            have ConditionalFeature, so adding to that
                            would be a reasonable thing to consider.<br>
                            <br>
                            -- Kevin<br>
                            <br>
                            <u></u><u></u></span></p>
                        <div>
                          <p class="MsoNormal"><span style="font-size:11pt">On \
                9/19/2022 9:06
                              AM, Andy Goryachev wrote:<u></u><u></u></span></p>
                        </div>
                        <blockquote style="margin-top:5pt;margin-bottom:5pt">
                          <p \
                class="MsoNormal"><span>Greetings!</span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <p class="MsoNormal"><span>Thank you for proposing a
                              solution, Florian.   I wonder if we should
                              extrapolate the problem further.   Given
                              the fact that app developers always need
                              access to platform specific APIs, be it
                              integration with Mac menu, perhaps we
                              should consider a way to do so in such a
                              way that does not require various \
                tricks.</span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <p class="MsoNormal"><span>For example, we might
                              invent a way to query whether we are
                              running on a certain platform and get the
                              corresponding APIs.   Let&#39;s say the class
                              is PlatformAPI:</span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <p class="MsoNormal"><span>These methods allow for
                              querying whether the specific platform
                              APIs are available</span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <p \
                class="MsoNormal"><span>PlatformAPI.isWindows();</span><u></u><u></u></p>
                
                          <p \
                class="MsoNormal"><span>PlatformAPI.isMacOS();</span><u></u><u></u></p>
                
                          <p class="MsoNormal"><span>PlatformAPI.isLinux(); //
                              isUnix()? isPosix() ?</span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <p class="MsoNormal"><span>and these will actually
                              return a service object that provides
                              access to the APIs, or throws some kind of
                              exception:</span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <p class="MsoNormal"><span>IWindowsAPI
                              PlatformAPI.getWindowsAPI();</span><u></u><u></u></p>
                          <p class="MsoNormal"><span>IMacOSAPI
                              PlatformAPI.getMacOSAPI();</span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <p class="MsoNormal"><span>the service object
                              returned by one of these methods might
                              provide further information about the
                              platform version, as well as access to
                              platform-specific APIs.</span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <p class="MsoNormal"><span>Another thought is
                              perhaps we ought to think about expanding
                              functionality that became available on
                              every platform in the XXI century
                              (example: going to sleep/hibernate).  
                              Possibly external shutdown via Mac menu or
                              a signal discussed by the OP would be
                              considered as \
                platform-independent.</span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <p class="MsoNormal"><span>What do you \
                think?</span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <p class="MsoNormal"><span>-andy</span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <p class="MsoNormal"><span>  </span><u></u><u></u></p>
                          <div \
style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid \
                rgb(181,196,223);padding:3pt 0in 0in">
                            <p class="MsoNormal" style="margin-bottom:12pt"><b><span \
                style="font-size:12pt;color:black">From:
                                </span></b><span \
                style="font-size:12pt;color:black">openjfx-dev
                                <a href="mailto:openjfx-dev-retn@openjdk.org" \
target="_blank">  &lt;openjfx-dev-retn@openjdk.org&gt;</a>
                                on behalf of Florian Kirmaier <a \
                href="mailto:florian.kirmaier@gmail.com" target="_blank">
                                  &lt;florian.kirmaier@gmail.com&gt;</a><br>
                                <b>Date: </b>Tuesday, 2022/09/13 at
                                08:11<br>
                                <b>To: </b><a \
href="mailto:openjfx-dev@openjdk.java.net" \
                target="_blank">openjfx-dev@openjdk.java.net</a>
                                <a href="mailto:openjfx-dev@openjdk.java.net" \
target="_blank">&lt;openjfx-dev@openjdk.java.net&gt;</a><br>  <b>Subject: </b>Provide \
                Quit handler
                                for system menu bar</span><u></u><u></u></p>
                          </div>
                          <div>
                            <div>
                              <p class="MsoNormal"><span style="font-size:11pt">Hi \
Everyone,</span><u></u><u></u></p>  </div>
                            <div>
                              <p class="MsoNormal"><span style="font-size:11pt"><br>
                                  In one project, we have to handle the
                                  quit-logic for MacOS ourselves,<br>
                                  when the &lt;quit app&gt; menu entry
                                  is used.<br>
                                  As background information - this menu
                                  entry is set in the
                                  class  com.sun.glass.ui.mac.MacApplication.<br>
                                  It&#39;s basically hard coded. Currently,
                                  in this project, the menu entry
                                  doesn&#39;t work in some cases.<br>
                                  <br>
                                  My Solution would be:<br>
                                  <br>
                                  Provide a method
                                  \
&quot;Platform.setQuiteHandler(Supplier&lt;Boolean&gt;)&quot;<br>  This handler is \
called when quit  &lt;appname&gt; from the menu is
                                  called.<br>
                                  If the handler returns true, all
                                  windows are closed. Otherwise, nothing
                                  happens.<br>
                                  <br>
                                  It would look like the following:<br>
                                  ```<br>
                                  /**<br>
                                    * Sets the handler to be called when
                                  the application is about to quit.<br>
                                    * Currently, this can only happen on
                                  MacOS.<br>
                                    *<br>
                                    * This handler is called, when the
                                  user selects<br>
                                    * the &quot;Quit &lt;appname&gt;&quot; from the
                                  application menu.<br>
                                    * When the provided handler returns
                                  true,<br>
                                    * the application will close all
                                  windows.<br>
                                    * If the handler returns false, the
                                  application will not quit.<br>
                                    *<br>
                                    * @param The new quit handler.<br>
                                    */<br>
                                  public static void
                                  setQuitHandler(Supplier x) {<br>
                                        ...<br>
                                  }<br>
                                  ```<br>
                                  I&#39;ve created a ticket for this topic.  <a \
href="https://bugs.openjdk.org/browse/JDK-8293700" \
target="_blank">https://bugs.openjdk.org/browse/JDK-8293700</a></span><u></u><u></u></p>
  </div>
                            <div>
                              <p class="MsoNormal"><span style="font-size:11pt"><br>
                                  I&#39;ve got a working version for this
                                  change.  </span><u></u><u></u></p>
                            </div>
                            <div>
                              <p class="MsoNormal"><span \
style="font-size:11pt">According to  Kevin Rushforth this need a prior
                                  dicussion  on the mailing \
list.</span><u></u><u></u></p>  </div>
                            <div>
                              <p class="MsoNormal"><span style="font-size:11pt">Any \
opinion  regarding this?<br>
                                  <br>
                                  I could provide a pullrequest, if
                                  someone is interested.<br>
                                  <br>
                                  Florian Kirmaier</span><u></u><u></u></p>
                            </div>
                          </div>
                        </blockquote>
                        <p class="MsoNormal"><span style="font-size:11pt"><u></u>  \
<u></u></span></p>  </div>
                    </blockquote>
                    <br>
                  </div>
                </blockquote>
              </div>
            </div>
          </blockquote>
        </div>
      </blockquote>
    </blockquote>
    <br>
  </div>

</blockquote></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic