Revert "made aspect ratio accurate"
[lilass.git] / screen.py
index 39c9367d6b61291bfab410c9318755f194ccf241..6ba9418ae39058429b092aa4e1a646d91582e489 100644 (file)
--- a/screen.py
+++ b/screen.py
@@ -18,7 +18,6 @@
 
 import re, subprocess
 from enum import Enum
-from fractions import Fraction
 
 ## utility functions
 
@@ -47,6 +46,8 @@ class RelativeScreenPosition(Enum):
         cls = self.__class__
         self._value_ = len(cls.__members__) + 1
         self.text = text
+    def __str__(self):
+        return self.text
 
 class Resolution:
     '''Represents a resolution of a screen'''
@@ -85,8 +86,13 @@ class Resolution:
     
     def __str__(self):
         # get ratio
-        ratio = Fraction(self.width, self.height) # automatically divides by the gcd
-        strRatio = "%d:%d" % (ratio.numerator, ratio.denominator)
+        ratio = int(round(16.0*self.height/self.width))
+        if ratio == 12: # 16:12 = 4:3
+            strRatio = '4:3'
+        elif ratio == 13: # 16:12.8 = 5:4
+            strRatio = '5:4'
+        else: # let's just hope this will never be 14 or more...
+            strRatio = '16:%d' % ratio
         return '%dx%d (%s)' %(self.width, self.height, strRatio)
     
     def __repr__(self):
@@ -134,6 +140,13 @@ class ScreenSetup:
                 RelativeScreenPosition.MIRROR: '--same-as',
             }[self.relPosition], intName]
         return args
+    
+    def __str__(self):
+        if self.intResolution is None:
+            return "External display only, at "+str(self.extResolution)
+        if self.extResolution is None:
+            return "Internal display only, at "+str(self.intResolution)
+        return "External display %s at %s %s internal display %s at %s" % ("(primary)" if self.extIsPrimary else "", str(self.extResolution), str(self.relPosition), "" if self.extIsPrimary else "(primary)", str(self.intResolution))
 
 class Connector:
     def __init__(self, name=None):
@@ -208,7 +221,7 @@ class ScreenSituation:
         if self.internalConnector == self.externalConnector:
             raise Exception("Internal and external connector are the same. This must not happen. Please fix ~/.dsl.conf.");
         print("Detected external connector:",self.externalConnector)
-        # self.preferredSetup is left uninitialized so you can't access it before trying a lookup in the database
+        # self.lastSetup is left uninitialized so you can't access it before trying a lookup in the database
     
     # Run xrandr and fill the dict of connector names mapped to lists of available resolutions.
     def _getXrandrInformation(self):
@@ -296,13 +309,13 @@ class ScreenSituation:
 
     def fetchDBInfo(self, db):
         if self.externalConnector and self.externalConnector.edid:
-            self.preferredSetup = db.getConfig(self.externalConnector.edid) # may also return None
+            self.lastSetup = db.getConfig(self.externalConnector.edid) # may also return None
         else:
-            self.preferredSetup = None
-        if self.preferredSetup:
-            print("SETUP FOUND", self.preferredSetup)
-            self.externalConnector.lastResolution = self.preferredSetup.extResolution
-            self.internalConnector.lastResolution = self.preferredSetup.intResolution
+            self.lastSetup = None
+        if self.lastSetup:
+            print("SETUP FOUND", self.lastSetup)
+            self.externalConnector.lastResolution = self.lastSetup.extResolution
+            self.internalConnector.lastResolution = self.lastSetup.intResolution
         else:
             print("NO SETUP FOUND")