diff --git a/pym/cl_fill.py b/pym/cl_fill.py index 95e7a81..d2a2eb8 100644 --- a/pym/cl_fill.py +++ b/pym/cl_fill.py @@ -812,6 +812,148 @@ class fillVars(glob_attr): else: return "vesa" + def getX11Resolution(self): + """возвращает текущее разрешение экрана (ширина, высота), X запущен""" + 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 (searchRes.group(1), searchRes.group(2)) + else: + return "" + + def get_hr_x11_height(self): + """Получить высоту экрана в пикселах""" + resolution = self.getX11Resolution() + if resolution: + self.Set('hr_x11_width',resolution[0]) + return resolution[1] + return "768" + + def get_hr_x11_width(self): + """Получить ширину экрана в пикселах""" + resolution = self.getX11Resolution() + if resolution: + self.Set('hr_x11_height',resolution[1]) + return resolution[0] + return "1024" + + def get_hr_x11_standart(self): + """Получить ближайший стандартный размер изображения к текущему разрешению""" + #Стандартные разрешения + widthVal = self.Get('hr_x11_width') + heightVal = self.Get('hr_x11_height') + if not widthVal or not heightVal: + return "" + width = int(widthVal) + height = int(heightVal) + res = [(1024,768), + (1280,1024), + (1280,800), + (1440,900), + (1600,1200), + (1680,1050), + (1920,1200)] + resolution = [] + formats = [] + for w, h in res: + formats.append(float(w)/float(h)) + listFr = list(set(formats)) + listFormats = {} + for fr in listFr: + listFormats[fr] = [] + for w, h in res: + for fr in listFormats.keys(): + if fr == float(w)/float(h): + listFormats[fr].append((w,h)) + break + format = float(width)/float(height) + deltaFr = {} + for fr in listFormats.keys(): + deltaFr[abs(format - fr)] = fr + resolution = listFormats[deltaFr[min(deltaFr.keys())]] + flagFound = False + stResol = [] + stHeights = [] + stWidths = [] + stWidth = False + stHeight = False + for w, h in resolution: + if w >= width and h >= height: + stResol.append((w,h)) + stHeights.append(h) + if stHeights: + stHeight = min(stHeights) + for w, h in stResol: + if stHeight == h: + stWidths.append(w) + if stWidths: + stWidth = min(stWidths) + if (not stWidth) or (not stHeight): + return "%sx%s"%(resolution[-1][0],resolution[-1][1]) + else: + return "%sx%s"%(stWidth,stHeight) + + def get_hr_x11_composite(self): + """Включен ли композитный режим видеокарты on/off""" + defaultCompositeOn = ["nvidia","intel"] + if self.Get('hr_x11_video_drv') in defaultCompositeOn: + defaultComposite = "on" + else: + defaultComposite = "off" + xorgConfig = "/etc/X11/xorg.conf" + try: + confLines = open(xorgConfig,"r").readlines() + except: + return defaultComposite + + flagStartExtensions = False + lineCompositeTmp = "" + lineComposite = "" + for line in confLines: + if flagStartExtensions: + if 'EndSection' in line: + lineComposite = lineCompositeTmp + break + elif 'Section' in line: + break + if 'Option' in line and '"Composite"' in line: + lineCompositeTmp = line + else: + if '"Extensions"' in line and 'Section' in line: + flagStartExtensions = True + if lineComposite: + listOpt = filter(lambda x: x.strip(), lineComposite.split('"')) + if len(listOpt) == 3: + ret = listOpt[2].lower() + if ret in ("on","true","yes","1"): + return "on" + elif ret in ("off","false","no","0"): + return "off" + return defaultComposite + + def get_hr_laptop(self): + """Если компьютер ноутбук, то его производитель""" + formfactor = self._runos("hal-get-property --udi \ +/org/freedesktop/Hal/devices/computer --key system.formfactor") + if not formfactor: + return "" + if formfactor == 'laptop': + vendor = self._runos("hal-get-property --udi \ +/org/freedesktop/Hal/devices/computer --key system.hardware.vendor") + if vendor: + vendor = vendor.split(" ")[0] + else: + vendor = "unknown" + return vendor.lower() + return "" + def get_hr_video(self): """Производитель видеокарты""" lines=self._runos("lspci") diff --git a/pym/cl_vars.py b/pym/cl_vars.py index ec74359..f420679 100644 --- a/pym/cl_vars.py +++ b/pym/cl_vars.py @@ -175,9 +175,27 @@ class Data: # (имя_пакета == значение cl_belong_pkg) cl_belong_pkg = {'mode':'r', 'official':True} + # Video driver used by xorg + hr_x11_video_drv = {'official':True} + + #Разрешение X по вертикали + hr_x11_height = {'mode':"w"} + + #Разрешение X по горизонтали + hr_x11_width = {'mode':"w"} + + # ближайший стандартный размер изображения к текущему разрешению + hr_x11_standart = {} + + # Если компьютер ноутбук, то его производитель + hr_laptop = {} + # Название производителя видеокарты - hr_video = {'official':True} + hr_video = {} # Video driver used by xorg - hr_x11_video_drv = {'official':True} + hr_x11_video_drv = {} + + # Включен ли композитный режим видеокарты on/off + hr_x11_composite = {}