Skip to content

Commit

Permalink
screenshot: Add Impl:version property and query it (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsdg authored Aug 29, 2022
1 parent 7e3d59a commit eef818e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct _ScreenshotClass

static XdpDbusImplScreenshot *impl;
static XdpDbusImplAccess *access_impl;
static guint32 impl_version;
static Screenshot *screenshot;

GType screenshot_get_type (void) G_GNUC_CONST;
Expand Down Expand Up @@ -448,7 +449,11 @@ screenshot_iface_init (XdpDbusScreenshotIface *iface)
static void
screenshot_init (Screenshot *screenshot)
{
xdp_dbus_screenshot_set_version (XDP_DBUS_SCREENSHOT (screenshot), 2);
/* Before there was a version property, the version was hardcoded to 2, so
* make sure we retain that behaviour */
impl_version = 2;
xdp_dbus_screenshot_set_version (XDP_DBUS_SCREENSHOT (screenshot),
impl_version);
}

static void
Expand All @@ -462,6 +467,7 @@ screenshot_create (GDBusConnection *connection,
const char *dbus_name_screenshot)
{
g_autoptr(GError) error = NULL;
g_autoptr(GVariant) version = NULL;

impl = xdp_dbus_impl_screenshot_proxy_new_sync (connection,
G_DBUS_PROXY_FLAGS_NONE,
Expand All @@ -477,6 +483,10 @@ screenshot_create (GDBusConnection *connection,

g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (impl), G_MAXINT);

/* Set the version if supported; otherwise fallback to hardcoded version 2 */
version = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (impl), "version");
impl_version = (version != NULL) ? g_variant_get_uint32 (version) : 2;

screenshot = g_object_new (screenshot_get_type (), NULL);

access_impl = xdp_dbus_impl_access_proxy_new_sync (connection,
Expand Down
1 change: 1 addition & 0 deletions tests/backend/screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ screenshot_init (GDBusConnection *connection,

helper = G_DBUS_INTERFACE_SKELETON (xdp_dbus_impl_screenshot_skeleton_new ());

xdp_dbus_impl_screenshot_set_version (XDP_DBUS_IMPL_SCREENSHOT (helper), 2);
g_signal_connect (helper, "handle-screenshot", G_CALLBACK (handle_screenshot), NULL);
g_signal_connect (helper, "handle-pick-color", G_CALLBACK (handle_screenshot), NULL);

Expand Down

0 comments on commit eef818e

Please sign in to comment.