From 270ba07e839d569582041f2dd2a04785173b5ce1 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 25 Dec 2020 19:21:42 +0200 Subject: [PATCH] clipboard: add a `clipboard.x11` submodule, use it by default; add a `clipboard.dummy` for solaris --- vlib/clipboard/clipboard_default.c.v | 13 ++++++ vlib/clipboard/clipboard_solaris.c.v | 44 +++--------------- vlib/clipboard/dummy/dummy_clipboard.v | 45 +++++++++++++++++++ .../clipboard.c.v} | 8 ++-- vlib/time/time_solaris.c.v | 10 ----- 5 files changed, 67 insertions(+), 53 deletions(-) create mode 100644 vlib/clipboard/clipboard_default.c.v create mode 100644 vlib/clipboard/dummy/dummy_clipboard.v rename vlib/clipboard/{clipboard_linux.c.v => x11/clipboard.c.v} (99%) diff --git a/vlib/clipboard/clipboard_default.c.v b/vlib/clipboard/clipboard_default.c.v new file mode 100644 index 0000000000..0572feeddf --- /dev/null +++ b/vlib/clipboard/clipboard_default.c.v @@ -0,0 +1,13 @@ +module clipboard + +import clipboard.x11 + +pub type Clipboard = x11.Clipboard + +fn new_clipboard() &Clipboard { + return x11.new_clipboard() +} + +pub fn new_primary() &Clipboard { + return x11.new_primary() +} diff --git a/vlib/clipboard/clipboard_solaris.c.v b/vlib/clipboard/clipboard_solaris.c.v index a8abc87e83..d0e1094155 100644 --- a/vlib/clipboard/clipboard_solaris.c.v +++ b/vlib/clipboard/clipboard_solaris.c.v @@ -1,47 +1,13 @@ module clipboard -pub struct Clipboard { -mut: - text string // text data sent or received - got_text bool // used to confirm that we have got the text - is_owner bool // to save selection owner state -} +import clipboard.dummy + +pub type Clipboard = dummy.Clipboard fn new_clipboard() &Clipboard { - eprintln('TODO: support clipboard on solaris') - return &Clipboard{} + return dummy.new_clipboard() } pub fn new_primary() &Clipboard { - eprintln('TODO: support clipboard on solaris') - return &Clipboard{} -} - -fn (mut cb Clipboard) set_text(text string) bool { - cb.text = text - cb.is_owner = true - cb.got_text = true - return true -} - -fn (mut cb Clipboard) get_text() string { - return cb.text -} - -fn (mut cb Clipboard) clear() { - cb.text = '' - cb.is_owner = false -} - -fn (mut cb Clipboard) free() { -} - -fn (cb &Clipboard) has_ownership() bool { - return cb.is_owner -} - -fn (cb &Clipboard) check_availability() bool { - // This is a dummy clipboard implementation, - // which can be always used, although it does not do much... - return true + return dummy.new_primary() } diff --git a/vlib/clipboard/dummy/dummy_clipboard.v b/vlib/clipboard/dummy/dummy_clipboard.v new file mode 100644 index 0000000000..a42f7dfc95 --- /dev/null +++ b/vlib/clipboard/dummy/dummy_clipboard.v @@ -0,0 +1,45 @@ +module dummy + +pub struct Clipboard { +mut: + text string // text data sent or received + got_text bool // used to confirm that we have got the text + is_owner bool // to save selection owner state +} + +pub fn new_clipboard() &Clipboard { + return &Clipboard{} +} + +pub fn new_primary() &Clipboard { + return &Clipboard{} +} + +fn (mut cb Clipboard) set_text(text string) bool { + cb.text = text + cb.is_owner = true + cb.got_text = true + return true +} + +fn (mut cb Clipboard) get_text() string { + return cb.text +} + +fn (mut cb Clipboard) clear() { + cb.text = '' + cb.is_owner = false +} + +fn (mut cb Clipboard) free() { +} + +fn (cb &Clipboard) has_ownership() bool { + return cb.is_owner +} + +fn (cb &Clipboard) check_availability() bool { + // This is a dummy clipboard implementation, + // which can be always used, although it does not do much... + return true +} diff --git a/vlib/clipboard/clipboard_linux.c.v b/vlib/clipboard/x11/clipboard.c.v similarity index 99% rename from vlib/clipboard/clipboard_linux.c.v rename to vlib/clipboard/x11/clipboard.c.v index b15606b663..2dee2f40b3 100644 --- a/vlib/clipboard/clipboard_linux.c.v +++ b/vlib/clipboard/x11/clipboard.c.v @@ -1,6 +1,6 @@ // Currently there is only X11 Selections support and no way to handle Wayland // but since Wayland isn't extremely adopted, we are covering almost all Linux distros. -module clipboard +module x11 import time import sync @@ -132,7 +132,7 @@ struct Property{ data byteptr } -fn new_clipboard() &Clipboard { +pub fn new_clipboard() &Clipboard { return new_x11_clipboard(.clipboard) } @@ -198,7 +198,7 @@ fn (cb &Clipboard) take_ownership(){ C.XFlush(cb.display) } -fn (mut cb Clipboard) set_text(text string) bool { +pub fn (mut cb Clipboard) set_text(text string) bool { if cb.window == C.Window(C.None) {return false} cb.mutex.m_lock() cb.text = text @@ -255,7 +255,7 @@ fn (mut cb Clipboard) start_listener(){ C.XNextEvent(cb.display, &event) if event.@type == 0 { println("error") - continue + continue } match event.@type { C.DestroyNotify { diff --git a/vlib/time/time_solaris.c.v b/vlib/time/time_solaris.c.v index e3e24b1fda..be02862387 100644 --- a/vlib/time/time_solaris.c.v +++ b/vlib/time/time_solaris.c.v @@ -21,21 +21,11 @@ fn solaris_utc() Time { return unix2(int(ts.tv_sec), int(ts.tv_nsec / 1000)) } -// dummy to compile with all compilers -pub fn linux_now() Time { - return Time{} -} - // dummy to compile with all compilers pub fn darwin_now() Time { return Time{} } -// dummy to compile with all compilers -pub fn linux_utc() Time { - return Time{} -} - // dummy to compile with all compilers pub fn darwin_utc() Time { return Time{}