diff --git a/app/SysTray-X/SysTray-X.pro b/app/SysTray-X/SysTray-X.pro index 7890ea9..1fe873b 100644 --- a/app/SysTray-X/SysTray-X.pro +++ b/app/SysTray-X/SysTray-X.pro @@ -6,10 +6,6 @@ QT += core gui -unix: { - QT += x11extras -} - greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = SysTray-X @@ -165,7 +161,8 @@ SOURCES += \ debugwidget.cpp \ preferencesdialog.cpp \ preferences.cpp \ - windowctrl.cpp + windowctrl.cpp \ + container.cpp unix: { SOURCES += \ windowctrl-unix.cpp @@ -182,7 +179,9 @@ HEADERS += \ debugwidget.h \ preferencesdialog.h \ preferences.h \ - windowctrl.h + windowctrl.h \ + container.h \ + options.h unix: { HEADERS += \ windowctrl-unix.h diff --git a/app/SysTray-X/container.cpp b/app/SysTray-X/container.cpp new file mode 100644 index 0000000..eb0d241 --- /dev/null +++ b/app/SysTray-X/container.cpp @@ -0,0 +1,30 @@ +#include "container.h" +#include "ui_container.h" + +/* + * Qt includes + */ +#include + +/* + * Constructor + */ +Container::Container( QWidget *parent ) : QWidget( parent ) +{ + /* + * Construct conatainer + */ + QVBoxLayout* layout = new QVBoxLayout( this ); + setLayout( layout ); + + /* + * Set properties + */ + setWindowIcon( QIcon( ":/files/icons/Thunderbird.png" ) ); +} + + +void Container::setWidget( QWidget* widget ) +{ + layout()->addWidget( widget ); +} diff --git a/app/SysTray-X/container.h b/app/SysTray-X/container.h new file mode 100644 index 0000000..13f9f45 --- /dev/null +++ b/app/SysTray-X/container.h @@ -0,0 +1,40 @@ +#ifndef CONTAINER_H +#define CONTAINER_H + +/* + * Qt includes + */ +#include + +/* + * Predefines + */ +class QVBoxLayout; + +/** + * @brief The Container class. Class to hold the Thunderbird window. + */ +class Container : public QWidget +{ + Q_OBJECT + + public: + + /** + * @brief Container. Constructor. + * + * @param parent My parent. + */ + Container( QWidget *parent = nullptr ); + + /** + * @brief setWidget. Set the container widget. + * + * @param widget The widget. + */ + void setWidget( QWidget* widget ); + + private: +}; + +#endif // CONTAINER_H diff --git a/app/SysTray-X/options.h b/app/SysTray-X/options.h new file mode 100644 index 0000000..89eab79 --- /dev/null +++ b/app/SysTray-X/options.h @@ -0,0 +1,9 @@ +#ifndef OPTIONS_H +#define OPTIONS_H + +/* + * Use embedded container + */ +#define ENABLE_CONTAINER + +#endif // OPTIONS_H diff --git a/app/SysTray-X/systrayx.cpp b/app/SysTray-X/systrayx.cpp index f061a9c..551edef 100644 --- a/app/SysTray-X/systrayx.cpp +++ b/app/SysTray-X/systrayx.cpp @@ -8,6 +8,7 @@ #include "systrayxlink.h" #include "systrayxicon.h" #include "windowctrl.h" +#include "container.h" /* * Qt includes @@ -18,7 +19,7 @@ /* * Constants */ -const QString SysTrayX::JSON_PREF_REQUEST = "{\"preferences\":{}}"; +const QString SysTrayX::JSON_PREF_REQUEST = "{\"preferences\":{}}"; /* @@ -34,7 +35,12 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent ) /* * Setup window control */ - m_win_ctrl = new WindowCtrl( m_preferences ); + m_tb_container = new Container(); + + /* + * Setup window control + */ + m_win_ctrl = new WindowCtrl( m_tb_container, m_preferences ); /* * Setup the link @@ -132,7 +138,7 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent ) /* * Send a preferences request */ -void SysTrayX::getPreferences() +void SysTrayX::getPreferences() { /* * Request preferences from add-on @@ -145,7 +151,7 @@ void SysTrayX::getPreferences() /* * Create the actions for the system tray icon menu */ -void SysTrayX::createActions() +void SysTrayX::createActions() { /* m_minimizeAction = new QAction(tr("Mi&nimize"), this); @@ -173,7 +179,7 @@ void SysTrayX::createActions() /* * Create the system tray icon */ -void SysTrayX::createTrayIcon() +void SysTrayX::createTrayIcon() { /* * Setup menu actions @@ -212,7 +218,7 @@ void SysTrayX::createTrayIcon() /* * Quit the app */ -void SysTrayX::slotShutdown() +void SysTrayX::slotShutdown() { /* * Let's quit diff --git a/app/SysTray-X/systrayx.h b/app/SysTray-X/systrayx.h index ad787c5..6846133 100644 --- a/app/SysTray-X/systrayx.h +++ b/app/SysTray-X/systrayx.h @@ -23,6 +23,7 @@ class PreferencesDialog; class SysTrayXIcon; class SysTrayXLink; class WindowCtrl; +class Container; /** * @brief The SysTrayX class @@ -49,17 +50,17 @@ class SysTrayX : public QObject /** * @brief SysTrayX::getPreferences */ - void getPreferences(); + void getPreferences(); /** * @brief createTrayIcon. Create the system tray icon. */ - void createTrayIcon(); + void createTrayIcon(); /** * @brief createActions. Create the menu actions. */ - void createActions(); + void createActions(); signals: @@ -68,26 +69,26 @@ class SysTrayX : public QObject * * @param message */ - void signalWriteMessage( QByteArray message ); + void signalWriteMessage( QByteArray message ); private slots: /** * @brief slotShutdown Shutdown the app. */ - void slotShutdown(); + void slotShutdown(); private: /** * @brief m_preferences. Pointer to the preferences storage. */ - Preferences *m_preferences; + Preferences* m_preferences; /** * @brief m_debug */ - DebugWidget *m_debug; + DebugWidget* m_debug; /** * @brief m_win_ctrl. Pointer to the window control. @@ -97,29 +98,34 @@ class SysTrayX : public QObject /** * @brief m_link. Pointer to the link object. */ - SysTrayXLink *m_link; + SysTrayXLink* m_link; /** * @brief m_pref_dialog. Pointer to the preferences dialog. */ - PreferencesDialog *m_pref_dialog; + PreferencesDialog* m_pref_dialog; /** * @brief m_tray_icon. Pointer to the system tray icon. */ - SysTrayXIcon *m_tray_icon; + SysTrayXIcon* m_tray_icon; /** * @brief m_tray_icon_menu. Pointer to the tray icon menu. */ - QMenu *m_tray_icon_menu; + QMenu* m_tray_icon_menu; /** * @brief m_xxxx_action. Pointer to the menu actions. */ - QAction *m_pref_action; - QAction *m_quit_action; - QAction *m_showhide_action; + QAction* m_pref_action; + QAction* m_quit_action; + QAction* m_showhide_action; + + /** + * @brief m_tb_cotainer. Pointer to the Thunderbird container. + */ + Container* m_tb_container; }; #endif // SYSTRAYX_H diff --git a/app/SysTray-X/windowctrl-unix.cpp b/app/SysTray-X/windowctrl-unix.cpp index edeeeb4..1b0393b 100644 --- a/app/SysTray-X/windowctrl-unix.cpp +++ b/app/SysTray-X/windowctrl-unix.cpp @@ -8,12 +8,17 @@ #include #include - /* * Constructor */ WindowCtrlUnix::WindowCtrlUnix( QObject *parent ) : QObject( parent ) { + /* + * Initialize + */ + m_tb_windows = QList< quint64 >(); + m_tb_geometries = QList< QRect >(); + /* * Get the base display and window */ @@ -44,6 +49,17 @@ bool WindowCtrlUnix::findWindow( const QString& title ) * Store the XID */ m_tb_windows.append( static_cast( win.window ) ); + + /* + * Store geometry + */ + XWindowAttributes attr; + XGetWindowAttributes( m_display, win.window, &attr ); + + Window child; + XTranslateCoordinates( m_display, win.window, m_root_window, 0, 0, &attr.x, &attr.y, &child); + + m_tb_geometries.append( QRect( attr.x, attr.y, attr.width, attr.height ) ); } } } @@ -153,6 +169,15 @@ QList< quint64 > WindowCtrlUnix::getWinIds() } +/* + * Get the Thunderbird window geometries + */ +QList< QRect > WindowCtrlUnix::getWinGeos() +{ + return m_tb_geometries; +} + + /* * Minimize a window */ diff --git a/app/SysTray-X/windowctrl-unix.h b/app/SysTray-X/windowctrl-unix.h index c21d7f0..a8cee1d 100644 --- a/app/SysTray-X/windowctrl-unix.h +++ b/app/SysTray-X/windowctrl-unix.h @@ -18,6 +18,7 @@ * Qt includes */ #include +#include /** * @brief The WindowCtrlUnix class. @@ -133,6 +134,13 @@ class WindowCtrlUnix : public QObject */ QList< quint64 > getWinIds(); + /** + * @brief getWinGeos. Get the Thunderbird window geometries. + * + * @return The list of window geometries. + */ + QList< QRect > getWinGeos(); + /** * @brief minimizeWindow. Minimize window. * @@ -259,6 +267,11 @@ class WindowCtrlUnix : public QObject * @brief m_tb_window. The Thunderbird windows. */ QList< quint64 > m_tb_windows; + + /** + * @brief m_tb_geometries. The Thunderbird window geometries. + */ + QList< QRect > m_tb_geometries; }; #endif // WINDOWCTRLUNIX_H diff --git a/app/SysTray-X/windowctrl.cpp b/app/SysTray-X/windowctrl.cpp index 1640eb7..55c55d6 100644 --- a/app/SysTray-X/windowctrl.cpp +++ b/app/SysTray-X/windowctrl.cpp @@ -12,12 +12,13 @@ /* * System includes */ +#include "container.h" #include "preferences.h" /* * Constructor */ -WindowCtrl::WindowCtrl( Preferences* pref, QObject *parent ) : +WindowCtrl::WindowCtrl( Container* container, Preferences* pref, QObject *parent ) : #ifdef Q_OS_UNIX WindowCtrlUnix( parent ) #elif defined Q_OS_WIN @@ -26,6 +27,11 @@ WindowCtrl::WindowCtrl( Preferences* pref, QObject *parent ) : public QObject #endif { + /* + * Store the containwe + */ + m_container = container; + /* * Store preferences */ @@ -45,11 +51,10 @@ void WindowCtrl::slotWindowTest1() // Do something. - displayWindowElements( "- Mozilla Thunderbird" ); +// displayWindowElements( "- Mozilla Thunderbird" ); // findWindow( 4313 ); - -// captureWindow( "Debugging with Firefox Developer Tools - Mozilla Thunderbird" ); + captureWindow( "Debugging with Firefox Developer Tools - Mozilla Thunderbird" ); emit signalConsole("Test 1 done"); } @@ -61,6 +66,11 @@ void WindowCtrl::slotWindowTest2() // Do something. + + m_tb_window->setParent( nullptr ); + m_tb_window->setFlags( Qt::Window ); + + /* * Disconnect container? */ @@ -86,24 +96,26 @@ void WindowCtrl::slotWindowTest3() bool WindowCtrl::captureWindow( const QString& title ) { - Q_UNUSED( title ) - -#ifdef FF_NEET - - unsigned long WinId; if( !findWindow( title ) ) { return false; } +#ifdef ENABLE_CONTAINER + /* * Wrap Thunderbird window */ - m_tb_window = QWindow::fromWinId( WinId ); - m_tb_window->parent(); - + m_tb_window = QWindow::fromWinId( getWinIds()[ 0 ] ); m_tb_container = QWidget::createWindowContainer( m_tb_window ); + /* + * Integrate the window container + */ + m_container->setWidget( m_tb_container ); + m_container->setGeometry( getWinGeos()[ 0 ] ); + m_container->show(); + #endif return true; @@ -123,7 +135,29 @@ void WindowCtrl::slotWindowTitle( QString title ) /* * Get the window IDs */ - findWindow( title ); + if( !findWindow( title ) ) + { + return; + } + +#ifdef ENABLE_CONTAINER + + /* + * Wrap Thunderbird window + */ + m_tb_window = QWindow::fromWinId( getWinIds()[ 0 ] ); + m_tb_window->parent(); + + m_tb_container = QWidget::createWindowContainer( m_tb_window ); + + /* + * Integrate the container + */ + m_container->setWidget( m_tb_container ); + m_container->setGeometry( getWinGeos()[ 0 ] ); + m_container->show(); + +#endif } diff --git a/app/SysTray-X/windowctrl.h b/app/SysTray-X/windowctrl.h index e1f531f..d974469 100644 --- a/app/SysTray-X/windowctrl.h +++ b/app/SysTray-X/windowctrl.h @@ -1,8 +1,16 @@ #ifndef WINDOWCTRL_H #define WINDOWCTRL_H +/* + * Qt includes + */ #include +/* + * Local includes + */ +#include "options.h" + #ifdef Q_OS_UNIX #include "windowctrl-unix.h" #endif // Q_OS_UNIX @@ -11,11 +19,11 @@ #include "windowctrl-win.h" #endif // Q_OS_WIN - /* * Predefines */ class QWindow; +class Container; class Preferences; /** @@ -38,7 +46,7 @@ class WindowCtrl : public QObject * * @param parent My parent. */ - explicit WindowCtrl( Preferences* pref, QObject *parent = nullptr ); + explicit WindowCtrl( Container* container, Preferences* pref, QObject *parent = nullptr ); /** * @brief captureWindow. Capture the TB window. @@ -94,6 +102,11 @@ class WindowCtrl : public QObject private: + /** + * @brief m_container. Pointer to the container. + */ + Container* m_container; + /** * @brief m_pref. Pointer to the preferences storage. */