{"thread":{"id":"33464","subject":"[PATCH] gitk: workaround Tcl/Tk Cmd-TAB behavior on OSX","startedAt":"2013-04-10T19:02:48Z","lastAt":"2013-04-24T09:48:27Z","messageCount":7,"participants":["Tair Sabirgaliev","Paul Mackerras","Stefan Haller"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"213806","messageId":"5165B758.4070308@bee.kz","threadId":"33464","inReplyTo":null,"subject":"[PATCH] gitk: workaround Tcl/Tk Cmd-TAB behavior on OSX","fromName":"Tair Sabirgaliev","fromEmail":"tair.sabirgaliev@bee.kz","sentAt":"2013-04-10T19:02:48Z","receivedAt":"2013-04-10T19:02:48Z","isPatch":true,"sender":{"key":"tair.sabirgaliev@bee.kz","avatar":null},"body":"On OSX Tcl/Tk application windows are created behind all\nthe applications down the stack of windows. This is very\nannoying, because once a gitk window appears, it's the\ndownmost window and switching to it is pain.\n\nThe patch is trivial: if we are on OSX, emulate Cmd-Shift-TAB\nkey event, so that the gitk application window is brought\nfrom bottom to top.\n\nSigned-off-by: Tair Sabirgaliev <tair.sabirgaliev@gmail.com>\n---\n  gitk | 13 +++++++++++++\n  1 file changed, 13 insertions(+)\n\ndiff --git a/gitk b/gitk\nindex 572f73f..60a87fc 100755\n--- a/gitk\n+++ b/gitk\n@@ -11687,6 +11687,19 @@ if {[catch {package require Tk 8.4} err]} {\n      exit 1\n  }\n  +# On OSX workaround the Tcl/Tk windows going down the stack of Cmd-TAB\n+if {[tk windowingsystem] eq \"aqua\"} {\n+    exec osascript -e {\n+        tell application \"System Events\"\n+            key down command\n+            key down shift\n+            keystroke tab\n+            key up shift\n+            key up command\n+        end tell    +    }\n+}\n+\n  # Unset GIT_TRACE var if set\n  if { [info exists ::env(GIT_TRACE)] } {\n      unset ::env(GIT_TRACE)\n-- \n1.8.2\n"},{"id":"213810","messageId":"5165B9B0.8060301@bee.kz","threadId":"33464","inReplyTo":"5165B758.4070308@bee.kz","subject":"Re: [PATCH] gitk: workaround Tcl/Tk Cmd-TAB behavior on OSX","fromName":"Tair Sabirgaliev","fromEmail":"tair.sabirgaliev@bee.kz","sentAt":"2013-04-10T19:12:48Z","receivedAt":"2013-04-10T19:12:48Z","isPatch":true,"sender":{"key":"tair.sabirgaliev@bee.kz","avatar":null},"body":"The prev message was garbled :( Here is the correct patch (I hope).\n\nOn OSX Tcl/Tk application windows are created behind all\nthe applications down the stack of windows. This is very\nannoying, because once a gitk window appears, it's the\ndownmost window and switching to it is pain.\n\nThe patch is trivial: if we are on OSX, emulate Cmd-Shift-TAB\nkey event, so that the gitk application window is brought\nfrom bottom to top.\n\nSigned-off-by: Tair Sabirgaliev <tair.sabirgaliev@gmail.com>\n---\n  gitk | 13 +++++++++++++\n  1 file changed, 13 insertions(+)\n\ndiff --git a/gitk b/gitk\nindex 572f73f..60a87fc 100755\n--- a/gitk\n+++ b/gitk\n@@ -11687,6 +11687,19 @@ if {[catch {package require Tk 8.4} err]} {\n      exit 1\n  }\n\n+# On OSX workaround the Tcl/Tk windows going down the stack of Cmd-TAB\n+if {[tk windowingsystem] eq \"aqua\"} {\n+    exec osascript -e {\n+        tell application \"System Events\"\n+            key down command\n+            key down shift\n+            keystroke tab\n+            key up shift\n+            key up command\n+        end tell\n+    }\n+}\n+\n  # Unset GIT_TRACE var if set\n  if { [info exists ::env(GIT_TRACE)] } {\n      unset ::env(GIT_TRACE)\n-- \n1.8.2\n"},{"id":"213896","messageId":"51663DBE.2080603@bee.kz","threadId":"33464","inReplyTo":"CAJDDKr76K_-d6JSgv67DcXnZybpxkTjYPJxdObU3wrn+nYV3dw@mail.gmail.com","subject":"Re: [PATCH] gitk: workaround Tcl/Tk Cmd-TAB behavior on OSX","fromName":"Tair Sabirgaliev","fromEmail":"tair.sabirgaliev@bee.kz","sentAt":"2013-04-11T04:36:14Z","receivedAt":"2013-04-11T04:36:14Z","isPatch":true,"sender":{"key":"tair.sabirgaliev@bee.kz","avatar":null},"body":"On 4/11/13 8:46 AM, David Aguilar wrote:\n> Apologies because I don't know the Tk API very well.\n>\n> In Qt there is an API method to raise windows -- QWidget::raise().\n>\n> Is there no similar API in Tk?\n>\n> I seems like this may be related:\n>\n> http://wiki.tcl.tk/9457\n>\n> ..but it seems that -topmost may not be exactly the same thing.\n>\n> That said, if there's no portable way to do it, then this is certainly a\n> workaround.\n\nYes, I tried that one. Here is a quick test:\n\n========== hello.tcl =============\n#!/bin/sh\n# Tcl ignores the next line -*- tcl -*- \\\nexec wish \"$0\" -- \"$@\"\n\npackage require Tk\n\ngrid [ttk::button .b -text \"Hello World\"]\nwm attributes . -topmost true\n==================================\n\nI'm not sure I'm doing it right, but it doesn't work.\n\nLook like Tcl/Tk dev are very paranoic about windows created from \nTerminal/shell scripts: they don't let them take over , even if it is \ndesired.\n"},{"id":"214898","messageId":"20130420031955.GA30856@iris.ozlabs.ibm.com","threadId":"33464","inReplyTo":"5165B758.4070308@bee.kz","subject":"Re: [PATCH] gitk: workaround Tcl/Tk Cmd-TAB behavior on OSX","fromName":"Paul Mackerras","fromEmail":"paulus@samba.org","sentAt":"2013-04-20T03:19:55Z","receivedAt":"2013-04-20T03:19:55Z","isPatch":true,"sender":{"key":"paulus@samba.org","avatar":"https://avatars.githubusercontent.com/u/1606439?v=4"},"body":"On Thu, Apr 11, 2013 at 01:02:48AM +0600, Tair Sabirgaliev wrote:\n> On OSX Tcl/Tk application windows are created behind all\n> the applications down the stack of windows. This is very\n> annoying, because once a gitk window appears, it's the\n> downmost window and switching to it is pain.\n> \n> The patch is trivial: if we are on OSX, emulate Cmd-Shift-TAB\n> key event, so that the gitk application window is brought\n> from bottom to top.\n> \n> Signed-off-by: Tair Sabirgaliev <tair.sabirgaliev@gmail.com>\n> ---\n>  gitk | 13 +++++++++++++\n>  1 file changed, 13 insertions(+)\n> \n> diff --git a/gitk b/gitk\n> index 572f73f..60a87fc 100755\n> --- a/gitk\n> +++ b/gitk\n> @@ -11687,6 +11687,19 @@ if {[catch {package require Tk 8.4} err]} {\n>      exit 1\n>  }\n>  +# On OSX workaround the Tcl/Tk windows going down the stack of Cmd-TAB\n> +if {[tk windowingsystem] eq \"aqua\"} {\n> +    exec osascript -e {\n> +        tell application \"System Events\"\n> +            key down command\n> +            key down shift\n> +            keystroke tab\n> +            key up shift\n> +            key up command\n> +        end tell    +    }\n> +}\n\nIs this really the only way to do it?  It seems a bit hacky to me.  I\nwould think you should be able to use the \"wm\" command to achieve what\nyou want.  I don't use Mac OS, so I don't know exactly how Tcl/Tk\nbehaves on it, but this page looks like it might hold some clues for\nwhat you want to do:\n\nhttp://teapot.activestate.com/package/name/windowlist/ver/1.4/arch/tcl/file.tm\n\nPaul.\n"},{"id":"214910","messageId":"A7483D1D-2A01-4C56-85A8-DAD781171333@bee.kz","threadId":"33464","inReplyTo":"20130420031955.GA30856@iris.ozlabs.ibm.com","subject":"Re: [PATCH] gitk: workaround Tcl/Tk Cmd-TAB behavior on OSX","fromName":"Tair Sabirgaliev","fromEmail":"tair.sabirgaliev@bee.kz","sentAt":"2013-04-20T10:45:26Z","receivedAt":"2013-04-20T10:45:26Z","isPatch":true,"sender":{"key":"tair.sabirgaliev@bee.kz","avatar":null},"body":"\nOn Apr 20, 2013, at 9:19 AM, Paul Mackerras <paulus@samba.org> wrote:\n\n> On Thu, Apr 11, 2013 at 01:02:48AM +0600, Tair Sabirgaliev wrote:\n>> On OSX Tcl/Tk application windows are created behind all\n>> the applications down the stack of windows. This is very\n>> annoying, because once a gitk window appears, it's the\n>> downmost window and switching to it is pain.\n>> \n>> The patch is trivial: if we are on OSX, emulate Cmd-Shift-TAB\n>> key event, so that the gitk application window is brought\n>> from bottom to top.\n> \n> Is this really the only way to do it?  It seems a bit hacky to me.  I\n> would think you should be able to use the \"wm\" command to achieve what\n> you want.  I don't use Mac OS, so I don't know exactly how Tcl/Tk\n> behaves on it, but this page looks like it might hold some clues for\n> what you want to do:\n> \n> http://teapot.activestate.com/package/name/windowlist/ver/1.4/arch/tcl/file.tm\n\nToday I did some further investigations on reasons app windows going behind. \nTurns out this is not something specific to Tcl/Tk. \n\nOn OSX, GUI applications can be launched from Terminal in 2 ways:\n1. Interactively, directly using app executable:\n         sh$ /Applications/Chess.app/Contents/MacOS/Chess\n2. Asynchronously, using OSX 'open' facility\n         sh$ open -a Chess\n\nThe problem with 1st way is that OSX always puts the new app window behind \nthe others, thus making sure the focus remains at Terminal input. \n\nThe problem with the 2nd approach is that app is launched 'asynchronously', \ndetached from Terminal, so when you close the app, focus doesn't necessarily \nreturn back to Terminal as it would normally do in Linux for example.\n\nSo, yes, this is a really hacky workaround, but it consistently takes the interactively \nlaunched app window to foreground on most modern OSX versions.\n\nAnd regarding the link you provided -- I tried them, unfortunately the techniques \nthere don't bring the application to foreground. Looks like they are mostly intended\nto manipulate windows within a single multi-window application.\n\nTair."},{"id":"215218","messageId":"1l1scng.k9ly7ci7gjd2M%lists@haller-berlin.de","threadId":"33464","inReplyTo":"5165B758.4070308@bee.kz","subject":"Re: [PATCH] gitk: workaround Tcl/Tk Cmd-TAB behavior on OSX","fromName":"Stefan Haller","fromEmail":"lists@haller-berlin.de","sentAt":"2013-04-23T13:26:55Z","receivedAt":"2013-04-23T13:26:55Z","isPatch":true,"sender":{"key":"lists@haller-berlin.de","avatar":null},"body":"Tair Sabirgaliev <tair.sabirgaliev@bee.kz> wrote:\n\n> On OSX Tcl/Tk application windows are created behind all\n> the applications down the stack of windows. This is very\n> annoying, because once a gitk window appears, it's the\n> downmost window and switching to it is pain.\n> \n> The patch is trivial: if we are on OSX, emulate Cmd-Shift-TAB\n> key event, so that the gitk application window is brought\n> from bottom to top.\n> \n> Signed-off-by: Tair Sabirgaliev <tair.sabirgaliev@gmail.com>\n> ---\n>\n>   +# On OSX workaround the Tcl/Tk windows going down the stack of Cmd-TAB\n> +if {[tk windowingsystem] eq \"aqua\"} {\n> +    exec osascript -e {\n> +        tell application \"System Events\"\n> +            key down command\n> +            key down shift\n> +            keystroke tab\n> +            key up shift\n> +            key up command\n> +        end tell    +    }\n> +}\n> +\n\nFirst of all, I absolutely want this behaviour.  Bringing windows up in\nthe background is one of the biggest usability problems of git on Mac.\n\nHowever, I don't think that synthesizing the keystrokes for\nCommand-Shift-Tab is a good solution. It would be better to explicitly\nbring our process to the front.  One way to achieve this would be:\n\nif {[tk windowingsystem] eq \"aqua\"} {\n    exec osascript -e [format {\n    tell application \"System Events\"\n        set frontmost of processes whose unix id is %d to true\n    end tell\n    } [pid] ]\n}\n\n(Not sure about the formatting, I don't speak Tcl...)\n\nAlso, we need the same thing in git gui as well.\n\nBest,\n   Stefan\n\n\n-- \nStefan Haller\nBerlin, Germany\nhttp://www.haller-berlin.de/\n"},{"id":"215304","messageId":"3EE7D8B9-5FAE-43F5-9BE3-C4AE2A75B57D@bee.kz","threadId":"33464","inReplyTo":"1l1scng.k9ly7ci7gjd2M%lists@haller-berlin.de","subject":"Re: [PATCH 1] gitk: on OSX bring the gitk window to front","fromName":"Tair Sabirgaliev","fromEmail":"tair.sabirgaliev@bee.kz","sentAt":"2013-04-24T09:48:27Z","receivedAt":"2013-04-24T09:48:27Z","isPatch":true,"sender":{"key":"tair.sabirgaliev@bee.kz","avatar":null},"body":"On OSX Tcl/Tk application windows are created behind all\nthe applications down the stack of windows. This is very\nannoying, because once a gitk window appears, it's the\ndownmost window and switching to it is pain.\n\nThe patch is: if we are on OSX, use osascript to\nbring the current Wish process window to front.\n\nSigned-off-by: Tair Sabirgaliev <tair.sabirgaliev@gmail.com>\nThanks-to: Stefan Haller <lists@haller-berlin.de>\n---\n gitk | 9 +++++++++\n 1 file changed, 9 insertions(+)\n\ndiff --git a/gitk b/gitk\nindex 572f73f..66e59b1 100755\n--- a/gitk\n+++ b/gitk\n@@ -11687,6 +11687,15 @@ if {[catch {package require Tk 8.4} err]} {\n     exit 1\n }\n \n+# on OSX bring the current Wish process window to front\n+if {[tk windowingsystem] eq \"aqua\"} {\n+    exec osascript -e [format {\n+        tell application \"System Events\"\n+            set frontmost of processes whose unix id is %d to true\n+        end tell\n+    } [pid] ]\n+}\n+\n # Unset GIT_TRACE var if set\n if { [info exists ::env(GIT_TRACE)] } {\n     unset ::env(GIT_TRACE)\n-- \n1.8.2.1\n"}]}