From 43a8cef1979eeecd49dec3c054df0d6d945df0e7 Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Tue, 10 Mar 2020 00:17:23 +0100 Subject: [PATCH] Check parent executable name --- app/SysTray-X/windowctrl-unix.cpp | 29 +++++++++++++++++++++++++---- app/SysTray-X/windowctrl-unix.h | 19 +++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/app/SysTray-X/windowctrl-unix.cpp b/app/SysTray-X/windowctrl-unix.cpp index f69545b..314fabf 100644 --- a/app/SysTray-X/windowctrl-unix.cpp +++ b/app/SysTray-X/windowctrl-unix.cpp @@ -40,6 +40,27 @@ qint64 WindowCtrlUnix::getPpid() } +/* + * Is the pid from thunderbird + */ +bool WindowCtrlUnix::isThunderbird( qint64 pid ) +{ + return getProcessName( pid ).contains( "thunderbird", Qt::CaseInsensitive ); +} + + +/* + * Get the process name + */ +QString WindowCtrlUnix::getProcessName( qint64 pid ) +{ + QString process_name = QString( "/proc/%1/exe" ).arg( pid ); + QFileInfo process( process_name ); + + return process.canonicalFilePath(); +} + + /* * Find window(s) by title */ @@ -237,7 +258,7 @@ QList< quint64 > WindowCtrlUnix::getWinIds() */ void WindowCtrlUnix::minimizeWindow( quint64 window, bool hide ) { - if( !window ) + if( !isThunderbird( getPpid() ) ) { return; } @@ -259,7 +280,7 @@ void WindowCtrlUnix::minimizeWindow( quint64 window, bool hide ) */ void WindowCtrlUnix::normalizeWindow( quint64 window ) { - if( !window ) + if( !isThunderbird( getPpid() ) ) { return; } @@ -288,7 +309,7 @@ void WindowCtrlUnix::normalizeWindow( quint64 window ) */ void WindowCtrlUnix::hideWindow( quint64 window, bool set ) { - if( !window ) + if( !isThunderbird( getPpid() ) ) { return; } @@ -375,7 +396,7 @@ void WindowCtrlUnix::hideWindow( quint64 window, bool set ) */ void WindowCtrlUnix::deleteWindow( quint64 window ) { - if( !window ) + if( !isThunderbird( getPpid() ) ) { return; } diff --git a/app/SysTray-X/windowctrl-unix.h b/app/SysTray-X/windowctrl-unix.h index bdcfdba..1db14a9 100644 --- a/app/SysTray-X/windowctrl-unix.h +++ b/app/SysTray-X/windowctrl-unix.h @@ -17,6 +17,7 @@ * Qt includes */ #include +#include /* * Predefines @@ -121,6 +122,24 @@ class WindowCtrlUnix : 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 (sub)title. *