graphics.h (4385B)
1 2 #include <stdint.h> 3 #include <sys/types.h> 4 #include <X11/Xlib.h> 5 6 /// Initialize the graphics module. 7 void gr_init(Display *disp, Visual *vis, Colormap cm); 8 /// Deinitialize the graphics module. 9 void gr_deinit(); 10 11 /// Add an image rectangle to a list if rectangles to draw. This function may 12 /// actually draw some rectangles, or it may wait till more rectangles are 13 /// appended. Must be called between `gr_start_drawing` and `gr_finish_drawing`. 14 /// - `img_start_col..img_end_col` and `img_start_row..img_end_row` define the 15 /// part of the image to draw (row/col indices are zero-based, ends are 16 /// excluded). 17 /// - `x_col` and `y_row` are the coordinates of the top-left corner of the 18 /// image in the terminal grid. 19 /// - `x_pix` and `y_pix` are the same but in pixels. 20 /// - `reverse` indicates whether colors should be inverted. 21 void gr_append_imagerect(Drawable buf, uint32_t image_id, uint32_t placement_id, 22 int img_start_col, int img_end_col, int img_start_row, 23 int img_end_row, int x_col, int y_row, int x_pix, 24 int y_pix, int cw, int ch, int reverse); 25 /// Prepare for image drawing. `cw` and `ch` are dimensions of the cell. 26 void gr_start_drawing(Drawable buf, int cw, int ch); 27 /// Finish image drawing. This functions will draw all the rectangles left to 28 /// draw. 29 void gr_finish_drawing(Drawable buf); 30 /// Mark rows containing animations as dirty if it's time to redraw them. Must 31 /// be called right after `gr_start_drawing`. 32 void gr_mark_dirty_animations(int *dirty, int rows); 33 34 /// Parse and execute a graphics command. `buf` must start with 'G' and contain 35 /// at least `len + 1` characters (including '\0'). Returns 1 on success. 36 /// Additional informations is returned through `graphics_command_result`. 37 int gr_parse_command(char *buf, size_t len); 38 39 /// Executes `command` with the name of the file corresponding to `image_id` as 40 /// the argument. Executes xmessage with an error message on failure. 41 void gr_preview_image(uint32_t image_id, const char *command); 42 43 /// Executes `<st> -e less <file>` where <file> is the name of a temporary file 44 /// containing the information about an image and placement, and <st> is 45 /// specified with `st_executable`. 46 void gr_show_image_info(uint32_t image_id, uint32_t placement_id, 47 uint32_t imgcol, uint32_t imgrow, 48 char is_classic_placeholder, int32_t diacritic_count, 49 char *st_executable); 50 51 /// Dumps the internal state (images and placements) to stderr. 52 void gr_dump_state(); 53 54 /// Unloads images to reduce RAM usage. 55 void gr_unload_images_to_reduce_ram(); 56 57 /// Executes `callback` for each image cell. `callback` may return 1 to erase 58 /// the cell or 0 to keep it. This function is implemented in `st.c`. 59 void gr_for_each_image_cell(int (*callback)(void *data, uint32_t image_id, 60 uint32_t placement_id, int col, 61 int row, char is_classic), 62 void *data); 63 64 /// Marks all the rows containing the image with `image_id` as dirty. 65 void gr_schedule_image_redraw_by_id(uint32_t image_id); 66 67 typedef enum { 68 GRAPHICS_DEBUG_NONE = 0, 69 GRAPHICS_DEBUG_LOG = 1, 70 GRAPHICS_DEBUG_LOG_AND_BOXES = 2, 71 } GraphicsDebugMode; 72 73 /// Print additional information, draw bounding bounding boxes, etc. 74 extern GraphicsDebugMode graphics_debug_mode; 75 76 /// Whether to display images or just draw bounding boxes. 77 extern char graphics_display_images; 78 79 /// The time in milliseconds until the next redraw to update animations. 80 /// INT_MAX means no redraw is needed. Populated by `gr_finish_drawing`. 81 extern int graphics_next_redraw_delay; 82 83 #define MAX_GRAPHICS_RESPONSE_LEN 256 84 85 /// A structure representing the result of a graphics command. 86 typedef struct { 87 /// Indicates if the terminal needs to be redrawn. 88 char redraw; 89 /// The response of the command that should be sent back to the client 90 /// (may be empty if the quiet flag is set). 91 char response[MAX_GRAPHICS_RESPONSE_LEN]; 92 /// Whether there was an error executing this command (not very useful, 93 /// the response must be sent back anyway). 94 char error; 95 /// Whether the terminal has to create a placeholder for a non-virtual 96 /// placement. 97 char create_placeholder; 98 /// The placeholder that needs to be created. 99 struct { 100 uint32_t rows, columns; 101 uint32_t image_id, placement_id; 102 char do_not_move_cursor; 103 } placeholder; 104 } GraphicsCommandResult; 105 106 /// The result of a graphics command. 107 extern GraphicsCommandResult graphics_command_result;