Comparing version 3.1.0 to 3.1.3
@@ -32,3 +32,3 @@ 'use strict'; | ||
this._decorated = mode === 'windowed'; | ||
this._decorated = true; | ||
if (opts.decorated !== undefined) { | ||
@@ -98,2 +98,34 @@ this._decorated = opts.decorated; | ||
getCurrentMonitor() { | ||
if ( ! this._window ) { | ||
return this._primaryDisplay; | ||
} | ||
let bestoverlap = 0; | ||
let bestmonitor = null; | ||
const { x: wx, y: wy } = this.pos; | ||
const { width: ww, height: wh } = this.size; | ||
this._monitors = glfw.getMonitors(); | ||
this._monitors.forEach(monitor => { | ||
const { width: mw, height: mh } = monitor; | ||
const { pos_x: mx, pos_y: my } = monitor; | ||
let overlap = ( | ||
Math.max(0, Math.min(wx + ww, mx + mw) - Math.max(wx, mx)) * | ||
Math.max(0, Math.min(wy + wh, my + mh) - Math.max(wy, my)) | ||
); | ||
if (bestoverlap < overlap) { | ||
bestoverlap = overlap; | ||
bestmonitor = monitor; | ||
} | ||
}); | ||
return bestmonitor; | ||
} | ||
get mode() { return this._mode; } | ||
@@ -105,2 +137,5 @@ set mode(v) { | ||
} | ||
const currentMonitor = this.getCurrentMonitor(); | ||
const prevMode = this._mode; | ||
@@ -125,13 +160,13 @@ this._mode = v; | ||
const isBadId = this._display === undefined || this._display >= this._monitors.length; | ||
const dispId = isBadId ? -1 : this._display; | ||
const currentScreen = dispId > -1 ? this._monitors[dispId] : this._primaryDisplay; | ||
this._display = this._monitors.indexOf(currentMonitor); | ||
this._display = this._monitors.indexOf(currentScreen); | ||
if (this._mode === 'windowed') { | ||
this._x = this._prevX || this._x; | ||
this._y = this._prevY || this._y; | ||
this._width = this._prevWidth || this._width; | ||
this._height = this._prevHeight || this._height; | ||
this._decorated = this._prevDecorated || this._decorated; | ||
delete this._prevX; | ||
delete this._prevY; | ||
delete this._prevWidth; | ||
@@ -144,9 +179,13 @@ delete this._prevHeight; | ||
if ( | ||
this._width !== currentScreen.width || | ||
this._height !== currentScreen.height | ||
this._width !== currentMonitor.width || | ||
this._height !== currentMonitor.height | ||
) { | ||
this._prevX = this._x; | ||
this._prevY = this._y; | ||
this._prevWidth = this._width; | ||
this._prevHeight = this._height; | ||
this._width = currentScreen.width; | ||
this._height = currentScreen.height; | ||
this._x = currentMonitor.pos_x; | ||
this._y = currentMonitor.pos_y; | ||
this._width = currentMonitor.width; | ||
this._height = currentMonitor.height; | ||
} | ||
@@ -168,2 +207,16 @@ | ||
if (this._mode === 'windowed') { | ||
if (this._x && this._y) { | ||
glfw.setWindowPos(this._window, this._x, this._y); | ||
} | ||
} else if (this._mode === 'borderless') { | ||
const monitor = this._monitors[this._display]; | ||
glfw.setWindowPos(this._window, monitor.pos_x, monitor.pos_y); | ||
glfw.setWindowSize(this._window, monitor.width, monitor.height); | ||
} | ||
this.makeCurrent(); | ||
@@ -258,3 +311,3 @@ | ||
this._x = v; | ||
glfw.setWindowSize(this._window, this._x, this._y); | ||
glfw.setWindowPos(this._window, this._x, this._y); | ||
} | ||
@@ -266,3 +319,3 @@ set y(v) { | ||
this._y = v; | ||
glfw.setWindowSize(this._window, this._x, this._y); | ||
glfw.setWindowPos(this._window, this._x, this._y); | ||
} | ||
@@ -348,3 +401,8 @@ | ||
glfw.windowHint(glfw.DECORATED, this._decorated ? glfw.TRUE : glfw.FALSE); | ||
this._window = glfw.createWindow(this._width, this._height, this._emitter, this._title); | ||
this._window = glfw.createWindow( | ||
this._width, | ||
this._height, | ||
this._emitter, | ||
this._title | ||
); | ||
@@ -358,6 +416,9 @@ } else if (this._mode === 'borderless') { | ||
this._window = glfw.createWindow(this._width, this._height, this._emitter, this._title); | ||
this._window = glfw.createWindow( | ||
this._width, | ||
this._height, | ||
this._emitter, | ||
this._title | ||
); | ||
glfw.setWindowPos(this._window, 0, 0); | ||
} else if (this._mode === 'fullscreen') { | ||
@@ -368,3 +429,7 @@ | ||
this._window = glfw.createWindow( | ||
this._width, this._height, this._emitter, this._title, this._display | ||
this._width, | ||
this._height, | ||
this._emitter, | ||
this._title, | ||
this._display | ||
); | ||
@@ -371,0 +436,0 @@ |
{ | ||
"author": "Luis Blanco <luisblanco1337@gmail.com>", | ||
"name": "glfw-raub", | ||
"version": "3.1.0", | ||
"version": "3.1.3", | ||
"description": "GLFW for Node.js", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
72711
661