# [PATCH] gitk: force focus to main window

6 messages from 2008-12-17 to 2008-12-18. Participants: Johannes Sixt, Paul Mackerras, Johannes Schindelin, Jeff King.
Thread: https://gitlist.dev/t/16766

## Johannes Sixt, 2008-12-17 11:50

Subject: [PATCH] gitk: force focus to main window
Message-ID: <4948E771.4050705@viscovery.net>
URL: https://gitlist.dev/e/4948E771.4050705%40viscovery.net

```
From: Johannes Schindelin <johannes.schindelin@gmx.de>

On msysGit, the focus is first on the (Tk) console.  This console is then
hidden, but keeps the focus.  Work around that by forcing the focus onto
the gitk window.

This fixes issue 14.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 gitk-git/gitk |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/gitk-git/gitk b/gitk-git/gitk
index 1c8d98e..b3d8219 100644
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -10898,4 +10898,5 @@ if {[info exists permviews]} {
 	addviewmenu $n
     }
 }
+focus -force .
 getcommits {}
-- 
1.6.1.rc3.980.ga0bb

```

## Paul Mackerras, 2008-12-17 21:38

Subject: Re: [PATCH] gitk: force focus to main window
Message-ID: <18761.29020.237388.687560@cargo.ozlabs.ibm.com>
URL: https://gitlist.dev/e/18761.29020.237388.687560%40cargo.ozlabs.ibm.com
In-Reply-To: <4948E771.4050705@viscovery.net>

```
Johannes Sixt writes:

> On msysGit, the focus is first on the (Tk) console.  This console is then
> hidden, but keeps the focus.  Work around that by forcing the focus onto
> the gitk window.

Hmmm, I don't like doing focus -force unconditionally on all
platforms.  I hate it when applications decide they know best and
override what the window manager decides.

At least put a if {[tk windowingsystem] eq "win32"} in there.
(msysGit is a windows thing, isn't it?)

Paul.

```

## Johannes Schindelin, 2008-12-18 03:14

Subject: Re: [PATCH] gitk: force focus to main window
Message-ID: <alpine.DEB.1.00.0812180413240.14632@racer>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0812180413240.14632%40racer
In-Reply-To: <18761.29020.237388.687560@cargo.ozlabs.ibm.com>

```
Hi,

On Thu, 18 Dec 2008, Paul Mackerras wrote:

> Johannes Sixt writes:
> 
> > On msysGit, the focus is first on the (Tk) console.  This console is 
> > then hidden, but keeps the focus.  Work around that by forcing the 
> > focus onto the gitk window.
> 
> Hmmm, I don't like doing focus -force unconditionally on all platforms.  
> I hate it when applications decide they know best and override what the 
> window manager decides.

>From my previous experience with my patches to gitk, I did not expect 
otherwise.  That is why I did not even bother with this one.

> At least put a if {[tk windowingsystem] eq "win32"} in there. (msysGit 
> is a windows thing, isn't it?)

Yeah, because on other platforms, when you start gitk, you don't want it 
to take focus.  Yeah, right.

Ciao,
Dscho

```

## Jeff King, 2008-12-18 03:23

Subject: Re: [PATCH] gitk: force focus to main window
Message-ID: <20081218032358.GB20749@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20081218032358.GB20749%40coredump.intra.peff.net
In-Reply-To: <alpine.DEB.1.00.0812180413240.14632@racer>

```
On Thu, Dec 18, 2008 at 04:14:25AM +0100, Johannes Schindelin wrote:

> > At least put a if {[tk windowingsystem] eq "win32"} in there. (msysGit 
> > is a windows thing, isn't it?)
> 
> Yeah, because on other platforms, when you start gitk, you don't want it 
> to take focus.  Yeah, right.

That is _exactly_ what I want on my platform: no window should steal the
focus when I am in the middle of typing in some other window. And to
that end, my window manager does not shift the focus until I tell it to
do so.

So yes, this patch _does_ break at least my setup. But more importantly,
it is an application making a decision about focus policy that should be
made by the window manager. I understand that the window manager in
Windows sucks, and that this is a workaround that makes things better
there. But please don't inflict this braindeadedness on the rest of us.

-Peff

```

## Paul Mackerras, 2008-12-18 04:09

Subject: Re: [PATCH] gitk: force focus to main window
Message-ID: <18761.52488.206887.985268@cargo.ozlabs.ibm.com>
URL: https://gitlist.dev/e/18761.52488.206887.985268%40cargo.ozlabs.ibm.com
In-Reply-To: <alpine.DEB.1.00.0812180413240.14632@racer>

```
Johannes Schindelin writes:

> > At least put a if {[tk windowingsystem] eq "win32"} in there. (msysGit 
> > is a windows thing, isn't it?)
> 
> Yeah, because on other platforms, when you start gitk, you don't want it 
> to take focus.  Yeah, right.

No - on other platforms I have a window manager that gives focus to
new applications automatically.  Or, if I don't want new applications
to grab the focus, I tell the window manager that that's what the
policy should be.  Either way the application shouldn't forcibly and
unilaterally grab the focus.

I'm prepared (predisposed, even :-) to believe that windows sucks, so
I'll take the patch if it only affects windows.

Paul.

```

## Johannes Sixt, 2008-12-18 07:30

Subject: [PATCH v2] gitk: force the focus to the main window on Windows
Message-ID: <4949FC29.2080200@viscovery.net>
URL: https://gitlist.dev/e/4949FC29.2080200%40viscovery.net
In-Reply-To: <18761.29020.237388.687560@cargo.ozlabs.ibm.com>

```
From: Johannes Sixt <j6t@kdbg.org>

On msysGit, the focus is first on the (Tk) console.  This console is then
hidden, but keeps the focus.  Work around that by forcing the focus onto
the gitk window.

This fixes msysGit issue 14. Diagnosed and originally fixed by
Johannes Schindelin.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
Paul Mackerras schrieb:
> At least put a if {[tk windowingsystem] eq "win32"} in there.
> (msysGit is a windows thing, isn't it?)

I did that.

-- Hannes

 gitk |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/gitk b/gitk
index b63109b..121b621 100644
--- a/gitk
+++ b/gitk
@@ -10898,4 +10898,9 @@ if {[info exists permviews]} {
 	addviewmenu $n
     }
 }
+
+if {[tk windowingsystem] eq "win32"} {
+    focus -force .
+}
+
 getcommits {}
-- 
1.6.1.rc3.950.g5dd2

```
