Bitcoin ABC  0.22.13
P2P Digital Currency
macdockiconhandler.mm
Go to the documentation of this file.
1 // Copyright (c) 2011-2019 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include "macdockiconhandler.h"
6 
7 #include <AppKit/AppKit.h>
8 #include <objc/runtime.h>
9 
10 static MacDockIconHandler *s_instance = nullptr;
11 
12 bool dockClickHandler(id self, SEL _cmd, ...) {
13  Q_UNUSED(self)
14  Q_UNUSED(_cmd)
15 
16  Q_EMIT s_instance->dockIconClicked();
17 
18  // Return NO (false) to suppress the default macOS actions
19  return false;
20 }
21 
23  Class delClass =
24  (Class)[[[NSApplication sharedApplication] delegate] class];
25  SEL shouldHandle =
26  sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
27  class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "[email protected]:");
28 }
29 
32 }
33 
35  if (!s_instance) s_instance = new MacDockIconHandler();
36  return s_instance;
37 }
38 
40  delete s_instance;
41 }
42 
49  [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
50 }
void setupDockClickHandler()
macOS-specific Dock icon handler.
static MacDockIconHandler * instance()
static MacDockIconHandler * s_instance
bool dockClickHandler(id self, SEL _cmd,...)
void ForceActivation()
Force application activation on macOS.