Compare commits

..

No commits in common. "c8b70599764598225853e15751f8a833e2b0d115" and "49eff984ab2ff6bdcc15e2dc6d5e85b0a114b8ca" have entirely different histories.

3 changed files with 11 additions and 24 deletions

View File

@ -102,8 +102,7 @@ func (claim *Claim) fulfillSelectionRequest (
} }
// While the selection claim is active, HandleSelectionRequest should be called // While the selection claim is active, HandleSelectionRequest should be called
// when the owner window recieves a SelectionRequest event. This must be // when the owner window recieves a SelectionRequest event.
// registered as an event handler manually.
func (claim *Claim) HandleSelectionRequest ( func (claim *Claim) HandleSelectionRequest (
connection *xgbutil.XUtil, connection *xgbutil.XUtil,
event xevent.SelectionRequestEvent, event xevent.SelectionRequestEvent,

26
data.go
View File

@ -3,25 +3,18 @@ package xgbsel
import "io" import "io"
import "strings" import "strings"
// Data represents X selection data. // Data represents a polymorphic data structure
type Data interface { type Data interface {
// Convert converts the data to the specified target and returns it. If Convert (Target) (reader io.ReadSeekCloser, ok bool)
// the target is not supported, this behavior will return false for ok.
Convert (Target) (reader io.ReadSeekCloser, ok bool)
// Supported returns a slice of targets that Convert can accept. This
// can just be the result of MimeToTargets.
Supported () []Target Supported () []Target
} }
// Target represents an X selection target. It defines the type of data stored // Target represents an X selection target. It defines the type of data stored
// within an X selection. This data may be a MIME type, or a more specific name // within an X selection. This data may be a mime type, or a more specific name
// that is unique to X. A list of these names can be found here: // that is unique to X. A list of these names can be found here:
// https://tronche.com/gui/x/icccm/sec-2.html#s-2.6.2 // https://tronche.com/gui/x/icccm/sec-2.html#s-2.6.2
type Target string type Target string
// Confidence represents how accurate a conversion from a target to a MIME type
// is.
type Confidence int; const ( type Confidence int; const (
ConfidenceNone Confidence = iota ConfidenceNone Confidence = iota
ConfidencePartial ConfidencePartial
@ -30,10 +23,9 @@ type Confidence int; const (
// ToMime converts the specified target to a MIME type. Because a single MIME // ToMime converts the specified target to a MIME type. Because a single MIME
// type may correspond to several targets, a confidence value is returned // type may correspond to several targets, a confidence value is returned
// representing how one-to-one of a match it is. If some data is represented by // representing how good of a match it is. If data is represented by multiple
// multiple targets, they can each be checked individually and the one with the // targets, they can be checked one after the other and the one with the highest
// highest confidence value can be chosen. If a target cannot be converted to a // confidence value chosen.
// MIME type, ("", ConfidenceNone) is returned.
func (target Target) ToMime () (string, Confidence) { func (target Target) ToMime () (string, Confidence) {
// TODO: add other stuff. reference this table: // TODO: add other stuff. reference this table:
// https://tronche.com/gui/x/icccm/sec-2.html#s-2.6.2 // https://tronche.com/gui/x/icccm/sec-2.html#s-2.6.2
@ -66,10 +58,8 @@ func (target Target) ToMime () (string, Confidence) {
} }
} }
// MimeToTargets returns a slice of targets that correspond to a specified MIME // MimeToTargets returns a list of targets that correspond to a specified MIME
// type. The MIME type itself is always the first item of the slice. All targets // type.
// returned by this function are guaranteed to convert to the given MIME type
// when ToMime is called on them.
func MimeToTargets (mime string) []Target { func MimeToTargets (mime string) []Target {
targets := []Target { Target(mime) } targets := []Target { Target(mime) }
switch mime { switch mime {

View File

@ -106,8 +106,7 @@ func (request *Request) open () bool {
} }
// While the selection request is active, HandleSelectionNotify should be called // While the selection request is active, HandleSelectionNotify should be called
// when the requesting window recieves a SelectionNotify event. This must be // when the requesting window recieves a SelectionNotify event.
// registered as an event handler manually.
func (request *Request) HandleSelectionNotify ( func (request *Request) HandleSelectionNotify (
connection *xgbutil.XUtil, connection *xgbutil.XUtil,
event xevent.SelectionNotifyEvent, event xevent.SelectionNotifyEvent,
@ -238,8 +237,7 @@ func (request *Request) HandleSelectionNotify (
} }
// While the selection request is active, HandlePropertyNotify should be called // While the selection request is active, HandlePropertyNotify should be called
// when the requesting window recieves a PropertyNotify event. This must be // when the requesting window recieves a PropertyNotify event.
// registered as an event handler manually.
func (request *Request) HandlePropertyNotify ( func (request *Request) HandlePropertyNotify (
connection *xgbutil.XUtil, connection *xgbutil.XUtil,
event xevent.PropertyNotifyEvent, event xevent.PropertyNotifyEvent,