summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-13 18:12:37 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-13 18:12:37 +0100
commitfb734bf54d9eb0136f0e88aa8f55a27622c8ef6d (patch)
treec732dd4a413aea9a0c391ccca4e91c72bcf57f0a
parentadd drm connection manager (diff)
downloadblueshift-fb734bf54d9eb0136f0e88aa8f55a27622c8ef6d.tar.gz
blueshift-fb734bf54d9eb0136f0e88aa8f55a27622c8ef6d.tar.bz2
blueshift-fb734bf54d9eb0136f0e88aa8f55a27622c8ef6d.tar.xz
m + add list_screens_drm, rename list_screens to list_screens_randr and make list_screens run eiher list_screens_randr or list_screens_drm
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/blueshift_drm.pyx6
-rw-r--r--src/monitor.py61
2 files changed, 63 insertions, 4 deletions
diff --git a/src/blueshift_drm.pyx b/src/blueshift_drm.pyx
index 30f07c1..001ec41 100644
--- a/src/blueshift_drm.pyx
+++ b/src/blueshift_drm.pyx
@@ -270,9 +270,9 @@ def drm_get_connector_type_name(int connection, int connector_index):
@param connection The identifier for the connection to the card
@param connector_index The index of the connector
@return :str The connector type by name, "Unknown" if not identifiable,
- "Unrecognised" if Blueshift does not recognise it.
+ "Unrecognised" if Blueshift does not recognise it.
'''
- return <bytes>blueshift_drm_get_connector_type_name(connection, connector_index)
+ return (<bytes>blueshift_drm_get_connector_type_name(connection, connector_index)).decode('utf-8', 'replace')
def drm_get_edid(int connection, int connector_index):
@@ -303,5 +303,5 @@ def drm_get_edid(int connection, int connector_index):
edid[got * 2] = 0
rc = edid
free(edid)
- return rc
+ return rc.decode('utf-8', 'replace')
diff --git a/src/monitor.py b/src/monitor.py
index 9df1ffe..d3a7a97 100644
--- a/src/monitor.py
+++ b/src/monitor.py
@@ -420,10 +420,26 @@ class Output:
rc = '[Name: %s, Connected: %s, Width: %s, Height: %s, CRTC: %s, Screen: %s, EDID: %s]' % rc
return rc
-def list_screens():
+
+def list_screens(method = 'randr'):
'''
Retrieve informantion about all screens, outputs and CRTC:s
+ @param method:str The listing method: 'randr' for RandR (under X),
+ 'drm' for DRM (under TTY)
+ @return :Screens An instance of a datastructure with the relevant information
+ '''
+ if method == 'randr':
+ return list_screens_randr()
+ if method == 'drm':
+ return list_screens_drm()
+ return None # Error: invalid method
+
+
+def list_screens_randr():
+ '''
+ Retrieve informantion about all screens, outputs and CRTC:s, using RandR
+
@return :Screens An instance of a datastructure with the relevant information
'''
process = Popen([LIBEXECDIR + "/blueshift_idcrtc"], stdout = PIPE)
@@ -467,6 +483,48 @@ def list_screens():
return rc
+def list_screens_drm():
+ '''
+ Retrieve informantion about all screens, outputs and CRTC:s, using DRM
+
+ @return :Screens An instance of a datastructure with the relevant information
+ '''
+ # This method should not use `drm_manager` because we want to be able to find updates
+ screens = Screens()
+ screens.screens = []
+ for card in range(drm_card_count()):
+ screen = Screen()
+ screens.screens.append(screen)
+ connection = drm_open_card(card)
+ if connection == -1:
+ continue
+ drm_update_card(connection)
+ screen.crtc_count = drm_crtc_count(connection)
+ used_names = {}
+ for connector in range(drm_connector_count(connection)):
+ drm_open_connector(connection, connector)
+ output = Output()
+ screen.outputs.append(output)
+ output.name = drm_get_connector_type_name(connection, connector)
+ if output.name not in used_names:
+ used_names[output.name] = 0
+ count = used_names[output.name]
+ used_names[output.name] += 1
+ output.name = '%s-%i' % (output.name, count)
+ output.connected = drm_is_connected(connection, connector) == 1
+ if output.connected:
+ output.widthmm = drm_get_width(connection, connector)
+ output.heightmm = drm_get_height(connection, connector)
+ if (output.widthmm <= 0) or (output.heightmm <= 0):
+ output.widthmm, output.heightmm = None, None
+ output.crtc = drm_get_crtc(connection, connector)
+ output.edid = drm_get_edid(connection, connector)
+ output.screen = card
+ drm_close_connector(connection, connector)
+ drm_close_card(connection)
+ return screens
+
+
class DRMManager:
'''
Manager for DRM connections to avoid monitor flicker on unnecessary connections
@@ -492,6 +550,7 @@ class DRMManager:
self.connectors = [None] * drm_card_count()
if self.cards[card] == -1:
self.cards[card] = drm_open_card(card)
+ drm_update_card(drm_open_card(self.cards[card]))
return self.cards[card]
def open_connector(self, card, connector):