Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement better mouse capturing #91

Open
aggregate1166877 opened this issue Dec 10, 2022 · 0 comments
Open

Implement better mouse capturing #91

aggregate1166877 opened this issue Dec 10, 2022 · 0 comments
Labels
high-level concept pre-alpha grind Pre-alpha MVP task: tasks used as rough indication of what needs to be done to get out of pre-alpha

Comments

@aggregate1166877
Copy link
Collaborator

aggregate1166877 commented Dec 10, 2022

The current implementation uses the standard pointer API. This is problematic because pressing Escape locks the player out of being able to relock the mouse for 2 seconds (even being triggered by a manual keypress isn't good enough for the browser engine).

There is a hack solution to dealing with the problem: implement an OS-wide NW.js shortcut key which is just Escape. On blur, deactivate the shortcut so we don't wreck user experience when alt-tabbed. On focus, reactivate shortcut. This allows us to hide that Escape was pressed from the browser engine.

The 'shortcut' needs to be deactivated prior to window reload in dev mode as the application loses knowledge that it has a shortcut assigned, and then loses control of Escape overrides.

Example snippets

// Key override
const escapeOverride = new nw.Shortcut({
  key: 'Escape',
  active: () => {
    this.unlock();
    console.log(this)
  }
});
// On boot and on focus
nw.App.registerGlobalHotKey(escapeOverride);
// On blur
nw.App.registerGlobalHotKey(escapeOverride);

Task

Use above snippets to forcibly grab Escape appropriately. We should can override nw.Window.get().reload() and chrome.tabs.reload() to produce a seamless experience in the early-load polyfill bits that don't work with the usual engine lifecycles.

An additional thing we should probably try do is keep track of whether of not the app has focus so that we can check a flag at any stage. This is because the application currently forcibly uses nw.Window.get().focus to ensure initial focus, which causes the mouse to freak out on Windows in some cases.

@aggregate1166877 aggregate1166877 added pre-alpha grind Pre-alpha MVP task: tasks used as rough indication of what needs to be done to get out of pre-alpha high-level concept labels Dec 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
high-level concept pre-alpha grind Pre-alpha MVP task: tasks used as rough indication of what needs to be done to get out of pre-alpha
Projects
None yet
Development

No branches or pull requests

1 participant