Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit b3ee9f1

Browse filesBrowse files
livecode-vulcanlivecodeian
authored andcommitted
[[ emscripten ]] Listen for device pixel ratio changes
This patch adds a listener for changes to the Window.devicePixelRatio property, triggering a redraw of open stack windows at the new scale.
1 parent b371af8 commit b3ee9f1
Copy full SHA for b3ee9f1

File tree

2 files changed

+39
-1
lines changed
Filter options

2 files changed

+39
-1
lines changed

‎engine/src/em-event.js

Copy file name to clipboardExpand all lines: engine/src/em-event.js
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ mergeInto(LibraryManager.library, {
130130
tInput.addEventListener(type, handler);
131131
});
132132

133+
// Add listener for changes to device pixel ratio
134+
var matchQuery = `(resolution: ${window.devicePixelRatio}dppx)`;
135+
window.matchMedia(matchQuery).addListener(LiveCodeEvents._handleDevicePixelRatioChanged);
136+
133137
LiveCodeEvents._initialised = true;
134138
},
135139

@@ -892,6 +896,16 @@ mergeInto(LibraryManager.library, {
892896
// UI events
893897
// ----------------------------------------------------------------
894898

899+
_handleDevicePixelRatioChanged: function() {
900+
LiveCodeAsync.delay(function() {
901+
Module.ccall('MCEmscriptenHandleDevicePixelRatioChanged',
902+
'number', /* bool */
903+
[],
904+
[])
905+
});
906+
LiveCodeAsync.resume();
907+
},
908+
895909
// prevent context menu popup on right-click
896910
_handleContextMenu: function(e) {
897911
e.preventDefault()

‎engine/src/em-resolution.cpp

Copy file name to clipboardExpand all lines: engine/src/em-resolution.cpp
+25-1Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@ for more details.
1616
You should have received a copy of the GNU General Public License
1717
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1818

19+
#include "globdefs.h"
20+
#include "filedefs.h"
21+
#include "osspec.h"
22+
#include "typedefs.h"
23+
#include "parsedef.h"
24+
#include "objdefs.h"
25+
26+
#include "globals.h"
27+
1928
#include "em-util.h"
2029

2130
#include "sysdefs.h"
2231

2332
#include "graphics.h"
2433
#include "resolution.h"
34+
#include "stacklst.h"
2535

2636
#include <emscripten.h>
2737

@@ -70,5 +80,19 @@ MCResPlatformGetUIDeviceScale()
7080
void
7181
MCResPlatformHandleScaleChange()
7282
{
73-
MCEmscriptenNotImplemented();
83+
// Global use-pixel-scaling value has been updated, so now we just need to reopen any open stack windows
84+
MCstacks->reopenallstackwindows();
85+
}
86+
87+
extern "C" MC_DLLEXPORT_DEF bool
88+
MCEmscriptenHandleDevicePixelRatioChanged()
89+
{
90+
MCGFloat t_scale = emscripten_get_device_pixel_ratio();
91+
if (t_scale != s_emscripten_device_scale)
92+
{
93+
s_emscripten_device_scale = t_scale;
94+
MCResPlatformHandleScaleChange();
95+
}
96+
97+
return true;
7498
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.