mirror of
https://github.com/tomru/switchmon.git
synced 2026-03-04 15:07:26 +01:00
fix selecting a single device
This commit is contained in:
11
swm.js
11
swm.js
@@ -15,13 +15,12 @@ function getDevices() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateXrandrOptions(monitorList, devices) {
|
function generateXrandrOptions(explicitlySelectedMonitors, devices) {
|
||||||
let xrandrOptions = '';
|
let xrandrOptions = '';
|
||||||
let deviceOrder = Object.keys(devices).sort();
|
let deviceOrder = Object.keys(devices).sort();
|
||||||
|
|
||||||
// remove explicitly selected monitors inside the array and add them to the
|
// fix the sort order if monitors were explicitly selected
|
||||||
// beginning in the order they have been specified.
|
explicitlySelectedMonitors.reverse().forEach((monitor) => {
|
||||||
monitorList.reverse().forEach((monitor) => {
|
|
||||||
const index = deviceOrder.indexOf(monitor);
|
const index = deviceOrder.indexOf(monitor);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
console.error('Unkown monitor', monitor, '(ignored)');
|
console.error('Unkown monitor', monitor, '(ignored)');
|
||||||
@@ -35,7 +34,9 @@ function generateXrandrOptions(monitorList, devices) {
|
|||||||
deviceOrder.forEach(deviceKey => {
|
deviceOrder.forEach(deviceKey => {
|
||||||
const device = devices[deviceKey];
|
const device = devices[deviceKey];
|
||||||
|
|
||||||
const deviceStatus = device.connected ? '--auto' : '--off';
|
const activateDevice = device.connected && (!explicitlySelectedMonitors.length || explicitlySelectedMonitors.indexOf(deviceKey) > -1 );
|
||||||
|
|
||||||
|
const deviceStatus = activateDevice ? '--auto' : '--off';
|
||||||
const monitorOptions = ['', '--output', deviceKey, deviceStatus];
|
const monitorOptions = ['', '--output', deviceKey, deviceStatus];
|
||||||
|
|
||||||
if (device.connected) {
|
if (device.connected) {
|
||||||
|
|||||||
Reference in New Issue
Block a user