3 /* This "driver" is designed to go on top of an existing driver
4 to provide support for features only present if using an
5 xterm or compatible program for your console output.
6 Currently, it supports resizing and separating debug messages from
8 It does not currently support changing the title bar.
13 #include <sys/ioctl.h>
23 char console_xterm_prog
[80];
25 static BOOL32
wine_create_console(FILE **master
, FILE **slave
, int *pid
);
26 FILE *wine_openpty(int *master
, int *slave
, char *name
,
27 struct termios
*term
, struct winsize
*winsize
);
29 /* The console -- I chose to keep the master and slave
30 * (UNIX) file descriptors around in case they are needed for
31 * ioctls later. The pid is needed to destroy the xterm on close
33 typedef struct _XTERM_CONSOLE
{
34 FILE *master
; /* xterm side of pty */
35 FILE *slave
; /* wine side of pty */
36 int pid
; /* xterm's pid, -1 if no xterm */
39 static XTERM_CONSOLE xterm_console
;
42 FILE *old_in
, *old_out
;
46 /* Here, this is a supplementary driver so we should remember to call
48 chain
.init
= driver
.init
;
49 driver
.init
= XTERM_Init
;
51 chain
.close
= driver
.close
;
52 driver
.close
= XTERM_Close
;
54 chain
.resizeScreen
= driver
.resizeScreen
;
55 driver
.resizeScreen
= XTERM_ResizeScreen
;
57 /* Read in driver configuration */
58 PROFILE_GetWineIniString("console", "XtermProg",
59 "xterm", console_xterm_prog
, 79);
65 wine_create_console(&xterm_console
.master
, &xterm_console
.slave
,
68 old_in
= driver
.console_in
;
69 driver
.console_in
= xterm_console
.slave
;
71 old_out
= driver
.console_out
;
72 driver
.console_out
= xterm_console
.slave
;
74 /* Then call the chain... */
81 /* Call the chain first... */
85 driver
.console_in
= old_in
;
86 driver
.console_out
= old_out
;
88 /* make sure a xterm exists to kill */
89 if (xterm_console
.pid
!= -1) {
90 kill(xterm_console
.pid
, SIGTERM
);
94 void XTERM_ResizeScreen(int x
, int y
)
98 /* Call the chain first, there shoudln't be any... */
99 if (chain
.resizeScreen
)
100 chain
.resizeScreen(x
, y
);
102 sprintf(temp
, "\x1b[8;%d;%dt", y
, x
);
103 CONSOLE_WriteRawString(temp
);
105 CONSOLE_NotifyResizeScreen(x
, y
);
109 static BOOL32
wine_create_console(FILE **master
, FILE **slave
, int *pid
)
111 /* There is definately a bug in this routine that causes a lot
112 of garbage to be written to the screen, but I can't find it...
120 char xterm_resolution
[10];
122 sprintf(xterm_resolution
, "%dx%d", driver
.x_res
,
125 if (tcgetattr(0, &term
) < 0) return FALSE
;
126 term
.c_lflag
|= ICANON
;
127 term
.c_lflag
&= ~ECHO
;
128 if (wine_openpty(&tmaster
, &tslave
, NULL
, &term
, NULL
) < 0)
130 *master
= fdopen(tmaster
, "r+");
131 *slave
= fdopen(tslave
, "r+");
133 if ((*pid
=fork()) == 0) {
134 tcsetattr(fileno(*slave
), TCSADRAIN
, &term
);
135 sprintf(buf
, "-Sxx%d", fileno(*master
));
136 execlp(console_xterm_prog
, console_xterm_prog
, buf
, "-fg",
137 "white", "-bg", "black", "-g",
138 xterm_resolution
, NULL
);
139 ERR(console
, "error creating xterm (file not found?)\n");
143 /* most xterms like to print their window ID when used with -S;
144 * read it and continue before the user has a chance...
145 * NOTE: this is the reason we started xterm with ECHO off,
146 * we'll turn it back on below
149 for (i
=0; c
!='\n'; (status
=fread(&c
, 1, 1, *slave
)), i
++) {
150 if (status
== -1 && c
== '\0') {
151 /* wait for xterm to be created */
155 WARN(console
, "can't read xterm WID\n");
160 term
.c_lflag
|= ECHO
;
161 tcsetattr(fileno(*master
), TCSADRAIN
, &term
);