@@ -39,11 +39,10 @@ type LayerSurface struct {
3939 wlSurface * client.Surface
4040 layerSurf * wlr_layer_shell.ZwlrLayerSurfaceV1
4141 viewport * wp_viewporter.WpViewport
42- wlPool * client.ShmPool
43- wlBuffer * client.Buffer
44- bufferBusy bool
45- oldPool * client.ShmPool
46- oldBuffer * client.Buffer
42+ wlPools [2 ]* client.ShmPool
43+ wlBuffers [2 ]* client.Buffer
44+ slotBusy [2 ]bool
45+ needsRedraw bool
4746 scopyBuffer * client.Buffer
4847 configured bool
4948 hidden bool
@@ -136,6 +135,7 @@ func (p *Picker) Run() (*Color, error) {
136135 break
137136 }
138137
138+ p .flushRedraws ()
139139 p .checkDone ()
140140 }
141141
@@ -164,6 +164,15 @@ func (p *Picker) checkDone() {
164164 }
165165}
166166
167+ func (p * Picker ) flushRedraws () {
168+ for _ , ls := range p .surfaces {
169+ if ! ls .needsRedraw {
170+ continue
171+ }
172+ p .redrawSurface (ls )
173+ }
174+ }
175+
167176func (p * Picker ) connect () error {
168177 display , err := client .Connect ("" )
169178 if err != nil {
@@ -507,47 +516,45 @@ func (p *Picker) captureForSurface(ls *LayerSurface) {
507516}
508517
509518func (p * Picker ) redrawSurface (ls * LayerSurface ) {
519+ slot := ls .state .FrontIndex ()
520+ if ls .slotBusy [slot ] {
521+ ls .needsRedraw = true
522+ return
523+ }
524+
510525 var renderBuf * ShmBuffer
511- if ls .hidden {
526+ switch {
527+ case ls .hidden :
512528 renderBuf = ls .state .RedrawScreenOnly ()
513- } else {
529+ default :
514530 renderBuf = ls .state .Redraw ()
515531 }
516532 if renderBuf == nil {
517533 return
518534 }
519535
520- if ls .oldBuffer != nil {
521- ls .oldBuffer .Destroy ()
522- ls .oldBuffer = nil
523- }
524- if ls .oldPool != nil {
525- ls .oldPool .Destroy ()
526- ls .oldPool = nil
527- }
536+ ls .needsRedraw = false
528537
529- ls .oldPool = ls .wlPool
530- ls .oldBuffer = ls .wlBuffer
531- ls .wlPool = nil
532- ls .wlBuffer = nil
538+ if ls .wlPools [slot ] == nil {
539+ pool , err := p .shm .CreatePool (renderBuf .Fd (), int32 (renderBuf .Size ()))
540+ if err != nil {
541+ return
542+ }
543+ ls .wlPools [slot ] = pool
533544
534- pool , err := p . shm . CreatePool ( renderBuf .Fd ( ), int32 (renderBuf .Size ()))
535- if err != nil {
536- return
537- }
538- ls .wlPool = pool
545+ wlBuffer , err := pool . CreateBuffer ( 0 , int32 ( renderBuf .Width ), int32 ( renderBuf . Height ), int32 (renderBuf .Stride ), uint32 ( ls . state . ScreenFormat ()))
546+ if err != nil {
547+ return
548+ }
549+ ls .wlBuffers [ slot ] = wlBuffer
539550
540- wlBuffer , err := pool .CreateBuffer (0 , int32 (renderBuf .Width ), int32 (renderBuf .Height ), int32 (renderBuf .Stride ), uint32 (ls .state .ScreenFormat ()))
541- if err != nil {
542- return
551+ s := slot
552+ wlBuffer .SetReleaseHandler (func (e client.BufferReleaseEvent ) {
553+ ls .slotBusy [s ] = false
554+ })
543555 }
544- ls .wlBuffer = wlBuffer
545556
546- lsRef := ls
547- wlBuffer .SetReleaseHandler (func (e client.BufferReleaseEvent ) {
548- lsRef .bufferBusy = false
549- })
550- ls .bufferBusy = true
557+ ls .slotBusy [slot ] = true
551558
552559 logicalW , logicalH := ls .state .LogicalSize ()
553560 if logicalW == 0 || logicalH == 0 {
@@ -566,7 +573,7 @@ func (p *Picker) redrawSurface(ls *LayerSurface) {
566573 }
567574 _ = ls .wlSurface .SetBufferScale (bufferScale )
568575 }
569- _ = ls .wlSurface .Attach (wlBuffer , 0 , 0 )
576+ _ = ls .wlSurface .Attach (ls . wlBuffers [ slot ] , 0 , 0 )
570577 _ = ls .wlSurface .Damage (0 , 0 , int32 (logicalW ), int32 (logicalH ))
571578 _ = ls .wlSurface .Commit ()
572579
@@ -634,7 +641,7 @@ func (p *Picker) setupPointerHandlers() {
634641 }
635642
636643 p .activeSurface .state .OnPointerMotion (e .SurfaceX , e .SurfaceY )
637- p .redrawSurface ( p . activeSurface )
644+ p .activeSurface . needsRedraw = true
638645 })
639646
640647 p .pointer .SetLeaveHandler (func (e client.PointerLeaveEvent ) {
@@ -655,7 +662,7 @@ func (p *Picker) setupPointerHandlers() {
655662 return
656663 }
657664 p .activeSurface .state .OnPointerMotion (e .SurfaceX , e .SurfaceY )
658- p .redrawSurface ( p . activeSurface )
665+ p .activeSurface . needsRedraw = true
659666 })
660667
661668 p .pointer .SetButtonHandler (func (e client.PointerButtonEvent ) {
@@ -679,17 +686,13 @@ func (p *Picker) cleanup() {
679686 if ls .scopyBuffer != nil {
680687 ls .scopyBuffer .Destroy ()
681688 }
682- if ls .oldBuffer != nil {
683- ls .oldBuffer .Destroy ()
684- }
685- if ls .oldPool != nil {
686- ls .oldPool .Destroy ()
687- }
688- if ls .wlBuffer != nil {
689- ls .wlBuffer .Destroy ()
690- }
691- if ls .wlPool != nil {
692- ls .wlPool .Destroy ()
689+ for i := range ls .wlBuffers {
690+ if ls .wlBuffers [i ] != nil {
691+ ls .wlBuffers [i ].Destroy ()
692+ }
693+ if ls .wlPools [i ] != nil {
694+ ls .wlPools [i ].Destroy ()
695+ }
693696 }
694697 if ls .viewport != nil {
695698 ls .viewport .Destroy ()
0 commit comments