display: Use GDBus instead of dbus-glib

https://bugzilla.gnome.org/show_bug.cgi?id=667685
This commit is contained in:
Robert Ancell 2012-01-11 12:55:17 +01:00 committed by Bastien Nocera
parent 6c304370eb
commit 89bbb0a73a
3 changed files with 37 additions and 55 deletions

View file

@ -90,7 +90,7 @@ PKG_CHECK_MODULES(DATETIME_PANEL, $COMMON_MODULES dbus-glib-1
gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION
polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION
gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED_VERSION) gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED_VERSION)
PKG_CHECK_MODULES(DISPLAY_PANEL, $COMMON_MODULES dbus-glib-1 gnome-desktop-3.0 >= 3.1.0) PKG_CHECK_MODULES(DISPLAY_PANEL, $COMMON_MODULES gnome-desktop-3.0 >= 3.1.0)
PKG_CHECK_MODULES(INFO_PANEL, $COMMON_MODULES libgtop-2.0 PKG_CHECK_MODULES(INFO_PANEL, $COMMON_MODULES libgtop-2.0
polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION) polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION)
PKG_CHECK_MODULES(KEYBOARD_PANEL, $COMMON_MODULES x11) PKG_CHECK_MODULES(KEYBOARD_PANEL, $COMMON_MODULES x11)

View file

@ -23,7 +23,7 @@ libdisplay_la_SOURCES = \
scrollarea.h \ scrollarea.h \
$(MARSHALFILES) $(MARSHALFILES)
libdisplay_la_LIBADD = $(DBUS_LIBS) $(PANEL_LIBS) $(DISPLAY_PANEL_LIBS) libdisplay_la_LIBADD = $(PANEL_LIBS) $(DISPLAY_PANEL_LIBS)
libdisplay_la_LDFLAGS = $(PANEL_LDFLAGS) libdisplay_la_LDFLAGS = $(PANEL_LDFLAGS)
# You will need a recent intltool or the patch from this bug # You will need a recent intltool or the patch from this bug

View file

