Skip to content
This repository was archived by the owner on Dec 9, 2021. It is now read-only.

Commit dea8f30

Browse files
committed
Merge branch 'mac-autotype' into build
2 parents 254723b + b5d4a98 commit dea8f30

15 files changed

Lines changed: 822 additions & 2 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ if(MINGW)
134134
set(DATA_INSTALL_DIR "share")
135135
elseif(APPLE)
136136
set(BIN_INSTALL_DIR ".")
137-
set(PLUGIN_INSTALL_DIR ".")
137+
set(PLUGIN_INSTALL_DIR "${PROGNAME}.app/Contents/PlugIns")
138138
set(DATA_INSTALL_DIR "${PROGNAME}.app/Contents/Resources")
139139
else()
140140
include(GNUInstallDirs)

build_mac.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Install xcode
4+
# Install homebrew
5+
# > brew install cmake qt5 libgcrypt
6+
7+
if cd build; then
8+
QT5_DIR="/usr/local/opt/qt5"
9+
10+
export CMAKE_PREFIX_PATH=$QT5_DIR
11+
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Release
12+
make -j4
13+
14+
$QT5_DIR/bin/macdeployqt src/KeePassX.app
15+
fi

src/autotype/AutoType.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ void AutoType::performAutoType(const Entry* entry, QWidget* hideWindow, const QS
146146
}
147147

148148
if (hideWindow) {
149+
#if defined(Q_OS_MAC)
150+
m_plugin->raiseLastActiveWindow();
151+
#else
149152
hideWindow->showMinimized();
153+
#endif
150154
}
151155

152156
Tools::wait(m_plugin->initialTimeout());
@@ -215,6 +219,12 @@ void AutoType::performGlobalAutoType(const QList<Database*>& dbList)
215219
SLOT(performAutoTypeFromGlobal(Entry*,QString)));
216220
connect(selectDialog, SIGNAL(rejected()), SLOT(resetInAutoType()));
217221
selectDialog->setEntries(entryList, sequenceHash);
222+
223+
#if defined(Q_OS_MAC)
224+
m_plugin->raiseOwnWindow();
225+
Tools::wait(500);
226+
#endif
227+
218228
selectDialog->show();
219229
// necessary when the main window is minimized
220230
selectDialog->activateWindow();

src/autotype/AutoTypePlatformPlugin.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class AutoTypePlatformInterface
3939

4040
virtual AutoTypeExecutor* createExecutor() = 0;
4141

42+
#if defined(Q_OS_MAC)
43+
virtual bool raiseLastActiveWindow() = 0;
44+
virtual bool raiseOwnWindow() = 0;
45+
#endif
46+
4247
// implementations should also provide a globalShortcutTriggered() signal
4348
};
4449

src/autotype/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ if(UNIX AND NOT APPLE)
99
add_subdirectory(xcb)
1010
endif()
1111
elseif(WIN32)
12-
add_subdirectory(windows)
12+
add_subdirectory(windows)
13+
elseif(APPLE)
14+
add_subdirectory(mac)
1315
endif()
1416

1517
if(WITH_TESTS)

src/autotype/mac/AppKit.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) 2016 Lennart Glauer <mail@lennart-glauer.de>
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 2 or (at your option)
7+
* version 3 of the License.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef KEEPASSX_APPKIT_H
19+
#define KEEPASSX_APPKIT_H
20+
21+
#include <unistd.h>
22+
23+
extern "C" {
24+
25+
class AppKit
26+
{
27+
public:
28+
AppKit();
29+
~AppKit();
30+
31+
pid_t lastActiveProcessId();
32+
pid_t activeProcessId();
33+
pid_t ownProcessId();
34+
bool activateProcess(pid_t pid);
35+
36+
private:
37+
void *self;
38+
};
39+
40+
} // extern "C"
41+
42+
#endif // KEEPASSX_APPKIT_H

src/autotype/mac/AppKitImpl.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2016 Lennart Glauer <mail@lennart-glauer.de>
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 2 or (at your option)
7+
* version 3 of the License.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#import "AppKit.h"
19+
20+
#import <Foundation/Foundation.h>
21+
#import <AppKit/NSRunningApplication.h>
22+
23+
@interface AppKitImpl : NSObject
24+
25+
@property (strong) NSRunningApplication *lastActiveApplication;
26+
27+
- (pid_t) activeProcessId;
28+
- (pid_t) ownProcessId;
29+
- (bool) activateProcess:(pid_t) pid;
30+
31+
@end

src/autotype/mac/AppKitImpl.mm

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (C) 2016 Lennart Glauer <mail@lennart-glauer.de>
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 2 or (at your option)
7+
* version 3 of the License.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#import "AppKitImpl.h"
19+
20+
#import <AppKit/NSWorkspace.h>
21+
22+
@implementation AppKitImpl
23+
24+
AppKit::AppKit()
25+
{
26+
self = [[AppKitImpl alloc] init];
27+
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:static_cast<id>(self)
28+
selector:@selector(didDeactivateApplicationObserver:)
29+
name:NSWorkspaceDidDeactivateApplicationNotification
30+
object:nil];
31+
}
32+
33+
AppKit::~AppKit()
34+
{
35+
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:static_cast<id>(self)];
36+
[static_cast<id>(self) dealloc];
37+
}
38+
39+
//
40+
// Update last active application property
41+
//
42+
- (void) didDeactivateApplicationObserver:(NSNotification *) notification
43+
{
44+
NSDictionary *userInfo = notification.userInfo;
45+
NSRunningApplication *app = userInfo[NSWorkspaceApplicationKey];
46+
47+
if (app.processIdentifier != [self ownProcessId]) {
48+
self.lastActiveApplication = app;
49+
}
50+
}
51+
52+
//
53+
// Get process id of frontmost application (-> keyboard input)
54+
//
55+
- (pid_t) activeProcessId
56+
{
57+
return [NSWorkspace sharedWorkspace].frontmostApplication.processIdentifier;
58+
}
59+
60+
//
61+
// Get process id of own process
62+
//
63+
- (pid_t) ownProcessId
64+
{
65+
return [NSProcessInfo processInfo].processIdentifier;
66+
}
67+
68+
//
69+
// Activate application by process id
70+
//
71+
- (bool) activateProcess:(pid_t) pid
72+
{
73+
NSRunningApplication *app = [NSRunningApplication runningApplicationWithProcessIdentifier:pid];
74+
75+
return [app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
76+
}
77+
78+
//
79+
// ------------------------- C++ Trampolines -------------------------
80+
//
81+
82+
pid_t AppKit::lastActiveProcessId()
83+
{
84+
return [static_cast<id>(self) lastActiveApplication].processIdentifier;
85+
}
86+
87+
pid_t AppKit::activeProcessId()
88+
{
89+
return [static_cast<id>(self) activeProcessId];
90+
}
91+
92+
pid_t AppKit::ownProcessId()
93+
{
94+
return [static_cast<id>(self) ownProcessId];
95+
}
96+
97+
bool AppKit::activateProcess(pid_t pid)
98+
{
99+
return [static_cast<id>(self) activateProcess:pid];
100+
}
101+
102+
@end

0 commit comments

Comments
 (0)