3 Copyright (C) 2013 Proxmox Server Solutions GmbH
5 Copyright: spiceterm is under GNU GPL, the GNU General Public License.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; version 2 dated June, 1991.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 Author: Dietmar Maurer <dietmar@proxmox.com>
23 Note: most of the code here is copied from vncterm (which is
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <arpa/inet.h>
37 #include <pty.h> /* for openpty and forkpty */
40 #include <sys/ioctl.h>
45 #include "spiceterm.h"
49 #include <spice/enums.h>
50 #include <spice/macros.h>
51 #include <spice/qxl_dev.h>
53 #include <gdk/gdkkeysyms.h>
55 #include "event_loop.h"
56 #include "translations.h"
60 #define DPRINTF(x, format, ...) { \
62 printf("%s: " format "\n" , __FUNCTION__, ## __VA_ARGS__); \
68 #define TERMIDCODE "[?1;2c" // vt100 ID
70 #define CHECK_ARGC(argc,argv,i) if (i >= argc-1) { \
71 fprintf(stderr, "ERROR: not enough arguments for: %s\n", argv[i]); \
76 /* these colours are from linux kernel drivers/char/vt.c */
78 unsigned char color_table
[] = { 0, 4, 2, 6, 1, 5, 3, 7,
79 8,12,10,14, 9,13,11,15 };
83 print_usage(const char *msg
)
85 if (msg
) { fprintf(stderr
, "ERROR: %s\n", msg
); }
86 fprintf(stderr
, "USAGE: spiceterm [spiceopts] [-c command [args]]\n");
90 draw_char_at (spiceTerm
*vt
, int x
, int y
, gunichar2 ch
, TextAttributes attrib
)
92 if (x
< 0 || y
< 0 || x
>= vt
->width
|| y
>= vt
->height
) {
96 spice_screen_draw_char(vt
->screen
, x
, y
, ch
, attrib
);
100 spiceterm_update_xy (spiceTerm
*vt
, int x
, int y
)
102 if (x
< 0 || y
< 0 || x
>= vt
->width
|| y
>= vt
->height
) { return; }
104 int y1
= (vt
->y_base
+ y
) % vt
->total_height
;
105 int y2
= y1
- vt
->y_displ
;
107 y2
+= vt
->total_height
;
109 if (y2
< vt
->height
) {
110 TextCell
*c
= &vt
->cells
[y1
* vt
->width
+ x
];
111 draw_char_at (vt
, x
, y2
, c
->ch
, c
->attrib
);
116 spiceterm_clear_xy (spiceTerm
*vt
, int x
, int y
)
118 if (x
< 0 || y
< 0 || x
>= vt
->width
|| y
>= vt
->height
) { return; }
120 int y1
= (vt
->y_base
+ y
) % vt
->total_height
;
121 int y2
= y1
- vt
->y_displ
;
123 y2
+= vt
->total_height
;
125 if (y2
< vt
->height
) {
126 TextCell
*c
= &vt
->cells
[y1
* vt
->width
+ x
];
128 c
->attrib
= vt
->default_attrib
;
129 c
->attrib
.fgcol
= vt
->cur_attrib
.fgcol
;
130 c
->attrib
.bgcol
= vt
->cur_attrib
.bgcol
;
132 draw_char_at (vt
, x
, y
, c
->ch
, c
->attrib
);
137 spiceterm_toggle_marked_cell(spiceTerm
*vt
, int pos
)
139 int x
= (pos
%vt
->width
);
140 int y
= (pos
/vt
->width
);
142 if (x
< 0 || y
< 0 || x
>= vt
->width
|| y
>= vt
->height
) { return; }
144 int y1
= (vt
->y_base
+ y
) % vt
->total_height
;
145 int y2
= y1
- vt
->y_displ
;
147 y2
+= vt
->total_height
;
149 if (y2
< vt
->height
) {
150 TextCell
*c
= &vt
->cells
[y1
* vt
->width
+ x
];
151 c
->attrib
.selected
= c
->attrib
.selected
? 0 : 1;
152 spice_screen_draw_char(vt
->screen
, x
, y
, c
->ch
, c
->attrib
);
157 spiceterm_show_cursor (spiceTerm
*vt
, int show
)
160 if (x
>= vt
->width
) {
164 int y1
= (vt
->y_base
+ vt
->cy
) % vt
->total_height
;
165 int y
= y1
- vt
->y_displ
;
167 y
+= vt
->total_height
;
170 if (y
< vt
->height
) {
172 TextCell
*c
= &vt
->cells
[y1
* vt
->width
+ x
];
175 TextAttributes attrib
= vt
->default_attrib
;
176 attrib
.invers
= !(attrib
.invers
); /* invert fg and bg */
177 draw_char_at (vt
, x
, y
, c
->ch
, attrib
);
179 draw_char_at (vt
, x
, y
, c
->ch
, c
->attrib
);
185 spiceterm_refresh (spiceTerm
*vt
)
190 for(y
= 0; y
< vt
->height
; y
++) {
191 TextCell
*c
= vt
->cells
+ y1
* vt
->width
;
192 for(x
= 0; x
< vt
->width
; x
++) {
193 draw_char_at (vt
, x
, y
, c
->ch
, c
->attrib
);
196 if (++y1
== vt
->total_height
)
200 spiceterm_show_cursor (vt
, 1);
204 spiceterm_scroll_down (spiceTerm
*vt
, int top
, int bottom
, int lines
)
206 if ((top
+ lines
) >= bottom
) {
207 lines
= bottom
- top
-1;
210 if (top
< 0 || bottom
> vt
->height
|| top
>= bottom
|| lines
< 1) {
215 for(i
= bottom
- top
- lines
- 1; i
>= 0; i
--) {
216 int src
= ((vt
->y_base
+ top
+ i
) % vt
->total_height
)*vt
->width
;
217 int dst
= ((vt
->y_base
+ top
+ lines
+ i
) % vt
->total_height
)*vt
->width
;
219 memmove(vt
->cells
+ dst
, vt
->cells
+ src
, vt
->width
*sizeof (TextCell
));
222 for (i
= 0; i
< lines
; i
++) {
224 TextCell
*c
= vt
->cells
+ ((vt
->y_base
+ top
+ i
) % vt
->total_height
)*vt
->width
;
225 for(j
= 0; j
< vt
->width
; j
++) {
226 c
->attrib
= vt
->default_attrib
;
237 spice_screen_scroll(vt
->screen
, 0, y1
, vt
->screen
->primary_width
, y2
, 0, y0
);
238 spice_screen_clear(vt
->screen
, 0, y0
, vt
->screen
->primary_width
, y1
);
242 spiceterm_scroll_up (spiceTerm
*vt
, int top
, int bottom
, int lines
, int moveattr
)
244 if ((top
+ lines
) >= bottom
) {
245 lines
= bottom
- top
- 1;
248 if (top
< 0 || bottom
> vt
->height
|| top
>= bottom
|| lines
< 1) {
255 int y1
= (top
+ lines
)*16;
258 spice_screen_scroll(vt
->screen
, 0, y0
, vt
->screen
->primary_width
, y2
-h
, 0, y1
);
259 spice_screen_clear(vt
->screen
, 0, y2
-h
, vt
->screen
->primary_width
, y2
);
268 for(i
= 0; i
< (bottom
- top
- lines
); i
++) {
269 int dst
= ((vt
->y_base
+ top
+ i
) % vt
->total_height
)*vt
->width
;
270 int src
= ((vt
->y_base
+ top
+ lines
+ i
) % vt
->total_height
)*vt
->width
;
272 memmove(vt
->cells
+ dst
, vt
->cells
+ src
, vt
->width
*sizeof (TextCell
));
275 for (i
= 1; i
<= lines
; i
++) {
277 TextCell
*c
= vt
->cells
+ ((vt
->y_base
+ bottom
- i
) % vt
->total_height
)*vt
->width
;
278 for(j
= 0; j
< vt
->width
; j
++) {
279 c
->attrib
= vt
->default_attrib
;
287 spiceterm_virtual_scroll (spiceTerm
*vt
, int lines
)
289 if (vt
->altbuf
|| lines
== 0) return;
293 int i
= vt
->scroll_height
;
294 if (i
> vt
->total_height
- vt
->height
)
295 i
= vt
->total_height
- vt
->height
;
296 int y1
= vt
->y_base
- i
;
298 y1
+= vt
->total_height
;
299 for(i
= 0; i
< lines
; i
++) {
300 if (vt
->y_displ
== y1
) break;
301 if (--vt
->y_displ
< 0) {
302 vt
->y_displ
= vt
->total_height
- 1;
307 for(i
= 0; i
< lines
; i
++) {
308 if (vt
->y_displ
== vt
->y_base
) break;
309 if (++vt
->y_displ
== vt
->total_height
) {
315 spiceterm_refresh (vt
);
319 spiceterm_respond_esc (spiceTerm
*vt
, const char *esc
)
321 int len
= strlen (esc
);
324 if (vt
->ibuf_count
< (IBUFSIZE
- 1 - len
)) {
325 vt
->ibuf
[vt
->ibuf_count
++] = 27;
326 for (i
= 0; i
< len
; i
++) {
327 vt
->ibuf
[vt
->ibuf_count
++] = esc
[i
];
333 spiceterm_put_lf (spiceTerm
*vt
)
335 if (vt
->cy
+ 1 == vt
->region_bottom
) {
337 if (vt
->altbuf
|| vt
->region_top
!= 0 || vt
->region_bottom
!= vt
->height
) {
338 spiceterm_scroll_up (vt
, vt
->region_top
, vt
->region_bottom
, 1, 1);
342 if (vt
->y_displ
== vt
->y_base
) {
343 spiceterm_scroll_up (vt
, vt
->region_top
, vt
->region_bottom
, 1, 0);
346 if (vt
->y_displ
== vt
->y_base
) {
347 if (++vt
->y_displ
== vt
->total_height
) {
352 if (++vt
->y_base
== vt
->total_height
) {
356 if (vt
->scroll_height
< vt
->total_height
) {
360 int y1
= (vt
->y_base
+ vt
->height
- 1) % vt
->total_height
;
361 TextCell
*c
= &vt
->cells
[y1
* vt
->width
];
363 for (x
= 0; x
< vt
->width
; x
++) {
365 c
->attrib
= vt
->default_attrib
;
369 // fprintf (stderr, "BASE: %d DISPLAY %d\n", vt->y_base, vt->y_displ);
371 } else if (vt
->cy
< vt
->height
- 1) {
377 spiceterm_csi_m (spiceTerm
*vt
)
381 for (i
= 0; i
< vt
->esc_count
; i
++) {
382 switch (vt
->esc_buf
[i
]) {
383 case 0: /* reset all console attributes to default */
384 vt
->cur_attrib
= vt
->default_attrib
;
387 vt
->cur_attrib
.bold
= 1;
390 vt
->cur_attrib
.uline
= 1;
393 vt
->cur_attrib
.blink
= 1;
396 vt
->cur_attrib
.invers
= 1;
399 vt
->cur_attrib
.unvisible
= 1;
402 vt
->cur_enc
= LAT1_MAP
;
403 // fixme: dispaly controls = 0 ?
404 // fixme: toggle meta = 0 ?
407 vt
->cur_enc
= IBMPC_MAP
;
408 // fixme: dispaly controls = 1 ?
409 // fixme: toggle meta = 0 ?
412 vt
->cur_enc
= IBMPC_MAP
;
413 // fixme: dispaly controls = 1 ?
414 // fixme: toggle meta = 1 ?
417 vt
->cur_attrib
.bold
= 0;
420 vt
->cur_attrib
.uline
= 0;
423 vt
->cur_attrib
.blink
= 0;
426 vt
->cur_attrib
.invers
= 0;
429 vt
->cur_attrib
.unvisible
= 0;
439 /* set foreground color */
440 vt
->cur_attrib
.fgcol
= color_table
[vt
->esc_buf
[i
] - 30];
443 /* reset color to default, enable underline */
444 vt
->cur_attrib
.fgcol
= vt
->default_attrib
.fgcol
;
445 vt
->cur_attrib
.uline
= 1;
448 /* reset color to default, disable underline */
449 vt
->cur_attrib
.fgcol
= vt
->default_attrib
.fgcol
;
450 vt
->cur_attrib
.uline
= 0;
460 /* set background color */
461 vt
->cur_attrib
.bgcol
= color_table
[vt
->esc_buf
[i
] - 40];
464 /* reset background color */
465 vt
->cur_attrib
.bgcol
= vt
->default_attrib
.bgcol
;
468 fprintf(stderr
, "unhandled ESC[%d m code\n",vt
->esc_buf
[i
]);
475 spiceterm_save_cursor (spiceTerm
*vt
)
477 vt
->cx_saved
= vt
->cx
;
478 vt
->cy_saved
= vt
->cy
;
479 vt
->cur_attrib_saved
= vt
->cur_attrib
;
480 vt
->charset_saved
= vt
->charset
;
481 vt
->g0enc_saved
= vt
->g0enc
;
482 vt
->g1enc_saved
= vt
->g1enc
;
483 vt
->cur_enc_saved
= vt
->cur_enc
;
487 spiceterm_restore_cursor (spiceTerm
*vt
)
489 vt
->cx
= vt
->cx_saved
;
490 vt
->cy
= vt
->cy_saved
;
491 vt
->cur_attrib
= vt
->cur_attrib_saved
;
492 vt
->charset
= vt
->charset_saved
;
493 vt
->g0enc
= vt
->g0enc_saved
;
494 vt
->g1enc
= vt
->g1enc_saved
;
495 vt
->cur_enc
= vt
->cur_enc_saved
;
499 spiceterm_set_alternate_buffer (spiceTerm
*vt
, int on_off
)
503 vt
->y_displ
= vt
->y_base
;
507 if (vt
->altbuf
) return;
511 /* alternate buffer & cursor */
513 spiceterm_save_cursor (vt
);
514 /* save screen to altcels */
515 for (y
= 0; y
< vt
->height
; y
++) {
516 int y1
= (vt
->y_base
+ y
) % vt
->total_height
;
517 for (x
= 0; x
< vt
->width
; x
++) {
518 vt
->altcells
[y
*vt
->width
+ x
] = vt
->cells
[y1
*vt
->width
+ x
];
523 for (y
= 0; y
<= vt
->height
; y
++) {
524 for (x
= 0; x
< vt
->width
; x
++) {
525 spiceterm_clear_xy (vt
, x
, y
);
531 if (vt
->altbuf
== 0) return;
535 /* restore saved data */
536 for (y
= 0; y
< vt
->height
; y
++) {
537 int y1
= (vt
->y_base
+ y
) % vt
->total_height
;
538 for (x
= 0; x
< vt
->width
; x
++) {
539 vt
->cells
[y1
*vt
->width
+ x
] = vt
->altcells
[y
*vt
->width
+ x
];
543 spiceterm_restore_cursor (vt
);
546 spiceterm_refresh (vt
);
550 spiceterm_set_mode (spiceTerm
*vt
, int on_off
)
554 for (i
= 0; i
<= vt
->esc_count
; i
++) {
555 if (vt
->esc_ques
) { /* DEC private modes set/reset */
556 switch(vt
->esc_buf
[i
]) {
557 case 10: /* X11 mouse reporting on/off */
558 case 1000: /* SET_VT200_MOUSE */
559 case 1002: /* xterm SET_BTN_EVENT_MOUSE */
560 vt
->report_mouse
= on_off
;
562 case 1049: /* start/end special app mode (smcup/rmcup) */
563 spiceterm_set_alternate_buffer (vt
, on_off
);
565 case 25: /* Cursor on/off */
566 case 9: /* X10 mouse reporting on/off */
567 case 6: /* Origin relative/absolute */
568 case 1: /* Cursor keys in appl mode*/
569 case 5: /* Inverted screen on/off */
570 case 7: /* Autowrap on/off */
571 case 8: /* Autorepeat on/off */
574 } else { /* ANSI modes set/reset */
575 //g_assert_not_reached();
577 /* fixme: implement me */
583 spiceterm_gotoxy (spiceTerm
*vt
, int x
, int y
)
585 /* verify all boundaries */
591 if (x
>= vt
->width
) {
601 if (y
>= vt
->height
) {
609 debug_print_escape_buffer(spiceTerm
*vt
, const char *func
, const char *prefix
,
610 const char *qes
, gunichar2 ch
)
613 if (vt
->esc_count
== 0) {
614 printf("%s:%s ESC[%s%c\n", func
, prefix
, qes
, ch
);
615 } else if (vt
->esc_count
== 1) {
616 printf("%s:%s ESC[%s%d%c\n", func
, prefix
, qes
, vt
->esc_buf
[0], ch
);
619 printf("%s:%s ESC[%s%d", func
, prefix
, qes
, vt
->esc_buf
[0]);
620 for (i
= 1; i
< vt
->esc_count
; i
++) {
621 printf(";%d", vt
->esc_buf
[i
]);
628 enum { ESnormal
, ESesc
, ESsquare
, ESgetpars
, ESgotpars
, ESfunckey
,
629 EShash
, ESsetG0
, ESsetG1
, ESpercent
, ESignore
, ESnonstd
,
630 ESpalette
, ESidquery
, ESosc1
, ESosc2
};
633 spiceterm_putchar (spiceTerm
*vt
, gunichar2 ch
)
637 if (debug
&& !vt
->tty_state
) {
638 DPRINTF(1, "CHAR:%2d: %4x '%c' (cur_enc %d) %d %d",
639 vt
->tty_state
, ch
, ch
, vt
->cur_enc
, vt
->cx
, vt
->cy
);
642 switch(vt
->tty_state
) {
644 vt
->tty_state
= ESnormal
;
647 vt
->tty_state
= ESsquare
;
650 vt
->tty_state
= ESnonstd
;
653 vt
->tty_state
= ESpercent
;
656 spiceterm_save_cursor (vt
);
659 spiceterm_restore_cursor (vt
);
662 vt
->tty_state
= ESsetG0
; // SET G0
665 vt
->tty_state
= ESsetG1
; // SET G1
669 if (vt
->cy
== vt
->region_top
)
670 spiceterm_scroll_down (vt
, vt
->region_top
, vt
->region_bottom
, 1);
671 else if (vt
->cy
> 0) {
676 /* numeric keypad - ignored */
679 /* appl. keypad - ignored */
682 DPRINTF(1, "got unhandled ESC%c %d", ch
, ch
);
686 case ESnonstd
: /* Operating System Controls */
687 vt
->tty_state
= ESnormal
;
690 case 'P': /* palette escape sequence */
691 for(i
= 0; i
< MAX_ESC_PARAMS
; i
++) {
696 vt
->tty_state
= ESpalette
;
698 case 'R': /* reset palette */
699 // fixme: reset_palette(vc);
706 vt
->osc_textbuf
[0] = 0;
707 vt
->tty_state
= ESosc1
;
710 DPRINTF(1, "got unhandled OSC %c", ch
);
711 vt
->tty_state
= ESnormal
;
716 vt
->tty_state
= ESnormal
;
718 vt
->tty_state
= ESosc2
;
720 DPRINTF(1, "got illegal OSC sequence");
724 if (ch
!= 0x9c && ch
!= 7) {
726 while (vt
->osc_textbuf
[i
]) i
++;
727 vt
->osc_textbuf
[i
++] = ch
;
728 vt
->osc_textbuf
[i
] = 0;
730 DPRINTF(1, "OSC:%c:%s", vt
->osc_cmd
, vt
->osc_textbuf
);
731 vt
->tty_state
= ESnormal
;
735 if ((ch
>= '0' && ch
<= '9') || (ch
>= 'A' && ch
<= 'F')
736 || (ch
>= 'a' && ch
<= 'f')) {
737 vt
->esc_buf
[vt
->esc_count
++] = (ch
> '9' ? (ch
& 0xDF) - 'A' + 10 : ch
- '0');
738 if (vt
->esc_count
== 7) {
739 // fixme: this does not work - please test
741 rfbColourMap *cmap =&vt->screen->colourMap;
743 int i = color_table[vt->esc_buf[0]] * 3, j = 1;
744 cmap->data.bytes[i] = 16 * vt->esc_buf[j++];
745 cmap->data.bytes[i++] += vt->esc_buf[j++];
746 cmap->data.bytes[i] = 16 * vt->esc_buf[j++];
747 cmap->data.bytes[i++] += vt->esc_buf[j++];
748 cmap->data.bytes[i] = 16 * vt->esc_buf[j++];
749 cmap->data.bytes[i] += vt->esc_buf[j];
753 vt
->tty_state
= ESnormal
;
756 vt
->tty_state
= ESnormal
;
759 for(i
= 0; i
< MAX_ESC_PARAMS
; i
++) {
765 vt
->tty_state
= ESgetpars
;
768 vt
->tty_state
= ESidquery
;
772 if ((vt
->esc_ques
= (ch
== '?'))) {
776 if (ch
>= '0' && ch
<= '9') {
778 if (vt
->esc_count
< MAX_ESC_PARAMS
) {
779 vt
->esc_buf
[vt
->esc_count
] = vt
->esc_buf
[vt
->esc_count
] * 10 + ch
- '0';
782 } else if (ch
== ';') {
786 if (vt
->esc_has_par
) {
789 vt
->tty_state
= ESgotpars
;
793 vt
->tty_state
= ESnormal
;
795 char *qes
= vt
->esc_ques
? "?" : "";
798 debug_print_escape_buffer(vt
, __func__
, "", qes
, ch
);
803 spiceterm_set_mode(vt
, 1);
806 spiceterm_set_mode(vt
, 0);
809 if (!vt
->esc_count
) {
810 vt
->esc_count
++; // default parameter 0
812 spiceterm_csi_m (vt
);
815 /* report cursor position */
816 /* TODO: send ESC[row;colR */
820 if (vt
->esc_buf
[0] == 0) {
823 vt
->cy
-= vt
->esc_buf
[0];
830 /* move cursor down */
831 if (vt
->esc_buf
[0] == 0) {
834 vt
->cy
+= vt
->esc_buf
[0];
835 if (vt
->cy
>= vt
->height
) {
836 vt
->cy
= vt
->height
- 1;
841 /* move cursor right */
842 if (vt
->esc_buf
[0] == 0) {
845 vt
->cx
+= vt
->esc_buf
[0];
846 if (vt
->cx
>= vt
->width
) {
847 vt
->cx
= vt
->width
- 1;
851 /* move cursor left */
852 if (vt
->esc_buf
[0] == 0) {
855 vt
->cx
-= vt
->esc_buf
[0];
862 /* move cursor to column */
863 spiceterm_gotoxy (vt
, vt
->esc_buf
[0] - 1, vt
->cy
);
866 /* move cursor to row */
867 spiceterm_gotoxy (vt
, vt
->cx
, vt
->esc_buf
[0] - 1);
871 /* move cursor to row, column */
872 spiceterm_gotoxy (vt
, vt
->esc_buf
[1] - 1, vt
->esc_buf
[0] - 1);
875 switch (vt
->esc_buf
[0]) {
877 /* clear to end of screen */
878 for (y
= vt
->cy
; y
< vt
->height
; y
++) {
879 for (x
= 0; x
< vt
->width
; x
++) {
880 if (y
== vt
->cy
&& x
< vt
->cx
) {
883 spiceterm_clear_xy (vt
, x
, y
);
888 /* clear from beginning of screen */
889 for (y
= 0; y
<= vt
->cy
; y
++) {
890 for (x
= 0; x
< vt
->width
; x
++) {
891 if (y
== vt
->cy
&& x
> vt
->cx
) {
894 spiceterm_clear_xy (vt
, x
, y
);
899 /* clear entire screen */
900 for (y
= 0; y
<= vt
->height
; y
++) {
901 for (x
= 0; x
< vt
->width
; x
++) {
902 spiceterm_clear_xy (vt
, x
, y
);
909 switch (vt
->esc_buf
[0]) {
912 for(x
= vt
->cx
; x
< vt
->width
; x
++) {
913 spiceterm_clear_xy (vt
, x
, vt
->cy
);
917 /* clear from beginning of line */
918 for (x
= 0; x
<= vt
->cx
; x
++) {
919 spiceterm_clear_xy (vt
, x
, vt
->cy
);
923 /* clear entire line */
924 for(x
= 0; x
< vt
->width
; x
++) {
925 spiceterm_clear_xy (vt
, x
, vt
->cy
);
934 if (c
> vt
->height
- vt
->cy
)
935 c
= vt
->height
- vt
->cy
;
939 spiceterm_scroll_down (vt
, vt
->cy
, vt
->region_bottom
, c
);
945 if (c
> vt
->height
- vt
->cy
)
946 c
= vt
->height
- vt
->cy
;
950 spiceterm_scroll_up (vt
, vt
->cy
, vt
->region_bottom
, c
, 1);
956 spiceterm_scroll_down (vt
, vt
->region_top
, vt
->region_bottom
, c
);
962 spiceterm_scroll_up (vt
, vt
->region_top
, vt
->region_bottom
, c
, 1);
965 /* delete c character */
968 if (c
> vt
->width
- vt
->cx
)
969 c
= vt
->width
- vt
->cx
;
973 for (x
= vt
->cx
; x
< vt
->width
- c
; x
++) {
974 int y1
= (vt
->y_base
+ vt
->cy
) % vt
->total_height
;
975 TextCell
*dst
= &vt
->cells
[y1
* vt
->width
+ x
];
976 TextCell
*src
= dst
+ c
;
978 spiceterm_update_xy (vt
, x
+ c
, vt
->cy
);
980 src
->attrib
= vt
->default_attrib
;
981 spiceterm_update_xy (vt
, x
, vt
->cy
);
985 /* save cursor position */
986 spiceterm_save_cursor (vt
);
989 /* restore cursor position */
990 spiceterm_restore_cursor (vt
);
993 /* erase c characters */
997 if (c
> (vt
->width
- vt
->cx
)) c
= vt
->width
- vt
->cx
;
999 for(i
= 0; i
< c
; i
++) {
1000 spiceterm_clear_xy (vt
, vt
->cx
+ i
, vt
->cy
);
1004 /* insert c character */
1006 if (c
> (vt
->width
- vt
->cx
)) {
1007 c
= vt
->width
- vt
->cx
;
1011 for (x
= vt
->width
- c
; x
>= vt
->cx
; x
--) {
1012 int y1
= (vt
->y_base
+ vt
->cy
) % vt
->total_height
;
1013 TextCell
*src
= &vt
->cells
[y1
* vt
->width
+ x
];
1014 TextCell
*dst
= src
+ c
;
1016 spiceterm_update_xy (vt
, x
+ c
, vt
->cy
);
1018 src
->attrib
= vt
->cur_attrib
;
1019 spiceterm_update_xy (vt
, x
, vt
->cy
);
1025 if (!vt
->esc_buf
[0])
1027 if (!vt
->esc_buf
[1])
1028 vt
->esc_buf
[1] = vt
->height
;
1029 /* Minimum allowed region is 2 lines */
1030 if (vt
->esc_buf
[0] < vt
->esc_buf
[1] &&
1031 vt
->esc_buf
[1] <= vt
->height
) {
1032 vt
->region_top
= vt
->esc_buf
[0] - 1;
1033 vt
->region_bottom
= vt
->esc_buf
[1];
1035 vt
->cy
= vt
->region_top
;
1036 DPRINTF(1, "set region %d %d", vt
->region_top
, vt
->region_bottom
);
1042 debug_print_escape_buffer(vt
, __func__
, " unhandled escape", qes
, ch
);
1048 case ESsetG0
: // Set G0
1049 vt
->tty_state
= ESnormal
;
1052 vt
->g0enc
= GRAF_MAP
;
1054 vt
->g0enc
= LAT1_MAP
;
1056 vt
->g0enc
= IBMPC_MAP
;
1058 vt
->g0enc
= USER_MAP
;
1060 if (vt
->charset
== 0)
1061 vt
->cur_enc
= vt
->g0enc
;
1064 case ESsetG1
: // Set G1
1065 vt
->tty_state
= ESnormal
;
1068 vt
->g1enc
= GRAF_MAP
;
1070 vt
->g1enc
= LAT1_MAP
;
1072 vt
->g1enc
= IBMPC_MAP
;
1074 vt
->g1enc
= USER_MAP
;
1076 if (vt
->charset
== 1)
1077 vt
->cur_enc
= vt
->g1enc
;
1080 case ESidquery
: // vt100 query id
1081 vt
->tty_state
= ESnormal
;
1084 DPRINTF(1, "ESC[>c Query term ID");
1085 spiceterm_respond_esc (vt
, TERMIDCODE
);
1089 vt
->tty_state
= ESnormal
;
1091 case '@': /* defined in ISO 2022 */
1094 case 'G': /* prelim official escape code */
1095 case '8': /* retained for compatibility */
1100 default: // ESnormal
1101 vt
->tty_state
= ESnormal
;
1106 case 7: /* alert aka. bell */
1108 //rfbSendBell(vt->screen);
1110 case 8: /* backspace */
1114 case 9: /* tabspace */
1115 if (vt
->cx
+ (8 - (vt
->cx
% 8)) > vt
->width
) {
1117 spiceterm_put_lf (vt
);
1119 vt
->cx
= vt
->cx
+ (8 - (vt
->cx
% 8));
1125 spiceterm_put_lf (vt
);
1127 case 13: /* carriage return */
1131 /* SI (shift in), select character set 1 */
1133 vt
->cur_enc
= vt
->g1enc
;
1134 /* fixme: display controls = 1 */
1137 /* SO (shift out), select character set 0 */
1139 vt
->cur_enc
= vt
->g0enc
;
1140 /* fixme: display controls = 0 */
1143 vt
->tty_state
= ESesc
;
1145 case 127: /* delete */
1148 case 128+27: /* csi */
1149 vt
->tty_state
= ESsquare
;
1152 if (vt
->cx
>= vt
->width
) {
1155 spiceterm_put_lf (vt
);
1158 int y1
= (vt
->y_base
+ vt
->cy
) % vt
->total_height
;
1159 TextCell
*c
= &vt
->cells
[y1
*vt
->width
+ vt
->cx
];
1160 c
->attrib
= vt
->cur_attrib
;
1162 spiceterm_update_xy (vt
, vt
->cx
, vt
->cy
);
1171 spiceterm_puts (spiceTerm
*vt
, const char *buf
, int len
)
1175 spiceterm_show_cursor (vt
, 0);
1178 unsigned char c
= *buf
;
1182 if (vt
->tty_state
!= ESnormal
) {
1183 // never translate escape sequence
1185 } else if (vt
->utf8
&& !vt
->cur_enc
) {
1187 if(c
& 0x80) { // utf8 multi-byte sequence
1189 if (vt
->utf_count
> 0 && (c
& 0xc0) == 0x80) {
1190 // inside UTF8 sequence
1191 vt
->utf_char
= (vt
->utf_char
<< 6) | (c
& 0x3f);
1193 if (vt
->utf_count
== 0) {
1199 // first char of a UTF8 sequence
1200 if ((c
& 0xe0) == 0xc0) {
1202 vt
->utf_char
= (c
& 0x1f);
1203 } else if ((c
& 0xf0) == 0xe0) {
1205 vt
->utf_char
= (c
& 0x0f);
1206 } else if ((c
& 0xf8) == 0xf0) {
1208 vt
->utf_char
= (c
& 0x07);
1209 } else if ((c
& 0xfc) == 0xf8) {
1211 vt
->utf_char
= (c
& 0x03);
1212 } else if ((c
& 0xfe) == 0xfc) {
1214 vt
->utf_char
= (c
& 0x01);
1227 // never translate controls
1228 if (c
>= 32 && c
!= 127 && c
!= (128+27)) {
1229 tc
= translations
[vt
->cur_enc
][c
& 0x0ff];
1235 spiceterm_putchar (vt
, tc
);
1238 spiceterm_show_cursor (vt
, 1);
1245 spiceterm_set_xcut_text (char* str, int len, struct _rfbClientRec* cl)
1247 spiceTerm *vt =(spiceTerm *)cl->screen->screenData;
1249 // seems str is Latin-1 encoded
1250 if (vt->selection) free (vt->selection);
1251 vt->selection = (gunichar2 *)malloc (len*sizeof (gunichar2));
1253 for (i = 0; i < len; i++) {
1254 vt->selection[i] = str[i] & 0xff;
1256 vt->selection_len = len;
1261 spiceterm_update_watch_mask(spiceTerm
*vt
, gboolean writable
)
1263 g_assert(vt
!= NULL
);
1265 int mask
= SPICE_WATCH_EVENT_READ
;
1268 mask
|= SPICE_WATCH_EVENT_WRITE
;
1271 vt
->screen
->core
->watch_update_mask(vt
->screen
->mwatch
, mask
);
1275 mouse_report(spiceTerm
*vt
, int butt
, int mrx
, int mry
)
1279 sprintf (buf
, "[M%c%c%c", (char)(' ' + butt
), (char)('!' + mrx
),
1282 spiceterm_respond_esc(vt
, buf
);
1284 spiceterm_update_watch_mask(vt
, TRUE
);
1288 spiceterm_respond_unichar2(spiceTerm
*vt
, gunichar2 uc
)
1292 gint len
= g_unichar_to_utf8(uc
, buf
);
1295 if ((vt
->ibuf_count
+ len
) < IBUFSIZE
) {
1297 for (i
= 0; i
< len
; i
++) {
1298 vt
->ibuf
[vt
->ibuf_count
++] = buf
[i
];
1301 fprintf(stderr
, "warning: input buffer overflow\n");
1305 if ((vt
->ibuf_count
+ 1) < IBUFSIZE
) {
1306 vt
->ibuf
[vt
->ibuf_count
++] = (char)uc
;
1308 fprintf(stderr
, "warning: input buffer overflow\n");
1314 spiceterm_motion_event(spiceTerm
*vt
, uint32_t x
, uint32_t y
, uint32_t buttons
)
1316 DPRINTF(1, "mask=%08x x=%d y=%d", buttons
, x
,y
);
1318 static int last_mask
= 0;
1319 static int sel_start_pos
= 0;
1320 static int sel_end_pos
= 0;
1321 static int button2_released
= 1;
1328 if (cx
>= vt
->width
) cx
= vt
->width
- 1;
1330 if (cy
>= vt
->height
) cy
= vt
->height
- 1;
1332 if (vt
->report_mouse
&& buttons
!= last_mask
) {
1333 last_mask
= buttons
;
1335 mouse_report(vt
, 0, cx
, cy
);
1338 mouse_report (vt
, 1, cx
, cy
);
1341 mouse_report (vt
, 2, cx
, cy
);
1344 mouse_report (vt
, 3, cx
, cy
);
1349 if(button2_released
&& vt
->selection
) {
1351 for(i
= 0; i
< vt
->selection_len
; i
++) {
1352 spiceterm_respond_unichar2(vt
, vt
->selection
[i
]);
1354 spiceterm_update_watch_mask(vt
, TRUE
);
1355 if (vt
->y_displ
!= vt
->y_base
) {
1356 vt
->y_displ
= vt
->y_base
;
1357 spiceterm_refresh(vt
);
1360 button2_released
= 0;
1362 button2_released
= 1;
1366 int pos
= cy
*vt
->width
+ cx
;
1368 // code borrowed from libvncserver (VNCconsole.c)
1370 if (!vt
->mark_active
) {
1372 if (sel_start_pos
!= sel_end_pos
) {
1373 while (sel_start_pos
<= sel_end_pos
) {
1374 spiceterm_toggle_marked_cell(vt
, sel_start_pos
++);
1378 vt
->mark_active
= 1;
1379 sel_start_pos
= sel_end_pos
= pos
;
1380 spiceterm_toggle_marked_cell(vt
, pos
);
1384 if (pos
!= sel_end_pos
) {
1386 if (pos
> sel_end_pos
) {
1387 cx
= sel_end_pos
; cy
=pos
;
1389 cx
=pos
; cy
=sel_end_pos
;
1392 if (cx
< sel_start_pos
) {
1393 if (cy
< sel_start_pos
) cy
--;
1399 spiceterm_toggle_marked_cell(vt
, cx
);
1407 } else if (vt
->mark_active
) {
1408 vt
->mark_active
= 0;
1410 if (sel_start_pos
> sel_end_pos
) {
1411 int tmp
= sel_start_pos
- 1;
1412 sel_start_pos
= sel_end_pos
;
1416 int len
= sel_end_pos
- sel_start_pos
+ 1;
1418 if (vt
->selection
) free (vt
->selection
);
1419 vt
->selection
= (gunichar2
*)malloc (len
*sizeof(gunichar2
));
1420 vt
->selection_len
= len
;
1422 for (i
= 0; i
< len
; i
++) {
1423 int pos
= sel_start_pos
+ i
;
1424 int x
= pos
% vt
->width
;
1425 int y1
= ((pos
/ vt
->width
) + vt
->y_displ
) % vt
->total_height
;
1426 TextCell
*c
= &vt
->cells
[y1
*vt
->width
+ x
];
1427 vt
->selection
[i
] = c
->ch
;
1431 DPRINTF(1, "selection length = %d", vt
->selection_len
);
1433 // fixme: tell client we have something seletced
1434 //rfbGotXCutText (vt->screen, sel_latin1, len);
1439 my_kbd_push_key(SpiceKbdInstance
*sin
, uint8_t frag
)
1441 // spiceTerm *vt = SPICE_CONTAINEROF(sin, spiceTerm, keyboard_sin);
1443 /* we no not need this */
1449 my_kbd_push_keyval(SpiceKbdInstance
*sin
, uint32_t keySym
, int flags
)
1451 spiceTerm
*vt
= SPICE_CONTAINEROF(sin
, spiceTerm
, keyboard_sin
);
1452 static int control
= 0;
1453 static int shift
= 0;
1458 DPRINTF(1, "flags=%d keySym=%08x", flags
, keySym
);
1461 if (keySym
== GDK_KEY_Shift_L
|| keySym
== GDK_KEY_Shift_R
) {
1463 } if (keySym
== GDK_KEY_Control_L
|| keySym
== GDK_KEY_Control_R
) {
1465 } else if (vt
->ibuf_count
< (IBUFSIZE
- 32)) {
1468 if(keySym
>= 'a' && keySym
<= 'z')
1469 uc
= keySym
- 'a' + 1;
1470 else if (keySym
>= 'A' && keySym
<= 'Z')
1471 uc
= keySym
- 'A' + 1;
1477 case GDK_KEY_Escape
:
1479 case GDK_KEY_Return
:
1481 case GDK_KEY_BackSpace
:
1485 case GDK_KEY_Delete
: /* kdch1 */
1486 case GDK_KEY_KP_Delete
:
1488 case GDK_KEY_Home
: /* khome */
1489 case GDK_KEY_KP_Home
:
1492 case GDK_KEY_KP_End
: /* kend */
1494 case GDK_KEY_Insert
: /* kich1 */
1495 case GDK_KEY_KP_Insert
:
1498 case GDK_KEY_KP_Up
: /* kcuu1 */
1500 case GDK_KEY_Down
: /* kcud1 */
1501 case GDK_KEY_KP_Down
:
1504 case GDK_KEY_KP_Right
: /* kcuf1 */
1507 case GDK_KEY_KP_Left
: /* kcub1 */
1509 case GDK_KEY_Page_Up
:
1511 spiceterm_virtual_scroll (vt
, -vt
->height
/2);
1515 case GDK_KEY_Page_Down
:
1517 spiceterm_virtual_scroll (vt
, vt
->height
/2);
1546 if (keySym
< 0x100) {
1553 DPRINTF(1, "escape=%s unicode=%08x\n", esc
, uc
);
1555 if (vt
->y_displ
!= vt
->y_base
) {
1556 vt
->y_displ
= vt
->y_base
;
1557 spiceterm_refresh (vt
);
1561 spiceterm_respond_esc(vt
, esc
);
1562 } else if (uc
> 0) {
1563 spiceterm_respond_unichar2(vt
, uc
);
1571 if (flags
& 2) { // UP
1572 if (keySym
== GDK_KEY_Shift_L
|| keySym
== GDK_KEY_Shift_R
) {
1574 } else if (keySym
== GDK_KEY_Control_L
|| keySym
== GDK_KEY_Control_R
) {
1579 spiceterm_update_watch_mask(vt
, TRUE
);
1583 my_kbd_get_leds(SpiceKbdInstance
*sin
)
1588 static SpiceKbdInterface my_keyboard_sif
= {
1589 .base
.type
= SPICE_INTERFACE_KEYBOARD
,
1590 .base
.description
= "spiceterm keyboard device",
1591 .base
.major_version
= SPICE_INTERFACE_KEYBOARD_MAJOR
,
1592 .base
.minor_version
= SPICE_INTERFACE_KEYBOARD_MINOR
,
1593 .push_keyval
= my_kbd_push_keyval
,
1594 .push_scan_freg
= my_kbd_push_key
,
1595 .get_leds
= my_kbd_get_leds
,
1598 /* vdagent interface - to get mouse/clipboarde support */
1600 vmc_write(SpiceCharDeviceInstance
*sin
, const uint8_t *buf
, int len
)
1602 spiceTerm
*vt
= SPICE_CONTAINEROF(sin
, spiceTerm
, vdagent_sin
);
1604 VDIChunkHeader
*hdr
= (VDIChunkHeader
*)buf
;
1605 VDAgentMessage
*msg
= (VDAgentMessage
*)&hdr
[1];
1607 //g_assert(hdr->port == VDP_SERVER_PORT);
1608 g_assert(msg
->protocol
== VD_AGENT_PROTOCOL
);
1610 DPRINTF(1, "%d %d %d %d", len
, hdr
->port
, msg
->protocol
, msg
->type
);
1612 if (msg
->type
== VD_AGENT_MOUSE_STATE
) {
1613 VDAgentMouseState
*info
= (VDAgentMouseState
*)&msg
[1];
1614 spiceterm_motion_event(vt
, info
->x
, info
->y
, info
->buttons
);
1615 } else if (msg
->type
== VD_AGENT_ANNOUNCE_CAPABILITIES
) {
1616 /* ignore for now */
1617 } else if (msg
->type
== VD_AGENT_MONITORS_CONFIG
) {
1618 /* ignore for now */
1620 DPRINTF(0, "got uknown vdagent message type %d\n", msg
->type
);
1627 vmc_read(SpiceCharDeviceInstance
*sin
, uint8_t *buf
, int len
)
1629 DPRINTF(1, "%d", len
);
1635 vmc_state(SpiceCharDeviceInstance
*sin
, int connected
)
1640 static SpiceCharDeviceInterface my_vdagent_sif
= {
1641 .base
.type
= SPICE_INTERFACE_CHAR_DEVICE
,
1642 .base
.description
= "spice virtual channel char device",
1643 .base
.major_version
= SPICE_INTERFACE_CHAR_DEVICE_MAJOR
,
1644 .base
.minor_version
= SPICE_INTERFACE_CHAR_DEVICE_MINOR
,
1651 create_spiceterm(int argc
, char** argv
, int maxx
, int maxy
, guint timeout
)
1655 SpiceScreen
*spice_screen
;
1657 SpiceCoreInterface
*core
= basic_event_loop_init();
1658 spice_screen
= spice_screen_new(core
, timeout
);
1659 //spice_server_set_image_compression(server, SPICE_IMAGE_COMPRESS_OFF);
1661 spiceTerm
*vt
= (spiceTerm
*)calloc (sizeof(spiceTerm
), 1);
1663 vt
->keyboard_sin
.base
.sif
= &my_keyboard_sif
.base
;
1664 spice_server_add_interface(spice_screen
->server
, &vt
->keyboard_sin
.base
);
1666 vt
->vdagent_sin
.base
.sif
= &my_vdagent_sif
.base
;
1667 vt
->vdagent_sin
.subtype
= "vdagent";
1668 spice_server_add_interface(spice_screen
->server
, &vt
->vdagent_sin
.base
);
1670 // screen->setXCutText = spiceterm_set_xcut_text;
1671 // screen->ptrAddEvent = spiceterm_pointer_event;
1672 // screen->newClientHook = new_client;
1673 // screen->desktopName = "SPICE Command Terminal";
1675 vt
->maxx
= spice_screen
->width
;
1676 vt
->maxy
= spice_screen
->height
;
1678 vt
->width
= vt
->maxx
/ 8;
1679 vt
->height
= vt
->maxy
/ 16;
1681 vt
->total_height
= vt
->height
* 20;
1682 vt
->scroll_height
= 0;
1687 vt
->region_bottom
= vt
->height
;
1689 vt
->g0enc
= LAT1_MAP
;
1690 vt
->g1enc
= GRAF_MAP
;
1691 vt
->cur_enc
= vt
->g0enc
;
1694 /* default text attributes */
1695 vt
->default_attrib
.bold
= 0;
1696 vt
->default_attrib
.uline
= 0;
1697 vt
->default_attrib
.blink
= 0;
1698 vt
->default_attrib
.invers
= 0;
1699 vt
->default_attrib
.unvisible
= 0;
1700 vt
->default_attrib
.fgcol
= 7;
1701 vt
->default_attrib
.bgcol
= 0;
1703 vt
->cur_attrib
= vt
->default_attrib
;
1705 vt
->cells
= (TextCell
*)calloc (sizeof (TextCell
), vt
->width
*vt
->total_height
);
1707 for (i
= 0; i
< vt
->width
*vt
->total_height
; i
++) {
1708 vt
->cells
[i
].ch
= ' ';
1709 vt
->cells
[i
].attrib
= vt
->default_attrib
;
1712 vt
->altcells
= (TextCell
*)calloc (sizeof (TextCell
), vt
->width
*vt
->height
);
1714 vt
->screen
= spice_screen
;
1720 master_error_callback(GIOChannel
*channel
, GIOCondition condition
,
1723 //spiceTerm *vt = (spiceTerm *)data;
1725 DPRINTF(1, "condition %d", condition
);
1733 master_watch(int master
, int event
, void *opaque
)
1735 spiceTerm
*vt
= (spiceTerm
*)opaque
;
1738 // fixme: if (!vt->mark_active) {
1740 if (event
== SPICE_WATCH_EVENT_READ
) {
1742 while ((c
= read(master
, buffer
, 1024)) == -1) {
1743 if (errno
!= EAGAIN
) break;
1746 perror("master pipe read error"); // fixme
1748 spiceterm_puts (vt
, buffer
, c
);
1750 if (vt
->ibuf_count
> 0) {
1751 DPRINTF(1, "write input %x %d", vt
->ibuf
[0], vt
->ibuf_count
);
1752 if ((c
= write (master
, vt
->ibuf
, vt
->ibuf_count
)) >= 0) {
1753 if (c
== vt
->ibuf_count
) {
1756 // not all data written
1757 memmove(vt
->ibuf
, vt
->ibuf
+ c
, vt
->ibuf_count
- c
);
1758 vt
->ibuf_count
-= c
;
1760 // nothing written -ignore and try later
1763 perror("master pipe write error");
1766 if (vt
->ibuf_count
== 0) {
1767 spiceterm_update_watch_mask(vt
, FALSE
);
1773 main (int argc
, char** argv
)
1776 char **cmdargv
= NULL
;
1777 char *command
= "/bin/bash"; // execute normal shell as default
1781 struct winsize dimensions
;
1783 g_thread_init(NULL
);
1785 for (i
= 1; i
< argc
; i
++) {
1786 if (!strcmp (argv
[i
], "-c")) {
1787 command
= argv
[i
+1];
1788 cmdargv
= &argv
[i
+1];
1795 if (0) print_usage(NULL
); // fixme:
1797 spiceTerm
*vt
= create_spiceterm (argc
, argv
, 745, 400, 10);
1799 setlocale(LC_ALL
, ""); // set from environment
1801 char *ctype
= setlocale (LC_CTYPE
, NULL
); // query LC_CTYPE
1803 // fixme: ist there a standard way to detect utf8 mode ?
1804 if (strcasestr (ctype
, ".utf-8")||strcasestr (ctype
, ".utf8")) {
1808 dimensions
.ws_col
= vt
->width
;
1809 dimensions
.ws_row
= vt
->height
;
1811 setenv("TERM", TERM
, 1);
1813 DPRINTF(1, "execute %s", command
);
1815 pid
= forkpty (&master
, ptyname
, NULL
, &dimensions
);
1818 // install default signal handlers
1819 signal (SIGQUIT
, SIG_DFL
);
1820 signal (SIGTERM
, SIG_DFL
);
1821 signal (SIGINT
, SIG_DFL
);
1824 execvp (command
, cmdargv
);
1826 execlp (command
, command
, NULL
);
1828 perror ("Error: exec failed\n");
1829 exit (-1); // should not be reached
1830 } else if (pid
== -1) {
1831 perror ("Error: fork failed\n");
1835 /* watch for errors - we need to use glib directly because spice
1836 * does not have SPICE_WATCH_EVENT for this */
1837 GIOChannel
*channel
= g_io_channel_unix_new(master
);
1838 g_io_channel_set_flags(channel
, G_IO_FLAG_NONBLOCK
, NULL
);
1839 g_io_channel_set_encoding(channel
, NULL
, NULL
);
1840 g_io_add_watch(channel
, G_IO_ERR
|G_IO_HUP
, master_error_callback
, vt
);
1842 vt
->screen
->mwatch
= vt
->screen
->core
->watch_add(
1843 master
, SPICE_WATCH_EVENT_READ
/* |SPICE_WATCH_EVENT_WRITE */,
1846 basic_event_loop_mainloop();
1850 waitpid(pid
, &status
, 0);