6
6
7
7
#include <fcntl.h>
8
8
#include <linux/fb.h>
9
- #include <linux/kd.h>
10
- #include <linux/vt.h>
11
9
#include <stdlib.h>
12
10
#include <sys/ioctl.h>
13
11
#include <sys/mman.h>
14
12
#include <twin.h>
15
13
#include <unistd.h>
16
14
17
15
#include "linux_input.h"
16
+ #include "linux_vt.h"
18
17
#include "twin_backend.h"
19
18
#include "twin_private.h"
20
19
@@ -31,8 +30,6 @@ typedef struct {
31
30
32
31
/* Linux virtual terminal (VT) */
33
32
int vt_fd ;
34
- int vt_num ;
35
- bool vt_active ;
36
33
37
34
/* Linux framebuffer */
38
35
int fb_fd ;
@@ -139,51 +136,6 @@ static bool twin_fbdev_apply_config(twin_fbdev_t *tx)
139
136
return true;
140
137
}
141
138
142
- static int twin_vt_open (int vt_num )
143
- {
144
- int fd ;
145
-
146
- char vt_dev [30 ] = {0 };
147
- snprintf (vt_dev , 30 , "/dev/tty%d" , vt_num );
148
-
149
- fd = open (vt_dev , O_RDWR );
150
- if (fd < 0 ) {
151
- log_error ("Failed to open %s" , vt_dev );
152
- }
153
-
154
- return fd ;
155
- }
156
-
157
- static bool twin_vt_setup (twin_fbdev_t * tx )
158
- {
159
- /* Open VT0 to inquire information */
160
- if ((tx -> vt_fd = twin_vt_open (0 )) < -1 ) {
161
- log_error ("Failed to open VT0" );
162
- return false;
163
- }
164
-
165
- /* Inquire for current VT number */
166
- struct vt_stat vt ;
167
- if (ioctl (tx -> vt_fd , VT_GETSTATE , & vt ) == -1 ) {
168
- log_error ("Failed to get VT number" );
169
- return false;
170
- }
171
- tx -> vt_num = vt .v_active ;
172
-
173
- /* Open the VT */
174
- if ((tx -> vt_fd = twin_vt_open (tx -> vt_num )) < -1 ) {
175
- return false;
176
- }
177
-
178
- /* Set VT to graphics mode to inhibit command-line text */
179
- if (ioctl (tx -> vt_fd , KDSETMODE , KD_GRAPHICS ) < 0 ) {
180
- log_error ("Failed to set KD_GRAPHICS mode" );
181
- return false;
182
- }
183
-
184
- return true;
185
- }
186
-
187
139
twin_context_t * twin_fbdev_init (int width , int height )
188
140
{
189
141
char * fbdev_path = getenv (FBDEV_NAME );
@@ -210,7 +162,7 @@ twin_context_t *twin_fbdev_init(int width, int height)
210
162
}
211
163
212
164
/* Set up virtual terminal environment */
213
- if (!twin_vt_setup (tx )) {
165
+ if (!twin_vt_setup (& tx -> vt_fd )) {
214
166
goto bail_fb_fd ;
215
167
}
216
168
@@ -262,7 +214,7 @@ static void twin_fbdev_exit(twin_context_t *ctx)
262
214
return ;
263
215
264
216
twin_fbdev_t * tx = PRIV (ctx );
265
- ioctl (tx -> vt_fd , KDSETMODE , KD_TEXT );
217
+ twin_vt_mode (tx -> vt_fd , KD_TEXT );
266
218
munmap (tx -> fb_base , tx -> fb_len );
267
219
twin_linux_input_destroy (tx -> input );
268
220
close (tx -> vt_fd );
0 commit comments