Jelajahi Sumber

added flag --connected to show connected only

Fabian Peter Hammerle 7 tahun lalu
induk
melakukan
0bd1d586c8
2 mengubah file dengan 32 tambahan dan 6 penghapusan
  1. 22 0
      README.md
  2. 10 6
      scripts/xrandrl

+ 22 - 0
README.md

@@ -5,3 +5,25 @@
 ```{sh}
 sudo apt-get install python3 libx11-dev libxrandr-dev
 ```
+
+## Examples
+
+```{sh}
+$ xrandrl
+eDP2
+DP1
+DP2
+DP2-1
+DP2-2
+DP2-3
+HDMI1
+HDMI2
+VGA1
+VIRTUAL1
+eDP-1-1
+DVI-D-1-1
+$ xrandrl --connected
+eDP2
+DP2-1
+DP2-2
+```

+ 10 - 6
scripts/xrandrl

@@ -133,20 +133,24 @@ def get_xrandr_output_infos(xdisplay):
             for o in range(screen_resrcs.contents.noutput)]
 
 
-def process():
+def process(connected):
     xdisplay = X11.XOpenDisplay(None)
     for output_info in get_xrandr_output_infos(xdisplay):
-        output_name = output_info.contents.name \
-            .decode(sys.getfilesystemencoding())
-        print(output_name)
-        # if output_info.contents.connection == RR_Connected:
-        #     print(output_name)
+        if not connected or output_info.contents.connection == RR_Connected:
+            output_name = output_info.contents.name \
+                .decode(sys.getfilesystemencoding())
+            print(output_name)
     X11.XCloseDisplay(xdisplay)
 
 
 def _init_argparser():
     import argparse
     argparser = argparse.ArgumentParser(description=None)
+    argparser.add_argument(
+        '--connected',
+        action='store_true',
+        help='connected only',
+    )
     return argparser