Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions ntfy/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ def shell_output(cmd):
return check_output(shlex.split(cmd)).decode()


def tmux_is_focused():
if "TMUX" not in environ:
return False

cur_pane = environ['TMUX_PANE']

cmd = 'tmux list-panes -F "#{pane_id}:#{pane_active}:#{window_active}:#{session_attached}"'
panes = shell_output(cmd)

return True if panes.find(cur_pane + ':1:1:1') != -1 else False


def linux_window_is_focused():
xprop_cmd = shlex.split('xprop -root _NET_ACTIVE_WINDOW')
try:
Expand Down Expand Up @@ -67,9 +79,12 @@ def darwin_app_shell_is_focused():


def is_focused():
if "TMUX" in environ:
return tmux_is_focused()

if platform.startswith('linux') and environ.get('DISPLAY'):
return linux_window_is_focused()
elif platform == 'darwin':
return darwin_app_shell_is_focused()
else:
return False

return False