summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm
Commit message (Collapse)AuthorAgeFilesLines
* Expose QPA API under qpa/*Girish Ramakrishnan2012-05-071-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The main reasons for doing this are: 1. _qpa.h end up in the master QtGui include file. QtGui is meant for userland applications. qpa code is neither binary nor source compatible. Inadvertant use of QPA api makes the user code binary-incompatible. 2. syncqt creates forwarding headers for non-private header files. This gives people the impression that this is public API. As discussed on the mailing list, even though QPA api is internal and subject to change, it needs to treated differently from private headers since they will be used by in-qtbase and out-of-qtbase plugins. This commit does the following: 1. The _qpa in QPA header files is dropped. 2. syncqt now treats any file with qplatform prefix as a special file and moves it to qpa/ directory. The recommended way of using QPA API in plugins is: #include <qpa/qplatformfoo.h>. This allows the user include QPA API from multiple modules (for example, qplatformfoo might be in QtPrintSupport) 3. The user needs to explicitly add QT += <module>-private to get access to the qpa api. 4. Creates compat headers for the olden style qplatformfoo_qpa.h and QPlatformFoo includes. This commit does not change the cpp filenames. This requires a more careful merging of existing non qpa cpp files and existing cpp files on a case by case basis. This can be done at anytime. The following files are not renamed as part of this changed but will be fixed as part of a future change: src/gui/kernel/qgenericpluginfactory_qpa.h src/gui/kernel/qgenericplugin_qpa.h src/gui/kernel/qwindowsysteminterface_qpa.h files were renamed using for x in `find . -name "qplatform*_qpa.h"`; do git mv $x "${x/_qpa.h/.h}"; done for x in `find . -name "qplatform*_qpa_p.h"`; do git mv $x "${x/_qpa_p.h/_p.h}"; done includes were renamed using script for file in `find . -name "*.h" -or -name "*.cpp" -or -name "*.mm"`; do sed -i -e 's,.*#.*include.*<\(Qt.*/\)\?\(QPlatform.*\)>,#include <qpa/\L\2.h>,g' \ -e 's,.*#.*include.*"\(Qt.*/\)\?\(QPlatform.*\)",#include <qpa/\L\2.h>,g' \ -e 's,.*#.*include.* "\(qplatform.*\)_qpa.h",#include <qpa/\L\1.h>,g' \ -e 's,.*#.*include.*"\(qplatform.*\)_qpa_p.h",#include <qpa/\L\1_p.h>,g' \ -e 's,.*#.*include.*<\(Qt.*/\|Qt.*/private/\|private/\)\?\(qplatform.*\)_qpa\(.*\)>,#include <qpa/\2\3>,g' \ -e 's,.*#.*include.*"\(Qt.*/\|Qt.*/private/\|private/\)\?\(qplatform.*\)_qpa\(.*\)",#include <qpa/\2\3>,g' \ $file done Change-Id: I04a350314a45746e3911f54b3b21ad03315afb67 Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com> Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
* Cocoa: support modal windowsBradley T. Hughes2012-04-251-26/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | Qt::WindowModal windows and dialogs are shown using [NSApp beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:] as long as they have a valid parent. Otherwise they are behave as application modal. Use the existing modal session support in the QCocoaEventDispatcher (which was inherited from Qt 4) to support Qt::ApplicationModal windows and dialogs. Some changes to this code are needed to ensure proper behavior: 1. Window level modification is now done in QCocoaWindow::recreateWindow() instead of in QCocoaEventDispatcher. 2. Make interrupt() use [NSApp abortModal] to stop a modal session (previously we were freeing memory from under Cocoa's feet, causing tools like valgrind and Instruments.app to complain) 3. Do not remove an item from a list and use a const reference to the removed item immediately after (minor bug fix). Also make sure that QCocoaEventDispatcher cleans up any modal sessions and retained user input events on destruction (otherwise we leave NSApplication in a weird state, which causes some autotest failures). Change-Id: Iaeefa025400f324b5348b8c81a40384ef026efb4 Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
* Merge remote-tracking branch 'origin/api_changes'Lars Knoll2012-04-171-0/+13
|\ | | | | | | Change-Id: I964b0a6f5c38351fdfafb8a2a128a349ff8c89d1
| * Add a remainingTime() method to the public interface of the QTimer classLaszlo Papp2012-04-031-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is an extension coming from the use case when you, for instance, need to implement a countdown timer in client codes, and manually maintain a dedicated variable for counting down with the help of yet another Timer. There might be other use cases as well. The returned value is meant to be in milliseconds, as the method documentation says, since it is reasonable, and consistent with the rest (ie. the interval accessor). The elapsed time is already being tracked inside the event dispatcher, thus the effort is only exposing that for all platforms supported according to the desired timer identifier, and propagating up to the QTimer public API. It is done by using the QTimerInfoList class in the glib and unix dispatchers, and the WinTimeInfo struct for the windows dispatcher. It might be a good idea to to establish a QWinTimerInfo (qtimerinfo_win{_p.h,cpp}) in the future for resembling the interface for windows with the glib/unix management so that it would be consistent. That would mean abstracting out a base class (~interface) for the timer info classes. Something like that QAbstractTimerInfo. Test: Build test only on (Arch)Linux, Windows and Mac. I have also run the unit tests and they passed as well. Change-Id: Ie37b3aff909313ebc92e511e27d029abb070f110 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
* | Cocoa: allow timer activation to recurseBradley T. Hughes2012-04-171-19/+53
|/ | | | | | | | | | | | CFRunLoopTimer's callback will never recurse. Since we are using one CFRunLoopTimer to drive all Qt timers, we need to work around this by sending all timers via a dedicated CFRunLoopSource (since these callbacks can recurse). We also need to block this new timer source along with the posted event source when calling processEvents() "manually" to prevent livelock deep in CFRunLoop. Change-Id: I375e46b6cfa0c76db678a1085314d42d8996d062 Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
* Cocoa: initialize QCocoaEventDispacherPrivate::lastSerialBradley T. Hughes2012-03-261-0/+1
| | | | | | | | This silences warnings from valgrind about a conditional depending on an uninitialized value. Change-Id: I819a44ed5dc02e163c00849811870c94f66b6651 Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
* Ensure that posted events are sent by Q*Application::processEvents()Bradley T. Hughes2012-02-071-0/+9
| | | | | | | | | | | | Commit b7ca6a81dbf6a2b96c8f04b856372050618e60c0 removed a call to sendPostedEvents() that deemed unnecessary. Unfortunately, it is necessary, as shown by the tst_QScriptEngine::processEventsWhileRunning() test in the QtScript module. Re-add the call, but only when not waiting for more events. Change-Id: I648d66dd3ba484ad9e9a93fc03a9792cca5035c6 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@nokia.com>
* processEvents(WaitForMoreEvents) should return after delivering eventsBradley T. Hughes2012-02-031-11/+25
| | | | | | | | | | | | | | | | | | | | | | The Cocoa event dispatcher sends timer, socket, and posted events correctly, but they are not NSEvents, and as such, they do not cause [NSApp nextEventMatchingMask] to return. When calling processEvents() with WaitForMoreEvents, but the EventLoopExec flag isn't set, we want to interrupt the WaitForMoreEvents. As a result, We should not call wakeUp() at the top of processEvents(), otherwise we end up shortcutting other event sources. We also do not need to call QCoreApplication::sendPostedEvents() directly either in processEvents(), it's the postedEventsSource job to do that. The interruptLater mechanism is always run when calling processEvents() directly (not via exec()), which causes problems when testing processEvents(). Don't use interruptLater unless the modal sessions change (which is indicated by the cached session pointer being reset to zero). Change-Id: Iec2b49a4f306b2702c979522f12a28d0b5fbd0b4 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@nokia.com>
* Remove duplicated function from QCocoaEventDispatcherBradley T. Hughes2012-02-021-23/+7
| | | | | | | | | | | | | | The qt_mac_waitForMoreModalSessionEvents() is identical to qt_mac_waitForMoreEvents(), except that it passes a different inMode parameter to [NSApp nextEventMatchingMask]. Change the latter function to take the mode as a parameter itself, defaulting to the default mode. Change the dequeue parameter to [NSApp nextEventMatchingMask] from YES to NO. Having the function dequeue the event, and then immediately reposting the event is not necessary. Change-Id: Iba45d41ad3ff4d5721d1068e6d5c78585cb15810 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@nokia.com>
* Remove "All rights reserved" line from license headers.Jason McDonald2012-01-301-1/+1
| | | | | | | | | | As in the past, to avoid rewriting various autotests that contain line-number information, an extra blank line has been inserted at the end of the license text to ensure that this commit does not change the total number of lines in the license header. Change-Id: I311e001373776812699d6efc045b5f742890c689 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update contact information in license headers.Jason McDonald2012-01-231-1/+1
| | | | | | | Replace Nokia contact email address with Qt Project website. Change-Id: I431bbbf76d7c27d8b502f87947675c116994c415 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Change QCocoaEventDispatcher timer handling to use QTimerInfoListBradley T. Hughes2012-01-091-89/+93
| | | | | | | | | | | | | | | | This gives us support for the various Qt::TimerTypes. We only use one CFRunLoopTimer to drive all of the Qt timers. We update the time-to-fire for this timer as we add/remove/fire Qt timers. The documentation for the CFRunLoopTimerSetNextFireDate() function says that this is a valid use case, and is more performant than constantly adding and removing CFRunLoopTimers. The documentation recommends using a large interval for this use case (the docs say "several decades", but we use 1 year). Change-Id: Ie7fd7a845f4254699a5b6a5720e7626f2c5e787f Reviewed-by: Robin Burchell <robin+qt@viroteck.net> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@nokia.com>
* QCocoaEventDispatcherPrivate members should not be staticBradley T. Hughes2012-01-051-48/+40
| | | | | | | | | | | | | | | Keep the Cocoa event dispatcher's private data as normal members of QCocoaEventDispatcherPrivate. This removes the global initializers for the macTimerHash and cocoaModalSessionStask as well. To keep timers working, we pass a pointer to the timer's MacTimerInfo struct to the callback, instead of just the timer id. The MacTimerInfo needs to keep a pointer back to the QCocoaEventDispatcherPrivate to get access to the private's members. Change-Id: Ic3a61e5e1d1d82030735de73cf0b0c70a13c21a4 Reviewed-by: Robin Burchell <robin+qt@viroteck.net> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@nokia.com>
* Update copyright year in license headers.Jason McDonald2012-01-051-1/+1
| | | | | Change-Id: I02f2c620296fcd91d4967d58767ea33fc4e1e7dc Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Don't release timer ids in event dispatcher codeBradley T. Hughes2012-01-041-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 3rdparty event dispatchers are impossible to write without using the internal API QAbstractEventDispatcherPrivate::releaseTimerId(). Fix this by having each QObject keep track of its own timer ids, and release them when they are no longer used. As a side effect, this makes the QObjectData::pendTimer bit unnecessary. This also removes the QObjectData::inThreadChangeEvent hack that the event dispatchers used to avoid releasing timer ids when moving timers to a new thread. QBasicTimer becomes even more low-level. It cannot use QObject::startTimer() anymore, since we do not have a way to call QObject::killTimer() from QBasicTimer::stop(). QBasicTimer uses the QAbstractEventDispatcher interface directly, and releases the timer id explicitly as well when stopping the timer. This change also fixes some rare timer id "leaks" when destroying or stopping timers after a thread has exited and destroyed its event dispatcher (the timer ids would never be released when no dispatcher exists). Globally destructed QObjects that have running timers may try to release their timer ids after the timer id freelist has been destroyed. This commit accomodates such objects by avoiding the null dereference in QAbstractEventDispatcherPrivate::releaseTimerId(). Change-Id: I2d7cd8221fae441f3cf02b6c0b4bc16063834d00 Reviewed-by: David Faure <faure@kde.org> Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
* Make QCocoaEventDispatcher inherit from QAbstractEventDispatcherBradley T. Hughes2012-01-031-1/+4
| | | | | | | | | | | ... instead of QEventDispatcherUNIX. The Cocoa dispatcher does not use any of the facilities of the UNIX dispatcher, and it reimplements every virtual method already (with the exception of flush(), which just needs an empty implementation). Change-Id: I24aefd169888946afac7800192a0f96770787718 Reviewed-by: Robin Burchell <robin+qt@viroteck.net> Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
* Add Qt::TimerType argument to QAbstractEventDispatcher::registerTimer()Bradley T. Hughes2012-01-021-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | ... and deprecate the old registerTimer() functions. The new pure- virtual registerTimer() breaks source-compatibility. Subclasses cannot be instantiated anymore, since the pure virtual function signature has changed. QAbstractEventDispatcher::TimerInfo is no longer a QPair. It is now a struct with timerId, interval, and timerType members. This is a source incompatibility that should only affect subclasses of QAbstractEventDispatcher, which will need to pass 3 arguments to the TimerInfo constructor instead of 2. If the subclass used QPair<int,int> instead of the TimerInfo typedef, the QPair<int,int> declarations will need to be replaced with TimerInfo. Call the new registerTimer() function with the type from QObject::startTimer(). Change all subclasses of QAbstractEventDispatcher to reimplement the new virtual function. The type argument is unused at the momemnt, except to ensure that registeredTimers() returns the type each timer was registered with. Implementations for the various dispatchers will be done in separate commits. Author: Thiago Macieira <thiago.macieira@nokia.com> Change-Id: Ia22697e0ab0847810c5d162ef473e0e5a17a904b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace implicit QAtomic* casts with explicit load()/store()Bradley T. Hughes2011-10-271-2/+3
| | | | | Change-Id: Ia7ef1a8e01001f203e409c710c977d6f4686342e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Cocoa: clean up compiler warnings.Morten Sorvig2011-10-231-0/+3
| | | | | Change-Id: I2cb65bb455b79b218a317b21e5a3b0d9792e0e22 Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
* Cocoa: QMenu refactor.Morten Sorvig2011-09-071-18/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change prepares for enabling native menus on OS X. Move code from src/widgets to cocoa: - qcocoaapplicaiton - qcocoaapplicaitondelegate - qcocoamenuloader - qcocoamenu - qmenu_mac - misc helpers to qcocoahelpers Create a QNSApplication and QCocoaApplicationDelegate at application startup. New Lighthouse API: - class QPlatformMenu - class QPlatformMenuBar - QPlatformIntegration::createPlatformMenu() - QPlatformIntegration::createPlatformMenuBar() Platforms that wants a native menu integration subclasses QPlatformMenu[|Bar] and implements the create function. The default implementation returns 0, which causes QMenu to use the standard Qt menus. This API is based on the current native menu abstraction that Mac, Wince and S60 uses in Qt 4. The main difference is that the platform classes are proper standalone classes and not #ifdeffed into QMenuPrivate. Change-Id: I3da41f80b0ae903a476937908b1f9b88014b7954 Reviewed-on: http://codereview.qt.nokia.com/4068 Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
* Undefine "slots" before including cocoa headers to make it compileGunnar Sletta2011-08-051-0/+1
| | | | | | | Change-Id: Id2ba9d657a93e0d10b70b31b6a44a6ea9f598d8f Reviewed-on: http://codereview.qt.nokia.com/2328 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
* Refactor window system event dispatching.Morten Sorvig2011-06-231-4/+2
| | | | | | | | | | Add QWindowSystemInterface::sendWindowSystemEvents, which contains the canonical "empty and send queued window system events" implementation. Make the Cocoa, QPA, and GLIB dispatchers use the new implementation. Cocoa now no longer inherits from QPA.
* Add lighthouse event dispatcher API.Morten Sorvig2011-06-221-0/+1135
Platform plugin creation is now moved forward in order to have a platform plugin instance at event dispatcher creation time. Plugins are now responsible for implementing PlatformIntegration::createEventDispatcher and returning an QAbstractEventDispatcher subclass.