From 8abc4defa7c67a8c20c61815648675d01fc327c8 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 29 Mar 2023 23:24:42 -0400 Subject: [PATCH] Fixed INCR Oops! --- backends/x/event.go | 21 +++++++++++++++++++++ backends/x/selection.go | 16 +++++----------- backends/x/selectionclaim.go | 24 ++++++++++++++++++++++++ backends/x/window.go | 6 ++++++ 4 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 backends/x/selectionclaim.go diff --git a/backends/x/event.go b/backends/x/event.go index 0ee4aa6..c355134 100644 --- a/backends/x/event.go +++ b/backends/x/event.go @@ -244,6 +244,27 @@ func (window *window) handleSelectionNotify ( if !window.selectionRequest.open() { window.selectionRequest = nil } } +func (window *window) handlePropertyNotify ( + connection *xgbutil.XUtil, + event xevent.PropertyNotifyEvent, +) { + if window.selectionRequest == nil { return } + window.selectionRequest.handlePropertyNotify(connection, event) + if !window.selectionRequest.open() { window.selectionRequest = nil } +} + +func (window *window) handleSelectionClear ( + connection *xgbutil.XUtil, + event xevent.SelectionClearEvent, +) { + // TODO: schedule the claim to be deleted. when the event loop fires we + // will check to see if the claim is scheduled to be deleted and if it + // is, delete it. + if window.selectionClaim != nil { + window.selectionClaim.scheduledDelete = true + } +} + func (window *window) compressExpose ( firstEvent xproto.ExposeEvent, ) ( diff --git a/backends/x/selection.go b/backends/x/selection.go index 8bcec0e..26959fa 100644 --- a/backends/x/selection.go +++ b/backends/x/selection.go @@ -13,7 +13,6 @@ type selReqState int; const ( selReqStateClosed selReqState = iota selReqStateAwaitTargets selReqStateAwaitValue - selReqStateAwaitFirstChunk selReqStateAwaitChunk ) @@ -153,8 +152,7 @@ func (request *selectionRequest) handleSelectionNotify ( ) { // the only valid states that we can process a SelectionNotify event in invalidState := - request.state != selReqStateAwaitFirstChunk && - request.state != selReqStateAwaitValue && + request.state != selReqStateAwaitValue && request.state != selReqStateAwaitTargets if invalidState { return } @@ -168,13 +166,6 @@ func (request *selectionRequest) handleSelectionNotify ( // data. if event.Property == 0 { request.die(nil); return } - // if we are waiting for the first INCR chunk, do the special stuff for - // that and not the other stuff. - if request.state == selReqStateAwaitFirstChunk { - request.handleINCRProperty(event.Property) - return - } - // When using GetProperty to retrieve the value of a selection, the // property argument should be set to the corresponding value in the // SelectionNotify event. Because the requestor has no way of knowing @@ -216,7 +207,7 @@ func (request *selectionRequest) handleSelectionNotify ( if err != nil { request.die(err); return } // await the first chunk - request.state = selReqStateAwaitFirstChunk + request.state = selReqStateAwaitChunk return } @@ -337,6 +328,9 @@ func (request *selectionRequest) handleINCRProperty (property xproto.Atom) { // finalize the request with the data we have, and don't wait // for more. request.finalize(data.Bytes(request.incrMime, request.incrBuffer)) + + // we want to be extra sure we aren't holding onto this memory + request.incrBuffer = nil } else { // a property with content means the transfer is still ongoing. // we append the data we got and wait for more. diff --git a/backends/x/selectionclaim.go b/backends/x/selectionclaim.go new file mode 100644 index 0000000..39f0260 --- /dev/null +++ b/backends/x/selectionclaim.go @@ -0,0 +1,24 @@ +package x + +import "git.tebibyte.media/sashakoshka/tomo/data" + +type selectionClaim struct { + data data.Data + scheduledDelete bool +} + +func (window *window) newSelectionClaim (data data.Data) *selectionClaim { + return &selectionClaim{ + data: data, + } +} + +func (claim *selectionClaim) idle () bool { + // TODO +} + +func (claim *selectionClaim) handleSelectionRequest ( + // TODO +) { + // TODO +} diff --git a/backends/x/window.go b/backends/x/window.go index c272ff9..945daf9 100644 --- a/backends/x/window.go +++ b/backends/x/window.go @@ -34,6 +34,7 @@ type window struct { config config.Config selectionRequest *selectionRequest + selectionClaim *selectionClaim metrics struct { width int @@ -69,6 +70,7 @@ func (backend *Backend) newWindow ( err = window.xWindow.Listen ( xproto.EventMaskExposure, xproto.EventMaskStructureNotify, + xproto.EventMaskPropertyChange, xproto.EventMaskPointerMotion, xproto.EventMaskKeyPress, xproto.EventMaskKeyRelease, @@ -96,6 +98,10 @@ func (backend *Backend) newWindow ( Connect(backend.connection, window.xWindow.Id) xevent.SelectionNotifyFun(window.handleSelectionNotify). Connect(backend.connection, window.xWindow.Id) + xevent.PropertyNotifyFun(window.handlePropertyNotify). + Connect(backend.connection, window.xWindow.Id) + xevent.SelectionClearFun(window.handleSelectionClear). + Connect(backend.connection, window.xWindow.Id) window.SetTheme(backend.theme) window.SetConfig(backend.config)