1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

clipboard: add a clipboard.x11 submodule, use it by default; add a clipboard.dummy for solaris

This commit is contained in:
Delyan Angelov 2020-12-25 19:21:42 +02:00
parent 17cccc7b36
commit 270ba07e83
5 changed files with 67 additions and 53 deletions

View File

@ -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()
}

View File

@ -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()
}

View File

@ -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
}

View File

@ -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 {

View File

@ -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{}