Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 49795e1

Browse files
feat(#39): in fullscreen mode, hide mouse cursor after 4 seconds and displays it if moved
1 parent d180a7f commit 49795e1

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

src/components/deck/deckdeckgo-deck/deckdeckgo-deck.tsx

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export class DeckdeckgoDeck {
4141
@Event() slideDrag: EventEmitter<number>;
4242
@Event() slideWillChange: EventEmitter<number>;
4343

44+
private fullscreen: boolean = false;
45+
private cursorHidden: boolean = false;
46+
private idleMouseTimer: number;
47+
4448
async componentDidLoad() {
4549
this.initWindowResize();
4650
this.initKeyboardAssist();
@@ -121,6 +125,7 @@ export class DeckdeckgoDeck {
121125
}
122126

123127
private async move(e: Event) {
128+
await this.clearMouseCursorTimer(true);
124129

125130
if (this.blockSlide) {
126131
return;
@@ -465,7 +470,7 @@ export class DeckdeckgoDeck {
465470

466471
@Method()
467472
toggleFullScreen(): Promise<void> {
468-
return new Promise<void>((resolve) => {
473+
return new Promise<void>(async (resolve) => {
469474
const doc = window.document;
470475
const docEl = doc.documentElement;
471476

@@ -477,14 +482,74 @@ export class DeckdeckgoDeck {
477482
// @ts-ignore
478483
if (!doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement && !doc.msFullscreenElement) {
479484
requestFullScreen.call(docEl);
485+
486+
this.fullscreen = true;
487+
this.hideMouseCursorWithDelay();
480488
} else {
481489
cancelFullScreen.call(doc);
490+
491+
await this.clearMouseCursorTimer(false);
492+
this.fullscreen = false;
482493
}
483494

484495
resolve();
485496
});
486497
}
487498

499+
private async clearMouseCursorTimer(hideWithDelay: boolean) {
500+
if (!this.fullscreen) {
501+
return;
502+
}
503+
504+
if (this.idleMouseTimer > 0) {
505+
clearTimeout(this.idleMouseTimer);
506+
}
507+
508+
await this.showHideMouseCursor(true);
509+
510+
if (hideWithDelay) {
511+
this.hideMouseCursorWithDelay();
512+
}
513+
}
514+
515+
private hideMouseCursorWithDelay() {
516+
if (!this.fullscreen) {
517+
return;
518+
}
519+
520+
this.idleMouseTimer = setTimeout(async () => {
521+
await this.showHideMouseCursor(false);
522+
}, 4000);
523+
}
524+
525+
private showHideMouseCursor(show: boolean): Promise<void> {
526+
return new Promise<void>((resolve) => {
527+
if (!this.fullscreen) {
528+
resolve();
529+
return;
530+
}
531+
532+
if (!this.cursorHidden && show) {
533+
// Cursor already displayed, we don't want to touch the style multiple times if not needed
534+
resolve();
535+
return;
536+
}
537+
538+
const slider: HTMLElement = this.el.shadowRoot.querySelector('div.deckgo-deck');
539+
540+
if (!slider) {
541+
resolve();
542+
return;
543+
}
544+
545+
slider.style.setProperty('cursor', show ? 'initial' : 'none');
546+
547+
this.cursorHidden = !show;
548+
549+
resolve();
550+
});
551+
}
552+
488553
/* END: Full screen */
489554

490555
/* BEGIN: Full screen */

0 commit comments

Comments
 (0)