Skip to content

Linux + iPhone Continuity / iMessage / SMS

fix: implement ext-data-control-v1

Zack Bartel7abc397dddba
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index cf3038d..9a47b95 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -3,7 +3,6 @@ add_library(tether STATIC
src/i18n.cpp
src/event_loop.cpp
src/net.cpp
- src/clipboard.cpp
src/base64.cpp
src/otp.cpp
src/file_transfer.cpp
@@ -36,6 +35,7 @@ add_library(tether STATIC
src/wayland.cpp
src/wayland_protocols/wayland.cpp
src/wayland_protocols/wlr-data-control-unstable-v1.cpp
+ src/wayland_protocols/ext-data-control-v1.cpp
)
pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0 gio-2.0)
diff --git a/src/core/include/tether/clipboard.hpp b/src/core/include/tether/clipboard.hpp
index 3b8cf0c..302c761 100644
--- a/src/core/include/tether/clipboard.hpp
+++ b/src/core/include/tether/clipboard.hpp
@@ -1,43 +1,192 @@
+#pragma once
+
#include "tether/event_loop.hpp"
+#include <cerrno>
+#include <fcntl.h>
#include <functional>
#include <map>
#include <memory>
#include <string>
+#include <tether/log.hpp>
+#include <thread>
+#include <unistd.h>
#include <vector>
#include <wayland-client.h>
-class CCZwlrDataControlManagerV1;
-class CCWlSeat;
-class CCZwlrDataControlDeviceV1;
-class CCZwlrDataControlOfferV1;
-class CCZwlrDataControlSourceV1;
-
namespace tether {
+ // Clipboard access needs a data-control protocol. wlroots compositors expose
+ // zwlr_data_control_v1, KWin exposes ext_data_control_v1. Both have the
+ // exact same shape, so the implementation is reused.
class ClipboardManager {
public:
- ClipboardManager(CCZwlrDataControlManagerV1* manager,
- CCWlSeat* seat,
- EpollEventLoop& loop,
- wl_display* display);
- ~ClipboardManager();
+ virtual ~ClipboardManager() = default;
+
+ // Callback for native clipboard updates
+ virtual void set_update_callback(std::function<void(const std::string&)> cb) = 0;
+
+ // Push text from Tether network to the native clipboard
+ virtual void copy(const std::string& text) = 0;
+ };
+
+ template <typename Manager, typename Device, typename Offer, typename Source>
+ class DataControlClipboard final : public ClipboardManager {
+ public:
+ DataControlClipboard(Manager* manager, wl_proxy* seat, EpollEventLoop& loop, wl_display* display)
+ : manager_(manager), loop_(loop), display_(display) {
+
+ device_ = std::make_unique<Device>(manager_->sendGetDataDevice(seat));
+
+ device_->setDataOffer([this](Device*, wl_proxy* offer_proxy) {
+ auto offer = std::make_unique<Offer>(offer_proxy);
+
+ if (offers_.size() > 5) {
+ offers_.erase(offers_.begin());
+ offer_mimes_.erase(offer_mimes_.begin());
+ }
+
+ offer->setOffer([this, offer_proxy](Offer*, const char* mime_type) {
+ offer_mimes_[offer_proxy].push_back(mime_type);
+ });
+
+ offers_[offer_proxy] = std::move(offer);
+ });
+
+ device_->setSelection([this](Device*, wl_proxy* offer_proxy) { on_selection(offer_proxy); });
+ }
+
+ ~DataControlClipboard() override {
+ for (auto const& [fd, _] : pending_reads_) {
+ loop_.removeFd(fd);
+ close(fd);
+ }
+ source_.reset(); // before the device that owns the selection
+ if (device_) {
+ device_->sendDestroy();
+ }
+ }
+
+ void set_update_callback(std::function<void(const std::string&)> cb) override { cb_ = std::move(cb); }
+
+ void copy(const std::string& text) override {
+ auto source = std::make_unique<Source>(manager_->sendCreateDataSource());
- // Set callback to receive native Wayland clipboard updates
- void set_update_callback(std::function<void(const std::string&)> cb);
+ source->sendOffer("text/plain");
+ source->sendOffer("UTF8_STRING");
- // Push text from Tether network to native Wayland clipboard
- void copy(const std::string& text);
+ std::string text_to_send = text;
+ source->setSend([text_to_send](Source*, const char*, int32_t fd) {
+ // detached write thread: touches no manager state
+ std::thread([text_to_send, fd]() {
+ if (write(fd, text_to_send.c_str(), text_to_send.size()) < 0) {
+ debug::log(ERR, "clipboard write error\n");
+ }
+ close(fd);
+ }).detach();
+ });
+
+ // compositor cancels our source when something else takes the selection.
+ source->setCancelled([this](Source* s) {
+ if (source_.get() == s)
+ source_.reset();
+ });
+
+ device_->sendSetSelection(source.get());
+ source_ = std::move(source);
+ }
private:
- CCZwlrDataControlManagerV1* manager_;
- CCWlSeat* seat_;
+ void on_selection(wl_proxy* offer_proxy) {
+ if (!offer_proxy) {
+ offers_.clear();
+ offer_mimes_.clear();
+ if (cb_)
+ cb_("");
+ return;
+ }
+
+ auto it_mimes = offer_mimes_.find(offer_proxy);
+ auto it_offer = offers_.find(offer_proxy);
+
+ if (it_mimes == offer_mimes_.end() || it_offer == offers_.end()) {
+ return;
+ }
+
+ static const std::vector<std::string> priorities = {"text/plain;charset=utf-8",
+ "text/plain;charset=UTF-8",
+ "UTF8_STRING",
+ "text/plain;charset=utf8",
+ "text/plain",
+ "TEXT",
+ "STRING"};
+
+ std::string best_mime;
+ for (const auto& p : priorities) {
+ for (const auto& m : it_mimes->second) {
+ if (m == p) {
+ best_mime = m;
+ break;
+ }
+ }
+ if (!best_mime.empty())
+ break;
+ }
+
+ if (best_mime.empty())
+ return;
+
+ int pipefs[2];
+ if (pipe(pipefs) < 0)
+ return;
+
+ // non-blocking read end for the event loop
+ fcntl(pipefs[0], F_SETFL, O_NONBLOCK);
+
+ it_offer->second->sendReceive(best_mime.c_str(), pipefs[1]);
+ close(pipefs[1]);
+ wl_display_flush(display_);
+
+ // Cleanup: remove all other offers as this one is now the active selection
+ auto saved_offer = std::move(it_offer->second);
+ auto saved_mimes = std::move(it_mimes->second);
+ offers_.clear();
+ offer_mimes_.clear();
+ offers_[offer_proxy] = std::move(saved_offer);
+ offer_mimes_[offer_proxy] = std::move(saved_mimes);
+
+ loop_.addFd(pipefs[0], [this](int fd) {
+ char buf[4096];
+ ssize_t n = read(fd, buf, sizeof(buf));
+ if (n > 0) {
+ pending_reads_[fd].append(buf, n);
+ } else if (n == 0 || (n < 0 && errno != EAGAIN)) {
+ // Done reading or error
+ std::string result = pending_reads_[fd];
+ pending_reads_.erase(fd);
+ loop_.removeFd(fd);
+ close(fd);
+
+ // trim trailing nulls and whitespace
+ while (!result.empty() &&
+ (result.back() == '\0' || isspace(static_cast<unsigned char>(result.back())))) {
+ result.pop_back();
+ }
+
+ if (cb_) {
+ cb_(result);
+ }
+ }
+ });
+ }
+
+ Manager* manager_;
EpollEventLoop& loop_;
wl_display* display_;
- std::unique_ptr<CCZwlrDataControlDeviceV1> device_;
- std::unique_ptr<CCZwlrDataControlSourceV1> source_;
+ std::unique_ptr<Device> device_;
+ std::unique_ptr<Source> source_;
std::function<void(const std::string&)> cb_;
- std::map<wl_proxy*, std::unique_ptr<CCZwlrDataControlOfferV1>> offers_;
+ std::map<wl_proxy*, std::unique_ptr<Offer>> offers_;
std::map<wl_proxy*, std::vector<std::string>> offer_mimes_;
std::map<int, std::string> pending_reads_;
};
diff --git a/src/core/include/tether/wayland.hpp b/src/core/include/tether/wayland.hpp
index 6adb404..76ee892 100644
--- a/src/core/include/tether/wayland.hpp
+++ b/src/core/include/tether/wayland.hpp
@@ -11,6 +11,7 @@ class CCWlDisplay;
class CCWlRegistry;
class CCWlSeat;
class CCZwlrDataControlManagerV1;
+class CCExtDataControlManagerV1;
struct wl_display;
namespace tether {
@@ -34,7 +35,8 @@ namespace tether {
std::unique_ptr<CCWlRegistry> registry_;
std::unique_ptr<CCWlSeat> seat_;
- std::unique_ptr<CCZwlrDataControlManagerV1> data_control_manager_;
+ std::unique_ptr<CCZwlrDataControlManagerV1> wlr_data_control_manager_;
+ std::unique_ptr<CCExtDataControlManagerV1> ext_data_control_manager_;
std::unique_ptr<ClipboardManager> clipboard_;
std::function<void(const std::string&)> clipboard_cb_;
diff --git a/src/core/src/clipboard.cpp b/src/core/src/clipboard.cpp
deleted file mode 100644
index bfdda01..0000000
--- a/src/core/src/clipboard.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
-#include "tether/clipboard.hpp"
-#include "wayland_protocols/wayland.hpp"
-#include "wayland_protocols/wlr-data-control-unstable-v1.hpp"
-#include <cstring>
-#include <fcntl.h>
-#include <tether/log.hpp>
-#include <thread>
-#include <unistd.h>
-
-namespace tether {
-
- ClipboardManager::ClipboardManager(CCZwlrDataControlManagerV1* manager,
- CCWlSeat* seat,
- EpollEventLoop& loop,
- wl_display* display)
- : manager_(manager), seat_(seat), loop_(loop), display_(display) {
-
- auto proxy = manager_->sendGetDataDevice((wl_proxy*)seat_->resource());
- device_ = std::make_unique<CCZwlrDataControlDeviceV1>(proxy);
-
- device_->setDataOffer([this](CCZwlrDataControlDeviceV1*, wl_proxy* offer_proxy) {
- auto offer = std::make_unique<CCZwlrDataControlOfferV1>(offer_proxy);
-
- // Clean up previous offers that were never selected to avoid memory growth,
- // but keep the current one and any very recent ones.
- // Wayland selection events usually follow data_offer events quickly.
- if (offers_.size() > 5) {
- offers_.erase(offers_.begin());
- offer_mimes_.erase(offer_mimes_.begin());
- }
-
- offer->setOffer([this, offer_proxy](CCZwlrDataControlOfferV1*, const char* mime_type) {
- offer_mimes_[offer_proxy].push_back(mime_type);
- });
-
- offers_[offer_proxy] = std::move(offer);
- });
-
- device_->setSelection([this](CCZwlrDataControlDeviceV1*, wl_proxy* offer_proxy) {
- if (!offer_proxy) {
- offers_.clear();
- offer_mimes_.clear();
- if (cb_)
- cb_("");
- return;
- }
-
- auto it_mimes = offer_mimes_.find(offer_proxy);
- auto it_offer = offers_.find(offer_proxy);
-
- if (it_mimes == offer_mimes_.end() || it_offer == offers_.end()) {
- return;
- }
-
- const auto& current_mimes = it_mimes->second;
- auto& current_offer = it_offer->second;
-
- // Selection changed, negotiate best mime type
- std::string best_mime = "text/plain"; // fallback
- bool found = false;
-
- static const std::vector<std::string> priorities = {"text/plain;charset=utf-8",
- "text/plain;charset=UTF-8",
- "UTF8_STRING",
- "text/plain;charset=utf8",
- "text/plain",
- "TEXT",
- "STRING"};
-
- for (const auto& p : priorities) {
- for (const auto& m : current_mimes) {
- if (m == p) {
- best_mime = m;
- found = true;
- break;
- }
- }
- if (found)
- break;
- }
-
- // text-only sync. No text mime => skip it. Reading the
- // first offered mime (image/png) feeds binary into the JSON
- // string field and aborts the daemon on invalid UTF-8.
- if (!found)
- return;
-
- int pipefs[2];
- if (pipe(pipefs) < 0)
- return;
-
- // Use non-blocking read end for the event loop
- fcntl(pipefs[0], F_SETFL, O_NONBLOCK);
-
- current_offer->sendReceive(best_mime.c_str(), pipefs[1]);
- close(pipefs[1]);
- wl_display_flush(display_);
-
- // Cleanup: remove all other offers as this one is now the active selection
- auto saved_offer = std::move(offers_[offer_proxy]);
- auto saved_mimes = std::move(offer_mimes_[offer_proxy]);
- offers_.clear();
- offer_mimes_.clear();
- offers_[offer_proxy] = std::move(saved_offer);
- offer_mimes_[offer_proxy] = std::move(saved_mimes);
-
- loop_.addFd(pipefs[0], [this](int fd) {
- char buf[4096];
- ssize_t n = read(fd, buf, sizeof(buf));
- if (n > 0) {
- pending_reads_[fd].append(buf, n);
- } else if (n == 0 || (n < 0 && errno != EAGAIN)) {
- // Done reading or error
- std::string result = pending_reads_[fd];
- pending_reads_.erase(fd);
- loop_.removeFd(fd);
- close(fd);
-
- // Trim trailing nulls and whitespace. Cast: isspace() on a negative
- // char is UB, and clipboard text is routinely non-ASCII.
- while (!result.empty() &&
- (result.back() == '\0' || isspace(static_cast<unsigned char>(result.back())))) {
- result.pop_back();
- }
-
- if (cb_) {
- cb_(result);
- }
- }
- });
- });
- }
-
- ClipboardManager::~ClipboardManager() {
- for (auto const& [fd, _] : pending_reads_) {
- loop_.removeFd(fd);
- close(fd);
- }
- source_.reset(); // before the device that owns the selection
- if (device_) {
- device_->sendDestroy();
- }
- }
-
- void ClipboardManager::set_update_callback(std::function<void(const std::string&)> cb) { cb_ = std::move(cb); }
-
- void ClipboardManager::copy(const std::string& text) {
- auto proxy = manager_->sendCreateDataSource();
- auto source = std::make_unique<CCZwlrDataControlSourceV1>(proxy);
-
- source->sendOffer("text/plain");
- source->sendOffer("UTF8_STRING");
-
- // Capture text by value for the callback
- std::string text_to_send = text;
- source->setSend([text_to_send](CCZwlrDataControlSourceV1* s, const char* mime_type, int32_t fd) {
- // For writing, a detached thread is safer than reading because it doesn't
- // trigger an immediate broadcast callback on its own; however, for
- // strict single-threading we could use EPOLLOUT.
- // Given that we are primarily fixing the READ data race, we'll keep
- // the write simple but ensure it doesn't touch any manager state.
- std::thread([text_to_send, fd]() {
- if (write(fd, text_to_send.c_str(), text_to_send.size()) < 0) {
- debug::log(ERR, "clipboard write error\n");
- }
- close(fd);
- }).detach();
- });
-
- // compositor cancels our source when something else takes the selection.
- source->setCancelled([this](CCZwlrDataControlSourceV1* s) {
- if (source_.get() == s)
- source_.reset();
- });
-
- device_->sendSetSelection(source.get());
- source_ = std::move(source);
- }
-
-} // namespace tether
diff --git a/src/core/src/wayland.cpp b/src/core/src/wayland.cpp
index 99ac48d..43250fb 100644
--- a/src/core/src/wayland.cpp
+++ b/src/core/src/wayland.cpp
@@ -1,5 +1,6 @@
#include "tether/wayland.hpp"
#include "wayland_protocols/wayland.hpp"
+#include "wayland_protocols/ext-data-control-v1.hpp"
#include "wayland_protocols/wlr-data-control-unstable-v1.hpp"
#include <cstring>
@@ -18,7 +19,8 @@ namespace tether {
if (raw_display_) {
// Crucial: Destroy all regular proxies BEFORE disconnecting the display.
clipboard_.reset();
- data_control_manager_.reset();
+ ext_data_control_manager_.reset();
+ wlr_data_control_manager_.reset();
seat_.reset();
registry_.reset();
@@ -55,7 +57,10 @@ namespace tether {
} else if (std::strcmp(interface, "zwlr_data_control_manager_v1") == 0) {
auto p =
wl_registry_bind((wl_registry*)r->resource(), name, &zwlr_data_control_manager_v1_interface, 1);
- data_control_manager_ = std::make_unique<CCZwlrDataControlManagerV1>((wl_proxy*)p);
+ wlr_data_control_manager_ = std::make_unique<CCZwlrDataControlManagerV1>((wl_proxy*)p);
+ } else if (std::strcmp(interface, "ext_data_control_manager_v1") == 0) {
+ auto p = wl_registry_bind((wl_registry*)r->resource(), name, &ext_data_control_manager_v1_interface, 1);
+ ext_data_control_manager_ = std::make_unique<CCExtDataControlManagerV1>((wl_proxy*)p);
}
});
@@ -64,12 +69,30 @@ namespace tether {
wl_display_roundtrip(raw_display_);
wl_display_roundtrip(raw_display_);
- if (!seat_ || !data_control_manager_) {
- debug::log(ERR, "WaylandContext: Failed to obtain necessary globals.");
+ if (!seat_) {
+ debug::log(ERR, "WaylandContext: compositor exposes no wl_seat.");
return false;
}
- clipboard_ = std::make_unique<ClipboardManager>(data_control_manager_.get(), seat_.get(), loop_, raw_display_);
+ // Prefer the standardized protocol; KWin only implements this one.
+ if (ext_data_control_manager_) {
+ clipboard_ = std::make_unique<DataControlClipboard<CCExtDataControlManagerV1,
+ CCExtDataControlDeviceV1,
+ CCExtDataControlOfferV1,
+ CCExtDataControlSourceV1>>(
+ ext_data_control_manager_.get(), (wl_proxy*)seat_->resource(), loop_, raw_display_);
+ } else if (wlr_data_control_manager_) {
+ clipboard_ = std::make_unique<DataControlClipboard<CCZwlrDataControlManagerV1,
+ CCZwlrDataControlDeviceV1,
+ CCZwlrDataControlOfferV1,
+ CCZwlrDataControlSourceV1>>(
+ wlr_data_control_manager_.get(), (wl_proxy*)seat_->resource(), loop_, raw_display_);
+ } else {
+ debug::log(ERR,
+ "WaylandContext: compositor exposes neither ext_data_control_manager_v1 nor "
+ "zwlr_data_control_manager_v1; clipboard sync unavailable.");
+ return false;
+ }
clipboard_->set_update_callback([this](const std::string& text) {
bool changed = false;
diff --git a/src/core/src/wayland_protocols/ext-data-control-v1.cpp b/src/core/src/wayland_protocols/ext-data-control-v1.cpp
new file mode 100644
index 0000000..7979ad1
--- /dev/null
+++ b/src/core/src/wayland_protocols/ext-data-control-v1.cpp
@@ -0,0 +1,379 @@
+// Generated with hyprwayland-scanner 0.4.6. Made with vaxry's keyboard and ❤️.
+// ext_data_control_v1
+
+/*
+ This protocol's authors' copyright notice is:
+
+
+ Copyright © 2018 Simon Ser
+ Copyright © 2019 Ivan Molodetskikh
+ Copyright © 2024 Neal Gompa
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that copyright notice and this permission
+ notice appear in supporting documentation, and that the name of
+ the copyright holders not be used in advertising or publicity
+ pertaining to distribution of the software without specific,
+ written prior permission. The copyright holders make no
+ representations about the suitability of this software for any
+ purpose. It is provided "as is" without express or implied
+ warranty.
+
+ THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ THIS SOFTWARE.
+
+*/
+
+#define private public
+#define HYPRWAYLAND_SCANNER_NO_INTERFACES
+#include "ext-data-control-v1.hpp"
+#undef private
+#define F std::function
+
+static const wl_interface* extDataControlV1_dummyTypes[] = { nullptr };
+
+// Reference all other interfaces.
+// The reason why this is in snake is to
+// be able to cooperate with existing
+// wayland_scanner interfaces (they are interop)
+extern const wl_interface ext_data_control_manager_v1_interface;
+extern const wl_interface ext_data_control_device_v1_interface;
+extern const wl_interface ext_data_control_source_v1_interface;
+extern const wl_interface ext_data_control_offer_v1_interface;
+extern const wl_interface wl_seat_interface;
+
+static const void* _CCExtDataControlManagerV1VTable[] = {
+ nullptr,
+};
+
+wl_proxy* CCExtDataControlManagerV1::sendCreateDataSource() {
+ if (!pResource)
+ return nullptr;
+
+ auto proxy = wl_proxy_marshal_flags(pResource, 0, &ext_data_control_source_v1_interface, wl_proxy_get_version(pResource), 0, nullptr);
+
+ return proxy;
+}
+
+wl_proxy* CCExtDataControlManagerV1::sendGetDataDevice(wl_proxy* seat) {
+ if (!pResource)
+ return nullptr;
+
+ auto proxy = wl_proxy_marshal_flags(pResource, 1, &ext_data_control_device_v1_interface, wl_proxy_get_version(pResource), 0, nullptr, seat);
+
+ return proxy;
+}
+
+void CCExtDataControlManagerV1::sendDestroy() {
+ if (!pResource)
+ return;
+ destroyed = true;
+
+ auto proxy = wl_proxy_marshal_flags(pResource, 2, nullptr, wl_proxy_get_version(pResource), 1);
+ proxy;
+}
+static const wl_interface* _CExtDataControlManagerV1CreateDataSourceTypes[] = {
+ &ext_data_control_source_v1_interface,
+};
+static const wl_interface* _CExtDataControlManagerV1GetDataDeviceTypes[] = {
+ &ext_data_control_device_v1_interface,
+ &wl_seat_interface,
+};
+
+static const wl_message _CExtDataControlManagerV1Requests[] = {
+ { .name = "create_data_source", .signature = "n", .types = _CExtDataControlManagerV1CreateDataSourceTypes + 0},
+ { .name = "get_data_device", .signature = "no", .types = _CExtDataControlManagerV1GetDataDeviceTypes + 0},
+ { .name = "destroy", .signature = "", .types = extDataControlV1_dummyTypes + 0},
+};
+
+const wl_interface ext_data_control_manager_v1_interface = {
+ .name = "ext_data_control_manager_v1", .version = 1,
+ .method_count = 3, .methods = _CExtDataControlManagerV1Requests,
+ .event_count = 0, .events = nullptr,
+};
+
+CCExtDataControlManagerV1::CCExtDataControlManagerV1(wl_proxy* resource) : pResource(resource) {
+
+ if (!pResource)
+ return;
+
+ wl_proxy_add_listener(pResource, (void (**)(void))&_CCExtDataControlManagerV1VTable, this);
+}
+
+CCExtDataControlManagerV1::~CCExtDataControlManagerV1() {
+ if (!destroyed)
+ sendDestroy();
+}
+
+static void _CExtDataControlDeviceV1DataOffer(void* data, void* resource, wl_proxy* id) {
+ const auto PO = (CCExtDataControlDeviceV1*)data;
+ if (PO && PO->requests.dataOffer)
+ PO->requests.dataOffer(PO, id);
+}
+
+static void _CExtDataControlDeviceV1Selection(void* data, void* resource, wl_proxy* id) {
+ const auto PO = (CCExtDataControlDeviceV1*)data;
+ if (PO && PO->requests.selection)
+ PO->requests.selection(PO, id);
+}
+
+static void _CExtDataControlDeviceV1Finished(void* data, void* resource) {
+ const auto PO = (CCExtDataControlDeviceV1*)data;
+ if (PO && PO->requests.finished)
+ PO->requests.finished(PO);
+}
+
+static void _CExtDataControlDeviceV1PrimarySelection(void* data, void* resource, wl_proxy* id) {
+ const auto PO = (CCExtDataControlDeviceV1*)data;
+ if (PO && PO->requests.primarySelection)
+ PO->requests.primarySelection(PO, id);
+}
+
+static const void* _CCExtDataControlDeviceV1VTable[] = {
+ (void*)_CExtDataControlDeviceV1DataOffer,
+ (void*)_CExtDataControlDeviceV1Selection,
+ (void*)_CExtDataControlDeviceV1Finished,
+ (void*)_CExtDataControlDeviceV1PrimarySelection,
+};
+
+void CCExtDataControlDeviceV1::sendSetSelection(CCExtDataControlSourceV1* source) {
+ if (!pResource)
+ return;
+
+ auto proxy = wl_proxy_marshal_flags(pResource, 0, nullptr, wl_proxy_get_version(pResource), 0, source ? source->pResource : nullptr);
+ proxy;
+}
+
+void CCExtDataControlDeviceV1::sendDestroy() {
+ if (!pResource)
+ return;
+ destroyed = true;
+
+ auto proxy = wl_proxy_marshal_flags(pResource, 1, nullptr, wl_proxy_get_version(pResource), 1);
+ proxy;
+}
+
+void CCExtDataControlDeviceV1::sendSetPrimarySelection(CCExtDataControlSourceV1* source) {
+ if (!pResource)
+ return;
+
+ auto proxy = wl_proxy_marshal_flags(pResource, 2, nullptr, wl_proxy_get_version(pResource), 0, source ? source->pResource : nullptr);
+ proxy;
+}
+static const wl_interface* _CExtDataControlDeviceV1SetSelectionTypes[] = {
+ &ext_data_control_source_v1_interface,
+};
+static const wl_interface* _CExtDataControlDeviceV1SetPrimarySelectionTypes[] = {
+ &ext_data_control_source_v1_interface,
+};
+static const wl_interface* _CExtDataControlDeviceV1DataOfferTypes[] = {
+ &ext_data_control_offer_v1_interface,
+};
+static const wl_interface* _CExtDataControlDeviceV1SelectionTypes[] = {
+ &ext_data_control_offer_v1_interface,
+};
+static const wl_interface* _CExtDataControlDeviceV1PrimarySelectionTypes[] = {
+ &ext_data_control_offer_v1_interface,
+};
+
+static const wl_message _CExtDataControlDeviceV1Requests[] = {
+ { .name = "set_selection", .signature = "?o", .types = _CExtDataControlDeviceV1SetSelectionTypes + 0},
+ { .name = "destroy", .signature = "", .types = extDataControlV1_dummyTypes + 0},
+ { .name = "set_primary_selection", .signature = "?o", .types = _CExtDataControlDeviceV1SetPrimarySelectionTypes + 0},
+};
+
+static const wl_message _CExtDataControlDeviceV1Events[] = {
+ { .name = "data_offer", .signature = "n", .types = _CExtDataControlDeviceV1DataOfferTypes + 0},
+ { .name = "selection", .signature = "?o", .types = _CExtDataControlDeviceV1SelectionTypes + 0},
+ { .name = "finished", .signature = "", .types = extDataControlV1_dummyTypes + 0},
+ { .name = "primary_selection", .signature = "?o", .types = _CExtDataControlDeviceV1PrimarySelectionTypes + 0},
+};
+
+const wl_interface ext_data_control_device_v1_interface = {
+ .name = "ext_data_control_device_v1", .version = 1,
+ .method_count = 3, .methods = _CExtDataControlDeviceV1Requests,
+ .event_count = 4, .events = _CExtDataControlDeviceV1Events,
+};
+
+CCExtDataControlDeviceV1::CCExtDataControlDeviceV1(wl_proxy* resource) : pResource(resource) {
+
+ if (!pResource)
+ return;
+
+ wl_proxy_add_listener(pResource, (void (**)(void))&_CCExtDataControlDeviceV1VTable, this);
+}
+
+CCExtDataControlDeviceV1::~CCExtDataControlDeviceV1() {
+ if (!destroyed)
+ sendDestroy();
+}
+
+void CCExtDataControlDeviceV1::setDataOffer(F<void(CCExtDataControlDeviceV1*, wl_proxy*)> &&handler) {
+ requests.dataOffer = std::move(handler);
+}
+
+void CCExtDataControlDeviceV1::setSelection(F<void(CCExtDataControlDeviceV1*, wl_proxy*)> &&handler) {
+ requests.selection = std::move(handler);
+}
+
+void CCExtDataControlDeviceV1::setFinished(F<void(CCExtDataControlDeviceV1*)> &&handler) {
+ requests.finished = std::move(handler);
+}
+
+void CCExtDataControlDeviceV1::setPrimarySelection(F<void(CCExtDataControlDeviceV1*, wl_proxy*)> &&handler) {
+ requests.primarySelection = std::move(handler);
+}
+
+static void _CExtDataControlSourceV1Send(void* data, void* resource, const char* mime_type, int32_t fd) {
+ const auto PO = (CCExtDataControlSourceV1*)data;
+ if (PO && PO->requests.send)
+ PO->requests.send(PO, mime_type, fd);
+}
+
+static void _CExtDataControlSourceV1Cancelled(void* data, void* resource) {
+ const auto PO = (CCExtDataControlSourceV1*)data;
+ if (PO && PO->requests.cancelled)
+ PO->requests.cancelled(PO);
+}
+
+static const void* _CCExtDataControlSourceV1VTable[] = {
+ (void*)_CExtDataControlSourceV1Send,
+ (void*)_CExtDataControlSourceV1Cancelled,
+};
+
+void CCExtDataControlSourceV1::sendOffer(const char* mime_type) {
+ if (!pResource)
+ return;
+
+ auto proxy = wl_proxy_marshal_flags(pResource, 0, nullptr, wl_proxy_get_version(pResource), 0, mime_type);
+ proxy;
+}
+
+void CCExtDataControlSourceV1::sendDestroy() {
+ if (!pResource)
+ return;
+ destroyed = true;
+
+ auto proxy = wl_proxy_marshal_flags(pResource, 1, nullptr, wl_proxy_get_version(pResource), 1);
+ proxy;
+}
+static const wl_interface* _CExtDataControlSourceV1OfferTypes[] = {
+ nullptr,
+};
+static const wl_interface* _CExtDataControlSourceV1SendTypes[] = {
+ nullptr,
+ nullptr,
+};
+
+static const wl_message _CExtDataControlSourceV1Requests[] = {
+ { .name = "offer", .signature = "s", .types = _CExtDataControlSourceV1OfferTypes + 0},
+ { .name = "destroy", .signature = "", .types = extDataControlV1_dummyTypes + 0},
+};
+
+static const wl_message _CExtDataControlSourceV1Events[] = {
+ { .name = "send", .signature = "sh", .types = _CExtDataControlSourceV1SendTypes + 0},
+ { .name = "cancelled", .signature = "", .types = extDataControlV1_dummyTypes + 0},
+};
+
+const wl_interface ext_data_control_source_v1_interface = {
+ .name = "ext_data_control_source_v1", .version = 1,
+ .method_count = 2, .methods = _CExtDataControlSourceV1Requests,
+ .event_count = 2, .events = _CExtDataControlSourceV1Events,
+};
+
+CCExtDataControlSourceV1::CCExtDataControlSourceV1(wl_proxy* resource) : pResource(resource) {
+
+ if (!pResource)
+ return;
+
+ wl_proxy_add_listener(pResource, (void (**)(void))&_CCExtDataControlSourceV1VTable, this);
+}
+
+CCExtDataControlSourceV1::~CCExtDataControlSourceV1() {
+ if (!destroyed)
+ sendDestroy();
+}
+
+void CCExtDataControlSourceV1::setSend(F<void(CCExtDataControlSourceV1*, const char*, int32_t)> &&handler) {
+ requests.send = std::move(handler);
+}
+
+void CCExtDataControlSourceV1::setCancelled(F<void(CCExtDataControlSourceV1*)> &&handler) {
+ requests.cancelled = std::move(handler);
+}
+
+static void _CExtDataControlOfferV1Offer(void* data, void* resource, const char* mime_type) {
+ const auto PO = (CCExtDataControlOfferV1*)data;
+ if (PO && PO->requests.offer)
+ PO->requests.offer(PO, mime_type);
+}
+
+static const void* _CCExtDataControlOfferV1VTable[] = {
+ (void*)_CExtDataControlOfferV1Offer,
+};
+
+void CCExtDataControlOfferV1::sendReceive(const char* mime_type, int32_t fd) {
+ if (!pResource)
+ return;
+
+ auto proxy = wl_proxy_marshal_flags(pResource, 0, nullptr, wl_proxy_get_version(pResource), 0, mime_type, fd);
+ proxy;
+}
+
+void CCExtDataControlOfferV1::sendDestroy() {
+ if (!pResource)
+ return;
+ destroyed = true;
+
+ auto proxy = wl_proxy_marshal_flags(pResource, 1, nullptr, wl_proxy_get_version(pResource), 1);
+ proxy;
+}
+static const wl_interface* _CExtDataControlOfferV1ReceiveTypes[] = {
+ nullptr,
+ nullptr,
+};
+static const wl_interface* _CExtDataControlOfferV1OfferTypes[] = {
+ nullptr,
+};
+
+static const wl_message _CExtDataControlOfferV1Requests[] = {
+ { .name = "receive", .signature = "sh", .types = _CExtDataControlOfferV1ReceiveTypes + 0},
+ { .name = "destroy", .signature = "", .types = extDataControlV1_dummyTypes + 0},
+};
+
+static const wl_message _CExtDataControlOfferV1Events[] = {
+ { .name = "offer", .signature = "s", .types = _CExtDataControlOfferV1OfferTypes + 0},
+};
+
+const wl_interface ext_data_control_offer_v1_interface = {
+ .name = "ext_data_control_offer_v1", .version = 1,
+ .method_count = 2, .methods = _CExtDataControlOfferV1Requests,
+ .event_count = 1, .events = _CExtDataControlOfferV1Events,
+};
+
+CCExtDataControlOfferV1::CCExtDataControlOfferV1(wl_proxy* resource) : pResource(resource) {
+
+ if (!pResource)
+ return;
+
+ wl_proxy_add_listener(pResource, (void (**)(void))&_CCExtDataControlOfferV1VTable, this);
+}
+
+CCExtDataControlOfferV1::~CCExtDataControlOfferV1() {
+ if (!destroyed)
+ sendDestroy();
+}
+
+void CCExtDataControlOfferV1::setOffer(F<void(CCExtDataControlOfferV1*, const char*)> &&handler) {
+ requests.offer = std::move(handler);
+}
+
+#undef F
diff --git a/src/core/src/wayland_protocols/ext-data-control-v1.hpp b/src/core/src/wayland_protocols/ext-data-control-v1.hpp
new file mode 100644
index 0000000..8f74cca
--- /dev/null
+++ b/src/core/src/wayland_protocols/ext-data-control-v1.hpp
@@ -0,0 +1,301 @@
+// Generated with hyprwayland-scanner 0.4.6. Made with vaxry's keyboard and ❤️.
+// ext_data_control_v1
+
+/*
+ This protocol's authors' copyright notice is:
+
+
+ Copyright © 2018 Simon Ser
+ Copyright © 2019 Ivan Molodetskikh
+ Copyright © 2024 Neal Gompa
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that copyright notice and this permission
+ notice appear in supporting documentation, and that the name of
+ the copyright holders not be used in advertising or publicity
+ pertaining to distribution of the software without specific,
+ written prior permission. The copyright holders make no
+ representations about the suitability of this software for any
+ purpose. It is provided "as is" without express or implied
+ warranty.
+
+ THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ THIS SOFTWARE.
+
+*/
+
+#pragma once
+
+#include <functional>
+#include <cstdint>
+#include <string>
+#include <wayland-client.h>
+
+#define F std::function
+
+struct wl_proxy;
+
+enum extDataControlDeviceV1Error : uint32_t {
+ EXT_DATA_CONTROL_DEVICE_V1_ERROR_USED_SOURCE = 1,
+};
+
+enum extDataControlSourceV1Error : uint32_t {
+ EXT_DATA_CONTROL_SOURCE_V1_ERROR_INVALID_OFFER = 1,
+};
+
+
+class CCExtDataControlManagerV1;
+class CCExtDataControlSourceV1;
+class CCExtDataControlDeviceV1;
+class CCWlSeat;
+class CCExtDataControlDeviceV1;
+class CCExtDataControlSourceV1;
+class CCExtDataControlSourceV1;
+class CCExtDataControlOfferV1;
+class CCExtDataControlOfferV1;
+class CCExtDataControlOfferV1;
+class CCExtDataControlSourceV1;
+class CCExtDataControlOfferV1;
+
+#ifndef HYPRWAYLAND_SCANNER_NO_INTERFACES
+extern const wl_interface ext_data_control_manager_v1_interface;
+extern const wl_interface ext_data_control_device_v1_interface;
+extern const wl_interface ext_data_control_source_v1_interface;
+extern const wl_interface ext_data_control_offer_v1_interface;
+
+#endif
+
+
+class CCExtDataControlManagerV1 {
+ public:
+ CCExtDataControlManagerV1(wl_proxy*);
+ ~CCExtDataControlManagerV1();
+
+
+ // set the data for this resource
+ void setData(void* data) {{
+ pData = data;
+ }}
+
+ // get the data for this resource
+ void* data() {{
+ return pData;
+ }}
+
+ // get the raw wl_resource (wl_proxy) ptr
+ wl_proxy* resource() {{
+ return pResource;
+ }}
+
+ // get the raw wl_proxy ptr
+ wl_proxy* proxy() {{
+ return pResource;
+ }}
+
+ // get the resource version
+ int version() {{
+ return wl_proxy_get_version(pResource);
+ }}
+
+ // --------------- Requests --------------- //
+
+
+ // --------------- Events --------------- //
+
+ wl_proxy* sendCreateDataSource();
+ wl_proxy* sendGetDataDevice(wl_proxy*);
+ void sendDestroy();
+
+ private:
+ struct {
+ } requests;
+
+ wl_proxy* pResource = nullptr;
+
+ bool destroyed = false;
+
+ void* pData = nullptr;
+};
+
+
+
+class CCExtDataControlDeviceV1 {
+ public:
+ CCExtDataControlDeviceV1(wl_proxy*);
+ ~CCExtDataControlDeviceV1();
+
+
+ // set the data for this resource
+ void setData(void* data) {{
+ pData = data;
+ }}
+
+ // get the data for this resource
+ void* data() {{
+ return pData;
+ }}
+
+ // get the raw wl_resource (wl_proxy) ptr
+ wl_proxy* resource() {{
+ return pResource;
+ }}
+
+ // get the raw wl_proxy ptr
+ wl_proxy* proxy() {{
+ return pResource;
+ }}
+
+ // get the resource version
+ int version() {{
+ return wl_proxy_get_version(pResource);
+ }}
+
+ // --------------- Requests --------------- //
+
+ void setDataOffer(F<void(CCExtDataControlDeviceV1*, wl_proxy*)> &&handler);
+ void setSelection(F<void(CCExtDataControlDeviceV1*, wl_proxy*)> &&handler);
+ void setFinished(F<void(CCExtDataControlDeviceV1*)> &&handler);
+ void setPrimarySelection(F<void(CCExtDataControlDeviceV1*, wl_proxy*)> &&handler);
+
+ // --------------- Events --------------- //
+
+ void sendSetSelection(CCExtDataControlSourceV1*);
+ void sendDestroy();
+ void sendSetPrimarySelection(CCExtDataControlSourceV1*);
+
+ private:
+ struct {
+ F<void(CCExtDataControlDeviceV1*, wl_proxy*)> dataOffer;
+ F<void(CCExtDataControlDeviceV1*, wl_proxy*)> selection;
+ F<void(CCExtDataControlDeviceV1*)> finished;
+ F<void(CCExtDataControlDeviceV1*, wl_proxy*)> primarySelection;
+ } requests;
+
+ wl_proxy* pResource = nullptr;
+
+ bool destroyed = false;
+
+ void* pData = nullptr;
+};
+
+
+
+class CCExtDataControlSourceV1 {
+ public:
+ CCExtDataControlSourceV1(wl_proxy*);
+ ~CCExtDataControlSourceV1();
+
+
+ // set the data for this resource
+ void setData(void* data) {{
+ pData = data;
+ }}
+
+ // get the data for this resource
+ void* data() {{
+ return pData;
+ }}
+
+ // get the raw wl_resource (wl_proxy) ptr
+ wl_proxy* resource() {{
+ return pResource;
+ }}
+
+ // get the raw wl_proxy ptr
+ wl_proxy* proxy() {{
+ return pResource;
+ }}
+
+ // get the resource version
+ int version() {{
+ return wl_proxy_get_version(pResource);
+ }}
+
+ // --------------- Requests --------------- //
+
+ void setSend(F<void(CCExtDataControlSourceV1*, const char*, int32_t)> &&handler);
+ void setCancelled(F<void(CCExtDataControlSourceV1*)> &&handler);
+
+ // --------------- Events --------------- //
+
+ void sendOffer(const char*);
+ void sendDestroy();
+
+ private:
+ struct {
+ F<void(CCExtDataControlSourceV1*, const char*, int32_t)> send;
+ F<void(CCExtDataControlSourceV1*)> cancelled;
+ } requests;
+
+ wl_proxy* pResource = nullptr;
+
+ bool destroyed = false;
+
+ void* pData = nullptr;
+};
+
+
+
+class CCExtDataControlOfferV1 {
+ public:
+ CCExtDataControlOfferV1(wl_proxy*);
+ ~CCExtDataControlOfferV1();
+
+
+ // set the data for this resource
+ void setData(void* data) {{
+ pData = data;
+ }}
+
+ // get the data for this resource
+ void* data() {{
+ return pData;
+ }}
+
+ // get the raw wl_resource (wl_proxy) ptr
+ wl_proxy* resource() {{
+ return pResource;
+ }}
+
+ // get the raw wl_proxy ptr
+ wl_proxy* proxy() {{
+ return pResource;
+ }}
+
+ // get the resource version
+ int version() {{
+ return wl_proxy_get_version(pResource);
+ }}
+
+ // --------------- Requests --------------- //
+
+ void setOffer(F<void(CCExtDataControlOfferV1*, const char*)> &&handler);
+
+ // --------------- Events --------------- //
+
+ void sendReceive(const char*, int32_t);
+ void sendDestroy();
+
+ private:
+ struct {
+ F<void(CCExtDataControlOfferV1*, const char*)> offer;
+ } requests;
+
+ wl_proxy* pResource = nullptr;
+
+ bool destroyed = false;
+
+ void* pData = nullptr;
+};
+
+
+
+#undef F