Re: [gedit-list] Focus problem
- From: Perriman <chuchiperriman gmail com>
- To: Larry Reaves <larry yrral net>
- Cc: gedit-list <gedit-list gnome org>, Gtk app list <gtk-app-devel-list gnome org>
- Subject: Re: [gedit-list] Focus problem
- Date: Mon, 1 Dec 2008 20:03:17 +0100
Hi Larry,
Thank a lo for you patch but it don't work for me :( I think
the problem is Metacity... Andrea get works without metacity and it
works on my xfce but not in my gnome with metacty (ubuntu 8.10)...
The code below works fine in metacity using your changes and
set_modal (thank Jesse and gedit) but I cannot show the decoration
because the popup is a GTK_WINDOW_POPUP :)
I'll try some changes to do it work on all environments
Regards,
Perriman
#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");
}
static void
focus_out_win_cb (GtkWidget * widget, gpointer user_data)
{
g_debug ("focus-out-win");
}
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_debug ("unfocus al popup");
set_focus = FALSE;
gtk_widget_grab_focus (view);
gtk_window_set_decorated (GTK_WINDOW (popup), FALSE);
}
}
else if (event->keyval == GDK_F6)
{
if (GTK_WIDGET_VISIBLE (GTK_WIDGET (popup)))
{
if (set_focus == FALSE)
{
g_debug ("focus al popup");
set_focus = TRUE;
gtk_window_set_modal(GTK_WINDOW (popup), 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;
gtk_window_set_modal(GTK_WINDOW (popup), FALSE);
focus_window (window);
gtk_widget_grab_focus (view);
gtk_window_set_decorated (GTK_WINDOW (popup), FALSE);
}
}
}
return FALSE;
}
GtkWidget *
create_popup (void)
{
popup = gtk_window_new (GTK_WINDOW_POPUP);
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_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);
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, "key-release-event", G_CALLBACK (key_press),
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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]