mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +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
|
wsize image.Point // window config size before going fullscreen or maximized
|
||||||
inCompositor bool // window is moving or being resized
|
inCompositor bool // window is moving or being resized
|
||||||
|
|
||||||
|
clipReads chan clipboard.Event
|
||||||
|
|
||||||
wakeups chan struct{}
|
wakeups chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,11 +334,12 @@ func (d *wlDisplay) createNativeWindow(options []Option) (*window, error) {
|
|||||||
ppdp := detectUIScale()
|
ppdp := detectUIScale()
|
||||||
|
|
||||||
w := &window{
|
w := &window{
|
||||||
disp: d,
|
disp: d,
|
||||||
scale: scale,
|
scale: scale,
|
||||||
ppdp: ppdp,
|
ppdp: ppdp,
|
||||||
ppsp: ppdp,
|
ppsp: ppdp,
|
||||||
wakeups: make(chan struct{}, 1),
|
wakeups: make(chan struct{}, 1),
|
||||||
|
clipReads: make(chan clipboard.Event, 1),
|
||||||
}
|
}
|
||||||
w.surf = C.wl_compositor_create_surface(d.compositor)
|
w.surf = C.wl_compositor_create_surface(d.compositor)
|
||||||
if w.surf == nil {
|
if w.surf == nil {
|
||||||
@@ -945,7 +948,8 @@ func (w *window) ReadClipboard() {
|
|||||||
go func() {
|
go func() {
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
data, _ := ioutil.ReadAll(r)
|
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
|
return err
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
|
case e := <-w.clipReads:
|
||||||
|
w.w.Event(e)
|
||||||
case <-w.wakeups:
|
case <-w.wakeups:
|
||||||
w.w.Event(wakeupEvent{})
|
w.w.Event(wakeupEvent{})
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user