@@ -1112,7 +1112,15 @@ var LibraryGLFW = {
11121112
11131113 // Get non alive id
11141114 const canvas = Module [ 'canvas' ] ;
1115- var win = new GLFW_Window ( id , canvas . clientWidth , canvas . clientHeight , canvas . width , canvas . height , title , monitor , share ) ;
1115+
1116+ var clientWidth = canvas . clientWidth ;
1117+ var clientHeight = canvas . clientHeight ;
1118+ if ( GLFW . isCSSScalingEnabled ( ) ) {
1119+ clientWidth = width ;
1120+ clientHeight = height ;
1121+ }
1122+
1123+ var win = new GLFW_Window ( id , clientWidth , clientHeight , canvas . width , canvas . height , title , monitor , share ) ;
11161124
11171125 // Set window to array
11181126 if ( id - 1 == GLFW . windows . length ) {
@@ -1266,6 +1274,11 @@ var LibraryGLFW = {
12661274 var cw = Module [ "canvas" ] . clientWidth ;
12671275 var ch = Module [ "canvas" ] . clientHeight ;
12681276
1277+ if ( GLFW . isCSSScalingEnabled ( ) ) {
1278+ cw = GLFW . active . width ;
1279+ ch = GLFW . active . height ;
1280+ }
1281+
12691282 // Neither .scrollX or .pageXOffset are defined in a spec, but
12701283 // we prefer .scrollX because it is currently in a spec draft.
12711284 // (see: http://www.w3.org/TR/2013/WD-cssom-view-20131217/)
@@ -1308,9 +1321,24 @@ var LibraryGLFW = {
13081321 return false ;
13091322 } ,
13101323
1324+ /**
1325+ * CSS Scaling is a feature that is NOT part of the GLFW API, but for historical reasons, it is available
1326+ * in Emscripten.
1327+ * It is enabled by default but can be disabled by setting Module['EMSCRIPTEN_GLFW_DISABLE_CSS_SCALING'] to true.
1328+ * It is automatically disabled when using Hi DPI (the library overrides CSS sizes). */
1329+ isCSSScalingEnabled ( ) {
1330+ return Module [ 'EMSCRIPTEN_GLFW_DISABLE_CSS_SCALING' ] !== true && ! GLFW . isHiDPIAware ( ) ;
1331+ } ,
1332+
13111333 adjustCanvasDimensions ( ) {
13121334 const canvas = Module [ 'canvas' ] ;
1313- Browser . updateCanvasDimensions ( canvas , canvas . clientWidth , canvas . clientHeight ) ;
1335+ var clientWidth = canvas . clientWidth ;
1336+ var clientHeight = canvas . clientHeight ;
1337+ if ( GLFW . isCSSScalingEnabled ( ) ) {
1338+ clientWidth = GLFW . active . width ;
1339+ clientHeight = GLFW . active . height ;
1340+ }
1341+ Browser . updateCanvasDimensions ( canvas , clientWidth , clientHeight ) ;
13141342 Browser . updateResizeListeners ( ) ;
13151343 } ,
13161344
0 commit comments