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.
12 #include <sys/ioctl.h>
25 char console_xterm_prog
[80];
26 char console_xterm_resolution
[10];
28 static BOOL32
wine_create_console(FILE **master
, FILE **slave
, int *pid
);
29 FILE *wine_openpty(int *master
, int *slave
, char *name
,
30 struct termios
*term
, struct winsize
*winsize
);
32 /* The console -- I chose to keep the master and slave
33 * (UNIX) file descriptors around in case they are needed for
34 * ioctls later. The pid is needed to destroy the xterm on close
36 typedef struct _XTERM_CONSOLE
{
37 FILE *master
; /* xterm side of pty */
38 FILE *slave
; /* wine side of pty */
39 int pid
; /* xterm's pid, -1 if no xterm */
42 static XTERM_CONSOLE xterm_console
;
45 FILE *old_in
, *old_out
;
49 /* Here, this is a supplementary driver so we should remember to call
51 chain
.init
= driver
.init
;
52 driver
.init
= XTERM_Init
;
54 chain
.close
= driver
.close
;
55 driver
.close
= XTERM_Close
;
57 chain
.resizeScreen
= driver
.resizeScreen
;
58 driver
.resizeScreen
= XTERM_ResizeScreen
;
60 /* Read in driver configuration */
61 PROFILE_GetWineIniString("console", "XtermProg",
62 "xterm", console_xterm_prog
, 79);
63 PROFILE_GetWineIniString("console", "XtermResolution",
64 "80x24", console_xterm_resolution
, 9);
70 wine_create_console(&xterm_console
.master
, &xterm_console
.slave
,
73 old_in
= driver
.console_in
;
74 driver
.console_in
= xterm_console
.slave
;
76 old_out
= driver
.console_out
;
77 driver
.console_out
= xterm_console
.slave
;
79 /* Then call the chain... */
86 /* Call the chain first... */
90 driver
.console_in
= old_in
;
91 driver
.console_out
= old_out
;
93 /* make sure a xterm exists to kill */
94 if (xterm_console
.pid
!= -1) {
95 kill(xterm_console
.pid
, SIGTERM
);
99 void XTERM_ResizeScreen(int x
, int y
)
103 /* Call the chain first, there shoudln't be any... */
104 if (chain
.resizeScreen
)
105 chain
.resizeScreen(x
, y
);
107 sprintf(temp
, "\x1b[8;%d;%dt", y
, x
);
108 CONSOLE_WriteRawString(temp
);
110 CONSOLE_NotifyResizeScreen(x
, y
);
114 static BOOL32
wine_create_console(FILE **master
, FILE **slave
, int *pid
)
116 /* There is definately a bug in this routine that causes a lot
117 of garbage to be written to the screen, but I can't find it...
126 if (tcgetattr(0, &term
) < 0) return FALSE
;
127 term
.c_lflag
|= ICANON
;
128 term
.c_lflag
&= ~ECHO
;
129 if (wine_openpty(&tmaster
, &tslave
, NULL
, &term
, NULL
) < 0)
131 *master
= fdopen(tmaster
, "r+");
132 *slave
= fdopen(tslave
, "r+");
134 if ((*pid
=fork()) == 0) {
135 tcsetattr(fileno(*slave
), TCSADRAIN
, &term
);
136 sprintf(buf
, "-Sxx%d", fileno(*master
));
137 execlp(console_xterm_prog
, console_xterm_prog
, buf
, "-fg",
138 "white", "-bg", "black", "-g",
139 console_xterm_resolution
, NULL
);
140 ERR(console
, "error creating xterm (file not found?)\n");
144 /* most xterms like to print their window ID when used with -S;
145 * read it and continue before the user has a chance...
146 * NOTE: this is the reason we started xterm with ECHO off,
147 * we'll turn it back on below
150 for (i
=0; c
!='\n'; (status
=fread(&c
, 1, 1, *slave
)), i
++) {
151 if (status
== -1 && c
== '\0') {
152 /* wait for xterm to be created */
156 WARN(console
, "can't read xterm WID\n");
161 term
.c_lflag
|= ECHO
;
162 tcsetattr(fileno(*master
), TCSADRAIN
, &term
);