factor/library/ui/x11/clipboard.factor

26 lines
862 B
Factor
Raw Normal View History

! Copyright (C) 2006 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
USING: alien kernel math namespaces ;
IN: x11
! This code was inspired by McCLIM's Backends/CLX/port.lisp.
: selection-property ( -- n )
2006-06-03 18:06:50 -04:00
dpy get "org.factorcode.Factor.SELECTION" 0 XInternAtom ;
: convert-selection ( win -- n )
>r dpy get XA_PRIMARY XA_STRING selection-property r>
CurrentTime XConvertSelection ;
: snarf-property ( length-return prop-return -- string )
swap *ulong zero? [ drop f ] [ *char* ] if ;
: window-property ( win prop delete? -- string )
2006-06-03 18:06:50 -04:00
>r dpy get -rot 0 -1 r> AnyProperty
0 <Atom> 0 <int> 0 <ulong> 0 <ulong> f <void*>
2006-06-03 18:06:50 -04:00
[ XGetWindowProperty ] 2keep snarf-property ;
: selection-from-event ( event -- string )
dup XSelectionEvent-property zero?
2006-06-03 18:06:50 -04:00
[ drop f ] [ selection-property 1 window-property ] if ;