mirror of
https://github.com/hyprwm/xdg-desktop-portal-hyprland.git
synced 2024-11-24 15:15:58 +01:00
Add session boilerplate
This commit is contained in:
parent
03599925b6
commit
a9e904a0c8
3 changed files with 51 additions and 0 deletions
|
@ -8,6 +8,10 @@ struct xdpw_request {
|
||||||
sd_bus_slot *slot;
|
sd_bus_slot *slot;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct xdpw_session {
|
||||||
|
sd_bus_slot *slot;
|
||||||
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PORTAL_RESPONSE_SUCCESS = 0,
|
PORTAL_RESPONSE_SUCCESS = 0,
|
||||||
PORTAL_RESPONSE_CANCELLED = 1,
|
PORTAL_RESPONSE_CANCELLED = 1,
|
||||||
|
@ -19,4 +23,7 @@ int init_screenshot(sd_bus *bus);
|
||||||
struct xdpw_request *request_create(sd_bus *bus, const char *object_path);
|
struct xdpw_request *request_create(sd_bus *bus, const char *object_path);
|
||||||
void request_destroy(struct xdpw_request *req);
|
void request_destroy(struct xdpw_request *req);
|
||||||
|
|
||||||
|
struct xdpw_session *session_create(sd_bus *bus, const char *object_path);
|
||||||
|
void session_destroy(struct xdpw_session *req);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,6 +26,7 @@ executable(
|
||||||
files([
|
files([
|
||||||
'main.c',
|
'main.c',
|
||||||
'request.c',
|
'request.c',
|
||||||
|
'session.c',
|
||||||
'screenshot.c',
|
'screenshot.c',
|
||||||
]),
|
]),
|
||||||
dependencies: [
|
dependencies: [
|
||||||
|
|
43
session.c
Normal file
43
session.c
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "xdpw.h"
|
||||||
|
|
||||||
|
static const char interface_name[] = "org.freedesktop.impl.portal.Session";
|
||||||
|
|
||||||
|
static int method_close(sd_bus_message *msg, void *data,
|
||||||
|
sd_bus_error *ret_error) {
|
||||||
|
// struct xdpw_session *session = data;
|
||||||
|
// TODO
|
||||||
|
printf("Session.Close\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const sd_bus_vtable session_vtable[] = {
|
||||||
|
SD_BUS_VTABLE_START(0),
|
||||||
|
SD_BUS_METHOD("Close", "", "", method_close, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
|
SD_BUS_VTABLE_END
|
||||||
|
};
|
||||||
|
|
||||||
|
struct xdpw_session *session_create(sd_bus *bus, const char *object_path) {
|
||||||
|
struct xdpw_session *req = calloc(1, sizeof(struct xdpw_session));
|
||||||
|
|
||||||
|
if (sd_bus_add_object_vtable(bus, &req->slot, object_path, interface_name,
|
||||||
|
session_vtable, NULL) < 0) {
|
||||||
|
free(req);
|
||||||
|
fprintf(stderr, "sd_bus_add_object_vtable failed: %s\n",
|
||||||
|
strerror(-errno));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
void session_destroy(struct xdpw_session *req) {
|
||||||
|
if (req == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sd_bus_slot_unref(req->slot);
|
||||||
|
free(req);
|
||||||
|
}
|
Loading…
Reference in a new issue