]> git.proxmox.com Git - spiceterm.git/blob - spiceterm.h
3df2ef8cec0449cfbfbf15a3ccc073aca23b317c
[spiceterm.git] / spiceterm.h
1 #include <glib.h>
2 #include <spice.h>
3
4 #define IBUFSIZE 1024
5 #define MAX_ESC_PARAMS 16
6
7 typedef struct TextAttributes {
8 unsigned int fgcol:4;
9 unsigned int bgcol:4;
10 unsigned int bold:1;
11 unsigned int uline:1;
12 unsigned int blink:1;
13 unsigned int invers:1;
14 unsigned int unvisible:1;
15 unsigned int selected:1;
16 } TextAttributes;
17
18 typedef struct TextCell {
19 gunichar2 ch;
20 TextAttributes attrib;
21 } TextCell;
22
23 #define COMMANDS_SIZE (1024)
24 #define MAX_HEIGHT 1440
25 #define MAX_WIDTH 2560
26
27 typedef struct SpiceTermOptions {
28 guint timeout;
29 int port;
30 char *addr;
31 gboolean noauth;
32 gboolean sasl;
33 } SpiceTermOptions;
34
35 typedef struct SpiceScreen SpiceScreen;
36
37 typedef struct CachedImage {
38 uint8_t *bitmap;
39 int cache_id;
40 } CachedImage;
41
42 struct SpiceScreen {
43 SpiceCoreInterface *core;
44 SpiceServer *server;
45
46 QXLInstance qxl_instance;
47 QXLWorker *qxl_worker;
48
49 uint8_t primary_surface[MAX_HEIGHT * MAX_WIDTH * 4];
50 int primary_height;
51 int primary_width;
52
53 SpiceTimer *conn_timeout_timer;
54 SpiceWatch *mwatch; /* watch master pty */
55
56 // Current mode (set by create_primary)
57 int width;
58 int height;
59
60 GCond* command_cond;
61 GMutex* command_mutex;
62
63 int commands_end;
64 int commands_start;
65 struct QXLCommandExt* commands[COMMANDS_SIZE];
66
67 //cache for glyphs bitmaps
68 GHashTable *image_cache;
69
70 gboolean cursor_set;
71
72 // callbacks
73 void (*on_client_connected)(SpiceScreen *spice_screen);
74 void (*on_client_disconnected)(SpiceScreen *spice_screen);
75 };
76
77 SpiceScreen* spice_screen_new(SpiceCoreInterface* core, uint32_t width, uint32_t height, SpiceTermOptions *opts);
78
79 void spice_screen_resize(SpiceScreen *spice_screen, uint32_t width, uint32_t height);
80 void spice_screen_draw_char(SpiceScreen *spice_screen, int x, int y, gunichar2 ch, TextAttributes attrib);
81 void spice_screen_scroll(SpiceScreen *spice_screen, int x1, int y1, int x2, int y2, int src_x, int src_y);
82 void spice_screen_clear(SpiceScreen *spice_screen, int x1, int y1, int x2, int y2);
83 uint32_t spice_screen_get_width(void);
84 uint32_t spice_screen_get_height(void);
85
86 typedef struct spiceTerm {
87 int pty; // pty file descriptor
88
89 int width;
90 int height;
91
92 int total_height;
93 int scroll_height;
94 int y_base;
95 int y_displ;
96 int altbuf:1;
97
98 unsigned int utf8:1; // utf8 mode
99 gunichar utf_char; // used by utf8 parser
100 int utf_count; // used by utf8 parser
101
102 TextAttributes default_attrib;
103
104 TextCell *cells;
105 TextCell *altcells;
106
107 SpiceScreen *screen;
108 SpiceKbdInstance keyboard_sin;
109 SpiceCharDeviceInstance vdagent_sin;
110
111 // cursor
112 TextAttributes cur_attrib;
113 TextAttributes cur_attrib_saved;
114 int tty_state; // 0 - normal, 1 - ESC, 2 - CSI
115 int cx; // cursor x position
116 int cy; // cursor y position
117 int cx_saved; // saved cursor x position
118 int cy_saved; // saved cursor y position
119 int esc_buf[MAX_ESC_PARAMS];
120 int esc_count;
121 int esc_ques;
122 int esc_has_par;
123 char osc_textbuf[4096];
124 char osc_cmd;
125 int region_top;
126 int region_bottom;
127
128 unsigned int charset:1; // G0 or G1
129 unsigned int charset_saved:1; // G0 or G1
130 unsigned int g0enc:2;
131 unsigned int g0enc_saved:2;
132 unsigned int g1enc:2;
133 unsigned int g1enc_saved:2;
134 unsigned int cur_enc:2;
135 unsigned int cur_enc_saved:2;
136
137 // input buffer
138 char ibuf[IBUFSIZE];
139 int ibuf_count;
140
141 gunichar2 *selection;
142 int selection_len;
143
144 unsigned int mark_active:1;
145
146 unsigned int report_mouse:1;
147
148 } spiceTerm;
149
150 void init_spiceterm(spiceTerm *vt, uint32_t width, uint32_t height);
151 void spiceterm_refresh(spiceTerm *vt);
152
153 void spiceterm_resize(spiceTerm *vt, uint32_t width, uint32_t height);
154 void spiceterm_virtual_scroll(spiceTerm *vt, int lines);
155 void spiceterm_clear_selection(spiceTerm *vt);
156 void spiceterm_motion_event(spiceTerm *vt, uint32_t x, uint32_t y,
157 uint32_t buttons);
158
159 void spiceterm_respond_esc(spiceTerm *vt, const char *esc);
160 void spiceterm_respond_data(spiceTerm *vt, int len, uint8_t *data);
161 void spiceterm_update_watch_mask(spiceTerm *vt, gboolean writable);
162
163 spiceTerm *spiceterm_create(uint32_t width, uint32_t height, SpiceTermOptions *opts);
164
165 gboolean vdagent_owns_clipboard(spiceTerm *vt);
166 void vdagent_request_clipboard(spiceTerm *vt);
167 void vdagent_grab_clipboard(spiceTerm *vt);
168
169 int pve_auth_verify(const char *clientip, const char *username, const char *passwd);
170 void pve_auth_set_path(char *path);
171 void pve_auth_set_permissions(char *perm);
172