Re: [gedit-list] Focus problem



Hi,
	I think this patch should do what you want:

--- test.orig.c	2008-11-30 20:40:21.000000000 -0500
+++ test.c	2008-11-30 20:49:57.000000000 -0500
@@ -78,7 +78,11 @@
 	{
 	  gtk_widget_show_all(popup);
 	  focus_window(window);
-          
+	  g_debug("unfocus al popup");
+	  set_focus = FALSE;
+	  focus_window(window);
+	  gtk_widget_grab_focus(view);
+	  gtk_window_set_decorated(GTK_WINDOW(popup),FALSE);
 	  //g_timeout_add(2000,focus_window,window);
 	}
     }
@@ -86,10 +90,22 @@
     {
       if (GTK_WIDGET_VISIBLE(GTK_WIDGET(popup)))
 	{
-	  g_debug("focus al popup");
-	  set_focus = TRUE;
-	  focus_window(popup);
-	  gtk_widget_grab_focus(popup_view);
+	  if (set_focus == FALSE)
+	    {
+	      g_debug("focus al popup");
+	      set_focus = TRUE;
+	      focus_window(popup);
+	      gtk_widget_grab_focus(popup_view);
+	      gtk_window_set_decorated(GTK_WINDOW(popup),TRUE);
+	    }
+	  else
+	    {
+	      g_debug("unfocus al popup");
+	      set_focus = FALSE;
+	      focus_window(window);
+	      gtk_widget_grab_focus(view);
+	      gtk_window_set_decorated(GTK_WINDOW(popup),FALSE);
+	    }
 	}
     }
   
@@ -103,7 +119,7 @@
   gtk_window_set_transient_for(GTK_WINDOW(popup),GTK_WINDOW(window));
   gtk_window_set_focus_on_map(GTK_WINDOW(popup), FALSE);
   gtk_window_set_type_hint(GTK_WINDOW(popup),
-			   GDK_WINDOW_TYPE_HINT_TOOLTIP);
+			   GDK_WINDOW_TYPE_HINT_NORMAL);
   gtk_window_set_decorated(GTK_WINDOW(popup),FALSE);
   gtk_container_set_border_width(GTK_CONTAINER(popup),2);
   gtk_window_resize(GTK_WINDOW(popup),200,200);
@@ -112,6 +128,8 @@
   gtk_container_add(GTK_CONTAINER(scroll),popup_view);
   gtk_container_add(GTK_CONTAINER(popup),scroll);
   
