+
+@dataclass
+class Recording:
+ process: subprocess.Popen[bytes]
+
+
+recording: Recording | None = None
+
+
+def make_filename() -> str:
+ directory = os.environ.get(
+ 'XDG_VIDEOS_DIR',
+ os.path.expanduser('~/Videos/SRec'))
+ os.makedirs(directory, exist_ok=True)
+ timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
+ return os.path.join(directory, f'srec {timestamp}.mkv')
+
+
+def video_source(stack: Gtk.Stack) -> list[str]:
+ if stack.get_child_by_name('not_recording').get_first_child().get_active():
+ return ['-f', 'x11grab', '-i', ':0.0+0,0']
+ return ['-f', 'v4l2', '-i', '/dev/video0']
+
+
+def find_size_display(stack: Gtk.Stack) -> Gtk.Label:
+ return stack.get_child_by_name(
+ 'recording').get_first_child().get_next_sibling()
+
+
+def summarize_size(n: int) -> str:
+ if n > 100_000_000:
+ m = int(n / (1024 * 1024))
+ return f'{m}M'
+ if n > 100_000:
+ k = int(n / 1024)
+ return f'{k}K'
+ return str(n)