Skip to content

Commit 3047735

Browse files
yetistraveit65
authored andcommitted
mate-display-properties: Migrate from dbus-glib to GDBus
1 parent c5e048b commit 3047735

File tree

1 file changed

+80
-71
lines changed

1 file changed

+80
-71
lines changed

capplets/display/xrandr-capplet.c

Lines changed: 80 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
#include <X11/Xlib.h>
3636
#include <glib/gi18n.h>
3737
#include <gio/gio.h>
38-
#include <dbus/dbus-glib.h>
39-
#include <dbus/dbus-glib-bindings.h>
4038

4139
typedef struct App App;
4240
typedef struct GrabInfo GrabInfo;
@@ -71,9 +69,8 @@ struct App
7169
GSettings *settings;
7270

7371
/* These are used while we are waiting for the ApplyConfiguration method to be executed over D-bus */
74-
DBusGConnection *connection;
75-
DBusGProxy *proxy;
76-
DBusGProxyCall *proxy_call;
72+
GDBusConnection *connection;
73+
GDBusProxy *proxy;
7774

7875
enum {
7976
APPLYING_VERSION_1,
@@ -93,7 +90,7 @@ static gboolean output_overlaps (MateRROutputInfo *output, MateRRConfig *config)
9390
static void select_current_output_from_dialog_position (App *app);
9491
static void monitor_on_off_toggled_cb (GtkToggleButton *toggle, gpointer data);
9592
static void get_geometry (MateRROutputInfo *output, int *w, int *h);
96-
static void apply_configuration_returned_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, void *data);
93+
static void apply_configuration_returned_cb (GObject *source_object, GAsyncResult *res, gpointer data);
9794
static gboolean get_clone_size (MateRRScreen *screen, int *width, int *height);
9895
static gboolean output_info_supports_mode (App *app, MateRROutputInfo *info, int width, int height);
9996

@@ -1938,48 +1935,61 @@ static void
19381935
begin_version2_apply_configuration (App *app, GdkWindow *parent_window, guint32 timestamp)
19391936
{
19401937
XID parent_window_xid;
1938+
GError *error = NULL;
19411939

19421940
parent_window_xid = GDK_WINDOW_XID (parent_window);
19431941

1944-
app->proxy = dbus_g_proxy_new_for_name (app->connection,
1945-
"org.mate.SettingsDaemon",
1946-
"/org/mate/SettingsDaemon/XRANDR",
1947-
"org.mate.SettingsDaemon.XRANDR_2");
1948-
g_assert (app->proxy != NULL); /* that call does not fail unless we pass bogus names */
1949-
1950-
app->apply_configuration_state = APPLYING_VERSION_2;
1951-
app->proxy_call = dbus_g_proxy_begin_call (app->proxy, "ApplyConfiguration",
1952-
apply_configuration_returned_cb, app,
1953-
NULL,
1954-
G_TYPE_INT64, (gint64) parent_window_xid,
1955-
G_TYPE_INT64, (gint64) timestamp,
1956-
G_TYPE_INVALID,
1957-
G_TYPE_INVALID);
1958-
/* FIXME: we don't check for app->proxy_call == NULL, which could happen if
1959-
* the connection was disconnected. This is left as an exercise for the
1960-
* reader.
1961-
*/
1942+
app->proxy = g_dbus_proxy_new_sync (app->connection,
1943+
G_DBUS_PROXY_FLAGS_NONE,
1944+
NULL,
1945+
"org.mate.SettingsDaemon",
1946+
"/org/mate/SettingsDaemon/XRANDR",
1947+
"org.mate.SettingsDaemon.XRANDR_2",
1948+
NULL,
1949+
&error);
1950+
if (app->proxy == NULL) {
1951+
g_warning ("Failed to get dbus connection: %s", error->message);
1952+
g_error_free (error);
1953+
} else {
1954+
app->apply_configuration_state = APPLYING_VERSION_2;
1955+
g_dbus_proxy_call (app->proxy,
1956+
"ApplyConfiguration",
1957+
g_variant_new ("(xx)", parent_window_xid, timestamp),
1958+
G_DBUS_CALL_FLAGS_NONE,
1959+
-1,
1960+
NULL,
1961+
(GAsyncReadyCallback) apply_configuration_returned_cb,
1962+
app);
1963+
}
19621964
}
19631965