+  g_signal_connect(popup, "key-release-event",
+		   G_CALLBACK(key_press), NULL); 
   /*g_signal_connect(popup, "show", G_CALLBACK(show_cb), NULL);
     g_signal_connect(popup, "realize", G_CALLBACK(realize_cb),
     NULL); g_signal_connect(popup, "map", G_CALLBACK(map_cb), NULL);


Summary of changes:
1.  set type hint to be 'normal' instead of 'tooltip'
2.  connect up key-release-event to popup also, so when it has focus we
can get out of it
3.  on f6, only grab focus if we don't have it and add decorations
4.  if we do have it, return focus to main window and remove decorations
5.  if we hide popup while it has focus, remove decorations and focus

So, you open the app and the main window has focus.  Pressing F5 will
show the popup, but focus will remain with the main window.  Pressing F5
again will hide it.  If F6 is pressed while the popup is open, it will
grab focus and become decorated.  While it has focus, it can remove
decorations and pass focus back via F6.  F5 also returns focus and
removes decorations, but also hides the window.  If this is not the
desired behavior, let me know and I'll see if I can help.

P.S.
I'm not sure what you're trying to do with gtk_window_set_default, but
it isn't doing anything... I get:

(test:19164): Gtk-CRITICAL **: gtk_window_set_default: assertion
`GTK_WIDGET_CAN_DEFAULT (default_widget)' failed

at runtime.  devhelp says:
Before making a widget the default widget, you must set the
GTK_CAN_DEFAULT flag on the widget you'd like to make the default using
GTK_WIDGET_SET_FLAGS().
However, I'm not sure you need the call in the first place to achieve
your desired behavior.

-Larry Reaves
<larry yrral net>



On Mon, 2008-12-01 at 00:47 +0100, Perriman wrote:
> Hi all,
> 
> 	I want to create a GTK_WINDOW_POPUP and change the type
> to GTK_WINDOW_TOPLEVEL. 
> 
> 	If you have used eclipse, when you are writting you can see a
> calltip (but the focus is in the editor) and if you press F2, then the
> calltip window gets the focus and show the decoration.
> 
> 	I'm trying for two weeks and I cannot do the same in the
> example program. If I set GTK_WINDOW_POPUP then I cannot set the focus
> to the window and, If I use GTK_WINDOW_TOPLEVEL then the window lost
> the focus. If I show the popup window and set the focus to the main
> window, it does not work... I'm desperated....
> 
> Can you help me?
> 
> Thank you again!!
> 
> El Sun, 30 Nov 2008 23:37:29 +0100
> Perriman <chuchiperriman gmail com> escribió:
> 
> > Hi Michael
> > 
> > I paste the code:
> > 
> > #include <gtk/gtk.h>
> > #include <gdk/gdkkeysyms.h>
> > 
> > static GtkWidget *window;
> > static GtkWidget *view;
> > static GtkWidget *popup;
> > static GtkWidget *popup_view;
> > static gboolean set_focus = FALSE;
> > 
> > static void
> > destroy_cb(GtkObject *object,gpointer   user_data)
> > {
> > 	gtk_main_quit ();
> > }
> > 
> > static gboolean
> > focus_window(gpointer win)
> > {
> > 	g_debug("focus win");
> > 	gtk_window_present_with_time(GTK_WINDOW(win),GDK_CURRENT_TIME);
> > 	gtk_window_activate_focus(GTK_WINDOW(win));
> > 	gtk_widget_grab_focus(GTK_WIDGET(win));
> > 	return FALSE;
> > }
> > 
> > 
> > static void
> > show_cb(GtkWidget *widget, gpointer user_data)
> > {
> > 	g_debug("show popup");
> > 	focus_window(window);
> > }
> > 
> > static void
> > realize_cb(GtkWidget *widget, gpointer user_data)
> > {
> > 	g_debug("realize popup");
> > 	focus_window(window);
> > }
> > 
> > static void
> > focus_in_cb(GtkWidget *widget, gpointer user_data)
> > {
> > 	g_debug("focus-in");
> > 	//focus_window(window);
> > }
> > 
> > static void
> > focus_out_win_cb(GtkWidget *widget, gpointer user_data)
> > {
> > 	g_debug("focus-out-win");
> > /*	if (!set_focus)
> > 		focus_window(window);
> > 	else
> > 		set_focus = FALSE;
> > */
> > }
> > 
> > static void
> > map_cb(GtkWidget *widget, gpointer user_data)
> > {
> > 	g_debug("map popup");
> > 	focus_window(window);
> > }
> > 
> > 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);
> > 			focus_window(window);
> > 			
> > 			//g_timeout_add(2000,focus_window,window);
> > 		}
> > 	}
> > 	else if (event->keyval == GDK_F6)
> > 	{
> > 		if (GTK_WIDGET_VISIBLE(GTK_WIDGET(popup)))
> > 		{
> > 			g_debug("focus al popup");
> > 			set_focus = TRUE;
> > 			focus_window(popup);
> > 			gtk_widget_grab_focus(popup_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_set_type_hint(GTK_WINDOW(popup),
> > 		GDK_WINDOW_TYPE_HINT_TOOLTIP);
> > 	gtk_window_set_decorated(GTK_WINDOW(popup),FALSE);
> > 	gtk_container_set_border_width(GTK_CONTAINER(popup),2);
> > 	gtk_window_resize(GTK_WINDOW(popup),200,200);
> > 	popup_view = gtk_text_view_new();
> > 	GtkWidget *scroll = gtk_scrolled_window_new(NULL,NULL);
> > 	gtk_container_add(GTK_CONTAINER(scroll),popup_view);
> > 	gtk_container_add(GTK_CONTAINER(popup),scroll);
> > 	
> > 	/*g_signal_connect(popup, "show", G_CALLBACK(show_cb), NULL);
> > 	g_signal_connect(popup, "realize", G_CALLBACK(realize_cb),
> > NULL); g_signal_connect(popup, "map", G_CALLBACK(map_cb), NULL);
> > 	g_signal_connect(popup, "focus-in-event",
> > G_CALLBACK(focus_in_cb), NULL); */
> > 	
> > 	return popup;
> > }
> > 
> > GtkWidget*
> > create_window (void)
> > {
> > 	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
> > 	gtk_window_resize(GTK_WINDOW(window),800,600);
> > 	view = gtk_text_view_new();
> > 	gtk_window_set_default(GTK_WINDOW(window),view);
> > 	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); g_signal_connect(window, "focus-out-event",
> > G_CALLBACK(focus_out_win_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;
> > }
> > 
> > 
> > 
> > 
> > 
> > El Sat, 29 Nov 2008 16:50:09 -0600
> > Michael Cronenworth <mike cchtml com> escribió:
> > 
> > > Perriman wrote:
> > > >
> > > > Can you help me?? (I attach the example)
> > > >
> > > >
> > > >   
> > > 
> > > Sorry, I don't see the example.
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



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