Skip to content
This repository has been archived by the owner on May 28, 2023. It is now read-only.

Commit

Permalink
Reset resolution if necessary when exiting a game
Browse files Browse the repository at this point in the history
  • Loading branch information
cgarst committed Sep 19, 2020
1 parent dde1a2f commit e86cd6e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
3 changes: 2 additions & 1 deletion dist/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
gamestream_launchpad.zip
gamestream_launchpad.zip
.swp
Binary file modified dist/gamestream_launchpad.exe
Binary file not shown.
26 changes: 19 additions & 7 deletions gamestream_launchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
def windowEnumerationHandler(hwnd, top_windows):
top_windows.append((hwnd, win32gui.GetWindowText(hwnd)))


def set_resolution(gamestream_width, gamestream_height):
print("Switching resolution to {0}x{1}".format(gamestream_width, gamestream_height))
devmode = pywintypes.DEVMODEType()
devmode.PelsWidth = int(gamestream_width)
devmode.PelsHeight = int(gamestream_height)
devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
win32api.ChangeDisplaySettings(devmode, 0)


# Define a default config file to write if we're missing one
config_filename = 'gamestream_launchpad_cfg.ini'
default_config = """[LAUNCHER]
Expand Down Expand Up @@ -56,12 +66,7 @@ def windowEnumerationHandler(hwnd, top_windows):
sys.exit(1)

# Set resolution to target
print("Switching resolution to {0}x{1}".format(gamestream_width, gamestream_height))
devmode = pywintypes.DEVMODEType()
devmode.PelsWidth = int(gamestream_width)
devmode.PelsHeight = int(gamestream_height)
devmode.Fields = win32con.DM_PELSWIDTH | win32con.DM_PELSHEIGHT
win32api.ChangeDisplaySettings(devmode, 0)
set_resolution(gamestream_width, gamestream_height)

# Minimize all windows
print("Minimizing windows")
Expand Down Expand Up @@ -119,7 +124,14 @@ def windowEnumerationHandler(hwnd, top_windows):
print("Watching for Playnite to close")
while True:
if "Playnite.FullscreenApp.exe" in (p.name() for p in psutil.process_iter()):
sleep(3)
sleep(2)
# Check to ensure desired GSLP resolution is still set whenever the launcher is in focus in case it didn't reset when exiting a game
focused_window = win32gui.GetWindowText(win32gui.GetForegroundWindow())
if focused_window == "Playnite":
current_width = win32api.GetSystemMetrics(0)
current_height = win32api.GetSystemMetrics(1)
if current_width != gamestream_width and current_height != gamestream_height:
set_resolution(gamestream_width, gamestream_height)
else:
break

Expand Down

0 comments on commit e86cd6e

Please sign in to comment.