19641966
static void
19651967
begin_version1_apply_configuration (App *app)
19661968
{
1967-
app->proxy = dbus_g_proxy_new_for_name (app->connection,
1968-
"org.mate.SettingsDaemon",
1969-
"/org/mate/SettingsDaemon/XRANDR",
1970-
"org.mate.SettingsDaemon.XRANDR");
1971-
g_assert (app->proxy != NULL); /* that call does not fail unless we pass bogus names */
1972-
1973-
app->apply_configuration_state = APPLYING_VERSION_1;
1974-
app->proxy_call = dbus_g_proxy_begin_call (app->proxy, "ApplyConfiguration",
1975-
apply_configuration_returned_cb, app,
1976-
NULL,
1977-
G_TYPE_INVALID,
1978-
G_TYPE_INVALID);
1979-
/* FIXME: we don't check for app->proxy_call == NULL, which could happen if
1980-
* the connection was disconnected. This is left as an exercise for the
1981-
* reader.
1982-
*/
1969+
GError *error = NULL;
1970+
1971+
app->proxy = g_dbus_proxy_new_sync (app->connection,
1972+
G_DBUS_PROXY_FLAGS_NONE,
1973+
NULL,
1974+
"org.mate.SettingsDaemon",
1975+
"/org/mate/SettingsDaemon/XRANDR",
1976+
"org.mate.SettingsDaemon.XRANDR",
1977+
NULL,
1978+
&error);
1979+
if (app->proxy == NULL) {
1980+
g_warning ("Failed to get dbus connection: %s", error->message);
1981+
g_error_free (error);
1982+
} else {
1983+
app->apply_configuration_state = APPLYING_VERSION_1;
1984+
g_dbus_proxy_call (app->proxy,
1985+
"ApplyConfiguration",
1986+
g_variant_new ("()"),
1987+
G_DBUS_CALL_FLAGS_NONE,
1988+
-1,
1989+
NULL,
1990+
(GAsyncReadyCallback) apply_configuration_returned_cb,
1991+
app);
1992+
}
19831993
}
19841994

19851995
static void
@@ -2007,45 +2017,45 @@ ensure_current_configuration_is_saved (void)
20072017
g_object_unref (rr_screen);
20082018
}
20092019

2010-
/* Callback for dbus_g_proxy_begin_call() */
2020+
/* Callback for g_dbus_proxy_call() */
20112021
static void
2012-
apply_configuration_returned_cb (DBusGProxy *proxy,
2013-
DBusGProxyCall *call_id,
2014-
void *data)
2022+
apply_configuration_returned_cb (GObject *source_object,
2023+
GAsyncResult *res,
2024+
gpointer data)
20152025
{
2016-
App *app = data;
2017-
gboolean success;
2026+
GVariant *variant;
20182027
GError *error;
2019-
2020-
g_assert (call_id == app->proxy_call);
2028+
App *app = data;
20212029

20222030
error = NULL;
2023-
success = dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID);
20242031

2025-
if (!success) {
2026-
if (app->apply_configuration_state == APPLYING_VERSION_2
2027-
&& g_error_matches (error, DBUS_GERROR, DBUS_GERROR_UNKNOWN_METHOD)) {
2028-
g_error_free (error);
2029-
2030-
g_object_unref (app->proxy);
2031-
app->proxy = NULL;
2032+
if (app->proxy == NULL)
2033+
return;
20322034

2033-
begin_version1_apply_configuration (app);
2034-
return;
2035-
} else {
2036-
/* We don't pop up an error message; mate-settings-daemon already does that
2037-
* in case the selected RANDR configuration could not be applied.
2038-
*/
2039-
g_error_free (error);
2040-
}
2035+
variant = g_dbus_proxy_call_finish (app->proxy, res, &error);
2036+
if (variant == NULL) {
2037+
if (app->apply_configuration_state == APPLYING_VERSION_2
2038+
&& g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) {
2039+
g_error_free (error);
2040+
2041+
g_object_unref (app->proxy);
2042+
app->proxy = NULL;
2043+
2044+
begin_version1_apply_configuration (app);
2045+
return;
2046+
} else {
2047+
/* We don't pop up an error message; mate-settings-daemon already does that
2048+
* in case the selected RANDR configuration could not be applied.
2049+
*/
2050+
g_error_free (error);
2051+
}
20412052
}
20422053

20432054
g_object_unref (app->proxy);
20442055
app->proxy = NULL;
20452056

2046-
dbus_g_connection_unref (app->connection);
2057+
g_object_unref (app->connection);
20472058
app->connection = NULL;
2048-
app->proxy_call = NULL;
20492059

20502060
gtk_widget_set_sensitive (app->dialog, TRUE);
20512061
}
@@ -2084,13 +2094,12 @@ apply (App *app)
20842094

20852095
g_assert (app->connection == NULL);
20862096
g_assert (app->proxy == NULL);
2087-
g_assert (app->proxy_call == NULL);
20882097

2089-
app->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
2098+
app->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
20902099
if (app->connection == NULL) {
2091-
error_message (app, _("Could not get session bus while applying display configuration"), error->message);
2092-
g_error_free (error);
2093-
return;
2100+
error_message (app, _("Could not get session bus while applying display configuration"), error->message);
2101+
g_error_free (error);
2102+
return;
20942103
}
20952104

20962105
gtk_widget_set_sensitive (app->dialog, FALSE);

0 commit comments

Comments
 (0)