Skip to content

Commit

Permalink
Update StayOnTop.py
Browse files Browse the repository at this point in the history
enable toggling between making a window always on top and disabling it
  • Loading branch information
DlgshKurd authored Nov 19, 2023
1 parent 64276c3 commit 1af07e7
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions StayOnTop.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
import win32gui
import win32con

def make_always_on_top(window):
win32gui.SetWindowPos(window._hWnd, win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
print(f'Success! {window.title} is now always on top.')
def toggle_always_on_top(window):
# Get the window style
style = win32gui.GetWindowLong(window._hWnd, win32con.GWL_EXSTYLE)

# Check if the window is currently set as always on top
if style & win32con.WS_EX_TOPMOST:
# If yes, remove the always on top style
win32gui.SetWindowPos(window._hWnd, win32con.HWND_NOTOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
print(f'Success! {window.title} is no longer always on top.')
else:
# If not, set the always on top style
win32gui.SetWindowPos(window._hWnd, win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
print(f'Success! {window.title} is now always on top.')

if __name__ == "__main__":
for i in range(3, 0, -1):
print(f"Switch to the window you want to stay on top. Countdown: {i}")
print(f"Switch to the window you want to toggle. Countdown: {i}")
time.sleep(1)

focused_window = gw.getActiveWindow()
make_always_on_top(focused_window)
toggle_always_on_top(focused_window)

0 comments on commit 1af07e7

Please sign in to comment.