Skip to content

Commit

Permalink
driver/xgbutil/copypaste: request primary atom from x server instead …
Browse files Browse the repository at this point in the history
…of using predefined value (possible that some x servers define it with other values. Improves #12).
  • Loading branch information
jmigpin committed Nov 20, 2018
1 parent 5bb25db commit 13b8563
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
28 changes: 15 additions & 13 deletions driver/xgbutil/copypaste/copy.go
Expand Up @@ -36,7 +36,7 @@ func (c *Copy) Set(i event.CopyPasteIndex, str string) error {
switch i {
case event.CPIPrimary:
c.primaryStr = str
return c.set(xproto.AtomPrimary)
return c.set(CopyAtoms.Primary)
case event.CPIClipboard:
c.clipboardStr = str
return c.set(CopyAtoms.Clipboard)
Expand Down Expand Up @@ -96,7 +96,7 @@ func (c *Copy) debugRequest(ev *xproto.SelectionRequestEvent, events chan<- inte
func (c *Copy) transferBytes(ev *xproto.SelectionRequestEvent) error {
var b []byte
switch ev.Selection {
case xproto.AtomPrimary:
case CopyAtoms.Primary:
b = []byte(c.primaryStr)
case CopyAtoms.Clipboard:
b = []byte(c.clipboardStr)
Expand Down Expand Up @@ -137,6 +137,8 @@ func (c *Copy) transferBytes(ev *xproto.SelectionRequestEvent) error {

//----------

// testing: $ xclip -o -target TARGETS -selection primary

func (c *Copy) transferTargets(ev *xproto.SelectionRequestEvent) error {
targets := []xproto.Atom{
CopyAtoms.Targets,
Expand All @@ -155,10 +157,10 @@ func (c *Copy) transferTargets(ev *xproto.SelectionRequestEvent) error {
c1 := xproto.ChangePropertyChecked(
c.conn,
xproto.PropModeReplace,
ev.Requestor, // requestor window
ev.Property, // property
xproto.AtomAtom, // (would not work in some cases with ev.Target)
32, // format
ev.Requestor, // requestor window
ev.Property, // property
CopyAtoms.Atom, // (would not work in some cases with ev.Target)
32, // format
uint32(len(targets)),
tbuf.Bytes())
if err := c1.Check(); err != nil {
Expand Down Expand Up @@ -187,7 +189,7 @@ func (c *Copy) transferTargets(ev *xproto.SelectionRequestEvent) error {
// Another application now owns the selection.
func (c *Copy) OnSelectionClear(ev *xproto.SelectionClearEvent) {
switch ev.Selection {
case xproto.AtomPrimary:
case CopyAtoms.Primary:
c.primaryStr = ""
case CopyAtoms.Clipboard:
c.clipboardStr = ""
Expand All @@ -197,14 +199,14 @@ func (c *Copy) OnSelectionClear(ev *xproto.SelectionClearEvent) {
//----------

var CopyAtoms struct {
XSelData xproto.Atom `loadAtoms:"XSEL_DATA"`
Atom xproto.Atom `loadAtoms:"ATOM"`
Primary xproto.Atom `loadAtoms:"PRIMARY"`
Clipboard xproto.Atom `loadAtoms:"CLIPBOARD"`
Targets xproto.Atom `loadAtoms:"TARGETS"`

Utf8String xproto.Atom `loadAtoms:"UTF8_STRING"`
Text xproto.Atom `loadAtoms:"TEXT"`
TextPlain xproto.Atom `loadAtoms:"text/plain"`
TextPlainCharsetUtf8 xproto.Atom `loadAtoms:"text/plain;charset=utf-8"`

Utf8String xproto.Atom `loadAtoms:"UTF8_STRING"`
Text xproto.Atom `loadAtoms:"TEXT"`
TextPlain xproto.Atom `loadAtoms:"text/plain"`
TextPlainCharsetUtf8 xproto.Atom `loadAtoms:"text/plain;charset=utf-8"`
GtkTextBufferContents xproto.Atom `loadAtoms:"GTK_TEXT_BUFFER_CONTENTS"`
}
10 changes: 6 additions & 4 deletions driver/xgbutil/copypaste/paste.go
Expand Up @@ -47,7 +47,7 @@ func (p *Paste) Get(index event.CopyPasteIndex, fn func(string, error)) {
func (p *Paste) get2(index event.CopyPasteIndex) (string, error) {
switch index {
case event.CPIPrimary:
return p.request(xproto.AtomPrimary)
return p.request(PasteAtoms.Primary)
case event.CPIClipboard:
return p.request(PasteAtoms.Clipboard)
default:
Expand Down Expand Up @@ -207,8 +207,10 @@ func (p *Paste) waitForPropertyNewValue(ev *xproto.SelectionNotifyEvent) error {
//----------

var PasteAtoms struct {
Primary xproto.Atom `loadAtoms:"PRIMARY"`
Clipboard xproto.Atom `loadAtoms:"CLIPBOARD"`
XSelData xproto.Atom `loadAtoms:"XSEL_DATA"`
Incr xproto.Atom `loadAtoms:"INCR"`

Utf8String xproto.Atom `loadAtoms:"UTF8_STRING"`
XSelData xproto.Atom `loadAtoms:"XSEL_DATA"`
Clipboard xproto.Atom `loadAtoms:"CLIPBOARD"`
Incr xproto.Atom `loadAtoms:"INCR"`
}

0 comments on commit 13b8563

Please sign in to comment.