Web lists-archives.com

How to avoid "window is ready" notification when receiving an activate signal?




Hi Folks

TL;DR:
I'm using the GtkApplication "activate" signal to display a window. However sometimes the "window is ready" notification appears instead. See example code at the bottom of this email. Could you please let me know what am I missing? 

Long version:

I'm new to gtk+ and as my first real application I'm coding a guake like terminal. I'm using GtkApplication where the terminal window is created inside the "startup" callback and later shown by the "activate" callback. 

This way my user can create a keyboard shortcut (F12 for example) that launches the application. If another instance of the application is already running the terminal window is toggled (hide/show) by the "activate" callback. 

However after launching the application a couple of times to hide/show the window the gnome "window is ready" notification is shown instead. Looks like DBus got confused or (most likely) I'm doing something terribly wrong. 

I noticed that if I change the window hint to GDK_WINDOW_TYPE_HINT_SPLASHSCREEN (commented in the code below) it solves the problem but this is just a workaround and I want to understand what is really happening. 

Below you can see a short code example in case you want to try it for yourself. Just run the application multiple times to see the window hide and show until the "window is ready" notification is displayed. 

Example code: 

/*
 * Compile: gcc toggle_window.c -o toggle_window `pkg-config --cflags --libs gtk+-3.0`
 */
#include <gtk/gtk.h>

typedef struct app_state {
GtkWidget *window;
gboolean window_is_visible;
} app_state;

static void startup (GApplication *app, gpointer data)
{
app_state *state = (app_state *) data;
state->window = gtk_application_window_new (GTK_APPLICATION (app));
state->window_is_visible = FALSE;
/* gtk_window_set_type_hint (GTK_WINDOW (state->window),
  GDK_WINDOW_TYPE_HINT_SPLASHSCREEN); */
}

static void activate (GApplication *app, gpointer data)
{
app_state *state = (app_state *) data;

/* Toggle window visibility */
if (state->window_is_visible) {
gtk_widget_hide (state->window);
state->window_is_visible = FALSE;
} else {
gtk_window_present (GTK_WINDOW (state->window));
state->window_is_visible = TRUE;
}
}

int main (int argc, char **argv)
{
GtkApplication *app = gtk_application_new ("org.example.toggle.window",
   G_APPLICATION_FLAGS_NONE);
app_state state = {0};
g_signal_connect (app, "startup", G_CALLBACK (startup), &state);
g_signal_connect (app, "activate", G_CALLBACK (activate), &state);
return g_application_run (G_APPLICATION (app), argc, argv);
}


Many thanks,
Eduardo


_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list