code style
This commit is contained in:
parent
a2cc0dbb9c
commit
be25b29bde
21
src/main.cpp
21
src/main.cpp
|
@ -19,16 +19,15 @@
|
||||||
using namespace Snore;
|
using namespace Snore;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
void bringWindowToFront(WId _wid)
|
||||||
void bringWindowToFront( WId _wid) {
|
{
|
||||||
snoreDebug(SNORE_DEBUG) << _wid;
|
snoreDebug(SNORE_DEBUG) << _wid;
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
HWND wid = (HWND)_wid;
|
HWND wid = (HWND)_wid;
|
||||||
HWND hwndActiveWin = GetForegroundWindow();
|
HWND hwndActiveWin = GetForegroundWindow();
|
||||||
int idActive = GetWindowThreadProcessId(hwndActiveWin, NULL);
|
int idActive = GetWindowThreadProcessId(hwndActiveWin, NULL);
|
||||||
|
|
||||||
if ( AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) )
|
if (AttachThreadInput(GetCurrentThreadId(), idActive, TRUE)) {
|
||||||
{
|
|
||||||
SetForegroundWindow(wid);
|
SetForegroundWindow(wid);
|
||||||
SetFocus(wid);
|
SetFocus(wid);
|
||||||
FlashWindow(wid, TRUE);
|
FlashWindow(wid, TRUE);
|
||||||
|
@ -45,18 +44,19 @@ void bringToFront(QString pid)
|
||||||
{
|
{
|
||||||
snoreDebug(SNORE_DEBUG) << pid;
|
snoreDebug(SNORE_DEBUG) << pid;
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
auto findWindowForPid = [](ulong pid)
|
auto findWindowForPid = [](ulong pid) {
|
||||||
{
|
|
||||||
// based on http://stackoverflow.com/a/21767578
|
// based on http://stackoverflow.com/a/21767578
|
||||||
pair<ulong, HWND> data = make_pair(pid, (HWND)0);
|
pair<ulong, HWND> data = make_pair(pid, (HWND)0);
|
||||||
::EnumWindows([](HWND handle, LPARAM lParam) -> BOOL {
|
::EnumWindows([](HWND handle, LPARAM lParam) -> BOOL {
|
||||||
auto isMainWindow = [](HWND handle){
|
auto isMainWindow = [](HWND handle)
|
||||||
|
{
|
||||||
return ::GetWindow(handle, GW_OWNER) == (HWND)0 && IsWindowVisible(handle);
|
return ::GetWindow(handle, GW_OWNER) == (HWND)0 && IsWindowVisible(handle);
|
||||||
};
|
};
|
||||||
pair<ulong, HWND> &data = *(pair<ulong, HWND> *)lParam;
|
pair<ulong, HWND> &data = *(pair<ulong, HWND> *)lParam;
|
||||||
ulong process_id = 0;
|
ulong process_id = 0;
|
||||||
::GetWindowThreadProcessId(handle, &process_id);
|
::GetWindowThreadProcessId(handle, &process_id);
|
||||||
if (data.first != process_id || !isMainWindow(handle)) {
|
if (data.first != process_id || !isMainWindow(handle))
|
||||||
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
data.second = handle;
|
data.second = handle;
|
||||||
|
@ -108,8 +108,6 @@ int main(int argc, char *argv[])
|
||||||
QCommandLineOption _bringWindowToFront(QStringList() << "bring-window-to-front", "Bring window with wid to front if notification is clicked.", "wid");
|
QCommandLineOption _bringWindowToFront(QStringList() << "bring-window-to-front", "Bring window with wid to front if notification is clicked.", "wid");
|
||||||
parser.addOption(_bringWindowToFront);
|
parser.addOption(_bringWindowToFront);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
parser.process(app);
|
parser.process(app);
|
||||||
snoreDebug(SNORE_DEBUG) << app.arguments();
|
snoreDebug(SNORE_DEBUG) << app.arguments();
|
||||||
if (parser.isSet(title) && parser.isSet(message)) {
|
if (parser.isSet(title) && parser.isSet(message)) {
|
||||||
|
@ -125,8 +123,7 @@ 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))
|
if (parser.isSet(_bringProcessToFront) || parser.isSet(_bringWindowToFront)) {
|
||||||
{
|
|
||||||
n.addAction(Action(1, "Bring to Front"));
|
n.addAction(Action(1, "Bring to Front"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue