@ 261105.1

261006.1 · c2d660f0fafb796cc261dcdda8451da67a209b51

fix(resize): report the pixel size in resize events

reading declarations

input.go

@@ -175,19 +175,20 @@ func (ip *inputParser) SetPixelMouse(on bool) { 	} } -func (ip *inputParser) SetSize(w, h int) {+func (ip *inputParser) SetSize(ws WindowSize) { 	if ip.nested != nil {-		ip.nested.SetSize(w, h)+		ip.nested.SetSize(ws) 		return 	} 	go func() { 		ip.l.Lock()-		ip.rows = h-		ip.cols = w-		ip.post(NewEventResize(w, h))+		ip.rows = ws.Height+		ip.cols = ws.Width+		ip.post(newEventResize(ws)) 		ip.l.Unlock() 	}() }+ func (ip *inputParser) post(ev Event) { 	if ip.escaped { 		ip.escaped = false@@ -1462,14 +1463,18 @@ func (ip *inputParser) handleCsi(mode rune, params []byte, intermediate []byte) 				h := P[1] 				w := P[2] 				if h != ip.rows || w != ip.cols {-					ip.SetSize(w, h)+					ip.SetSize(WindowSize{Width: w, Height: h}) 				} 				return 			} 		case 48: 			if len(P) > 2 {-				// window resize report-				ip.post(NewEventResize(P[2], P[1]))+				// window resize report, with the size in pixels if given+				ws := WindowSize{Width: P[2], Height: P[1]}+				if len(P) > 4 {+					ws.PixelWidth, ws.PixelHeight = P[4], P[3]+				}+				ip.post(newEventResize(ws)) 				return 			} 		}

input_test.go

@@ -1545,3 +1545,27 @@ func TestInputMouseSgrPixelNoClip(t *testing.T) { 		t.Errorf("expected re-clipped position (79,23), got (%d,%d)", x, y) 	} }++// TestInputInBandResizePixels tests that an in-band resize report carries the size in pixels.+func TestInputInBandResizePixels(t *testing.T) {+	evch := make(chan Event, 10)+	ip := newInputParser(evch)++	ip.ScanUTF8([]byte("\x1b[48;25;80;400;640t"))++	select {+	case ev := <-evch:+		rev, ok := ev.(*EventResize)+		if !ok {+			t.Fatalf("Expected EventResize, got %T", ev)+		}+		if w, h := rev.Size(); w != 80 || h != 25 {+			t.Errorf("Expected size 80x25, got %dx%d", w, h)+		}+		if w, h := rev.PixelSize(); w != 640 || h != 400 {+			t.Errorf("Expected pixel size 640x400, got %dx%d", w, h)+		}+	case <-time.After(100 * time.Millisecond):+		t.Fatal("Timeout waiting for resize event")+	}+}

resize.go

@@ -25,10 +25,10 @@ type EventResize struct { // NewEventResize creates an EventResize with the new updated window size, // which is given in character cells. func NewEventResize(width, height int) *EventResize {-	ws := WindowSize{-		Width:  width,-		Height: height,-	}+	return newEventResize(WindowSize{Width: width, Height: height})+}++func newEventResize(ws WindowSize) *EventResize { 	ev := &EventResize{ws: ws} 	ev.SetEventNow() 	return ev

tscreen.go

@@ -1253,7 +1253,7 @@ func (t *tScreen) resize() { 	t.cells.Invalidate() 	t.h = ws.Height 	t.w = ws.Width-	t.input.SetSize(ws.Width, ws.Height)+	t.input.SetSize(ws) }  func (t *tScreen) Colors() int {