Skip to content

Commit

Permalink
config: add a config with hyprlang
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Jan 3, 2024
1 parent 54a3025 commit c5b69eb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,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
22 changes: 21 additions & 1 deletion 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, 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 @@ -238,7 +257,8 @@ void CPortalManager::onGlobal(void* data, struct wl_registry* registry, uint32_t
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
m_sHelpers.toplevel->activate();
if (!std::any_cast<Hyprlang::INT>(m_sConfig.config->getConfigValue("general:toplevel_dynamic_bind")))
m_sHelpers.toplevel->activate();
}
}

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

0 comments on commit c5b69eb

Please sign in to comment.