X11: Add support for custom window icon

This commit is contained in:
Ben Blank
2023-07-15 22:24:27 -07:00
parent 5d3ba9d35e
commit b1f557d98b
3 changed files with 57 additions and 32 deletions

View File

@@ -1183,3 +1183,23 @@ def cmdline_for_hold(cmd: Sequence[str] = (), opts: Optional['Options'] = None)
import shlex
shell = shlex.join(resolved_shell(opts))
return [kitten_exe(), 'run-shell', f'--shell={shell}', f'--shell-integration={ksi}'] + list(cmd)
def safe_mtime(path: str) -> Optional[float]:
with suppress(OSError):
return os.path.getmtime(path)
return None
@run_once
def get_custom_window_icon() -> Union[Tuple[float, str], Tuple[None, None]]:
filenames = ['kitty.app.png']
if is_macos:
# On macOS, prefer icns to png.
filenames.insert(0, 'kitty.app.icns')
for name in filenames:
custom_icon_path = os.path.join(config_dir, name)
custom_icon_mtime = safe_mtime(custom_icon_path)
if custom_icon_mtime is not None:
return custom_icon_mtime, custom_icon_path
return None, None