Exemplo n.º 1
0
static gboolean
handle_prepare_print (XdpPrint *object,
                      GDBusMethodInvocation *invocation,
                      const gchar *arg_parent_window,
                      const gchar *arg_title,
                      GVariant *arg_settings,
                      GVariant *arg_page_setup,
                      GVariant *arg_options)
{
  Request *request = request_from_invocation (invocation);
  const char *app_id = xdp_app_info_get_id (request->app_info);
  g_autoptr(GError) error = NULL;
  g_autoptr(XdpImplRequest) impl_request = NULL;
  GVariantBuilder opt_builder;

  if (xdp_impl_lockdown_get_disable_printing (lockdown))
    {
      g_debug ("Printing disabled");
      g_dbus_method_invocation_return_error (invocation,
                                             XDG_DESKTOP_PORTAL_ERROR,
                                             XDG_DESKTOP_PORTAL_ERROR_NOT_ALLOWED,
                                             "Printing disabled");
      return TRUE;
    }

  REQUEST_AUTOLOCK (request);

  impl_request = xdp_impl_request_proxy_new_sync (g_dbus_proxy_get_connection (G_DBUS_PROXY (impl)),
                                                  G_DBUS_PROXY_FLAGS_NONE,
                                                  g_dbus_proxy_get_name (G_DBUS_PROXY (impl)),
                                                  request->id,
                                                  NULL, &error);
  if (!impl_request)
    {
      g_dbus_method_invocation_return_gerror (invocation, error);
      return TRUE;
    }

  request_set_impl_request (request, impl_request);
  request_export (request, g_dbus_method_invocation_get_connection (invocation));

  g_variant_builder_init (&opt_builder, G_VARIANT_TYPE_VARDICT);
  xdp_filter_options (arg_options, &opt_builder,
                      prepare_print_options, G_N_ELEMENTS (prepare_print_options));
  xdp_impl_print_call_prepare_print (impl,
                                     request->id,
                                     app_id,
                                     arg_parent_window,
                                     arg_title,
                                     arg_settings,
                                     arg_page_setup,
                                     g_variant_builder_end (&opt_builder),
                                     NULL,
                                     prepare_print_done,
                                     g_object_ref (request));

  xdp_print_complete_prepare_print (object, invocation, request->id);

  return TRUE;
}
Exemplo n.º 2
0
SecretPrompt *
_secret_prompt_instance (SecretService *service,
                         const gchar *prompt_path)
{
	GDBusProxy *proxy;
	SecretPrompt *prompt;
	GError *error = NULL;

	g_return_val_if_fail (SECRET_IS_SERVICE (service), NULL);
	g_return_val_if_fail (prompt_path != NULL, NULL);

	proxy = G_DBUS_PROXY (service);
	prompt = g_initable_new (SECRET_TYPE_PROMPT, NULL, &error,
	                         "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
	                         "g-interface-info", _secret_gen_prompt_interface_info (),
	                         "g-name", g_dbus_proxy_get_name (proxy),
	                         "g-connection", g_dbus_proxy_get_connection (proxy),
	                         "g-object-path", prompt_path,
	                         "g-interface-name", SECRET_PROMPT_INTERFACE,
	                         NULL);

	if (error != NULL) {
		g_warning ("couldn't create SecretPrompt object: %s", error->message);
		g_clear_error (&error);
		return NULL;
	}

	return prompt;
}
Exemplo n.º 3
0
/**
 * fcitx_input_method_set_imlist:
 * @im: A #FcitxInputMethod
 * @array: (element-type FcitxIMItem) (transfer none): A #FcitxIMItem List
 *
 * Set Fcitx all im list
 **/
