def main(filename): from io import BytesIO from xpra.os_util import memoryview_to_bytes from xpra.gtk_common.gtk_util import get_default_root_window, get_root_size root = get_default_root_window() capture = setup_capture(root) capture.refresh() w, h = get_root_size() image = capture.get_image(0, 0, w, h) from PIL import Image fmt = image.get_pixel_format().replace("X", "A") pixels = memoryview_to_bytes(image.get_pixels()) log("converting %i bytes in format %s to RGBA", len(pixels), fmt) if len(fmt) == 3: target = "RGB" else: target = "RGBA" pil_image = Image.frombuffer(target, (w, h), pixels, "raw", fmt, image.get_rowstride()) if target != "RGB": pil_image = pil_image.convert("RGB") buf = BytesIO() pil_image.save(buf, "png") data = buf.getvalue() buf.close() with open(filename, "wb") as f: f.write(data) return 0
def move(*_args): x, y = window.get_position() maxx, maxy = get_root_size() new_x = (x + 100) % maxx new_y = (y + 100) % maxy print("moving to %s x %s" % (new_x, new_y)) window.move(new_x, new_y)
def main(): rw, rh = get_root_size() window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL) window.set_default_size(100, rh) window.move(rw-100, 0) window.set_type_hint(Gdk.WindowTypeHint.DOCK) window.show() window.get_window().property_change("_NET_WM_STRUT", "CARDINAL", 32, Gtk.gdk.PROP_MODE_REPLACE, [0, 100, 0, 0]) Gtk.main()
def main(): rw, rh = get_root_size() window = gtk.Window(WINDOW_TOPLEVEL) window.set_default_size(100, rh) window.move(rw - 100, 0) window.set_type_hint(gdk.WINDOW_TYPE_HINT_DOCK) window.show() window.get_window().property_change("_NET_WM_STRUT", "CARDINAL", 32, gtk.gdk.PROP_MODE_REPLACE, [0, 100, 0, 0]) gtk.main()
def main(filename): from xpra.os_util import StringIOClass, memoryview_to_bytes from xpra.gtk_common.gtk_util import get_default_root_window, get_root_size root = get_default_root_window() capture = setup_capture(root) capture.refresh() w, h = get_root_size() image = capture.get_image(0, 0, w, h) from PIL import Image fmt = image.get_pixel_format().replace("X", "A") pixels = memoryview_to_bytes(image.get_pixels()) pil_image = Image.frombuffer("RGBA", (w, h), pixels, "raw", fmt, image.get_rowstride()) pil_image = pil_image.convert("RGB") buf = StringIOClass() pil_image.save(buf, "png") data = buf.getvalue() buf.close() with open(filename, "wb") as f: f.write(data)
def get_root_size(self): return get_root_size()
def with_server(start_server_command, stop_server_commands, in_tests, get_stats_cb): tests = in_tests[config.STARTING_TEST:config.LIMIT_TESTS] print("going to run %s tests:" % len(tests)) for test in tests: print(" * %s" % test[0]) print("*******************************************") print("ETA: %s minutes" % int((config.SERVER_SETTLE_TIME+config.DEFAULT_TEST_COMMAND_SETTLE_TIME+config.SETTLE_TIME+config.MEASURE_TIME+1)*len(tests)/60)) print("*******************************************") server_process = None test_command_process = None env = {} for k,v in os.environ.items(): #whitelist what we want to keep: if k.startswith("XPRA") or k in ( "LOGNAME", "XDG_RUNTIME_DIR", "USER", "HOME", "PATH", "LD_LIBRARY_PATH", "XAUTHORITY", "SHELL", "TERM", "USERNAME", "HOSTNAME", "PWD", ): env[k] = v env["DISPLAY"] = ":%s" % config.DISPLAY_NO errors = 0 results = [] count = 0 for name, tech_name, server_version, client_version, encoding, quality, speed, \ opengl, compression, encryption, ssh, (down,up,latency), test_command, client_cmd in tests: try: print("**************************************************************") count += 1 test_command_settle_time = config.TEST_COMMAND_SETTLE_TIME.get(test_command[0], config.DEFAULT_TEST_COMMAND_SETTLE_TIME) eta = int((config.SERVER_SETTLE_TIME+test_command_settle_time+config.SETTLE_TIME+config.MEASURE_TIME+1)*(len(tests)-count)/60) print("%s/%s: %s ETA=%s minutes" % (count, len(tests), name, eta)) test_command_process = None try: clean_sys_state() #start the server: if config.START_SERVER: print("starting server: %s" % str(start_server_command)) server_process = Popen(start_server_command, stdin=None) #give it time to settle down: t = config.SERVER_SETTLE_TIME if count==1: #first run, give it enough time to cleanup the socket t += 5 time.sleep(t) server_pid = server_process.pid code = server_process.poll() assert code is None, "server failed to start, return code is %s, please ensure that you can run the server command line above and that a server does not already exist on that port or DISPLAY" % code else: server_pid = 0 try: #start the test command: if config.USE_VIRTUALGL: if isinstance(test_command, str): cmd = config.VGLRUN_BIN + " -d "+os.environ.get("DISPLAY")+" -- "+ test_command elif isinstance(test_command, (list, tuple)): cmd = [config.VGLRUN_BIN, "-d", os.environ.get("DISPLAY"), "--"] + list(test_command) else: raise Exception("invalid test command type: %s for %s" % (type(test_command), test_command)) else: cmd = test_command print("starting test command: %s with env=%s, settle time=%s" % (cmd, env, test_command_settle_time)) shell = isinstance(cmd, str) test_command_process = Popen(cmd, stdin=None, stdout=PIPE, stderr=PIPE, env=env, shell=shell) if config.PREVENT_SLEEP: Popen(config.PREVENT_SLEEP_COMMAND) time.sleep(test_command_settle_time) code = test_command_process.poll() assert code is None, "test command %s failed to start: exit code is %s" % (cmd, code) print("test command %s is running with pid=%s" % (cmd, test_command_process.pid)) #run the client test data = {"Test Name" : name, "Remoting Tech" : tech_name, "Server Version" : server_version, "Client Version" : client_version, "Custom Params" : config.CUSTOM_PARAMS, "SVN Version" : SVN_VERSION, "Encoding" : encoding, "Quality" : quality, "Speed" : speed, "OpenGL" : opengl, "Test Command" : get_command_name(test_command), "Sample Duration (s)" : config.MEASURE_TIME, "Sample Time (epoch)" : time.time(), "CPU info" : CPU_INFO, "Platform" : PLATFORM, "Kernel Version" : KERNEL_VERSION, "Xorg version" : XORG_VERSION, "OpenGL" : OPENGL_INFO, "Client Window Manager" : WINDOW_MANAGER, "Screen Size" : "%sx%s" % get_root_size(), "Compression" : compression, "Encryption" : encryption, "Connect via" : ssh, "download limit (KB)" : down, "upload limit (KB)" : up, "latency (ms)" : latency, } data.update(measure_client(server_pid, name, client_cmd, get_stats_cb)) results.append([data.get(x, "") for x in HEADERS]) except Exception as e: import traceback traceback.print_exc() errors += 1 print("error during client command run for %s: %s" % (name, e)) if errors>config.MAX_ERRORS: print("too many errors, aborting tests") break finally: if test_command_process: print("stopping '%s' with pid=%s" % (test_command, test_command_process.pid)) try_to_stop(test_command_process) try_to_kill(test_command_process, 2) if config.START_SERVER: try_to_stop(server_process) time.sleep(2) for s in stop_server_commands: print("stopping server with: %s" % (s)) try: stop_process = Popen(s, stdin=None, stdout=PIPE, stderr=PIPE, shell=True) stop_process.wait() except Exception as e: print("error: %s" % e) try_to_kill(server_process, 5) time.sleep(1) except KeyboardInterrupt as e: print("caught %s: stopping this series of tests" % e) break return results
while cpu_name.find(o)>=0: cpu_name = cpu_name.replace(o, r) cpu_info = "%sx %s" % (len(lines), cpu_name.strip()) print("CPU_INFO=%s" % cpu_info) return cpu_info, n XORG_VERSION = getoutput_line([config.XORG_BIN, "-version"], "X.Org X Server") print("XORG_VERSION=%s" % XORG_VERSION) CPU_INFO, N_CPUS = get_cpu_info() KERNEL_VERSION = getoutput(["uname", "-r"]).replace("\n", "").replace("\r", "") PAGE_SIZE = int(getoutput(["getconf", "PAGESIZE"]).replace("\n", "").replace("\r", "")) PLATFORM = getoutput(["uname", "-p"]).replace("\n", "").replace("\r", "") OPENGL_INFO = getoutput_line(["glxinfo"], "OpenGL renderer string").split("OpenGL renderer string:")[1].strip() SCREEN_SIZE = get_root_size() print("screen size=%s" % str(SCREEN_SIZE)) #detect Xvnc version: XVNC_VERSION = "" VNCVIEWER_VERSION = "" DETECT_XVNC_VERSION_CMD = [config.XVNC_BIN, "--help"] DETECT_VNCVIEWER_VERSION_CMD = [config.VNCVIEWER_BIN, "--help"] def get_stderr(command): try: process = Popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE) return process.communicate()[1] except Exception as e: print("error running %s: %s" % (DETECT_XVNC_VERSION_CMD, e)) err = get_stderr(DETECT_XVNC_VERSION_CMD)
def print_screen_info(self): X11ServerBase.print_screen_info(self) root_w, root_h = get_root_size() sss = get_screen_sizes() log_screen_sizes(root_w, root_h, sss)
def print_screen_info(self): super().print_screen_info() root_w, root_h = get_root_size() log.info(" initial resolution: %ix%i", root_w, root_h) sss = get_screen_sizes() log_screen_sizes(root_w, root_h, sss)
def configure_best_screen_size(self): root_w, root_h = get_root_size() return root_w, root_h
def get_max_screen_size(self): max_w, max_h = get_root_size() return max_w, max_h
def get_root_window_size(self): return get_root_size()
def print_screen_info(self): super(XpraDesktopServer, self).print_screen_info() root_w, root_h = get_root_size() sss = get_screen_sizes() log_screen_sizes(root_w, root_h, sss)