Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-10899

Make Qt send a QEvent::ApplicationActivate event if NSApplicationDelegate receives "applicationShouldHandleReopen"

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Done
    • P3: Somewhat important
    • 4.8.7, 5.4.0
    • 4.7.0
    • GUI: Window management
    • None
    • Qt/Cocoa, OS X 10.5/10.6

    • 3d5122eab127fbe13d4e13a92ee5f6d6686d2f2f 787692a09ee3e7e224ddb36b2c602bc3c37e9fab

    Description

      Mac application windows are closed by the window close button, but it is expected the application stays active
      until the user explicitly quits the app (from application menu, or Cmd-Q). If clicking on the application icon again
      an active application is expected to restore its application window (without reloading the app image).
      To emulate this more native behavior on Mac it is possible to simple hide the main window on QWidget::closeEvent().
      Then, if the user clicks on the dock icon, or double clicks on the app icon in Finder, an applicationShouldHandleReopen is issued, but
      ignored by Qt. But if another app was activated and the user clicks back on the dock icon OS X will send a "applicationDidBecomeActive"
      and Qt translates it to a QEvent::ApplicationActivate.

      It would be nice to also get a QEvent::ApplicationActivate event on "applicationShouldHandleReopen".

      Thereby you could write in the main window even handler:

      if ((event->type() == QEvent::ApplicationActivate) && (!isVisible())) {
      // ohh, must have been closed before
      reopen();
      }

      The 3 line patch I attached makes the event mapping.
      It wouldn't affect applications that simply terminate on QWidget::closeEvent().

      If it's a little unclear, what I'm talking about (Apple logic), see also:
      http://th30z.netsons.org/2008/08/123/ (Carbon hack to solve same problem)
      http://lists.trolltech.com/qt-interest/2007-06/thread00801-0.html (a lost user, faces same issue)

      Related Apple docs:
      http://developer.apple.com/mac/library/documentation/Cocoa/Reference/NSApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSApplicationDelegate/applicationShouldHandleReopen:hasVisibleWindows:

      Attachments

        1. Application_mac.h
          1 kB
        2. Application_mac.mm
          3 kB
        3. out.gif
          out.gif
          1.26 MB
        4. reopen.patch
          0.6 kB
        For Gerrit Dashboard: QTBUG-10899
        # Subject Branch Project Status CR V

        Activity

          People

            sgaist Samuel Gaist
            unclewerner Frank Mertens
            Votes:
            5 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: