Skip to content

Commit

Permalink
Show indicator when no face is found
Browse files Browse the repository at this point in the history
Partially addresses #26
Also working towards #41
and #49
  • Loading branch information
1j01 committed May 9, 2024
1 parent 13d26d6 commit 5659495
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 5 deletions.
8 changes: 7 additions & 1 deletion core/tracky-mouse.css
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@
transform: translate(-50%, -50%);
}

/* prefer manual takeback indicator, rather than showing both at once */
body.tracky-mouse-manual-takeback .tracky-mouse-head-not-found-indicator,
body:not(.tracky-mouse-head-not-found) .tracky-mouse-head-not-found-indicator {
display: none;
}

body:not(.tracky-mouse-manual-takeback) .tracky-mouse-manual-takeback-indicator {
display: none;
}
Expand All @@ -254,7 +260,7 @@ body:not(.tracky-mouse-manual-takeback) .tracky-mouse-manual-takeback-indicator
display: none;
}

.tracky-mouse-manual-takeback-indicator img {
.tracky-mouse-screen-overlay-status-indicator img {
filter: drop-shadow(0 0 4px #000) drop-shadow(2px 2px 2px #000);
opacity: 0.5;
}
Expand Down
4 changes: 4 additions & 0 deletions core/tracky-mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,10 @@ TrackyMouse.init = function (div) {
mainOops.update(imageData);
}

if (window.electronAPI) {
window.electronAPI.notifyCameraFeedDiagnostics({ headNotFound: !face && !facemeshPrediction });
}

if (facemeshPrediction) {
ctx.fillStyle = "red";

Expand Down
135 changes: 135 additions & 0 deletions desktop-app/images/head-not-found.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion desktop-app/src/electron-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,13 @@ const createWindow = () => {
const regainControlForTime = 2000; // in milliseconds, AFTER the mouse hasn't moved for more than mouseMoveRequestHistoryDuration milliseconds (I think)
let regainControlTimeout = null; // also used to check if we're pausing temporarily
let enabled = true; // for starting/stopping until the user requests otherwise
let cameraFeedDiagnostics = {};
const updateDwellClicking = () => {
screenOverlayWindow.webContents.send(
'change-dwell-clicking',
enabled && regainControlTimeout === null,
enabled && regainControlTimeout !== null
enabled && regainControlTimeout !== null,
cameraFeedDiagnostics,
);
};
ipcMain.on('move-mouse', async (_event, x, y, time) => {
Expand Down Expand Up @@ -306,6 +308,11 @@ const createWindow = () => {
mousePosHistory.push({ point: { x: initialPos.x, y: initialPos.y }, time: performance.now(), from: "notify-toggle-state" });
}
});
ipcMain.on('notify-camera-feed-diagnostics', (_event, data) => {
cameraFeedDiagnostics = data;
updateDwellClicking();
});


ipcMain.on('set-options', (_event, newOptions) => {
deserializeSettings(newOptions);
Expand Down
9 changes: 7 additions & 2 deletions desktop-app/src/electron-screen-overlay.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
</head>

<body>
<div class="tracky-mouse-absolute-center tracky-mouse-manual-takeback-indicator">
<img src="../images/manual-takeback.svg" alt="hand reaching for mouse" width="128" height="128">
<div class="tracky-mouse-absolute-center">
<div class="tracky-mouse-screen-overlay-status-indicator tracky-mouse-manual-takeback-indicator">
<img src="../images/manual-takeback.svg" alt="hand reaching for mouse" width="128" height="128">
</div>
<div class="tracky-mouse-screen-overlay-status-indicator tracky-mouse-head-not-found-indicator">
<img src="../images/head-not-found.svg" alt="head not found" width="128" height="128">
</div>
</div>
<div id="tracky-mouse-screen-overlay-message">
<div class="tracky-mouse-manual-takeback-indicator">
Expand Down
4 changes: 4 additions & 0 deletions desktop-app/src/preload-app-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ contextBridge.exposeInMainWorld("electronAPI", {
ipcRenderer.send('notify-toggle-state', nowEnabled);
},

notifyCameraFeedDiagnostics: (data) => {
ipcRenderer.send('notify-camera-feed-diagnostics', data);
},

setOptions: (optionsPatch) => {
ipcRenderer.send('set-options', optionsPatch);
},
Expand Down
10 changes: 9 additions & 1 deletion desktop-app/src/screen-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ electronAPI.onMouseMove((_event, x, y) => {
window.dispatchEvent(domEvent);
});

electronAPI.onChangeDwellClicking((_event, isEnabled, isManualTakeback) => {
electronAPI.onChangeDwellClicking((_event, isEnabled, isManualTakeback, cameraFeedDiagnostics) => {
// console.log("onChangeDwellClicking", isEnabled);

// Other diagnostics in the future would be stuff like:
// - head too far away (smaller than a certain size) https://github.com/1j01/tracky-mouse/issues/49
// - bad lighting conditions
// see: https://github.com/1j01/tracky-mouse/issues/26

document.body.classList.toggle("tracky-mouse-manual-takeback", isManualTakeback);
document.body.classList.toggle("tracky-mouse-head-not-found", cameraFeedDiagnostics.headNotFound);
actionSpan.innerText = isEnabled ? "disable" : "enable";

if (!isEnabled && !isManualTakeback) {
// Fade out the message after a little while so it doesn't get in the way.
// TODO: make sure animation isn't interrupted by cameraFeedDiagnostics updates.
message.style.animation = "tracky-mouse-screen-overlay-message-fade-out 2s ease-in-out forwards 10s";
} else {
message.style.animation = "";
Expand Down

0 comments on commit 5659495

Please sign in to comment.