1 // Copyright 2005-2019 The Mumble Developers. All rights reserved.
2 // Use of this source code is governed by a BSD-style license
3 // that can be found in the LICENSE file at the root of the
4 // Mumble source tree or at <https://www.mumble.info/LICENSE>.
5 
6 #ifndef MUMBLE_MUMBLE_GLOBALSHORTCUT_MACX_H_
7 #define MUMBLE_MUMBLE_GLOBALSHORTCUT_MACX_H_
8 
9 #include <stdlib.h>
10 #include <QtCore/QObject>
11 
12 #include <ApplicationServices/ApplicationServices.h>
13 
14 #include "GlobalShortcut.h"
15 #include "Global.h"
16 
17 class GlobalShortcutMac : public GlobalShortcutEngine {
18 	private:
19 		Q_OBJECT
20 		Q_DISABLE_COPY(GlobalShortcutMac)
21 	public:
22 		GlobalShortcutMac();
23 		~GlobalShortcutMac() Q_DECL_OVERRIDE;
24 		QString buttonName(const QVariant &) Q_DECL_OVERRIDE;
25 		void dumpEventTaps();
26 		void needRemap() Q_DECL_OVERRIDE;
27 		bool handleModButton(CGEventFlags newmask);
28 		bool canSuppress() Q_DECL_OVERRIDE;
29 
30 	void setEnabled(bool) Q_DECL_OVERRIDE;
31 	bool enabled() Q_DECL_OVERRIDE;
32 	bool canDisable() Q_DECL_OVERRIDE;
33 
34 	public slots:
35 		void forwardEvent(void *evt);
36 
37 	protected:
38 		CFRunLoopRef loop;
39 		CFMachPortRef port;
40 		CGEventFlags modmask;
41 		UCKeyboardLayout *kbdLayout;
42 
43 		void run() Q_DECL_OVERRIDE;
44 
45 		static CGEventRef callback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *udata);
46 		QString translateMouseButton(const unsigned int keycode) const;
47 		QString translateModifierKey(const unsigned int keycode) const;
48 		QString translateKeyName(const unsigned int keycode) const;
49 };
50 
51 #endif
52