hide minimized window (C++,gtkmm)

Especially if you use a status icon you don’t want to have the window of your program minimized. It will eat space in your taskbar (in gnome3 the bar in the activity view) and needs to be handled.
To remove the icon you can use hide() but this must be triggered.
For this use on_my_window_state_event(GdkEventWindowState* event) and read the next state of the window out of GdkEventWindowState. Have a look for the valid states in
http://developer.gnome.org/gdk/stable/gdk-Event-Structures.html#GdkWindowState

Before I come to the examples a little hint for getting the window back. First use deiconify(), then show() elsewise the window is stucked in the invisibility state.
Now some gkmm,C++ examples:

The initialisation of the trigger to hide:

main_win->signal_window_state_event().connect (sigc::mem_fun(*this,&gui::on_my_window_state_event));

The trigger method:

bool gui::on_my_window_state_event(GdkEventWindowState* event)
{
    if (event->new_window_state==GDK_WINDOW_STATE_ICONIFIED)
    {    
        hide();
        return false;
    }
    else
        return false;
}

The restore method:

void gui::show()
{
    main_win->deiconify();
    main_win->show();
}

References:
http://developer.gnome.org/gtkmm/stable/classGtk_1_1Widget.html
http://developer.gnome.org/gdk/stable/gdk-Event-Structures.html

The project I used as example:
https://github.com/devkral/asaus  (my project)

Comment