2323from collections .abc import Sequence
2424from typing import Optional
2525
26- from gi .repository import Adw , Gio
26+ from gi .repository import Adw , Gio , Xdp
2727
2828from gradia .ui .window import GradientWindow
2929from gradia .backend .logger import Logger
@@ -39,7 +39,7 @@ def __init__(self, version: str):
3939 flags = Gio .ApplicationFlags .HANDLES_COMMAND_LINE | Gio .ApplicationFlags .HANDLES_OPEN
4040 )
4141 self .version = version
42- self .screenshot_mode = False
42+ self .screenshot_flags : Optional [ Xdp . ScreenshotFlags ] = None
4343 self .temp_dirs : list [str ] = []
4444
4545 # Connect to shutdown signal for cleanup
@@ -50,7 +50,7 @@ def do_command_line(self, command_line: Gio.ApplicationCommandLine) -> int:
5050
5151 logging .debug (f"Command line arguments: { args } " )
5252
53- self .screenshot_mode = "--screenshot" in args
53+ self .screenshot_flags = self . _parse_screenshot_flag ( args )
5454 files_to_open = []
5555
5656 for arg in args :
@@ -74,6 +74,22 @@ def do_command_line(self, command_line: Gio.ApplicationCommandLine) -> int:
7474
7575 return 0
7676
77+ def _parse_screenshot_flag (self , args : list [str ]) -> Optional [Xdp .ScreenshotFlags ]:
78+ for arg in args :
79+ if arg .startswith ("--screenshot" ):
80+ if "=" in arg :
81+ mode = arg .split ("=" , 1 )[1 ].strip ().upper ()
82+ else :
83+ mode = "INTERACTIVE"
84+ if mode == "INTERACTIVE" :
85+ return Xdp .ScreenshotFlags .INTERACTIVE
86+ elif mode == "FULL" :
87+ return Xdp .ScreenshotFlags .NONE
88+ else :
89+ logging .warning (f"Unknown screenshot mode: { mode } . Defaulting to INTERACTIVE." )
90+ return Xdp .ScreenshotFlags .INTERACTIVE
91+ return None
92+
7793 def do_open (self , files : Sequence [Gio .File ], hint : str ):
7894 logging .debug (f"do_open called with files: { [file .get_path () for file in files ]} and hint: { hint } " )
7995 for file in files :
@@ -84,11 +100,10 @@ def do_open(self, files: Sequence[Gio.File], hint: str):
84100
85101 def do_activate (self ):
86102 logging .debug ("do_activate called" )
87- # Fallback if app is run without args and not via do_open/command_line
88103 self ._open_window (None )
89104
90105 def _open_window (self , file_path : Optional [str ]):
91- logging .debug (f"Opening window with file_path={ file_path } , screenshot_mode ={ self .screenshot_mode } " )
106+ logging .debug (f"Opening window with file_path={ file_path } , screenshot_flags ={ self .screenshot_flags } " )
92107 temp_dir = tempfile .mkdtemp ()
93108 logging .debug (f"Created temp directory: { temp_dir } " )
94109 self .temp_dirs .append (temp_dir )
@@ -97,7 +112,7 @@ def _open_window(self, file_path: Optional[str]):
97112 temp_dir = temp_dir ,
98113 version = self .version ,
99114 application = self ,
100- init_with_screenshot = self .screenshot_mode ,
115+ init_screenshot_mode = self .screenshot_flags ,
101116 file_path = file_path
102117 )
103118 window .build_ui ()
0 commit comments