1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/ozone/platform/dri/virtual_terminal_manager.h"
11 #include <sys/ioctl.h>
14 #include "base/logging.h"
20 const char kTTYDevice
[] = "/dev/tty1";
26 VirtualTerminalManager::VirtualTerminalManager() {
27 // Use the current console.
28 fd_
= open(kTTYDevice
, O_RDWR
| O_CLOEXEC
, 0);
30 LOG(ERROR
) << "Failed to open '" << kTTYDevice
<< "' " << strerror(errno
);
32 if (ioctl(fd_
, VT_ACTIVATE
, kVT
) || ioctl(fd_
, VT_WAITACTIVE
, kVT
))
33 LOG(ERROR
) << "Failed to switch to VT: " << kVT
34 << " error: " << strerror(errno
);;
36 if (ioctl(fd_
, KDGETMODE
, &vt_mode_
))
37 LOG(ERROR
) << "Failed to get VT mode: " << strerror(errno
);
39 if (ioctl(fd_
, KDSETMODE
, KD_GRAPHICS
))
40 LOG(ERROR
) << "Failed to set graphics mode: " << strerror(errno
);
42 if (tcgetattr(fd_
, &terminal_attributes_
))
43 LOG(ERROR
) << "Failed to get terminal attributes";
45 // Stop the TTY from processing keys and echo-ing them to the terminal.
46 struct termios raw_attributes
= terminal_attributes_
;
47 cfmakeraw(&raw_attributes
);
48 raw_attributes
.c_oflag
|= OPOST
;
49 if (tcsetattr(fd_
, TCSANOW
, &raw_attributes
))
50 LOG(ERROR
) << "Failed to set raw attributes";
52 if (ioctl(fd_
, KDGKBMODE
, &previous_keyboard_mode_
))
53 LOG(ERROR
) << "Failed to get keyboard mode";
55 if (ioctl(fd_
, KDSKBMODE
, K_OFF
) && ioctl(fd_
, KDSKBMODE
, K_RAW
))
56 LOG(ERROR
) << "Failed to set keyboard mode";
59 VirtualTerminalManager::~VirtualTerminalManager() {
63 if (ioctl(fd_
, KDSETMODE
, &vt_mode_
))
64 LOG(ERROR
) << "Failed to restore VT mode";
66 if (ioctl(fd_
, KDSKBMODE
, previous_keyboard_mode_
))
67 LOG(ERROR
) << "Failed to restore keyboard mode";
69 if (tcsetattr(fd_
, TCSANOW
, &terminal_attributes_
))
70 LOG(ERROR
) << "Failed to restore terminal attributes";