1 #ifndef HAVE_TUI_INT 2 3 #define REQID_COPYWINDOW 0xbaab 4 5 #ifndef COUNT_OF 6 #define COUNT_OF(x) \ 7 ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) 8 #endif 9 10 enum dirty_state { 11 DIRTY_NONE = 0, 12 DIRTY_CURSOR = 1, 13 DIRTY_PARTIAL = 2, 14 DIRTY_FULL = 4 15 }; 16 17 /* globally shared 'local copy/paste' target where tsm- screen 18 * data gets copy/pasted */ 19 static volatile _Atomic int paste_destination = -1; 20 21 struct color { 22 uint8_t rgb[3]; 23 uint8_t bg[3]; 24 bool bgset; 25 }; 26 27 struct tui_font; 28 struct tui_raster_context; 29 struct tui_context; 30 31 struct tui_context { 32 /* cfg->nal / state control */ 33 struct tsm_screen* screen; 34 struct tsm_utf8_mach* ucsconv; 35 struct tui_raster_context* raster; 36 37 /* BASE is the only allocation here, and front/back are aliases into it. We 38 * use the double- buffering as a refactoring stage to eventually get rid of 39 * the tsm_screen implementation and layer scrollback mode on top of the screen 40 * implementation rather than mixing them like it is done now. The base/front 41 * are compared and built into the packed tui_rasterer screen format */ 42 struct tui_cell* base; 43 struct tui_cell* front; 44 struct tui_cell* back; 45 uint8_t fstamp; 46 47 float progress[5]; 48 49 unsigned flags; 50 bool inactive, subseg; 51 int inact_timer; 52 53 /* font rendering / tracking - we support one main that defines cell size 54 * and one secondary that can be used for alternative glyphs */ 55 struct tui_font* font[2]; 56 57 float font_sz; /* size in mm */ 58 int hint; 59 int render_flags; 60 float ppcm; 61 enum dirty_state dirty; 62 63 /* mouse and/or selection management */ 64 int mouse_x, mouse_y; 65 uint32_t mouse_btnmask; 66 int lm_x, lm_y; 67 int bsel_x, bsel_y; 68 int last_dbl_x,last_dbl_y; 69 bool in_select; 70 int scrollback; 71 bool mouse_forward; 72 bool scroll_lock; 73 bool select_townd; 74 bool defocus; 75 76 /* if we receive a label set in mouse events, we switch to a different 77 * interpreteation where drag, click, dblclick, wheelup, wheeldown work */ 78 bool gesture_support; 79 80 /* color, cursor and other drawing states */ 81 int rows; 82 int cols; 83 84 /* track scrollback state so that we can send content-hints accordingly */ 85 long sbofs; 86 struct { 87 long ofs; 88 unsigned len; 89 struct arcan_event hint; 90 bool dirty; 91 } sbstat; 92 93 /* if the server-side has hinted with valid cell dimensions, skip probing */ 94 bool cell_auth; 95 int cell_w, cell_h, pad_w, pad_h; 96 int modifiers; 97 98 struct color colors[TUI_COL_LIMIT]; 99 100 bool cursor_off; /* current blink state */ 101 bool cursor_hard_off; /* user / state toggle */ 102 bool cursor_upd; /* invalidation, need to draw- old / new */ 103 int cursor_period; /* blink setting */ 104 struct { 105 bool active; 106 size_t row, col; 107 } last_cursor; 108 enum tui_cursors cursor; /* visual style */ 109 110 uint8_t alpha; 111 112 /* track last time counter we did update on to avoid overdraw */ 113 uint_fast32_t age; 114 115 /* upstream connection */ 116 struct arcan_shmif_cont acon; 117 struct arcan_shmif_cont clip_in; 118 struct arcan_shmif_cont clip_out; 119 120 /* retain these so that we can renegotiate on crash */ 121 struct arcan_event last_ident; 122 struct arcan_event last_state_sz; 123 124 /* cached after calls to tui_wndhint */ 125 struct tui_constraints last_constraints; 126 127 struct tsm_save_buf* pending_copy_window; 128 129 /* NEWSEGEMENT -> on_subwindow -> handover call chain */ 130 bool got_pending; 131 struct arcan_event pending_wnd; 132 133 /* caller- event handlers */ 134 struct tui_cbcfg handlers; 135 }; 136 137 /* ========================================================================== */ 138 /* SCREEN (tui_screen.c) related code */ 139 /* ========================================================================== */ 140 141 /* 142 * redraw and synchronise the output with our external source. 143 */ 144 int tui_screen_refresh(struct tui_context* tui); 145 146 /* 147 * cell dimensions or cell quantities has changed, rebuild the display 148 */ 149 void tui_screen_resized(struct tui_context* tui); 150 151 /* 152 * this is normally called from within refresh, but can be used to obtain 153 * a tpack representation of the screen front-buffer or back buffer. 154 * 155 * if [full] is set, the type generated will always be an I frame 156 * regardless of the dirty state of the window 157 * 158 * if [commit] is set, the contents of the back buffer will be synched 159 * to the front-buffer 160 * 161 * if [back] is set, the contents of the back buffer will be used 162 * rather than the front buffer 163 */ 164 struct tpack_gen_opts { 165 bool full; 166 bool synch; 167 bool back; 168 }; 169 170 int tui_screen_tpack(struct tui_context* tui, 171 struct tpack_gen_opts opts, uint8_t** rbuf, size_t* rbuf_sz); 172 173 /* ========================================================================== */ 174 /* DISPATCH (tui_dispatch.c) related code */ 175 /* ========================================================================== */ 176 177 bool tui_push_message(struct arcan_shmif_cont* tui, 178 struct arcan_event* base, const char* msg, size_t len); 179 180 /* 181 * Poll the incoming event queue on the tui segment, process TARGET events 182 * and forward IO events to 183 */ 184 void tui_event_poll(struct tui_context* tui); 185 186 /* 187 * necessary on setup and when having been 'reset' 188 */ 189 void tui_queue_requests(struct tui_context* tui, bool clipboard, bool ident); 190 191 /* ========================================================================== */ 192 /* CLIPBOARD (tui_clipboard.c) related code */ 193 /* ========================================================================== */ 194 195 /* 196 * Process events from the clipboard (if any), called from the main API impl. 197 * as part of the process stage if a clipboard / pasteboard is currently 198 * allocated. 199 */ 200 void tui_clipboard_check(struct tui_context* tui); 201 202 /* 203 * Set the selected text with len as the current clipboard output contents 204 */ 205 bool tui_clipboard_push(struct tui_context* tui, const char* sel, size_t len); 206 207 208 /* ========================================================================== */ 209 /* INPUT (tui_input.c) related code */ 210 /* ========================================================================== */ 211 212 /* 213 * Send LABELHINTs that mach the set of implemented inputs and bindings. 214 */ 215 void tui_expose_labels(struct tui_context* tui); 216 217 /* 218 * Should be routed into this function from the dispatch 219 */ 220 void tui_input_event( 221 struct tui_context* tui, arcan_ioevent* ioev, const char* label); 222 223 /* ========================================================================== */ 224 /* FONT (tui_fontmgr.c) related code */ 225 /* ========================================================================== */ 226 227 /* 228 * consume a FONTHINT event and apply the changes to the tui context 229 */ 230 void tui_fontmgmt_fonthint(struct tui_context* tui, struct arcan_tgtevent* ev); 231 232 /* 233 * setup / copy the font state from one context to another 234 */ 235 void tui_fontmgmt_inherit(struct tui_context* tui, struct tui_context* parent); 236 237 /* 238 * setup the font stat from the 'start' state provided from the connection 239 */ 240 void tui_fontmgmt_setup( 241 struct tui_context* tui, struct arcan_shmif_initial* init); 242 243 /* 244 * check if any of the attached fonts has a glyph for the specific codepoint 245 */ 246 bool tui_fontmgmt_hasglyph(struct tui_context* tui, uint32_t cp); 247 248 /* 249 * Call whenever the properties of the underlying fonts etc. has changed, 250 * may cause loading / unloading / build etc. 251 */ 252 void tui_fontmgmt_invalidate(struct tui_context* tui); 253 254 #endif 255