KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have developed one popup window (Non decorated) using GTK+ and glade tool in C. It popup on its parent window when a button clicked. I want to destroy or hide this popup window when user clicks out side this window. User can click on parent window or any other window. I have tried to capture GDK_FOCUS_CHANGE event but I am not able to capture this event. Is there any way to achieve this? How do I know that click is on other window then pop up window? How is it clear that pop up window has lost it's focus? So that I can hide it. The relevant code is as follow: /* * Compile me with: gcc -o popup popup.c $(pkg-config --cflags --libs gtk+-2.0 gmodule-2.0) */ #include <gtk/gtk.h> static void on_popup_clicked (GtkButton*, GtkWidget*); static gboolean on_popup_window_event(GtkWidget*, GdkEventExpose*); int main (int argc, char *argv[]) { GtkWidget *window, *button, *vbox; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "Parent window"); gtk_container_set_border_width (GTK_CONTAINER (window), 10); gtk_widget_set_size_request (window, 300, 300); gtk_window_set_position (GTK_WINDOW (window),GTK_WIN_POS_CENTER); button = gtk_button_new_with_label("Pop Up"); g_signal_connect (G_OBJECT (button), "clicked",G_CALLBACK (on_popup_clicked),(gpointer) window); vbox = gtk_vbox_new (FALSE, 3); gtk_box_pack_end(GTK_BOX (vbox), button, FALSE, FALSE, 5); gtk_container_add (GTK_CONTAINER (window), vbox); gtk_widget_show_all (window); gtk_main (); return 0; } void on_popup_clicked (GtkButton* button, GtkWidget* pWindow) { GtkWidget *popup_window; popup_window = gtk_window_new (GTK_WINDOW_POPUP); gtk_window_set_title (GTK_WINDOW (popup_window), "Pop Up window"); gtk_container_set_border_width (GTK_CONTAINER (popup_window), 10); gtk_window_set_resizable(GTK_WINDOW (popup_window), FALSE)
Tags (comma-separated)
Save Edits
Cancel