Initial commit: X11 C code editor
This commit is contained in:
commit
8eae6763f6
21 files changed
+36389
No files matched your search
@@ -0,0 +1,286 @@
|
||||
#ifndef EDITOR_H
|
||||
#define EDITOR_H
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/cursorfont.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
|
||||
#define MAX_LINES 4096
|
||||
#define MAX_LEN 1024
|
||||
#define FNAME_LEN 256
|
||||
#define STATUS_LEN 512
|
||||
#define SEARCH_LEN 256
|
||||
#define MAX_UNDO 128
|
||||
#define MAX_SYMBOLS 512
|
||||
#define SYM_NAME_LEN 64
|
||||
#define MAX_NAV_HISTORY 64
|
||||
#define MAX_TABS 16
|
||||
#define MAX_DIR_ENTRIES 1024
|
||||
|
||||
#define MENUBAR_H 26
|
||||
#define TABBAR_H 26
|
||||
#define TOP_UI_H (MENUBAR_H + TABBAR_H)
|
||||
#define GUTTER_W 52
|
||||
#define STATUS_H 24
|
||||
#define SCROLLBAR_W 14
|
||||
|
||||
typedef struct {
|
||||
char (*lines)[MAX_LEN];
|
||||
int num_lines;
|
||||
int cx, cy;
|
||||
} UndoStep;
|
||||
|
||||
typedef struct {
|
||||
char name[SYM_NAME_LEN];
|
||||
int line;
|
||||
} SymbolItem;
|
||||
|
||||
typedef struct {
|
||||
int cx, cy;
|
||||
} NavPoint;
|
||||
|
||||
typedef struct {
|
||||
char name[FNAME_LEN];
|
||||
int is_dir;
|
||||
} DirEntry;
|
||||
|
||||
typedef struct {
|
||||
char (*lines)[MAX_LEN];
|
||||
int num_lines;
|
||||
int cx, cy;
|
||||
int scroll_x, scroll_y;
|
||||
int has_sel, sel_ax, sel_ay;
|
||||
UndoStep undo_stack[MAX_UNDO];
|
||||
int undo_count;
|
||||
UndoStep redo_stack[MAX_UNDO];
|
||||
int redo_count;
|
||||
NavPoint nav_back[MAX_NAV_HISTORY];
|
||||
int nav_back_count;
|
||||
NavPoint nav_fwd[MAX_NAV_HISTORY];
|
||||
int nav_fwd_count;
|
||||
int dirty;
|
||||
int saved_undo_level;
|
||||
char filename[FNAME_LEN];
|
||||
} EditorTab;
|
||||
|
||||
typedef struct {
|
||||
Display *dpy;
|
||||
int screen;
|
||||
Window win;
|
||||
Cursor cursor_hand;
|
||||
int cursor_is_hand;
|
||||
int hover_btn;
|
||||
int pressed_btn;
|
||||
GC gc;
|
||||
Pixmap backbuf;
|
||||
int win_w, win_h;
|
||||
int running;
|
||||
|
||||
XIM xim;
|
||||
XIC xic;
|
||||
|
||||
XftFont *font;
|
||||
XftDraw *xft_draw;
|
||||
int char_w;
|
||||
int line_h;
|
||||
|
||||
unsigned long col_bg;
|
||||
unsigned long col_gutter;
|
||||
unsigned long col_curline;
|
||||
unsigned long col_sel;
|
||||
unsigned long col_match_all;
|
||||
unsigned long col_match_cur;
|
||||
unsigned long col_fg;
|
||||
unsigned long col_status;
|
||||
unsigned long col_sb_track;
|
||||
unsigned long col_sb_thumb;
|
||||
|
||||
XftColor xft_fg;
|
||||
XftColor xft_lineno;
|
||||
XftColor xft_kw;
|
||||
XftColor xft_type;
|
||||
XftColor xft_num;
|
||||
XftColor xft_str;
|
||||
XftColor xft_com;
|
||||
XftColor xft_mcom;
|
||||
XftColor xft_prep;
|
||||
XftColor xft_link;
|
||||
|
||||
/* Вкладки документов */
|
||||
EditorTab tabs[MAX_TABS];
|
||||
int num_tabs;
|
||||
int active_tab;
|
||||
int hover_tab;
|
||||
int hover_tab_close;
|
||||
|
||||
/* Активный документ (рабочий буфер) */
|
||||
char lines[MAX_LINES][MAX_LEN];
|
||||
int num_lines;
|
||||
int cx, cy;
|
||||
int scroll_x, scroll_y;
|
||||
|
||||
/* Главное меню и Navigation -> Список функций */
|
||||
int menu_open;
|
||||
int menu_sub_open;
|
||||
int menu_hover_item;
|
||||
int menu_hover_sym;
|
||||
int menu_sym_scroll;
|
||||
SymbolItem symbols[MAX_SYMBOLS];
|
||||
int num_symbols;
|
||||
|
||||
/* Подсветка функции по Ctrl + наведение */
|
||||
int hover_sym_line;
|
||||
int hover_sym_sx;
|
||||
int hover_sym_ex;
|
||||
int hover_sym_target;
|
||||
|
||||
/* Стек навигации (Назад / Вперед) */
|
||||
NavPoint nav_back[MAX_NAV_HISTORY];
|
||||
int nav_back_count;
|
||||
NavPoint nav_fwd[MAX_NAV_HISTORY];
|
||||
int nav_fwd_count;
|
||||
|
||||
/* Выделение текста */
|
||||
int has_sel;
|
||||
int sel_ax, sel_ay;
|
||||
int drag_select;
|
||||
|
||||
/* Буфер обмена X11 */
|
||||
Atom atom_clipboard;
|
||||
Atom atom_utf8;
|
||||
Atom atom_targets;
|
||||
Atom atom_prop;
|
||||
char *clip_data;
|
||||
|
||||
/* История Undo/Redo */
|
||||
UndoStep undo_stack[MAX_UNDO];
|
||||
int undo_count;
|
||||
UndoStep redo_stack[MAX_UNDO];
|
||||
int redo_count;
|
||||
|
||||
/* Поиск по тексту */
|
||||
int search_mode;
|
||||
int search_highlight_all;
|
||||
char search_query[SEARCH_LEN];
|
||||
int chk_x1, chk_x2;
|
||||
|
||||
/* Всплывающий файловый менеджер */
|
||||
int fbrowser_open;
|
||||
char fb_cwd[FNAME_LEN * 2];
|
||||
char fb_filter[64];
|
||||
DirEntry fb_entries[MAX_DIR_ENTRIES];
|
||||
int fb_count;
|
||||
int fb_selected;
|
||||
int fb_scroll;
|
||||
int fb_hover_btn; /* 0: Открыть, 1: Отмена, 2: Вверх (..) */
|
||||
int fb_last_click_idx;
|
||||
Time fb_last_click_time;
|
||||
|
||||
/* Диалог подтверждения закрытия (0: нет, 1: закрыть вкладку, 2: выход) */
|
||||
int confirm_mode;
|
||||
int confirm_target_tab;
|
||||
int confirm_hover_btn;
|
||||
|
||||
/* Сворачивание статус-бара */
|
||||
int status_collapsed;
|
||||
|
||||
/* Состояние файла и мигание курсора */
|
||||
int dirty;
|
||||
int saved_undo_level;
|
||||
int cursor_visible;
|
||||
|
||||
int drag_vscroll;
|
||||
int drag_hscroll;
|
||||
int drag_offset;
|
||||
|
||||
char filename[FNAME_LEN];
|
||||
char status_msg[STATUS_LEN];
|
||||
} Editor;
|
||||
|
||||
static inline int editor_status_h(const Editor *ed) {
|
||||
return ed->status_collapsed ? 0 : STATUS_H;
|
||||
}
|
||||
|
||||
/* UTF-8 утилиты (input/utf8.c) */
|
||||
int utf8_char_count(const char *s, int max_bytes);
|
||||
int utf8_byte_offset(const char *s, int char_idx);
|
||||
int utf8_prev_char_pos(const char *s, int byte_pos);
|
||||
int utf8_next_char_pos(const char *s, int byte_pos);
|
||||
|
||||
/* Выделение и вставка (input/text_ops.c) */
|
||||
void editor_ensure_cursor_visible(Editor *ed);
|
||||
void editor_get_sel_bounds(const Editor *ed, int *sy, int *sx, int *ey, int *ex);
|
||||
void editor_delete_selection(Editor *ed);
|
||||
void editor_insert_text(Editor *ed, const char *text);
|
||||
|
||||
/* file_io.c */
|
||||
void editor_set_dirty(Editor *ed, int dirty);
|
||||
void editor_load(Editor *ed, const char *fname);
|
||||
void editor_save(Editor *ed);
|
||||
void editor_open_system_dialog(Editor *ed);
|
||||
int editor_max_line_len(const Editor *ed);
|
||||
|
||||
/* tabs.c */
|
||||
void tabs_init(Editor *ed, int argc, char *argv[]);
|
||||
void tabs_new(Editor *ed, const char *fname);
|
||||
void tabs_open_file(Editor *ed, const char *fname);
|
||||
void tabs_switch(Editor *ed, int idx);
|
||||
void tabs_next(Editor *ed, int prev);
|
||||
void tabs_request_close(Editor *ed, int idx);
|
||||
void tabs_request_quit(Editor *ed);
|
||||
void tabs_close_force(Editor *ed, int idx);
|
||||
void tabs_free_all(Editor *ed);
|
||||
void tabs_render(Editor *ed);
|
||||
int tabs_handle_click(Editor *ed, int mx, int my, int button);
|
||||
int tabs_handle_motion(Editor *ed, int mx, int my);
|
||||
void confirm_render(Editor *ed);
|
||||
int confirm_handle_click(Editor *ed, int mx, int my);
|
||||
int confirm_handle_motion(Editor *ed, int mx, int my);
|
||||
void confirm_handle_key(Editor *ed, KeySym ks);
|
||||
|
||||
/* file_dialog.c */
|
||||
void fbrowser_show(Editor *ed);
|
||||
void fbrowser_render(Editor *ed);
|
||||
int fbrowser_handle_click(Editor *ed, int mx, int my, int button, Time time);
|
||||
int fbrowser_handle_motion(Editor *ed, int mx, int my);
|
||||
void fbrowser_handle_key(Editor *ed, KeySym ks, int ctrl, const char *buf, int n);
|
||||
|
||||
/* render/render_main.c */
|
||||
void editor_render(Editor *ed);
|
||||
|
||||
/* input/keyboard.c & input/mouse.c */
|
||||
void editor_handle_key(Editor *ed, XKeyEvent *kev);
|
||||
void editor_handle_button_press(Editor *ed, XButtonEvent *bev);
|
||||
void editor_handle_motion(Editor *ed, XMotionEvent *mev);
|
||||
void editor_handle_button_release(Editor *ed, XButtonEvent *bev);
|
||||
int mouse_update_cursor(Editor *ed, int mx, int my, unsigned int state);
|
||||
|
||||
/* clipboard.c */
|
||||
void clipboard_init(Editor *ed);
|
||||
void clipboard_copy(Editor *ed);
|
||||
void clipboard_request_paste(Editor *ed);
|
||||
void clipboard_handle_selection_request(Editor *ed, XSelectionRequestEvent *req);
|
||||
void clipboard_handle_selection_notify(Editor *ed, XSelectionEvent *sev);
|
||||
|
||||
/* history_search.c */
|
||||
void history_push_undo(Editor *ed);
|
||||
void history_undo(Editor *ed);
|
||||
void history_redo(Editor *ed);
|
||||
void history_free_all(Editor *ed);
|
||||
void search_find_next(Editor *ed, int from_cur_pos);
|
||||
void search_find_prev(Editor *ed);
|
||||
|
||||
/* menu.c */
|
||||
void menu_init(Editor *ed);
|
||||
void menu_refresh_symbols(Editor *ed);
|
||||
int menu_goto_symbol_at_cursor(Editor *ed);
|
||||
int menu_update_hover_symbol(Editor *ed, int mx, int my, unsigned int state);
|
||||
void nav_go_back(Editor *ed);
|
||||
void nav_go_forward(Editor *ed);
|
||||
void menu_render(Editor *ed);
|
||||
int menu_handle_click(Editor *ed, int mx, int my, int button);
|
||||
int menu_handle_motion(Editor *ed, int mx, int my);
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user