Note that there are some explanatory texts on larger screens.

plurals
  1. POgtk: how to hide a window when the application loses focus
    primarykey
    data
    text
    <p>I want to duplicate the behaviour of tool windows in OpenOfice. When the application loses focus, the tool windows (if they are not docked) are hidden.</p> <p>So, I have a main window, and another utility window (<code>win_dock</code>). I want to hide <code>win_dock</code> when all the windows of the application loses focus and show it again if a window gain focus.</p> <p>What I did is that I connected to the focus-in-event and focus-out-event of all windows of the application, and I maintain a counter of how many windows have focus. When this counter drops to zero, I want to hide <code>win_dock</code>, and if this counter is positive again, I want to show <code>win_dock</code></p> <p>The problem is with this solution I can never focus <code>win_dock</code>. Because when I click on it, the main window drops the focus, so it hides <code>win_dock</code> that still hadn't gained the focus. Nevertheless the focus-in-event is still sent to <code>win_dock</code> and the windows reappears. But in the meantime it has lost the focus.</p> <p>Do you have a better solution?</p> <p>Here is the Vala source code:</p> <pre><code>public class Main { private Gtk.Builder builder; private Gtk.Window win_messages; private Gtk.Window win_dock; private int focus_count = 0; public Main() { builder = new Gtk.Builder(); builder.add_from_file("ui2.glade"); win_messages = builder.get_object("win_messages") as Gtk.Window; win_dock = builder.get_object("win_dock") as Gtk.Window; handle_focus(win_messages); handle_focus(win_dock); } public void start(){ win_messages.show_all(); //win_dock.show_all(); Gtk.main(); } private void handle_focus(Gtk.Window w) { w.focus_in_event.connect ((w, e) =&gt; { stdout.printf("Focus In (%s)\n", w.name); focus_count++; manage_focus(w == win_dock); }); w.focus_out_event.connect((w, e) =&gt; { stdout.printf("Focus Out (%s)\n", w.name); focus_count--; manage_focus(w == win_dock); }); } private void manage_focus(bool is_dock){ if(focus_count &gt; 0) { win_dock.show_all(); stdout.printf("Show (focus: %d)\n", focus_count); } else if(is_dock) { win_dock.hide_all(); stdout.printf("Hide (focus: %d, has: %d) dock\n", focus_count, win_dock.is_active ? 1 : 0); } else if(!is_dock) { if(win_dock.is_active) { win_dock.hide_all(); stdout.printf("Hide (focus: %d, has: %d) !dock\n", focus_count, win_dock.is_active ? 1 : 0); } else { stdout.printf("Nop (focus: %d, has: %d) !dock\n", focus_count, win_dock.is_active ? 1 : 0); } } } public static int main (string[] args) { Gtk.init (ref args); Main m = new Main(); m.start(); return 0; } } </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload