package miaou-driver-matrix

  1. Overview
  2. Docs

Source file matrix_config.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
(*****************************************************************************)
(*                                                                           *)
(* SPDX-License-Identifier: MIT                                              *)
(* Copyright (c) 2025 Nomadic Labs <contact@nomadic-labs.com>                *)
(*                                                                           *)
(*****************************************************************************)

type t = {
  fps_cap : int;
  frame_time_ms : float;
  tps_cap : int;
  tick_time_ms : float;
  scrub_interval_frames : int;
  debug : bool;
  enable_mouse : bool;
  handle_sigint : bool;
  inline_mode : bool;
}

let time_of_rate rate =
  let rate = max 1 (min 120 rate) in
  1000.0 /. float_of_int rate

let default =
  let fps_cap = 60 in
  let tps_cap = 60 in
  {
    fps_cap;
    frame_time_ms = time_of_rate fps_cap;
    tps_cap;
    tick_time_ms = time_of_rate tps_cap;
    scrub_interval_frames = 300;
    debug = false;
    enable_mouse = true;
    handle_sigint = true;
    inline_mode = false;
  }

let load () =
  let fps_cap =
    match Sys.getenv_opt "MIAOU_MATRIX_FPS" with
    | Some s -> (
        match int_of_string_opt s with
        | Some n when n >= 1 && n <= 120 -> n
        | _ -> 60)
    | None -> 60
  in
  let tps_cap =
    match Sys.getenv_opt "MIAOU_MATRIX_TPS" with
    | Some s -> (
        match int_of_string_opt s with
        | Some n when n >= 1 && n <= 120 -> n
        | _ -> 60)
    | None -> 60
  in
  let debug =
    match Sys.getenv_opt "MIAOU_MATRIX_DEBUG" with
    | Some ("1" | "true" | "TRUE" | "yes" | "YES") -> true
    | _ -> false
  in
  let scrub_interval_frames =
    match Sys.getenv_opt "MIAOU_MATRIX_SCRUB_FRAMES" with
    | Some s -> (
        match int_of_string_opt s with
        | Some n when n >= 0 && n <= 10000 -> n
        | _ -> 300)
    | None -> 300
  in
  let inline_mode =
    match Sys.getenv_opt "MIAOU_INLINE_MODE" with
    | Some ("1" | "true" | "TRUE" | "yes" | "YES") -> true
    | _ -> false
  in
  let enable_mouse =
    match Sys.getenv_opt "MIAOU_ENABLE_MOUSE" with
    | Some ("0" | "false" | "FALSE" | "no" | "NO") -> false
    | _ -> not inline_mode
    (* mouse tracking interferes with inline-mode copy/paste *)
  in
  {
    fps_cap;
    frame_time_ms = time_of_rate fps_cap;
    tps_cap;
    tick_time_ms = time_of_rate tps_cap;
    scrub_interval_frames;
    debug;
    enable_mouse;
    handle_sigint = true;
    inline_mode;
  }

let with_mouse_disabled config = {config with enable_mouse = false}