Skip to content

Commit 98717c0

Browse files
committed
Make it more apparent that you need to click on the screen for pointer lock
1 parent b0104f1 commit 98717c0

2 files changed

Lines changed: 47 additions & 20 deletions

File tree

‎src/Mac.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ body.embed {
3838
border-radius: 10px;
3939
}
4040

41-
.Mac-Loading-Slow {
41+
.Mac-Loading-OneLine {
4242
white-space: nowrap;
4343
display: block;
4444
}

‎src/Mac.tsx‎

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -633,15 +633,16 @@ export default function Mac({
633633
);
634634
}
635635

636-
const {showMacOSXSlowNotification, clearMacOSXSlowNotification} =
637-
useMacOSXSlowNotification(
636+
const [showMacOSXSlowNotification, clearMacOSXSlowNotification] =
637+
useTemporaryNotification(
638638
!progress &&
639639
emulatorLoaded &&
640-
disks[0]?.infiniteHdSubset === "macosx"
640+
disks[0]?.infiniteHdSubset === "macosx",
641+
"mac-os-x-slow-notification-count"
641642
);
642643
if (showMacOSXSlowNotification) {
643644
progress = (
644-
<div className="Mac-Loading Mac-Loading-Non-Modal Mac-Loading-Slow">
645+
<div className="Mac-Loading Mac-Loading-Non-Modal Mac-Loading-OneLine">
645646
<span
646647
className="Mac-Loading-Dismiss"
647648
onClick={clearMacOSXSlowNotification}>
@@ -653,6 +654,39 @@ export default function Mac({
653654
);
654655
}
655656

657+
const [mouseHasMoved, setMouseHasMoved] = useState(false);
658+
const [showPointerLockNotification, clearPointerLockNotification] =
659+
useTemporaryNotification(
660+
!progress &&
661+
emulatorLoaded &&
662+
mouseHasMoved &&
663+
emulatorNeedsMouseDeltas(emulatorType) &&
664+
!USING_TOUCH_INPUT,
665+
"pointer-lock-notification-count"
666+
);
667+
if (showPointerLockNotification) {
668+
progress = (
669+
<div className="Mac-Loading Mac-Loading-Non-Modal Mac-Loading-OneLine">
670+
<span
671+
className="Mac-Loading-Dismiss"
672+
onClick={clearPointerLockNotification}>
673+
ⓧ
674+
</span>
675+
Click the screen to lock the mouse for full control.
676+
</div>
677+
);
678+
}
679+
const handlePointerMove = useCallback(() => {
680+
if (!mouseHasMoved) {
681+
setMouseHasMoved(true);
682+
}
683+
}, [mouseHasMoved]);
684+
const handlePointerDown = useCallback(() => {
685+
if (showPointerLockNotification) {
686+
clearPointerLockNotification();
687+
}
688+
}, [clearPointerLockNotification, showPointerLockNotification]);
689+
656690
function handleDragStart(event: React.DragEvent) {
657691
// Don't allow the screen to be dragged off when using a touchpad on
658692
// the iPad.
@@ -862,6 +896,8 @@ export default function Mac({
862896
width={screenWidth}
863897
height={screenHeight}
864898
onContextMenu={e => e.preventDefault()}
899+
onPointerMove={handlePointerMove}
900+
onPointerDown={handlePointerDown}
865901
/>
866902
{USING_TOUCH_INPUT && (
867903
<input
@@ -1171,27 +1207,18 @@ function MacError({text, onDone}: {text: string; onDone: () => void}) {
11711207
);
11721208
}
11731209

1174-
function useMacOSXSlowNotification(emulatorReady: boolean) {
1175-
const [count, setCount] = usePersistentState(
1176-
10,
1177-
"mac-os-x-slow-notification-count"
1178-
);
1210+
function useTemporaryNotification(canShow: boolean, key: string) {
1211+
const [count, setCount] = usePersistentState(10, key);
11791212
const [hide, setHide] = useState(false);
1180-
const shouldShow = count > 0 && emulatorReady;
1213+
const shouldShow = count > 0 && canShow;
11811214

11821215
useEffect(() => {
11831216
if (shouldShow) {
11841217
setCount(v => v - 1);
1218+
setTimeout(() => setHide(true), 10_000);
11851219
}
1186-
setTimeout(() => setHide(true), 10_000);
11871220
}, [setCount, shouldShow]);
11881221

1189-
const clearMacOSXSlowNotification = useCallback(
1190-
() => setCount(0),
1191-
[setCount]
1192-
);
1193-
return {
1194-
showMacOSXSlowNotification: shouldShow && !hide,
1195-
clearMacOSXSlowNotification,
1196-
};
1222+
const clearNotification = useCallback(() => setCount(0), [setCount]);
1223+
return [shouldShow && !hide, clearNotification] as const;
11971224
}

0 commit comments

Comments
 (0)