Browse Source

argument -t

master
Simon Vieille 2 years ago
parent
commit
c040a4da02
2 changed files with 28 additions and 12 deletions
  1. 5
    2
      README.md
  2. 23
    10
      monitordisplay

+ 5
- 2
README.md View File

@@ -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:

+ 23
- 10
monitordisplay View File

@@ -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']);
}

Loading…
Cancel
Save