66
77#include <fcntl.h>
88#include <linux/fb.h>
9- #include <linux/kd.h>
10- #include <linux/vt.h>
119#include <stdlib.h>
1210#include <sys/ioctl.h>
1311#include <sys/mman.h>
1412#include <twin.h>
1513#include <unistd.h>
1614
1715#include "linux_input.h"
16+ #include "linux_vt.h"
1817#include "twin_backend.h"
1918#include "twin_private.h"
2019
@@ -31,8 +30,6 @@ typedef struct {
3130
3231 /* Linux virtual terminal (VT) */
3332 int vt_fd ;
34- int vt_num ;
35- bool vt_active ;
3633
3734 /* Linux framebuffer */
3835 int fb_fd ;
@@ -139,51 +136,6 @@ static bool twin_fbdev_apply_config(twin_fbdev_t *tx)
139136 return true;
140137}
141138
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-
187139twin_context_t * twin_fbdev_init (int width , int height )
188140{
189141 char * fbdev_path = getenv (FBDEV_NAME );
@@ -210,7 +162,7 @@ twin_context_t *twin_fbdev_init(int width, int height)
210162 }
211163
212164 /* Set up virtual terminal environment */
213- if (!twin_vt_setup (tx )) {
165+ if (!twin_vt_setup (& tx -> vt_fd )) {
214166 goto bail_fb_fd ;
215167 }
216168
@@ -262,7 +214,7 @@ static void twin_fbdev_exit(twin_context_t *ctx)
262214 return ;
263215
264216 twin_fbdev_t * tx = PRIV (ctx );
265- ioctl (tx -> vt_fd , KDSETMODE , KD_TEXT );
217+ twin_vt_mode (tx -> vt_fd , KD_TEXT );
266218 munmap (tx -> fb_base , tx -> fb_len );
267219 twin_linux_input_destroy (tx -> input );
268220 close (tx -> vt_fd );
0 commit comments