From 9bf6c2c8098dd44f868ed60f0459935243eaea33 Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Sun, 21 Jun 2020 11:09:10 +0200 Subject: [PATCH] Setup initial mac target --- app/SysTray-X/SysTray-X.pro | 27 +- app/SysTray-X/files/mac/LICENSE | 373 ++++++++++++++++++ app/SysTray-X/preferencesdialog.cpp | 2 +- app/SysTray-X/systrayx.cpp | 10 +- app/SysTray-X/systrayx.h | 2 +- app/SysTray-X/systrayxlink.cpp | 2 +- app/SysTray-X/systrayxstatusnotifier.cpp | 2 +- app/SysTray-X/systrayxstatusnotifier.h | 2 +- ...windowctrl-unix.cpp => windowctrl-lin.cpp} | 56 +-- .../{windowctrl-unix.h => windowctrl-lin.h} | 18 +- app/SysTray-X/windowctrl-mac.cpp | 219 ++++++++++ app/SysTray-X/windowctrl-mac.h | 309 +++++++++++++++ app/SysTray-X/windowctrl.cpp | 6 +- app/SysTray-X/windowctrl.h | 16 +- 14 files changed, 981 insertions(+), 63 deletions(-) create mode 100644 app/SysTray-X/files/mac/LICENSE rename app/SysTray-X/{windowctrl-unix.cpp => windowctrl-lin.cpp} (89%) rename app/SysTray-X/{windowctrl-unix.h => windowctrl-lin.h} (96%) create mode 100644 app/SysTray-X/windowctrl-mac.cpp create mode 100644 app/SysTray-X/windowctrl-mac.h diff --git a/app/SysTray-X/SysTray-X.pro b/app/SysTray-X/SysTray-X.pro index 73a4063..a7a8d84 100644 --- a/app/SysTray-X/SysTray-X.pro +++ b/app/SysTray-X/SysTray-X.pro @@ -78,7 +78,7 @@ win32: { } unix:macx: { QMAKE_LFLAGS += -framework IOKit -framework Foundation - QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7 + QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.13 LIBS += -dead_strip } @@ -173,16 +173,20 @@ SOURCES += \ preferencesdialog.cpp \ preferences.cpp \ windowctrl.cpp -unix: { -SOURCES += \ - windowctrl-unix.cpp +unix:!macx: { + SOURCES += \ + windowctrl-lin.cpp contains(DEFINES,KDE_INTEGRATION) { SOURCES += \ systrayxstatusnotifier.cpp } } +unix:macx: { + SOURCES += \ + windowctrl-mac.cpp +} win32: { -SOURCES += \ + SOURCES += \ windowctrl-win.cpp } @@ -194,17 +198,20 @@ HEADERS += \ preferencesdialog.h \ preferences.h \ windowctrl.h -unix: { -HEADERS += \ - windowctrl-unix.h - +unix:!macx: { + HEADERS += \ + windowctrl-lin.h contains(DEFINES,KDE_INTEGRATION) { HEADERS += \ systrayxstatusnotifier.h } } +unix:macx: { + HEADERS += \ + windowctrl-mac.h +} win32: { -HEADERS += \ + HEADERS += \ windowctrl-win.h } diff --git a/app/SysTray-X/files/mac/LICENSE b/app/SysTray-X/files/mac/LICENSE new file mode 100644 index 0000000..a612ad9 --- /dev/null +++ b/app/SysTray-X/files/mac/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/app/SysTray-X/preferencesdialog.cpp b/app/SysTray-X/preferencesdialog.cpp index f5ba68c..61ed385 100644 --- a/app/SysTray-X/preferencesdialog.cpp +++ b/app/SysTray-X/preferencesdialog.cpp @@ -46,7 +46,7 @@ PreferencesDialog::PreferencesDialog( SysTrayXLink *link, Preferences *pref, QWi #endif -#if defined( Q_OS_UNIX ) && defined( NO_KDE_INTEGRATION ) +#if defined(Q_OS_MACOS) || defined( Q_OS_LINUX ) && defined( NO_KDE_INTEGRATION ) m_ui->hideDefaultIconCheckBox->hide(); diff --git a/app/SysTray-X/systrayx.cpp b/app/SysTray-X/systrayx.cpp index 017f6ad..3b043fc 100644 --- a/app/SysTray-X/systrayx.cpp +++ b/app/SysTray-X/systrayx.cpp @@ -158,7 +158,9 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent ) * Request preferences from add-on */ getPreferences(); -} + + slotSelectIconObjectPref() +;} /* @@ -324,7 +326,7 @@ void SysTrayX::hideTrayIcon() } -#if defined( Q_OS_UNIX ) && defined( KDE_INTEGRATION ) +#if defined( Q_OS_LINUX ) && defined( KDE_INTEGRATION ) /* * Show / create tray icon @@ -438,7 +440,7 @@ void SysTrayX::slotSelectIconObjectPref() void SysTrayX::slotSelectIconObject( bool state ) { -#if defined( Q_OS_UNIX ) && defined( KDE_INTEGRATION ) +#if defined( Q_OS_LINUX ) && defined( KDE_INTEGRATION ) if( state ) { @@ -574,7 +576,7 @@ void SysTrayX::slotVersion( QString version ) QSystemTrayIcon::Warning ); } -#if defined( Q_OS_UNIX ) && defined( KDE_INTEGRATION ) +#if defined( Q_OS_LINUX ) && defined( KDE_INTEGRATION ) if( m_kde_tray_icon ) { diff --git a/app/SysTray-X/systrayx.h b/app/SysTray-X/systrayx.h index efeca60..81213ff 100644 --- a/app/SysTray-X/systrayx.h +++ b/app/SysTray-X/systrayx.h @@ -74,7 +74,7 @@ class SysTrayX : public QObject */ void hideTrayIcon(); -#ifdef Q_OS_UNIX +#if defined( Q_OS_LINUX ) && defined( NO_KDE_INTEGRATION ) /** * @brief showKdeTrayIcon. Create and show the KDE icon. diff --git a/app/SysTray-X/systrayxlink.cpp b/app/SysTray-X/systrayxlink.cpp index 97f38cc..a91d400 100644 --- a/app/SysTray-X/systrayxlink.cpp +++ b/app/SysTray-X/systrayxlink.cpp @@ -362,7 +362,7 @@ void SysTrayXLink::DecodeMessage( const QByteArray& message ) */ emit signalKdeIntegration( hide_default_icon ); -#if defined( Q_OS_UNIX ) && defined( NO_KDE_INTEGRATION ) +#if defined( Q_OS_LINUX ) && defined( NO_KDE_INTEGRATION ) sendDisableKdeIntegration(); diff --git a/app/SysTray-X/systrayxstatusnotifier.cpp b/app/SysTray-X/systrayxstatusnotifier.cpp index c24eb0a..c6baff2 100644 --- a/app/SysTray-X/systrayxstatusnotifier.cpp +++ b/app/SysTray-X/systrayxstatusnotifier.cpp @@ -1,6 +1,6 @@ #include "systrayxstatusnotifier.h" -#if defined( Q_OS_UNIX ) && defined( KDE_INTEGRATION ) +#if defined( Q_OS_LINUX ) && defined( KDE_INTEGRATION ) /* * Local includes diff --git a/app/SysTray-X/systrayxstatusnotifier.h b/app/SysTray-X/systrayxstatusnotifier.h index 4f1beb5..d1aee4f 100644 --- a/app/SysTray-X/systrayxstatusnotifier.h +++ b/app/SysTray-X/systrayxstatusnotifier.h @@ -1,5 +1,5 @@ #include -#if defined( Q_OS_UNIX ) && defined( KDE_INTEGRATION ) +#if defined( Q_OS_LINUX ) && defined( KDE_INTEGRATION ) #ifndef SYSTRAYXSTATUSNOTIFIER_H #define SYSTRAYXSTATUSNOTIFIER_H diff --git a/app/SysTray-X/windowctrl-unix.cpp b/app/SysTray-X/windowctrl-lin.cpp similarity index 89% rename from app/SysTray-X/windowctrl-unix.cpp rename to app/SysTray-X/windowctrl-lin.cpp index 06891bd..ff8ef80 100644 --- a/app/SysTray-X/windowctrl-unix.cpp +++ b/app/SysTray-X/windowctrl-lin.cpp @@ -1,6 +1,6 @@ -#include "windowctrl-unix.h" +#include "windowctrl-lin.h" -#ifdef Q_OS_UNIX +#ifdef Q_OS_LINUX /* * System includes @@ -14,7 +14,7 @@ /* * Constructor */ -WindowCtrlUnix::WindowCtrlUnix( QObject *parent ) : QObject( parent ) +WindowCtrlLin::WindowCtrlLin( QObject *parent ) : QObject( parent ) { /* * Initialize @@ -35,7 +35,7 @@ WindowCtrlUnix::WindowCtrlUnix( QObject *parent ) : QObject( parent ) /* * Set the minimize type */ -void WindowCtrlUnix::setMinimizeType( Preferences::MinimizeType type ) +void WindowCtrlLin::setMinimizeType( Preferences::MinimizeType type ) { m_minimize_type = type; } @@ -44,7 +44,7 @@ void WindowCtrlUnix::setMinimizeType( Preferences::MinimizeType type ) /* * Set the window state. */ -void WindowCtrlUnix::setWindowState( int state ) +void WindowCtrlLin::setWindowState( int state ) { m_window_state = state; } @@ -55,7 +55,7 @@ void WindowCtrlUnix::setWindowState( int state ) * * @return The state. */ -int WindowCtrlUnix::getWindowState() const +int WindowCtrlLin::getWindowState() const { return m_window_state; } @@ -64,7 +64,7 @@ int WindowCtrlUnix::getWindowState() const /* * Get the minimize type */ -Preferences::MinimizeType WindowCtrlUnix::getMinimizeType() const +Preferences::MinimizeType WindowCtrlLin::getMinimizeType() const { return m_minimize_type; } @@ -73,7 +73,7 @@ Preferences::MinimizeType WindowCtrlUnix::getMinimizeType() const /* * Get the parent pid of SysTray-X, TB hopefully */ -qint64 WindowCtrlUnix::getPpid() const +qint64 WindowCtrlLin::getPpid() const { return getppid(); } @@ -82,7 +82,7 @@ qint64 WindowCtrlUnix::getPpid() const /* * Is the pid from thunderbird */ -bool WindowCtrlUnix::isThunderbird( qint64 pid ) const +bool WindowCtrlLin::isThunderbird( qint64 pid ) const { return getProcessName( pid ).contains( "thunderbird", Qt::CaseInsensitive ); } @@ -91,7 +91,7 @@ bool WindowCtrlUnix::isThunderbird( qint64 pid ) const /* * Get the process name */ -QString WindowCtrlUnix::getProcessName( qint64 pid ) const +QString WindowCtrlLin::getProcessName( qint64 pid ) const { QString process_name = QString( "/proc/%1/exe" ).arg( pid ); QFileInfo process( process_name ); @@ -103,7 +103,7 @@ QString WindowCtrlUnix::getProcessName( qint64 pid ) const /* * Find window(s) by title */ -bool WindowCtrlUnix::findWindow( const QString& title ) +bool WindowCtrlLin::findWindow( const QString& title ) { QList< WindowItem > windows = listXWindows( m_display, m_root_window ); @@ -137,7 +137,7 @@ bool WindowCtrlUnix::findWindow( const QString& title ) /* * Find a window by PID */ -void WindowCtrlUnix::findWindow( qint64 pid ) +void WindowCtrlLin::findWindow( qint64 pid ) { QList< WindowItem > windows = listXWindows( m_display, m_root_window ); @@ -185,7 +185,7 @@ void WindowCtrlUnix::findWindow( qint64 pid ) /* * Display window atoms */ -void WindowCtrlUnix::displayWindowElements( const QString& title ) +void WindowCtrlLin::displayWindowElements( const QString& title ) { QList< WindowItem > windows = listXWindows( m_display, m_root_window ); @@ -211,7 +211,7 @@ void WindowCtrlUnix::displayWindowElements( const QString& title ) /* * Display window atoms */ -void WindowCtrlUnix::displayWindowElements( quint64 window ) +void WindowCtrlLin::displayWindowElements( quint64 window ) { QString name = atomName( m_display, window ); emit signalConsole( QString( "Atom name: %1" ).arg( name ) ); @@ -282,7 +282,7 @@ void WindowCtrlUnix::displayWindowElements( quint64 window ) /* * Get the Thunderbird window ID */ -quint64 WindowCtrlUnix::getWinId() +quint64 WindowCtrlLin::getWinId() { return m_tb_window; } @@ -291,7 +291,7 @@ quint64 WindowCtrlUnix::getWinId() /* * Get the Thunderbird window IDs */ -QList< quint64 > WindowCtrlUnix::getWinIds() +QList< quint64 > WindowCtrlLin::getWinIds() { return m_tb_windows; } @@ -300,7 +300,7 @@ QList< quint64 > WindowCtrlUnix::getWinIds() /* * Minimize a window */ -void WindowCtrlUnix::minimizeWindow( quint64 window, int hide ) +void WindowCtrlLin::minimizeWindow( quint64 window, int hide ) { if( !isThunderbird( getPpid() ) ) { @@ -317,7 +317,7 @@ void WindowCtrlUnix::minimizeWindow( quint64 window, int hide ) /* * Hide window to system tray */ -void WindowCtrlUnix::hideWindow( quint64 window, int set ) +void WindowCtrlLin::hideWindow( quint64 window, int set ) { switch( m_minimize_type ) { @@ -344,7 +344,7 @@ void WindowCtrlUnix::hideWindow( quint64 window, int set ) /* * Normalize a window */ -void WindowCtrlUnix::normalizeWindow( quint64 window ) +void WindowCtrlLin::normalizeWindow( quint64 window ) { if( !isThunderbird( getPpid() ) ) { @@ -380,7 +380,7 @@ void WindowCtrlUnix::normalizeWindow( quint64 window ) /* * Delete the window */ -void WindowCtrlUnix::deleteWindow( quint64 window ) +void WindowCtrlLin::deleteWindow( quint64 window ) { if( !isThunderbird( getPpid() ) ) { @@ -416,7 +416,7 @@ void WindowCtrlUnix::deleteWindow( quint64 window ) /* * Hide window to system tray */ -void WindowCtrlUnix::hideWindowEvent( quint64 window, bool set ) +void WindowCtrlLin::hideWindowEvent( quint64 window, bool set ) { if( !isThunderbird( getPpid() ) ) { @@ -445,7 +445,7 @@ void WindowCtrlUnix::hideWindowEvent( quint64 window, bool set ) /* * Remove window from taskbar */ -void WindowCtrlUnix::hideWindowAtom( quint64 window, bool set ) +void WindowCtrlLin::hideWindowAtom( quint64 window, bool set ) { if( !isThunderbird( getPpid() ) ) { @@ -532,7 +532,7 @@ void WindowCtrlUnix::hideWindowAtom( quint64 window, bool set ) /* * Get the X11 window list */ -QList< WindowCtrlUnix::WindowItem > WindowCtrlUnix::listXWindows( Display *display, quint64 window, int level ) +QList< WindowCtrlLin::WindowItem > WindowCtrlLin::listXWindows( Display *display, quint64 window, int level ) { Window root; Window parent; @@ -558,7 +558,7 @@ QList< WindowCtrlUnix::WindowItem > WindowCtrlUnix::listXWindows( Display *dis /* * Send a X event */ -void WindowCtrlUnix::sendEvent( quint64 window, const char* msg, long action, +void WindowCtrlLin::sendEvent( quint64 window, const char* msg, long action, long prop1, long prop2, long prop3, long prop4 ) { Window win = static_cast( window ); @@ -589,7 +589,7 @@ void WindowCtrlUnix::sendEvent( quint64 window, const char* msg, long action, /* * Get the title of the window */ -QString WindowCtrlUnix::atomName( Display *display, quint64 window ) +QString WindowCtrlLin::atomName( Display *display, quint64 window ) { char prop_name[] = "_NET_WM_NAME"; Atom prop = XInternAtom( display, prop_name, True ); @@ -621,7 +621,7 @@ QString WindowCtrlUnix::atomName( Display *display, quint64 window ) /* * Get the _NET_WM_STATE of the window */ -QStringList WindowCtrlUnix::atomNetWmState( Display *display, quint64 window ) +QStringList WindowCtrlLin::atomNetWmState( Display *display, quint64 window ) { char prop_name[] = "_NET_WM_STATE"; Atom prop = XInternAtom( display, prop_name, True ); @@ -664,7 +664,7 @@ QStringList WindowCtrlUnix::atomNetWmState( Display *display, quint64 window /* * Get the WM_STATE of the window */ -long WindowCtrlUnix::atomWmState( Display *display, quint64 window ) +long WindowCtrlLin::atomWmState( Display *display, quint64 window ) { char prop_name[] = "WM_STATE"; Atom prop = XInternAtom( display, prop_name, False ); @@ -694,7 +694,7 @@ long WindowCtrlUnix::atomWmState( Display *display, quint64 window ) /* * Get the type of the window */ -QStringList WindowCtrlUnix::atomWindowType( Display *display, quint64 window ) +QStringList WindowCtrlLin::atomWindowType( Display *display, quint64 window ) { char prop_name[] = "_NET_WM_WINDOW_TYPE"; Atom prop = XInternAtom( display, prop_name, True ); diff --git a/app/SysTray-X/windowctrl-unix.h b/app/SysTray-X/windowctrl-lin.h similarity index 96% rename from app/SysTray-X/windowctrl-unix.h rename to app/SysTray-X/windowctrl-lin.h index 9706fb2..274c92b 100644 --- a/app/SysTray-X/windowctrl-unix.h +++ b/app/SysTray-X/windowctrl-lin.h @@ -1,8 +1,8 @@ #include -#ifdef Q_OS_UNIX +#ifdef Q_OS_LINUX -#ifndef WINDOWCTRLUNIX_H -#define WINDOWCTRLUNIX_H +#ifndef WINDOWCTRLLIN_H +#define WINDOWCTRLLIN_H /* * Local includes @@ -25,9 +25,9 @@ typedef struct _XDisplay Display; /** - * @brief The WindowCtrlUnix class. + * @brief The WindowCtrlLin class. */ -class WindowCtrlUnix : public QObject +class WindowCtrlLin : public QObject { Q_OBJECT @@ -119,11 +119,11 @@ class WindowCtrlUnix : public QObject public: /** - * @brief WindowCtrlUnix. Constructor. + * @brief WindowCtrlLin. Constructor. * * @param parent My parent. */ - explicit WindowCtrlUnix( QObject *parent = nullptr ); + explicit WindowCtrlLin( QObject *parent = nullptr ); /** * @brief setWindowState. Set the window state. @@ -382,6 +382,6 @@ class WindowCtrlUnix : public QObject int m_window_state; }; -#endif // WINDOWCTRLUNIX_H +#endif // WINDOWCTRLLIN_H -#endif // Q_OS_UNIX +#endif // Q_OS_LINUX diff --git a/app/SysTray-X/windowctrl-mac.cpp b/app/SysTray-X/windowctrl-mac.cpp new file mode 100644 index 0000000..15549b5 --- /dev/null +++ b/app/SysTray-X/windowctrl-mac.cpp @@ -0,0 +1,219 @@ +#include "windowctrl-mac.h" + +#ifdef Q_OS_MACOS + +/* + * System includes + */ +#include + + +/* + * Constructor + */ +WindowCtrlMac::WindowCtrlMac( QObject *parent ) : QObject( parent ) +{ + /* + * Initialize + */ + m_tb_window = 0; + m_tb_windows = QList< quint64 >(); + m_window_state = Preferences::STATE_UNKNOWN; +} + + +/* + * Set the minimize type + */ +void WindowCtrlMac::setMinimizeType( Preferences::MinimizeType type ) +{ + m_minimize_type = type; +} + + +/* + * Set the window state. + */ +void WindowCtrlMac::setWindowState( int state ) +{ + m_window_state = state; +} + + +/** + * @brief getWindowState. Get the window state. + * + * @return The state. + */ +int WindowCtrlMac::getWindowState() const +{ + return m_window_state; +} + + +/* + * Get the minimize type + */ +Preferences::MinimizeType WindowCtrlMac::getMinimizeType() const +{ + return m_minimize_type; +} + + +/* + * Get the parent pid of SysTray-X, TB hopefully + */ +qint64 WindowCtrlMac::getPpid() const +{ + return getppid(); +} + + +/* + * Is the pid from thunderbird + */ +bool WindowCtrlMac::isThunderbird( qint64 pid ) const +{ + return getProcessName( pid ).contains( "thunderbird", Qt::CaseInsensitive ); +} + + +/* + * Get the process name + */ +QString WindowCtrlMac::getProcessName( qint64 pid ) const +{ + QString process_name = QString( "/proc/%1/exe" ).arg( pid ); + QFileInfo process( process_name ); + + return process.canonicalFilePath(); +} + + +/* + * Find window(s) by title + */ +bool WindowCtrlMac::findWindow( const QString& title ) +{ + return false; +} + + +/* + * Find a window by PID + */ +void WindowCtrlMac::findWindow( qint64 pid ) +{ +} + + +/* + * Display window atoms + */ +void WindowCtrlMac::displayWindowElements( const QString& title ) +{ +} + + +/* + * Display window atoms + */ +void WindowCtrlMac::displayWindowElements( quint64 window ) +{ +} + + +/* + * Get the Thunderbird window ID + */ +quint64 WindowCtrlMac::getWinId() +{ + return m_tb_window; +} + + +/* + * Get the Thunderbird window IDs + */ +QList< quint64 > WindowCtrlMac::getWinIds() +{ + return m_tb_windows; +} + + +/* + * Minimize a window + */ +void WindowCtrlMac::minimizeWindow( quint64 window, int hide ) +{ + if( !isThunderbird( getPpid() ) ) + { + return; + } + + hideWindow( window, hide ); + + // minimize() here +} + + +/* + * Hide window to system tray + */ +void WindowCtrlMac::hideWindow( quint64 window, int set ) +{ + hideWindowEvent( window, set ); +} + + +/* + * Normalize a window + */ +void WindowCtrlMac::normalizeWindow( quint64 window ) +{ + if( !isThunderbird( getPpid() ) ) + { + return; + } + + hideWindow( window, false ); + + // normalize here +} + + +/* + * Delete the window + */ +void WindowCtrlMac::deleteWindow( quint64 window ) +{ + if( !isThunderbird( getPpid() ) ) + { + return; + } + + // delete here +} + + +/* + * Hide window to system tray + */ +void WindowCtrlMac::hideWindowEvent( quint64 window, bool set ) +{ + if( !isThunderbird( getPpid() ) ) + { + return; + } + + if( set ) + { + // minimize + } + else + { + // normalize + } +} + +#endif // Q_OS_UNIX diff --git a/app/SysTray-X/windowctrl-mac.h b/app/SysTray-X/windowctrl-mac.h new file mode 100644 index 0000000..5589c2d --- /dev/null +++ b/app/SysTray-X/windowctrl-mac.h @@ -0,0 +1,309 @@ +#include +#ifdef Q_OS_MACOS + +#ifndef WINDOWCTRLMAC_H +#define WINDOWCTRLMAC_H + +/* + * Local includes + */ +#include "preferences.h" + +/* + * System includes + */ + +/* + * Qt includes + */ +#include +#include + +/* + * Predefines + */ + + +/** + * @brief The WindowCtrlMac class. + */ +class WindowCtrlMac : public QObject +{ + Q_OBJECT + + public: + + /* + * Window types + */ + enum WindowType + { + TYPE_UNKNOWN = 0, + TYPE_DESKTOP, + TYPE_DOCK, + TYPE_TOOLBAR, + TYPE_MENU, + TYPE_UTILITY, + TYPE_SPLASH, + TYPE_DIALOG, + TYPE_DROPDOWN_MENU, + TYPE_POPUP_MENU, + TYPE_TOOLTIP, + TYPE_NOTIFICATION, + TYPE_COMBO, + TYPE_DND, + TYPE_NORMAL + }; + + /* + * State actions + */ + enum StateActions + { + _NET_WM_STATE_REMOVE = 0, + _NET_WM_STATE_ADD, + _NET_WM_STATE_TOGGLE + }; + + /* + * Window states + */ + enum WindowState + { + STATE_MODAL = 0, + STATE_STICKY, + STATE_MAXIMIZED_VERT, + STATE_MAXIMIZED_HORZ, + STATE_SHADED, + STATE_SKIP_TASKBAR, + STATE_SKIP_PAGER, + STATE_HIDDEN, + STATE_FULLSCREEN, + STATE_ABOVE, + STATE_BELOW, + STATE_DEMANDS_ATTENTION + }; + + const QStringList WindowStates = { + "_NET_WM_STATE_MODAL", + "_NET_WM_STATE_STICKY", + "_NET_WM_STATE_MAXIMIZED_VERT", + "_NET_WM_STATE_MAXIMIZED_HORZ", + "_NET_WM_STATE_SHADED", + "_NET_WM_STATE_SKIP_TASKBAR", + "_NET_WM_STATE_SKIP_PAGER", + "_NET_WM_STATE_HIDDEN", + "_NET_WM_STATE_FULLSCREEN", + "_NET_WM_STATE_ABOVE", + "_NET_WM_STATE_BELOW", + "_NET_WM_STATE_DEMANDS_ATTENTION" + }; + + /* + * Window list item + */ + class WindowItem + { + public: + + WindowItem( quint64 win, int lev ) + { + window = win; + level = lev; + } + + quint64 window; + int level; + }; + + public: + + /** + * @brief WindowCtrlMac. Constructor. + * + * @param parent My parent. + */ + explicit WindowCtrlMac( QObject *parent = nullptr ); + + /** + * @brief setWindowState. Set the window state. + * + * @param state The state. + */ + void setWindowState( int state ); + + /** + * @brief getWindowState. Get the window state. + * + * @return The state. + */ + int getWindowState() const; + + /** + * @brief setMinimizeType + * + * @param type Set the minimize type. + */ + void setMinimizeType( Preferences::MinimizeType type ); + + /** + * @brief getMinimizeType + * + * @return The minimize type. + */ + Preferences::MinimizeType getMinimizeType() const; + + /** + * @brief getPpid. Get the parent process id. + * + * @return The ppid + */ + qint64 getPpid() const; + + /** + * @brief isThunderbird. Is this a thunderbird pid. + * + * @param pid The process Id to check. + * + * @return True if this is thunderbird. + */ + bool isThunderbird( qint64 pid ) const; + + /** + * @brief getProcessName. Get the name of the proces by pid. + * + * @param pid The process Id. + * + * @return The process name. + */ + QString getProcessName( qint64 pid ) const; + + /** + * @brief findWindow. Find window by (sub)title. + * + * @param title The title to find. + * + * @return State of the find. + */ + bool findWindow( const QString& title ); + + /** + * @brief findWindow. Find window of a process. + * + * @param pid The process id. + */ + void findWindow( qint64 pid ); + + /** + * @brief displayWindowElements. Display window elements (atoms). + * + * @param title The window title to find. + */ + void displayWindowElements( const QString& title ); + + /** + * @brief displayWindowElements. Display window elements (atoms). + * + * @param window The window. + */ + void displayWindowElements( quint64 window ); + + /** + * @brief getWinId. Get the Thunderbird window ID. + * + * @return The window ID. + */ + quint64 getWinId(); + + /** + * @brief getWinIds. Get the Thunderbird window IDs. + * + * @return The list of window ID. + */ + QList< quint64 > getWinIds(); + + /** + * @brief minimizeWindow. Minimize window. + * + * @param window The window. + * @param hide Hide from taskbar. + */ + void minimizeWindow( quint64 window, int hide ); + + /** + * @brief normalizeWindow. Normalize window. + * + * @param window The window. + */ + void normalizeWindow( quint64 window ); + + /** + * @brief hideWindow. Hide a window from the taskbar. + * + * @param window The window. + * @param set The state of the window. + */ + void hideWindow( quint64 window, int set ); + + /** + * @brief deleteWindow. Delete the window. + * + * @param window The window. + */ + void deleteWindow( quint64 window ); + + private: + + /** + * @brief hideWindowEvent. Hide a window from the taskbar using an event message. + * + * @param window The window. + * @param set The state of the window. + */ + void hideWindowEvent( quint64 window, bool set ); + + signals: + + /** + * @brief signalConsole. Send a console message. + * + * @param message The message. + */ + void signalConsole( QString message ); + + private: + + /** + * @brief m_screen. The screen number. + */ + int m_screen; + + /** + * @brief m_root_window. The root window. + */ + quint64 m_root_window; + + /** + * @brief m_tb_window. The Thunderbird window. + */ + quint64 m_tb_window; + + /** + * @brief m_tb_windows. The Thunderbird windows (used by title search). + */ + QList< quint64 > m_tb_windows; + + /** + * @brief m_minimize_type. Minimize type. + */ + Preferences::MinimizeType m_minimize_type; + + /** + * @brief m_window_state. State of the TB window. + */ + int m_window_state; +}; + +#endif // WindowCtrlMac_H + +#endif // Q_OS_MACOS diff --git a/app/SysTray-X/windowctrl.cpp b/app/SysTray-X/windowctrl.cpp index 148648a..234929e 100644 --- a/app/SysTray-X/windowctrl.cpp +++ b/app/SysTray-X/windowctrl.cpp @@ -19,10 +19,12 @@ * Constructor */ WindowCtrl::WindowCtrl( Preferences* pref, QObject *parent ) -#ifdef Q_OS_UNIX - : WindowCtrlUnix( parent ) +#ifdef Q_OS_LINUX + : WindowCtrlLin( parent ) #elif defined Q_OS_WIN : WindowCtrlWin( parent ) +#elif defined Q_OS_MACOS + : WindowCtrlMac( parent ) #else : public QObject #endif diff --git a/app/SysTray-X/windowctrl.h b/app/SysTray-X/windowctrl.h index dc531eb..11fa4c6 100644 --- a/app/SysTray-X/windowctrl.h +++ b/app/SysTray-X/windowctrl.h @@ -3,14 +3,18 @@ #include -#ifdef Q_OS_UNIX +#ifdef Q_OS_LINUX #include "windowctrl-unix.h" -#endif // Q_OS_UNIX +#endif // Q_OS_LINUX #ifdef Q_OS_WIN #include "windowctrl-win.h" #endif // Q_OS_WIN +#ifdef Q_OS_MACOS +#include "windowctrl-mac.h" +#endif // Q_OS_MACOS + /* * Predefines @@ -21,10 +25,12 @@ class Preferences; /** * @brief The WindowCtrl class. */ -#ifdef Q_OS_UNIX -class WindowCtrl : public WindowCtrlUnix +#ifdef Q_OS_LINUX +class WindowCtrl : public WindowCtrlLin #elif defined Q_OS_WIN class WindowCtrl : public WindowCtrlWin +#elif defined Q_OS_MACOS +class WindowCtrl : public WindowCtrlMac #else class WindowCtrl : public QObject #endif @@ -34,7 +40,7 @@ class WindowCtrl : public QObject public: /** - * @brief WindowCtrlUnix. Constructor. + * @brief WindowCtrlLin. Constructor. * * @param parent My parent. */