summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-09-22 18:07:34 +0100
committerVincent Sanders <vince@kyllikki.org>2014-09-22 18:11:39 +0100
commit79c6617cfb1b54b72f5c37631b4bb3a9c9afb16e (patch)
tree07588a70957c1d16bbeba33371f346676073103f
parenta8101a99ea48c1af23941a0322246cace3dfa69e (diff)
downloadnetsurf-79c6617cfb1b54b72f5c37631b4bb3a9c9afb16e.tar.gz
netsurf-79c6617cfb1b54b72f5c37631b4bb3a9c9afb16e.tar.bz2
move gtk to using its own main loop instead of core polling
-rw-r--r--gtk/gui.c85
1 files changed, 48 insertions, 37 deletions
diff --git a/gtk/gui.c b/gtk/gui.c
index 9fa152a5c..eefb03a9c 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -79,6 +79,7 @@
#include "gtk/selection.h"
#include "gtk/search.h"
+bool nsgtk_complete = false;
char *toolbar_indices_file_location;
char *res_dir_location;
@@ -484,49 +485,60 @@ static bool nslog_stream_configure(FILE *fptr)
}
-
-static void nsgtk_poll(bool active)
+/**
+ * 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 = 0;
- bool block = true;
-
- fetcher_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;
+ 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);
+
+ fetcher_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();
+ schedule_run();
- gtk_main_iteration_do(block);
+ 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]);
+ for (unsigned int i = 0; i != fd_count; i++) {
+ g_main_context_remove_poll(0, fd_list[i]);
+ free(fd_list[i]);
+ }
}
-
}
@@ -1229,7 +1241,6 @@ static nserror nsgtk_option_init(int *pargc, char** argv)
}
static struct gui_browser_table nsgtk_browser_table = {
- .poll = nsgtk_poll,
.schedule = nsgtk_schedule,
.quit = gui_quit,
@@ -1260,7 +1271,7 @@ int main(int argc, char** argv)
ret = netsurf_register(&nsgtk_table);
if (ret != NSERROR_OK) {
- die("NetSurf operation table failed registration");
+ die("NetSurf operation table failed registration\n");
}
/* build the common resource path list */
@@ -1322,7 +1333,7 @@ int main(int argc, char** argv)
fprintf(stderr, "NetSurf gtk specific initialise failed (%s)\n",
messages_get_errorcode(ret));
} else {
- netsurf_main_loop();
+ nsgtk_main();
}
/* common finalisation */