Focus weirdness



Hi,

I'm having a weird focus problem with an xterm embedded in a GtkDrawingArea.
When I put the main application on sleep, the xterm can get the focus.
Otherwise, it can't.

Could somebody suggest me a way to allow the embedded xterm to get the focus
when the GtkDrawingArea gets it?

A minimal example follows. Move the focus in and out of the window. The main
application will be put on sleep for 3 seconds when the GtkDrawingArea gets
the focus. During these 3 seconds, you can type in the embedded xterm. When
the main application wakes up, the embedded xterm loses the focus.

Thanks in advance for any help!

David

-------------------------------------------------

FILE: minex.c

// gcc -o minex -Wall `pkg-config --cflags --libs gtk+-2.0` minex.c &&
./minex

#include <glib.h>
#include <glib/gprintf.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>


static void
destroy(GtkWidget *widget, gpointer data)
{
    gtk_main_quit();
}

static void
realize(GtkWidget *xterm_area, GdkEvent *event, gpointer data)
{
    char cmd[256];
    GError *err;

    g_sprintf(cmd, "xterm -into %lu",
GDK_WINDOW_XID(gtk_widget_get_window(xterm_area)));
    g_spawn_command_line_async(cmd, &err);
}

static gboolean
focus_in_event(GtkWidget *xterm_area, GdkEventFocus *event, gpointer data)
{
    g_print("focus in\n");
    g_usleep(3ul * 1000000ul);
    return FALSE;
}

int
main(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *xterm_area;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy),
NULL);

    xterm_area = gtk_drawing_area_new();
    gtk_container_add(GTK_CONTAINER(window), xterm_area);

    gtk_widget_set_size_request(GTK_WIDGET(xterm_area), 484, 316);
    gtk_widget_show(xterm_area);

    GTK_WIDGET_SET_FLAGS(xterm_area, GTK_CAN_FOCUS);

    g_signal_connect(G_OBJECT(xterm_area), "realize", G_CALLBACK(realize),
NULL);
    g_signal_connect(G_OBJECT(xterm_area), "focus-in-event",
G_CALLBACK(focus_in_event), NULL);

    gtk_widget_show(window);
    gtk_main();

    return 0;
}



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