FCITX_EXPORT_API
void
fcitx_input_method_set_imlist(FcitxInputMethod *im, GPtrArray* array)
{
    GVariantBuilder builder;
    g_variant_builder_init(&builder, G_VARIANT_TYPE("a(sssb)"));
    g_ptr_array_foreach(array, _fcitx_im_item_foreach_cb, &builder);
    GVariant* value = g_variant_builder_end(&builder);
    GError* error = NULL;
    GVariant* result = g_dbus_connection_call_sync(g_dbus_proxy_get_connection(G_DBUS_PROXY(im)),
                       g_dbus_proxy_get_name(G_DBUS_PROXY(im)),
                       FCITX_IM_DBUS_PATH,
                       "org.freedesktop.DBus.Properties",
                       "Set",
                       g_variant_new("(ssv)", FCITX_IM_DBUS_INTERFACE, "IMList", value),
                       G_VARIANT_TYPE_UNIT,
                       G_DBUS_CALL_FLAGS_NONE,
                       -1,           /* timeout */
                       NULL,
                       &error);

    if (error) {
        g_warning("%s", error->message);
        g_error_free(error);
    }

    g_variant_unref(result);
}
Exemplo n.º 4
0
/**
 * fcitx_input_method_get_imlist_nofree: (rename-to fcitx_input_method_get_imlist)
 * @im: A #FcitxInputMethod
 *
 * Get Fcitx all im list
 *
 * Returns: (transfer full) (element-type FcitxIMItem): A #FcitxIMItem List
 *
 * Rename to: fcitx_input_method_get_imlist
 **/
FCITX_EXPORT_API
GPtrArray*
fcitx_input_method_get_imlist_nofree(FcitxInputMethod* im)
{
    GPtrArray *array = NULL;
    GVariant* value;
    GVariantIter *iter;
    gchar *name, *unique_name, *langcode;
    gboolean enable;
    value = g_dbus_proxy_get_cached_property(G_DBUS_PROXY(im), "IMList");

    if (value == NULL) {
        GError* error = NULL;
        GVariant* result = g_dbus_connection_call_sync(g_dbus_proxy_get_connection(G_DBUS_PROXY(im)),
                           g_dbus_proxy_get_name(G_DBUS_PROXY(im)),
                           FCITX_IM_DBUS_PATH,
                           "org.freedesktop.DBus.Properties",
                           "Get",
                           g_variant_new("(ss)", FCITX_IM_DBUS_INTERFACE, "IMList"),
                           G_VARIANT_TYPE("(v)"),
                           G_DBUS_CALL_FLAGS_NONE,
                           -1,           /* timeout */
                           NULL,
                           &error);

        if (error) {
            g_warning("%s", error->message);
            g_error_free(error);
        } else if (result) {
            g_variant_get(result, "(v)", &value);
            g_variant_unref(result);
        }
    }

    if (value) {
        array = g_ptr_array_new();
        g_variant_get(value, "a(sssb)", &iter);
        while (g_variant_iter_next(iter, "(sssb)", &name, &unique_name, &langcode, &enable, NULL)) {
            FcitxIMItem *item = g_slice_new(FcitxIMItem);
            item->name = name;
            item->unique_name = unique_name;
            item->langcode = langcode;
            item->enable = enable;
            g_ptr_array_add(array, item);
        }
        g_variant_iter_free(iter);

        g_variant_unref(value);
    }

    return array;
}
Exemplo n.º 5
0
static void
print_proxy_info (GDBusProxy *proxy)
{
    g_print ("proxy info:\n"
             "name %s\n"
             "name owner %s\n"
             "object path %s\n"
             "interface name %s\n",
             g_dbus_proxy_get_name (proxy),
             g_dbus_proxy_get_name_owner (proxy),
             g_dbus_proxy_get_object_path (proxy),
             g_dbus_proxy_get_interface_name (proxy));
}
Exemplo n.º 6
0
/* D-Bus has an upper limit on number of Match rules and it's rather easy
 * to hit as the proxy likes to add one for each object. Let's remove the Match
 * rule the proxy added and ensure a less granular rule is present instead.
 *
 * Also, don't do this immediately since it has a performance penalty.
 * Still better than loosing the signals altogether.
 *
 * Ideally, we should be able to tell glib not to hook its rules:
 * https://bugzilla.gnome.org/show_bug.cgi?id=758749
 */
