def set_default_profile(systray, mode_type): """Sets the default XServer display mode (single, multi, fullscreen)""" global current_custom_profile, display_mode try: if mode_type == display_mode: return True if ask(): sett = iset.read() mode_names = {"m": "multi", "s": "single", "f": "full"} sett["graphics"]["window_mode"] = mode_names[mode_type] iset.set(sett) display_mode = mode_type current_custom_profile = "" menu = build_menu() mode_names = { "m": "Multi Window", "s": "Single Window", "f": "Fullscreen" } name = mode_names[display_mode] systray.update(hover_text=f"GWSL Running - {name}", menu_options=menu) restart_server() except: logger.exception( "Exception occurred - Cannot switch to profile type " + str(mode_type))
def main(): global systray, display_mode, clipboard, exiter, ic, timer # Kill VcXsrv if already running if get_running(): kill_server() # Start VcXsrv start_server() # Start Tray Icon menu = build_menu() if display_mode == "c": name = current_custom_profile else: mode_names = {"m": "Multi Window", "s": "Single Window", "f": "Fullscreen"} name = mode_names[display_mode] systray = tray(ic, f"GWSL Running - {name}", menu, default_menu_index=open_dashboard) systray.start() # start service listener timer = time.perf_counter() while True: try: if time.perf_counter() - timer > 4: timer = timer = time.perf_counter() if not get_running(): # In case someone closes a single-window server... restart as multi window. if display_mode == "s": display_mode = "m" menu = build_menu() systray.update(hover_text="GWSL Running - Multi Window", menu_options=menu) sett = iset.read() sett["graphics"]["window_mode"] = "multi" iset.set(sett) restart_server() elif ask_restart(): restart_server() else: systray.shutdown() kill_server() subprocess.getoutput('taskkill /F /IM GWSL.exe') sys.exit() if exiter: kill_server() subprocess.getoutput('taskkill /F /IM GWSL.exe') systray.shutdown() sys.exit() except Exception as e: logger.exception("Exception occurred in main loop") time.sleep(2) kill_server() systray.shutdown() sys.exit()
def rescan(systray=False): global profile_dict, custom_profiles try: sett = iset.read() profile_dict = sett["xserver_profiles"] if systray != False: menu = build_menu() systray.update(menu_options=menu) custom_profiles = list(profile_dict) except Exception as e: logger.exception("Exception occurred - Cannot scan profiles") custom_profiles = []
def add_profile(systray): try: new_profile = profile.add() if new_profile != None: name = new_profile["name"] arguments = new_profile["args"].split(" ") sett = iset.read() sett["xserver_profiles"][name] = arguments iset.set(sett) rescan() menu = build_menu() systray.update(menu_options=menu) except Exception as e: logger.exception("Exception occurred - Cannot Create Profile")
def add_profile(systray): """Allows one to add a custom XServer profile (config)""" try: new_profile = profile.add(bundle_dir) if new_profile != None: name = new_profile["name"] arguments = new_profile["args"].split(" ") sett = iset.read() sett["xserver_profiles"][name] = arguments iset.set(sett) rescan() menu = build_menu() systray.update(menu_options=menu) except: logger.exception("Exception occurred - Cannot Create Profile")
def rescan(systray=False): """Rescan config""" global profile_dict, custom_profiles, hidpi try: sett = iset.read() profile_dict = sett["xserver_profiles"] hidpi = sett["graphics"]["hidpi"] if systray != False: menu = build_menu() systray.update(menu_options=menu) custom_profiles = list(profile_dict) except: logger.exception("Exception occurred - Cannot scan profiles") custom_profiles = []
def dpi_set(systray, hi_dpi): """Changes vcxsrv main dpi backend server""" global hidpi if hi_dpi != hidpi: try: sett = iset.read() sett["graphics"]["hidpi"] = hi_dpi iset.set(sett) #hidpi = hi_dpi except: logger.exception("Exception occurred - Cannot Change DPI (dpi_set)") if ask_dpi() == True: rescan() menu = build_menu() systray.update(menu_options=menu) restart_server()
def toggle_clipboard(systray, state): global clipboard try: if state == True: phrase = "Enable" else: phrase = "Disable" if ask_clip(phrase): clipboard = state menu = build_menu() systray.update(menu_options=menu) sett = iset.read() sett["general"]["clipboard"] = clipboard iset.set(sett) restart_server() except Exception as e: logger.exception("Exception occurred - Cannot toggle clipboard")
def toggle_clipboard(systray, state): """Toggles the clipboard between Windows and WSL graphical apps being on/off. (Only functional in 3 default profiles)""" global clipboard try: if state == True: phrase = "Enable" else: phrase = "Disable" if ask_clip(phrase): clipboard = state menu = build_menu() systray.update(menu_options=menu) sett = iset.read() sett["general"]["clipboard"] = clipboard iset.set(sett) restart_server() except: logger.exception("Exception occurred - Cannot toggle clipboard")
def set_custom_profile(systray, profile): global current_custom_profile, display_mode try: if profile == current_custom_profile: return True if ask(): sett = iset.read() sett["graphics"]["window_mode"] = profile iset.set(sett) display_mode = "c" current_custom_profile = profile menu = build_menu() systray.update(hover_text=f"GWSL Running - {profile}", menu_options=menu) print("setting", profile) restart_server() except Exception as e: logger.exception("Exception occurred - Cannot switch to custom profile " + str(profile))
sett_path = os.getenv('APPDATA') + "\\GWSL\\errorbegin" if not os.path.isdir(sett_path): os.mkdir(sett_path) sys.exit() try: import ctypes import platform if int(platform.release()) >= 8: ctypes.windll.shcore.SetProcessDpiAwareness(True) except: logger.exception("Exception occurred - Cannot Set DPI Aware") try: mode = iset.read()["graphics"]["window_mode"] key = {"multi": "m", "single": "s", "full": "f"} try: if key[mode] == "m" or key[mode] == "s" or key[mode] == "f": print("We have a default!! Hooray!") display_mode = key[mode] clipboard = iset.read()["general"]["clipboard"] else: print("We have a custom profile") current_custom_profile = mode except: print("We have a custom profile") current_custom_profile = mode display_mode = "c" rescan()
def main(): """Main entry point for application""" global systray, display_mode, clipboard, exiter, ic, timer, audio_enabled # Kill VcXsrv if already running #if get_running(): we dont need to check do we... kill_server() kill_audio() # Start VcXsrv start_server() # Start audio try: sett = iset.read() audio_enabled = sett["general"]["pulseaudio"] except: pass start_audio() # Start Tray Icon menu = build_menu() if display_mode == "c": name = current_custom_profile else: mode_names = { "m": "Multi Window", "s": "Single Window", "f": "Fullscreen" } name = mode_names[display_mode] systray = tray(ic, f"GWSL Running - {name}", menu, default_menu_index=open_dashboard) systray.start() # start service listener timer = time.time() while True: try: #print(time.time() - timer) if time.time() - timer > 4: timer = time.time() if not get_running(): # In case someone closes a single-window server... restart as multi window. if display_mode == "s": display_mode = "m" menu = build_menu() systray.update( hover_text="GWSL Running - Multi Window", menu_options=menu) sett = iset.read() sett["graphics"]["window_mode"] = "multi" iset.set(sett) restart_server() elif ask_restart(): restart_server() else: systray.shutdown() kill_server() kill_audio() subprocess.getoutput('taskkill /F /IM GWSL.exe') sys.exit() if audio_enabled == True: if not get_audio_running(): #if pulseaudio crashes kill_audio() start_audio() if exiter: kill_server() kill_audio() subprocess.getoutput('taskkill /F /IM GWSL.exe') systray.shutdown() sys.exit() except: logger.exception("Exception occurred in main loop") kill_server() systray.shutdown() sys.exit() time.sleep(2) kill_server() systray.shutdown() sys.exit()