Skip to content

Commit

Permalink
updating to not use request dance more
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhbooth committed Oct 31, 2022
1 parent cd1d478 commit 9130a52
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 156 deletions.
12 changes: 11 additions & 1 deletion data/org.freedesktop.impl.portal.Clipboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,17 @@
@session_handle: Object path for the #org.freedesktop.portal.Session object
@options: Vardict with optional further information
Sets the owner of the clipboard formats in 'mime-types' in @options to
Supported keys in the @options vardict include:
<variablelist>
<varlistentry>
<term>mime_types as</term>
<listitem><para>
An array of strings representing the mime types that the session has content for.
</para></listitem>
</varlistentry>
</variablelist>
Sets the owner of the clipboard formats in 'mime_types' in @options to
the session, i.e. this session has data for the advertised clipboard formats.
-->
<method name="SetSelection">
Expand Down
4 changes: 2 additions & 2 deletions data/org.freedesktop.portal.Clipboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
Supported keys in the @options vardict include:
<variablelist>
<varlistentry>
<term>mime-types as</term>
<term>mime_types as</term>
<listitem><para>
An array of strings representing the mime types that the session has content for.
</para></listitem>
</varlistentry>
</variablelist>
Sets the owner of the clipboard formats in 'mime-types' in @options to
Sets the owner of the clipboard formats in 'mime_types' in @options to
the session, i.e. this session has data for the advertised clipboard formats.
-->
<method name="SetSelection">
Expand Down
6 changes: 1 addition & 5 deletions src/clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ static Clipboard *clipboard;
GType clipboard_get_type (void) G_GNUC_CONST;
static void clipboard_iface_init (XdpDbusClipboardIface *iface);

static GQuark quark_request_session;

G_DEFINE_TYPE_WITH_CODE (Clipboard, clipboard,
XDP_DBUS_TYPE_CLIPBOARD_SKELETON,
G_IMPLEMENT_INTERFACE (XDP_DBUS_TYPE_CLIPBOARD,
clipboard_iface_init))

static XdpOptionKey clipboard_set_selection_options[] = {
{ "mime-types", G_VARIANT_TYPE_STRING_ARRAY, NULL },
{ "mime_types", G_VARIANT_TYPE_STRING_ARRAY, NULL },
};

static gboolean
Expand Down Expand Up @@ -388,8 +386,6 @@ clipboard_init (Clipboard *clipboard)
static void
clipboard_class_init (ClipboardClass *klass)
{
quark_request_session
= g_quark_from_static_string ("-xdp-request-clipboard-session");
}

