Skip to content

Commit

Permalink
update: made it uptodate with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
DRAGONTOS committed Jan 7, 2024
1 parent 486110e commit 2802d5e
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 63 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Expand All @@ -56,9 +57,8 @@ build-*/

.cache
.vscode/
.idea

hyprland-share-picker/build/

protocols/*.c
protocols/*.h
protocols/*.h
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ include_directories(
)

set(CMAKE_CXX_STANDARD 23)
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-value -Wno-missing-field-initializers -Wno-narrowing -Wno-pointer-arith -fpermissive)
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-value
-Wno-missing-field-initializers -Wno-narrowing -Wno-pointer-arith
-fpermissive -Wno-address-of-temporary)

message(STATUS "Checking deps...")
add_subdirectory(subprojects/sdbus-cpp)
Expand All @@ -34,7 +36,7 @@ add_subdirectory(hyprland-share-picker)
find_package(Threads REQUIRED)

find_package(PkgConfig REQUIRED)
pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-protocols libpipewire-0.3 libspa-0.2 libdrm gbm)
pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-protocols libpipewire-0.3 libspa-0.2 libdrm gbm hyprlang>=0.2.0)

file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp")
add_executable(xdg-desktop-portal-hyprland ${SRCFILES})
Expand Down
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
# xdg-desktop-portal-hyprland With GTK
# xdg-desktop-portal-hyprland
An [XDG Desktop Portal](https://github.com/flatpak/xdg-desktop-portal) backend for Hyprland.

## Installing
```sh
git clone -b theoparis/fix-build --recursive https://github.com/dragontos/xdg-desktop-portal-hyprland
git clone --recursive https://github.com/hyprwm/xdg-desktop-portal-hyprland
cd xdg-desktop-portal-hyprland/
make all
sudo make install
```
## Make all
```sh
make all
sudo make install
```
## Make hyprland-share-picker
```
meson build
ninja -C build
```

## Running, FAQs, etc.
See [the Hyprland wiki](https://wiki.hyprland.org/Useful-Utilities/Hyprland-desktop-portal/)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.6
1.3.0
43 changes: 39 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
inputs.nixpkgs.follows = "nixpkgs";
inputs.systems.follows = "systems";
};

hyprlang.url = "github:hyprwm/hyprlang";
};

outputs = {
Expand Down
14 changes: 0 additions & 14 deletions go.mod

This file was deleted.

12 changes: 0 additions & 12 deletions go.sum

This file was deleted.

2 changes: 2 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
meson,
ninja,
pkg-config,
hyprlang,
libdrm,
mesa,
pipewire,
Expand Down Expand Up @@ -48,6 +49,7 @@ stdenv.mkDerivation {
libdrm
mesa
pipewire
hyprlang
qtbase
qttools
qtwayland
Expand Down
1 change: 1 addition & 0 deletions nix/overlays.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ in {
inherit (final) hyprland-protocols;
inherit (final.qt6) qtbase qttools wrapQtAppsHook qtwayland;
inherit version;
inherit (inputs.hyprlang.packages.${prev.system}) hyprlang;
};
};
}
31 changes: 27 additions & 4 deletions src/core/PortalManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,25 @@ inline const zwp_linux_dmabuf_feedback_v1_listener dmabufFeedbackListener = {

//

CPortalManager::CPortalManager() {
const auto XDG_CONFIG_HOME = getenv("XDG_CONFIG_HOME");
const auto HOME = getenv("HOME");

if (!HOME && !XDG_CONFIG_HOME) {
Debug::log(CRIT, "Cannot proceed: neither $HOME nor $XDG_CONFIG_HOME is present in env");
throw "$HOME and $XDG_CONFIG_HOME both missing from env";
}

std::string path = XDG_CONFIG_HOME ? std::string{XDG_CONFIG_HOME} + "/hypr/xdph.conf" : std::string{HOME} + "/.config/hypr/xdph.conf";

m_sConfig.config = std::make_unique<Hyprlang::CConfig>(path.c_str(), Hyprlang::SConfigOptions{.allowMissingConfig = true});

m_sConfig.config->addConfigValue("general:toplevel_dynamic_bind", {0L});

m_sConfig.config->commence();
m_sConfig.config->parse();
}

void CPortalManager::onGlobal(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version) {
const std::string INTERFACE = interface;

Expand Down Expand Up @@ -234,9 +253,13 @@ void CPortalManager::onGlobal(void* data, struct wl_registry* registry, uint32_t
else if (INTERFACE == wl_shm_interface.name)
m_sWaylandConnection.shm = (wl_shm*)wl_registry_bind(registry, name, &wl_shm_interface, version);

else if (INTERFACE == zwlr_foreign_toplevel_manager_v1_interface.name)
m_sHelpers.toplevel =
std::make_unique<CToplevelManager>((zwlr_foreign_toplevel_manager_v1*)wl_registry_bind(registry, name, &zwlr_foreign_toplevel_manager_v1_interface, version));
else if (INTERFACE == zwlr_foreign_toplevel_manager_v1_interface.name) {
m_sHelpers.toplevel = std::make_unique<CToplevelManager>(registry, name, version);

// remove when another fix is found for https://github.com/hyprwm/xdg-desktop-portal-hyprland/issues/147
if (!std::any_cast<Hyprlang::INT>(m_sConfig.config->getConfigValue("general:toplevel_dynamic_bind")))
m_sHelpers.toplevel->activate();
}
}

void CPortalManager::onGlobalRemoved(void* data, struct wl_registry* registry, uint32_t name) {
Expand Down Expand Up @@ -331,7 +354,7 @@ void CPortalManager::startEventLoop() {

std::thread pollThr([this, &pollfds]() {
while (1) {
int ret = poll(pollfds, 3, 5 /* 5 seconds, reasonable. It's because we might need to terminate */);
int ret = poll(pollfds, 3, 5000 /* 5 seconds, reasonable. It's because we might need to terminate */);
if (ret < 0) {
Debug::log(CRIT, "[core] Polling fds failed with {}", strerror(errno));
g_pPortalManager->terminate();
Expand Down
7 changes: 7 additions & 0 deletions src/core/PortalManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <memory>
#include <sdbus-c++/sdbus-c++.h>
#include <wayland-client.h>
#include <hyprlang.hpp>

#include "../portals/Screencopy.hpp"
#include "../portals/Screenshot.hpp"
Expand Down Expand Up @@ -30,6 +31,8 @@ struct SDMABUFModifier {

class CPortalManager {
public:
CPortalManager();

void init();

void onGlobal(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version);
Expand Down Expand Up @@ -67,6 +70,10 @@ class CPortalManager {
} dma;
} m_sWaylandConnection;

struct {
std::unique_ptr<Hyprlang::CConfig> config;
} m_sConfig;

std::vector<SDMABUFModifier> m_vDMABUFMods;

void addTimer(const CTimer& timer);
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ executable('xdg-desktop-portal-hyprland',
[src, wl_proto_files],
dependencies: [
dependency('gbm'),
dependency('hyprlang'),
dependency('libdrm'),
dependency('libpipewire-0.3'),
dependency('sdbus-c++'),
Expand Down
24 changes: 20 additions & 4 deletions src/portals/Screencopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ static void wlrOnReady(void* data, zwlr_screencopy_frame_v1* frame, uint32_t tv_

g_pPortalManager->m_sPortals.screencopy->m_pPipewire->enqueue(PSESSION);

g_pPortalManager->m_sPortals.screencopy->queueNextShareFrame(PSESSION);
if (g_pPortalManager->m_sPortals.screencopy->m_pPipewire->streamFromSession(PSESSION))
g_pPortalManager->m_sPortals.screencopy->queueNextShareFrame(PSESSION);

zwlr_screencopy_frame_v1_destroy(frame);
PSESSION->sharingData.frameCallback = nullptr;
Expand Down Expand Up @@ -284,6 +285,8 @@ static const hyprland_toplevel_export_frame_v1_listener hyprlandFrameListener =
void CScreencopyPortal::onCreateSession(sdbus::MethodCall& call) {
sdbus::ObjectPath requestHandle, sessionHandle;

g_pPortalManager->m_sHelpers.toplevel->activate();

call >> requestHandle;
call >> sessionHandle;

Expand All @@ -299,13 +302,16 @@ void CScreencopyPortal::onCreateSession(sdbus::MethodCall& call) {

// create objects
PSESSION->session = createDBusSession(sessionHandle);
PSESSION->session->onDestroy = [PSESSION, this]() {
PSESSION->session->onDestroy = [PSESSION, this]() {
if (PSESSION->sharingData.active) {
m_pPipewire->destroyStream(PSESSION);
Debug::log(LOG, "[screencopy] Stream destroyed");
}
PSESSION->session.release();
Debug::log(LOG, "[screencopy] Session destroyed");

// deactivate toplevel so it doesn't listen and waste battery
g_pPortalManager->m_sHelpers.toplevel->deactivate();
};
PSESSION->request = createDBusRequest(requestHandle);
PSESSION->request->onDestroy = [PSESSION]() { PSESSION->request.release(); };
Expand Down Expand Up @@ -1084,7 +1090,7 @@ uint32_t CPipewireConnection::buildFormatsFor(spa_pod_builder* b[2], const spa_p

paramCount = 2;
params[0] = build_format(b[0], pwFromDrmFourcc(stream->pSession->sharingData.frameInfoDMA.fmt), stream->pSession->sharingData.frameInfoDMA.w,
stream->pSession->sharingData.frameInfoDMA.h, stream->pSession->sharingData.framerate, modifiers, modCount);
stream->pSession->sharingData.frameInfoDMA.h, stream->pSession->sharingData.framerate, modifiers, modCount);
assert(params[0] != NULL);
params[1] = build_format(b[1], pwFromDrmFourcc(stream->pSession->sharingData.frameInfoSHM.fmt), stream->pSession->sharingData.frameInfoSHM.w,
stream->pSession->sharingData.frameInfoSHM.h, stream->pSession->sharingData.framerate, NULL, 0);
Expand All @@ -1094,7 +1100,7 @@ uint32_t CPipewireConnection::buildFormatsFor(spa_pod_builder* b[2], const spa_p

paramCount = 1;
params[0] = build_format(b[0], pwFromDrmFourcc(stream->pSession->sharingData.frameInfoSHM.fmt), stream->pSession->sharingData.frameInfoSHM.w,
stream->pSession->sharingData.frameInfoSHM.h, stream->pSession->sharingData.framerate, NULL, 0);
stream->pSession->sharingData.frameInfoSHM.h, stream->pSession->sharingData.framerate, NULL, 0);
}

if (modifiers)
Expand All @@ -1118,6 +1124,11 @@ CPipewireConnection::SPWStream* CPipewireConnection::streamFromSession(CScreenco
void CPipewireConnection::enqueue(CScreencopyPortal::SSession* pSession) {
const auto PSTREAM = streamFromSession(pSession);

if (!PSTREAM) {
Debug::log(ERR, "[pw] Attempted enqueue on invalid session??");
return;
}

Debug::log(TRACE, "[pw] enqueue on {}", (void*)PSTREAM);

if (!PSTREAM->currentPWBuffer) {
Expand Down Expand Up @@ -1202,6 +1213,11 @@ void CPipewireConnection::enqueue(CScreencopyPortal::SSession* pSession) {
void CPipewireConnection::dequeue(CScreencopyPortal::SSession* pSession) {
const auto PSTREAM = streamFromSession(pSession);

if (!PSTREAM) {
Debug::log(ERR, "[pw] Attempted dequeue on invalid session??");
return;
}

Debug::log(TRACE, "[pw] dequeue on {}", (void*)PSTREAM);

const auto PWBUF = pw_stream_dequeue_buffer(PSTREAM->stream);
Expand Down
4 changes: 3 additions & 1 deletion src/shared/ScreencopyShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ uint32_t drmFourccFromSHM(wl_shm_format format) {
case WL_SHM_FORMAT_ARGB2101010:
case WL_SHM_FORMAT_ABGR2101010:
case WL_SHM_FORMAT_RGBA1010102:
case WL_SHM_FORMAT_BGRA1010102: return (uint32_t)format;
case WL_SHM_FORMAT_BGRA1010102:
case WL_SHM_FORMAT_BGR888: return (uint32_t)format;
default: Debug::log(ERR, "[screencopy] Unknown format {}", (int)format); abort();
}
}
Expand All @@ -178,6 +179,7 @@ spa_video_format pwFromDrmFourcc(uint32_t format) {
case DRM_FORMAT_ABGR2101010: return SPA_VIDEO_FORMAT_ABGR_210LE;
case DRM_FORMAT_RGBA1010102: return SPA_VIDEO_FORMAT_RGBA_102LE;
case DRM_FORMAT_BGRA1010102: return SPA_VIDEO_FORMAT_BGRA_102LE;
case DRM_FORMAT_BGR888: return SPA_VIDEO_FORMAT_BGR;
default: Debug::log(ERR, "[screencopy] Unknown format {}", (int)format); abort();
}
}
Expand Down
Loading

0 comments on commit 2802d5e

Please sign in to comment.