2 * Copyright (c) 2018, De Rais <derais@cock.li>
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
20 struct lws_client_connect_info
;
24 /* A thing that we can play */
25 struct playlist_entry
{
27 char *title
; /* What to show in the list */
28 int title_width
; /* How many cells the title takes to print */
29 char *uri
; /* How to get the bits */
30 char *runtime
; /* How long we have to sit through this */
31 int uid
; /* For being deleted, skipped to, queued after */
34 /* A list of playlist entries */
37 struct playlist_entry
*entries
;
39 int current_playing_uid
;
47 /* A thing said by a person */
50 char *user
; /* Who said it */
51 char *text
; /* What they said */
52 int special
; /* Whether this is really an announcement/poll/something */
55 /* Things said by people */
58 struct chat_msg
*msgs
;
62 /* User data passed to callbacks: all state */
65 Note that there is NO locking, because I don't care quite enough
66 to put it in, much less get it correct.
69 /* connection info; const are from argv and should not be free()d */
71 const char *channel_name
;
75 char *host
; /* address + port; free this */
76 /* Fucking layers on top of layers on top of insanity */
78 size_t stored_cmd_len
;
80 /* middleware stuff */
81 char *sid
; /* From socket.io's initialization */
82 time_t ping_interval
; /* Ping this often */
83 time_t last_ping
; /* When we ping'd last */
84 time_t last_playlist_req
; /* When we last requested playlist */
85 int established
; /* Have we seen LWS_CALLBACK_CLIENT_ESTABLISHED? */
86 /* application state - domain of state.c */
87 struct playlist playlist
; /* What the server tells us is queued */
88 struct chat_log chat_log
; /* What the clowns have said */
89 int please_die
; /* Should we shut down */
90 int must_write_ping
; /* Determining what to write */
91 int must_write_upgrade
; /* ^ */
92 int must_join_channel
; /* ^ */
93 int must_ask_for_playlist
; /* ^ */
94 /* UI state - domain of ui.c */
95 struct TermKey
*tk
; /* How to get a key pressed */
96 struct unibi_term
*ut
; /* How to talk to unibilium about terminfo */
97 int term_width
; /* Width of controlling term, in cells */
98 int term_height
; /* Height of controlling term, in cells */
99 int *dirty_line
; /* What we need to touch on next redraw */
100 int dirty_top
; /* Whether we should redraw [all of] top */
101 int dirty_playlist
; /* Whether we should redraw [all of] bottom */
102 size_t playlist_offset
; /* Index of first playlist entry displayed */
103 size_t playlist_hover_idx
; /* What entry in the playlist we're hovering over */
104 size_t pos_mid_line
; /* The y-position of the middle line */
105 size_t pos_hints_top
; /* The y-position of the first UI hint line */
106 int uri_or_chat
; /* 0: show chat, and 1: show URIs */
110 * cytube.c (libwebsockets, site-specific stuff)
113 /* Extract the ip-session cookie that sync demands */
115 cytube_get_session_cookie(const char *server
, const char *protocol
, const
116 char *port
, const char *channel
, struct state
119 /* Pass setup connection info (do this first) */
121 cytube_set_cci_and_s(struct lws_client_connect_info
*cci
, struct state
125 * launch.c (mpv spawning)
128 launch_only_once(const char *uri
);
131 * state.c (also includes some cytube-specific handling of emitted events)
134 state_clean(struct state
volatile *s
);
137 state_handle(struct state
volatile *s
, const char *msg
, size_t len
);
143 ui_init(struct state
volatile *s
);
146 ui_loop(struct state
volatile *s
);
152 /* snprintf + malloc + sprintf */
154 aprintf(const char *format
, ...);
156 /* strlen, but with wcwidth in the middle */
158 strwidth(const char *s
);