Add -M CLI argument to display cloned monitors

Works the same as -m but doesn't purge cloned monitors
This commit is contained in:
patrick96 2019-06-24 17:58:40 +02:00 committed by Patrick Ziegler
parent cc36350849
commit 2edd8275ff
4 changed files with 18 additions and 5 deletions

View File

@ -35,6 +35,7 @@ _polybar() {
-r --reload -r --reload
-d --dump= -d --dump=
-m --list-monitors -m --list-monitors
-M --list-all-monitors
-w --print-wmname -w --print-wmname
-s --stdout -s --stdout
-p --png=' -p --png='

View File

@ -10,6 +10,7 @@ _polybar() {
local R='-r --reload' local R='-r --reload'
local D='-d --dump' local D='-d --dump'
local M='-m --list-monitors' local M='-m --list-monitors'
local MM='-M --list-all-monitors'
local W='-w --print-wmname' local W='-w --print-wmname'
local S='-s --stdout' local S='-s --stdout'
@ -21,7 +22,8 @@ _polybar() {
"($C)"{-c,--config=}'[Path to the configuration file]:configuration file:_files' \ "($C)"{-c,--config=}'[Path to the configuration file]:configuration file:_files' \
"($R)"{-r,--reload}'[Reload when the configuration has been modified]' \ "($R)"{-r,--reload}'[Reload when the configuration has been modified]' \
"($D $R $M $W $S)"{-d,--dump=}'[Print parameter value in bar section and exit]:parameter name' \ "($D $R $M $W $S)"{-d,--dump=}'[Print parameter value in bar section and exit]:parameter name' \
"($M $D $R $W $S)"{-m,--list-monitors}'[Print list of available monitors and exit]' \ "($MM $M $D $R $W $S)"{-m,--list-monitors}'[Print list of available monitors and exit (Removes cloned monitors)]' \
"($MM $M $D $R $W $S)"{-M,--list-all-monitors}'[Print list of all available monitors (Including cloned monitors) and exit]' \
"($W $R $D $M $S)"{-w,--print-wmname}'[Print the generated WM_NAME and exit]' \ "($W $R $D $M $S)"{-w,--print-wmname}'[Print the generated WM_NAME and exit]' \
"($S)"{-s,--stdout}'[Output data to stdout instead of drawing the X window]' \ "($S)"{-s,--stdout}'[Output data to stdout instead of drawing the X window]' \
'::bar name:_polybar_list_names' '::bar name:_polybar_list_names'

View File

@ -44,6 +44,13 @@ OPTIONS
.. option:: -m, --list-monitors .. option:: -m, --list-monitors
Print list of available monitors and exit Print list of available monitors and exit
If some monitors are cloned, this will remove all but one of them
.. option:: -M, --list-all-monitors
Print list of available monitors and exit
This will also include all cloned monitors.
.. option:: -w, --print-wmname .. option:: -w, --print-wmname
Print the generated *WM_NAME* and exit Print the generated *WM_NAME* and exit

View File

@ -21,7 +21,8 @@ int main(int argc, char** argv) {
command_line::option{"-c", "--config", "Path to the configuration file", "FILE"}, command_line::option{"-c", "--config", "Path to the configuration file", "FILE"},
command_line::option{"-r", "--reload", "Reload when the configuration has been modified"}, command_line::option{"-r", "--reload", "Reload when the configuration has been modified"},
command_line::option{"-d", "--dump", "Print value of PARAM in bar section and exit", "PARAM"}, command_line::option{"-d", "--dump", "Print value of PARAM in bar section and exit", "PARAM"},
command_line::option{"-m", "--list-monitors", "Print list of available monitors and exit"}, command_line::option{"-m", "--list-monitors", "Print list of available monitors and exit (Removes cloned monitors)"},
command_line::option{"-M", "--list-all-monitors", "Print list of all available monitors (Including cloned monitors) and exit"},
command_line::option{"-w", "--print-wmname", "Print the generated WM_NAME and exit"}, command_line::option{"-w", "--print-wmname", "Print the generated WM_NAME and exit"},
command_line::option{"-s", "--stdout", "Output data to stdout instead of drawing it to the X window"}, command_line::option{"-s", "--stdout", "Output data to stdout instead of drawing it to the X window"},
command_line::option{"-p", "--png", "Save png snapshot to FILE after running for 3 seconds", "FILE"}, command_line::option{"-p", "--png", "Save png snapshot to FILE after running for 3 seconds", "FILE"},
@ -76,8 +77,10 @@ int main(int argc, char** argv) {
//================================================== //==================================================
// List available XRandR entries // List available XRandR entries
//================================================== //==================================================
if (cli->has("list-monitors")) { if (cli->has("list-monitors") || cli->has("list-all-monitors")) {
for (auto&& mon : randr_util::get_monitors(conn, conn.root(), true)) { bool purge_clones = !cli->has("list-all-monitors");
auto monitors = randr_util::get_monitors(conn, conn.root(), true, purge_clones);
for (auto&& mon : monitors) {
if (WITH_XRANDR_MONITORS && mon->output == XCB_NONE) { if (WITH_XRANDR_MONITORS && mon->output == XCB_NONE) {
printf("%s: %ix%i+%i+%i (XRandR monitor%s)\n", mon->name.c_str(), mon->w, mon->h, mon->x, mon->y, printf("%s: %ix%i+%i+%i (XRandR monitor%s)\n", mon->name.c_str(), mon->w, mon->h, mon->x, mon->y,
mon->primary ? ", primary" : ""); mon->primary ? ", primary" : "");