[gedit-list] Focus problem



Hi all,

	I have a problem with the window focus. I have a main window
and a second window. I want to show the second window always on top but
set the focus in the main window. I'm setted this in the second window:

gtk_window_set_transient_for(GTK_WINDOW(popup),GTK_WINDOW(window));
gtk_window_set_focus_on_map(GTK_WINDOW(popup), FALSE);

But when I show the second window, the focus is losed. The main window
has not the focus and the second window neither.

If I try to set the focus on the main window with 

gtk_window_present(GTK_WINDOW(window));
gtk_window_activate_focus(GTK_WINDOW(window));
gtk_widget_grab_focus(GTK_WIDGET(view));

Only works the first time I show the second window.

I think it's a gtk bug or a window manager bug... 

Can you help me?? (I attach the example)

I'm using ubuntu 8.10 with gnome.

Regards,
	Perriman
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <gtksourceview/gtksourceview.h>

static GtkWidget *window;
static GtkWidget *view;
static GtkWidget *popup;

static void
destroy_cb(GtkObject *object,gpointer   user_data)
{
	gtk_main_quit ();
}


static gboolean
key_press(GtkWidget   *widget,
	GdkEventKey *event,
	gpointer     user_data)
{
	if (event->keyval == GDK_F5)
	{
		if (GTK_WIDGET_VISIBLE(GTK_WIDGET(popup)))
		{
			gtk_widget_hide(popup);
		}
		else
		{
			gtk_widget_show_all(popup);
			gtk_window_present(GTK_WINDOW(window));
			gtk_window_activate_focus(GTK_WINDOW(window));
			gtk_widget_grab_focus(GTK_WIDGET(view));
		}
	}

	return FALSE;
}

GtkWidget*
create_popup (void)
{
	popup = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_transient_for(GTK_WINDOW(popup),GTK_WINDOW(window));
	gtk_window_set_focus_on_map(GTK_WINDOW(popup), FALSE);
	gtk_window_resize(GTK_WINDOW(popup),200,200);
	GtkWidget *view = gtk_source_view_new();
	GtkWidget *scroll = gtk_scrolled_window_new(NULL,NULL);
	gtk_container_add(GTK_CONTAINER(scroll),view);
	gtk_container_add(GTK_CONTAINER(popup),scroll);
	
	
	return popup;
}

GtkWidget*
create_window (void)
{
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_resize(GTK_WINDOW(window),800,600);
	view = gtk_source_view_new();
	GtkWidget *scroll = gtk_scrolled_window_new(NULL,NULL);
	gtk_container_add(GTK_CONTAINER(scroll),view);
	gtk_container_add(GTK_CONTAINER(window),scroll);
	g_signal_connect(view, "key-release-event", G_CALLBACK(key_press), NULL);
	
	g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL);
	
	return window;
}

int
main (int argc, char *argv[])
{
 	GtkWidget *window;
	
	gtk_set_locale ();
	gtk_init (&argc, &argv);

	window = create_window ();
	popup = create_popup();
	gtk_widget_show_all (window);

	gtk_main ();
	return 0;
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]