5

Given that the external and primary monitor always has the same resolution, is it possible to have two programs say VLC and a browser open in their separate designated screens?

It is worth mentioning that the external monitor and internal monitor will have to be power cycled, sometimes remaining off for a long period. When they come back they need to remain at their respective monitor, whereas currently they will typically all be moved into the remaining active monitor.

Bonus: Is this possible to achieve by using a desktop environment like Unity from Ubuntu 16.04? It's okay for me to create a custom session as long as the software remains in its given location.

Syncretic
  • 55
  • 3

1 Answers1

2

For standard vanilla Ubuntu using Unity: CCSM: CompizConfig Settings Manager to the rescue:

sudo apt install compizconfig-settings-manager
  • Start CCSM
  • Go to Window Management CCSM Main Window Management
  • Then Place Windows, Tab Fixed Window Placement Fixed Window Placement
  • both monitors are one large screen estate, so calculate the XY coordinate you want each window at:
    • E.g. if you have 2 standard VGA monitors of 640x480, the second monitor starts at X=641, Y=1 if you have no Unity Launcher on the second monitor, otherwise X=641+42 (the width of the launcher)
  • under the list item Windows with fixed positions, pres New
  • Grab the window name or type it together with the X and Y coordinate for each and every application you wish to position.
  • Voilà: Done

For OP's specific use-case they made this work automatically by detecting added displays using the electron screen API.

Important: In app.on('ready'), a state that is needed for the screen API to work, issue the following statements:

const electron = require('electron');
electron.screen.on('display-added', (e,d) => { _reposition(); }

async function _reposition() { 
      const util = require('util'); 
      const exec = util.promisify(require('child_process').exec);
       const { stdout, stderr } = await setTimeout(() => { exec('compiz --replace') }, 5000); 
       console.log(stdout); console.log(stderr); 
}
}
Fabby
  • 5,836
  • 2
  • 22
  • 38
  • Awesome and so simple when you're already in the unity environment. Will this persist when the external monitor is disabled as if someone unplugged the HDMI and plugged it back in? – Syncretic Jan 08 '19 at 22:39
  • I never tried as I've given up on multiple monitors and am using multiple viewports, except to hook up the laptop to the TV, but not around that right now. (Not home). – Fabby Jan 08 '19 at 23:21
  • 1
    Worked until the monitor disconnected. Solved it with a script that listens for added displays executing a compiz --replace command. Works really good for my use case :) – Syncretic Jan 10 '19 at 15:02
  • 1
    @Syncretic Please [edit] my answer to add your script and add in the comment: "Editing as per answerer's request" just in case some other reviewer gets to it before I do. That way It'll help the next guy stumbling over cables all the time **;-) :D** – Fabby Jan 10 '19 at 23:48