mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
app: [Wayland] make clipboard reads synchronous
app.Window.Event is no longer safe to call for goroutines outside the event loop. This change ensures that clipboard reads happen on the even loop. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+12
-6
@@ -194,6 +194,8 @@ type window struct {
|
||||
wsize image.Point // window config size before going fullscreen or maximized
|
||||
inCompositor bool // window is moving or being resized
|
||||
|
||||
clipReads chan clipboard.Event
|
||||
|
||||
wakeups chan struct{}
|
||||
}
|
||||
|
||||
@@ -332,11 +334,12 @@ func (d *wlDisplay) createNativeWindow(options []Option) (*window, error) {
|
||||
ppdp := detectUIScale()
|
||||
|
||||
w := &window{
|
||||
disp: d,
|
||||
scale: scale,
|
||||
ppdp: ppdp,
|
||||
ppsp: ppdp,
|
||||
wakeups: make(chan struct{}, 1),
|
||||
disp: d,
|
||||
scale: scale,
|
||||
ppdp: ppdp,
|
||||
ppsp: ppdp,
|
||||
wakeups: make(chan struct{}, 1),
|
||||
clipReads: make(chan clipboard.Event, 1),
|
||||
}
|
||||
w.surf = C.wl_compositor_create_surface(d.compositor)
|
||||
if w.surf == nil {
|
||||
@@ -945,7 +948,8 @@ func (w *window) ReadClipboard() {
|
||||
go func() {
|
||||
defer r.Close()
|
||||
data, _ := ioutil.ReadAll(r)
|
||||
w.w.Event(clipboard.Event{Text: string(data)})
|
||||
w.clipReads <- clipboard.Event{Text: string(data)}
|
||||
w.Wakeup()
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -1310,6 +1314,8 @@ func (w *window) loop() error {
|
||||
return err
|
||||
}
|
||||
select {
|
||||
case e := <-w.clipReads:
|
||||
w.w.Event(e)
|
||||
case <-w.wakeups:
|
||||
w.w.Event(wakeupEvent{})
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user