detect the the title bar height for a window for different operating systems with javascript

房东的猫 提交于 2019-12-11 01:27:26

问题


I am making a canvas game in a chrome app with it's own window. I made my game resize with the window's size using window.onResize. Since my game is made with an 8-bit style, I don't want the default window size to have blurry pixels because it is partially resized.

I am aware that you can specify the window's size in the background.js file, but when the window opens, the size of the window includes the title bar.

Basically, I want the game height to be 400px, but I can only set the window height. The title bar is included in the window height, so different operating systems with different title bar heights will affect the size of the game height. I need a way to detect the height of the operating systems title bar height in background.js.


回答1:


To fully control window size of the app create a frameless window that won't have any built-in decorations, draw everything yourself.

chrome.app.runtime.onLaunched.addListener(function() {
    chrome.app.window.create("window.html", {  
         frame: "none",
         .............
    });
});

chrome.app.window API documentation provides a sample app, here's a screenshot:



来源:https://stackoverflow.com/questions/33740780/detect-the-the-title-bar-height-for-a-window-for-different-operating-systems-wit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!