se

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

extension.h (3959B)


      1 #ifndef EXTENSION_H_
      2 #define EXTENSION_H_
      3 
      4 #include "se.h"
      5 
      6 struct extension {
      7         char* name;
      8         char* description;
      9 
     10 // standard functions
     11         void(*init)(struct extension* self);
     12         void(*frame)(void);
     13         void(*enable)(void);
     14         void(*disable)(void);
     15 
     16 /////////////////////////////////////////
     17 // callbacks
     18 //
     19 // A non-zero return value from an extension callback
     20 // will not call any further extensions that have the same callback.
     21 // This is necearry for any of the callbacks that have "return" values,
     22 // namely wb_new_line_draw, wb_write_status_bar
     23 // and wn_custom_window_keypress_override
     24 //
     25 
     26 
     27 // window buffer
     28         int(*wb_cursor_movement)(struct window_buffer* wb, enum cursor_reason reason);
     29 
     30         ///////////////////////////////////
     31         // string will be drawn at the start of a new line
     32         int(*wb_new_line_draw)(char** string, struct window_buffer* wb, int y, int lines_left, int minx, int maxx, struct glyph* attr);
     33 
     34         ///////////////////////////////////
     35         // write_again means the line will be written and the callback will
     36         // be called again with minx at the end line
     37         int(*wb_write_status_bar)(int* write_again, struct window_buffer* wb, int minx, int maxx, int cx, int cy, char line[LINE_MAX_LEN], struct glyph* g);
     38 
     39 
     40 // file buffer
     41         int(*fb_new_file_opened)(struct file_buffer* fb);
     42 
     43         int(*fb_paste)(struct file_buffer* fb, char* data, int len);
     44         int(*keypress)(KeySym keycode, int modkey, const char* buf, int len);
     45         int(*fb_written_to_file)(struct file_buffer* fb);
     46 
     47         ///////////////////////////////////
     48         // For undo functionality you can use this function to update the undo buffers
     49         // there is provided the fb_add_to_undo function, but you may implement your own
     50         // see buffer.h/buffer.c fb_add_to_undo()
     51         int(*fb_contents_updated)(struct file_buffer* fb, int offset, enum buffer_content_reason reason);
     52 
     53 
     54 // window node
     55         int(*wn_custom_window_draw)(struct window_split_node* wn);
     56         int(*window_written_to_screen)(struct window_split_node* wn, const int offset_start, const int offset_end, uint8_t* move_buffer, const int move_buffer_len);
     57         int(*wn_custom_window_keypress_override)(int* skip_keypress_callback, struct window_split_node* wn, KeySym keycode, int modkey, const char* buf, int len);
     58 };
     59 
     60 struct extension_meta {
     61         struct extension e;
     62         size_t enabled;
     63         size_t end;
     64 };
     65 
     66 #define extension_callback_exists(_callback, ...)                       \
     67         do {                                                            \
     68                 if (!extensions)                                        \
     69                         break;                                          \
     70                 for (int _iterator = 0; !extensions[_iterator].end; _iterator++) { \
     71                         if (extensions[_iterator].e._callback && extensions[_iterator].enabled) { \
     72                                 __VA_ARGS__                             \
     73                                 break;                                  \
     74                         }                                               \
     75                 }                                                       \
     76         } while (0)
     77 
     78 #define call_extension(_callback, ...)                                  \
     79         do {                                                            \
     80                 if (!extensions)                                        \
     81                         break;                                          \
     82                 for (int _iterator = 0; !extensions[_iterator].end; _iterator++) \
     83                         if (extensions[_iterator].e._callback && extensions[_iterator].enabled) \
     84                                 if (extensions[_iterator].e._callback(__VA_ARGS__)) \
     85                                         break;                          \
     86         } while (0)
     87 
     88 
     89 #endif // EXTENSION_H_