# Change the focus of Gtk windows

**URL:** <https://discourse.julialang.org/t/change-the-focus-of-gtk-windows/19560>\
**Category:** Visualization\
**Tags:** package, gtk\
**Created:** [January 12, 2019, 2:18pm UTC](https://discourse.julialang.org/t/change-the-focus-of-gtk-windows/19560 "2019-01-12T14:18:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carsten](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Carsten](https://discourse.julialang.org/u/Carsten)\
**Post date:** [January 12, 2019, 2:18pm UTC](https://discourse.julialang.org/t/change-the-focus-of-gtk-windows/19560/1 "2019-01-12T14:18:49Z")

</div>

I have two overlapping Gtk-windows open. How can I change the focus via button clicking to get the hidden Gtk-window on top?  
Any advice would be very welcome.

Carsten

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [January 12, 2019, 2:28pm UTC](https://discourse.julialang.org/t/change-the-focus-of-gtk-windows/19560/2 "2019-01-12T14:28:55Z")

</div>

Focus is decided by the window manager → Just click on the window?

---

<div class="post-metadata">

**Author:** ![Carsten](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Carsten](https://discourse.julialang.org/u/Carsten)\
**Post date:** [January 12, 2019, 3:01pm UTC](https://discourse.julialang.org/t/change-the-focus-of-gtk-windows/19560/3 "2019-01-12T15:01:12Z")

</div>

Of course I can change the focus e.g. via +Tab (Windows10) or it is possible to get information from the statusbar and then select the wanted window.  
However I want to change the active Gtk window via button action. Especially when the second window is hidden by a larger one.  
Nevertheless thank you for your quick reply

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [January 12, 2019, 3:08pm UTC](https://discourse.julialang.org/t/change-the-focus-of-gtk-windows/19560/4 "2019-01-12T15:08:55Z")

</div>

There are some functions in Gtk to interact with the WM, but it’s tricky. I never used it, but you could look into:

> **[Gtk-3.0](https://docs.gtk.org/gtk3/)**
>
> Reference for Gtk-3.0

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [January 12, 2019, 3:50pm UTC](https://discourse.julialang.org/t/change-the-focus-of-gtk-windows/19560/5 "2019-01-12T15:50:50Z")

</div>

For `gtk_window_present` you have to do:

```
present(win::GtkWindow) 

```

There’s also `grab_focus(w::GtkWidget)` but that might be only for widgets inside windows.

---

<div class="post-metadata">

**Author:** ![Carsten](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Carsten](https://discourse.julialang.org/u/Carsten)\
**Post date:** [January 12, 2019, 9:51pm UTC](https://discourse.julialang.org/t/change-the-focus-of-gtk-windows/19560/6 "2019-01-12T21:51:09Z")

</div>

Thank you for reply. This was what I am looking for.

For `grab_focus(w::GtkWidget)` I did not found any information. What’s the use of it?

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [January 12, 2019, 11:07pm UTC](https://discourse.julialang.org/t/change-the-focus-of-gtk-windows/19560/7 "2019-01-12T23:07:51Z")

</div>

> **[Gtk-3.0](https://docs.gtk.org/gtk3/)**
>
> Reference for Gtk-3.0

---

<div class="post-metadata">

**Author:** ![Carsten](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Carsten](https://discourse.julialang.org/u/Carsten)\
**Post date:** [January 12, 2019, 11:45pm UTC](https://discourse.julialang.org/t/change-the-focus-of-gtk-windows/19560/8 "2019-01-12T23:45:28Z")

</div>

👍

---

<div class="post-metadata">

**Author:** ![Elyco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elyco/32/18418_2.png) [@Elyco](https://discourse.julialang.org/u/Elyco)\
**Post date:** [October 4, 2020, 9:39pm UTC](https://discourse.julialang.org/t/change-the-focus-of-gtk-windows/19560/9 "2020-10-04T21:39:32Z")

</div>

Hi Carsten,  
Have you managed to change the code programmatically?  
None of the solutions work for me.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 19, 2024, 2:51pm UTC](https://discourse.julialang.org/t/change-the-focus-of-gtk-windows/19560/10 "2024-01-19T14:51:03Z")

</div>

Is it possible to display a Gtk window without changing the current focus from where it is (say the input terminal/REPL) to the new window? Thanks.

_Related:_

- _[Gtk Layer Shell](https://github.com/wmww/gtk-layer-shell?tab=readme-ov-file) can display windows which do not grab the cursor focus_

- _See this_ _Makie.jl [thread](https://github.com/MakieOrg/Makie.jl/issues/452)_
