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.
16 #include <sys/ioctl.h>
23 #include "debugtools.h"
25 DEFAULT_DEBUG_CHANNEL(console
);
27 char console_xterm_prog
[80];
29 static BOOL
wine_create_console(FILE **master
, FILE **slave
, pid_t
*pid
);
30 int wine_openpty(int *master
, int *slave
, char *name
,
31 struct termios
*term
, struct winsize
*winsize
);
33 /* The console -- I chose to keep the master and slave
34 * (UNIX) file descriptors around in case they are needed for
35 * ioctls later. The pid is needed to destroy the xterm on close
37 typedef struct _XTERM_CONSOLE
{
38 FILE *master
; /* xterm side of pty */
39 FILE *slave
; /* wine side of pty */
40 pid_t pid
; /* xterm's pid, -1 if no xterm */
43 static XTERM_CONSOLE xterm_console
;
46 FILE *old_in
, *old_out
;
48 void XTERM_Start(void)
50 /* Here, this is a supplementary driver so we should remember to call
52 chain
.init
= driver
.init
;
53 driver
.init
= XTERM_Init
;
55 chain
.close
= driver
.close
;
56 driver
.close
= XTERM_Close
;
58 chain
.resizeScreen
= driver
.resizeScreen
;
59 driver
.resizeScreen
= XTERM_ResizeScreen
;
61 /* Read in driver configuration */
62 PROFILE_GetWineIniString("console", "XtermProg",
63 "xterm", console_xterm_prog
, 79);
69 wine_create_console(&xterm_console
.master
, &xterm_console
.slave
,
72 old_in
= driver
.console_in
;
73 driver
.console_in
= xterm_console
.slave
;
75 old_out
= driver
.console_out
;
76 driver
.console_out
= xterm_console
.slave
;
78 /* Then call the chain... */
85 /* Call the chain first... */
89 driver
.console_in
= old_in
;
90 driver
.console_out
= old_out
;
92 /* make sure a xterm exists to kill */
93 if (xterm_console
.pid
!= -1) {
94 kill(xterm_console
.pid
, SIGTERM
);
98 void XTERM_ResizeScreen(int x
, int y
)
102 /* Call the chain first, there shoudln't be any... */
103 if (chain
.resizeScreen
)
104 chain
.resizeScreen(x
, y
);
106 sprintf(temp
, "\x1b[8;%d;%dt", y
, x
);
107 CONSOLE_WriteRawString(temp
);
109 CONSOLE_NotifyResizeScreen(x
, y
);
113 static BOOL
wine_create_console(FILE **master
, FILE **slave
, pid_t
*pid
)
115 /* There is definately a bug in this routine that causes a lot
116 of garbage to be written to the screen, but I can't find it...
124 char xterm_resolution
[10];
126 sprintf(xterm_resolution
, "%dx%d", driver
.x_res
,
129 if (tcgetattr(0, &term
) < 0) return FALSE
;
130 term
.c_lflag
|= ICANON
;
131 term
.c_lflag
&= ~ECHO
;
132 if (wine_openpty(&tmaster
, &tslave
, NULL
, &term
, NULL
) < 0)
134 *master
= fdopen(tmaster
, "r+");
135 *slave
= fdopen(tslave
, "r+");
137 if ((*pid
=fork()) == 0) {
138 tcsetattr(fileno(*slave
), TCSADRAIN
, &term
);
139 sprintf(buf
, "-Sxx%d", fileno(*master
));
140 execlp(console_xterm_prog
, console_xterm_prog
, buf
, "-fg",
141 "white", "-bg", "black", "-g",
142 xterm_resolution
, NULL
);
143 ERR("error creating xterm (file not found?)\n");
147 /* most xterms like to print their window ID when used with -S;
148 * read it and continue before the user has a chance...
149 * NOTE: this is the reason we started xterm with ECHO off,
150 * we'll turn it back on below
153 for (i
=0; c
!='\n'; (status
=fread(&c
, 1, 1, *slave
)), i
++) {
154 if (status
== -1 && c
== '\0') {
155 /* wait for xterm to be created */
159 WARN("can't read xterm WID\n");
164 term
.c_lflag
|= ECHO
;
165 tcsetattr(fileno(*master
), TCSADRAIN
, &term
);