static void
_nm_dbus_proxy_replace_match (GDBusProxy *proxy)
{
	GDBusConnection *connection = g_dbus_proxy_get_connection (proxy);
	static unsigned match_counter = 1024;
	gchar *match;

	nm_assert (!g_strcmp0 (g_dbus_proxy_get_name (proxy), NM_DBUS_SERVICE));

	if (match_counter == 1) {
		/* If we hit the low matches watermark, install a
		 * less granular one. */
		g_dbus_connection_call (connection,
		                        "org.freedesktop.DBus",
		                        "/org/freedesktop/DBus",
		                        "org.freedesktop.DBus",
		                        "AddMatch",
		                        g_variant_new ("(s)", "type='signal',sender='" NM_DBUS_SERVICE "'"),
		                        NULL,
		                        G_DBUS_CALL_FLAGS_NONE,
		                        -1,
		                        NULL,
		                        NULL,
		                        NULL);
	}

	if (match_counter)
		match_counter--;
	if (match_counter)
		return;

	/* Remove what this proxy added. */
	match = g_strdup_printf ("type='signal',sender='" NM_DBUS_SERVICE "',"
	                         "interface='%s',path='%s'",
	                         g_dbus_proxy_get_interface_name (proxy),
	                         g_dbus_proxy_get_object_path (proxy));
	g_dbus_connection_call (connection,
	                        "org.freedesktop.DBus",
	                        "/org/freedesktop/DBus",
	                        "org.freedesktop.DBus",
	                        "RemoveMatch",
	                        g_variant_new ("(s)", match),
	                        NULL,
	                        G_DBUS_CALL_FLAGS_NONE,
	                        -1,
	                        NULL,
	                        NULL,
	                        NULL);
	g_free (match);
}
Exemplo n.º 7
0
static GVariant *
_get_session_property (
        GDBusProxy *proxy,
        const gchar *object_path,
        const gchar *prop_key)
{
    GError *error = NULL;
    GVariant *result = NULL;
    GVariant *prop_value = NULL;

    result = g_dbus_connection_call_sync (
            g_dbus_proxy_get_connection (proxy),
            g_dbus_proxy_get_name (proxy),
            object_path,
            "org.freedesktop.DBus.Properties",
            "GetAll",
            g_variant_new ("(s)",  "org.freedesktop.login1.Session"),
            G_VARIANT_TYPE ("(a{sv})"),
            G_DBUS_CALL_FLAGS_NONE,
            -1,
            NULL,
            &error);
    if (error) {
        printf ("Failed with error %d:%s", error->code, error->message);
        g_error_free (error);
        error = NULL;
        return NULL;
    }

    if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(a{sv})"))) {
        GVariantIter *iter = NULL;
        GVariant *item = NULL;
        g_variant_get (result, "(a{sv})",  &iter);
        while ((item = g_variant_iter_next_value (iter)))  {
            gchar *key;
            GVariant *value;
            g_variant_get (item, "{sv}", &key, &value);
            if (g_strcmp0 (key, prop_key) == 0) {
                prop_value = value;
                g_free (key); key = NULL;
                break;
            }
            g_free (key); key = NULL;
            g_variant_unref (value); value = NULL;
        }
    }
    g_variant_unref (result);
    return prop_value;
}
Exemplo n.º 8
0
static gboolean
handle_save_file (XdpFileChooser *object,
                  GDBusMethodInvocation *invocation,
                  const gchar *arg_parent_window,
                  const gchar *arg_title,
                  GVariant *arg_options)
{
  Request *request = request_from_invocation (invocation);
  const char *app_id = request->app_id;
  g_autoptr(GError) error = NULL;
  XdpImplRequest *impl_request;
  GVariantBuilder options;

  REQUEST_AUTOLOCK (request);

  g_variant_builder_init (&options, G_VARIANT_TYPE_VARDICT);
  xdp_filter_options (arg_options, &options,
                      save_file_options, G_N_ELEMENTS (save_file_options));

  impl_request = xdp_impl_request_proxy_new_sync (g_dbus_proxy_get_connection (G_DBUS_PROXY (impl)),
                                                  G_DBUS_PROXY_FLAGS_NONE,
                                                  g_dbus_proxy_get_name (G_DBUS_PROXY (impl)),
                                                  request->id,
                                                  NULL, &error);
  if (!impl_request)
    {
      g_dbus_method_invocation_return_gerror (invocation, error);
      return TRUE;
    }

  g_object_set_data (G_OBJECT (request), "for-save", GINT_TO_POINTER (TRUE));

  request_set_impl_request (request, impl_request);
  request_export (request, g_dbus_method_invocation_get_connection (invocation));

  xdp_impl_file_chooser_call_save_file (impl,
                                        request->id,
                                        app_id,
                                        arg_parent_window,
                                        arg_title,
                                        g_variant_builder_end (&options),
                                        NULL,
                                        save_file_done,
                                        g_object_ref (request));

  xdp_file_chooser_complete_open_file (object, invocation, request->id);

  return TRUE;
}
Exemplo n.º 9
0
static void steadyflow_iapp_service_proxy_set_visible (SteadyflowIAppService* self, gboolean visible, GError** error) {
	GDBusMessage *_message;
	GVariant *_arguments;
	GVariantBuilder _arguments_builder;
	GDBusMessage *_reply_message;
	G_IO_ERROR;
	_message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "net.launchpad.steadyflow.App", "SetVisible");
	g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE);
	g_variant_builder_add_value (&_arguments_builder, g_variant_new_boolean (visible));
	_arguments = g_variant_builder_end (&_arguments_builder);
	g_dbus_message_set_body (_message, _arguments);
	_reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error);
	g_object_unref (_message);
	if (!_reply_message) {
		return;
	}
	if (g_dbus_message_to_gerror (_reply_message, error)) {
		g_object_unref (_reply_message);
		return;
	}
	g_object_unref (_reply_message);
}
Exemplo n.º 10
0
static void
auth_session_get_object_path_reply (GObject *object, GAsyncResult *res,
                                    gpointer userdata)
{
    SsoAuthService *proxy = SSO_AUTH_SERVICE (object);
    gchar *object_path = NULL;
    GError *error = NULL;

    sso_auth_service_call_get_auth_session_object_path_finish (proxy,
                                                               &object_path,
                                                               res,
                                                               &error);
    SIGNON_RETURN_IF_CANCELLED (error);

    g_return_if_fail (SIGNON_IS_AUTH_SESSION (userdata));
    SignonAuthSession *self = SIGNON_AUTH_SESSION (userdata);
    SignonAuthSessionPrivate *priv = self->priv;
    g_return_if_fail (priv != NULL);

    priv->registering = FALSE;
    if (!g_strcmp0(object_path, "") || error)
    {
        if (error)
            DEBUG ("Error message is %s", error->message);
        else
            error = g_error_new (signon_error_quark(),
                                 SIGNON_ERROR_RUNTIME,
                                 "Cannot create remote AuthSession object");
    }
    else
    {
        GDBusConnection *connection;
        const gchar *bus_name;
        GError *proxy_error = NULL;

        connection = g_dbus_proxy_get_connection ((GDBusProxy *)proxy);
        bus_name = g_dbus_proxy_get_name ((GDBusProxy *)proxy);

        priv->proxy =
            sso_auth_session_proxy_new_sync (connection,
                                             G_DBUS_PROXY_FLAGS_NONE,
                                             bus_name,
                                             object_path,
                                             priv->cancellable,
                                             &proxy_error);
        if (G_UNLIKELY (proxy_error != NULL))
        {
            g_warning ("Failed to initialize AuthSession proxy: %s",
                       proxy_error->message);
            g_clear_error (&proxy_error);
        }

        g_dbus_proxy_set_default_timeout ((GDBusProxy *)priv->proxy,
                                          G_MAXINT);

        priv->signal_state_changed =
            g_signal_connect (priv->proxy,
                              "state-changed",
                              G_CALLBACK (auth_session_state_changed_cb),
                              self);

        priv->signal_unregistered =
           g_signal_connect (priv->proxy,
                             "unregistered",
                             G_CALLBACK (auth_session_remote_object_destroyed_cb),
                             self);
    }

    DEBUG ("Object path received: %s", object_path);
    _signon_object_ready (self, auth_session_object_quark (), error);
    g_clear_error (&error);
}
Exemplo n.º 11
0
static void
identity_registered (SignonIdentity *identity,
                     char *object_path, GVariant *identity_data,
                     GError *error)
{
    g_return_if_fail (SIGNON_IS_IDENTITY (identity));

    SignonIdentityPrivate *priv;
    priv = identity->priv;

    g_return_if_fail (priv != NULL);

    if (!error)
    {
        GDBusConnection *connection;
        GDBusProxy *auth_service_proxy;
        const gchar *bus_name;
        GError *proxy_error = NULL;

        DEBUG("%s: %s", G_STRFUNC, object_path);
        /*
         * TODO: as Aurel will finalize the code polishing so we will
         * need to implement the refresh of the proxy to SignonIdentity
         * */
        g_return_if_fail (priv->proxy == NULL);

        auth_service_proxy = (GDBusProxy *)priv->auth_service_proxy;
        connection = g_dbus_proxy_get_connection (auth_service_proxy);
        bus_name = g_dbus_proxy_get_name (auth_service_proxy);

        priv->proxy =
            sso_identity_proxy_new_sync (connection,
                                         G_DBUS_PROXY_FLAGS_NONE,
                                         bus_name,
                                         object_path,
                                         priv->cancellable,
                                         &proxy_error);
        if (G_UNLIKELY (proxy_error != NULL))
        {
            g_warning ("Failed to initialize Identity proxy: %s",
                       proxy_error->message);
            g_clear_error (&proxy_error);
        }

        priv->signal_info_updated =
            g_signal_connect (priv->proxy,
                              "info-updated",
                              G_CALLBACK (identity_state_changed_cb),
                              identity);

        priv->signal_unregistered =
            g_signal_connect (priv->proxy,
                              "unregistered",
                              G_CALLBACK (identity_remote_object_destroyed_cb),
                              identity);

        if (identity_data)
        {
            DEBUG("%s: ", G_STRFUNC);
            priv->identity_info =
                signon_identity_info_new_from_variant (identity_data);
            g_variant_unref (identity_data);
        }

        priv->updated = TRUE;
    }
    else
        g_warning ("%s: %s", G_STRFUNC, error->message);

    /*
     * execute queued operations or emit errors on each of them
     * */
    priv->registration_state = REGISTERED;

    /*
     * TODO: if we will add a new state for identity: "INVALID"
     * consider emission of another error, like "invalid"
     * */
    _signon_object_ready (identity, identity_object_quark (), error);

    /*
     * as the registration failed we do not
     * request for new registration, but emit
     * same error again and again
     * */
}
Exemplo n.º 12
0
static gboolean
handle_open_file (XdpFileChooser *object,
                  GDBusMethodInvocation *invocation,
                  const gchar *arg_parent_window,
                  const gchar *arg_title,
                  GVariant *arg_options)
{
  Request *request = request_from_invocation (invocation);
  const char *app_id = request->app_id;
  g_autoptr(GError) error = NULL;
  g_autoptr(XdpImplRequest) impl_request = NULL;
  GVariantBuilder options;
  g_autoptr(GVariant) value = NULL;

  REQUEST_AUTOLOCK (request);

  value = g_variant_lookup_value (arg_options, "filters", NULL);
  if (value != NULL)
    {
      if (!check_filters (value, &error))
        {
          g_prefix_error (&error, "invalid filters: ");
          g_dbus_method_invocation_return_gerror (invocation, error);
          return TRUE;
        }
      g_variant_unref (value);
      value = NULL;
    }
  value = g_variant_lookup_value (arg_options, "choices", NULL);
  if (value != NULL)
    {
      if (!check_choices (value, &error))
        {
          g_prefix_error (&error, "invalid choices: ");
          g_dbus_method_invocation_return_gerror (invocation, error);
          return TRUE;
        }
      g_variant_unref (value);
      value = NULL;
    }

  g_variant_builder_init (&options, G_VARIANT_TYPE_VARDICT);
  xdp_filter_options (arg_options, &options,
                      open_file_options, G_N_ELEMENTS (open_file_options));

  impl_request = xdp_impl_request_proxy_new_sync (g_dbus_proxy_get_connection (G_DBUS_PROXY (impl)),
                                                  G_DBUS_PROXY_FLAGS_NONE,
                                                  g_dbus_proxy_get_name (G_DBUS_PROXY (impl)),
                                                  request->id,
                                                  NULL, &error);
  if (!impl_request)
    {
      g_dbus_method_invocation_return_gerror (invocation, error);
      return TRUE;
    }

  request_set_impl_request (request, impl_request);
  request_export (request, g_dbus_method_invocation_get_connection (invocation));

  xdp_impl_file_chooser_call_open_file (impl,
                                        request->id,
                                        app_id,
                                        arg_parent_window,
                                        arg_title,
                                        g_variant_builder_end (&options),
                                        NULL,
                                        open_file_done,
                                        g_object_ref (request));

  xdp_file_chooser_complete_open_file (object, invocation, request->id);

  return TRUE;
}
Exemplo n.º 13
0
static void
gtk_application_impl_dbus_startup (GtkApplicationImpl *impl,
                                   gboolean            register_session)
{
  GtkApplicationImplDBus *dbus = (GtkApplicationImplDBus *) impl;
  static gchar *client_id;
  GError *error = NULL;
  GVariant *res;
  gboolean same_bus;
  const char *bus_name;
  const char *client_interface;

  dbus->session = g_application_get_dbus_connection (G_APPLICATION (impl->application));

  if (!dbus->session)
    goto out;

  dbus->application_id = g_application_get_application_id (G_APPLICATION (impl->application));
  dbus->object_path = g_application_get_dbus_object_path (G_APPLICATION (impl->application));
  dbus->unique_name = g_dbus_connection_get_unique_name (dbus->session);

  if (client_id == NULL)
    {
      const gchar *desktop_autostart_id;

      desktop_autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");
      /* Unset DESKTOP_AUTOSTART_ID in order to avoid child processes to
       * use the same client id.
       */
      g_unsetenv ("DESKTOP_AUTOSTART_ID");
      client_id = g_strdup (desktop_autostart_id ? desktop_autostart_id : "");
    }

  g_debug ("Connecting to session manager");

  /* Try the GNOME session manager first */
  dbus->sm_proxy = gtk_application_get_proxy_if_service_present (dbus->session,
                                                                 G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START |
                                                                 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
                                                                 G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
                                                                 GNOME_DBUS_NAME,
                                                                 GNOME_DBUS_OBJECT_PATH,
                                                                 GNOME_DBUS_INTERFACE,
                                                                 &error);

  if (error)
    {
      g_warning ("Failed to get the GNOME session proxy: %s", error->message);
      g_clear_error (&error);
    }

  if (!dbus->sm_proxy)
    {
      /* Fallback to trying the Xfce session manager */
      dbus->sm_proxy = gtk_application_get_proxy_if_service_present (dbus->session,
                                                                     G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START |
                                                                     G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
                                                                     G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
                                                                     XFCE_DBUS_NAME,
                                                                     XFCE_DBUS_OBJECT_PATH,
                                                                     XFCE_DBUS_INTERFACE,
                                                                     &error);

      if (error)
        {
          g_warning ("Failed to get the Xfce session proxy: %s", error->message);
          g_clear_error (&error);
          goto out;
        }
    }

  if (!register_session)
    goto out;

  g_debug ("Registering client '%s' '%s'", dbus->application_id, client_id);

  res = g_dbus_proxy_call_sync (dbus->sm_proxy,
                                "RegisterClient",
                                g_variant_new ("(ss)", dbus->application_id, client_id),
                                G_DBUS_CALL_FLAGS_NONE,
                                G_MAXINT,
                                NULL,
                                &error);

  if (error)
    {
      g_warning ("Failed to register client: %s", error->message);
      g_clear_error (&error);
      g_clear_object (&dbus->sm_proxy);
      goto out;
    }

  g_variant_get (res, "(o)", &dbus->client_path);
  g_variant_unref (res);

  g_debug ("Registered client at '%s'", dbus->client_path);

  if (g_str_equal (g_dbus_proxy_get_name (dbus->sm_proxy), GNOME_DBUS_NAME))
    {
      bus_name = GNOME_DBUS_NAME;
      client_interface = GNOME_DBUS_CLIENT_INTERFACE;
    }
  else
    {
      bus_name = XFCE_DBUS_NAME;
      client_interface = XFCE_DBUS_CLIENT_INTERFACE;
    }

  dbus->client_proxy = g_dbus_proxy_new_sync (dbus->session, 0,
                                              NULL,
                                              bus_name,
                                              dbus->client_path,
                                              client_interface,
                                              NULL,
                                              &error);
  if (error)
    {
      g_warning ("Failed to get client proxy: %s", error->message);
      g_clear_error (&error);
      g_free (dbus->client_path);
      dbus->client_path = NULL;
      goto out;
    }

  g_signal_connect (dbus->client_proxy, "g-signal", G_CALLBACK (client_proxy_signal), dbus);

 out:
  same_bus = FALSE;

  if (dbus->session)
    {
      const gchar *id;
      const gchar *id2;
      GValue value = G_VALUE_INIT;

      g_value_init (&value, G_TYPE_STRING);
      gdk_screen_get_setting (gdk_screen_get_default (), "gtk-session-bus-id", &value);
      id = g_value_get_string (&value);

      if (id && id[0])
        {
          res = g_dbus_connection_call_sync (dbus->session,
                                             "org.freedesktop.DBus",
                                             "/org/freedesktop/DBus",
                                             "org.freedesktop.DBus",
                                             "GetId",
                                             NULL,
                                             NULL,
                                             G_DBUS_CALL_FLAGS_NONE,
                                             -1,
                                             NULL,
                                             NULL);
          if (res)
            {
              g_variant_get (res, "(&s)", &id2);

              if (g_strcmp0 (id, id2) == 0)
                same_bus = TRUE;

              g_variant_unref (res);
            }
        }
      else
        same_bus = TRUE;

      g_value_unset (&value);
    }

  if (!same_bus)
    g_object_set (gtk_settings_get_default (),
                  "gtk-shell-shows-app-menu", FALSE,
                  "gtk-shell-shows-menubar", FALSE,
                  NULL);

  if (dbus->sm_proxy == NULL)
    {
      dbus->inhibit_proxy = gtk_application_get_proxy_if_service_present (dbus->session,
                                                                          G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
                                                                          "org.freedesktop.portal.Desktop",
                                                                          "/org/freedesktop/portal/desktop",
                                                                          "org.freedesktop.portal.Inhibit",
                                                                          &error);
      if (error)
        {
          g_warning ("Failed to get an inhibit portal proxy: %s", error->message);
          g_clear_error (&error);
        }
    }
}