From 5b1a2d670af7c28c84cbd711d47fa277f31b1774 Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Mon, 9 Mar 2020 23:23:02 +0100 Subject: [PATCH] Check parent executable name --- app/SysTray-X/windowctrl-win.cpp | 22 ++++++++++++++++------ app/SysTray-X/windowctrl-win.h | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/app/SysTray-X/windowctrl-win.cpp b/app/SysTray-X/windowctrl-win.cpp index 8e32c3d..c6457ae 100644 --- a/app/SysTray-X/windowctrl-win.cpp +++ b/app/SysTray-X/windowctrl-win.cpp @@ -13,6 +13,7 @@ * Qt includes */ #include +#include /* * Statics @@ -65,12 +66,21 @@ qint64 WindowCtrlWin::getPpid() } +/* + * Is the pid from thunderbird + */ +bool WindowCtrlWin::isThunderbird( qint64 pid ) +{ + return getProcessName( pid ).contains( "thunderbird", Qt::CaseInsensitive ); +} + + /* * Get the process name */ -QString WindowCtrl::getProcessName( qint64 pid ) +QString WindowCtrlWin::getProcessName( qint64 pid ) { - HANDLE proc = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, getPpid() ); + HANDLE proc = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, pid ); char name[ 256 ]; GetModuleBaseNameA( proc, NULL, name, 256); @@ -212,7 +222,7 @@ QList< quint64 > WindowCtrlWin::getWinIds() */ void WindowCtrlWin::minimizeWindow( quint64 window, bool hide ) { - if( !window ) + if( !isThunderbird( getPpid() ) ) { return; } @@ -231,7 +241,7 @@ void WindowCtrlWin::minimizeWindow( quint64 window, bool hide ) */ void WindowCtrlWin::normalizeWindow( quint64 window ) { - if( !window ) + if( !isThunderbird( getPpid() ) ) { return; } @@ -246,7 +256,7 @@ void WindowCtrlWin::normalizeWindow( quint64 window ) */ void WindowCtrlWin::hideWindow( quint64 window, bool state ) { - if( !window ) + if( !isThunderbird( getPpid() ) ) { return; } @@ -278,7 +288,7 @@ void WindowCtrlWin::hideWindow( HWND hwnd ) */ void WindowCtrlWin::deleteWindow( quint64 window ) { - if( !window ) + if( !isThunderbird( getPpid() ) ) { return; } diff --git a/app/SysTray-X/windowctrl-win.h b/app/SysTray-X/windowctrl-win.h index 5d97264..bfd6010 100644 --- a/app/SysTray-X/windowctrl-win.h +++ b/app/SysTray-X/windowctrl-win.h @@ -45,6 +45,24 @@ class WindowCtrlWin : public QObject */ qint64 getPpid(); + /** + * @brief isThunderbird. Is this a thunderbird pid. + * + * @param pid The process Id to check. + * + * @return True if this is thunderbird. + */ + bool isThunderbird( qint64 pid ); + + /** + * @brief getProcessName. Get the name of the proces by pid. + * + * @param pid The process Id. + * + * @return The process name. + */ + QString getProcessName( qint64 pid ); + /** * @brief findWindow. Find window by title. *