experiments in a post-browser web
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(window-placement): Phase 5 — tile-ipc.ts v2 positioning consolidated through computePlacement

+38 -14
+38 -14
backend/electron/tile-ipc.ts
··· 31 31 } from './tile-launcher.js'; 32 32 import { registerTileIpc } from './tile-ipc-gate.js'; 33 33 import { parseManifestFile } from './tile-manifest.js'; 34 + import { computePlacement } from './window-placement.js'; 34 35 import { publish, subscribe, unsubscribe, getStats as getPubSubStats } from './pubsub.js'; 35 36 import { DEBUG, TILE_STRICT, isHeadless } from './config.js'; 36 37 import { publishCapabilityViolation } from './tile-violations.js'; ··· 2881 2882 return { success: false, error: 'Window not found' }; 2882 2883 } 2883 2884 const bounds = win.getBounds(); 2884 - const display = screen.getDisplayNearestPoint({ 2885 - x: bounds.x + Math.round(bounds.width / 2), 2886 - y: bounds.y + Math.round(bounds.height / 2), 2885 + // Route through `computePlacement` so the "center this window" command 2886 + // shares the same code path as automatic re-centering on display change. 2887 + // Use a synthetic cursorPoint at the window's current center so the 2888 + // chosen display is the one the window is already on (preserving the 2889 + // original `screen.getDisplayNearestPoint(<window center>)` semantics). 2890 + // If the window is stranded (<50% on any display), `computePlacement` 2891 + // will rescue to the cursor display — a more useful outcome than 2892 + // centering on a display the user can't see. 2893 + const result = computePlacement({ 2894 + placement: { mode: 'centered' }, 2895 + currentBounds: bounds, 2896 + windowSize: { width: bounds.width, height: bounds.height }, 2897 + displays: screen.getAllDisplays(), 2898 + cursorPoint: { 2899 + x: bounds.x + Math.round(bounds.width / 2), 2900 + y: bounds.y + Math.round(bounds.height / 2), 2901 + }, 2887 2902 }); 2888 - const wa = display.workArea; 2889 - const x = wa.x + Math.round((wa.width - bounds.width) / 2); 2890 - const y = wa.y + Math.round((wa.height - bounds.height) / 2); 2891 - win.setBounds({ x, y, width: bounds.width, height: bounds.height }); 2903 + if (result.kind === 'reposition') { 2904 + win.setBounds(result.bounds); 2905 + } 2892 2906 return { success: true }; 2893 2907 } catch (err) { 2894 2908 const message = err instanceof Error ? err.message : String(err); ··· 2913 2927 try { 2914 2928 const windows = BrowserWindow.getAllWindows(); 2915 2929 let centered = 0; 2930 + // Snapshot displays once outside the loop — they don't change between 2931 + // iterations and `screen.getAllDisplays()` is not free. 2932 + const displays = screen.getAllDisplays(); 2916 2933 for (const win of windows) { 2917 2934 if (win.isDestroyed() || !win.isVisible()) continue; 2918 2935 const bounds = win.getBounds(); 2919 - const display = screen.getDisplayNearestPoint({ 2920 - x: bounds.x + Math.round(bounds.width / 2), 2921 - y: bounds.y + Math.round(bounds.height / 2), 2936 + // Same synthetic-cursor trick as `tile:window:center` so each window 2937 + // centers on its OWN current display rather than the user's cursor. 2938 + const result = computePlacement({ 2939 + placement: { mode: 'centered' }, 2940 + currentBounds: bounds, 2941 + windowSize: { width: bounds.width, height: bounds.height }, 2942 + displays, 2943 + cursorPoint: { 2944 + x: bounds.x + Math.round(bounds.width / 2), 2945 + y: bounds.y + Math.round(bounds.height / 2), 2946 + }, 2922 2947 }); 2923 - const wa = display.workArea; 2924 - const x = wa.x + Math.round((wa.width - bounds.width) / 2); 2925 - const y = wa.y + Math.round((wa.height - bounds.height) / 2); 2926 - win.setBounds({ x, y, width: bounds.width, height: bounds.height }); 2948 + if (result.kind === 'reposition') { 2949 + win.setBounds(result.bounds); 2950 + } 2927 2951 centered++; 2928 2952 } 2929 2953 return { success: true, centered };