allwo passing of a window id too
This commit is contained in:
parent
87f6bdfcc5
commit
a2cc0dbb9c
63
src/main.cpp
63
src/main.cpp
|
@ -19,10 +19,31 @@
|
||||||
using namespace Snore;
|
using namespace Snore;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void bringToFront(QString pid, Notification noti)
|
|
||||||
|
void bringWindowToFront( WId _wid) {
|
||||||
|
snoreDebug( SNORE_DEBUG ) << _wid;
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
HWND wid = (HWND)_wid;
|
||||||
|
HWND hwndActiveWin = GetForegroundWindow();
|
||||||
|
int idActive = GetWindowThreadProcessId( hwndActiveWin, NULL );
|
||||||
|
|
||||||
|
if ( AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) )
|
||||||
|
{
|
||||||
|
SetForegroundWindow( wid );
|
||||||
|
SetFocus( wid );
|
||||||
|
FlashWindow( wid, TRUE );
|
||||||
|
AttachThreadInput( GetCurrentThreadId(), idActive, FALSE );
|
||||||
|
} else {
|
||||||
|
// try it anyhow
|
||||||
|
SetForegroundWindow( wid );
|
||||||
|
SetFocus( wid );
|
||||||
|
FlashWindow( wid, TRUE );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
void bringToFront(QString pid)
|
||||||
{
|
{
|
||||||
Q_UNUSED(pid)
|
snoreDebug( SNORE_DEBUG ) << pid;
|
||||||
Q_UNUSED(noti)
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
auto findWindowForPid = [](ulong pid)
|
auto findWindowForPid = [](ulong pid)
|
||||||
{
|
{
|
||||||
|
@ -46,21 +67,7 @@ void bringToFront(QString pid, Notification noti)
|
||||||
|
|
||||||
HWND wid = findWindowForPid(pid.toInt());
|
HWND wid = findWindowForPid(pid.toInt());
|
||||||
if(wid) {
|
if(wid) {
|
||||||
HWND hwndActiveWin = GetForegroundWindow();
|
bringWindowToFront((WId)wid);
|
||||||
int idActive = GetWindowThreadProcessId( hwndActiveWin, NULL );
|
|
||||||
|
|
||||||
if ( AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) )
|
|
||||||
{
|
|
||||||
SetForegroundWindow( wid );
|
|
||||||
SetFocus( wid );
|
|
||||||
FlashWindow( wid, TRUE );
|
|
||||||
AttachThreadInput( GetCurrentThreadId(), idActive, FALSE );
|
|
||||||
} else {
|
|
||||||
// try it anyhow
|
|
||||||
SetForegroundWindow( wid );
|
|
||||||
SetFocus( wid );
|
|
||||||
FlashWindow( wid, TRUE );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -95,12 +102,16 @@ int main(int argc, char *argv[])
|
||||||
QCommandLineOption silent(QStringList() << "silent", "Don't print to stdout.");
|
QCommandLineOption silent(QStringList() << "silent", "Don't print to stdout.");
|
||||||
parser.addOption(silent);
|
parser.addOption(silent);
|
||||||
|
|
||||||
QCommandLineOption _bringToFront(QStringList() << "bring-to-front", "Bring process with pid to front if notification is clicked.", "pid");
|
QCommandLineOption _bringProcessToFront(QStringList() << "bring-process-to-front", "Bring process with pid to front if notification is clicked.", "pid");
|
||||||
parser.addOption(_bringToFront);
|
parser.addOption(_bringProcessToFront);
|
||||||
|
|
||||||
|
QCommandLineOption _bringWindowToFront(QStringList() << "bring-window-to-front", "Bring window with wid to front if notification is clicked.", "wid");
|
||||||
|
parser.addOption(_bringWindowToFront);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
parser.process(app);
|
parser.process(app);
|
||||||
|
snoreDebug( SNORE_DEBUG ) << app.arguments();
|
||||||
if (parser.isSet(title) && parser.isSet(message)) {
|
if (parser.isSet(title) && parser.isSet(message)) {
|
||||||
SnoreCore &core = SnoreCore::instance();
|
SnoreCore &core = SnoreCore::instance();
|
||||||
|
|
||||||
|
@ -114,6 +125,10 @@ int main(int argc, char *argv[])
|
||||||
core.registerApplication(application);
|
core.registerApplication(application);
|
||||||
|
|
||||||
Notification n(application, alert, parser.value(title), parser.value(message), icon);
|
Notification n(application, alert, parser.value(title), parser.value(message), icon);
|
||||||
|
if(parser.isSet(_bringProcessToFront) || parser.isSet(_bringWindowToFront))
|
||||||
|
{
|
||||||
|
n.addAction(Action(1, "Bring to Front"));
|
||||||
|
}
|
||||||
|
|
||||||
core.broadcastNotification(n);
|
core.broadcastNotification(n);
|
||||||
int returnCode = -1;
|
int returnCode = -1;
|
||||||
|
@ -124,8 +139,12 @@ int main(int argc, char *argv[])
|
||||||
QDebug(&reason) << noti.closeReason();
|
QDebug(&reason) << noti.closeReason();
|
||||||
cout << qPrintable(reason) << endl;
|
cout << qPrintable(reason) << endl;
|
||||||
}
|
}
|
||||||
if(noti.closeReason() == Notification::CLOSED && parser.isSet(_bringToFront)) {
|
if(noti.closeReason() == Notification::CLOSED) {
|
||||||
bringToFront(parser.value(_bringToFront), noti);
|
if(parser.isSet(_bringProcessToFront)) {
|
||||||
|
bringToFront(parser.value(_bringProcessToFront));
|
||||||
|
} else if(parser.isSet(_bringWindowToFront)) {
|
||||||
|
bringWindowToFront((WId)parser.value(_bringWindowToFront).toULongLong());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
returnCode = noti.closeReason();
|
returnCode = noti.closeReason();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue