A question about GtkSocket confusing me for a long time



Hi All:

A GtkSocket problem confused me for a long time.
By all ways I can not solve the problem, so I post it in this mail
list to find help from gtk experts.
Thanks lot.

Here is the source code:

static pid_t kbd_pid;
static const char *xkbd_path = "xkbd";
static guint xkbd_xid = 0;
static void
spawn_xkbd (void)
{
    int fd[2];

    pipe (fd);
    kbd_pid = fork ();

    if (kbd_pid == 0)
    {
        char *xkbd_args[MAX_ARGS + 1];

        printf ("\bthe xkdb_xid is:%d\n", xkbd_xid);
        close (fd[0]);

        if (dup2 (fd[1], 1) < 0)
            perror ("dup2");
        close (fd[1]);

        if (fcntl (1, F_SETFD, 0))
            perror ("fcntl");

        xkbd_args[0] = (char *)xkbd_path;
        xkbd_args[1] = "-xid";
        xkbd_args[2] = NULL;

        execvp (xkbd_path, xkbd_args);
        perror (xkbd_path);
        _exit (1);
    }

    close (fd[1]);

    {
        char buf[256];
        char c;
        unsigned int a = 0;
        size_t n;

        do {
            n = read (fd[0], &c, 1);

            if (n)
            {
                buf[a++] = c;
            }
        } while (n && (c != 10) && (a < (sizeof (buf) - 1)));

        printf ("\bthe xkdb_xid is:%d\n", xkbd_xid);

        if (a)
        {
            buf[a] = 0;
            xkbd_xid = atoi (buf);
            printf ("\bthe xkdb_xid is:%d\n", xkbd_xid);
        }
    }
}

my_function ()
{
    spawn_xkbd (void)
    m_main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_size_request (m_main_window, 240, 320 -
				 Global::get_top_panel_height ());
    gtk_window_move (GTK_WINDOW (m_main_window), 0,
		     Global::get_top_panel_height ());
    gtk_widget_hide (m_main_window);

    m_vbox = gtk_vbox_new (FALSE, 0);
    gtk_widget_set_size_request (m_vbox, 240, 320 -
				 Global::get_top_panel_height ());
    gtk_container_add (GTK_CONTAINER (m_main_window), m_vbox);
    gtk_widget_show_all (m_vbox);


    socket = gtk_socket_new ();
    gtk_container_add (GTK_CONTAINER (m_vbox), socket);
    gtk_widget_show (socket);

    if (xkbd_xid && socket)
    {
        gtk_socket_add_id (GTK_SOCKET (socket), xkbd_xid);
    }

    gtk_widget_show (socket);
    gtk_widget_show_all (m_vbox);
}


*******************************************************************************************

when the source code run into :  gtk_socket_add_id (GTK_SOCKET
(socket), xkbd_xid);

An error is printed out:
(palmtopen-sms:1326): Gtk-WARNING **: Calling gtk_widget_realize() on
a widget that isn't inside a toplevel window is not going to work very
well. Widgets .
and the programm crashed.


*******************************************************************************************
Event without the "gtk_socket_add_id ()" and "spawn_xkbd () ", the
following a few lines will result the same WARNING and broken:


    socket = gtk_socket_new ();
    gtk_container_add (GTK_CONTAINER (m_vbox), socket);
    gtk_widget_show (socket);
    gtk_widget_realize (socket);  // WARNING and broken here.

the same WARNING,
(palmtopen-sms:1326): Gtk-WARNING **: Calling gtk_widget_realize() on
a widget that isn't inside a toplevel window is not going to work very
well. Widgets .


Who can give some help?
Thanks in advance.

topen



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