From b742ab8cc3fa259990551f2d4265c09681ba705f Mon Sep 17 00:00:00 2001 From: AntiCat Date: Mon, 8 Oct 2018 07:20:21 +0200 Subject: [PATCH] osx: fix annoying focus behaviour (#689) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 14 ++++++++++++++ client/util_darwin.h | 3 +++ client/util_darwin.m | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/client/Makefile b/client/Makefile index 96f610cd..9e5bde30 100644 --- a/client/Makefile +++ b/client/Makefile @@ -42,7 +42,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 8fc1f990..30e4c8de 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -26,6 +26,10 @@ #include #include "proxgui.h" #include + +extern "C" { +#include "util_darwin.h" +} //#include bool g_useOverlays = false; @@ -60,7 +64,12 @@ void ProxGuiQT::_ShowGraphWindow(void) return; if (!plotwidget) + { +#if defined(__MACH__) && defined(__APPLE__) + makeFocusable(); +#endif plotwidget = new ProxWidget(); + } plotwidget->show(); } @@ -108,6 +117,11 @@ 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 923a4dfc..dd159ec5 100644 --- a/client/util_darwin.h +++ b/client/util_darwin.h @@ -14,4 +14,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.m b/client/util_darwin.m index d07ebebc..c0f69aa9 100644 --- a/client/util_darwin.m +++ 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 -- 2.39.5