Example #1
0
void gui_poll(bool active)
{
	CURLMcode code;
	fd_set read_fd_set, write_fd_set, exc_fd_set;
	int max_fd;
	GPollFD *fd_list[1000];
	unsigned int fd_count = 0;
	bool block = true;

	schedule_run();
	
	if (browser_reformat_pending)
		block = false;

	if (active) {
		FD_ZERO(&read_fd_set);
		FD_ZERO(&write_fd_set);
		FD_ZERO(&exc_fd_set);
		code = curl_multi_fdset(fetch_curl_multi,
				&read_fd_set,
				&write_fd_set,
				&exc_fd_set,
				&max_fd);
		assert(code == CURLM_OK);
		for (int i = 0; i <= max_fd; i++) {
			if (FD_ISSET(i, &read_fd_set)) {
				GPollFD *fd = malloc(sizeof *fd);
				fd->fd = i;
				fd->events = G_IO_IN | G_IO_HUP | G_IO_ERR;
				g_main_context_add_poll(0, fd, 0);
				fd_list[fd_count++] = fd;
			}
			if (FD_ISSET(i, &write_fd_set)) {
				GPollFD *fd = malloc(sizeof *fd);
				fd->fd = i;
				fd->events = G_IO_OUT | G_IO_ERR;
				g_main_context_add_poll(0, fd, 0);
				fd_list[fd_count++] = fd;
			}
			if (FD_ISSET(i, &exc_fd_set)) {
				GPollFD *fd = malloc(sizeof *fd);
				fd->fd = i;
				fd->events = G_IO_ERR;
				g_main_context_add_poll(0, fd, 0);
				fd_list[fd_count++] = fd;
			}
		}
	}

	gtk_main_iteration_do(block);

	for (unsigned int i = 0; i != fd_count; i++) {
		g_main_context_remove_poll(0, fd_list[i]);
		free(fd_list[i]);
	}

	schedule_run();

	if (browser_reformat_pending)
		nsgtk_window_process_reformats();
}
Example #2
0
void
gui_poll(bool active)
{
  CURLMcode code;
  fd_set read_fd_set, write_fd_set, exc_fd_set;
  int max_fd;
  GPollFD *fd_list[1000];
  unsigned int fd_count = 0;
  bool block = true;
        
  schedule_run();

  if (browser_reformat_pending)
    block = false;

  if (active) {
    FD_ZERO(&read_fd_set);
    FD_ZERO(&write_fd_set);
    FD_ZERO(&exc_fd_set);
    code = curl_multi_fdset(fetch_curl_multi,
                            &read_fd_set,
                            &write_fd_set,
                            &exc_fd_set,
                            &max_fd);
    assert(code == CURLM_OK);
    LOG(("maxfd from curl is %d", max_fd));
    for (int i = 0; i <= max_fd; i++) {
      if (FD_ISSET(i, &read_fd_set)) {
        GPollFD *fd = malloc(sizeof *fd);
        fd->fd = i;
        fd->events = G_IO_IN | G_IO_HUP | G_IO_ERR;
        g_main_context_add_poll(0, fd, 0);
        fd_list[fd_count++] = fd;
        LOG(("Want to read %d", i));
      }
      if (FD_ISSET(i, &write_fd_set)) {
        GPollFD *fd = malloc(sizeof *fd);
        fd->fd = i;
        fd->events = G_IO_OUT | G_IO_ERR;
        g_main_context_add_poll(0, fd, 0);
        fd_list[fd_count++] = fd;
        LOG(("Want to write %d", i));
      }
      if (FD_ISSET(i, &exc_fd_set)) {
        GPollFD *fd = malloc(sizeof *fd);
        fd->fd = i;
        fd->events = G_IO_ERR;
        g_main_context_add_poll(0, fd, 0);
        fd_list[fd_count++] = fd;
        LOG(("Want to check %d", i));
      }
    }
  }
  
  LOG(("Iterate %sactive %sblocking", active?"":"in", block?"":"non-"));
  if (block) {
    fprintf(stdout, "GENERIC POLL BLOCKING\n");
  }
  g_main_context_iteration(g_main_context_default(), block);

  for (unsigned int i = 0; i != fd_count; i++) {
    g_main_context_remove_poll(0, fd_list[i]);
    free(fd_list[i]);
  }

  schedule_run();

  if (browser_reformat_pending)
    monkey_window_process_reformats();
}
Example #3
0
GtkWidget*
gtk_xtbin_new (GdkWindow *parent_window, String * f)
{
  GtkXtBin *xtbin;
  gpointer user_data;

  assert(parent_window != NULL);
  xtbin = g_object_new (GTK_TYPE_XTBIN, NULL);

  if (!xtbin)
    return (GtkWidget*)NULL;

  if (f)
    fallback = f;

  /* Initialize the Xt toolkit */
  xtbin->parent_window = parent_window;

  xt_client_init(&(xtbin->xtclient), 
      GDK_VISUAL_XVISUAL(gdk_rgb_get_visual()),
      GDK_COLORMAP_XCOLORMAP(gdk_rgb_get_colormap()),
      gdk_rgb_get_visual()->depth);

  if (!xtbin->xtclient.xtdisplay) {
    /* If XtOpenDisplay failed, we can't go any further.
     *  Bail out.
     */
#ifdef DEBUG_XTBIN
    printf("gtk_xtbin_init: XtOpenDisplay() returned NULL.\n");
#endif
    g_free (xtbin);
    return (GtkWidget *)NULL;
  }

  /* If this is the first running widget, hook this display into the
     mainloop */
  if (0 == num_widgets) {
    int           cnumber;
    /*
     * hook Xt event loop into the glib event loop.
     */

    /* the assumption is that gtk_init has already been called */
    GSource* gs = g_source_new(&xt_event_funcs, sizeof(GSource));
      if (!gs) {
       return NULL;
      }
    
    g_source_set_priority(gs, GDK_PRIORITY_EVENTS);
    g_source_set_can_recurse(gs, TRUE);
    tag = g_source_attach(gs, (GMainContext*)NULL);
#ifdef VMS
    cnumber = XConnectionNumber(xtdisplay);
#else
    cnumber = ConnectionNumber(xtdisplay);
#endif
    xt_event_poll_fd.fd = cnumber;
    xt_event_poll_fd.events = G_IO_IN; 
    xt_event_poll_fd.revents = 0;    /* hmm... is this correct? */

    g_main_context_add_poll ((GMainContext*)NULL, 
                             &xt_event_poll_fd, 
                             G_PRIORITY_LOW);
    /* add a timer so that we can poll and process Xt timers */
    xt_polling_timer_id =
      g_timeout_add(25,
                    (GtkFunction)xt_event_polling_timer_callback,
                    xtdisplay);
  }

  /* Bump up our usage count */
  num_widgets++;

  /* Build the hierachy */
  xtbin->xtdisplay = xtbin->xtclient.xtdisplay;
  gtk_widget_set_parent_window(GTK_WIDGET(xtbin), parent_window);
  gdk_window_get_user_data(xtbin->parent_window, &user_data);
  if (user_data)
    gtk_container_add(GTK_CONTAINER(user_data), GTK_WIDGET(xtbin));

  /* This GtkSocket has a visible window, but the Xt plug will cover this
   * window.  Normally GtkSockets let the X server paint their background and
   * this would happen immediately (before the plug is mapped).  Setting the
   * background to None prevents the server from painting this window,
   * avoiding flicker.
   */
  gtk_widget_realize(GTK_WIDGET(xtbin));
  gdk_window_set_back_pixmap(GTK_WIDGET(xtbin)->window, NULL, FALSE);

  return GTK_WIDGET (xtbin);
}