Skip to content

Commit

Permalink
Fix wasm fullscreen behaviour
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Jul 8, 2023
1 parent 644f065 commit ed6a093
Showing 1 changed file with 47 additions and 21 deletions.
68 changes: 47 additions & 21 deletions dgl/src/pugl-extra/wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,18 +604,27 @@ puglUiCallback(const int eventType, const EmscriptenUiEvent* const uiEvent, void
{
PuglView* const view = (PuglView*)userData;
const char* const className = view->world->className;
const bool isFullscreen = view->impl->isFullscreen;

// FIXME
const int width = EM_ASM_INT({
var canvasWrapper = document.getElementById(UTF8ToString($0)).parentElement;
canvasWrapper.style.setProperty("--device-pixel-ratio", window.devicePixelRatio);
return canvasWrapper.clientWidth;
}, className);
if ($1) {
return window.innerWidth;
} else {
return canvasWrapper.clientWidth;
}
}, className, isFullscreen);

const int height = EM_ASM_INT({
var canvasWrapper = document.getElementById(UTF8ToString($0)).parentElement;
return canvasWrapper.clientHeight;
}, className);
if ($1) {
return window.innerHeight;
} else {
var canvasWrapper = document.getElementById(UTF8ToString($0)).parentElement;
return canvasWrapper.clientHeight;
}
}, className, isFullscreen);

if (!width || !height)
return EM_FALSE;
Expand All @@ -634,43 +643,60 @@ puglUiCallback(const int eventType, const EmscriptenUiEvent* const uiEvent, void
puglDispatchEvent(view, &event);

emscripten_set_canvas_element_size(view->world->className, width * scaleFactor, height * scaleFactor);

#ifdef __MOD_DEVICES__
if (isFullscreen) {
EM_ASM({
document.getElementById("pedalboard-dashboard").style.transform = "scale(1.0)";
});
}
#endif

return EM_TRUE;
}

static EM_BOOL
puglFullscreenChangeCallback(const int eventType, const EmscriptenFullscreenChangeEvent* const fscEvent, void* const userData)
{
PuglView* const view = (PuglView*)userData;
const char* const className = view->world->className;

view->impl->isFullscreen = fscEvent->isFullscreen;

double scaleFactor = emscripten_get_device_pixel_ratio();
#ifdef __MOD_DEVICES__
scaleFactor *= MOD_SCALE_FACTOR_MULT;
#endif

view->world->impl->scaleFactor = scaleFactor;

if (fscEvent->isFullscreen) {
PuglEvent event = {{PUGL_CONFIGURE, 0}};
event.configure.x = 0;
event.configure.y = 0;
event.configure.width = fscEvent->elementWidth * scaleFactor;
event.configure.height = fscEvent->elementHeight * scaleFactor;
puglDispatchEvent(view, &event);
if (!fscEvent->isFullscreen)
return puglUiCallback(0, NULL, userData);

emscripten_set_canvas_element_size(view->world->className,
fscEvent->elementWidth * scaleFactor,
fscEvent->elementHeight * scaleFactor);
const int width = EM_ASM_INT({
return window.innerWidth;
});

const int height = EM_ASM_INT({
return window.innerHeight;
});

PuglEvent event = {{PUGL_CONFIGURE, 0}};
event.configure.x = 0;
event.configure.y = 0;
event.configure.width = width;
event.configure.height = height;
puglDispatchEvent(view, &event);

emscripten_set_canvas_element_size(view->world->className, width, height);

#ifdef __MOD_DEVICES__
EM_ASM({
document.getElementById("pedalboard-dashboard").style.transform = "scale(1.0)";
});
EM_ASM({
document.getElementById("pedalboard-dashboard").style.transform = "scale(1.0)";
});
#endif
return EM_TRUE;
}

return puglUiCallback(0, NULL, userData);
return EM_TRUE;
}

static EM_BOOL
Expand Down

0 comments on commit ed6a093

Please sign in to comment.