@ -35,8 +35,6 @@
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-bindings.h>
#include <gdesktop-enums.h> #include <gdesktop-enums.h>
G_DEFINE_DYNAMIC_TYPE (CcDisplayPanel, cc_display_panel, CC_TYPE_PANEL) G_DEFINE_DYNAMIC_TYPE (CcDisplayPanel, cc_display_panel, CC_TYPE_PANEL)
@ -95,9 +93,7 @@ struct _CcDisplayPanelPrivate
gboolean dragging_top_bar; gboolean dragging_top_bar;
/* These are used while we are waiting for the ApplyConfiguration method to be executed over D-bus */ /* These are used while we are waiting for the ApplyConfiguration method to be executed over D-bus */
DBusGConnection *connection; GDBusProxy *proxy;
DBusGProxy *proxy;
DBusGProxyCall *proxy_call;
}; };
typedef struct typedef struct
@ -114,7 +110,7 @@ static gboolean output_overlaps (GnomeRROutputInfo *output, GnomeRRConfig *confi
static void select_current_output_from_dialog_position (CcDisplayPanel *self); static void select_current_output_from_dialog_position (CcDisplayPanel *self);
static void monitor_switch_active_cb (GObject *object, GParamSpec *pspec, gpointer data); static void monitor_switch_active_cb (GObject *object, GParamSpec *pspec, gpointer data);
static void get_geometry (GnomeRROutputInfo *output, int *w, int *h); static void get_geometry (GnomeRROutputInfo *output, int *w, int *h);
static void apply_configuration_returned_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, void *data); static void apply_configuration_returned_cb (GObject *proxy, GAsyncResult *res, gpointer data);
static gboolean get_clone_size (GnomeRRScreen *screen, int *width, int *height); static gboolean get_clone_size (GnomeRRScreen *screen, int *width, int *height);
static gboolean output_info_supports_mode (CcDisplayPanel *self, GnomeRROutputInfo *info, int width, int height); static gboolean output_info_supports_mode (CcDisplayPanel *self, GnomeRROutputInfo *info, int width, int height);
static char *make_resolution_string (int width, int height); static char *make_resolution_string (int width, int height);
@ -2250,26 +2246,32 @@ static void
begin_version2_apply_configuration (CcDisplayPanel *self, GdkWindow *parent_window, guint32 timestamp) begin_version2_apply_configuration (CcDisplayPanel *self, GdkWindow *parent_window, guint32 timestamp)
{ {
XID parent_window_xid; XID parent_window_xid;
GError *error = NULL;
parent_window_xid = GDK_WINDOW_XID (parent_window); parent_window_xid = GDK_WINDOW_XID (parent_window);
self->priv->proxy = dbus_g_proxy_new_for_name (self->priv->connection, self->priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
"org.gnome.SettingsDaemon", "org.gnome.SettingsDaemon",
"/org/gnome/SettingsDaemon/XRANDR", "/org/gnome/SettingsDaemon/XRANDR",
"org.gnome.SettingsDaemon.XRANDR_2"); "org.gnome.SettingsDaemon.XRANDR_2",
g_assert (self->priv->proxy != NULL); /* that call does not fail unless we pass bogus names */
self->priv->proxy_call = dbus_g_proxy_begin_call (self->priv->proxy, "ApplyConfiguration",
apply_configuration_returned_cb, self,
NULL, NULL,
G_TYPE_INT64, (gint64) parent_window_xid, &error);
G_TYPE_INT64, (gint64) timestamp, if (self->priv->proxy == NULL) {
G_TYPE_INVALID, error_message (self, _("Failed to apply configuration: %s"), error->message);
G_TYPE_INVALID); g_error_free (error);
/* FIXME: we don't check for self->priv->proxy_call == NULL, which could happen if return;
* the connection was disconnected. This is left as an exercise for the }
* reader.
*/ g_dbus_proxy_call (self->priv->proxy,
"ApplyConfiguration",
g_variant_new ("(xx)", (gint64) parent_window_xid, (gint64) timestamp),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
apply_configuration_returned_cb,
self);
} }
static void static void
@ -2298,35 +2300,25 @@ ensure_current_configuration_is_saved (void)
g_object_unref (rr_screen); g_object_unref (rr_screen);
} }
/* Callback for dbus_g_proxy_begin_call() */
static void static void
apply_configuration_returned_cb (DBusGProxy *proxy, apply_configuration_returned_cb (GObject *proxy,
DBusGProxyCall *call_id, GAsyncResult *res,
void *data) gpointer data)
{ {
CcDisplayPanel *self = data; CcDisplayPanel *self = data;
gboolean success; GVariant *result;
GError *error; GError *error = NULL;
g_assert (call_id == self->priv->proxy_call); result = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, &error);
if (error)
error = NULL; error_message (self, _("Failed to apply configuration: %s"), error->message);
success = dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID); g_clear_error (&error);
if (result)
if (!success) { g_variant_unref (result);
/* We don't pop up an error message; gnome-settings-daemon already does that
* in case the selected RANDR configuration could not be applied.
*/
g_error_free (error);
}
g_object_unref (self->priv->proxy); g_object_unref (self->priv->proxy);
self->priv->proxy = NULL; self->priv->proxy = NULL;
dbus_g_connection_unref (self->priv->connection);
self->priv->connection = NULL;
self->priv->proxy_call = NULL;
gtk_widget_set_sensitive (self->priv->panel, TRUE); gtk_widget_set_sensitive (self->priv->panel, TRUE);
} }
@ -2358,7 +2350,6 @@ sanitize_and_save_configuration (CcDisplayPanel *self)
static void static void
apply (CcDisplayPanel *self) apply (CcDisplayPanel *self)
{ {
GError *error = NULL;
GdkWindow *window; GdkWindow *window;
self->priv->apply_button_clicked_timestamp = gtk_get_current_event_time (); self->priv->apply_button_clicked_timestamp = gtk_get_current_event_time ();
@ -2366,16 +2357,7 @@ apply (CcDisplayPanel *self)
if (!sanitize_and_save_configuration (self)) if (!sanitize_and_save_configuration (self))
return; return;
g_assert (self->priv->connection == NULL);
g_assert (self->priv->proxy == NULL); g_assert (self->priv->proxy == NULL);
g_assert (self->priv->proxy_call == NULL);
self->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (self->priv->connection == NULL) {
error_message (self, _("Could not get session bus while applying display configuration"), error->message);
g_error_free (error);
return;
}
gtk_widget_set_sensitive (self->priv->panel, FALSE); gtk_widget_set_sensitive (self->priv->panel, FALSE);