电子获得标题栏的高度/在相同的Y坐标上设置第二个窗口?

时间:2018-08-22 13:14:11

标签: node.js electron titlebar

现在,我正在用NodeJS / Electron编写一个小型应用程序。 它基本上是一张带有客户列表的地图,但是客户列表也应该能够弹出到第二个窗口中。

到目前为止,一切正常,但是我希望第二个窗口与第一个窗口的右边界对齐,并且应该在相同的高度/ y坐标上。像这样:

windows aligned

但是问题是,当我将第二个窗口的边界设置为与第一个窗口的边界相同时,它将导致第二个窗口具有偏移。偏移量恰好是标题栏的高度。

查看此处:

windows not aligned

我现在想找出大约两个星期的时间,但是我似乎找不到始终获得补偿的可靠方法。该应用程序将在Linux和Windows计算机上运行,​​因此我无法设置固定偏移量。

这是我现在使用的代码,发生偏移:

var window = new BrowserWindow({width: 1000, height:800});
var bounds = electron.screen.getPrimaryDisplay().bounds;
var wBounds = window.getBounds();
window.setBounds({ 
    x: Math.ceil(bounds.width / 2 - wBounds.width / 2),
    y: Math.ceil(bounds.height / 2 - wBounds.height / 2),
    height: wBounds.height,
    width: wBounds.width
});
wBounds = window.getBounds();
extWindow = new BrowserWindow({width: 600 , height: wBounds.height , x: wBounds.x + wBounds.width , y: wBounds.y});

//in my case window.getBounds().y -> 168, extWindow.getBounds().y -> 168

其中window是我的主窗口,extwindow是第二个窗口。 读取window.getBounds().yextWindow.getBounds().y时,它们是相同的。那么这是什么问题呢? extWindow 不是window的孩子!

有什么方法可以获取标题栏的高度或禁用新窗口偏移吗?

我正在使用:

  • 电子2.0.5
  • Electron-Builder 20.21.2
  • Linux Mint 19 Cinnamon 3.8.8

3m7ecc

0 个答案:

没有答案