how can a GTK application get Xconnection?



Hello GTK's friends! 

   How can I fork a graphical GTK application? 
   I've a GTK application only with a label and a button. The button's 
callback function calls fork, and when in child process, it builds again all 
the graphical interface (calling gtk_init too). 
   When I click at "fork" button I saw the two applications with their 
windows, but they don't answer to any event, and I get the following error: 
Xlib: unexpected async reply (sequence 0x254)! 
Gdk-ERROR **: BadWindow (invalid Window parameter) 
  serial 718 error_code 3 request_code 4 minor_code 0 
Gdk-ERROR **: BadWindow (invalid Window parameter) 
  serial 732 error_code 3 request_code 4 minor_code 0 
bash-2.05a# Gdk-ERROR **: BadWindow (invalid Window parameter) 
  serial 717 error_code 3 request_code 10 minor_code 0 

   I think that can be something with Xserver connection! 

   Bellow i put the code: 

#include <gtk-1.2/gtk/gtk.h> 
#include <unistd.h> 
#include <stdio.h> 

struct command_line_data 
{ 
  int *i;			/* Save argc's address*/ 
  char **arg;			/* Save argv's address*/ 
} line_command_argument;     /* Save the command line contents */ 

void button_new_click(GtkButton *button, gpointer data) 
{ 
  int j; 
  void create_interface(); 
  if ( !fork() )		/* create a new interface for child process */ 
    create_interface(line_command_argument.i, &line_command_argument.arg); 
} 

void create_interface(int *i, char **arg) 
{ 
  int j; 
  GtkWidget *window; 
  GtkWidget *hbox; 
  GtkWidget *button_new; 
  GtkWidget *label; 
  char string[12]; 

  gtk_init(i, &arg); 

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 
  gtk_signal_connect(GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC 
(gtk_main_quit), NULL); 

  hbox = gtk_hbox_new(FALSE, 0); 
  gtk_container_add(GTK_CONTAINER (window), hbox); 
  gtk_widget_show(hbox); 

  sprintf(string, "PID: %d", (int) getpid()); 
  label = gtk_label_new(string); 
  gtk_box_pack_start(GTK_BOX (hbox), label, TRUE, TRUE, 5); 
  gtk_widget_show(label); 

  button_new = gtk_button_new_with_label("Fork!"); 
  gtk_signal_connect(GTK_OBJECT (button_new), "clicked", GTK_SIGNAL_FUNC 
(button_new_click), NULL); 
  gtk_box_pack_start(GTK_BOX (hbox), button_new, TRUE, TRUE, 5); 
  gtk_widget_show(button_new); 

  gtk_widget_show(window); 
} 


int main(int argc, char *argv[]) 
{ 
  int i; 
  line_command_argument.i = &argc; 
  line_command_argument.arg = argv; 
  create_interface(&argc, argv); 
  gtk_main(); 
} 

    I hope someone could help me, 

                                                 Thank you!! 

                                                Vinicius M. R 


_________________________________________________________
Voce quer um iGMail protegido contra vírus e spams? 
Clique aqui: http://www.igmailseguro.ig.com.br




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