mirror of
https://github.com/hyprwm/xdg-desktop-portal-hyprland.git
synced 2024-12-22 17:59:47 +01:00
Add D-Bus boilerplate for Screenshot
This commit is contained in:
parent
7618fdc67d
commit
2f2fe91ff4
3 changed files with 84 additions and 3 deletions
|
@ -4,6 +4,13 @@
|
|||
#include <wayland-client.h>
|
||||
#include <systemd/sd-bus.h>
|
||||
|
||||
struct xdpw_request {
|
||||
sd_bus_slot *slot;
|
||||
};
|
||||
|
||||
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
|
||||
|
|
|
@ -25,6 +25,7 @@ executable(
|
|||
'xdg-desktop-portal-wlr',
|
||||
files([
|
||||
'main.c',
|
||||
'request.c',
|
||||
'screenshot.c',
|
||||
]),
|
||||
dependencies: [
|
||||
|
|
79
screenshot.c
79
screenshot.c
|
@ -1,5 +1,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "xdpw.h"
|
||||
|
||||
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,
|
||||
sd_bus_error *ret_error) {
|
||||
// TODO
|
||||
printf("Screenshot\n");
|
||||
int ret = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue