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");
89 /* Convert UCS2 to UTF8 sequence, trailing zero */
92 ucs2_to_utf8 (gunichar2 c, char *out)
95 out[0] = c; // 0*******
98 } else if (c < 0x800) {
99 out[0] = 0xc0 | (c >> 6); // 110***** 10******
100 out[1] = 0x80 | (c & 0x3f);
104 out[0] = 0xe0 | (c >> 12); // 1110**** 10****** 10******
105 out[1] = 0x80 | ((c >> 6) & 0x3f);
106 out[2] = 0x80 | (c & 0x3f);
116 draw_char_at (spiceTerm
*vt
, int x
, int y
, gunichar2 ch
, TextAttributes attrib
)
118 if (x
< 0 || y
< 0 || x
>= vt
->width
|| y
>= vt
->height
) {
122 spice_screen_draw_char(vt
->screen
, x
, y
, ch
, attrib
);
126 spiceterm_update_xy (spiceTerm
*vt
, int x
, int y
)
128 if (x
< 0 || y
< 0 || x
>= vt
->width
|| y
>= vt
->height
) { return; }
130 int y1
= (vt
->y_base
+ y
) % vt
->total_height
;
131 int y2
= y1
- vt
->y_displ
;
133 y2
+= vt
->total_height
;
135 if (y2
< vt
->height
) {
136 TextCell
*c
= &vt
->cells
[y1
* vt
->width
+ x
];
137 draw_char_at (vt
, x
, y2
, c
->ch
, c
->attrib
);
142 spiceterm_clear_xy (spiceTerm
*vt
, int x
, int y
)
144 if (x
< 0 || y
< 0 || x
>= vt
->width
|| y
>= vt
->height
) { return; }
146 int y1
= (vt
->y_base
+ y
) % vt
->total_height
;
147 int y2
= y1
- vt
->y_displ
;
149 y2
+= vt
->total_height
;
151 if (y2
< vt
->height
) {
152 TextCell
*c
= &vt
->cells
[y1
* vt
->width
+ x
];
154 c
->attrib
= vt
->default_attrib
;
155 c
->attrib
.fgcol
= vt
->cur_attrib
.fgcol
;
156 c
->attrib
.bgcol
= vt
->cur_attrib
.bgcol
;
158 draw_char_at (vt
, x
, y
, c
->ch
, c
->attrib
);
163 spiceterm_show_cursor (spiceTerm
*vt
, int show
)
166 if (x
>= vt
->width
) {
170 int y1
= (vt
->y_base
+ vt
->cy
) % vt
->total_height
;
171 int y
= y1
- vt
->y_displ
;
173 y
+= vt
->total_height
;
176 if (y
< vt
->height
) {
178 TextCell
*c
= &vt
->cells
[y1
* vt
->width
+ x
];
181 TextAttributes attrib
= vt
->default_attrib
;
182 attrib
.invers
= !(attrib
.invers
); /* invert fg and bg */
183 draw_char_at (vt
, x
, y
, c
->ch
, attrib
);
185 draw_char_at (vt
, x
, y
, c
->ch
, c
->attrib
);
191 spiceterm_refresh (spiceTerm
*vt
)
196 for(y
= 0; y
< vt
->height
; y
++) {
197 TextCell
*c
= vt
->cells
+ y1
* vt
->width
;
198 for(x
= 0; x
< vt
->width
; x
++) {
199 draw_char_at (vt
, x
, y
, c
->ch
, c
->attrib
);
202 if (++y1
== vt
->total_height
)
206 spiceterm_show_cursor (vt
, 1);
210 spiceterm_scroll_down (spiceTerm
*vt
, int top
, int bottom
, int lines
)
212 if ((top
+ lines
) >= bottom
) {
213 lines
= bottom
- top
-1;
216 if (top
< 0 || bottom
> vt
->height
|| top
>= bottom
|| lines
< 1) {
221 for(i
= bottom
- top
- lines
- 1; i
>= 0; i
--) {
222 int src
= ((vt
->y_base
+ top
+ i
) % vt
->total_height
)*vt
->width
;
223 int dst
= ((vt
->y_base
+ top
+ lines
+ i
) % vt
->total_height
)*vt
->width
;
225 memmove(vt
->cells
+ dst
, vt
->cells
+ src
, vt
->width
*sizeof (TextCell
));
228 for (i
= 0; i
< lines
; i
++) {
230 TextCell
*c
= vt
->cells
+ ((vt
->y_base
+ top
+ i
) % vt
->total_height
)*vt
->width
;
231 for(j
= 0; j
< vt
->width
; j
++) {
232 c
->attrib
= vt
->default_attrib
;
243 spice_screen_scroll(vt
->screen
, 0, y1
, vt
->screen
->primary_width
, y2
, 0, y0
);
244 spice_screen_clear(vt
->screen
, 0, y0
, vt
->screen
->primary_width
, y1
);
248 spiceterm_scroll_up (spiceTerm
*vt
, int top
, int bottom
, int lines
, int moveattr
)
250 if ((top
+ lines
) >= bottom
) {
251 lines
= bottom
- top
- 1;
254 if (top
< 0 || bottom
> vt
->height
|| top
>= bottom
|| lines
< 1) {
261 int y1
= (top
+ lines
)*16;
264 spice_screen_scroll(vt
->screen
, 0, y0
, vt
->screen
->primary_width
, y2
-h
, 0, y1
);
265 spice_screen_clear(vt
->screen
, 0, y2
-h
, vt
->screen
->primary_width
, y2
);
274 for(i
= 0; i
< (bottom
- top
- lines
); i
++) {
275 int dst
= ((vt
->y_base
+ top
+ i
) % vt
->total_height
)*vt
->width
;
276 int src
= ((vt
->y_base
+ top
+ lines
+ i
) % vt
->total_height
)*vt
->width
;
278 memmove(vt
->cells
+ dst
, vt
->cells
+ src
, vt
->width
*sizeof (TextCell
));
281 for (i
= 1; i
<= lines
; i
++) {
283 TextCell
*c
= vt
->cells
+ ((vt
->y_base
+ bottom
- i
) % vt
->total_height
)*vt
->width
;
284 for(j
= 0; j
< vt
->width
; j
++) {
285 c
->attrib
= vt
->default_attrib
;
293 spiceterm_virtual_scroll (spiceTerm
*vt
, int lines
)
295 if (vt
->altbuf
|| lines
== 0) return;
299 int i
= vt
->scroll_height
;
300 if (i
> vt
->total_height
- vt
->height
)
301 i
= vt
->total_height
- vt
->height
;
302 int y1
= vt
->y_base
- i
;
304 y1
+= vt
->total_height
;
305 for(i
= 0; i
< lines
; i
++) {
306 if (vt
->y_displ
== y1
) break;
307 if (--vt
->y_displ
< 0) {
308 vt
->y_displ
= vt
->total_height
- 1;
313 for(i
= 0; i
< lines
; i
++) {
314 if (vt
->y_displ
== vt
->y_base
) break;
315 if (++vt
->y_displ
== vt
->total_height
) {
321 spiceterm_refresh (vt
);
325 spiceterm_respond_esc (spiceTerm
*vt
, const char *esc
)
327 int len
= strlen (esc
);
330 if (vt
->ibuf_count
< (IBUFSIZE
- 1 - len
)) {
331 vt
->ibuf
[vt
->ibuf_count
++] = 27;
332 for (i
= 0; i
< len
; i
++) {
333 vt
->ibuf
[vt
->ibuf_count
++] = esc
[i
];
339 spiceterm_put_lf (spiceTerm
*vt
)
341 if (vt
->cy
+ 1 == vt
->region_bottom
) {
343 if (vt
->altbuf
|| vt
->region_top
!= 0 || vt
->region_bottom
!= vt
->height
) {
344 spiceterm_scroll_up (vt
, vt
->region_top
, vt
->region_bottom
, 1, 1);
348 if (vt
->y_displ
== vt
->y_base
) {
349 spiceterm_scroll_up (vt
, vt
->region_top
, vt
->region_bottom
, 1, 0);
352 if (vt
->y_displ
== vt
->y_base
) {
353 if (++vt
->y_displ
== vt
->total_height
) {
358 if (++vt
->y_base
== vt
->total_height
) {
362 if (vt
->scroll_height
< vt
->total_height
) {
366 int y1
= (vt
->y_base
+ vt
->height
- 1) % vt
->total_height
;
367 TextCell
*c
= &vt
->cells
[y1
* vt
->width
];
369 for (x
= 0; x
< vt
->width
; x
++) {
371 c
->attrib
= vt
->default_attrib
;
375 // fprintf (stderr, "BASE: %d DISPLAY %d\n", vt->y_base, vt->y_displ);
377 } else if (vt
->cy
< vt
->height
- 1) {
383 spiceterm_csi_m (spiceTerm
*vt
)
387 for (i
= 0; i
< vt
->esc_count
; i
++) {
388 switch (vt
->esc_buf
[i
]) {
389 case 0: /* reset all console attributes to default */
390 vt
->cur_attrib
= vt
->default_attrib
;
393 vt
->cur_attrib
.bold
= 1;
396 vt
->cur_attrib
.uline
= 1;
399 vt
->cur_attrib
.blink
= 1;
402 vt
->cur_attrib
.invers
= 1;
405 vt
->cur_attrib
.unvisible
= 1;
408 vt
->cur_enc
= LAT1_MAP
;
409 // fixme: dispaly controls = 0 ?
410 // fixme: toggle meta = 0 ?
413 vt
->cur_enc
= IBMPC_MAP
;
414 // fixme: dispaly controls = 1 ?
415 // fixme: toggle meta = 0 ?
418 vt
->cur_enc
= IBMPC_MAP
;
419 // fixme: dispaly controls = 1 ?
420 // fixme: toggle meta = 1 ?
423 vt
->cur_attrib
.bold
= 0;
426 vt
->cur_attrib
.uline
= 0;
429 vt
->cur_attrib
.blink
= 0;
432 vt
->cur_attrib
.invers
= 0;
435 vt
->cur_attrib
.unvisible
= 0;
445 /* set foreground color */
446 vt
->cur_attrib
.fgcol
= color_table
[vt
->esc_buf
[i
] - 30];
449 /* reset color to default, enable underline */
450 vt
->cur_attrib
.fgcol
= vt
->default_attrib
.fgcol
;
451 vt
->cur_attrib
.uline
= 1;
454 /* reset color to default, disable underline */
455 vt
->cur_attrib
.fgcol
= vt
->default_attrib
.fgcol
;
456 vt
->cur_attrib
.uline
= 0;
466 /* set background color */
467 vt
->cur_attrib
.bgcol
= color_table
[vt
->esc_buf
[i
] - 40];
470 /* reset background color */
471 vt
->cur_attrib
.bgcol
= vt
->default_attrib
.bgcol
;
474 fprintf(stderr
, "unhandled ESC[%d m code\n",vt
->esc_buf
[i
]);
481 spiceterm_save_cursor (spiceTerm
*vt
)
483 vt
->cx_saved
= vt
->cx
;
484 vt
->cy_saved
= vt
->cy
;
485 vt
->cur_attrib_saved
= vt
->cur_attrib
;
486 vt
->charset_saved
= vt
->charset
;
487 vt
->g0enc_saved
= vt
->g0enc
;
488 vt
->g1enc_saved
= vt
->g1enc
;
489 vt
->cur_enc_saved
= vt
->cur_enc
;
493 spiceterm_restore_cursor (spiceTerm
*vt
)
495 vt
->cx
= vt
->cx_saved
;
496 vt
->cy
= vt
->cy_saved
;
497 vt
->cur_attrib
= vt
->cur_attrib_saved
;
498 vt
->charset
= vt
->charset_saved
;
499 vt
->g0enc
= vt
->g0enc_saved
;
500 vt
->g1enc
= vt
->g1enc_saved
;
501 vt
->cur_enc
= vt
->cur_enc_saved
;
505 spiceterm_set_alternate_buffer (spiceTerm
*vt
, int on_off
)
509 vt
->y_displ
= vt
->y_base
;
513 if (vt
->altbuf
) return;
517 /* alternate buffer & cursor */
519 spiceterm_save_cursor (vt
);
520 /* save screen to altcels */
521 for (y
= 0; y
< vt
->height
; y
++) {
522 int y1
= (vt
->y_base
+ y
) % vt
->total_height
;
523 for (x
= 0; x
< vt
->width
; x
++) {
524 vt
->altcells
[y
*vt
->width
+ x
] = vt
->cells
[y1
*vt
->width
+ x
];
529 for (y
= 0; y
<= vt
->height
; y
++) {
530 for (x
= 0; x
< vt
->width
; x
++) {
531 spiceterm_clear_xy (vt
, x
, y
);
537 if (vt
->altbuf
== 0) return;
541 /* restore saved data */
542 for (y
= 0; y
< vt
->height
; y
++) {
543 int y1
= (vt
->y_base
+ y
) % vt
->total_height
;
544 for (x
= 0; x
< vt
->width
; x
++) {
545 vt
->cells
[y1
*vt
->width
+ x
] = vt
->altcells
[y
*vt
->width
+ x
];
549 spiceterm_restore_cursor (vt
);
552 spiceterm_refresh (vt
);
556 spiceterm_set_mode (spiceTerm
*vt
, int on_off
)
560 for (i
= 0; i
<= vt
->esc_count
; i
++) {
561 if (vt
->esc_ques
) { /* DEC private modes set/reset */
562 switch(vt
->esc_buf
[i
]) {
563 case 10: /* X11 mouse reporting on/off */
564 case 1000: /* SET_VT200_MOUSE */
565 case 1002: /* xterm SET_BTN_EVENT_MOUSE */
566 vt
->report_mouse
= on_off
;
568 case 1049: /* start/end special app mode (smcup/rmcup) */
569 spiceterm_set_alternate_buffer (vt
, on_off
);
571 case 25: /* Cursor on/off */
572 case 9: /* X10 mouse reporting on/off */
573 case 6: /* Origin relative/absolute */
574 case 1: /* Cursor keys in appl mode*/
575 case 5: /* Inverted screen on/off */
576 case 7: /* Autowrap on/off */
577 case 8: /* Autorepeat on/off */
580 } else { /* ANSI modes set/reset */
581 //g_assert_not_reached();
583 /* fixme: implement me */
589 spiceterm_gotoxy (spiceTerm
*vt
, int x
, int y
)
591 /* verify all boundaries */
597 if (x
>= vt
->width
) {
607 if (y
>= vt
->height
) {
615 debug_print_escape_buffer(spiceTerm
*vt
, const char *func
, const char *prefix
,
616 const char *qes
, gunichar2 ch
)
619 if (vt
->esc_count
== 0) {
620 printf("%s:%s ESC[%s%c\n", func
, prefix
, qes
, ch
);
621 } else if (vt
->esc_count
== 1) {
622 printf("%s:%s ESC[%s%d%c\n", func
, prefix
, qes
, vt
->esc_buf
[0], ch
);
625 printf("%s:%s ESC[%s%d", func
, prefix
, qes
, vt
->esc_buf
[0]);
626 for (i
= 1; i
< vt
->esc_count
; i
++) {
627 printf(";%d", vt
->esc_buf
[i
]);
634 enum { ESnormal
, ESesc
, ESsquare
, ESgetpars
, ESgotpars
, ESfunckey
,
635 EShash
, ESsetG0
, ESsetG1
, ESpercent
, ESignore
, ESnonstd
,
636 ESpalette
, ESidquery
, ESosc1
, ESosc2
};
639 spiceterm_putchar (spiceTerm
*vt
, gunichar2 ch
)
643 if (debug
&& !vt
->tty_state
) {
644 DPRINTF(1, "CHAR:%2d: %4x '%c' (cur_enc %d) %d %d",
645 vt
->tty_state
, ch
, ch
, vt
->cur_enc
, vt
->cx
, vt
->cy
);
648 switch(vt
->tty_state
) {
650 vt
->tty_state
= ESnormal
;
653 vt
->tty_state
= ESsquare
;
656 vt
->tty_state
= ESnonstd
;
659 vt
->tty_state
= ESpercent
;
662 spiceterm_save_cursor (vt
);
665 spiceterm_restore_cursor (vt
);
668 vt
->tty_state
= ESsetG0
; // SET G0
671 vt
->tty_state
= ESsetG1
; // SET G1
675 if (vt
->cy
== vt
->region_top
)
676 spiceterm_scroll_down (vt
, vt
->region_top
, vt
->region_bottom
, 1);
677 else if (vt
->cy
> 0) {
682 /* numeric keypad - ignored */
685 /* appl. keypad - ignored */
688 DPRINTF(1, "got unhandled ESC%c %d", ch
, ch
);
692 case ESnonstd
: /* Operating System Controls */
693 vt
->tty_state
= ESnormal
;
696 case 'P': /* palette escape sequence */
697 for(i
= 0; i
< MAX_ESC_PARAMS
; i
++) {
702 vt
->tty_state
= ESpalette
;
704 case 'R': /* reset palette */
705 // fixme: reset_palette(vc);
712 vt
->osc_textbuf
[0] = 0;
713 vt
->tty_state
= ESosc1
;
716 DPRINTF(1, "got unhandled OSC %c", ch
);
717 vt
->tty_state
= ESnormal
;
722 vt
->tty_state
= ESnormal
;
724 vt
->tty_state
= ESosc2
;
726 DPRINTF(1, "got illegal OSC sequence");
730 if (ch
!= 0x9c && ch
!= 7) {
732 while (vt
->osc_textbuf
[i
]) i
++;
733 vt
->osc_textbuf
[i
++] = ch
;
734 vt
->osc_textbuf
[i
] = 0;
736 DPRINTF(1, "OSC:%c:%s", vt
->osc_cmd
, vt
->osc_textbuf
);
737 vt
->tty_state
= ESnormal
;
741 if ((ch
>= '0' && ch
<= '9') || (ch
>= 'A' && ch
<= 'F')
742 || (ch
>= 'a' && ch
<= 'f')) {
743 vt
->esc_buf
[vt
->esc_count
++] = (ch
> '9' ? (ch
& 0xDF) - 'A' + 10 : ch
- '0');
744 if (vt
->esc_count
== 7) {
745 // fixme: this does not work - please test
747 rfbColourMap *cmap =&vt->screen->colourMap;
749 int i = color_table[vt->esc_buf[0]] * 3, j = 1;
750 cmap->data.bytes[i] = 16 * vt->esc_buf[j++];
751 cmap->data.bytes[i++] += vt->esc_buf[j++];
752 cmap->data.bytes[i] = 16 * vt->esc_buf[j++];
753 cmap->data.bytes[i++] += vt->esc_buf[j++];
754 cmap->data.bytes[i] = 16 * vt->esc_buf[j++];
755 cmap->data.bytes[i] += vt->esc_buf[j];
759 vt
->tty_state
= ESnormal
;
762 vt
->tty_state
= ESnormal
;
765 for(i
= 0; i
< MAX_ESC_PARAMS
; i
++) {
771 vt
->tty_state
= ESgetpars
;
774 vt
->tty_state
= ESidquery
;
778 if ((vt
->esc_ques
= (ch
== '?'))) {
782 if (ch
>= '0' && ch
<= '9') {
784 if (vt
->esc_count
< MAX_ESC_PARAMS
) {
785 vt
->esc_buf
[vt
->esc_count
] = vt
->esc_buf
[vt
->esc_count
] * 10 + ch
- '0';
788 } else if (ch
== ';') {
792 if (vt
->esc_has_par
) {
795 vt
->tty_state
= ESgotpars
;
799 vt
->tty_state
= ESnormal
;
801 char *qes
= vt
->esc_ques
? "?" : "";
804 debug_print_escape_buffer(vt
, __func__
, "", qes
, ch
);
809 spiceterm_set_mode(vt
, 1);
812 spiceterm_set_mode(vt
, 0);
815 if (!vt
->esc_count
) {
816 vt
->esc_count
++; // default parameter 0
818 spiceterm_csi_m (vt
);
821 /* report cursor position */
822 /* TODO: send ESC[row;colR */
826 if (vt
->esc_buf
[0] == 0) {
829 vt
->cy
-= vt
->esc_buf
[0];
836 /* move cursor down */
837 if (vt
->esc_buf
[0] == 0) {
840 vt
->cy
+= vt
->esc_buf
[0];
841 if (vt
->cy
>= vt
->height
) {
842 vt
->cy
= vt
->height
- 1;
847 /* move cursor right */
848 if (vt
->esc_buf
[0] == 0) {
851 vt
->cx
+= vt
->esc_buf
[0];
852 if (vt
->cx
>= vt
->width
) {
853 vt
->cx
= vt
->width
- 1;
857 /* move cursor left */
858 if (vt
->esc_buf
[0] == 0) {
861 vt
->cx
-= vt
->esc_buf
[0];
868 /* move cursor to column */
869 spiceterm_gotoxy (vt
, vt
->esc_buf
[0] - 1, vt
->cy
);
872 /* move cursor to row */
873 spiceterm_gotoxy (vt
, vt
->cx
, vt
->esc_buf
[0] - 1);
877 /* move cursor to row, column */
878 spiceterm_gotoxy (vt
, vt
->esc_buf
[1] - 1, vt
->esc_buf
[0] - 1);
881 switch (vt
->esc_buf
[0]) {
883 /* clear to end of screen */
884 for (y
= vt
->cy
; y
< vt
->height
; y
++) {
885 for (x
= 0; x
< vt
->width
; x
++) {
886 if (y
== vt
->cy
&& x
< vt
->cx
) {
889 spiceterm_clear_xy (vt
, x
, y
);
894 /* clear from beginning of screen */
895 for (y
= 0; y
<= vt
->cy
; y
++) {
896 for (x
= 0; x
< vt
->width
; x
++) {
897 if (y
== vt
->cy
&& x
> vt
->cx
) {
900 spiceterm_clear_xy (vt
, x
, y
);
905 /* clear entire screen */
906 for (y
= 0; y
<= vt
->height
; y
++) {
907 for (x
= 0; x
< vt
->width
; x
++) {
908 spiceterm_clear_xy (vt
, x
, y
);
915 switch (vt
->esc_buf
[0]) {
918 for(x
= vt
->cx
; x
< vt
->width
; x
++) {
919 spiceterm_clear_xy (vt
, x
, vt
->cy
);
923 /* clear from beginning of line */
924 for (x
= 0; x
<= vt
->cx
; x
++) {
925 spiceterm_clear_xy (vt
, x
, vt
->cy
);
929 /* clear entire line */
930 for(x
= 0; x
< vt
->width
; x
++) {
931 spiceterm_clear_xy (vt
, x
, vt
->cy
);
940 if (c
> vt
->height
- vt
->cy
)
941 c
= vt
->height
- vt
->cy
;
945 spiceterm_scroll_down (vt
, vt
->cy
, vt
->region_bottom
, c
);
951 if (c
> vt
->height
- vt
->cy
)
952 c
= vt
->height
- vt
->cy
;
956 spiceterm_scroll_up (vt
, vt
->cy
, vt
->region_bottom
, c
, 1);
962 spiceterm_scroll_down (vt
, vt
->region_top
, vt
->region_bottom
, c
);
968 spiceterm_scroll_up (vt
, vt
->region_top
, vt
->region_bottom
, c
, 1);
971 /* delete c character */
974 if (c
> vt
->width
- vt
->cx
)
975 c
= vt
->width
- vt
->cx
;
979 for (x
= vt
->cx
; x
< vt
->width
- c
; x
++) {
980 int y1
= (vt
->y_base
+ vt
->cy
) % vt
->total_height
;
981 TextCell
*dst
= &vt
->cells
[y1
* vt
->width
+ x
];
982 TextCell
*src
= dst
+ c
;
984 spiceterm_update_xy (vt
, x
+ c
, vt
->cy
);
986 src
->attrib
= vt
->default_attrib
;
987 spiceterm_update_xy (vt
, x
, vt
->cy
);
991 /* save cursor position */
992 spiceterm_save_cursor (vt
);
995 /* restore cursor position */
996 spiceterm_restore_cursor (vt
);
999 /* erase c characters */
1003 if (c
> (vt
->width
- vt
->cx
)) c
= vt
->width
- vt
->cx
;
1005 for(i
= 0; i
< c
; i
++) {
1006 spiceterm_clear_xy (vt
, vt
->cx
+ i
, vt
->cy
);
1010 /* insert c character */
1012 if (c
> (vt
->width
- vt
->cx
)) {
1013 c
= vt
->width
- vt
->cx
;
1017 for (x
= vt
->width
- c
; x
>= vt
->cx
; x
--) {
1018 int y1
= (vt
->y_base
+ vt
->cy
) % vt
->total_height
;
1019 TextCell
*src
= &vt
->cells
[y1
* vt
->width
+ x
];
1020 TextCell
*dst
= src
+ c
;
1022 spiceterm_update_xy (vt
, x
+ c
, vt
->cy
);
1024 src
->attrib
= vt
->cur_attrib
;
1025 spiceterm_update_xy (vt
, x
, vt
->cy
);
1031 if (!vt
->esc_buf
[0])
1033 if (!vt
->esc_buf
[1])
1034 vt
->esc_buf
[1] = vt
->height
;
1035 /* Minimum allowed region is 2 lines */
1036 if (vt
->esc_buf
[0] < vt
->esc_buf
[1] &&
1037 vt
->esc_buf
[1] <= vt
->height
) {
1038 vt
->region_top
= vt
->esc_buf
[0] - 1;
1039 vt
->region_bottom
= vt
->esc_buf
[1];
1041 vt
->cy
= vt
->region_top
;
1042 DPRINTF(1, "set region %d %d", vt
->region_top
, vt
->region_bottom
);
1048 debug_print_escape_buffer(vt
, __func__
, " unhandled escape", qes
, ch
);
1054 case ESsetG0
: // Set G0
1055 vt
->tty_state
= ESnormal
;
1058 vt
->g0enc
= GRAF_MAP
;
1060 vt
->g0enc
= LAT1_MAP
;
1062 vt
->g0enc
= IBMPC_MAP
;
1064 vt
->g0enc
= USER_MAP
;
1066 if (vt
->charset
== 0)
1067 vt
->cur_enc
= vt
->g0enc
;
1070 case ESsetG1
: // Set G1
1071 vt
->tty_state
= ESnormal
;
1074 vt
->g1enc
= GRAF_MAP
;
1076 vt
->g1enc
= LAT1_MAP
;
1078 vt
->g1enc
= IBMPC_MAP
;
1080 vt
->g1enc
= USER_MAP
;
1082 if (vt
->charset
== 1)
1083 vt
->cur_enc
= vt
->g1enc
;
1086 case ESidquery
: // vt100 query id
1087 vt
->tty_state
= ESnormal
;
1090 DPRINTF(1, "ESC[>c Query term ID");
1091 spiceterm_respond_esc (vt
, TERMIDCODE
);
1095 vt
->tty_state
= ESnormal
;
1097 case '@': /* defined in ISO 2022 */
1100 case 'G': /* prelim official escape code */
1101 case '8': /* retained for compatibility */
1106 default: // ESnormal
1107 vt
->tty_state
= ESnormal
;
1112 case 7: /* alert aka. bell */
1114 //rfbSendBell(vt->screen);
1116 case 8: /* backspace */
1120 case 9: /* tabspace */
1121 if (vt
->cx
+ (8 - (vt
->cx
% 8)) > vt
->width
) {
1123 spiceterm_put_lf (vt
);
1125 vt
->cx
= vt
->cx
+ (8 - (vt
->cx
% 8));
1131 spiceterm_put_lf (vt
);
1133 case 13: /* carriage return */
1137 /* SI (shift in), select character set 1 */
1139 vt
->cur_enc
= vt
->g1enc
;
1140 /* fixme: display controls = 1 */
1143 /* SO (shift out), select character set 0 */
1145 vt
->cur_enc
= vt
->g0enc
;
1146 /* fixme: display controls = 0 */
1149 vt
->tty_state
= ESesc
;
1151 case 127: /* delete */
1154 case 128+27: /* csi */
1155 vt
->tty_state
= ESsquare
;
1158 if (vt
->cx
>= vt
->width
) {
1161 spiceterm_put_lf (vt
);
1164 int y1
= (vt
->y_base
+ vt
->cy
) % vt
->total_height
;
1165 TextCell
*c
= &vt
->cells
[y1
*vt
->width
+ vt
->cx
];
1166 c
->attrib
= vt
->cur_attrib
;
1168 spiceterm_update_xy (vt
, vt
->cx
, vt
->cy
);
1177 spiceterm_puts (spiceTerm
*vt
, const char *buf
, int len
)
1181 spiceterm_show_cursor (vt
, 0);
1184 unsigned char c
= *buf
;
1188 if (vt
->tty_state
!= ESnormal
) {
1189 // never translate escape sequence
1191 } else if (vt
->utf8
&& !vt
->cur_enc
) {
1193 if(c
& 0x80) { // utf8 multi-byte sequence
1195 if (vt
->utf_count
> 0 && (c
& 0xc0) == 0x80) {
1196 // inside UTF8 sequence
1197 vt
->utf_char
= (vt
->utf_char
<< 6) | (c
& 0x3f);
1199 if (vt
->utf_count
== 0) {
1205 // first char of a UTF8 sequence
1206 if ((c
& 0xe0) == 0xc0) {
1208 vt
->utf_char
= (c
& 0x1f);
1209 } else if ((c
& 0xf0) == 0xe0) {
1211 vt
->utf_char
= (c
& 0x0f);
1212 } else if ((c
& 0xf8) == 0xf0) {
1214 vt
->utf_char
= (c
& 0x07);
1215 } else if ((c
& 0xfc) == 0xf8) {
1217 vt
->utf_char
= (c
& 0x03);
1218 } else if ((c
& 0xfe) == 0xfc) {
1220 vt
->utf_char
= (c
& 0x01);
1233 // never translate controls
1234 if (c
>= 32 && c
!= 127 && c
!= (128+27)) {
1235 tc
= translations
[vt
->cur_enc
][c
& 0x0ff];
1241 spiceterm_putchar (vt
, tc
);
1244 spiceterm_show_cursor (vt
, 1);
1251 spiceterm_set_xcut_text (char* str, int len, struct _rfbClientRec* cl)
1253 spiceTerm *vt =(spiceTerm *)cl->screen->screenData;
1255 // seems str is Latin-1 encoded
1256 if (vt->selection) free (vt->selection);
1257 vt->selection = (gunichar2 *)malloc (len*sizeof (gunichar2));
1259 for (i = 0; i < len; i++) {
1260 vt->selection[i] = str[i] & 0xff;
1262 vt->selection_len = len;
1267 mouse_report(spiceTerm
*vt
, int butt
, int mrx
, int mry
)
1271 sprintf (buf
, "[M%c%c%c", (char)(' ' + butt
), (char)('!' + mrx
),
1274 spiceterm_respond_esc(vt
, buf
);
1277 vt
->screen
->core
->watch_update_mask(vt
->screen
->mwatch
,
1278 SPICE_WATCH_EVENT_READ
|SPICE_WATCH_EVENT_WRITE
);
1283 spiceterm_toggle_marked_cell (spiceTerm
*vt
, int pos
)
1287 int x= (pos%vt->width)*8;
1288 int y= (pos/vt->width)*16;
1291 rfbScreenInfoPtr s=vt->screen;
1293 char *b = s->frameBuffer+y*s->width+x;
1295 for (j=0; j < 16; j++) {
1296 for(i=0; i < 8; i++) {
1297 b[j*s->width+i] ^= 0x0f;
1298 rfbMarkRectAsModified (s, x, y, x+8, y+16);
1307 spiceterm_pointer_event (int buttonMask, int x, int y, rfbClientPtr cl)
1310 spiceTerm *vt =(spiceTerm *)cl->screen->screenData;
1311 static int button2_released = 1;
1312 static int last_mask = 0;
1313 static int sel_start_pos = 0;
1314 static int sel_end_pos = 0;
1321 if (cx >= vt->width) cx = vt->width - 1;
1323 if (cy >= vt->height) cy = vt->height - 1;
1325 if (vt->report_mouse && buttonMask != last_mask) {
1326 last_mask = buttonMask;
1327 if (buttonMask & 1) {
1328 mouse_report (vt, 0, cx, cy);
1330 if (buttonMask & 2) {
1331 mouse_report (vt, 1, cx, cy);
1333 if (buttonMask & 4) {
1334 mouse_report (vt, 2, cx, cy);
1337 mouse_report (vt, 3, cx, cy);
1341 if (buttonMask & 2) {
1342 if(button2_released && vt->selection) {
1344 for(i = 0; i < vt->selection_len; i++) {
1345 if (vt->ibuf_count < IBUFSIZE - 6) { // uft8 is max 6 characters wide
1347 vt->ibuf_count += ucs2_to_utf8 (vt->selection[i], &vt->ibuf[vt->ibuf_count]);
1349 vt->ibuf[vt->ibuf_count++] = vt->selection[i];
1353 if (vt->y_displ != vt->y_base) {
1354 vt->y_displ = vt->y_base;
1355 spiceterm_refresh (vt);
1358 button2_released = 0;
1360 button2_released = 1;
1363 if (buttonMask & 1) {
1364 int pos = cy*vt->width + cx;
1366 // code borrowed from libvncserver (VNCconsole.c)
1368 if (!vt->mark_active) {
1370 vt->mark_active = 1;
1371 sel_start_pos = sel_end_pos = pos;
1372 spiceterm_toggle_marked_cell (vt, pos);
1376 if (pos != sel_end_pos) {
1378 if (pos > sel_end_pos) {
1379 cx = sel_end_pos; cy=pos;
1381 cx=pos; cy=sel_end_pos;
1384 if (cx < sel_start_pos) {
1385 if (cy < sel_start_pos) cy--;
1391 spiceterm_toggle_marked_cell (vt, cx);
1399 } else if (vt->mark_active) {
1400 vt->mark_active = 0;
1402 if (sel_start_pos > sel_end_pos) {
1403 int tmp = sel_start_pos - 1;
1404 sel_start_pos = sel_end_pos;
1408 int len = sel_end_pos - sel_start_pos + 1;
1410 if (vt->selection) free (vt->selection);
1411 vt->selection = (gunichar2 *)malloc (len*sizeof (gunichar2));
1412 vt->selection_len = len;
1413 char *sel_latin1 = (char *)malloc (len + 1);
1415 for (i = 0; i < len; i++) {
1416 int pos = sel_start_pos + i;
1417 int x = pos % vt->width;
1418 int y1 = ((pos / vt->width) + vt->y_displ) % vt->total_height;
1419 TextCell *c = &vt->cells[y1*vt->width + x];
1420 vt->selection[i] = c->ch;
1421 sel_latin1[i] = (char)c->ch;
1424 sel_latin1[len] = 0;
1425 rfbGotXCutText (vt->screen, sel_latin1, len);
1428 while (sel_start_pos <= sel_end_pos) {
1429 spiceterm_toggle_marked_cell (vt, sel_start_pos++);
1434 rfbDefaultPtrAddEvent (buttonMask, x, y, cl);
1440 spiceterm_motion_event(spiceTerm
*vt
, uint32_t x
, uint32_t y
, uint32_t buttons
)
1442 DPRINTF(0, "mask=%08x x=%d y=%d", buttons
, x
,y
);
1444 static int last_mask
= 0;
1450 if (cx
>= vt
->width
) cx
= vt
->width
- 1;
1452 if (cy
>= vt
->height
) cy
= vt
->height
- 1;
1454 if (vt
->report_mouse
&& buttons
!= last_mask
) {
1455 DPRINTF(0, "report=%d", vt
->report_mouse
);
1457 last_mask
= buttons
;
1459 mouse_report(vt
, 0, cx
, cy
);
1462 mouse_report (vt
, 1, cx
, cy
);
1465 mouse_report (vt
, 2, cx
, cy
);
1468 mouse_report (vt
, 3, cx
, cy
);
1474 my_kbd_push_key(SpiceKbdInstance
*sin
, uint8_t frag
)
1476 // spiceTerm *vt = SPICE_CONTAINEROF(sin, spiceTerm, keyboard_sin);
1478 /* we no not need this */
1484 my_kbd_push_keyval(SpiceKbdInstance
*sin
, uint32_t keySym
, int flags
)
1486 spiceTerm
*vt
= SPICE_CONTAINEROF(sin
, spiceTerm
, keyboard_sin
);
1487 static int control
= 0;
1488 static int shift
= 0;
1493 DPRINTF(1, "flags=%d keySym=%08x", flags
, keySym
);
1496 if (keySym
== GDK_KEY_Shift_L
|| keySym
== GDK_KEY_Shift_R
) {
1498 } if (keySym
== GDK_KEY_Control_L
|| keySym
== GDK_KEY_Control_R
) {
1500 } else if (vt
->ibuf_count
< (IBUFSIZE
- 32)) {
1503 if(keySym
>= 'a' && keySym
<= 'z')
1504 uc
= keySym
- 'a' + 1;
1505 else if (keySym
>= 'A' && keySym
<= 'Z')
1506 uc
= keySym
- 'A' + 1;
1512 case GDK_KEY_Escape
:
1514 case GDK_KEY_Return
:
1516 case GDK_KEY_BackSpace
:
1520 case GDK_KEY_Delete
: /* kdch1 */
1521 case GDK_KEY_KP_Delete
:
1523 case GDK_KEY_Home
: /* khome */
1524 case GDK_KEY_KP_Home
:
1527 case GDK_KEY_KP_End
: /* kend */
1529 case GDK_KEY_Insert
: /* kich1 */
1530 case GDK_KEY_KP_Insert
:
1533 case GDK_KEY_KP_Up
: /* kcuu1 */
1535 case GDK_KEY_Down
: /* kcud1 */
1536 case GDK_KEY_KP_Down
:
1539 case GDK_KEY_KP_Right
: /* kcuf1 */
1542 case GDK_KEY_KP_Left
: /* kcub1 */
1544 case GDK_KEY_Page_Up
:
1546 spiceterm_virtual_scroll (vt
, -vt
->height
/2);
1550 case GDK_KEY_Page_Down
:
1552 spiceterm_virtual_scroll (vt
, vt
->height
/2);
1581 if (keySym
< 0x100) {
1588 DPRINTF(1, "escape=%s unicode=%08x\n", esc
, uc
);
1590 if (vt
->y_displ
!= vt
->y_base
) {
1591 vt
->y_displ
= vt
->y_base
;
1592 spiceterm_refresh (vt
);
1596 spiceterm_respond_esc(vt
, esc
);
1597 } else if (uc
> 0) {
1600 gint len
= g_unichar_to_utf8(uc
, buf
);
1604 for (i
= 0; i
< len
; i
++) {
1605 vt
->ibuf
[vt
->ibuf_count
++] = buf
[i
];
1609 vt
->ibuf
[vt
->ibuf_count
++] = (char)uc
;
1618 if (flags
& 2) { // UP
1619 if (keySym
== GDK_KEY_Shift_L
|| keySym
== GDK_KEY_Shift_R
) {
1621 } else if (keySym
== GDK_KEY_Control_L
|| keySym
== GDK_KEY_Control_R
) {
1626 vt
->screen
->core
->watch_update_mask(vt
->screen
->mwatch
,
1627 SPICE_WATCH_EVENT_READ
|SPICE_WATCH_EVENT_WRITE
);
1631 my_kbd_get_leds(SpiceKbdInstance
*sin
)
1636 static SpiceKbdInterface my_keyboard_sif
= {
1637 .base
.type
= SPICE_INTERFACE_KEYBOARD
,
1638 .base
.description
= "spiceterm keyboard device",
1639 .base
.major_version
= SPICE_INTERFACE_KEYBOARD_MAJOR
,
1640 .base
.minor_version
= SPICE_INTERFACE_KEYBOARD_MINOR
,
1641 .push_keyval
= my_kbd_push_keyval
,
1642 .push_scan_freg
= my_kbd_push_key
,
1643 .get_leds
= my_kbd_get_leds
,
1646 /* vdagent interface - to get mouse/clipboarde support */
1648 vmc_write(SpiceCharDeviceInstance
*sin
, const uint8_t *buf
, int len
)
1650 spiceTerm
*vt
= SPICE_CONTAINEROF(sin
, spiceTerm
, vdagent_sin
);
1652 VDIChunkHeader
*hdr
= (VDIChunkHeader
*)buf
;
1653 VDAgentMessage
*msg
= (VDAgentMessage
*)&hdr
[1];
1655 //g_assert(hdr->port == VDP_SERVER_PORT);
1656 g_assert(msg
->protocol
== VD_AGENT_PROTOCOL
);
1658 DPRINTF(1, "%d %d %d %d", len
, hdr
->port
, msg
->protocol
, msg
->type
);
1660 if (msg
->type
== VD_AGENT_MOUSE_STATE
) {
1661 VDAgentMouseState
*info
= (VDAgentMouseState
*)&msg
[1];
1662 spiceterm_motion_event(vt
, info
->x
, info
->y
, info
->buttons
);
1663 } else if (msg
->type
== VD_AGENT_ANNOUNCE_CAPABILITIES
) {
1664 /* ignore for now */
1665 } else if (msg
->type
== VD_AGENT_MONITORS_CONFIG
) {
1666 /* ignore for now */
1668 DPRINTF(0, "got uknown vdagent message type %d\n", msg
->type
);
1675 vmc_read(SpiceCharDeviceInstance
*sin
, uint8_t *buf
, int len
)
1677 DPRINTF(1, "%d", len
);
1683 vmc_state(SpiceCharDeviceInstance
*sin
, int connected
)
1688 static SpiceCharDeviceInterface my_vdagent_sif
= {
1689 .base
.type
= SPICE_INTERFACE_CHAR_DEVICE
,
1690 .base
.description
= "spice virtual channel char device",
1691 .base
.major_version
= SPICE_INTERFACE_CHAR_DEVICE_MAJOR
,
1692 .base
.minor_version
= SPICE_INTERFACE_CHAR_DEVICE_MINOR
,
1699 create_spiceterm(int argc
, char** argv
, int maxx
, int maxy
, guint timeout
)
1703 SpiceScreen
*spice_screen
;
1705 SpiceCoreInterface
*core
= basic_event_loop_init();
1706 spice_screen
= spice_screen_new(core
, timeout
);
1707 //spice_server_set_image_compression(server, SPICE_IMAGE_COMPRESS_OFF);
1709 spiceTerm
*vt
= (spiceTerm
*)calloc (sizeof(spiceTerm
), 1);
1711 vt
->keyboard_sin
.base
.sif
= &my_keyboard_sif
.base
;
1712 spice_server_add_interface(spice_screen
->server
, &vt
->keyboard_sin
.base
);
1714 vt
->vdagent_sin
.base
.sif
= &my_vdagent_sif
.base
;
1715 vt
->vdagent_sin
.subtype
= "vdagent";
1716 spice_server_add_interface(spice_screen
->server
, &vt
->vdagent_sin
.base
);
1718 // screen->setXCutText = spiceterm_set_xcut_text;
1719 // screen->ptrAddEvent = spiceterm_pointer_event;
1720 // screen->newClientHook = new_client;
1721 // screen->desktopName = "SPICE Command Terminal";
1723 vt
->maxx
= spice_screen
->width
;
1724 vt
->maxy
= spice_screen
->height
;
1726 vt
->width
= vt
->maxx
/ 8;
1727 vt
->height
= vt
->maxy
/ 16;
1729 vt
->total_height
= vt
->height
* 20;
1730 vt
->scroll_height
= 0;
1735 vt
->region_bottom
= vt
->height
;
1737 vt
->g0enc
= LAT1_MAP
;
1738 vt
->g1enc
= GRAF_MAP
;
1739 vt
->cur_enc
= vt
->g0enc
;
1742 /* default text attributes */
1743 vt
->default_attrib
.bold
= 0;
1744 vt
->default_attrib
.uline
= 0;
1745 vt
->default_attrib
.blink
= 0;
1746 vt
->default_attrib
.invers
= 0;
1747 vt
->default_attrib
.unvisible
= 0;
1748 vt
->default_attrib
.fgcol
= 7;
1749 vt
->default_attrib
.bgcol
= 0;
1751 vt
->cur_attrib
= vt
->default_attrib
;
1753 vt
->cells
= (TextCell
*)calloc (sizeof (TextCell
), vt
->width
*vt
->total_height
);
1755 for (i
= 0; i
< vt
->width
*vt
->total_height
; i
++) {
1756 vt
->cells
[i
].ch
= ' ';
1757 vt
->cells
[i
].attrib
= vt
->default_attrib
;
1760 vt
->altcells
= (TextCell
*)calloc (sizeof (TextCell
), vt
->width
*vt
->height
);
1762 vt
->screen
= spice_screen
;
1768 master_error_callback(GIOChannel
*channel
, GIOCondition condition
,
1771 //spiceTerm *vt = (spiceTerm *)data;
1773 DPRINTF(1, "condition %d", condition
);
1781 master_watch(int master
, int event
, void *opaque
)
1783 spiceTerm
*vt
= (spiceTerm
*)opaque
;
1785 // fixme: if (!vt->mark_active) {
1787 if (event
== SPICE_WATCH_EVENT_READ
) {
1790 while ((c
= read(master
, buffer
, 1024)) == -1) {
1791 if (errno
!= EAGAIN
) break;
1794 g_error("got read error"); // fixme
1796 spiceterm_puts (vt
, buffer
, c
);
1798 if (vt
->ibuf_count
> 0) {
1799 DPRINTF(1, "write input %x %d", vt
->ibuf
[0], vt
->ibuf_count
);
1800 write (master
, vt
->ibuf
, vt
->ibuf_count
);
1801 vt
->ibuf_count
= 0; // fixme: what if not all data written
1803 vt
->screen
->core
->watch_update_mask(vt
->screen
->mwatch
, SPICE_WATCH_EVENT_READ
);
1808 main (int argc
, char** argv
)
1811 char **cmdargv
= NULL
;
1812 char *command
= "/bin/bash"; // execute normal shell as default
1816 struct winsize dimensions
;
1818 g_thread_init(NULL
);
1820 for (i
= 1; i
< argc
; i
++) {
1821 if (!strcmp (argv
[i
], "-c")) {
1822 command
= argv
[i
+1];
1823 cmdargv
= &argv
[i
+1];
1830 if (0) print_usage(NULL
); // fixme:
1832 spiceTerm
*vt
= create_spiceterm (argc
, argv
, 745, 400, 10);
1834 setlocale(LC_ALL
, ""); // set from environment
1836 char *ctype
= setlocale (LC_CTYPE
, NULL
); // query LC_CTYPE
1838 // fixme: ist there a standard way to detect utf8 mode ?
1839 if (strcasestr (ctype
, ".utf-8")||strcasestr (ctype
, ".utf8")) {
1843 dimensions
.ws_col
= vt
->width
;
1844 dimensions
.ws_row
= vt
->height
;
1846 setenv("TERM", TERM
, 1);
1848 DPRINTF(1, "execute %s", command
);
1850 pid
= forkpty (&master
, ptyname
, NULL
, &dimensions
);
1853 // install default signal handlers
1854 signal (SIGQUIT
, SIG_DFL
);
1855 signal (SIGTERM
, SIG_DFL
);
1856 signal (SIGINT
, SIG_DFL
);
1859 execvp (command
, cmdargv
);
1861 execlp (command
, command
, NULL
);
1863 perror ("Error: exec failed\n");
1864 exit (-1); // should not be reached
1865 } else if (pid
== -1) {
1866 perror ("Error: fork failed\n");
1870 /* watch for errors - we need to use glib directly because spice
1871 * does not have SPICE_WATCH_EVENT for this */
1872 GIOChannel
*channel
= g_io_channel_unix_new(master
);
1873 g_io_channel_set_flags(channel
, G_IO_FLAG_NONBLOCK
, NULL
);
1874 g_io_channel_set_encoding(channel
, NULL
, NULL
);
1875 g_io_add_watch(channel
, G_IO_ERR
|G_IO_HUP
, master_error_callback
, vt
);
1877 vt
->screen
->mwatch
= vt
->screen
->core
->watch_add(
1878 master
, SPICE_WATCH_EVENT_READ
/* |SPICE_WATCH_EVENT_WRITE */,
1881 basic_event_loop_mainloop();
1885 waitpid(pid
, &status
, 0);