]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
osx: fix annoying focus behaviour (#689)
authorAntiCat <contiki@anticat.ch>
Mon, 8 Oct 2018 05:20:21 +0000 (07:20 +0200)
committerpwpiwi <pwpiwi@users.noreply.github.com>
Mon, 8 Oct 2018 05:20:21 +0000 (07:20 +0200)
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
client/proxguiqt.cpp
client/util_darwin.h
client/util_darwin.m

index 96f610cd80f92b0c8a730e4dbb206ecc6911d4cb..9e5bde308b6896444b0fa15ad813d16e6ba116da 100644 (file)
@@ -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
index 8fc1f990291a595dada84a688eebb25b526403a2..30e4c8de782cd0f94d60db9d4834f35753296fde 100644 (file)
 #include <string.h>
 #include "proxgui.h"
 #include <QtGui>
+
+extern "C" {
+#include "util_darwin.h"
+}
 //#include <ctime>
 
 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();
 }
 
index 923a4dfc0bdeeb520b22f5513a5a642f55f89b80..dd159ec5e1eb96925bc2aea082f4acc05fd7938b 100644 (file)
@@ -14,4 +14,7 @@
 void disableAppNap(const char* reason);
 void enableAppNap();
 
+void makeUnfocusable();
+void makeFocusable();
+
 #endif
\ No newline at end of file
index d07ebebc40e3cf6f80b3bf7a5e825fd6290daf09..c0f69aa92f74a973d570186553883d3245ac1a6e 100644 (file)
@@ -12,6 +12,7 @@
 
 #import <Foundation/NSString.h>
 #import <Foundation/NSProcessInfo.h>
+#import <AppKit/NSApplication.h>
 
 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
Impressum, Datenschutz