1
0
Fork 0
Dieser Commit ist enthalten in:
Simon Vieille 2017-08-15 21:30:12 +02:00
Ursprung 95818fd280
Commit c040a4da02
2 geänderte Dateien mit 28 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -33,12 +33,13 @@ resolutionY=1080
```
[mode:MODE_NAME]
config[]=HUMAIN_SCREEN_NAME1,HUMAIN_SCREEN_NAME2
config[]=HUMAIN_SCREEN_NAME2,HUMAIN_SCREEN_NAME1
config[foo]=HUMAIN_SCREEN_NAME1,HUMAIN_SCREEN_NAME2
config[bar]=HUMAIN_SCREEN_NAME2,HUMAIN_SCREEN_NAME1
primary=HUMAIN_SCREEN_NAME1
[mode:MODE_NAME2]
config[]=HUMAIN_SCREEN_NAME1,HUMAIN_SCREEN_NAME3
config[]=HUMAIN_SCREEN_NAME1,HUMAIN_SCREEN_NAME3
```
Usage
@ -61,6 +62,8 @@ Then you can run:
```
$ monitordisplay -t
# OR
$ monitordisplay -tbar
```
…which equals:

Datei anzeigen

@ -99,7 +99,7 @@ function build(array $modes, array $screens, $mode, $toggle, array $currentMode,
$mode = $modes[$mode];
}
if ($toggle === true) {
if ($toggle !== false) {
if ($currentMode['mode'] === null) {
return;
}
@ -107,15 +107,28 @@ function build(array $modes, array $screens, $mode, $toggle, array $currentMode,
if ($currentMode['config'] === null) {
return;
}
$currentMode['config'] = (int) $currentMode['config'];
$configs = $mode['config'];
$configsKeys = array_keys($configs);
if (!array_key_exists($currentMode['config'], $mode['config'])) {
return;
$currentMode['config'] = $configsKeys[0];
}
$configs = $mode['config'];
$config = ($currentMode['config'] + 1) % count($configs);
if ($toggle === true) {
foreach ($configsKeys as $k => $key) {
if ($key === $currentMode['config']) {
$currentKey = $k;
}
}
;
$config = $configsKeys[($currentKey + 1) % count($configsKeys)];
} elseif (array_key_exists($toggle, $configs)) {
$config = $toggle;
} else {
error(sprintf('Invalid config "%s"', $toggle));
die(1);
}
} else {
$config = 0;
}
@ -177,7 +190,7 @@ function build(array $modes, array $screens, $mode, $toggle, array $currentMode,
$command = implode(' ', $command);
return [
'tmp' => sprintf("mode=%s\nconfig=%d", $tmpMode, $tmpConfig),
'config' => sprintf("mode=%s\nconfig=%s", $tmpMode, $tmpConfig),
'command' => $command,
];
}
@ -245,13 +258,13 @@ if (empty($modes)) {
die(1);
}
$options = getopt('m:ts');
$options = getopt('m:t::s');
$mode = isset($options['m']) ? $options['m'] : null;
$toggle = isset($options['t']);
$toggle = isset($options['t']) ? (false === $options['t'] ? true : $options['t']) : false;
$addOff = !isset($options['s']);
$build = build($modes, $screens, $mode, $toggle, $currentMode, $addOff);
if (!empty($build)) {
file_put_contents(getCurrentModeFile(), $build['tmp']);
file_put_contents(getCurrentModeFile(), $build['config']);
shell_exec($build['command']);
}