argument -t
This commit is contained in:
parent
95818fd280
commit
c040a4da02
|
@ -33,12 +33,13 @@ resolutionY=1080
|
||||||
|
|
||||||
```
|
```
|
||||||
[mode:MODE_NAME]
|
[mode:MODE_NAME]
|
||||||
config[]=HUMAIN_SCREEN_NAME1,HUMAIN_SCREEN_NAME2
|
config[foo]=HUMAIN_SCREEN_NAME1,HUMAIN_SCREEN_NAME2
|
||||||
config[]=HUMAIN_SCREEN_NAME2,HUMAIN_SCREEN_NAME1
|
config[bar]=HUMAIN_SCREEN_NAME2,HUMAIN_SCREEN_NAME1
|
||||||
primary=HUMAIN_SCREEN_NAME1
|
primary=HUMAIN_SCREEN_NAME1
|
||||||
|
|
||||||
[mode:MODE_NAME2]
|
[mode:MODE_NAME2]
|
||||||
config[]=HUMAIN_SCREEN_NAME1,HUMAIN_SCREEN_NAME3
|
config[]=HUMAIN_SCREEN_NAME1,HUMAIN_SCREEN_NAME3
|
||||||
|
config[]=HUMAIN_SCREEN_NAME1,HUMAIN_SCREEN_NAME3
|
||||||
```
|
```
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
|
@ -61,6 +62,8 @@ Then you can run:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ monitordisplay -t
|
$ monitordisplay -t
|
||||||
|
# OR
|
||||||
|
$ monitordisplay -tbar
|
||||||
```
|
```
|
||||||
|
|
||||||
…which equals:
|
…which equals:
|
||||||
|
|
|
@ -99,7 +99,7 @@ function build(array $modes, array $screens, $mode, $toggle, array $currentMode,
|
||||||
$mode = $modes[$mode];
|
$mode = $modes[$mode];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($toggle === true) {
|
if ($toggle !== false) {
|
||||||
if ($currentMode['mode'] === null) {
|
if ($currentMode['mode'] === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -107,15 +107,28 @@ function build(array $modes, array $screens, $mode, $toggle, array $currentMode,
|
||||||
if ($currentMode['config'] === null) {
|
if ($currentMode['config'] === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$currentMode['config'] = (int) $currentMode['config'];
|
$configs = $mode['config'];
|
||||||
|
$configsKeys = array_keys($configs);
|
||||||
|
|
||||||
if (!array_key_exists($currentMode['config'], $mode['config'])) {
|
if (!array_key_exists($currentMode['config'], $mode['config'])) {
|
||||||
return;
|
$currentMode['config'] = $configsKeys[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$configs = $mode['config'];
|
if ($toggle === true) {
|
||||||
$config = ($currentMode['config'] + 1) % count($configs);
|
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 {
|
} else {
|
||||||
$config = 0;
|
$config = 0;
|
||||||
}
|
}
|
||||||
|
@ -177,7 +190,7 @@ function build(array $modes, array $screens, $mode, $toggle, array $currentMode,
|
||||||
$command = implode(' ', $command);
|
$command = implode(' ', $command);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'tmp' => sprintf("mode=%s\nconfig=%d", $tmpMode, $tmpConfig),
|
'config' => sprintf("mode=%s\nconfig=%s", $tmpMode, $tmpConfig),
|
||||||
'command' => $command,
|
'command' => $command,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -245,13 +258,13 @@ if (empty($modes)) {
|
||||||
die(1);
|
die(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = getopt('m:ts');
|
$options = getopt('m:t::s');
|
||||||
$mode = isset($options['m']) ? $options['m'] : null;
|
$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']);
|
$addOff = !isset($options['s']);
|
||||||
$build = build($modes, $screens, $mode, $toggle, $currentMode, $addOff);
|
$build = build($modes, $screens, $mode, $toggle, $currentMode, $addOff);
|
||||||
|
|
||||||
if (!empty($build)) {
|
if (!empty($build)) {
|
||||||
file_put_contents(getCurrentModeFile(), $build['tmp']);
|
file_put_contents(getCurrentModeFile(), $build['config']);
|
||||||
shell_exec($build['command']);
|
shell_exec($build['command']);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue