From 017543aa0f0d31fb99504ec5ae01016f6c2e8b6f Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 30 Mar 2023 18:05:29 -0400 Subject: [PATCH] Temporary redirect to patched xgbutil that will only work on my machine --- backends/x/event.go | 1 + backends/x/selection.go | 2 ++ backends/x/selectionclaim.go | 9 +++++++-- backends/x/window.go | 8 +++----- go.mod | 2 ++ 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/backends/x/event.go b/backends/x/event.go index 53552d4..58c6cf4 100644 --- a/backends/x/event.go +++ b/backends/x/event.go @@ -264,6 +264,7 @@ func (window *window) handleSelectionRequest ( connection *xgbutil.XUtil, event xevent.SelectionRequestEvent, ) { + println("got sel req") if window.selectionClaim == nil { return } window.selectionClaim.handleSelectionRequest(connection, event) } diff --git a/backends/x/selection.go b/backends/x/selection.go index ddfb9c9..8529d94 100644 --- a/backends/x/selection.go +++ b/backends/x/selection.go @@ -9,6 +9,8 @@ import "github.com/jezek/xgbutil/xprop" import "github.com/jezek/xgbutil/xevent" import "git.tebibyte.media/sashakoshka/tomo/data" +const clipboardName = "CLIPBOARD" + type selReqState int; const ( selReqStateClosed selReqState = iota selReqStateAwaitTargets diff --git a/backends/x/selectionclaim.go b/backends/x/selectionclaim.go index 3ded6a8..f3e0b6e 100644 --- a/backends/x/selectionclaim.go +++ b/backends/x/selectionclaim.go @@ -17,7 +17,7 @@ type selectionClaim struct { func (window *window) claimSelection (name xproto.Atom, data data.Data) *selectionClaim { // Follow: // https://tronche.com/gui/x/icccm/sec-2.html#s-2.1 - + // A client wishing to acquire ownership of a particular selection // should call SetSelectionOwner. The client should set the specified // selection to the atom that represents the selection, set the @@ -35,6 +35,11 @@ func (window *window) claimSelection (name xproto.Atom, data data.Data) *selecti window.xWindow.Id, name, 0).Check() // FIXME: should not be zero if err != nil { return nil } + ownerReply, err := xproto.GetSelectionOwner ( + window.backend.connection.Conn(), name).Reply() + if err != nil { return nil } + if ownerReply.Owner != window.xWindow.Id { return nil} + return &selectionClaim { window: window, data: data, @@ -139,7 +144,7 @@ func (claim *selectionClaim) handleSelectionRequest ( for index, name := range targetNames { atom, err := xprop.Atm(claim.window.backend.connection, name) if err != nil { die(); return } - xgb.Put32(data[:index * 4], uint32(atom)) + xgb.Put32(data[:(index + 1) * 4], uint32(atom)) } claim.window.fulfillSelectionRequest(data, 8, event) diff --git a/backends/x/window.go b/backends/x/window.go index 2d0b750..d8a273a 100644 --- a/backends/x/window.go +++ b/backends/x/window.go @@ -290,8 +290,7 @@ func (window *window) Hide () { } func (window *window) Copy (data data.Data) { - selectionName := "CLIPBOARD" - selectionAtom, err := xprop.Atm(window.backend.connection, selectionName) + selectionAtom, err := xprop.Atm(window.backend.connection, clipboardName) if err != nil { return } window.selectionClaim = window.claimSelection(selectionAtom, data) } @@ -307,9 +306,8 @@ func (window *window) Paste (callback func (data.Data, error), accept ...data.Mi return } - selectionName := "CLIPBOARD" - propertyName := "TOMO_SELECTION" - selectionAtom, err := xprop.Atm(window.backend.connection, selectionName) + propertyName := "TOMO_SELECTION" + selectionAtom, err := xprop.Atm(window.backend.connection, clipboardName) if err != nil { die(err); return } propertyAtom, err := xprop.Atm(window.backend.connection, propertyName) if err != nil { die(err); return } diff --git a/go.mod b/go.mod index 20559ab..7a0fc0a 100644 --- a/go.mod +++ b/go.mod @@ -22,3 +22,5 @@ require ( github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 // indirect github.com/jezek/xgb v1.1.0 ) + +replace github.com/jezek/xgbutil => /home/sashakoshka/repos/xgbutil