Add D-Bus boilerplate for Screenshot

This commit is contained in:
emersion 2018-12-13 18:03:44 +01:00
parent 7618fdc67d
commit 2f2fe91ff4
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
3 changed files with 84 additions and 3 deletions

View file

@ -4,6 +4,13 @@
#include <wayland-client.h> #include <wayland-client.h>
#include <systemd/sd-bus.h> #include <systemd/sd-bus.h>
struct xdpw_request {
sd_bus_slot *slot;
};
int init_screenshot(sd_bus *bus); int init_screenshot(sd_bus *bus);
struct xdpw_request *request_create(sd_bus *bus, const char *object_path);
void request_destroy(struct xdpw_request *req);
#endif #endif

View file

@ -25,6 +25,7 @@ executable(
'xdg-desktop-portal-wlr', 'xdg-desktop-portal-wlr',
files([ files([
'main.c', 'main.c',
'request.c',
'screenshot.c', 'screenshot.c',
]), ]),
dependencies: [ dependencies: [

View file

@ -1,5 +1,6 @@
#include <stdlib.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "xdpw.h" #include "xdpw.h"
static const char object_path[] = "/org/freedesktop/portal/desktop"; static const char object_path[] = "/org/freedesktop/portal/desktop";
@ -7,8 +8,80 @@ static const char interface_name[] = "org.freedesktop.impl.portal.Screenshot";
static int method_screenshot(sd_bus_message *msg, void *data, static int method_screenshot(sd_bus_message *msg, void *data,
sd_bus_error *ret_error) { sd_bus_error *ret_error) {
// TODO int ret = 0;
printf("Screenshot\n");
char *handle, *app_id, *parent_window;
ret = sd_bus_message_read(msg, "oss", &handle, &app_id, &parent_window);
if (ret < 0) {
return ret;
}
// TODO: read options
// TODO: cleanup this
struct xdpw_request *req =
request_create(sd_bus_message_get_bus(msg), handle);
if (req == NULL) {
return -ENOMEM;
}
sd_bus_message *reply = NULL;
ret = sd_bus_message_new_method_return(msg, &reply);
if (ret < 0) {
return ret;
}
ret = sd_bus_message_append(reply, "u", 0);
if (ret < 0) {
return ret;
}
ret = sd_bus_message_open_container(reply, 'a', "{sv}");
if (ret < 0) {
return ret;
}
ret = sd_bus_message_open_container(reply, 'e', "sv");
if (ret < 0) {
return ret;
}
ret = sd_bus_message_append_basic(reply, 's', "uri");
if (ret < 0) {
return ret;
}
ret = sd_bus_message_open_container(reply, 'v', "s");
if (ret < 0) {
return ret;
}
// TODO: take an actual screenshot
ret = sd_bus_message_append_basic(reply, 's', "file:///tmp/out.png");
if (ret < 0) {
return ret;
}
ret = sd_bus_message_close_container(reply);
if (ret < 0) {
return ret;
}
ret = sd_bus_message_close_container(reply);
if (ret < 0) {
return ret;
}
ret = sd_bus_message_close_container(reply);
if (ret < 0) {
return ret;
}
ret = sd_bus_send(NULL, reply, NULL);
if (ret < 0) {
return ret;
}
sd_bus_message_unref(reply);
return 0; return 0;
} }