diff --git a/src/lib/mwinlib/mwin_controller.svelte.ts b/src/lib/mwinlib/mwin_controller.svelte.ts index b8e7f0d..7e87e8b 100644 --- a/src/lib/mwinlib/mwin_controller.svelte.ts +++ b/src/lib/mwinlib/mwin_controller.svelte.ts @@ -95,6 +95,7 @@ class MWinController { this.#savedStyles = this.#node.style.cssText; this.#savedTransition = this.#node.style.transition; this.#node.style.transition = 'none'; + this.#node.style.willChange = 'transform'; this.#wrapper.style.position = 'relative'; this.#node.style.position = 'absolute'; @@ -347,6 +348,10 @@ class MWinController { if (!this.#pendingApply) { this.#pendingApply = true; this.#rafID = requestAnimationFrame(() => { + if (!this.state.moving && !this.state.resizing) { + this.#node.style.willChange = 'auto'; + } + this.#rafID = null; this.#pendingApply = false; this.#apply(); @@ -430,6 +435,7 @@ class MWinController { this.#node.style.transition = this.#savedTransition; this.#node.style.willChange = 'auto'; this.#node.style.touchAction = ''; + this.#node.style.cursor = 'auto'; window.removeEventListener('pointermove', this.#onPointerMove); window.removeEventListener('pointerup', this.#onPointerUp); @@ -522,7 +528,7 @@ class MWinController { this.state.height = this.#wrapperHeight; this.state.maximized = true; } - this.#scheduleApply(); + this.#apply(); } close(): void { diff --git a/src/lib/mwinlib/mwin_util.ts b/src/lib/mwinlib/mwin_util.ts index d1fe2c0..fdc9167 100644 --- a/src/lib/mwinlib/mwin_util.ts +++ b/src/lib/mwinlib/mwin_util.ts @@ -80,10 +80,17 @@ export function getWrapperManager(wrapper: HTMLElement): WrapperManager { export function resolveElement( input: HTMLElement | (() => HTMLElement) | string | undefined, - fallback?: HTMLElement + relativeTo: HTMLElement ): HTMLElement | null { if (!input) return null; + + if (input instanceof HTMLElement) return input; + if (typeof input === 'function') return input(); - if (typeof input === 'string') return fallback?.closest(input) ?? document.querySelector(input); - return input; + + if (typeof input === 'string') { + return relativeTo.closest(input) as HTMLElement | null; + } + + return null; } diff --git a/src/lib/termos/terminal/keybind_inhibitor.ts b/src/lib/termos/terminal/keybind_inhibitor.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/lib/termos/terminal/keybind_listenter.ts b/src/lib/termos/terminal/keybind_listenter.ts new file mode 100644 index 0000000..4961e50 --- /dev/null +++ b/src/lib/termos/terminal/keybind_listenter.ts @@ -0,0 +1,66 @@ +export class KeybindListener { + #abortController: AbortController; + #eventStack: KeyboardEvent[] = []; + #bindTable: Map = new Map(); + + constructor(elem: HTMLElement) { + this.#abortController = new AbortController(); + + elem.addEventListener('keydown', (e) => this.#captureEvent(e), { + signal: this.#abortController.signal, + passive: true + }); + } + + #captureEvent(e: KeyboardEvent) { + if (e.altKey || e.shiftKey || e.ctrlKey) { + this.#eventStack.push(e); + } + this.#processEvent(e); + } + + #processEvent(e: KeyboardEvent) { + const keybind: Keybind = { + key: e.key, + modifiers: this.#pushModifiers() + }; + + const value = this.#bindTable.get(keybind); + if (!value) return; + + value?.function?.(e); + console.log(`[keybind-listener] - executed a function under a keybind: ${keybind}`); + } + + #pushModifiers(): Modifier[] { + const mods: Modifier[] = []; + + for (const event of this.#eventStack) { + mods.push(event.key as Modifier); + } + + return mods; + } + + registerKeybinds(keybinds: { keybind: Keybind; options: KeybindOptions }[]): void { + for (const value of keybinds) { + this.#bindTable.set(value.keybind, { + function: value.options.function, + no_inhibit: value.options.no_inhibit ?? false + }); + console.log(`[keybind-listener] - keybind registered under the key: ${value.keybind}`); + } + } +} + +export type Keybind = { + key: string; + modifiers?: Modifier[]; +}; + +export type KeybindOptions = { + function: (e: KeyboardEvent) => void; + no_inhibit?: boolean; +}; + +export type Modifier = 'Control' | 'Alt' | 'Shift'; diff --git a/src/lib/termos/util/shell_keybinds.ts b/src/lib/termos/util/shell_keybinds.ts new file mode 100644 index 0000000..f4847d5 --- /dev/null +++ b/src/lib/termos/util/shell_keybinds.ts @@ -0,0 +1,13 @@ +import type { Keybind, KeybindOptions } from "../terminal/keybind_listenter"; + +export const SHELL_KEYBINDS: { keybind: Keybind; options: KeybindOptions }[] = [ + { + keybind: { + key: 'c', + modifiers: ['Control'] + } + options: { + function + } + } +] \ No newline at end of file diff --git a/src/modules/Terminal.svelte b/src/modules/Terminal.svelte index 45d339b..41cc358 100644 --- a/src/modules/Terminal.svelte +++ b/src/modules/Terminal.svelte @@ -1,6 +1,6 @@ -
+
(movableAPI = api) + onAPI: (api) => (mwin = api) }} >
-
@@ -92,9 +94,13 @@
inputComponent?.focusInput()} + onkeydown={() => inputComponent?.focusInput()} + role="textbox" + tabindex="-1" >
- +
diff --git a/src/modules/terminal/Input.svelte b/src/modules/terminal/Input.svelte index 38d1530..9c71448 100644 --- a/src/modules/terminal/Input.svelte +++ b/src/modules/terminal/Input.svelte @@ -1,4 +1,6 @@ -
-
(API = api) - }} - > -
- -
-
+