ci: fix union field warnings in `clipboard` module
parent
d645e45752
commit
7545ed4121
|
@ -3,9 +3,7 @@ module clipboard
|
||||||
#include <libkern/OSAtomic.h>
|
#include <libkern/OSAtomic.h>
|
||||||
#include <Cocoa/Cocoa.h>
|
#include <Cocoa/Cocoa.h>
|
||||||
#flag -framework Cocoa
|
#flag -framework Cocoa
|
||||||
|
|
||||||
#include "@VROOT/vlib/clipboard/clipboard_darwin.m"
|
#include "@VROOT/vlib/clipboard/clipboard_darwin.m"
|
||||||
|
|
||||||
pub struct Clipboard {
|
pub struct Clipboard {
|
||||||
pb voidptr
|
pb voidptr
|
||||||
last_cb_serial i64
|
last_cb_serial i64
|
||||||
|
@ -14,12 +12,14 @@ mut:
|
||||||
}
|
}
|
||||||
|
|
||||||
fn C.darwin_new_pasteboard() voidptr
|
fn C.darwin_new_pasteboard() voidptr
|
||||||
|
|
||||||
fn C.darwin_get_pasteboard_text(voidptr) byteptr
|
fn C.darwin_get_pasteboard_text(voidptr) byteptr
|
||||||
|
|
||||||
fn C.darwin_set_pasteboard_text(string) bool
|
fn C.darwin_set_pasteboard_text(string) bool
|
||||||
|
|
||||||
fn new_clipboard() &Clipboard {
|
fn new_clipboard() &Clipboard {
|
||||||
cb := &Clipboard{
|
cb := &Clipboard{
|
||||||
pb: C.darwin_new_pasteboard()// pb
|
pb: C.darwin_new_pasteboard() // pb
|
||||||
}
|
}
|
||||||
return cb
|
return cb
|
||||||
}
|
}
|
||||||
|
@ -58,9 +58,8 @@ fn (mut cb Clipboard) get_text() string {
|
||||||
if isnil(cb.pb) {
|
if isnil(cb.pb) {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
utf8_clip := C.darwin_get_pasteboard_text(cb.pb)
|
utf8_clip := C.darwin_get_pasteboard_text(cb.pb)
|
||||||
return unsafe {utf8_clip.vstring()}
|
return unsafe { utf8_clip.vstring() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_primary() &Clipboard {
|
pub fn new_primary() &Clipboard {
|
||||||
|
|
|
@ -255,19 +255,19 @@ fn (mut cb Clipboard) start_listener(){
|
||||||
mut to_be_requested := C.Atom(0)
|
mut to_be_requested := C.Atom(0)
|
||||||
for {
|
for {
|
||||||
C.XNextEvent(cb.display, &event)
|
C.XNextEvent(cb.display, &event)
|
||||||
if event.@type == 0 {
|
if unsafe { event.@type == 0 } {
|
||||||
println("error")
|
println("error")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
match event.@type {
|
match unsafe {event.@type} {
|
||||||
C.DestroyNotify {
|
C.DestroyNotify {
|
||||||
if event.xdestroywindow.window == cb.window {
|
if unsafe { event.xdestroywindow.window == cb.window } {
|
||||||
// we are done
|
// we are done
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
C.SelectionClear {
|
C.SelectionClear {
|
||||||
if event.xselectionclear.window == cb.window && event.xselectionclear.selection == cb.selection {
|
if unsafe { event.xselectionclear.window == cb.window } && unsafe { event.xselectionclear.selection == cb.selection } {
|
||||||
cb.mutex.m_lock()
|
cb.mutex.m_lock()
|
||||||
cb.is_owner = false
|
cb.is_owner = false
|
||||||
cb.text = ""
|
cb.text = ""
|
||||||
|
@ -275,9 +275,9 @@ fn (mut cb Clipboard) start_listener(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
C.SelectionRequest {
|
C.SelectionRequest {
|
||||||
if event.xselectionrequest.selection == cb.selection {
|
if unsafe { event.xselectionrequest.selection == cb.selection } {
|
||||||
mut xsre := &C.XSelectionRequestEvent{ display: 0 }
|
mut xsre := &C.XSelectionRequestEvent{ display: 0 }
|
||||||
xsre = &event.xselectionrequest
|
xsre = unsafe { &event.xselectionrequest }
|
||||||
|
|
||||||
mut xse := C.XSelectionEvent{
|
mut xse := C.XSelectionEvent{
|
||||||
@type: C.SelectionNotify // 31
|
@type: C.SelectionNotify // 31
|
||||||
|
@ -296,20 +296,20 @@ fn (mut cb Clipboard) start_listener(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
C.SelectionNotify {
|
C.SelectionNotify {
|
||||||
if event.xselection.selection == cb.selection && event.xselection.property != C.Atom(C.None) {
|
if unsafe { event.xselection.selection == cb.selection && event.xselection.property != C.Atom(C.None) } {
|
||||||
if event.xselection.target == cb.get_atom(.targets) && !sent_request {
|
if unsafe { event.xselection.target == cb.get_atom(.targets) && !sent_request } {
|
||||||
sent_request = true
|
sent_request = true
|
||||||
prop := read_property(cb.display, cb.window, cb.selection)
|
prop := read_property(cb.display, cb.window, cb.selection)
|
||||||
to_be_requested = cb.pick_target(prop)
|
to_be_requested = cb.pick_target(prop)
|
||||||
if to_be_requested != C.Atom(0) {
|
if to_be_requested != C.Atom(0) {
|
||||||
C.XConvertSelection(cb.display, cb.selection, to_be_requested, cb.selection, cb.window, C.CurrentTime)
|
C.XConvertSelection(cb.display, cb.selection, to_be_requested, cb.selection, cb.window, C.CurrentTime)
|
||||||
}
|
}
|
||||||
} else if event.xselection.target == to_be_requested {
|
} else if unsafe { event.xselection.target == to_be_requested } {
|
||||||
sent_request = false
|
sent_request = false
|
||||||
to_be_requested = C.Atom(0)
|
to_be_requested = C.Atom(0)
|
||||||
cb.mutex.m_lock()
|
cb.mutex.m_lock()
|
||||||
prop := read_property(event.xselection.display, event.xselection.requestor, event.xselection.property)
|
prop := unsafe{ read_property(event.xselection.display, event.xselection.requestor, event.xselection.property) }
|
||||||
C.XDeleteProperty(event.xselection.display, event.xselection.requestor, event.xselection.property)
|
unsafe{ C.XDeleteProperty(event.xselection.display, event.xselection.requestor, event.xselection.property) }
|
||||||
if cb.is_supported_target(prop.actual_type) {
|
if cb.is_supported_target(prop.actual_type) {
|
||||||
cb.got_text = true
|
cb.got_text = true
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Reference in New Issue