Пример #1
0
/**
 * Run the gtk event loop.
 *
 * The same as the standard gtk_main loop except this ensures active
 * FD are added to the gtk poll event set.
 */
static void nsgtk_main(void)
{
	fd_set read_fd_set, write_fd_set, exc_fd_set;
	int max_fd;
	GPollFD *fd_list[1000];
	unsigned int fd_count;

	while (!nsgtk_complete) {
		max_fd = -1;
		fd_count = 0;
		FD_ZERO(&read_fd_set);
		FD_ZERO(&write_fd_set);
		FD_ZERO(&exc_fd_set);

		fetch_fdset(&read_fd_set, &write_fd_set, &exc_fd_set, &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;
			}
			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;
			}
		}

		schedule_run();

		gtk_main_iteration();

		for (unsigned int i = 0; i != fd_count; i++) {
			g_main_context_remove_poll(0, fd_list[i]);
			free(fd_list[i]);
		}
	}
}
Пример #2
0
void
xt_client_xloop_destroy(void)
{
  num_widgets--; /* reduce our usage count */

  /* If this is the last running widget, remove the Xt display
     connection from the mainloop */
  if (0 == num_widgets) {
#ifdef DEBUG_XTBIN
    printf("removing the Xt connection from the main loop\n");
#endif
    g_main_context_remove_poll((GMainContext*)NULL, &xt_event_poll_fd);
    g_source_remove(tag);

    g_source_remove(xt_polling_timer_id);
    xt_polling_timer_id = 0;
  }
}
Пример #3
0
static void
gtk_xtbin_destroy (GtkObject *object)
{
  GtkXtBin *xtbin;

#ifdef DEBUG_XTBIN
  printf("gtk_xtbin_destroy()\n");
#endif

  g_return_if_fail (object != NULL);
  g_return_if_fail (GTK_IS_XTBIN (object));

  xtbin = GTK_XTBIN (object);

  if(xtbin->xtwindow) {
    /* remove the event handler */
    xt_client_destroy(&(xtbin->xtclient));
    xtbin->xtwindow = 0;

    num_widgets--; /* reduce our usage count */

    /* If this is the last running widget, remove the Xt display
       connection from the mainloop */
    if (0 == num_widgets) {
#ifdef DEBUG_XTBIN
      printf("removing the Xt connection from the main loop\n");
#endif
      g_main_context_remove_poll((GMainContext*)NULL, &xt_event_poll_fd);
      g_source_remove(tag);

      gtk_timeout_remove(xt_polling_timer_id);
      xt_polling_timer_id = 0;
    }
  }

  GTK_OBJECT_CLASS(parent_class)->destroy(object);
}
Пример #4
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();
}
Пример #5
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();
}