def load_browser(): logging.info('Loading browser...') global is_pro_init, current_browser_url is_pro_init = get_is_pro_init() if not is_pro_init: logging.debug('Detected Pro initiation cycle.') # Wait for the intro file to exist (if it doesn't) intro_file = path.join(settings.get_configdir(), 'intro.html') while not path.isfile(intro_file): logging.debug('intro.html missing. Going to sleep.') sleep(0.5) browser_load_url = 'file://' + intro_file elif settings['show_splash']: browser_load_url = "http://%s:%s/splash_page" % (settings.get_listen_ip(), settings.get_listen_port()) else: browser_load_url = black_page geom = [l for l in sh.xwininfo('-root').split("\n") if 'geometry' in l][0].split('y ')[1] browser = sh.Command('uzbl-browser')(g=geom, uri=browser_load_url, _bg=True) current_browser_url = browser_load_url logging.info('Browser loaded. Running as PID %d.' % browser.pid) if settings['show_splash']: # Show splash screen for 60 seconds. sleep(60) else: # Give browser some time to start (we have seen multiple uzbl running without this) sleep(10) return browser
def send_to_front(name): """Instruct X11 to bring a window with the given name in its title to front.""" r = [l for l in sh.xwininfo('-root', '-tree').split("\n") if name in l] if not len(r) == 1: logging.info("Unable to send window with %s in title to front - %d matches found." % (name, len(r))) return win_id = int(r[0].strip().split(" ", 2)[0], 16) dsp = libx11.XOpenDisplay(None) logging.debug("Raising %s window %X to front." % (name, win_id)) libx11.XRaiseWindow(dsp, win_id) libx11.XCloseDisplay(dsp)
def _handle_end_frame_gif(self, frame): self._end_frame(frame) if not frame % 5: return if not self.window_id: self.window_id = sh.grep(sh.xwininfo('-root', '-tree'), self.title).strip().split(' ')[0] cmd = sh.Command('import') # TODO: Might be faster to use a RAMdisk tmp = tempfile.NamedTemporaryFile(suffix='.gif') cmd('-window', self.window_id, tmp.name) self.gif_frames.append(tmp)
def _extract_info(self, cmd_options): query = xwininfo(cmd_options) self.title = None self.width = None self.height = None self.x = None self.y = None for raw_line in query.split("\n"): line = raw_line.strip() if line.startswith("xwininfo:"): if self.window_id: cut = line.split(self.window_id)[-1] self.title = self._gen_title(cut.strip()[1:-1]) else: self.title = self._gen_title(None) elif line.startswith("-geometry"): nums = map(int, re.findall(r"[0-9]+", line.split(" ")[-1])) self.width, self.height, self.x, self.y = nums
def get_window_position( window_id ): """ Absolute upper-left X: 1 Absolute upper-left Y: 30 Relative upper-left X: 1 Relative upper-left Y: 15 Width: 1918 Height: 1148 Depth: 24 Visual: 0x21 Visual Class: TrueColor Border width: 0 Class: InputOutput Colormap: 0x20 (installed) Bit Gravity State: NorthWestGravity Window Gravity State: NorthWestGravity Backing Store State: NotUseful Save Under State: no Map State: IsViewable Override Redirect State: no Corners: +1+30 -1+30 -1-22 +1-22 -geometry 319x88+0+15 """ output = xwininfo("-id", window_id ) data = { 'pos_x': 'Absolute upper-left X', 'pos_y': 'Absolute upper-left Y', 'width': 'Width', 'height': 'Height', } result = {} for line in output.splitlines(): if not ':' in line: continue field_name, field_value = line.strip().split(':', 1) for k, v in data.items(): if v == field_name: result[k] = int(field_value) return result
def select_window(): out = sh.xwininfo('-int') out = out.stdout.decode('utf-8') m = re.search(r'xwininfo: Window id: (\d+) ([^\n]+)', out) return m.group(1), m.group(2)