[PATCH] gitk: workaround Tcl/Tk Cmd-TAB behavior on OSX

Subsystems: the rest

STALE3715d

6 messages, 3 authors, 2016-06-15 · open the first message on its own page

[PATCH] gitk: workaround Tcl/Tk Cmd-TAB behavior on OSX

From: Tair Sabirgaliev <hidden>
Date: 2016-06-15 22:56:45

On OSX Tcl/Tk application windows are created behind all
the applications down the stack of windows. This is very
annoying, because once a gitk window appears, it's the
downmost window and switching to it is pain.

The patch is trivial: if we are on OSX, emulate Cmd-Shift-TAB
key event, so that the gitk application window is brought
from bottom to top.

Signed-off-by: Tair Sabirgaliev <redacted>
---
  gitk | 13 +++++++++++++
  1 file changed, 13 insertions(+)
diff --git a/gitk b/gitk
index 572f73f..60a87fc 100755
--- a/gitk
+++ b/gitk
@@ -11687,6 +11687,19 @@ if {[catch {package require Tk 8.4} err]} {
      exit 1
  }
  +# On OSX workaround the Tcl/Tk windows going down the stack of Cmd-TAB
+if {[tk windowingsystem] eq "aqua"} {
+    exec osascript -e {
+        tell application "System Events"
+            key down command
+            key down shift
+            keystroke tab
+            key up shift
+            key up command
+        end tell    +    }
+}
+
  # Unset GIT_TRACE var if set
  if { [info exists ::env(GIT_TRACE)] } {
      unset ::env(GIT_TRACE)
-- 
1.8.2

Re: [PATCH] gitk: workaround Tcl/Tk Cmd-TAB behavior on OSX

From: Tair Sabirgaliev <hidden>
Date: 2016-06-15 22:56:45

The prev message was garbled :( Here is the correct patch (I hope).

On OSX Tcl/Tk application windows are created behind all
the applications down the stack of windows. This is very
annoying, because once a gitk window appears, it's the
downmost window and switching to it is pain.

The patch is trivial: if we are on OSX, emulate Cmd-Shift-TAB
key event, so that the gitk application window is brought
from bottom to top.

Signed-off-by: Tair Sabirgaliev <redacted>
---
  gitk | 13 +++++++++++++
  1 file changed, 13 insertions(+)
diff --git a/gitk b/gitk
index 572f73f..60a87fc 100755
--- a/gitk
+++ b/gitk
@@ -11687,6 +11687,19 @@ if {[catch {package require Tk 8.4} err]} {
      exit 1
  }

+# On OSX workaround the Tcl/Tk windows going down the stack of Cmd-TAB
+if {[tk windowingsystem] eq "aqua"} {
+    exec osascript -e {
+        tell application "System Events"
+            key down command
+            key down shift
+            keystroke tab
+            key up shift
+            key up command
+        end tell
+    }
+}
+
  # Unset GIT_TRACE var if set
  if { [info exists ::env(GIT_TRACE)] } {
      unset ::env(GIT_TRACE)
-- 
1.8.2

Re: [PATCH] gitk: workaround Tcl/Tk Cmd-TAB behavior on OSX

From: Paul Mackerras <hidden>
Date: 2016-06-15 22:56:55

On Thu, Apr 11, 2013 at 01:02:48AM +0600, Tair Sabirgaliev wrote:
quoted hunk
On OSX Tcl/Tk application windows are created behind all
the applications down the stack of windows. This is very
annoying, because once a gitk window appears, it's the
downmost window and switching to it is pain.

The patch is trivial: if we are on OSX, emulate Cmd-Shift-TAB
key event, so that the gitk application window is brought
from bottom to top.

Signed-off-by: Tair Sabirgaliev <redacted>
---
 gitk | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff --git a/gitk b/gitk
index 572f73f..60a87fc 100755
--- a/gitk
+++ b/gitk
@@ -11687,6 +11687,19 @@ if {[catch {package require Tk 8.4} err]} {
     exit 1
 }
 +# On OSX workaround the Tcl/Tk windows going down the stack of Cmd-TAB
+if {[tk windowingsystem] eq "aqua"} {
+    exec osascript -e {
+        tell application "System Events"
+            key down command
+            key down shift
+            keystroke tab
+            key up shift
+            key up command
+        end tell    +    }
+}
Is this really the only way to do it?  It seems a bit hacky to me.  I
would think you should be able to use the "wm" command to achieve what
you want.  I don't use Mac OS, so I don't know exactly how Tcl/Tk
behaves on it, but this page looks like it might hold some clues for
what you want to do:

http://teapot.activestate.com/package/name/windowlist/ver/1.4/arch/tcl/file.tm

Paul.

Re: [PATCH] gitk: workaround Tcl/Tk Cmd-TAB behavior on OSX

From: Tair Sabirgaliev <hidden>
Date: 2016-06-15 22:56:55

On Apr 20, 2013, at 9:19 AM, Paul Mackerras [off-list ref] wrote:
On Thu, Apr 11, 2013 at 01:02:48AM +0600, Tair Sabirgaliev wrote:
quoted
On OSX Tcl/Tk application windows are created behind all
the applications down the stack of windows. This is very
annoying, because once a gitk window appears, it's the
downmost window and switching to it is pain.

The patch is trivial: if we are on OSX, emulate Cmd-Shift-TAB
key event, so that the gitk application window is brought
from bottom to top.
Is this really the only way to do it?  It seems a bit hacky to me.  I
would think you should be able to use the "wm" command to achieve what
you want.  I don't use Mac OS, so I don't know exactly how Tcl/Tk
behaves on it, but this page looks like it might hold some clues for
what you want to do:

http://teapot.activestate.com/package/name/windowlist/ver/1.4/arch/tcl/file.tm
Today I did some further investigations on reasons app windows going behind. 
Turns out this is not something specific to Tcl/Tk. 

On OSX, GUI applications can be launched from Terminal in 2 ways:
1. Interactively, directly using app executable:
         sh$ /Applications/Chess.app/Contents/MacOS/Chess
2. Asynchronously, using OSX 'open' facility
         sh$ open -a Chess

The problem with 1st way is that OSX always puts the new app window behind 
the others, thus making sure the focus remains at Terminal input. 

The problem with the 2nd approach is that app is launched 'asynchronously', 
detached from Terminal, so when you close the app, focus doesn't necessarily 
return back to Terminal as it would normally do in Linux for example.

So, yes, this is a really hacky workaround, but it consistently takes the interactively 
launched app window to foreground on most modern OSX versions.

And regarding the link you provided -- I tried them, unfortunately the techniques 
there don't bring the application to foreground. Looks like they are mostly intended
to manipulate windows within a single multi-window application.

Tair.

Re: [PATCH] gitk: workaround Tcl/Tk Cmd-TAB behavior on OSX

From: Stefan Haller <hidden>
Date: 2016-06-15 22:56:58

Tair Sabirgaliev [off-list ref] wrote:
On OSX Tcl/Tk application windows are created behind all
the applications down the stack of windows. This is very
annoying, because once a gitk window appears, it's the
downmost window and switching to it is pain.

The patch is trivial: if we are on OSX, emulate Cmd-Shift-TAB
key event, so that the gitk application window is brought
from bottom to top.

Signed-off-by: Tair Sabirgaliev <redacted>
---

  +# On OSX workaround the Tcl/Tk windows going down the stack of Cmd-TAB
+if {[tk windowingsystem] eq "aqua"} {
+    exec osascript -e {
+        tell application "System Events"
+            key down command
+            key down shift
+            keystroke tab
+            key up shift
+            key up command
+        end tell    +    }
+}
+
First of all, I absolutely want this behaviour.  Bringing windows up in
the background is one of the biggest usability problems of git on Mac.

However, I don't think that synthesizing the keystrokes for
Command-Shift-Tab is a good solution. It would be better to explicitly
bring our process to the front.  One way to achieve this would be:

if {[tk windowingsystem] eq "aqua"} {
    exec osascript -e [format {
    tell application "System Events"
        set frontmost of processes whose unix id is %d to true
    end tell
    } [pid] ]
}

(Not sure about the formatting, I don't speak Tcl...)

Also, we need the same thing in git gui as well.

Best,
   Stefan


-- 
Stefan Haller
Berlin, Germany
http://www.haller-berlin.de/

Re: [PATCH 1] gitk: on OSX bring the gitk window to front

From: Tair Sabirgaliev <hidden>
Date: 2016-06-15 22:56:58

On OSX Tcl/Tk application windows are created behind all
the applications down the stack of windows. This is very
annoying, because once a gitk window appears, it's the
downmost window and switching to it is pain.

The patch is: if we are on OSX, use osascript to
bring the current Wish process window to front.

Signed-off-by: Tair Sabirgaliev <redacted>
Thanks-to: Stefan Haller [off-list ref]
---
 gitk | 9 +++++++++
 1 file changed, 9 insertions(+)
diff --git a/gitk b/gitk
index 572f73f..66e59b1 100755
--- a/gitk
+++ b/gitk
@@ -11687,6 +11687,15 @@ if {[catch {package require Tk 8.4} err]} {
     exit 1
 }
 
+# on OSX bring the current Wish process window to front
+if {[tk windowingsystem] eq "aqua"} {
+    exec osascript -e [format {
+        tell application "System Events"
+            set frontmost of processes whose unix id is %d to true
+        end tell
+    } [pid] ]
+}
+
 # Unset GIT_TRACE var if set
 if { [info exists ::env(GIT_TRACE)] } {
     unset ::env(GIT_TRACE)
-- 
1.8.2.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help