summaryrefslogtreecommitdiff
path: root/src/state.h
blob: 20e1a7b1ee14d053830429495b5396800854cbf4 (plain)
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
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * vfetch - neofetch but the ascii part is a video
 *
 * Copyright (C) 2026  Doan Luu Duc Tai
 *
 */

#ifndef SRC__STATE_H
#define SRC__STATE_H

#include <glib.h>
#include <pthread.h>
#include <stdbool.h>
#include <stddef.h>
#include <termios.h>
#include "audio_defs.h"
#include "config.h"

typedef struct AppState {
  VfetchArgs *args;
  gchar *video_specific_cache_root;
  gchar *current_args_cache_dir;
  gchar *live_fetch_output;
  gchar *fetch_command;
  AudioState audio_state;
  struct termios original_termios;
  gint64 media_sync_start_time;
  pthread_mutex_t audio_state_mutex;
  pthread_mutex_t fetch_mutex;
  pthread_mutex_t stdout_mutex;
  pthread_t signal_monitor_thread_id;
  pthread_t fetch_thread_id;
  _Atomic size_t ascii_frames_completed;
  _Atomic size_t last_fetch_lines;
  _Atomic size_t previous_fetch_lines;
  _Atomic bool terminal_resized;
  _Atomic bool exit_requested;
  _Atomic bool animation_has_started;
  _Atomic bool termios_saved;
  _Atomic bool cursor_visible;
  _Atomic bool processing_finished;
  _Atomic bool paused;
} AppState;

typedef struct ProgressThreadArgs {
  AppState *state;
  size_t total_frames;
} ProgressThreadArgs;

typedef struct FetchUpdaterArgs {
  AppState *state;
  VfetchArgs *args;
  bool verbose_flag;
  bool debug_flag;
} FetchUpdaterArgs;

/* Required for the POSIX signal handler, which has a fixed signature and cannot
 * be passed user context. This global is the standard mechanism for the handler
 * to access application state.
 * NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) */
extern AppState *global_signal_handler_state_ptr;

/* Required for the self-pipe mechanism, which allows the signal handler to
 * safely communicate with the main application thread.
 * NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) */
extern int global_signal_pipe[2];

#endif /* SRC__STATE_H */