diff --git a/src/components/rdp/RdpView.vue b/src/components/rdp/RdpView.vue index f1cdea0..89b684d 100644 --- a/src/components/rdp/RdpView.vue +++ b/src/components/rdp/RdpView.vue @@ -204,17 +204,44 @@ onBeforeUnmount(() => { if (resizeTimeout) { clearTimeout(resizeTimeout); resizeTimeout = null; } }); -// Focus canvas and force full frame refresh when switching to this tab +// Focus canvas, re-check dimensions, and force full frame on tab switch watch( () => props.isActive, (active) => { - if (active && canvasRef.value) { - // Force full frame fetch to repaint the canvas immediately - invoke("rdp_force_refresh", { sessionId: props.sessionId }).catch(() => {}); - if (keyboardGrabbed.value) { - setTimeout(() => canvasRef.value?.focus(), 0); - } - } + if (!active || !canvasRef.value) return; + + // Wait for layout to settle after tab becomes visible + requestAnimationFrame(() => { + requestAnimationFrame(() => { + const wrapper = canvasWrapper.value; + const canvas = canvasRef.value; + if (!wrapper || !canvas) return; + + const { width: cw, height: ch } = wrapper.getBoundingClientRect(); + const newW = Math.round(cw) & ~1; + const newH = Math.round(ch); + + // If container size differs from canvas resolution, resize the RDP session + if (newW >= 200 && newH >= 200 && (newW !== canvas.width || newH !== canvas.height)) { + invoke("rdp_resize", { + sessionId: props.sessionId, + width: newW, + height: newH, + }).then(() => { + canvas.width = newW; + canvas.height = newH; + setTimeout(() => { + invoke("rdp_force_refresh", { sessionId: props.sessionId }).catch(() => {}); + }, 200); + }).catch(() => {}); + } else { + // Same size — just refresh the frame + invoke("rdp_force_refresh", { sessionId: props.sessionId }).catch(() => {}); + } + + if (keyboardGrabbed.value) canvas.focus(); + }); + }); }, );