@@ -68,7 +68,9 @@ var LibraryGLFW = {
6868 this . windowRefreshFunc = null ; // GLFWwindowrefreshfun
6969 this . windowFocusFunc = null ; // GLFWwindowfocusfun
7070 this . windowIconifyFunc = null ; // GLFWwindowiconifyfun
71+ this . windowMaximizeFunc = null ; // GLFWwindowmaximizefun
7172 this . framebufferSizeFunc = null ; // GLFWframebuffersizefun
73+ this . windowContentScaleFunc = null ; // GLFWwindowcontentscalefun
7274 this . mouseButtonFunc = null ; // GLFWmousebuttonfun
7375 this . cursorPosFunc = null ; // GLFWcursorposfun
7476 this . cursorEnterFunc = null ; // GLFWcursorenterfun
@@ -95,6 +97,7 @@ var LibraryGLFW = {
9597 errorFunc : null , // GLFWerrorfun
9698 monitorFunc : null , // GLFWmonitorfun
9799 active : null , // active window
100+ scale : null ,
98101 windows : null ,
99102 monitors : null ,
100103 monitorString : null ,
@@ -108,6 +111,8 @@ var LibraryGLFW = {
108111 0x00020003 :1 , // GLFW_RESIZABLE
109112 0x00020004 :1 , // GLFW_VISIBLE
110113 0x00020005 :1 , // GLFW_DECORATED
114+ 0x0002000A :0 , // GLFW_TRANSPARENT_FRAMEBUFFER
115+ 0x0002200C :0 , // GLFW_SCALE_TO_MONITOR. can we emulate this?
111116
112117 0x00021001 :8 , // GLFW_RED_BITS
113118 0x00021002 :8 , // GLFW_GREEN_BITS
@@ -350,6 +355,7 @@ var LibraryGLFW = {
350355 if ( win . keys [ 341 ] ) mod |= 0x0002 ; // GLFW_MOD_CONTROL
351356 if ( win . keys [ 342 ] ) mod |= 0x0004 ; // GLFW_MOD_ALT
352357 if ( win . keys [ 343 ] ) mod |= 0x0008 ; // GLFW_MOD_SUPER
358+ // add caps and num lock keys? only if lock_key_mod is set
353359 return mod ;
354360 } ,
355361
@@ -609,6 +615,15 @@ var LibraryGLFW = {
609615#endif
610616 } ,
611617
618+ onWindowContentScaleChanged : function ( scale ) {
619+ GLFW . scale = scale ;
620+ if ( ! GLFW . active ) return ;
621+
622+ #if USE_GLFW == 3
623+ { { { makeDynCall ( 'viff' , 'GLFW.active.windowContentScaleFunc' ) } } } ( GLFW . active . id , GLFW . scale , GLFW . scale ) ;
624+ #endif
625+ } ,
626+
612627 getTime : function ( ) {
613628 return _emscripten_get_now ( ) / 1000 ;
614629 } ,
@@ -873,6 +888,14 @@ var LibraryGLFW = {
873888 out ( "glfwSetInputMode called with GLFW_STICKY_MOUSE_BUTTONS mode not implemented." ) ;
874889 break ;
875890 }
891+ case 0x00033004 : { // GLFW_LOCK_KEY_MODS
892+ out ( "glfwSetInputMode called with GLFW_LOCK_KEY_MODS mode not implemented." ) ;
893+ break ;
894+ }
895+ case 0x000330005 : { // GLFW_RAW_MOUSE_MOTION
896+ out ( "glfwSetInputMode called with GLFW_RAW_MOUSE_MOTION mode not implemented." ) ;
897+ break ;
898+ }
876899 default : {
877900 out ( "glfwSetInputMode called with unknown mode parameter value: " + mode + "." ) ;
878901 break ;
@@ -1098,6 +1121,7 @@ var LibraryGLFW = {
10981121/*******************************************************************************
10991122 * GLFW FUNCTIONS
11001123 ******************************************************************************/
1124+ glfwInit__deps : [ 'emscripten_get_device_pixel_ratio' ] ,
11011125 glfwInit__sig : 'i' ,
11021126 glfwInit : function ( ) {
11031127 if ( GLFW . windows ) return 1 ; // GL_TRUE
@@ -1106,13 +1130,22 @@ var LibraryGLFW = {
11061130 GLFW . hints = GLFW . defaultHints ;
11071131 GLFW . windows = new Array ( )
11081132 GLFW . active = null ;
1133+ GLFW . scale = _emscripten_get_device_pixel_ratio ( ) ;
1134+
11091135
11101136 window . addEventListener ( "gamepadconnected" , GLFW . onGamepadConnected , true ) ;
11111137 window . addEventListener ( "gamepaddisconnected" , GLFW . onGamepadDisconnected , true ) ;
11121138 window . addEventListener ( "keydown" , GLFW . onKeydown , true ) ;
11131139 window . addEventListener ( "keypress" , GLFW . onKeyPress , true ) ;
11141140 window . addEventListener ( "keyup" , GLFW . onKeyup , true ) ;
11151141 window . addEventListener ( "blur" , GLFW . onBlur , true ) ;
1142+ // from https://stackoverflow.com/a/70514686/7484780 . maybe add this to browser.js?
1143+ // no idea how to remove this listener.
1144+ ( function updatePixelRatio ( ) {
1145+ window . matchMedia ( "(resolution: " + window . devicePixelRatio + "dppx)" )
1146+ . addEventListener ( 'change' , updatePixelRatio , { once : true } ) ;
1147+ GLFW . onWindowContentScaleChanged ( _emscripten_get_device_pixel_ratio ( ) ) ;
1148+ } ) ( ) ;
11161149 Module [ "canvas" ] . addEventListener ( "touchmove" , GLFW . onMousemove , true ) ;
11171150 Module [ "canvas" ] . addEventListener ( "touchstart" , GLFW . onMouseButtonDown , true ) ;
11181151 Module [ "canvas" ] . addEventListener ( "touchcancel" , GLFW . onMouseButtonUp , true ) ;
@@ -1257,6 +1290,15 @@ var LibraryGLFW = {
12571290 { { { makeSetValue ( 'y' , '0' , '0' , 'i32' ) } } } ;
12581291 } ,
12591292
1293+ glfwGetMonitorWorkarea__sig : 'viiiii' ,
1294+ glfwGetMonitorWorkarea : function ( monitor , x , y , w , h ) {
1295+ { { { makeSetValue ( 'x' , '0' , '0' , 'i32' ) } } } ;
1296+ { { { makeSetValue ( 'y' , '0' , '0' , 'i32' ) } } } ;
1297+
1298+ { { { makeSetValue ( 'w' , '0' , 'screen.availWidth' , 'i32' ) } } } ;
1299+ { { { makeSetValue ( 'h' , '0' , 'screen.availHeight' , 'i32' ) } } } ;
1300+ } ,
1301+
12601302 glfwGetMonitorPhysicalSize__sig : 'viii' ,
12611303 glfwGetMonitorPhysicalSize : function ( monitor , width , height ) {
12621304 // AFAIK there is no way to do this in javascript
@@ -1267,6 +1309,12 @@ var LibraryGLFW = {
12671309 { { { makeSetValue ( 'height' , '0' , '0' , 'i32' ) } } } ;
12681310 } ,
12691311
1312+ glfwGetMonitorContentScale__sig : 'viii' ,
1313+ glfwGetMonitorContentScale : function ( monitor , x , y ) {
1314+ { { { makeSetValue ( 'x' , '0' , 'GLFW.scale' , 'float' ) } } } ;
1315+ { { { makeSetValue ( 'y' , '0' , 'GLFW.scale' , 'float' ) } } } ;
1316+ } ,
1317+
12701318 glfwGetMonitorName__sig : 'ii' ,
12711319 glfwGetMonitorName : function ( mon ) {
12721320 if ( ! GLFW . monitorString ) {
@@ -1317,6 +1365,13 @@ var LibraryGLFW = {
13171365 GLFW . hints [ target ] = hint ;
13181366 } ,
13191367
1368+ glfwWindowHintString__sig : 'vii' ,
1369+ glfwWindowHintString : function ( hint , value ) {
1370+ // from glfw docs -> we just ignore this.
1371+ // Some hints are platform specific. These may be set on any platform but they
1372+ // will only affect their specific platform. Other platforms will ignore them.
1373+ } ,
1374+
13201375 glfwCreateWindow__sig : 'iiiiii' ,
13211376 glfwCreateWindow : function ( width , height , title , monitor , share ) {
13221377 return GLFW . createWindow ( width , height , title , monitor , share ) ;
@@ -1386,6 +1441,24 @@ var LibraryGLFW = {
13861441 }
13871442 } ,
13881443
1444+ glfwGetWindowContentScale__sig : 'viii' ,
1445+ glfwGetWindowContentScale : function ( winid , x , y ) {
1446+ // winid doesn't matter. all windows will use same scale anyway.
1447+ // hope i used this makeSetValue correctly
1448+ { { { makeSetValue ( 'x' , '0' , 'GLFW.scale' , 'float' ) } } } ;
1449+ { { { makeSetValue ( 'y' , '0' , 'GLFW.scale' , 'float' ) } } } ;
1450+ } ,
1451+
1452+ glfwGetWindowOpacity__sig : 'fi' ,
1453+ glfwGetWindowOpacity : function ( winid ) {
1454+ return 1.0 ;
1455+ } ,
1456+
1457+ glfwSetWindowOpacity__sig : 'vif' ,
1458+ glfwSetWindowOpacity : function ( winid , opacity ) {
1459+ // error
1460+ } ,
1461+
13891462 glfwIconifyWindow__sig : 'vi' ,
13901463 glfwIconifyWindow : function ( winid ) {
13911464#if ASSERTIONS
@@ -1420,6 +1493,13 @@ var LibraryGLFW = {
14201493 return win . attributes [ attrib ] ;
14211494 } ,
14221495
1496+ glfwSetWindowAttrib__sig : 'viii' ,
1497+ glfwSetWindowAttrib : function ( winid , attrib , value ) {
1498+ var win = GLFW . WindowFromId ( winid ) ;
1499+ if ( ! win ) return ;
1500+ win . attributes [ attrib ] = value ;
1501+ } ,
1502+
14231503 glfwSetWindowUserPointer__sig : 'vii' ,
14241504 glfwSetWindowUserPointer : function ( winid , ptr ) {
14251505 var win = GLFW . WindowFromId ( winid ) ;
@@ -1476,6 +1556,15 @@ var LibraryGLFW = {
14761556 return prevcbfun ;
14771557 } ,
14781558
1559+ glfwSetWindowMaximizeCallback__sig : 'iii' ,
1560+ glfwSetWindowMaximizeCallback : function ( winid , cbfun ) {
1561+ var win = GLFW . WindowFromId ( winid ) ;
1562+ if ( ! win ) return null ;
1563+ var prevcbfun = win . windowMaximizeFunc ;
1564+ win . windowMaximizeFunc = cbfun ;
1565+ return prevcbfun ;
1566+ } ,
1567+
14791568 glfwSetWindowIcon__sig : 'viii' ,
14801569 glfwSetWindowIcon : function ( winid , count , images ) { } ,
14811570
@@ -1494,6 +1583,9 @@ var LibraryGLFW = {
14941583 glfwFocusWindow__sig : 'vi' ,
14951584 glfwFocusWindow : function ( winid ) { } ,
14961585
1586+ glfwRequestWindowAttention__sig : 'vi' ,
1587+ glfwRequestWindowAttention : function ( winid ) { } , // maybe do window.focus()?
1588+
14971589 glfwSetWindowMonitor__sig : 'viiiiiii' ,
14981590 glfwSetWindowMonitor : function ( winid , monitor , xpos , ypos , width , height , refreshRate ) { throw "glfwSetWindowMonitor not implemented." ; } ,
14991591
@@ -1518,6 +1610,15 @@ var LibraryGLFW = {
15181610 return prevcbfun ;
15191611 } ,
15201612
1613+ glfwSetWindowContentScaleCallback_sig : 'iii' ,
1614+ glfwSetWindowContentScaleCallback : function ( winid , cbfun ) {
1615+ var win = GLFW . WindowFromId ( winid ) ;
1616+ if ( ! win ) return null ;
1617+ var prevcbfun = win . windowContentScaleFunc ;
1618+ win . windowContentScaleFunc = cbfun ;
1619+ return prevcbfun ;
1620+ } ,
1621+
15211622 glfwGetInputMode__sig : 'iii' ,
15221623 glfwGetInputMode : function ( winid , mode ) {
15231624 var win = GLFW . WindowFromId ( winid ) ;
@@ -1541,6 +1642,11 @@ var LibraryGLFW = {
15411642 GLFW . setInputMode ( winid , mode , value ) ;
15421643 } ,
15431644
1645+ glfwRawMouseMotionSupported__sig : 'i' ,
1646+ glfwRawMouseMotionSupported : function ( ) {
1647+ return 0 ;
1648+ } ,
1649+
15441650 glfwGetKey__sig : 'iii' ,
15451651 glfwGetKey : function ( winid , key ) {
15461652 return GLFW . getKey ( winid , key ) ;
@@ -1549,6 +1655,9 @@ var LibraryGLFW = {
15491655 glfwGetKeyName__sig : 'iii' ,
15501656 glfwGetKeyName : function ( key , scancode ) { throw "glfwGetKeyName not implemented." ; } ,
15511657
1658+ glfwGetKeyScancode__sig : 'ii' ,
1659+ glfwGetKeyScancode : function ( key ) { throw "glfwGetKeyScancode not implemented." ; } ,
1660+
15521661 glfwGetMouseButton__sig : 'iii' ,
15531662 glfwGetMouseButton : function ( winid , button ) {
15541663 return GLFW . getMouseButton ( winid , button ) ;
@@ -1665,6 +1774,11 @@ var LibraryGLFW = {
16651774 return state . buttons ;
16661775 } ,
16671776
1777+ glfwGetJoystickHats__sig : 'iii' ,
1778+ glfwGetJoystickHats : function ( joy , count ) {
1779+ throw "glfwGetJoystickHats is not implemented" ;
1780+ } ,
1781+
16681782 glfwGetJoystickName__sig : 'ii' ,
16691783 glfwGetJoystickName : function ( joy ) {
16701784 if ( GLFW . joys [ joy ] ) {
@@ -1673,6 +1787,26 @@ var LibraryGLFW = {
16731787 return 0 ;
16741788 } ,
16751789
1790+ glfwGetJoystickGUID__sig : 'ii' ,
1791+ glfwGetJoystickGUID : function ( jid ) {
1792+ throw "glfwGetJoystickGUID not implemented" ;
1793+ } ,
1794+
1795+ glfwSetJoystickUserPointer__sig : 'vii' ,
1796+ glfwSetJoystickUserPointer : function ( jid , ptr ) {
1797+ throw "glfwSetJoystickUserPointer not implemented" ;
1798+ } ,
1799+
1800+ glfwGetJoystickUserPointer__sig : 'ii' ,
1801+ glfwGetJoystickUserPointer : function ( jid ) {
1802+ throw "glfwSetJoystickUserPointer not implemented" ;
1803+ } ,
1804+
1805+ glfwJoystickIsGamepad__sig : 'ii' ,
1806+ glfwJoystickIsGamepad : function ( jid ) {
1807+ throw "glfwSetJoystickUserPointer not implemented" ;
1808+ } ,
1809+
16761810 glfwSetJoystickCallback__sig : 'ii' ,
16771811 glfwSetJoystickCallback : function ( cbfun ) {
16781812 GLFW . setJoystickCallback ( cbfun ) ;
0 commit comments