14 | {{ page.content | safe }}
15 | {% endblock content %}
--------------------------------------------------------------------------------
/documentation/website/themes/juice/templates/shortcodes/issue.html:
--------------------------------------------------------------------------------
1 | #{{ id }}
--------------------------------------------------------------------------------
/documentation/website/themes/juice/theme.toml:
--------------------------------------------------------------------------------
1 | name = "juice"
2 | description = "An intuitive, elegant, and lightweight Zola theme for product sites."
3 | license = "MIT"
4 | homepage = "https://github.com/huhu/juice"
5 | min_version = "0.11.0"
6 | demo = "https://juice.huhu.io"
7 |
8 | [extra]
9 |
10 | [author]
11 | name = "Huhu teams"
12 | homepage = "https://huhu.io"
13 |
--------------------------------------------------------------------------------
/documentation/website/themes/juice/vercel.json:
--------------------------------------------------------------------------------
1 | {
2 | "github": {
3 | "silent": true
4 | }
5 | }
--------------------------------------------------------------------------------
/install.ps1:
--------------------------------------------------------------------------------
1 | if (Test-Path $env:USERPROFILE\scoop) {
2 | scoop install clipboard
3 | exit
4 | }
5 |
6 | Invoke-WebRequest https://github.com/Slackadays/Clipboard/releases/latest/download/clipboard-windows-amd64.zip -OutFile clipboard-windows-amd64.zip
7 | Expand-Archive clipboard-windows-amd64.zip -DestinationPath .\clipboard-windows-amd64
8 |
9 | New-Item -ItemType Directory -Force -Path "C:\Program Files\Clipboard"
10 |
11 | Copy-Item .\clipboard-windows-amd64\bin\cb.exe -Force -Destination "C:\Program Files\Clipboard\cb.exe"
12 |
13 | $Old = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name path).path
14 | $New = "$Old;C:\Program Files\Clipboard"
15 | Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name path -Value $New
16 |
17 | Remove-Item .\clipboard-windows-amd64.zip -Force
18 | Remove-Item .\clipboard-windows-amd64 -Force -Recurse
19 |
20 | Write-Host "Please restart to use CB"
21 |
--------------------------------------------------------------------------------
/justfile:
--------------------------------------------------------------------------------
1 | default:
2 | @just --list
3 |
4 | build:
5 | if [ ! -d "build" ]; then mkdir build; fi
6 |
7 | cd build; cmake .. -DCMAKE_BUILD_TYPE=Release
8 |
9 | cd build; cmake --build . -j 12
10 |
11 | cd build; sudo cmake --install .
12 |
13 | clean:
14 | if [ -d "build" ]; then rm -rf build; fi
--------------------------------------------------------------------------------
/snapcraft.yaml:
--------------------------------------------------------------------------------
1 | name: clipboard
2 | version: "0.10.1"
3 | summary: The ultimate clipboard manager for the terminal
4 | description: |
5 | The Clipboard Project is one of the most advanced clipboard managers ever.
6 | Cut, copy, and paste anything, anytime, anywhere with unlimited capacity, clipboards, and history.
7 | It's feature packed and easy to use by anybody.
8 | confinement: strict
9 | base: core22
10 | parts:
11 | clipboard:
12 | plugin: cmake
13 | cmake-parameters:
14 | - -DCMAKE_BUILD_TYPE=Release
15 | - -DCMAKE_INSTALL_LIBDIR=bin
16 | source-type: git
17 | source: https://github.com/Slackadays/Clipboard
18 | source-branch: main
19 | build-packages:
20 | - g++
21 | - make
22 | - cmake
23 | - libasound2-dev
24 | - liburing-dev
25 | - libx11-dev
26 | - libwayland-dev
27 | - wayland-protocols
28 | - libssl-dev
29 | stage-packages:
30 | - libasound2-dev
31 | - liburing-dev
32 | - libx11-dev
33 | - libwayland-dev
34 | apps:
35 | clipboard:
36 | command: usr/local/bin/cb
37 | plugs:
38 | - alsa
39 | - x11
40 | - wayland
41 | - home
42 | - removable-media
--------------------------------------------------------------------------------
/src/cb/src/actions/add.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | namespace PerformAction {
19 |
20 | void addFiles() {
21 | if (path.holdsRawDataInCurrentEntry())
22 | error_exit(
23 | "%s",
24 | formatColors("[error][inverse] ✘ [noinverse] You can't add items to text. [blank][help] ⬤ Try copying text first, or add "
25 | "text instead.[blank]\n")
26 | );
27 | for (const auto& f : copying.items)
28 | copyItem(f);
29 | }
30 |
31 | void addData() {
32 | if (path.holdsRawDataInCurrentEntry()) {
33 | std::string content;
34 | if (io_type == IOType::Pipe)
35 | content = pipedInContent();
36 | else
37 | for (size_t i = 0; i < copying.items.size(); i++) {
38 | content += copying.items.at(i).string();
39 | if (i != copying.items.size() - 1) content += " ";
40 | }
41 | successes.bytes += writeToFile(path.data.raw, content, true);
42 | } else if (!fs::is_empty(path.data)) {
43 | error_exit(
44 | "%s",
45 | formatColors("[error][inverse] ✘ [noinverse] You can't add text to items. [blank][help] ⬤ Try copying text first, or add a "
46 | "file instead.[blank]\n")
47 | );
48 | } else {
49 | if (io_type == IOType::Pipe)
50 | pipeIn();
51 | else if (io_type == IOType::Text)
52 | for (size_t i = 0; i < copying.items.size(); i++) {
53 | successes.bytes += writeToFile(path.data.raw, copying.items.at(i).string());
54 | if (i != copying.items.size() - 1) successes.bytes += writeToFile(path.data.raw, " ");
55 | }
56 | }
57 | }
58 |
59 | } // namespace PerformAction
--------------------------------------------------------------------------------
/src/cb/src/actions/copy.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | namespace PerformAction {
19 |
20 | void copyItem(const fs::path& f, const bool use_regular_copy) {
21 | auto actuallyCopyItem = [&] {
22 | if (fs::is_directory(f)) {
23 | auto target = f.filename().empty() ? f.parent_path().filename() : f.filename();
24 | fs::create_directories(path.data / target);
25 | fs::copy(f, path.data / target, copying.opts);
26 | } else {
27 | fs::copy(f, path.data / f.filename(), use_regular_copy ? copying.opts : copying.opts | fs::copy_options::create_hard_links);
28 | }
29 | incrementSuccessesForItem(f);
30 | if (action == Action::Cut) writeToFile(path.metadata.originals, fs::absolute(f).string() + "\n", true);
31 | };
32 | try {
33 | actuallyCopyItem();
34 | } catch (const fs::filesystem_error& e) {
35 | if (!use_regular_copy && e.code() == std::errc::cross_device_link) {
36 | copyItem(f, true);
37 | } else {
38 | copying.failedItems.emplace_back(f.string(), e.code());
39 | }
40 | }
41 | }
42 |
43 | void copy() {
44 | for (const auto& f : copying.items)
45 | copyItem(f);
46 | }
47 |
48 | void copyText() {
49 | for (size_t i = 0; i < copying.items.size(); i++) {
50 | copying.buffer += copying.items.at(i).string();
51 | if (i != copying.items.size() - 1) copying.buffer += " ";
52 | }
53 | writeToFile(path.data.raw, copying.buffer);
54 |
55 | if (!output_silent && !confirmation_silent) {
56 | stopIndicator();
57 | printf(formatColors("[success][inverse] ✔ [noinverse] %s text \"[bold]%s[blank][success]\"[blank]\n").data(), did_action[action].data(), copying.buffer.data());
58 | }
59 |
60 | if (action == Action::Cut) writeToFile(path.metadata.originals, path.data.raw.string());
61 | successes.bytes = 0; // temporarily disable the bytes success message
62 | }
63 |
64 | } // namespace PerformAction
--------------------------------------------------------------------------------
/src/cb/src/actions/edit.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 | #include
18 |
19 | namespace PerformAction {
20 |
21 | void edit() {
22 | if (!path.holdsRawDataInCurrentEntry()) {
23 | if (path.holdsDataInCurrentEntry())
24 | error_exit("%s", formatColors("[error][inverse] ✘ [noinverse] You can currently only edit text content. [help]⬤ Try copying some text instead.[blank]\n"));
25 | else
26 | std::ofstream temp(path.data.raw);
27 | }
28 |
29 | auto editor = findUsableEditor();
30 |
31 | if (!editor) error_exit("%s", formatColors("[error][inverse] ✘ [noinverse] CB couldn't find a suitable editor to use. [help]⬤ Try setting the CLIPBOARD_EDITOR environment variable.[blank]\n"));
32 |
33 | // now run this editor with the text file as the argument
34 | auto command = editor.value() + " " + path.data.raw.string();
35 |
36 | stopIndicator();
37 |
38 | int res = system(command.data());
39 |
40 | if (res != 0) error_exit("%s", formatColors("[error][inverse] ✘ [noinverse] CB couldn't open the editor. [help]⬤ Try setting the CLIPBOARD_EDITOR environment variable.[blank]\n"));
41 | }
42 |
43 | } // namespace PerformAction
--------------------------------------------------------------------------------
/src/cb/src/actions/export.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | namespace PerformAction {
19 |
20 | void exportClipboards() {
21 | std::vector destinations;
22 | if (!copying.items.empty())
23 | std::transform(copying.items.begin(), copying.items.end(), std::back_inserter(destinations), [](const auto& item) { return item.string(); });
24 | else {
25 | for (const auto& entry : fs::directory_iterator(global_path.temporary))
26 | destinations.emplace_back(entry.path().filename().string());
27 | for (const auto& entry : fs::directory_iterator(global_path.persistent))
28 | destinations.emplace_back(entry.path().filename().string());
29 | }
30 |
31 | fs::path exportDirectory(fs::current_path() / "Exported_Clipboards");
32 |
33 | try {
34 | if (fs::exists(exportDirectory)) fs::remove_all(exportDirectory);
35 | fs::create_directory(exportDirectory);
36 | } catch (const fs::filesystem_error& e) {
37 | error_exit("%s", formatColors("[error][inverse] ✘ [noinverse] CB couldn't create the export directory. [help]⬤ Try checking if you have the right permissions or not.[blank]\n"));
38 | }
39 |
40 | auto exportClipboard = [&](const std::string& name) {
41 | try {
42 | Clipboard clipboard(name);
43 | clipboard.getLock();
44 | if (clipboard.isUnused()) return;
45 | fs::copy(clipboard, exportDirectory / name, copying.opts);
46 | fs::remove(exportDirectory / name / constants.metadata_directory / constants.lock_name);
47 | clipboard.releaseLock();
48 | successes.clipboards++;
49 | } catch (const fs::filesystem_error& e) {
50 | copying.failedItems.emplace_back(name, e.code());
51 | }
52 | };
53 |
54 | for (const auto& name : destinations)
55 | exportClipboard(name);
56 |
57 | if (destinations.empty() || successes.clipboards == 0) {
58 | stopIndicator();
59 | fprintf(stderr, "%s", no_clipboard_contents_message().data());
60 | error_exit(clipboard_action_prompt(), clipboard_invocation, clipboard_invocation);
61 | }
62 | }
63 |
64 | } // namespace PerformAction
--------------------------------------------------------------------------------
/src/cb/src/actions/help.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Slackadays/Clipboard/f24d6cd5f33693e5cad155a2e3dafd9ebb6767ad/src/cb/src/actions/help.cpp
--------------------------------------------------------------------------------
/src/cb/src/actions/import.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | namespace PerformAction {
19 |
20 | void importClipboards() {
21 | fs::path importDirectory;
22 | if (copying.items.empty())
23 | importDirectory = fs::current_path() / "Exported_Clipboards";
24 | else
25 | importDirectory = copying.items.at(0);
26 |
27 | if (!fs::exists(importDirectory))
28 | error_exit("%s", formatColors("[error][inverse] ✘ [noinverse] The directory you're trying to import from doesn't exist. [help]⬤ Try choosing a different one instead.[blank]\n"));
29 |
30 | if (!fs::is_directory(importDirectory))
31 | error_exit("%s", formatColors("[error][inverse] ✘ [noinverse] The directory you're trying to import from isn't a directory. [help]⬤ Try choosing a different one instead.[blank]\n"));
32 |
33 | for (const auto& entry : fs::directory_iterator(importDirectory)) {
34 | if (!entry.is_directory())
35 | copying.failedItems.emplace_back(entry.path().filename().string(), std::make_error_code(std::errc::not_a_directory));
36 | else {
37 | try {
38 | auto target = (isPersistent(entry.path().filename().string()) ? global_path.persistent : global_path.temporary) / entry.path().filename();
39 | if (fs::exists(target)) {
40 | using enum CopyPolicy;
41 | switch (copying.policy) {
42 | case SkipAll:
43 | continue;
44 | case ReplaceAll:
45 | fs::copy(entry.path(), target, fs::copy_options::recursive | fs::copy_options::overwrite_existing);
46 | successes.clipboards++;
47 | break;
48 | default:
49 | stopIndicator();
50 | copying.policy = userDecision(entry.path().filename().string());
51 | startIndicator();
52 | if (copying.policy == ReplaceOnce || copying.policy == ReplaceAll) {
53 | fs::copy(entry.path(), target, fs::copy_options::recursive | fs::copy_options::overwrite_existing);
54 | successes.clipboards++;
55 | }
56 | break;
57 | }
58 | } else {
59 | fs::copy(entry.path(), target, fs::copy_options::recursive);
60 | successes.clipboards++;
61 | }
62 | } catch (const fs::filesystem_error& e) {
63 | copying.failedItems.emplace_back(entry.path().filename().string(), e.code());
64 | }
65 | }
66 | }
67 | }
68 |
69 | } // namespace PerformAction
--------------------------------------------------------------------------------
/src/cb/src/actions/load.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | namespace PerformAction {
19 |
20 | void load() {
21 | if (!path.holdsDataInCurrentEntry()) {
22 | error_exit("%s", formatColors("[error][inverse] ✘ [noinverse] The clipboard you're trying to load from is empty. [help]⬤ Try choosing a different source instead.[blank]\n"));
23 | }
24 |
25 | std::vector destinations;
26 | if (!copying.items.empty())
27 | std::transform(copying.items.begin(), copying.items.end(), std::back_inserter(destinations), [](const auto& item) { return item.string(); });
28 | else
29 | destinations.emplace_back(constants.default_clipboard_name);
30 |
31 | if (std::find(destinations.begin(), destinations.end(), clipboard_name) != destinations.end())
32 | error_exit(
33 | "%s",
34 | formatColors("[error][inverse] ✘ [noinverse] You can't load a clipboard into itself. [help]⬤ Try choosing a different source instead, or choose different destinations.[blank]\n")
35 | );
36 |
37 | for (const auto& destination_number : destinations) {
38 | Clipboard destination(destination_number);
39 | try {
40 | for (const auto& entry : fs::directory_iterator(path.data)) {
41 | auto target = destination.data / entry.path().filename();
42 | auto loadItem = [&](bool use_regular_copy = copying.use_safe_copy) {
43 | if (entry.is_directory())
44 | fs::copy(entry.path(), target, copying.opts);
45 | else
46 | fs::copy(entry.path(), target, use_regular_copy ? copying.opts : (copying.opts | fs::copy_options::create_hard_links));
47 | };
48 | try {
49 | loadItem();
50 | } catch (const fs::filesystem_error& e) {
51 | if (!copying.use_safe_copy && e.code() == std::errc::cross_device_link) loadItem(true);
52 | }
53 | }
54 |
55 | destination.applyIgnoreRules();
56 |
57 | successes.clipboards++;
58 | } catch (const fs::filesystem_error& e) {
59 | copying.failedItems.emplace_back(destination_number, e.code());
60 | }
61 | }
62 |
63 | stopIndicator();
64 |
65 | if (std::find(destinations.begin(), destinations.end(), constants.default_clipboard_name) != destinations.end()) updateExternalClipboards(true);
66 | }
67 |
68 | } // namespace PerformAction
--------------------------------------------------------------------------------
/src/cb/src/actions/note.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | namespace PerformAction {
19 |
20 | void noteText() {
21 | if (copying.items.size() >= 1) {
22 | if (copying.items.at(0).string() == "") {
23 | fs::remove(path.metadata.notes);
24 | if (output_silent || confirmation_silent) return;
25 | stopIndicator();
26 | fprintf(stderr, "%s", formatColors("[success][inverse] ✔ [noinverse] Removed note[blank]\n").data());
27 | } else {
28 | fs::remove(path.metadata.notes);
29 | for (size_t i = 0; i < copying.items.size(); i++) {
30 | writeToFile(path.metadata.notes, copying.items.at(i).string(), true);
31 | if (i != copying.items.size() - 1) writeToFile(path.metadata.notes, " ", true);
32 | }
33 | if (output_silent || confirmation_silent) return;
34 | stopIndicator();
35 | fprintf(stderr, formatColors("[success][inverse] ✔ [noinverse] Saved note \"%s\"[blank]\n").data(), fileContents(path.metadata.notes).value().data());
36 | }
37 | } else if (copying.items.empty()) {
38 | if (fs::is_regular_file(path.metadata.notes)) {
39 | std::string content(fileContents(path.metadata.notes).value());
40 | if (is_tty.out) {
41 | stopIndicator();
42 | printf(formatColors("[info]┃ Note for this clipboard: %s[blank]\n").data(), content.data());
43 | } else
44 | printf(formatColors("%s").data(), content.data());
45 | } else {
46 | stopIndicator();
47 | fprintf(stderr, "%s", formatColors("[info]┃ There is no note for this clipboard.[blank]\n").data());
48 | }
49 | } else
50 | error_exit("%s", formatColors("[error][inverse] ✘ [noinverse] You can't add multiple items to a note. [help]⬤ Try providing a single piece of text instead.[blank]\n"));
51 | }
52 |
53 | void notePipe() {
54 | std::string content(pipedInContent());
55 | writeToFile(path.metadata.notes, content);
56 | if (output_silent || confirmation_silent) return;
57 | stopIndicator();
58 | fprintf(stderr, formatColors("[success][inverse] ✔ [noinverse] Saved note \"%s\"[blank]\n").data(), content.data());
59 | exit(EXIT_SUCCESS);
60 | }
61 |
62 | } // namespace PerformAction
--------------------------------------------------------------------------------
/src/cb/src/actions/pipeinout.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | #if defined(_WIN32) || defined(_WIN64)
19 | #include
20 | #include
21 | #include
22 | #endif
23 |
24 | namespace PerformAction {
25 |
26 | void pipeIn() {
27 | copying.buffer = pipedInContent();
28 | writeToFile(path.data.raw, copying.buffer);
29 | if (action == Action::Cut) writeToFile(path.metadata.originals, path.data.raw.string());
30 | }
31 |
32 | void pipeOut() {
33 | for (const auto& entry : fs::recursive_directory_iterator(path.data)) {
34 | std::string content(fileContents(entry.path()).value());
35 | #if !defined(_WIN32) && !defined(_WIN64)
36 | int len = write(fileno(stdout), content.data(), content.size());
37 | if (len < 0) throw std::runtime_error("write() failed");
38 | #elif defined(_WIN32) || defined(_WIN64)
39 | _setmode(_fileno(stdout), _O_BINARY);
40 | fwrite(content.data(), sizeof(char), content.size(), stdout);
41 | #endif
42 | fflush(stdout);
43 | successes.bytes += content.size();
44 | }
45 | removeOldFiles();
46 | }
47 |
48 | } // namespace PerformAction
--------------------------------------------------------------------------------
/src/cb/src/actions/redo.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | namespace PerformAction {
19 | void redo() {}
20 |
21 | } // namespace PerformAction
--------------------------------------------------------------------------------
/src/cb/src/actions/remove.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | namespace PerformAction {
19 |
20 | void removeRegex() {
21 | std::vector regexes;
22 | if (io_type == IOType::Pipe)
23 | regexes.emplace_back(pipedInContent());
24 | else
25 | std::transform(copying.items.begin(), copying.items.end(), std::back_inserter(regexes), [](const auto& item) { return std::regex(item.string()); });
26 |
27 | if (path.holdsRawDataInCurrentEntry()) {
28 | std::string content(fileContents(path.data.raw).value());
29 | size_t oldLength = content.size();
30 |
31 | for (const auto& pattern : regexes)
32 | content = std::regex_replace(content, pattern, "");
33 | successes.bytes += oldLength - content.size();
34 |
35 | if (oldLength != content.size())
36 | writeToFile(path.data.raw, content);
37 | else
38 | error_exit(
39 | "%s",
40 | formatColors("[error][inverse] ✘ [noinverse] CB couldn't match your pattern(s) against anything. [help]⬤ Try using a different pattern instead or check what's "
41 | "stored.[blank]\n")
42 | );
43 | } else {
44 | for (const auto& entry : fs::directory_iterator(path.data)) {
45 | for (const auto& pattern : regexes) {
46 | if (std::regex_match(entry.path().filename().string(), pattern)) {
47 | try {
48 | fs::remove_all(entry.path());
49 | incrementSuccessesForItem(entry.path());
50 | } catch (const fs::filesystem_error& e) {
51 | copying.failedItems.emplace_back(entry.path().filename().string(), e.code());
52 | }
53 | }
54 | }
55 | }
56 | if (successes.directories == 0 && successes.files == 0)
57 | error_exit(
58 | "%s",
59 | formatColors("[error][inverse] ✘ [noinverse] CB couldn't match your pattern(s) against anything. [help]⬤ Try using a different pattern instead or check what's "
60 | "stored.[blank]\n")
61 | );
62 | }
63 | }
64 |
65 | } // namespace PerformAction
--------------------------------------------------------------------------------
/src/cb/src/actions/share.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2024 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | namespace PerformAction {
19 | void share() {}
20 |
21 | } // namespace PerformAction
--------------------------------------------------------------------------------
/src/cb/src/actions/swap.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | namespace PerformAction {
19 |
20 | void swap() {
21 | if (copying.items.size() > 1)
22 | error_exit(
23 | formatColors("[error][inverse] ✘ [noinverse] You can only swap one clipboard at a time. [help]Try making sure there's only one other clipboard specified, like [bold]%s swap "
24 | "5[nobold] or [bold]%s swap3 0[nobold].[blank]\n"),
25 | clipboard_invocation,
26 | clipboard_invocation
27 | );
28 |
29 | std::string destination_name = copying.items.empty() ? std::string(constants.default_clipboard_name) : copying.items.at(0).string();
30 |
31 | if (destination_name == clipboard_name)
32 | error_exit(
33 | formatColors("[error][inverse] ✘ [noinverse] You can't swap a clipboard with itself. [help]Try choosing a different clipboard to swap with, like [bold]%s swap 5[nobold] or "
34 | "[bold]%s swap3 0[nobold].[blank]\n"),
35 | clipboard_invocation,
36 | clipboard_invocation
37 | );
38 |
39 | Clipboard destination(destination_name);
40 |
41 | fs::path swapTargetSource(path.data);
42 | swapTargetSource.replace_extension("swap");
43 |
44 | fs::path swapTargetDestination(destination.data);
45 | swapTargetDestination.replace_extension("swap");
46 |
47 | try {
48 | fs::copy(destination.data, swapTargetSource, fs::copy_options::recursive);
49 | fs::copy(path.data, swapTargetDestination, fs::copy_options::recursive);
50 |
51 | fs::remove_all(path.data);
52 | fs::remove_all(destination.data);
53 |
54 | fs::rename(swapTargetSource, path.data);
55 | fs::rename(swapTargetDestination, destination.data);
56 | } catch (const fs::filesystem_error& e) {
57 | copying.failedItems.emplace_back(destination_name, e.code());
58 | }
59 |
60 | stopIndicator();
61 |
62 | if (!output_silent && !confirmation_silent)
63 | fprintf(stderr, formatColors("[success][inverse] ✔ [noinverse] Swapped clipboard %s with %s[blank]\n").data(), clipboard_name.data(), destination_name.data());
64 |
65 | if (destination_name == constants.default_clipboard_name) updateExternalClipboards(true);
66 | }
67 |
68 | } // namespace PerformAction
--------------------------------------------------------------------------------
/src/cb/src/actions/undo.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | namespace PerformAction {
19 | void undo() {}
20 |
21 | } // namespace PerformAction
--------------------------------------------------------------------------------
/src/cb/src/main.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "clipboard.hpp"
17 |
18 | int main(int argc, char* argv[]) {
19 | try {
20 | setupHandlers();
21 |
22 | setupVariables(argc, argv);
23 |
24 | setupTerminal();
25 |
26 | setLocale();
27 |
28 | setClipboardAttributes();
29 |
30 | setFlags();
31 |
32 | startIndicator();
33 |
34 | verifyClipboardName();
35 |
36 | setFilepaths();
37 |
38 | action = getAction();
39 |
40 | if (auto pos = std::find_if(arguments.begin(), arguments.end(), [](const auto& arg) { return arg == "--"; }); pos != arguments.end()) arguments.erase(pos);
41 |
42 | copying.items.assign(arguments.begin(), arguments.end());
43 |
44 | io_type = getIOType();
45 |
46 | verifyAction();
47 |
48 | #if defined(__linux__)
49 | setupGUIClipboardDaemon();
50 | syncWithRemoteClipboard();
51 | if (action != Action::Info) path.getLock();
52 | #else
53 | if (action != Action::Info) path.getLock();
54 | syncWithExternalClipboards();
55 | #endif
56 |
57 | fixMissingItems();
58 |
59 | ignoreItemsPreemptively(copying.items);
60 |
61 | checkForNoItems();
62 |
63 | if (needsANewEntry()) path.makeNewEntry();
64 |
65 | (clipboard_state.exchange(ClipboardState::Action), cv.notify_one());
66 |
67 | (fs::create_directories(global_path.temporary), fs::create_directories(global_path.persistent));
68 |
69 | if (io_type != IOType::Text) deduplicate(copying.items);
70 |
71 | checkItemSize(totalItemSize());
72 |
73 | checkClipboardScriptEligibility();
74 |
75 | runClipboardScript();
76 |
77 | performAction();
78 |
79 | runClipboardScript();
80 |
81 | if (isAWriteAction()) path.applyIgnoreRules();
82 |
83 | copying.mime = getMIMEType();
84 |
85 | updateExternalClipboards();
86 |
87 | if (!copying.failedItems.empty()) clipboard_state = ClipboardState::Error;
88 |
89 | stopIndicator();
90 |
91 | deduplicate(copying.failedItems);
92 |
93 | showFailures();
94 |
95 | showSuccesses();
96 |
97 | path.trimHistoryEntries();
98 | } catch (const std::exception& e) {
99 | clipboard_state = ClipboardState::Error;
100 | stopIndicator();
101 | fprintf(stderr, internal_error_message().data(), e.what());
102 | exit(EXIT_FAILURE);
103 | }
104 | if (clipboard_state == ClipboardState::Error)
105 | exit(EXIT_FAILURE);
106 | else
107 | exit(EXIT_SUCCESS);
108 | }
--------------------------------------------------------------------------------
/src/cb/src/platforms/android.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include
17 | #include
18 | #include
19 |
20 | #include "../clipboard.hpp"
21 |
22 | const bool GUIClipboardSupportsCut = false;
23 |
24 | ClipboardContent getGUIClipboard(const std::string& requested_mime) {
25 | return ClipboardContent();
26 | }
27 |
28 | void writeToGUIClipboard(const ClipboardContent& clipboard) {
29 | if (clipboard.type() == ClipboardContentType::Text || clipboard.type() == ClipboardContentType::Binary) {
30 |
31 | } else if (clipboard.type() == ClipboardContentType::Paths) {
32 | }
33 | }
34 |
35 | bool playAsyncSoundEffect(const std::valarray& samples) {
36 | return false;
37 | }
--------------------------------------------------------------------------------
/src/cb/src/platforms/bsd.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | bool playAsyncSoundEffect(const std::valarray& samples) {
19 | return false;
20 | }
--------------------------------------------------------------------------------
/src/cb/src/platforms/haiku.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include
17 | #include
18 | #include
19 | #include
20 |
21 | #include "../clipboard.hpp"
22 |
23 | const bool GUIClipboardSupportsCut = false;
24 |
25 | ClipboardContent getGUIClipboard(const std::string& requested_mime) {
26 | std::unique_ptr gui_clipboard = std::make_unique("system");
27 | if (!gui_clipboard->Lock()) return {};
28 | BMessage* content = gui_clipboard->Data();
29 | gui_clipboard->Unlock();
30 | const char* temp;
31 | ssize_t tempLength = 0;
32 | if (!content->FindData("text/plain", B_MIME_TYPE, (const void**)&temp, &tempLength)) {
33 | std::string CBcontent(temp, tempLength);
34 | return ClipboardContent(CBcontent);
35 | }
36 | return {};
37 | }
38 |
39 | void writeToGUIClipboard(const ClipboardContent& clipboard) {
40 | std::unique_ptr gui_clipboard = std::make_unique("system");
41 | if (!gui_clipboard->Lock()) return;
42 | gui_clipboard->Clear();
43 | BMessage* content = (BMessage*)NULL;
44 | if (content = gui_clipboard->Data()) {
45 | if (clipboard.type() == ClipboardContentType::Text || clipboard.type() == ClipboardContentType::Binary) {
46 | content->AddData("text/plain", B_MIME_TYPE, clipboard.text().data(), clipboard.text().length());
47 | } else if (clipboard.type() == ClipboardContentType::Paths) {
48 | }
49 | gui_clipboard->Commit();
50 | }
51 | gui_clipboard->Unlock();
52 | }
53 |
54 | bool playAsyncSoundEffect(const std::valarray& samples) {
55 | return false;
56 | }
--------------------------------------------------------------------------------
/src/cb/src/platforms/linux.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 | #if defined(USE_ALSA)
18 | #include
19 | #endif
20 |
21 | void dummy_handler(const char* file, int line, const char* function, int err, const char* fmt, ...) {}
22 |
23 | bool playAsyncSoundEffect(const std::valarray& samples) {
24 | #if defined(USE_ALSA)
25 | if (fork()) return true;
26 |
27 | snd_lib_error_set_handler(dummy_handler); // suppress errors in console
28 |
29 | snd_pcm_t* device;
30 | if (snd_pcm_open(&device, "default", SND_PCM_STREAM_PLAYBACK, 0) < 0) std::_Exit(EXIT_FAILURE);
31 | snd_pcm_hw_params_t* params;
32 | snd_pcm_hw_params_alloca(¶ms);
33 | snd_pcm_hw_params_any(device, params);
34 | snd_pcm_hw_params_set_access(device, params, SND_PCM_ACCESS_RW_INTERLEAVED);
35 | snd_pcm_hw_params_set_format(device, params, SND_PCM_FORMAT_S16_LE);
36 | snd_pcm_hw_params_set_channels(device, params, 2);
37 | snd_pcm_hw_params_set_rate(device, params, 44100, 0);
38 | snd_pcm_hw_params_set_periods(device, params, 16, 0);
39 | snd_pcm_hw_params_set_period_time(device, params, 1024, 0);
40 | snd_pcm_hw_params(device, params);
41 |
42 | snd_pcm_writei(device, &(samples[0]), samples.size() / 2);
43 |
44 | snd_pcm_drain(device);
45 |
46 | snd_pcm_close(device);
47 |
48 | std::_Exit(EXIT_SUCCESS);
49 | #else
50 | return false;
51 | #endif
52 | }
53 |
--------------------------------------------------------------------------------
/src/cb/src/platforms/macos.mm:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #import
17 | #import
18 | #import
19 | #import
20 | #import
21 | #import "../clipboard.hpp"
22 |
23 | const bool GUIClipboardSupportsCut = false;
24 |
25 | static std::vector fileContent() {
26 | NSArray *classes = @[ [NSURL class] ];
27 | if ([[NSPasteboard generalPasteboard] canReadObjectForClasses:classes options:nil]) {
28 | NSArray *files = [[NSPasteboard generalPasteboard] readObjectsForClasses:classes options:nil];
29 | std::vector stringArray;
30 | for (NSURL *fileURL in files) {
31 | stringArray.push_back([[fileURL path] UTF8String]);
32 | }
33 | return stringArray;
34 | }
35 | return {};
36 | }
37 |
38 | static std::string textContent() {
39 | NSArray *classes = @[ [NSString class], [NSAttributedString class] ];
40 | if ([[NSPasteboard generalPasteboard] canReadObjectForClasses:classes options:nil]) {
41 | NSString *text = [[NSPasteboard generalPasteboard] stringForType:NSPasteboardTypeString];
42 | return [text UTF8String];
43 | }
44 | return "";
45 | }
46 |
47 | ClipboardContent getGUIClipboard(const std::string& requested_mime) {
48 | (void)requested_mime;
49 | auto files = fileContent();
50 | if (files.size() > 0) {
51 | std::vector fileVector;
52 | for (auto &file : files) {
53 | fileVector.push_back(file);
54 | }
55 | ClipboardPaths paths(fileVector);
56 | return ClipboardContent(paths);
57 | } else if (auto text = textContent(); text != "") {
58 | return ClipboardContent(text);
59 | }
60 | return ClipboardContent();
61 | }
62 |
63 | void writeToGUIClipboard(const ClipboardContent& clipboard) {
64 | [[NSPasteboard generalPasteboard] clearContents];
65 | if (clipboard.type() == ClipboardContentType::Text || clipboard.type() == ClipboardContentType::Binary) {
66 | [[NSPasteboard generalPasteboard] setString:@(clipboard.text().c_str()) forType:NSPasteboardTypeString];
67 | } else if (clipboard.type() == ClipboardContentType::Paths) {
68 | NSMutableArray *fileArray = [NSMutableArray new];
69 | for (auto const& path : clipboard.paths().paths()) {
70 | [fileArray addObject:[NSURL fileURLWithPath:@(path.c_str())]];
71 | }
72 | [[NSPasteboard generalPasteboard] writeObjects:fileArray];
73 | } else {
74 | // Write blank content
75 | [[NSPasteboard generalPasteboard] setString:@"" forType:NSPasteboardTypeString];
76 | }
77 | }
78 |
79 | bool playAsyncSoundEffect(const std::valarray& samples) {
80 | (void)samples;
81 | return false;
82 | }
--------------------------------------------------------------------------------
/src/cb/src/platforms/windows.hpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #pragma once
17 | #include "../clipboard.hpp"
18 | #include
19 | #include
20 | #include
21 |
22 | namespace fs = std::filesystem;
23 |
24 | template
25 | void decodeWindowsDropfilesPaths(void* filesList, std::vector& paths) {
26 |
27 | auto data = static_cast(filesList);
28 | std::vector currentPath;
29 |
30 | while (true) {
31 | auto c = *data++;
32 | currentPath.push_back(c);
33 |
34 | if (c == 0) {
35 | if (currentPath.size() == 1) {
36 | break;
37 | }
38 |
39 | paths.emplace_back(¤tPath[0]);
40 | currentPath.clear();
41 | }
42 | }
43 | }
44 |
45 | void onWindowsError(const std::string_view function);
46 | std::vector getWindowsClipboardDataFiles(void* clipboardPointer);
47 | std::string getWindowsClipboardDataPipe(void* clipboardPointer);
48 | void setWindowsClipboardDataPipe();
49 | void setWindowsClipboardDataFiles();
50 | ClipboardContent getGUIClipboard(const std::string& requested_mime);
51 | void writeToGUIClipboard(const ClipboardContent& clipboard);
52 |
--------------------------------------------------------------------------------
/src/cb/src/platforms/windows.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | UTF-8
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/cb/src/sounds/error.pcm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Slackadays/Clipboard/f24d6cd5f33693e5cad155a2e3dafd9ebb6767ad/src/cb/src/sounds/error.pcm
--------------------------------------------------------------------------------
/src/cb/src/sounds/error.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Slackadays/Clipboard/f24d6cd5f33693e5cad155a2e3dafd9ebb6767ad/src/cb/src/sounds/error.wav
--------------------------------------------------------------------------------
/src/cb/src/sounds/success.pcm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Slackadays/Clipboard/f24d6cd5f33693e5cad155a2e3dafd9ebb6767ad/src/cb/src/sounds/success.pcm
--------------------------------------------------------------------------------
/src/cb/src/sounds/success.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Slackadays/Clipboard/f24d6cd5f33693e5cad155a2e3dafd9ebb6767ad/src/cb/src/sounds/success.wav
--------------------------------------------------------------------------------
/src/cb/src/utils/cowcopy.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2024 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 | #if defined(__linux__)
18 | #include
19 | #include
20 | #endif
21 |
--------------------------------------------------------------------------------
/src/cb/src/utils/directorysize.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2024 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | #if defined(UNIX_OR_UNIX_LIKE)
19 | #include
20 | #endif
21 |
22 | size_t directoryOverhead(const fs::path& directory) {
23 | #if defined(UNIX_OR_UNIX_LIKE)
24 | struct stat info;
25 | if (stat(directory.string().data(), &info) != 0) return 0;
26 | return info.st_size;
27 | #else
28 | return 0;
29 | #endif
30 | }
31 |
32 | thread_local size_t size = 0; // thread_local because multiple threads could call ftwHandler
33 |
34 | #if defined(UNIX_OR_UNIX_LIKE)
35 | int ftwHandler(const char* fpath, const struct stat* sb, int typeflag) {
36 | size += sb->st_size;
37 | return 0;
38 | }
39 | #endif
40 |
41 | size_t totalDirectorySize(const fs::path& directory) {
42 | size = directoryOverhead(directory);
43 | #if defined(UNIX_OR_UNIX_LIKE)
44 | ftw(directory.string().data(), ftwHandler, 1);
45 | #else
46 | for (const auto& entry : fs::recursive_directory_iterator(directory))
47 | try {
48 | size += entry.is_directory() ? directoryOverhead(entry) : entry.file_size();
49 | } catch (const fs::filesystem_error& e) {
50 | if (e.code() != std::errc::no_such_file_or_directory) throw e;
51 | }
52 | #endif
53 | return size;
54 | }
--------------------------------------------------------------------------------
/src/cb/src/utils/distance.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | size_t levenshteinDistance(const std::string_view& one, const std::string_view& two) {
19 | if (one == two) return 0;
20 |
21 | if (one.empty()) return two.size();
22 | if (two.empty()) return one.size();
23 |
24 | std::vector> matrix(one.size() + 1, std::vector(two.size() + 1));
25 |
26 | for (size_t i = 0; i <= one.size(); i++)
27 | matrix.at(i).at(0) = i;
28 |
29 | for (size_t j = 0; j <= two.size(); j++)
30 | matrix.at(0).at(j) = j;
31 |
32 | for (size_t i = 1; i <= one.size(); i++) {
33 | for (size_t j = 1; j <= two.size(); j++) {
34 | if (one.at(i - 1) == two.at(j - 1))
35 | matrix.at(i).at(j) = matrix.at(i - 1).at(j - 1);
36 | else
37 | matrix.at(i).at(j) = std::min({matrix.at(i - 1).at(j - 1), matrix.at(i - 1).at(j), matrix.at(i).at(j - 1)}) + 1;
38 | }
39 | }
40 |
41 | return matrix.at(one.size()).at(two.size());
42 | };
--------------------------------------------------------------------------------
/src/cb/src/utils/editors.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 |
18 | std::optional findUsableEditor() {
19 | auto preferredEditor = []() -> std::optional {
20 | if (!copying.items.empty()) return copying.items.at(0).string();
21 | if (auto editor = getenv("CLIPBOARD_EDITOR"); editor != nullptr) return editor;
22 | if (auto editor = getenv("EDITOR"); editor != nullptr) return editor;
23 | if (auto editor = getenv("VISUAL"); editor != nullptr) return editor;
24 | return std::nullopt;
25 | };
26 |
27 | auto fallbackEditor = []() -> std::optional {
28 | constexpr std::array fallbacks {"nano", "vim", "nvim", "micro", "code", "gedit", "vi", "emacs", "subl", "sublime", "atom",
29 | "gedit", "kate", "mousepad", "leafpad", "pluma", "geany", "notepad.exe", "notepad++.exe", "wordpad.exe", "word.exe"};
30 |
31 | std::string pathContent(getenv("PATH"));
32 | std::vector paths;
33 |
34 | // split paths by : or ; (: for posix, ; for windows)
35 | auto strings = regexSplit(pathContent, std::regex("[:;]"));
36 | std::transform(strings.begin(), strings.end(), std::back_inserter(paths), [](const std::string& path) { return fs::path(path); });
37 |
38 | for (const auto& path : paths)
39 | for (const auto& fallback : fallbacks)
40 | if (fs::exists(path / fallback)) return fallback;
41 |
42 | return std::nullopt;
43 | };
44 |
45 | auto editor = preferredEditor();
46 |
47 | if (!editor) editor = fallbackEditor();
48 |
49 | return editor;
50 | }
--------------------------------------------------------------------------------
/src/cb/src/utils/files.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "../clipboard.hpp"
17 | #include
18 |
19 | std::optional fileContents(const fs::path& path) {
20 | #if defined(UNIX_OR_UNIX_LIKE)
21 | errno = 0;
22 | int fd = open(path.string().data(), O_RDONLY);
23 | if (fd == -1) {
24 | if (errno == ENOENT)
25 | return std::nullopt;
26 | else
27 | throw std::runtime_error("Couldn't open file " + path.string() + ": " + std::strerror(errno));
28 | }
29 | std::string contents;
30 | #if defined(__linux__) || defined(__FreeBSD__)
31 | std::array buffer;
32 | #elif defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
33 | std::array buffer;
34 | #else
35 | std::array buffer;
36 | #endif
37 | ssize_t bytes_read;
38 | errno = 0;
39 | while ((bytes_read = read(fd, buffer.data(), buffer.size())) > 0) {
40 | contents.append(buffer.data(), bytes_read);
41 | if (bytes_read < buffer.size() && errno == 0) break; // check if we reached EOF early and not due to an error
42 | }
43 | close(fd);
44 | return contents;
45 | #else
46 | std::stringstream buffer;
47 | std::ifstream file(path, std::ios::binary);
48 | if (!file.is_open()) return std::nullopt;
49 | buffer << file.rdbuf();
50 | return buffer.str();
51 | #endif
52 | }
53 |
54 | std::vector fileLines(const fs::path& path, bool includeEmptyLines) {
55 | std::vector lines;
56 | auto content = fileContents(path);
57 | if (!content) return lines;
58 | std::istringstream stream(*content);
59 | for (std::string line; std::getline(stream, line);) {
60 | if (!line.empty() || includeEmptyLines) lines.emplace_back(line);
61 | }
62 | return lines;
63 | }
64 |
65 | size_t writeToFile(const fs::path& path, const std::string& content, bool append) {
66 | std::ofstream file(path, append ? std::ios::app : std::ios::trunc | std::ios::binary);
67 | file << content;
68 | return content.size();
69 | }
--------------------------------------------------------------------------------
/src/cbwayland/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
2 | set(GENERATED_INCLUDE_DIR "${GENERATED_DIR}/include")
3 | set(GENERATED_SRC_DIR "${GENERATED_DIR}/src")
4 |
5 | find_program(WAYLAND_SCANNER wayland-scanner REQUIRED)
6 | pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir)
7 |
8 | set(XDG_SHELL_PROTOCOL "${WAYLAND_PROTOCOLS_DIR}/stable/xdg-shell/xdg-shell.xml")
9 | set(GENERATED_XDG_SHELL_HEADER "${GENERATED_INCLUDE_DIR}/wayland-xdg-shell.hpp")
10 | set(GENERATED_XDG_SHELL_CODE "${GENERATED_SRC_DIR}/wayland-xdg-shell.c")
11 |
12 | file(MAKE_DIRECTORY
13 | "${GENERATED_INCLUDE_DIR}"
14 | "${GENERATED_SRC_DIR}"
15 | )
16 |
17 | add_custom_command(
18 | OUTPUT "${GENERATED_XDG_SHELL_HEADER}"
19 | COMMAND "${WAYLAND_SCANNER}"
20 | ARGS
21 | --strict
22 | client-header
23 | "${XDG_SHELL_PROTOCOL}"
24 | "${GENERATED_XDG_SHELL_HEADER}"
25 | )
26 | add_custom_command(
27 | OUTPUT "${GENERATED_XDG_SHELL_CODE}"
28 | COMMAND "${WAYLAND_SCANNER}"
29 | ARGS
30 | --strict
31 | private-code
32 | "${XDG_SHELL_PROTOCOL}"
33 | "${GENERATED_XDG_SHELL_CODE}"
34 | )
35 | add_custom_target(cbwayland_generatedheaders
36 | DEPENDS "${GENERATED_XDG_SHELL_HEADER}"
37 | )
38 |
39 | add_library(cbwayland MODULE
40 | src/fd.cpp
41 | src/wayland.cpp
42 |
43 | src/objects/buffer.cpp
44 | src/objects/callback.cpp
45 | src/objects/data_device.cpp
46 | src/objects/data_offer.cpp
47 | src/objects/data_source.cpp
48 | src/objects/display.cpp
49 | src/objects/keyboard.cpp
50 | src/objects/registry.cpp
51 | src/objects/seat.cpp
52 | src/objects/shm.cpp
53 | src/objects/shm_pool.cpp
54 | src/objects/surface.cpp
55 | src/objects/xdg_surface.cpp
56 | src/objects/xdg_toplevel.cpp
57 | src/objects/xdg_wm_base.cpp
58 |
59 | "${GENERATED_XDG_SHELL_CODE}"
60 | )
61 | add_dependencies(cbwayland cbwayland_generatedheaders)
62 |
63 | enable_lto(cbwayland)
64 |
65 | target_link_libraries(cbwayland
66 | ${WAYLAND_CLIENT_LIBRARIES}
67 | gui
68 | )
69 | target_include_directories(cbwayland PRIVATE
70 | ${WAYLAND_CLIENT_INCLUDE_DIRS}
71 | ${GENERATED_INCLUDE_DIR}
72 | )
73 |
74 | install(TARGETS cbwayland LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
75 |
--------------------------------------------------------------------------------
/src/cbwayland/src/exception.hpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #pragma once
17 |
18 | #include
19 |
20 | class WlException : public SimpleException {
21 | using SimpleException::SimpleException;
22 | };
23 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/all.hpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #pragma once
17 |
18 | #include "buffer.hpp"
19 | #include "callback.hpp"
20 | #include "compositor.hpp"
21 | #include "data_device.hpp"
22 | #include "data_device_manager.hpp"
23 | #include "data_offer.hpp"
24 | #include "data_source.hpp"
25 | #include "display.hpp"
26 | #include "keyboard.hpp"
27 | #include "registry.hpp"
28 | #include "seat.hpp"
29 | #include "shm.hpp"
30 | #include "shm_pool.hpp"
31 | #include "surface.hpp"
32 | #include "xdg_surface.hpp"
33 | #include "xdg_toplevel.hpp"
34 | #include "xdg_wm_base.hpp"
35 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/buffer.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "buffer.hpp"
17 | #include "all.hpp"
18 |
19 | WlBuffer::WlBuffer(std::unique_ptr&& pool, std::int32_t offset, std::int32_t width, std::int32_t height, std::int32_t stride, wl_shm_format format)
20 | : WlObject {wl_shm_pool_create_buffer(getValue(pool), offset, width, height, stride, format)}
21 | , m_shmPool {std::move(pool)} {}
22 |
23 | std::unique_ptr WlBuffer::fromMemfd(const WlRegistry& registry, std::int32_t width, std::int32_t height, std::int32_t stride, wl_shm_format format) {
24 | if (!registry.get().supports(format)) {
25 | throw WlException("wl_shm doesn't support format ", format);
26 | }
27 |
28 | auto size = stride * height;
29 | return std::make_unique(WlShmPool::fromMemfd(registry, size), 0, width, height, stride, format);
30 | }
31 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/buffer.hpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #pragma once
17 |
18 | #include "forward.hpp"
19 | #include "spec.hpp"
20 |
21 | #include
22 |
23 | struct WlBufferSpec {
24 | WL_SPEC_BASE(wl_buffer, 1)
25 | WL_SPEC_DESTROY(wl_buffer)
26 | };
27 |
28 | class WlBuffer : public WlObject {
29 | private:
30 | std::unique_ptr m_shmPool;
31 |
32 | public:
33 | WlBuffer(std::unique_ptr&&, std::int32_t offset, std::int32_t width, std::int32_t height, std::int32_t stride, wl_shm_format);
34 |
35 | static std::unique_ptr fromMemfd(const WlRegistry&, std::int32_t width, std::int32_t height, std::int32_t stride, wl_shm_format);
36 | };
37 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/callback.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "callback.hpp"
17 | #include "all.hpp"
18 |
19 | decltype(WlCallbackSpec::listener) WlCallbackSpec::listener {
20 | .done = &eventHandler<&WlCallback::onDone>,
21 | };
22 |
23 | WlCallback::WlCallback(const WlDisplay& display) : WlObject {wl_display_sync(display.value())} {}
24 |
25 | void WlCallback::onDone(std::uint32_t serial) {
26 | m_serial = serial;
27 | }
28 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/callback.hpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #pragma once
17 |
18 | #include "forward.hpp"
19 | #include "spec.hpp"
20 |
21 | #include
22 |
23 | struct WlCallbackSpec {
24 | WL_SPEC_BASE(wl_callback, 1)
25 | WL_SPEC_DESTROY(wl_callback)
26 | WL_SPEC_LISTENER(wl_callback)
27 | };
28 |
29 | class WlCallback : public WlObject {
30 | friend WlCallbackSpec;
31 |
32 | std::optional m_serial {};
33 |
34 | public:
35 | explicit WlCallback(const WlDisplay&);
36 |
37 | [[nodiscard]] inline bool hasSerial() const { return m_serial.has_value(); }
38 | [[nodiscard]] inline std::uint32_t serial() const { return m_serial.value_or(0); }
39 |
40 | private:
41 | void onDone(std::uint32_t);
42 | };
43 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/compositor.hpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #pragma once
17 |
18 | #include "forward.hpp"
19 | #include "spec.hpp"
20 |
21 | struct WlCompositorSpec {
22 | WL_SPEC_BASE(wl_compositor, 5)
23 | WL_SPEC_DESTROY(wl_compositor)
24 | };
25 |
26 | class WlCompositor : public WlObject {
27 | public:
28 | explicit WlCompositor(obj_t* value) : WlObject {value} {}
29 | };
30 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/data_device.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "data_device.hpp"
17 | #include "all.hpp"
18 |
19 | #include
20 |
21 | wl_data_device_listener WlDataDeviceSpec::listener {
22 | .data_offer = &eventHandler<&WlDataDevice::onDataOffer>,
23 | .enter = &noHandler,
24 | .leave = &noHandler,
25 | .motion = &noHandler,
26 | .drop = &noHandler,
27 | .selection = &eventHandler<&WlDataDevice::onSelection>,
28 | };
29 |
30 | WlDataDevice::WlDataDevice(const WlDataDeviceManager& manager, const WlSeat& seat) : WlObject {wl_data_device_manager_get_data_device(manager.value(), seat.value())} {
31 | debugStream << "Created a data device for seat " << seat.name() << std::endl;
32 | }
33 |
34 | WlDataDevice::WlDataDevice(const WlRegistry& registry)
35 | : WlDataDevice {
36 | registry.get(),
37 | registry.get(),
38 | } {}
39 |
40 | void WlDataDevice::onDataOffer(wl_data_offer* offer) {
41 | if (offer == nullptr) {
42 | debugStream << "Received a null data offer, ignoring" << std::endl;
43 | return;
44 | }
45 |
46 | m_bufferedOffer = std::make_unique(offer);
47 | debugStream << "Got a new offer" << std::endl;
48 | }
49 |
50 | void WlDataDevice::onSelection(wl_data_offer* offer) {
51 | m_receivedSelectionEvent = true;
52 |
53 | if (offer == nullptr) {
54 | debugStream << "Selection was cleared" << std::endl;
55 | m_bufferedOffer.reset();
56 | m_selectionOffer.reset();
57 | return;
58 | }
59 |
60 | if (!m_bufferedOffer) {
61 | debugStream << "Got a new selection but its offer wasn't initialized before, ignoring" << std::endl;
62 | return;
63 | }
64 |
65 | if (getValue(m_bufferedOffer) != offer) {
66 | debugStream << "Got a selection but its offer didn't match the one that was initialized earlier, ignoring" << std::endl;
67 | return;
68 | }
69 |
70 | m_selectionOffer.reset();
71 | m_selectionOffer.swap(m_bufferedOffer);
72 | debugStream << "Offer was promoted to selection" << std::endl;
73 | }
74 |
75 | void WlDataDevice::setSelection(const WlDataSource& source, std::uint32_t serial) const {
76 | wl_data_device_set_selection(value(), source.value(), serial);
77 | }
78 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/data_device.hpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #pragma once
17 |
18 | #include "forward.hpp"
19 | #include "spec.hpp"
20 |
21 | struct WlDataDeviceSpec {
22 | WL_SPEC_BASE(wl_data_device, 3)
23 | WL_SPEC_RELEASE(wl_data_device)
24 | WL_SPEC_LISTENER(wl_data_device)
25 | };
26 |
27 | class WlDataDevice : public WlObject {
28 | friend WlDataDeviceSpec;
29 |
30 | bool m_receivedSelectionEvent {false};
31 | std::unique_ptr m_bufferedOffer {};
32 | std::unique_ptr m_selectionOffer {};
33 |
34 | public:
35 | explicit WlDataDevice(const WlDataDeviceManager&, const WlSeat&);
36 | explicit WlDataDevice(const WlRegistry&);
37 |
38 | [[nodiscard]] inline bool receivedSelectionEvent() const { return m_receivedSelectionEvent; }
39 | [[nodiscard]] inline bool hasSelectionOffer() const { return m_selectionOffer != nullptr; }
40 | [[nodiscard]] inline std::unique_ptr releaseSelectionOffer() { return std::move(m_selectionOffer); }
41 |
42 | void setSelection(const WlDataSource&, std::uint32_t serial) const;
43 |
44 | private:
45 | void onDataOffer(wl_data_offer*);
46 | void onSelection(wl_data_offer*);
47 | };
48 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/data_device_manager.hpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #pragma once
17 |
18 | #include "forward.hpp"
19 | #include "spec.hpp"
20 |
21 | struct WlDataDeviceManagerSpec {
22 | WL_SPEC_BASE(wl_data_device_manager, 3)
23 | WL_SPEC_DESTROY(wl_data_device_manager)
24 | };
25 |
26 | class WlDataDeviceManager : public WlObject {
27 | public:
28 | explicit WlDataDeviceManager(obj_t* value) : WlObject {value} {}
29 | };
30 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/data_offer.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "data_offer.hpp"
17 | #include "all.hpp"
18 |
19 | wl_data_offer_listener WlDataOfferSpec::listener {
20 | .offer = &eventHandler<&WlDataOffer::onOffer>,
21 | .source_actions = &noHandler,
22 | .action = &noHandler,
23 | };
24 |
25 | void WlDataOffer::onOffer(const char* mime) {
26 | m_mimeTypes.emplace(mime);
27 | }
28 |
29 | void WlDataOffer::receive(std::string_view mime, int fd) const {
30 | std::string mimeCopy {mime};
31 | wl_data_offer_receive(value(), mimeCopy.c_str(), fd);
32 | }
33 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/data_offer.hpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #pragma once
17 |
18 | #include "forward.hpp"
19 | #include "spec.hpp"
20 |
21 | #include
22 | #include
23 |
24 | struct WlDataOfferSpec {
25 | WL_SPEC_BASE(wl_data_offer, 3)
26 | WL_SPEC_DESTROY(wl_data_offer)
27 | WL_SPEC_LISTENER(wl_data_offer)
28 | };
29 |
30 | class WlDataOffer : public WlObject {
31 | friend WlDataOfferSpec;
32 |
33 | std::set m_mimeTypes {};
34 |
35 | public:
36 | explicit WlDataOffer(obj_t* value) : WlObject {value} {}
37 |
38 | void receive(std::string_view mime, int fd) const;
39 |
40 | /** Performs an action for each MIME Type supported by this offer. */
41 | template func_t>
42 | void forEachMimeType(func_t func) const;
43 |
44 | private:
45 | void onOffer(const char*);
46 | };
47 |
48 | template func_t>
49 | void WlDataOffer::forEachMimeType(func_t func) const {
50 | for (auto&& value : m_mimeTypes) {
51 | func(value);
52 | }
53 | }
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/data_source.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "data_source.hpp"
17 | #include "all.hpp"
18 |
19 | #include
20 |
21 | wl_data_source_listener WlDataSourceSpec::listener {
22 | .target = &noHandler,
23 | .send = &eventHandler<&WlDataSource::onSend>,
24 | .cancelled = &eventHandler<&WlDataSource::onCancelled>,
25 | .dnd_drop_performed = &noHandler,
26 | .dnd_finished = &noHandler,
27 | .action = &noHandler,
28 | };
29 |
30 | WlDataSource::WlDataSource(const WlDataDeviceManager& dataDeviceManager) : WlObject {wl_data_device_manager_create_data_source(dataDeviceManager.value())} {}
31 |
32 | WlDataSource::WlDataSource(const WlRegistry& registry) : WlDataSource {registry.get()} {}
33 |
34 | void WlDataSource::offer(std::string_view mime) const {
35 | std::string mimeCopy {mime};
36 | wl_data_source_offer(value(), mimeCopy.c_str());
37 | }
38 |
39 | void WlDataSource::onSend(const char* rawMime, std::int32_t rawFd) {
40 | std::string_view mime {rawMime};
41 | Fd fd {rawFd};
42 | if (m_sendCallback) {
43 | m_sendCallback(mime, std::move(fd));
44 | }
45 | }
46 |
47 | void WlDataSource::onCancelled() {
48 | m_isCancelled = true;
49 | debugStream << "Data source was cancelled" << std::endl;
50 | }
51 |
52 | void WlDataSource::sendCallback(std::function&& callback) {
53 | m_sendCallback = std::move(callback);
54 | }
55 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/data_source.hpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #pragma once
17 |
18 | #include "../fd.hpp"
19 | #include "forward.hpp"
20 | #include "spec.hpp"
21 |
22 | #include
23 |
24 | struct WlDataSourceSpec {
25 | WL_SPEC_BASE(wl_data_source, 3)
26 | WL_SPEC_DESTROY(wl_data_source)
27 | WL_SPEC_LISTENER(wl_data_source)
28 | };
29 |
30 | class WlDataSource : public WlObject {
31 | friend WlDataSourceSpec;
32 |
33 | public:
34 | using sendCallback_t = void(std::string_view, Fd&&);
35 |
36 | private:
37 | bool m_isCancelled {false};
38 | std::function m_sendCallback;
39 |
40 | public:
41 | explicit WlDataSource(const WlDataDeviceManager&);
42 | explicit WlDataSource(const WlRegistry&);
43 |
44 | [[nodiscard]] inline bool isCancelled() const { return m_isCancelled; }
45 |
46 | void sendCallback(std::function&&);
47 | void offer(std::string_view) const;
48 |
49 | private:
50 | void onSend(const char* mime, std::int32_t fd);
51 | void onCancelled();
52 | };
53 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/display.hpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #pragma once
17 |
18 | #include "forward.hpp"
19 | #include "spec.hpp"
20 |
21 | #include
22 |
23 | struct WlDisplaySpec {
24 | WL_SPEC_BASE(wl_display, 1)
25 | static constexpr auto deleter = &wl_display_disconnect;
26 | };
27 |
28 | class WlDisplay : public WlObject {
29 |
30 | void throwIfError() const;
31 | void flush() const;
32 | void dispatchPending() const;
33 | void readEvents() const;
34 | void pollWithTimeout(short events) const;
35 |
36 | public:
37 | explicit WlDisplay();
38 |
39 | void roundtrip() const;
40 | void dispatch() const;
41 | void dispatchWithTimeout() const;
42 |
43 | /**
44 | * Loops dispatch() until a certain predicate is met.
45 | * Throws if the operation takes too long.
46 | */
47 | template
48 | void dispatchUntil(predicate_t predicate) const;
49 |
50 | /**
51 | * Gets the next event serial from the Wayland server.
52 | * Requires a back-and-forth between the client and the server and may
53 | * dispatch other events in the meantime.
54 | */
55 | std::uint32_t getSerial() const;
56 | };
57 |
58 | template
59 | void WlDisplay::dispatchUntil(predicate_t predicate) const {
60 | using namespace std::literals;
61 | constexpr auto maxWaitTime = 5s;
62 |
63 | throwIfError();
64 |
65 | auto start = std::chrono::steady_clock::now();
66 | while (!predicate()) {
67 | dispatchWithTimeout();
68 |
69 | const auto time = std::chrono::steady_clock::now() - start;
70 | if (time > maxWaitTime) {
71 | throw WlException("Timed out waiting for the Wayland server to reply");
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/forward.hpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #pragma once
17 |
18 | class WlBuffer;
19 | class WlCallback;
20 | class WlCompositor;
21 | class WlDataDevice;
22 | class WlDataDeviceManager;
23 | class WlDataOffer;
24 | class WlDataSource;
25 | class WlDisplay;
26 | class WlKeyboard;
27 | class WlRegistry;
28 | class WlSeat;
29 | class WlShm;
30 | class WlShmPool;
31 | class WlSurface;
32 | class XdgSurface;
33 | class XdgToplevel;
34 | class XdgWmBase;
35 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/keyboard.cpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #include "keyboard.hpp"
17 | #include "all.hpp"
18 |
19 | decltype(WlKeyboardSpec::listener) WlKeyboardSpec::listener {
20 | .keymap = &noHandler,
21 | .enter = &eventHandler<&WlKeyboard::onEnter>,
22 | .leave = &eventHandler<&WlKeyboard::onLeave>,
23 | .key = &noHandler,
24 | .modifiers = &noHandler,
25 | .repeat_info = &noHandler};
26 |
27 | wl_keyboard* WlKeyboard::initKeyboard(const WlSeat& seat) {
28 | if (!seat.hasCapability(WL_SEAT_CAPABILITY_KEYBOARD)) {
29 | throw WlException("Seat ", seat.name(), " doesn't have Keyboard capabilities");
30 | }
31 |
32 | return wl_seat_get_keyboard(seat.value());
33 | }
34 |
35 | WlKeyboard::WlKeyboard(const WlSeat& seat) : WlObject {initKeyboard(seat)} {}
36 |
37 | WlKeyboard::WlKeyboard(const WlRegistry& registry) : WlKeyboard {registry.get()} {}
38 |
39 | bool WlKeyboard::hasFocus(wl_surface* surface) const {
40 | return m_focus.contains(surface);
41 | }
42 |
43 | bool WlKeyboard::hasFocus(const WlSurface& surface) const {
44 | return hasFocus(surface.value());
45 | }
46 |
47 | std::uint32_t WlKeyboard::getFocusSerial(wl_surface* surface) const {
48 | return m_focus.at(surface);
49 | }
50 |
51 | std::uint32_t WlKeyboard::getFocusSerial(const WlSurface& surface) const {
52 | return getFocusSerial(surface.value());
53 | }
54 |
55 | void WlKeyboard::onEnter(std::uint32_t serial, wl_surface* surface, wl_array*) {
56 | m_focus.insert_or_assign(surface, serial);
57 | }
58 |
59 | void WlKeyboard::onLeave(std::uint32_t serial, wl_surface* surface) {
60 | m_focus.erase(surface);
61 | }
62 |
--------------------------------------------------------------------------------
/src/cbwayland/src/objects/keyboard.hpp:
--------------------------------------------------------------------------------
1 | /* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2 | Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
3 | SPDX-License-Identifier: GPL-3.0-or-later
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .*/
16 | #pragma once
17 |
18 | #include "forward.hpp"
19 | #include "spec.hpp"
20 |
21 | #include