Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intercept CMD-Q in OS/X #291

Open
sufrin opened this issue Jun 5, 2024 · 1 comment
Open

Intercept CMD-Q in OS/X #291

sufrin opened this issue Jun 5, 2024 · 1 comment
Labels
Good First Issue Good for newcomers Help Wanted Extra attention is needed Platform: macOS

Comments

@sufrin
Copy link

sufrin commented Jun 5, 2024

First: thanks to all contributors. JWM does indeed play nicely with Skija (I've been making a UI toolkit for Scala -- soon to go open).

I've been unable to intercept CMD-Q in order to ask the user what she wants to do next (I can, of course, handle window-close requests from the traffic-light). The usual code for installing a quit handler runs without reporting any problem: but cmd-Q just quits the app. I realize there's no reason I should expect the awt.desktop stuff to work; but that's all I have.

   /**
     * This doesn't fail; but it doesn't prevent CMD-Q from torpedoing an in-flight app.
     */
    locally {
      if (java.awt.Desktop.isDesktopSupported) {
        val desk = java.awt.Desktop.getDesktop
        desk.disableSuddenTermination()
        if (!desk.isSupported(java.awt.Desktop.Action.APP_QUIT_HANDLER)) println(s"Can't handle Quit")
        desk.setQuitHandler(new java.awt.desktop.QuitHandler {
          def handleQuitRequestWith(e: QuitEvent, response: QuitResponse): Unit = {
            println(s"Quit: $e")
            if (false) response.performQuit() else response.cancelQuit()
          }
        })
      } else println("Desktop not supported")
@tonsky
Copy link
Collaborator

tonsky commented Jun 6, 2024

Yeah there needs to be a special handler for that which we don’t have yet

https://developer.apple.com/documentation/appkit/nsapplicationdelegate/1428642-applicationshouldterminate?language=objc

@tonsky tonsky added Good First Issue Good for newcomers Help Wanted Extra attention is needed Platform: macOS labels Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue Good for newcomers Help Wanted Extra attention is needed Platform: macOS
Development

No branches or pull requests

2 participants