-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for SuperAltF4 button on Linux
- Added support for closing focused window on Linux using xdotool - Updated close_window function to handle Linux-specific window closing - Updated get_focused_window function to handle Linux-specific focused window retrieval - Updated commands.py to prevent taskkill while not on windows
- Loading branch information
Showing
3 changed files
with
52 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
from app.utils.platform import is_win | ||
from app.utils.platform import is_windows, is_linux | ||
|
||
if is_win: | ||
import subprocess | ||
if is_windows: | ||
import win32gui | ||
import win32con | ||
from app.utils.logger import log | ||
|
||
|
||
def close_window(window_title): | ||
if not is_win: | ||
log.error("This command is only available on Windows") | ||
raise RuntimeError("This command is only available on Windows") | ||
def close_window(window): | ||
if is_windows: | ||
# Find the window | ||
window_name = window | ||
hwnd = win32gui.FindWindow(None, window_name) | ||
if hwnd == 0: | ||
log.warning(f"Window with title '{window_name}' not found or already closed") | ||
raise RuntimeError(f"Window with title '{window_name}' not found or already closed") | ||
|
||
# Close the window | ||
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) | ||
|
||
# Find the window | ||
hwnd = win32gui.FindWindow(None, window_title) | ||
if hwnd == 0: | ||
log.warning(f"Window with title '{window_title}' not found or already closed") | ||
raise RuntimeError(f"Window with title '{window_title}' not found or already closed") | ||
elif is_linux: | ||
# While using Linux, the window name is the window ID | ||
window_id = window | ||
if subprocess.run(["xdotool", "windowclose", window_id]).returncode != 0: | ||
log.warning(f"Window with ID '{window_id}' not found or already closed") | ||
raise RuntimeError(f"Window with ID '{window_id}' not found or already closed") | ||
log.success(f"Window with ID '{window_id}' has been closed") | ||
|
||
# Close the window | ||
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) | ||
else: | ||
log.error("This command is not implemented for this platform.") | ||
raise RuntimeError("This command is not implemented for this platform.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,31 @@ | ||
from app.utils.platform import is_win | ||
from app.utils.platform import is_windows, is_linux | ||
|
||
if is_win: import win32gui | ||
if is_windows: import win32gui | ||
from app.utils.logger import log | ||
import subprocess | ||
|
||
|
||
def get_focused_window(): | ||
if not is_win: | ||
log.error("This command is only available on Windows") | ||
raise RuntimeError("This command is only available on Windows") | ||
if is_windows: | ||
hwnd = win32gui.GetForegroundWindow() | ||
if hwnd == 0: | ||
log.debug("No window has focus") | ||
return None | ||
else: | ||
window_title = win32gui.GetWindowText(hwnd) | ||
log.debug(f"Focused window: {window_title}") | ||
return window_title | ||
|
||
hwnd = win32gui.GetForegroundWindow() | ||
if hwnd == 0: | ||
log.debug("No window has focus") | ||
return None | ||
elif is_linux: | ||
try: | ||
window_id = subprocess.check_output(["xdotool", "getwindowfocus"], universal_newlines=True).strip() | ||
window_title = subprocess.check_output(["xdotool", "getwindowname", window_id], universal_newlines=True).strip() | ||
log.debug(f"Focused window: '{window_title}' ; window_id: '{window_id}'") | ||
return window_id | ||
except subprocess.CalledProcessError: | ||
log.debug("No window has focus") | ||
return None | ||
|
||
else: | ||
window_title = win32gui.GetWindowText(hwnd) | ||
log.debug(f"Focused window: {window_title}") | ||
return window_title | ||
log.error("This command is not implemented for this platform.") | ||
raise RuntimeError("This command is not implemented for this platform.") |