static void
Expand Down
4 changes: 4 additions & 0 deletions src/remote-desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ process_results (RemoteDesktopSession *remote_desktop_session,
{
g_autoptr(GVariantIter) streams_iter = NULL;
uint32_t devices = 0;
gboolean clipboard_enabled = false;

if (g_variant_lookup (results, "streams", "a(ua{sv})", &streams_iter))
{
Expand All @@ -547,6 +548,9 @@ process_results (RemoteDesktopSession *remote_desktop_session,
if (g_variant_lookup (results, "devices", "u", &devices))
remote_desktop_session->shared_devices = devices;

if (g_variant_lookup (results, "clipboard_enabled", "b", &clipboard_enabled))
remote_desktop_session->clipboard_enabled = clipboard_enabled;

return TRUE;
}

Expand Down
26 changes: 1 addition & 25 deletions src/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,31 +271,7 @@ get_token (GDBusMethodInvocation *invocation)
}
else if (strcmp (interface, "org.freedesktop.portal.Clipboard") == 0)
{
if (strcmp (method, "EnableClipboard") == 0)
{
options = g_variant_get_child_value (parameters, 1);
}
else if (strcmp (method, "SetSelection") == 0)
{
options = g_variant_get_child_value (parameters, 1);
}
else if (strcmp (method, "SelectionWrite") == 0)
{
options = g_variant_get_child_value (parameters, 2);
}
else if (strcmp (method, "SelectionWriteDone") == 0)
{
options = g_variant_get_child_value (parameters, 3);
}
else if (strcmp (method, "SelectionRead") == 0)
{
options = g_variant_get_child_value (parameters, 2);
}
else
{
g_warning ("Support for %s::%s missing in %s", interface, method,
G_STRLOC);
}
// no request objects
}
else if (strcmp (interface, "org.freedesktop.portal.Location") == 0)
{
Expand Down
23 changes: 19 additions & 4 deletions src/xdg-desktop-portal.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@

#include <glib/gi18n.h>

#include "xdp-utils.h"
#include "xdp-dbus.h"
#include "xdp-impl-dbus.h"
#include "account.h"
#include "background.h"
#include "call.h"
#include "camera.h"
#include "clipboard.h"
#include "device.h"
#include "documents.h"
#include "dynamic-launcher.h"
Expand Down Expand Up @@ -61,7 +59,9 @@
#include "settings.h"
#include "trash.h"
#include "wallpaper.h"
#include "clipboard.c"
#include "xdp-dbus.h"
#include "xdp-impl-dbus.h"
#include "xdp-utils.h"

static GMainLoop *loop = NULL;

Expand Down Expand Up @@ -126,6 +126,21 @@ method_needs_request (GDBusMethodInvocation *invocation)
else
return TRUE;
}
else if (strcmp (interface, "org.freedesktop.portal.Clipboard") == 0)
{
if (strstr (method, "RequestClipboard") == 0)
return FALSE;
if (strstr (method, "SetSelection") == 0)
return FALSE;
if (strstr (method, "SelectionWrite") == 0)
return FALSE;
if (strstr (method, "SelectionWriteDone") == 0)
return FALSE;
if (strstr (method, "SelectionRead") == 0)
return FALSE;
else
return TRUE;
}
else if (strcmp (interface, "org.freedesktop.portal.Camera") == 0)
{
if (strcmp (method, "OpenPipeWireRemote") == 0)
Expand Down
126 changes: 28 additions & 98 deletions tests/templates/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,119 +35,66 @@ def load(mock, parameters=None):

@dbus.service.method(
MAIN_IFACE,
in_signature="oosa{sv}",
out_signature="ua{sv}",
in_signature="o",
out_signature="",
async_callbacks=("cb_success", "cb_error"),
)
def EnableClipboard(
self, handle, session_handle, app_id, options, cb_success, cb_error
):
def RequestClipboard(self, session_handle, cb_success, cb_error):
try:
logger.debug(
f"EnableClipboard({handle}, {session_handle}, {app_id}, {options})"
)

response = Response(self.response, {})

request = ImplRequest(self, BUS_NAME, handle)
logger.debug(f"RequestClipboard({session_handle})")

if self.expect_close:

def closed_callback():
response = Response(2, {})
logger.debug(f"EnableClipboard Close() response {response}")
cb_success(response.response, response.results)

request.export(closed_callback)
cb_success()
else:
request.export()

def reply():
logger.debug(f"EnableClipboard with response {response}")
cb_success(response.response, response.results)

logger.debug(f"scheduling delay of {self.delay}")
GLib.timeout_add(self.delay, reply)
GLib.timeout_add(self.delay, cb_success)
except Exception as e:
logger.critical(e)
cb_error(e)


@dbus.service.method(
MAIN_IFACE,
in_signature="oosa{sv}",
out_signature="ua{sv}",
in_signature="oa{sv}",
out_signature="",
async_callbacks=("cb_success", "cb_error"),
)
def SetSelection(self, handle, session_handle, app_id, options, cb_success, cb_error):
def SetSelection(self, session_handle, options, cb_success, cb_error):
try:
logger.debug(
f"EnableClipboard({handle}, {session_handle}, {app_id}, {options})"
)

response = Response(self.response, {})

request = ImplRequest(self, BUS_NAME, handle)
logger.debug(f"SetSelection({session_handle}, {options})")

if self.expect_close:

def closed_callback():
response = Response(2, {})
logger.debug(f"SetSelection Close() response {response}")
cb_success(response.response, response.results)

request.export(closed_callback)
cb_success()
else:
request.export()

def reply():
logger.debug(f"SetSelection with response {response}")
cb_success(response.response, response.results)

logger.debug(f"scheduling delay of {self.delay}")
GLib.timeout_add(self.delay, reply)
GLib.timeout_add(self.delay, cb_success)
except Exception as e:
logger.critical(e)
cb_error(e)


@dbus.service.method(
MAIN_IFACE,
in_signature="oosua{sv}",
out_signature="ua{sv}",
in_signature="ou",
out_signature="h",
async_callbacks=("cb_success", "cb_error"),
)
def SelectionWrite(
self, handle, session_handle, app_id, serial, options, cb_success, cb_error
self, session_handle, serial, cb_success, cb_error
):
try:
logger.debug(
f"SelectionWrite({handle}, {session_handle}, {app_id}, {serial}, {options})"
)

response = Response(self.response, {})

request = ImplRequest(self, BUS_NAME, handle)
logger.debug(f"SelectionWrite({session_handle}, {serial})")

# Open a temporary file and pass its fd
tmp = tempfile.TemporaryFile()
response.results["fd"] = dbus.types.UnixFd(tmp.fileno())
fd = dbus.types.UnixFd(tmp.fileno())

if self.expect_close:

def closed_callback():
response = Response(2, {})
logger.debug(f"SelectionWrite Close() response {response}")
cb_success(response.response, response.results)

request.export(closed_callback)
cb_success(fd)
else:
request.export()

def reply():
logger.debug(f"SelectionWrite with response {response}")
cb_success(response.response, response.results)

cb_success(fd)

logger.debug(f"scheduling delay of {self.delay}")
GLib.timeout_add(self.delay, reply)
except Exception as e:
Expand Down Expand Up @@ -197,43 +144,26 @@ def reply():

@dbus.service.method(
MAIN_IFACE,
in_signature="oossa{sv}",
out_signature="ua{sv}",
in_signature="os",
out_signature="h",
async_callbacks=("cb_success", "cb_error"),
)
def SelectionRead(
self, handle, session_handle, app_id, mime_type, options, cb_success, cb_error
self, session_handle, mime_type, cb_success, cb_error
):
try:
logger.debug(
f"SelectionRead({handle}, {session_handle}, {app_id}, {mime_type}, {options})"
)

response = Response(self.response, {})

request = ImplRequest(self, BUS_NAME, handle)
logger.debug(f"SelectionRead({session_handle}, {mime_type})")

# Open a temporary file and pass its fd
tmp = tempfile.TemporaryFile()
tmp.write(b"Clipboard")
tmp.seek(0)
response.results["fd"] = dbus.types.UnixFd(tmp.fileno())
fd = dbus.types.UnixFd(tmp.fileno())

if self.expect_close:

def closed_callback():
response = Response(2, {})
logger.debug(f"SelectionRead Close() response {response}")
cb_success(response.response, response.results)

request.export(closed_callback)
cb_success(fd)
else:
request.export()

def reply():
logger.debug(f"SelectionRead with response {response}")
cb_success(response.response, response.results)

cb_success(fd)

logger.debug(f"scheduling delay of {self.delay}")
GLib.timeout_add(self.delay, reply)
except Exception as e:
Expand Down
Loading

0 comments on commit 9130a52

Please sign in to comment.