2013-09-11 09:44:47 +04:00
# include <glib.h>
# include <spice.h>
2013-08-06 12:58:17 +04:00
# define IBUFSIZE 1024
# define MAX_ESC_PARAMS 16
2013-09-11 09:44:47 +04:00
typedef struct TextAttributes {
2013-09-12 16:23:57 +04:00
unsigned int fgcol : 4 ;
unsigned int bgcol : 4 ;
unsigned int bold : 1 ;
unsigned int uline : 1 ;
unsigned int blink : 1 ;
unsigned int invers : 1 ;
unsigned int unvisible : 1 ;
2013-09-13 11:53:24 +04:00
unsigned int selected : 1 ;
2013-09-11 09:44:47 +04:00
} TextAttributes ;
2013-08-06 12:58:17 +04:00
typedef struct TextCell {
2013-09-12 16:23:57 +04:00
gunichar2 ch ;
TextAttributes attrib ;
2013-08-06 12:58:17 +04:00
} TextCell ;
2013-10-09 15:34:06 +04:00
# define COMMANDS_SIZE (1024)
2013-10-08 14:20:43 +04:00
# define MAX_HEIGHT 1440
# define MAX_WIDTH 2560
2013-09-11 09:44:47 +04:00
2013-10-25 15:31:16 +04:00
typedef struct SpiceTermOptions {
guint timeout ;
int port ;
char * addr ;
2013-10-29 12:39:30 +04:00
char * keymap ;
2013-10-25 15:31:16 +04:00
gboolean noauth ;
gboolean sasl ;
} SpiceTermOptions ;
2013-09-11 13:57:01 +04:00
typedef struct SpiceScreen SpiceScreen ;
2013-09-11 09:44:47 +04:00
2013-10-08 11:57:57 +04:00
typedef struct CachedImage {
uint8_t * bitmap ;
int cache_id ;
} CachedImage ;
2013-09-11 13:57:01 +04:00
struct SpiceScreen {
2013-09-11 09:44:47 +04:00
SpiceCoreInterface * core ;
SpiceServer * server ;
QXLInstance qxl_instance ;
QXLWorker * qxl_worker ;
uint8_t primary_surface [ MAX_HEIGHT * MAX_WIDTH * 4 ] ;
int primary_height ;
int primary_width ;
SpiceTimer * conn_timeout_timer ;
SpiceWatch * mwatch ; /* watch master pty */
// Current mode (set by create_primary)
int width ;
int height ;
2015-02-27 18:40:45 +03:00
GCond command_cond ;
GMutex command_mutex ;
2013-09-11 09:44:47 +04:00
int commands_end ;
int commands_start ;
struct QXLCommandExt * commands [ COMMANDS_SIZE ] ;
2013-10-08 11:57:57 +04:00
//cache for glyphs bitmaps
GHashTable * image_cache ;
2013-10-09 15:09:51 +04:00
gboolean cursor_set ;
2013-10-08 11:57:57 +04:00
2013-09-11 09:44:47 +04:00
// callbacks
2013-09-11 13:57:01 +04:00
void ( * on_client_connected ) ( SpiceScreen * spice_screen ) ;
void ( * on_client_disconnected ) ( SpiceScreen * spice_screen ) ;
2013-09-11 09:44:47 +04:00
} ;
2013-10-25 15:31:16 +04:00
SpiceScreen * spice_screen_new ( SpiceCoreInterface * core , uint32_t width , uint32_t height , SpiceTermOptions * opts ) ;
2013-09-11 09:44:47 +04:00
2013-09-17 14:57:23 +04:00
void spice_screen_resize ( SpiceScreen * spice_screen , uint32_t width , uint32_t height ) ;
2013-09-11 15:15:53 +04:00
void spice_screen_draw_char ( SpiceScreen * spice_screen , int x , int y , gunichar2 ch , TextAttributes attrib ) ;
2013-09-11 13:57:01 +04:00
void spice_screen_scroll ( SpiceScreen * spice_screen , int x1 , int y1 , int x2 , int y2 , int src_x , int src_y ) ;
void spice_screen_clear ( SpiceScreen * spice_screen , int x1 , int y1 , int x2 , int y2 ) ;
uint32_t spice_screen_get_width ( void ) ;
uint32_t spice_screen_get_height ( void ) ;
2013-09-11 09:44:47 +04:00
2013-09-11 09:20:40 +04:00
typedef struct spiceTerm {
2013-09-17 14:57:23 +04:00
int pty ; // pty file descriptor
2013-08-06 12:58:17 +04:00
2013-09-12 16:23:57 +04:00
int width ;
int height ;
2013-08-06 12:58:17 +04:00
2013-09-12 16:23:57 +04:00
int total_height ;
int scroll_height ;
int y_base ;
int y_displ ;
int altbuf : 1 ;
unsigned int utf8 : 1 ; // utf8 mode
2013-10-17 11:04:20 +04:00
gunichar utf_char ; // used by utf8 parser
2013-09-12 16:23:57 +04:00
int utf_count ; // used by utf8 parser
TextAttributes default_attrib ;
TextCell * cells ;
TextCell * altcells ;
SpiceScreen * screen ;
SpiceKbdInstance keyboard_sin ;
SpiceCharDeviceInstance vdagent_sin ;
// cursor
TextAttributes cur_attrib ;
TextAttributes cur_attrib_saved ;
int tty_state ; // 0 - normal, 1 - ESC, 2 - CSI
int cx ; // cursor x position
int cy ; // cursor y position
int cx_saved ; // saved cursor x position
int cy_saved ; // saved cursor y position
int esc_buf [ MAX_ESC_PARAMS ] ;
int esc_count ;
int esc_ques ;
int esc_has_par ;
char osc_textbuf [ 4096 ] ;
char osc_cmd ;
int region_top ;
int region_bottom ;
unsigned int charset : 1 ; // G0 or G1
unsigned int charset_saved : 1 ; // G0 or G1
unsigned int g0enc : 2 ;
unsigned int g0enc_saved : 2 ;
unsigned int g1enc : 2 ;
unsigned int g1enc_saved : 2 ;
unsigned int cur_enc : 2 ;
unsigned int cur_enc_saved : 2 ;
// input buffer
char ibuf [ IBUFSIZE ] ;
int ibuf_count ;
gunichar2 * selection ;
int selection_len ;
unsigned int mark_active : 1 ;
unsigned int report_mouse : 1 ;
} spiceTerm ;
2013-10-17 10:44:52 +04:00
void init_spiceterm ( spiceTerm * vt , uint32_t width , uint32_t height ) ;
void spiceterm_refresh ( spiceTerm * vt ) ;
void spiceterm_resize ( spiceTerm * vt , uint32_t width , uint32_t height ) ;
void spiceterm_virtual_scroll ( spiceTerm * vt , int lines ) ;
void spiceterm_clear_selection ( spiceTerm * vt ) ;
void spiceterm_motion_event ( spiceTerm * vt , uint32_t x , uint32_t y ,
uint32_t buttons ) ;
void spiceterm_respond_esc ( spiceTerm * vt , const char * esc ) ;
void spiceterm_respond_data ( spiceTerm * vt , int len , uint8_t * data ) ;
void spiceterm_update_watch_mask ( spiceTerm * vt , gboolean writable ) ;
2013-10-25 15:31:16 +04:00
spiceTerm * spiceterm_create ( uint32_t width , uint32_t height , SpiceTermOptions * opts ) ;
2013-10-17 10:44:52 +04:00
gboolean vdagent_owns_clipboard ( spiceTerm * vt ) ;
void vdagent_request_clipboard ( spiceTerm * vt ) ;
void vdagent_grab_clipboard ( spiceTerm * vt ) ;
2013-10-23 12:57:11 +04:00
int pve_auth_verify ( const char * clientip , const char * username , const char * passwd ) ;
2013-10-25 15:31:16 +04:00
void pve_auth_set_path ( char * path ) ;
void pve_auth_set_permissions ( char * perm ) ;
2013-10-17 10:44:52 +04:00