From 1fb121474e89e321ba79718ac395899573a4bf62 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 7 Oct 2018 09:01:24 +0200 Subject: [PATCH] osx: fix annoying focus behaviour (@anticat) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/Proxmark/proxmark3/pull/689 OS X has a global menu bar and a per app dock icon. Therefore, all GUI applications launched from a terminal will become focused - even if they don’t show any windows. Thereby the terminal loses focus. Since is it very annoying to re-focus the terminal after each proxmark client launch, this change makes the client unfocusable during launch and restores the regular behaviour when a window is created. --- client/Makefile | 2 +- client/proxguiqt.cpp | 19 +++++++++++++++++-- client/util_darwin.h | 2 ++ client/{util_darwin.c => util_darwin.m} | 15 +++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) rename client/{util_darwin.c => util_darwin.m} (75%) diff --git a/client/Makefile b/client/Makefile index 31c9c6a2d..4d0312e80 100644 --- a/client/Makefile +++ b/client/Makefile @@ -38,7 +38,7 @@ else ifeq ($(platform),Darwin) LUAPLATFORM = macosx OBJCSRCS = util_darwin.m - LDFLAGS += -framework Foundation + LDFLAGS += -framework Foundation -framework AppKit else LUALIB += -ldl LDLIBS += -ltermcap -lncurses diff --git a/client/proxguiqt.cpp b/client/proxguiqt.cpp index 56de71b24..296862e65 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -27,6 +27,10 @@ #include "proxgui.h" #include +extern "C" { +#include "util_darwin.h" +} + bool g_useOverlays = false; int g_absVMax = 0; int startMax; @@ -53,9 +57,14 @@ void ProxGuiQT::_ShowGraphWindow(void) { if(!plotapp) return; - if (!plotwidget) + if (!plotwidget) { + +#if defined(__MACH__) && defined(__APPLE__) + makeFocusable(); +#endif + plotwidget = new ProxWidget(); - + } plotwidget->show(); } @@ -100,6 +109,12 @@ void ProxGuiQT::MainLoop() //start proxmark thread after starting event loop QTimer::singleShot(200, this, SLOT(_StartProxmarkThread())); +#if defined(__MACH__) && defined(__APPLE__) + //Prevent the terminal from loosing focus during launch by making the client unfocusable + makeUnfocusable(); +#endif + + plotapp->exec(); } diff --git a/client/util_darwin.h b/client/util_darwin.h index 923a4dfc0..c69a551d3 100644 --- a/client/util_darwin.h +++ b/client/util_darwin.h @@ -13,5 +13,7 @@ void disableAppNap(const char* reason); void enableAppNap(); +void makeUnfocusable(); +void makeFocusable(); #endif \ No newline at end of file diff --git a/client/util_darwin.c b/client/util_darwin.m similarity index 75% rename from client/util_darwin.c rename to client/util_darwin.m index d07ebebc4..9d7583903 100644 --- a/client/util_darwin.c +++ b/client/util_darwin.m @@ -12,6 +12,7 @@ #import #import +#import static id activity = nil; @@ -38,3 +39,17 @@ void enableAppNap() { void disableAppNap(const char* reason) { } void enableAppNap() { } #endif + + +//OS X Version 10.6 is defined in OS X 10.6 and later +#if defined(MAC_OS_X_VERSION_10_6) +void makeUnfocusable() { + [NSApp setActivationPolicy:NSApplicationActivationPolicyProhibited]; +} +void makeFocusable() { + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; +} +#else +void makeUnfocusable() { } +void makeFocusable() { } +#endif \ No newline at end of file