Sfoglia il codice sorgente

added flag --backlight to show outputs with backlight configurable via randr only

Fabian Peter Hammerle 7 anni fa
parent
commit
9b9a45b04c
2 ha cambiato i file con 46 aggiunte e 3 eliminazioni
  1. 4 0
      README.md
  2. 42 3
      scripts/xrandrl

+ 4 - 0
README.md

@@ -25,6 +25,7 @@ optional arguments:
   -c, --connected  connected only
   -d, --disabled   disabled only (does not imply --connected)
   -e, --enabled    enabled only (does not imply --connected)
+  -b, --backlight  outputs with backlight configurable via randr only
   -h, --help       show help message and exit
 ```
 
@@ -43,6 +44,9 @@ DP2-2
 $ xrandrl --connected --disabled
 DP2-1
 
+$ xrandrl --backlight
+eDP2
+
 $ xrandrl
 eDP2
 DP1

+ 42 - 3
scripts/xrandrl

@@ -43,6 +43,17 @@ X_Connection = ctypes.c_ushort
 typedef unsigned short	SubpixelOrder;
 """
 X_SubpixelOrder = ctypes.c_ushort
+""" /usr/include/X11/Xdefs.h
+#ifndef _XTYPEDEF_ATOM
+#  define _XTYPEDEF_ATOM
+#  ifndef _XSERVER64
+typedef unsigned long Atom;
+#  else
+typedef CARD32 Atom;
+#  endif
+#endif
+"""
+X_Atom = ctypes.c_ulong
 
 
 class X_XRRScreenResources(ctypes.Structure):
@@ -119,6 +130,7 @@ XRROutputInfo *
 XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, RROutput output);
 """
 Xrandr.XRRGetOutputInfo.restype = ctypes.POINTER(X_XRROutputInfo)
+Xrandr.XRRListOutputProperties.restype = ctypes.POINTER(X_Atom)
 
 
 class RandrScreenResources:
@@ -141,8 +153,10 @@ class RandrScreenResources:
 class RandrOutputInfo:
 
     def __init__(self, screen_resrcs: RandrScreenResources, output: X_RROutput):
+        self._xdisplay = screen_resrcs._xdisplay
+        self._output = output
         self._p = Xrandr.XRRGetOutputInfo(
-            screen_resrcs._xdisplay,
+            self._xdisplay,
             screen_resrcs._p,
             output,
         )
@@ -162,8 +176,27 @@ class RandrOutputInfo:
     def name(self):
         return self._p.contents.name.decode()
 
+    def _get_property_atoms_list(self):
+        nprop = ctypes.c_int()
+        props = Xrandr.XRRListOutputProperties(
+            self._xdisplay,
+            self._output,
+            ctypes.pointer(nprop),
+        )
+        atoms = [props[i] for i in range(nprop.value)]
+        X11.XFree(props)
+        return atoms
 
-def process(connected, disabled, enabled):
+    def has_backlight(self):
+        atom = X11.XInternAtom(self._xdisplay, b'Backlight', True)
+        if atom:
+            props = self._get_property_atoms_list()
+            return atom in props
+        else:
+            return False
+
+
+def process(connected, disabled, enabled, backlight):
     xdisplay = X11.XOpenDisplay(None)
     screen_resrcs = RandrScreenResources(
         xdisplay,
@@ -172,7 +205,8 @@ def process(connected, disabled, enabled):
     for output_info in screen_resrcs.get_output_infos():
         if ((not connected or output_info.connected)
                 and (not disabled or not output_info.enabled)
-                and (not enabled or output_info.enabled)):
+                and (not enabled or output_info.enabled)
+                and (not backlight or output_info.has_backlight())):
             print(output_info.name)
     X11.XCloseDisplay(xdisplay)
 
@@ -197,6 +231,11 @@ def _init_argparser():
         action='store_true',
         help='enabled only (does not imply --connected)',
     )
+    argparser.add_argument(
+        '-b', '--backlight',
+        action='store_true',
+        help='outputs with backlight configurable via randr only',
+    )
     return argparser