mirror of
https://github.com/hyprwm/xdg-desktop-portal-hyprland.git
synced 2024-11-22 06:35:57 +01:00
First commit
This commit is contained in:
parent
4e091184ed
commit
7618fdc67d
6 changed files with 153 additions and 0 deletions
25
README.md
25
README.md
|
@ -1,2 +1,27 @@
|
||||||
# xdg-desktop-portal-wlr
|
# xdg-desktop-portal-wlr
|
||||||
|
|
||||||
xdg-desktop-portal backend for wlroots
|
xdg-desktop-portal backend for wlroots
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
```sh
|
||||||
|
meson build
|
||||||
|
ninja -C build
|
||||||
|
```
|
||||||
|
|
||||||
|
## Installing
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ninja -C build install
|
||||||
|
```
|
||||||
|
|
||||||
|
Make sure `XDG_CURRENT_DESKTOP=sway` is set.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
/usr/lib/xdg-desktop-portal -r &
|
||||||
|
xdg-desktop-portal-wlr
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT
|
||||||
|
|
9
include/xdpw.h
Normal file
9
include/xdpw.h
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef XDPW_H
|
||||||
|
#define XDPW_H
|
||||||
|
|
||||||
|
#include <wayland-client.h>
|
||||||
|
#include <systemd/sd-bus.h>
|
||||||
|
|
||||||
|
int init_screenshot(sd_bus *bus);
|
||||||
|
|
||||||
|
#endif
|
48
main.c
Normal file
48
main.c
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "xdpw.h"
|
||||||
|
|
||||||
|
static const char service_name[] = "org.freedesktop.impl.portal.desktop.wlr";
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
sd_bus *bus = NULL;
|
||||||
|
ret = sd_bus_open_user(&bus);
|
||||||
|
if (ret < 0) {
|
||||||
|
fprintf(stderr, "Failed to connect to user bus: %s\n", strerror(-ret));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
init_screenshot(bus);
|
||||||
|
|
||||||
|
ret = sd_bus_request_name(bus, service_name, 0);
|
||||||
|
if (ret < 0) {
|
||||||
|
fprintf(stderr, "Failed to acquire service name: %s\n", strerror(-ret));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
ret = sd_bus_process(bus, NULL);
|
||||||
|
if (ret < 0) {
|
||||||
|
fprintf(stderr, "sd_bus_process failed: %s\n", strerror(-ret));
|
||||||
|
} else if (ret > 0) {
|
||||||
|
// We processed a request, try to process another one, right-away
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = sd_bus_wait(bus, (uint64_t)-1);
|
||||||
|
if (ret < 0) {
|
||||||
|
fprintf(stderr, "sd_bus_wait failed: %s\n", strerror(-ret));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: cleanup
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
|
error:
|
||||||
|
sd_bus_unref(bus);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
41
meson.build
Normal file
41
meson.build
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
project(
|
||||||
|
'xdg-desktop-portal-wlr',
|
||||||
|
'c',
|
||||||
|
version: '0.0.0',
|
||||||
|
license: 'MIT',
|
||||||
|
meson_version: '>=0.43.0',
|
||||||
|
default_options: [
|
||||||
|
'c_std=c11',
|
||||||
|
'warning_level=2',
|
||||||
|
'werror=true',
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
add_project_arguments('-Wno-unused-parameter', language: 'c')
|
||||||
|
|
||||||
|
xdpw_inc = include_directories('include')
|
||||||
|
|
||||||
|
wayland_client = dependency('wayland-client')
|
||||||
|
wayland_protos = dependency('wayland-protocols', version: '>=1.14')
|
||||||
|
systemd = dependency('libsystemd')
|
||||||
|
|
||||||
|
# subdir('protocol')
|
||||||
|
|
||||||
|
executable(
|
||||||
|
'xdg-desktop-portal-wlr',
|
||||||
|
files([
|
||||||
|
'main.c',
|
||||||
|
'screenshot.c',
|
||||||
|
]),
|
||||||
|
dependencies: [
|
||||||
|
wayland_client,
|
||||||
|
systemd,
|
||||||
|
],
|
||||||
|
include_directories: [xdpw_inc],
|
||||||
|
install: true,
|
||||||
|
)
|
||||||
|
|
||||||
|
install_data(
|
||||||
|
'wlr.portal',
|
||||||
|
install_dir: join_paths(get_option('datadir'), 'xdg-desktop-portal', 'portals'),
|
||||||
|
)
|
26
screenshot.c
Normal file
26
screenshot.c
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "xdpw.h"
|
||||||
|
|
||||||
|
static const char object_path[] = "/org/freedesktop/portal/desktop";
|
||||||
|
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");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const sd_bus_vtable screenshot_vtable[] = {
|
||||||
|
SD_BUS_VTABLE_START(0),
|
||||||
|
SD_BUS_METHOD("Screenshot", "ossa{sv}", "ua{sv}", method_screenshot, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
|
SD_BUS_VTABLE_END
|
||||||
|
};
|
||||||
|
|
||||||
|
int init_screenshot(sd_bus *bus) {
|
||||||
|
// TODO: cleanup
|
||||||
|
sd_bus_slot *slot = NULL;
|
||||||
|
return sd_bus_add_object_vtable(bus, &slot, object_path, interface_name,
|
||||||
|
screenshot_vtable, NULL);
|
||||||
|
}
|
4
wlr.portal
Normal file
4
wlr.portal
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[portal]
|
||||||
|
DBusName=org.freedesktop.impl.portal.desktop.wlr
|
||||||
|
Interfaces=org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.ScreenCast;
|
||||||
|
UseIn=sway
|
Loading…
Reference in a new issue