From aeedfbc7d8566386443b18e63be8c751d82235e1 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Sat, 12 Jul 2025 23:32:45 +0530 Subject: [PATCH] add special value listjson in panel output-name --- kitty/main.py | 19 ++++++++++++++++--- kitty/simple_cli_definitions.py | 3 ++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/kitty/main.py b/kitty/main.py index 4e916e7d8..51605d664 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # License: GPL v3 Copyright: 2016, Kovid Goyal +import json import locale import os import shutil @@ -222,13 +223,24 @@ def is_panel_kitten() -> bool: return _is_panel_kitten -def list_monitors() -> None: +def list_monitors(json_output: bool = False) -> None: monitor_names = glfw_get_monitor_names() has_descriptions = False for (name, desc) in monitor_names: if desc: has_descriptions = True break + + if json_output: + if has_descriptions: + monitors_list_of_dict = [{'name': name, 'desc': desc} for name, desc in monitor_names] + else: + monitors_list_of_dict = [{'name': name} for name, _ in monitor_names] + + json.dump(monitors_list_of_dict, sys.stdout) + print() + return + isatty = sys.stdout.isatty() for (name, desc) in monitor_names: if isatty: @@ -243,8 +255,9 @@ def list_monitors() -> None: def _run_app(opts: Options, args: CLIOptions, bad_lines: Sequence[BadLine] = (), talk_fd: int = -1) -> None: global _is_panel_kitten _is_panel_kitten = run_app.cached_values_name == 'panel' - if _is_panel_kitten and run_app.layer_shell_config and run_app.layer_shell_config.output_name == 'list': - list_monitors() + if _is_panel_kitten and run_app.layer_shell_config and run_app.layer_shell_config.output_name in ['list', 'listjson']: + is_json_output = run_app.layer_shell_config.output_name == 'listjson' + list_monitors(is_json_output) return if is_macos: global_shortcuts = set_cocoa_global_shortcuts(opts) diff --git a/kitty/simple_cli_definitions.py b/kitty/simple_cli_definitions.py index d7bb7bc36..709053ad7 100644 --- a/kitty/simple_cli_definitions.py +++ b/kitty/simple_cli_definitions.py @@ -660,7 +660,8 @@ Syntax: :italic:`name=value`. For example: :option:`kitty +kitten panel -o` font The panel can only be displayed on a single monitor (output) at a time. This allows you to specify which output is used, by name. If not specified the compositor will choose an output automatically, typically the last output the user interacted with or the primary monitor. -Use the special value :code:`list` to get a list of available outputs. +Use the special value :code:`list` to get a list of available outputs. Use :code:`listjson` for +a json encoded output. --class --app-id