Skip to content

Instantly share code, notes, and snippets.

@romgrk
Created November 1, 2020 02:47
Show Gist options
  • Save romgrk/56169975ccd8fa2ffafd134afcdfeedc to your computer and use it in GitHub Desktop.
Save romgrk/56169975ccd8fa2ffafd134afcdfeedc to your computer and use it in GitHub Desktop.
diff --git a/src/windows/window-manager.ts b/src/windows/window-manager.ts
index be87fe9..8e5538b 100644
--- a/src/windows/window-manager.ts
+++ b/src/windows/window-manager.ts
@@ -32,7 +32,16 @@ const getWindowById = (windowId: number) => {
const getInstanceWindows = (id = instances.current) =>
[...windows.values()].filter((win) => win.id.startsWith(`i${id}`))
+let webglTimeout: any;
+
const refreshWebGLGrid = () => {
+ if (webglTimeout)
+ clearTimeout(webglTimeout)
+ webglTimeout = setTimeout(refreshWebGLGridImplementation, 15)
+}
+
+const refreshWebGLGridImplementation = () => {
+ webglTimeout = undefined
webgl.clearAll()
getInstanceWindows().forEach((w) => w.redrawFromGridBuffer())
}
diff --git a/src/windows/window.ts b/src/windows/window.ts
index 0649a1d..ecf9cf3 100644
--- a/src/windows/window.ts
+++ b/src/windows/window.ts
@@ -161,6 +161,8 @@ export default () => {
container.appendChild(nameplate.element)
container.appendChild(content)
+ const dimensions = new WeakMap()
+
const api = {
get id() {
return wininfo.id
@@ -278,7 +280,15 @@ export default () => {
}
api.refreshLayout = () => {
- const { top, left, width, height } = content.getBoundingClientRect()
+ let rect
+ if (dimensions.has(content)) {
+ rect = dimensions.get(content)
+ }
+ else {
+ rect = content.getBoundingClientRect()
+ dimensions.set(content, rect)
+ }
+ const { top, left, width, height } = rect
const x = left
const y = top - titleSpecs.height
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment