implement 'd' for downloading things
[cycon.git] / cycon.h
blob2c3fc4b89d004d2dc30adfe997dda158a94f3f55
1 /*
2 * Copyright (c) 2019, 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
7 * copies.
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.
19 /* FWdecl */
20 struct lws_client_connect_info;
21 struct TermKey;
22 struct unibi_term;
24 /* A thing that we can play */
25 struct playlist_entry {
26 /* */
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 */
35 struct playlist {
36 /* */
37 struct playlist_entry *entries;
38 size_t entries_len;
39 int current_playing_uid;
40 int paused;
41 int current_playtime;
42 int current_length;
43 int zero_clocktime;
44 int zero_playtime;
47 /* A thing said by a person */
48 struct chat_msg {
49 /* */
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 */
56 struct chat_log {
57 /* */
58 struct chat_msg *msgs;
59 size_t msgs_len;
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.
68 struct state {
69 /* An error message the server may have sent */
70 char *server_error;
72 /* connection info; const are from argv and should not be free()d */
73 const char *address;
74 const char *channel_name;
75 int https;
76 char *socket_host; /* oh joy, there are multiple servers to talk to */
77 /* Fucking layers on top of layers on top of insanity */
78 char *stored_cmd;
79 size_t stored_cmd_len;
81 /* middleware stuff */
82 char *sid; /* From socket.io's initialization */
83 time_t ping_interval; /* Ping this often */
84 time_t last_ping; /* When we ping'd last */
85 time_t last_playlist_req; /* When we last requested playlist */
86 int established; /* Have we seen LWS_CALLBACK_CLIENT_ESTABLISHED? */
87 /* application state - domain of state.c */
88 struct playlist playlist; /* What the server tells us is queued */
89 struct chat_log chat_log; /* What the clowns have said */
90 int please_die; /* Should we shut down */
91 int must_write_ping; /* Determining what to write */
92 int must_write_upgrade; /* ^ */
93 int must_join_channel; /* ^ */
94 int must_ask_for_playlist; /* ^ */
95 /* UI state - domain of ui.c */
96 struct TermKey *tk; /* How to get a key pressed */
97 struct unibi_term *ut; /* How to talk to unibilium about terminfo */
98 int term_width; /* Width of controlling term, in cells */
99 int term_height; /* Height of controlling term, in cells */
100 int *dirty_line; /* What we need to touch on next redraw */
101 int dirty_top; /* Whether we should redraw [all of] top */
102 int dirty_playlist; /* Whether we should redraw [all of] bottom */
103 size_t playlist_offset; /* Index of first playlist entry displayed */
104 size_t playlist_hover_idx; /* What entry in the playlist we're hovering over */
105 size_t pos_mid_line; /* The y-position of the middle line */
106 size_t pos_hints_top; /* The y-position of the first UI hint line */
107 int uri_or_chat; /* 0: show chat, and 1: show URIs */
111 * cytube.c (libwebsockets, site-specific stuff)
114 /* Extract the ip-session cookie that sync demands */
115 int cytube_get_session_cookie(const char *server, const char *protocol, const
116 char *channel, struct state volatile *s);
118 /* Pass setup connection info (do this first) */
119 void cytube_set_cci_and_s(struct lws_client_connect_info *cci, struct state
120 volatile *sp);
123 * launch.c (mpv/youtube-dl spawning)
125 void launch_downloader(const char *uri);
127 void launch_player(const char *uri);
130 * state.c (also includes some cytube-specific handling of emitted events)
132 void state_clean(struct state volatile *s);
133 int state_handle(struct state volatile *s, const char *msg, size_t len);
136 * ui.c
138 int ui_init(struct state volatile *s);
139 void ui_loop(struct state volatile *s);
142 * util.c
145 /* snprintf + malloc + sprintf */
146 char * aprintf(const char *format, ...);
148 /* strlen, but with wcwidth in the middle */
149 int strwidth(const char *s);