From 1ae902eeb4d5ad7247bf69dffd5f685ce371db80 Mon Sep 17 00:00:00 2001 From: Marcin Puc Date: Fri, 13 Jan 2023 23:34:27 +0100 Subject: [PATCH] New package: Clipboard-0.2.1r2 --- srcpkgs/Clipboard/patches/support-32bit.patch | 231 ++++++++++++++++++ srcpkgs/Clipboard/template | 25 ++ 2 files changed, 256 insertions(+) create mode 100644 srcpkgs/Clipboard/patches/support-32bit.patch create mode 100644 srcpkgs/Clipboard/template diff --git a/srcpkgs/Clipboard/patches/support-32bit.patch b/srcpkgs/Clipboard/patches/support-32bit.patch new file mode 100644 index 000000000000..20b0bd854d75 --- /dev/null +++ b/srcpkgs/Clipboard/patches/support-32bit.patch @@ -0,0 +1,231 @@ +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index eb4d9f2..cb1e1eb 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -67,12 +67,5 @@ add_subdirectory(clipboard) + + add_compile_options("$<$:/utf-8>") + +-include(CheckCXXCompilerFlag) +-CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) +-if(COMPILER_SUPPORTS_MARCH_NATIVE AND (NOT DEFINED ENV{CI})) #do not use a native uarch if we are in a CI environment +- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") +- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native") +-endif() +- + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ADD_FLAGS}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ADD_FLAGS}") +diff --git a/src/clipboardx11/src/x11.cpp b/src/clipboardx11/src/x11.cpp +index ce725d0..2f63e50 100644 +--- a/src/clipboardx11/src/x11.cpp ++++ b/src/clipboardx11/src/x11.cpp +@@ -228,6 +228,10 @@ private: + std::size_t m_size; + + public: ++ using format8_t = std::uint8_t; ++ using format16_t = std::uint16_t; ++ using format32_t = std::conditional::type; ++ + enum Value : std::size_t { + Format8 = 8, + Format16 = 16, +@@ -236,9 +240,9 @@ public: + + constexpr X11PropertyFormat(Value value) : X11PropertyFormat( + static_cast(value), +- value == Format8 ? sizeof(std::uint8_t) : +- value == Format8 ? sizeof(std::uint16_t) : +- sizeof(std::uint64_t) // No, this is not a mistake. libx11 uses a 64-bit int for the 32 format ++ value == Format8 ? sizeof(format8_t) : ++ value == Format16 ? sizeof(format16_t) : ++ sizeof(format32_t) + ) { } + + [[nodiscard]] inline std::size_t size() const { return m_size; } +@@ -250,19 +254,8 @@ public: + return { static_cast(value) }; + } + +- static X11PropertyFormat fromSize(std::size_t size) { +- if (size == sizeof(std::uint8_t)) { +- return Format8; +- } +- if (size == sizeof(std::uint16_t)) { +- return Format16; +- } +- if (size == sizeof(std::uint64_t)) { +- return Format32; +- } +- +- throw X11Exception("Invalid format size"); +- } ++ template ++ constexpr static inline X11PropertyFormat fromSize(); + }; + + enum class X11PropertyMode : int { +@@ -277,7 +270,7 @@ private: + X11Atom const& m_type; + X11PropertyFormat m_format; + +- std::variant> m_data8; ++ std::variant> m_data8; + std::size_t m_size8; + + public: +@@ -294,21 +287,21 @@ public: + [[nodiscard]] std::size_t size() const { return m_size8 / m_format.size(); } + + [[nodiscard]] std::size_t size8() const { return m_size8; } +- [[nodiscard]] std::size_t size16() const { return size8() / X11PropertyFormat{X11PropertyFormat::Format16}.size(); } +- [[nodiscard]] std::size_t size32() const { return size8() / X11PropertyFormat{X11PropertyFormat::Format32}.size(); } ++ [[nodiscard]] std::size_t size16() const { return size8() / sizeof(X11PropertyFormat::format16_t); } ++ [[nodiscard]] std::size_t size32() const { return size8() / sizeof(X11PropertyFormat::format32_t); } + +- [[nodiscard]] std::uint8_t const* data8() const { +- return std::visit([](auto&& arg) -> std::uint8_t const* { ++ [[nodiscard]] X11PropertyFormat::format8_t const* data8() const { ++ return std::visit([](auto&& arg) -> X11PropertyFormat::format8_t const* { + using T = std::decay_t; +- if constexpr (std::is_same_v) ++ if constexpr (std::is_same_v) + return arg; + else + return arg.get(); + }, m_data8); + } + +- [[nodiscard]] std::uint16_t const* data16() const { return reinterpret_cast(data8()); } +- [[nodiscard]] std::uint64_t const* data32() const { return reinterpret_cast(data8()); } ++ [[nodiscard]] X11PropertyFormat::format16_t const* data16() const { return reinterpret_cast(data8()); } ++ [[nodiscard]] X11PropertyFormat::format32_t const* data32() const { return reinterpret_cast(data8()); } + + [[nodiscard]] X11PropertyIterator begin() const; + [[nodiscard]] X11PropertyIterator end() const; +@@ -324,7 +317,7 @@ private: + public: + X11PropertyIterator(X11Property const& property, std::size_t offset) : m_property(property), m_offset(offset) { } + +- std::uint64_t operator*() const; ++ X11PropertyFormat::format32_t operator*() const; + X11PropertyIterator& operator++(); + std::partial_ordering operator<=>(X11PropertyIterator const&) const; + +@@ -830,6 +823,26 @@ std::shared_ptr X11Connection::externalWindow(Window window) { + return result; + } + ++template<> ++constexpr X11PropertyFormat X11PropertyFormat::fromSize() { return X11PropertyFormat::Format8; } ++ ++template<> ++constexpr X11PropertyFormat X11PropertyFormat::fromSize() { return X11PropertyFormat::Format16; } ++ ++template<> ++constexpr X11PropertyFormat X11PropertyFormat::fromSize() { return X11PropertyFormat::Format32; } ++ ++template ++struct AssertFalse : std::false_type ++{ }; ++ ++template ++constexpr X11PropertyFormat X11PropertyFormat::fromSize() { ++ static_assert(AssertFalse::value); ++ return X11PropertyFormat::Format8; // Just here to make the compiler happy ++} ++ ++ + template + X11Property::X11Property( + X11Atom const& name, +@@ -839,7 +852,7 @@ X11Property::X11Property( + ) : X11Property( + name, + type, +- X11PropertyFormat::fromSize(sizeof(char_t)), ++ X11PropertyFormat::fromSize(), + data, + owned + ) { } +@@ -856,11 +869,11 @@ X11Property::X11Property( + , m_format(format) + , m_size8(data.size() * sizeof(char_t)) { + if (owned) { +- auto data8 = std::make_unique(m_size8); ++ auto data8 = std::make_unique(m_size8); + std::memcpy(data8.get(), &data[0], m_size8); +- m_data8.emplace>(std::move(data8)); ++ m_data8.emplace>(std::move(data8)); + } else { +- m_data8.emplace(reinterpret_cast(&data[0])); ++ m_data8.emplace(reinterpret_cast(&data[0])); + } + } + +@@ -894,7 +907,7 @@ std::partial_ordering X11PropertyIterator::operator<=>(X11PropertyIterator const + return m_offset <=> other.m_offset; + } + +-std::uint64_t X11PropertyIterator::operator*() const { ++X11PropertyFormat::format32_t X11PropertyIterator::operator*() const { + auto pointer8 = m_property.data8() + (m_property.format().size() * m_offset); + + if (m_property.format() == X11PropertyFormat::Format8) { +@@ -902,11 +915,11 @@ std::uint64_t X11PropertyIterator::operator*() const { + } + + if (m_property.format() == X11PropertyFormat::Format16) { +- return *reinterpret_cast(pointer8); ++ return *reinterpret_cast(pointer8); + } + + if (m_property.format() == X11PropertyFormat::Format32) { +- return *reinterpret_cast(pointer8); ++ return *reinterpret_cast(pointer8); + } + + throw X11Exception("Unknown property format"); +@@ -1056,9 +1069,9 @@ X11Property X11Window::getProperty(X11Atom const& name, bool delet) { + + Atom actualTypeReturn = None; + int actualFormatReturn = 0; +- std::size_t nitemsReturn = 0; +- std::size_t bytesAfterReturn = 0; +- std::uint8_t* propReturn = nullptr; ++ unsigned long nitemsReturn = 0; ++ unsigned long bytesAfterReturn = 0; ++ unsigned char* propReturn = nullptr; + + X_CALL(XGetWindowProperty, + /*display*/ display(), +@@ -1487,8 +1500,8 @@ bool X11SelectionDaemon::handleMultipleSelectionRequest(X11SelectionRequest cons + return refuseSelectionRequest(request); + } + +- std::vector result; +- std::optional target; ++ std::vector result; ++ std::optional target; + for (auto&& value : *pairs) { + if (!target) { + target = value; +@@ -1508,7 +1521,7 @@ bool X11SelectionDaemon::handleMultipleSelectionRequest(X11SelectionRequest cons + } + + bool X11SelectionDaemon::handleTargetsSelectionRequest(X11SelectionRequest const& request) { +- std::vector data { ++ std::vector data { + atom(atomTargets).value(), + atom(atomMultiple).value(), + atom(atomTimestamp).value(), +@@ -1530,8 +1543,7 @@ bool X11SelectionDaemon::handleTimestampSelectionRequest(X11SelectionRequest con + debugStream << "Got a TIMESTAMP request" << std::endl; + debugStream << "Replying with: " << m_selectionAcquiredTime << std::endl; + +- std::vector data { m_selectionAcquiredTime }; +- return replySelectionRequest(event, atom(atomInteger), data); ++ return replySelectionRequest(event, atom(atomInteger), ranges::single_view(m_selectionAcquiredTime)); + } + + bool X11SelectionDaemon::handleRegularSelectionRequest(X11SelectionRequest const& request) { diff --git a/srcpkgs/Clipboard/template b/srcpkgs/Clipboard/template new file mode 100644 index 000000000000..2653f228e4a7 --- /dev/null +++ b/srcpkgs/Clipboard/template @@ -0,0 +1,25 @@ +# Template file for 'Clipboard' +pkgname=Clipboard +version=0.2.1r2 +revision=1 +build_style=cmake +hostmakedepends="pkg-config" +makedepends="libX11-devel" +short_desc="Cut, copy, and paste anything, anywhere, all from the terminal" +maintainer="Marcin Puc " +license="GPL-3.0-or-later" +homepage="https://github.com/Slackadays/Clipboard" +distfiles="https://github.com/Slackadays/Clipboard/archive/refs/tags/${version}.tar.gz" +checksum=3d88f14aa38530f0af74c492e0e708b206b56e67bc6d04275dfe12e6983c865a + +if [ "${XBPS_TARGET_NO_ATOMIC8}" ]; then + makedepends+=" libatomic-devel" + CXXFLAGS+=" -latomic" +fi + +post_install() { + vman documentation/manpages/man.1 clipboard.1 + + # symlink fails to be installed automatically + ln -s clipboard "${DESTDIR}/usr/bin/cb" +}