From 6ab95bb565d62400cdbcaab08e6786ea825d031b Mon Sep 17 00:00:00 2001 From: tauraamui Date: Sat, 20 Sep 2025 19:13:40 +0100 Subject: [PATCH 1/5] feat(clipboard): provide wayland and xclip behaviour respectfully --- src/lib/clipboardv3/clipboard_linux.v | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/lib/clipboardv3/clipboard_linux.v b/src/lib/clipboardv3/clipboard_linux.v index b8725514..48ec6769 100644 --- a/src/lib/clipboardv3/clipboard_linux.v +++ b/src/lib/clipboardv3/clipboard_linux.v @@ -17,13 +17,54 @@ module clipboardv3 import os import time +const xdg_session_type_env_name = 'XDG_SESSION_TYPE' +const xclip_path = '/usr/bin/xclip' +const xclip_paste_args = ['-selection', 'clipboard', '-out'] +const xclip_copy_args = ['-selection', 'clipboard', '-in'] +const wayland_copy_path = '/usr/bin/wl-copy' +const wayland_paste_path = '/usr/bin/wl-paste' +const wayland_copy_args = ['--type', 'text/plain'] +const wayland_paste_args = ['--type', 'text/plain'] + +type Getenv = fn (key string) string + +struct Proc { + copy_proc_path string + paste_proc_path string + paste_args []string + copy_args []string +} + +fn resolve_copy_proc(os_getenv Getenv) Proc { + if is_x11(os_getenv) { + return Proc{ + copy_proc_path: xclip_path + paste_proc_path: xclip_path // on x11 we use the same util for copy and paste + paste_args: xclip_paste_args + copy_args: xclip_copy_args + } + } + return Proc{ + copy_proc_path: wayland_copy_path + paste_proc_path: wayland_paste_path + paste_args: wayland_paste_args + copy_args: wayland_copy_args + } +} + +fn is_x11(os_getenv Getenv) bool { + return os_getenv(xdg_session_type_env_name) == "x11" +} + struct LinuxClipboard { mut: + copy_proc Proc last_type ContentType } fn new_linux_clipboard() Clipboard { return LinuxClipboard{ + copy_proc: resolve_copy_proc(os.getenv) last_type: .block } } From 7e44269de21689e0063756a4325292eedf3b0624 Mon Sep 17 00:00:00 2001 From: tauraamui Date: Sat, 20 Sep 2025 19:14:06 +0100 Subject: [PATCH 2/5] test(clipboard): ensure simply that is_x11 detection "works" --- src/lib/clipboardv3/clipboard_test.v | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib/clipboardv3/clipboard_test.v b/src/lib/clipboardv3/clipboard_test.v index 788e12b0..c9ffecef 100644 --- a/src/lib/clipboardv3/clipboard_test.v +++ b/src/lib/clipboardv3/clipboard_test.v @@ -32,6 +32,18 @@ fn test_clipboard_native_implementation_sets_type_to_block() ! { } } +@[if linux ?] +fn test_linux_clipboard_chooses_proc_to_invoke_depending_on_window_server() { + mock_get_env_x11 := fn (key string) string { + return "x11" + } + mock_get_env_wayland := fn (key string) string { + return "wayland" + } + assert is_x11(mock_get_env_x11) + assert is_x11(mock_get_env_wayland) == false +} + @[if darwin ?] fn test_clipboard_native_implementation_returns_no_content_type_from_plaintext_data() { $if darwin { From 9eaea1d9c9b039ce7b78ce781df838e8beb84874 Mon Sep 17 00:00:00 2001 From: tauraamui Date: Sat, 20 Sep 2025 19:21:31 +0100 Subject: [PATCH 3/5] feat(clipboard): use correct utility depending on host compositor --- src/lib/clipboardv3/clipboard_linux.v | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lib/clipboardv3/clipboard_linux.v b/src/lib/clipboardv3/clipboard_linux.v index 48ec6769..d02b41e6 100644 --- a/src/lib/clipboardv3/clipboard_linux.v +++ b/src/lib/clipboardv3/clipboard_linux.v @@ -35,7 +35,7 @@ struct Proc { copy_args []string } -fn resolve_copy_proc(os_getenv Getenv) Proc { +fn resolve_clipboard_proc(os_getenv Getenv) Proc { if is_x11(os_getenv) { return Proc{ copy_proc_path: xclip_path @@ -58,13 +58,13 @@ fn is_x11(os_getenv Getenv) bool { struct LinuxClipboard { mut: - copy_proc Proc + proc Proc last_type ContentType } fn new_linux_clipboard() Clipboard { return LinuxClipboard{ - copy_proc: resolve_copy_proc(os.getenv) + proc: resolve_clipboard_proc(os.getenv) last_type: .block } } @@ -73,8 +73,10 @@ fn (c LinuxClipboard) get_content() ?ClipboardContent { mut out := []string{} mut er := []string{} - mut p := os.new_process('/usr/bin/xclip') - p.set_args(['-selection', 'clipboard', '-out']) + // mut p := os.new_process('/usr/bin/xclip') + // p.set_args(['-selection', 'clipboard', '-out']) + mut p := os.new_process(c.proc.paste_proc_path) + p.set_args(c.proc.paste_args) p.set_redirect_stdio() p.run() @@ -100,8 +102,10 @@ fn (c LinuxClipboard) get_content() ?ClipboardContent { } fn (mut c LinuxClipboard) set_content(content ClipboardContent) { - mut p := os.new_process('/usr/bin/xclip') - p.set_args(['-selection', 'clipboard', '-in']) + // mut p := os.new_process('/usr/bin/xclip') + // p.set_args(['-selection', 'clipboard', '-in']) + mut p := os.new_process(c.proc.copy_proc_path) + p.set_args(c.proc.copy_args) p.set_redirect_stdio() p.run() From a4950d9a9978c90bfe1c19da6b374e766c1dfb8c Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 20 Sep 2025 18:22:43 +0000 Subject: [PATCH 4/5] style: auto-format V code in src/ --- src/lib/clipboardv3/clipboard_linux.v | 42 +++++++++++++-------------- src/lib/clipboardv3/clipboard_test.v | 16 +++++----- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/lib/clipboardv3/clipboard_linux.v b/src/lib/clipboardv3/clipboard_linux.v index d02b41e6..45f1c1dd 100644 --- a/src/lib/clipboardv3/clipboard_linux.v +++ b/src/lib/clipboardv3/clipboard_linux.v @@ -29,42 +29,42 @@ const wayland_paste_args = ['--type', 'text/plain'] type Getenv = fn (key string) string struct Proc { - copy_proc_path string - paste_proc_path string - paste_args []string - copy_args []string + copy_proc_path string + paste_proc_path string + paste_args []string + copy_args []string } fn resolve_clipboard_proc(os_getenv Getenv) Proc { - if is_x11(os_getenv) { - return Proc{ - copy_proc_path: xclip_path - paste_proc_path: xclip_path // on x11 we use the same util for copy and paste - paste_args: xclip_paste_args - copy_args: xclip_copy_args - } - } - return Proc{ - copy_proc_path: wayland_copy_path - paste_proc_path: wayland_paste_path - paste_args: wayland_paste_args - copy_args: wayland_copy_args - } + if is_x11(os_getenv) { + return Proc{ + copy_proc_path: xclip_path + paste_proc_path: xclip_path // on x11 we use the same util for copy and paste + paste_args: xclip_paste_args + copy_args: xclip_copy_args + } + } + return Proc{ + copy_proc_path: wayland_copy_path + paste_proc_path: wayland_paste_path + paste_args: wayland_paste_args + copy_args: wayland_copy_args + } } fn is_x11(os_getenv Getenv) bool { - return os_getenv(xdg_session_type_env_name) == "x11" + return os_getenv(xdg_session_type_env_name) == 'x11' } struct LinuxClipboard { mut: - proc Proc + proc Proc last_type ContentType } fn new_linux_clipboard() Clipboard { return LinuxClipboard{ - proc: resolve_clipboard_proc(os.getenv) + proc: resolve_clipboard_proc(os.getenv) last_type: .block } } diff --git a/src/lib/clipboardv3/clipboard_test.v b/src/lib/clipboardv3/clipboard_test.v index c9ffecef..fcfca6ec 100644 --- a/src/lib/clipboardv3/clipboard_test.v +++ b/src/lib/clipboardv3/clipboard_test.v @@ -34,14 +34,14 @@ fn test_clipboard_native_implementation_sets_type_to_block() ! { @[if linux ?] fn test_linux_clipboard_chooses_proc_to_invoke_depending_on_window_server() { - mock_get_env_x11 := fn (key string) string { - return "x11" - } - mock_get_env_wayland := fn (key string) string { - return "wayland" - } - assert is_x11(mock_get_env_x11) - assert is_x11(mock_get_env_wayland) == false + mock_get_env_x11 := fn (key string) string { + return 'x11' + } + mock_get_env_wayland := fn (key string) string { + return 'wayland' + } + assert is_x11(mock_get_env_x11) + assert is_x11(mock_get_env_wayland) == false } @[if darwin ?] From d3e8e91076145bf4a68affe961d550147372081b Mon Sep 17 00:00:00 2001 From: tauraamui Date: Sat, 20 Sep 2025 19:24:22 +0100 Subject: [PATCH 5/5] chore(tidy): remove old/unwanted disabled code --- src/lib/clipboardv3/clipboard_linux.v | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/lib/clipboardv3/clipboard_linux.v b/src/lib/clipboardv3/clipboard_linux.v index 45f1c1dd..67aa6553 100644 --- a/src/lib/clipboardv3/clipboard_linux.v +++ b/src/lib/clipboardv3/clipboard_linux.v @@ -73,8 +73,6 @@ fn (c LinuxClipboard) get_content() ?ClipboardContent { mut out := []string{} mut er := []string{} - // mut p := os.new_process('/usr/bin/xclip') - // p.set_args(['-selection', 'clipboard', '-out']) mut p := os.new_process(c.proc.paste_proc_path) p.set_args(c.proc.paste_args) p.set_redirect_stdio() @@ -102,8 +100,6 @@ fn (c LinuxClipboard) get_content() ?ClipboardContent { } fn (mut c LinuxClipboard) set_content(content ClipboardContent) { - // mut p := os.new_process('/usr/bin/xclip') - // p.set_args(['-selection', 'clipboard', '-in']) mut p := os.new_process(c.proc.copy_proc_path) p.set_args(c.proc.copy_args) p.set_redirect_stdio()