From 54d19def31ed6bba3318be5198c67e775401f18e Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Wed, 17 Aug 2011 13:34:20 +0400 Subject: [PATCH] Modify variables. Change detect x11 resolution: instead of only xdpyinfo using at first xdpyinfo, at second xorg.log, at third xorg.conf, then cmdline and default value 1024x768. Add writable os_x11_resolution as base for os_x11_height and os_x11_width. os_x11_height and os_x11_width is readonly. --- pym/cl_fill.py | 72 +++++++++++++++++++++++++++++++++++++++++++------- pym/cl_vars.py | 7 +++-- 2 files changed, 67 insertions(+), 12 deletions(-) diff --git a/pym/cl_fill.py b/pym/cl_fill.py index 082b67e..066d029 100644 --- a/pym/cl_fill.py +++ b/pym/cl_fill.py @@ -429,21 +429,73 @@ class fillVars(varsShare): return videoVal return self.getVideoByDefault(list_available_drivers) + def getResByXDpyInfo(self): + """Get resolution by xdpyinfo utility""" + lines=self._runos("xdpyinfo") + if not lines: + return "" + reRes = re.compile("dimensions:\s+(\d+)x(\d+)\s+pixels") + searchRes=False + for line in lines: + searchRes = reRes.search(line) + if searchRes: + break + if searchRes: + return "%sx%s"%(searchRes.group(1), searchRes.group(2)) + return "" + + def get_os_x11_resolution(self): + """ + Return current screen resolution (width, height). + Try detect by xdpyinfo, then Xorg.log, xorg.conf + """ + resolution = self.getResByXDpyInfo() + if resolution: + return resolution + if self.Get('os_root_type') != 'usb-hdd': + xlog = "/var/log/Xorg.0.log" + if os.access(xlog,os.R_OK): + reXorgLogParser = re.compile(""" + Virtual\ screen\ size\ determined\ to\ be + \ ([0-9]+)\s*x\s*([0-9]+)| + Setting\ mode\ "(\d+)x(\d+)[0-9\@]"| + Output\ [\S]+\ using\ initial\ mode\ (\d+)x(\d+)| + Virtual\ size\ is\ (\d+)x(\d+)""", re.X | re.S) + resXorgLogParser = reXorgLogParser.search(open(xlog,'r').read()) + if resXorgLogParser: + return "%sx%s"%filter(lambda x:x, + resXorgLogParser.groups())[:2] + + # get resolution from xorg.conf + xorgconf = "/etc/X11/xorg.conf" + reScreenSections = re.compile('Section "Screen"(.*?)EndSection', + re.S) + reModes = re.compile('Modes\s+"(\d+x\d+)') + if os.access(xorgconf,os.R_OK): + sectionsScreen = filter(lambda x:"Modes" in x, + reScreenSections.findall(open('/etc/X11/xorg.conf', + 'r').read())) + modes = map(lambda x:x.groups()[0], + filter(lambda x:x, + map(reModes.search, sectionsScreen))) + if modes: + return max(modes,key=lambda x:int(x.partition('x')[0])) + + # get resolution from command line + reRightResolution = re.compile("^(\d+x\d+|auto)$",re.S) + kernelResolution = self.getValueFromCmdLine("calculate",3) + if kernelResolution and reRightResolution.match(kernelResolution): + return {'auto':''}.get(kernelResolution,kernelResolution) + else: + return "" + def get_os_x11_height(self): """Get screen height in pixeles""" - resolution = self.getX11Resolution() - if resolution: - self.Set('os_x11_width',resolution[0]) - return resolution[1] - return "768" + return self.Get('os_x11_resolution').partition('x')[2] or "768" def get_os_x11_width(self): """Get screen width in pixeles""" - resolution = self.getX11Resolution() - if resolution: - self.Set('os_x11_height',resolution[1]) - return resolution[0] - return "1024" + return self.Get('os_x11_resolution').partition('x')[0] or "1024" def get_os_x11_standart(self): """Get the nearest standard size of image relative current diff --git a/pym/cl_vars.py b/pym/cl_vars.py index 4d7f9f2..3194ff8 100644 --- a/pym/cl_vars.py +++ b/pym/cl_vars.py @@ -167,11 +167,14 @@ class Data: # (package_name == value of cl_belong_pkg) cl_belong_pkg = {'mode':'r', 'hide':True} + # x11 resolution (1024x768 and etc) + os_x11_resolution = {'mode':'w','hide':True} + # vertical resolution for X server - os_x11_height = {'mode':"w", 'hide':True} + os_x11_height = {'mode':"r", 'hide':True} # horizontal resolution for X server - os_x11_width = {'mode':"w", 'hide':True} + os_x11_width = {'mode':"r", 'hide':True} # the nearest standard size of image to current screen resolution os_x11_standart = {'hide':True}