Ejemplo n.º 1
0
void misc_test()
{
	GPollFunc func = g_main_context_get_poll_func(context);

	g_assert(func != NULL);

	g_main_context_set_poll_func(context,dummy_poll_func);
	func = g_main_context_get_poll_func(context);

	g_assert(func == dummy_poll_func);
}
Ejemplo n.º 2
0
static void
restore_poll_func(VALUE data)
{
    if (g_main_context_get_poll_func(NULL) == (GPollFunc)rbglib_poll) {
        g_main_context_set_poll_func(NULL, default_poll_func);
    }
}
Ejemplo n.º 3
0
nsresult
nsAppShell::Init()
{
#ifdef PR_LOGGING
    if (!gWidgetLog)
        gWidgetLog = PR_NewLogModule("Widget");
    if (!gWidgetFocusLog)
        gWidgetFocusLog = PR_NewLogModule("WidgetFocus");
    if (!gWidgetDragLog)
        gWidgetDragLog = PR_NewLogModule("WidgetDrag");
    if (!gWidgetDrawLog)
        gWidgetDrawLog = PR_NewLogModule("WidgetDraw");
#endif

    if (!sPollFunc) {
        sPollFunc = g_main_context_get_poll_func(NULL);
        g_main_context_set_poll_func(NULL, &PollWrapper);
    }

    if (PR_GetEnv("MOZ_DEBUG_PAINTS"))
        gdk_window_set_debug_updates(TRUE);

    int err = pipe(mPipeFDs);
    if (err)
        return NS_ERROR_OUT_OF_MEMORY;

    GIOChannel *ioc;
    GSource *source;

    // make the pipe nonblocking

    int flags = fcntl(mPipeFDs[0], F_GETFL, 0);
    if (flags == -1)
        goto failed;
    err = fcntl(mPipeFDs[0], F_SETFL, flags | O_NONBLOCK);
    if (err == -1)
        goto failed;
    flags = fcntl(mPipeFDs[1], F_GETFL, 0);
    if (flags == -1)
        goto failed;
    err = fcntl(mPipeFDs[1], F_SETFL, flags | O_NONBLOCK);
    if (err == -1)
        goto failed;

    ioc = g_io_channel_unix_new(mPipeFDs[0]);
    source = g_io_create_watch(ioc, G_IO_IN);
    g_io_channel_unref(ioc);
    g_source_set_callback(source, (GSourceFunc)EventProcessorCallback, this, nullptr);
    g_source_set_can_recurse(source, TRUE);
    mTag = g_source_attach(source, nullptr);
    g_source_unref(source);

    return nsBaseAppShell::Init();
failed:
    close(mPipeFDs[0]);
    close(mPipeFDs[1]);
    mPipeFDs[0] = mPipeFDs[1] = 0;
    return NS_ERROR_FAILURE;
}
Ejemplo n.º 4
0
gint
g_io_channel_win32_poll (GPollFD *fds,
			 gint     n_fds,
			 gint     timeout)
{
  int result;

  g_return_val_if_fail (n_fds >= 0, 0);

  result = (*g_main_context_get_poll_func (NULL)) (fds, n_fds, timeout);

  return result;
}
Ejemplo n.º 5
0
CAMLprim value lwt_glib_iter(value may_block)
{
  GMainContext *gc;
  gint max_priority, timeout;
  GPollFD *pollfds = NULL;
  gint pollfds_size = 0;
  gint nfds;
  gint i;

  /* Get the main context. */
  gc = g_main_context_default();

  /* Try to acquire it. */
  if (!g_main_context_acquire(gc))
    caml_failwith("Lwt_glib.iter");

  /* Dispatch pending events. */
  g_main_context_dispatch(gc);

  /* Prepare the context for polling. */
  g_main_context_prepare(gc, &max_priority);

  /* Get all file descriptors to poll. */
  while (pollfds_size < (nfds = g_main_context_query(gc, max_priority, &timeout, pollfds, pollfds_size))) {
    free(pollfds);
    pollfds_size = nfds;
    pollfds = lwt_unix_malloc(pollfds_size * sizeof (GPollFD));
  }

  /* Clear all revents fields. */
  for (i = 0; i < nfds; i++) pollfds[i].revents = 0;

  /* Set the timeout to 0 if we do not want to block. */
  if (!Bool_val(may_block)) timeout = 0;

  /* Do the blocking call. */
  caml_enter_blocking_section();
  g_main_context_get_poll_func(gc)(pollfds, nfds, timeout);
  caml_leave_blocking_section();

  /* Let glib parse the result. */
  g_main_context_check(gc, max_priority, pollfds, nfds);

  /* Release the context. */
  g_main_context_release(gc);

  free(pollfds);

  return Val_unit;
}
Ejemplo n.º 6
0
gint
gtk_module_init (gint   argc,
                 gchar *argv[])
{
	GDBusConnection *dbus;
	gchar *address;
	const gchar *socket;
	GError *error = NULL;

	ENTRY;

	if (!(socket = g_getenv("GDKEVENT_SOCKET"))) {
		CRITICAL(Gdk, "Failed to load gdkevent socket.");
		RETURN(-1);
	}

	address = g_strdup_printf("unix:path=%s", socket);
	dbus = g_dbus_connection_new_for_address_sync(address,
	                                              G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
	                                              NULL, NULL, &error);
	g_free(address);

	if (!dbus) {
		CRITICAL(Gdk, "Failed to load IPC socket: %s", error->message);
		g_error_free(error);
		RETURN(-1);
	}

	connection = dbus;

	gdk_event_handler_set(gdkevent_dispatcher, dbus,
	                      gdkevent_module_unloaded);

	g_get_current_time(&last_time);
	poll_func = g_main_context_get_poll_func(g_main_context_default());
	g_main_context_set_poll_func(g_main_context_default(), gdkevent_poll);

	RETURN(0);
}
Ejemplo n.º 7
0
int
main (int argc, char *argv[])
{
	const gchar *dir;
	GeditCommandLine *command_line;
	gboolean ret;
	gboolean service = FALSE;
#ifdef G_OS_UNIX
	GeditDBus *dbus;
	GeditDBusResult dbusret;
#endif

#ifdef OS_OSX
	GPollFunc orig_poll_func;
	GPollFunc gdk_poll_func;
#endif

#ifndef ENABLE_GVFS_METADATA
	const gchar *cache_dir;
	gchar *metadata_filename;
#endif

	/* Setup debugging */
	gedit_debug_init ();
	gedit_debug_message (DEBUG_APP, "Startup");

	/* Setup locale/gettext */
	setlocale (LC_ALL, "");

	gedit_dirs_init ();

	dir = gedit_dirs_get_gedit_locale_dir ();
	bindtextdomain (GETTEXT_PACKAGE, dir);

	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

#ifndef ENABLE_GVFS_METADATA
	/* Setup metadata-manager */
	cache_dir = gedit_dirs_get_user_cache_dir ();

	metadata_filename = g_build_filename (cache_dir, METADATA_FILE, NULL);

	gedit_metadata_manager_init (metadata_filename);

	g_free (metadata_filename);
#endif

#ifdef OS_OSX
	orig_poll_func = g_main_context_get_poll_func (NULL);
#endif

	/* Parse command line arguments */
	command_line = gedit_command_line_get_default ();

	ret = gedit_command_line_parse (command_line, &argc, &argv);

	if (!ret)
	{
		g_object_unref (command_line);
		return 1;
	}

#ifdef G_OS_UNIX
#ifdef OS_OSX
	/* Note: this is a bit of a hack. What happens here is that we are going to
	 * store the poll function installed by gdk (happens in post-parse of options)
	 * and replace it with the original main loop poll handler. We do this because
	 * the gedit dbus stuff is going to run some main loops to run async gdbus calls.
	 * The problem is that for OS X, the gdk poll func in the main context (which
	 * will be run due to the fact that the main loops in our dbus code iterate the
	 * main context) is going to process events from NSApp, INCLUDING apple events
	 * such as OpenFiles. Since we are not setup yet, we are going to miss these
	 * events. By swapping out the gdk poll func, and swapping it back in later,
	 * we prevent this from happening. Note that we only do this when building
	 * on OS X to prevent any possible future problems for other platforms.
	 * This is a dirty hack, but it works for now.
	 */
	gdk_poll_func = g_main_context_get_poll_func (NULL);
	g_main_context_set_poll_func (NULL, orig_poll_func);
#endif

	/* Run over dbus */
	dbus = gedit_dbus_new ();
	dbusret = gedit_dbus_run (dbus);

#ifdef OS_OSX
	g_main_context_set_poll_func (NULL, gdk_poll_func);
#endif

	switch (dbusret)
	{
		case GEDIT_DBUS_RESULT_SUCCESS:
		case GEDIT_DBUS_RESULT_FAILED: /* fallthrough */
			g_object_unref (command_line);
			g_object_unref (dbus);

			return dbusret == GEDIT_DBUS_RESULT_SUCCESS ? 0 : 1;
		break;
		case GEDIT_DBUS_RESULT_PROCEED_SERVICE:
			service = TRUE;
		break;
		case GEDIT_DBUS_RESULT_PROCEED:
		break;
	}
#endif

	gedit_main (service);

#ifdef G_OS_UNIX
	g_object_unref (dbus);
#endif
	g_object_unref (command_line);

	return 0;
}
Ejemplo n.º 8
0
CAMLprim value lwt_glib_poll(value val_fds, value val_count, value val_timeout)
{
  gint timeout, lwt_timeout;
  long count;
  int i;
  GPollFD *gpollfd;
  gint events, revents;

  CAMLparam3(val_fds, val_count, val_timeout);
  CAMLlocal5(node, src, node_result, src_result, tmp);

  count = Long_val(val_count);

  g_main_context_dispatch(gc);
  g_main_context_prepare(gc, &max_priority);

  while (fds_count < count + (n_fds = g_main_context_query(gc, max_priority, &timeout, gpollfds, fds_count))) {
    free(gpollfds);
    fds_count = n_fds + count;
    gpollfds = lwt_unix_malloc(fds_count * sizeof (GPollFD));
  }

  /* Clear all revents fields. */
  for (i = 0; i < n_fds + count; i++) gpollfds[i].revents = 0;

  /* Add all Lwt fds. */
  for (i = n_fds, node = val_fds; i < n_fds + count; i++, node = Field(node, 1)) {
    src = Field(node, 0);
    gpollfd = gpollfds + i;
#if defined(LWT_ON_WINDOWS)
    gpollfd->fd = Handle_val(Field(src, 0));
#else
    gpollfd->fd = Int_val(Field(src, 0));
#endif
    events = 0;
    if (Bool_val(Field(src, 1))) events |= G_IO_IN;
    if (Bool_val(Field(src, 2))) events |= G_IO_OUT;
    gpollfd->events = events;
  }

  lwt_timeout = Int_val(val_timeout);
  if (timeout < 0 || (lwt_timeout >= 0 && lwt_timeout < timeout))
    timeout = lwt_timeout;

  /* Do the blocking call. */
  caml_enter_blocking_section();
  g_main_context_get_poll_func(gc)(gpollfds, n_fds + count, timeout);
  caml_leave_blocking_section();

  g_main_context_check(gc, max_priority, gpollfds, n_fds);

  /* Build the result. */
  node_result = Val_int(0);
  for (i = n_fds, node = val_fds; i < n_fds + count; i++, node = Field(node, 1)) {
    gpollfd = gpollfds + i;
    src_result = caml_alloc_tuple(3);
    src = Field(node, 0);
    Field(src_result, 0) = Field(src, 0);
    revents = gpollfd->revents;
    if (revents & G_IO_HUP) {
      /* Treat HUP as ready. There's no point continuing to wait on this FD. */
      if (gpollfd->events & G_IO_IN)
        revents |= G_IO_IN;
      if (gpollfd->events & G_IO_OUT)
        revents |= G_IO_OUT;
    }
    Field(src_result, 1) = Val_bool(revents & G_IO_IN);
    Field(src_result, 2) = Val_bool(revents & G_IO_OUT);
    tmp = caml_alloc_tuple(2);
    Field(tmp, 0) = src_result;
    Field(tmp, 1) = node_result;
    node_result = tmp;
  }

  CAMLreturn(node_result);
}
Ejemplo n.º 9
0
bool wxApp::Initialize(int& argc, wxChar **argv)
{
    bool init_result;

#if wxUSE_THREADS
    if (!g_thread_supported())
        g_thread_init(NULL);

    wxgs_poll_func = g_main_context_get_poll_func(NULL);
    g_main_context_set_poll_func(NULL, wxapp_poll_func);
#endif // wxUSE_THREADS

    gtk_set_locale();

    // We should have the wxUSE_WCHAR_T test on the _outside_
#if wxUSE_WCHAR_T
    // gtk+ 2.0 supports Unicode through UTF-8 strings
    wxConvCurrent = &wxConvUTF8;
#else // !wxUSE_WCHAR_T
    if (!wxOKlibc())
        wxConvCurrent = (wxMBConv*) NULL;
#endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T

    // decide which conversion to use for the file names

    // (1) this variable exists for the sole purpose of specifying the encoding
    //     of the filenames for GTK+ programs, so use it if it is set
    wxString encName(wxGetenv(_T("G_FILENAME_ENCODING")));
    encName = encName.BeforeFirst(_T(','));
    if (encName.CmpNoCase(_T("@locale")) == 0)
        encName.clear();
    encName.MakeUpper();
#if wxUSE_INTL
    if (encName.empty())
    {
        // (2) if a non default locale is set, assume that the user wants his
        //     filenames in this locale too
        encName = wxLocale::GetSystemEncodingName().Upper();
        // (3) finally use UTF-8 by default
        if (encName.empty() || encName == _T("US-ASCII"))
            encName = _T("UTF-8");
        wxSetEnv(_T("G_FILENAME_ENCODING"), encName);
    }
#else
    if (encName.empty())
        encName = _T("UTF-8");
#endif // wxUSE_INTL

#if wxUSE_WCHAR_T
    static wxConvBrokenFileNames fileconv(encName);
    wxConvFileName = &fileconv;
#endif // wxUSE_WCHAR_T

#if wxUSE_UNICODE
    // gtk_init() wants UTF-8, not wchar_t, so convert
    int i;
    char **argvGTK = new char *[argc + 1];
    for ( i = 0; i < argc; i++ )
    {
        argvGTK[i] = wxStrdupA(wxConvUTF8.cWX2MB(argv[i]));
    }

    argvGTK[argc] = NULL;

    int argcGTK = argc;

#ifdef __WXGPE__
    init_result = true;  // is there a _check() version of this?
    gpe_application_init( &argcGTK, &argvGTK );
#else
    init_result = gtk_init_check( &argcGTK, &argvGTK );
#endif

    if ( argcGTK != argc )
    {
        // we have to drop the parameters which were consumed by GTK+
        for ( i = 0; i < argcGTK; i++ )
        {
            while ( strcmp(wxConvUTF8.cWX2MB(argv[i]), argvGTK[i]) != 0 )
            {
                memmove(argv + i, argv + i + 1, (argc - i)*sizeof(*argv));
            }
        }

        argc = argcGTK;
    }
    //else: gtk_init() didn't modify our parameters

    // free our copy
    for ( i = 0; i < argcGTK; i++ )
    {
        free(argvGTK[i]);
    }

    delete [] argvGTK;
#else // !wxUSE_UNICODE
    // gtk_init() shouldn't actually change argv itself (just its contents) so
    // it's ok to pass pointer to it
    init_result = gtk_init_check( &argc, &argv );
#endif // wxUSE_UNICODE/!wxUSE_UNICODE

    if (!init_result) {
        wxLogError(wxT("Unable to initialize gtk, is DISPLAY set properly?"));
        return false;
    }

    // update internal arg[cv] as GTK+ may have removed processed options:
    this->argc = argc;
    this->argv = argv;

    // we can not enter threads before gtk_init is done
    gdk_threads_enter();

    if ( !wxAppBase::Initialize(argc, argv) )
    {
        gdk_threads_leave();

        return false;
    }

    wxSetDetectableAutoRepeat( true );

#if wxUSE_INTL
    wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
#endif

    return true;
}
Ejemplo n.º 10
0
nsresult
nsAppShell::Init()
{
#ifdef PR_LOGGING
    if (!gWidgetLog)
        gWidgetLog = PR_NewLogModule("Widget");
    if (!gWidgetFocusLog)
        gWidgetFocusLog = PR_NewLogModule("WidgetFocus");
    if (!gWidgetDragLog)
        gWidgetDragLog = PR_NewLogModule("WidgetDrag");
    if (!gWidgetDrawLog)
        gWidgetDrawLog = PR_NewLogModule("WidgetDraw");
#endif

    if (!sPollFunc) {
        sPollFunc = g_main_context_get_poll_func(NULL);
        g_main_context_set_poll_func(NULL, &PollWrapper);
    }

    if (PR_GetEnv("MOZ_DEBUG_PAINTS"))
        gdk_window_set_debug_updates(TRUE);

    // Disable JasPer module (jpeg2000) in GDK-PixBuf.
    // Also disable known buggy TGA and icns formats
    GSList* pixbufFormats = gdk_pixbuf_get_formats();
    for (GSList* iter = pixbufFormats; iter; iter = iter->next) {
        GdkPixbufFormat* format = static_cast<GdkPixbufFormat*>(iter->data);
        gchar* name = gdk_pixbuf_format_get_name(format);
        if (strcmp(name, "jpeg2000") == 0 ||
            strcmp(name, "tga") == 0 ||
            strcmp(name, "icns") == 0) {
            gdk_pixbuf_format_set_disabled(format, TRUE);
        }
        g_free(name);
    }
    g_slist_free(pixbufFormats);

    int err = pipe(mPipeFDs);
    if (err)
        return NS_ERROR_OUT_OF_MEMORY;

    GIOChannel *ioc;
    GSource *source;

    // make the pipe nonblocking

    int flags = fcntl(mPipeFDs[0], F_GETFL, 0);
    if (flags == -1)
        goto failed;
    err = fcntl(mPipeFDs[0], F_SETFL, flags | O_NONBLOCK);
    if (err == -1)
        goto failed;
    flags = fcntl(mPipeFDs[1], F_GETFL, 0);
    if (flags == -1)
        goto failed;
    err = fcntl(mPipeFDs[1], F_SETFL, flags | O_NONBLOCK);
    if (err == -1)
        goto failed;

    ioc = g_io_channel_unix_new(mPipeFDs[0]);
    source = g_io_create_watch(ioc, G_IO_IN);
    g_io_channel_unref(ioc);
    g_source_set_callback(source, (GSourceFunc)EventProcessorCallback, this, nullptr);
    g_source_set_can_recurse(source, TRUE);
    mTag = g_source_attach(source, nullptr);
    g_source_unref(source);

    return nsBaseAppShell::Init();
failed:
    close(mPipeFDs[0]);
    close(mPipeFDs[1]);
    mPipeFDs[0] = mPipeFDs[1] = 0;
    return NS_ERROR_FAILURE;
}
Ejemplo n.º 11
0
/* ``plug'' our polling function into the glib: */
void lwt_glib_setup()
{
  old_poll_func = g_main_context_get_poll_func(NULL);
  g_main_context_set_poll_func(NULL, lwt_glib_poll);
}