Skip to content

Commit

Permalink
Merge pull request #18 from nnako/master
Browse files Browse the repository at this point in the history
allow negative x and y coordinates when placing the capture window
  • Loading branch information
mPyKen committed Apr 25, 2024
2 parents f0e4952 + eeafea4 commit 94315f3
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,32 @@ function checkWindowBounds(win) {
}

const createWindows = () => {
// Create the browser window.

//
// create and setup render window
//

const mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
backgroundThrottling: false, // continue playing <video> element https://stackoverflow.com/a/68685080
},
width: initCapRect.width,
height: initCapRect.height,
width: initRenderRect.width,
height: initRenderRect.height,
frame: false,
autoHideMenuBar: true,
resizable: false,
});

// start by setting initial window location starting at (0,0) and change it
// later, when all other settings have been applied
mainWindow.setPosition(
initRenderRect.x ?? mainWindow.getPosition()[0],
initRenderRect.y ?? mainWindow.getPosition()[1]
0,
0,
);

mainWindow.loadFile(path.join(__dirname, "render.html"));
mainWindow.on("closed", () => app.quit());
//mainWindow.setMenuBarVisibility(false)
Expand All @@ -99,7 +107,19 @@ const createWindows = () => {
mainWindow.send("window-move", mainWindow.getBounds());
mainWindow.on("moved", (event) => checkWindowBounds(mainWindow));

// capture window
// now, set the "real" location of the render window after all other
// settings have been done. hopefully, this eliminates electron's
// aversity about negative window coordinates
mainWindow.setPosition(
initRenderRect.x ?? mainWindow.getPosition()[0],
initRenderRect.y ?? mainWindow.getPosition()[1]
);


//
// create and setup capture window
//

const captureWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
Expand All @@ -112,10 +132,14 @@ const createWindows = () => {
frame: false,
opacity: freeze ? 0 : 0.6,
});

// start by setting initial window location starting at (0,0) and change it
// later, when all other settings have been applied
captureWindow.setPosition(
initCapRect.x ?? captureWindow.getPosition()[0],
initCapRect.y ?? captureWindow.getPosition()[1]
0,
0,
);

captureWindow.loadFile(path.join(__dirname, "capture.html"));
captureWindow.setContentProtection(true); // exclude from capture
captureWindow.setAlwaysOnTop(true);
Expand All @@ -124,6 +148,14 @@ const createWindows = () => {
captureWindow.setIgnoreMouseEvents(freeze);
//captureWindow.webContents.openDevTools();

// now, set the "real" location after all other settings have been done.
// hopefully, this eliminates electron's aversity about negative window
// coordinates
captureWindow.setPosition(
initCapRect.x ?? captureWindow.getPosition()[0],
initCapRect.y ?? captureWindow.getPosition()[1]
);

captureWindow.on("resized", (event) => {
checkWindowBounds(mainWindow);
checkWindowBounds(captureWindow);
Expand Down Expand Up @@ -163,6 +195,7 @@ const createWindows = () => {
}
}


async function getVideoSourceIdForDisplay(display) {
const inputSources = await desktopCapturer.getSources({
types: ["screen"],
Expand Down

0 comments on commit 94315f3

Please sign in to comment.