Switch to tty7 on POSIX fbdev

This commit is contained in:
Kuba Szczodrzyński 2024-02-12 16:32:38 +01:00
parent d77428db54
commit 9b3c88492c
No known key found for this signature in database
GPG Key ID: 43037AC62A600562
2 changed files with 13 additions and 3 deletions

View File

@ -203,7 +203,7 @@ void PosixDevice::update_backlight()
f << brightness;
f.close();
} else {
perror("Brightness write failed");
perror("Brightness write failed (are you root?)");
}
}
#endif

View File

@ -30,6 +30,7 @@
#include <fcntl.h>
#include <algorithm>
#include <fstream>
#include <linux/vt.h>
#if USE_BSD_EVDEV
#include <dev/evdev/input.h>
@ -83,6 +84,15 @@ static void* gui_entrypoint(void* arg)
void TftFbdevDrv::init(int32_t w, int h)
{
// try to switch the active tty to tty7
int tty_fd = open("/dev/tty0", O_WRONLY);
if(tty_fd == -1) {
perror("Couldn't open /dev/tty0 (try running as root)");
} else {
if(ioctl(tty_fd, VT_ACTIVATE, 7) == -1) perror("Couldn't change active tty");
}
close(tty_fd);
// check active tty
std::ifstream f;
f.open("/sys/class/tty/tty0/active");
@ -92,9 +102,9 @@ void TftFbdevDrv::init(int32_t w, int h)
f.close();
// try to hide the cursor
int tty_fd = open(tty.c_str(), O_WRONLY);
tty_fd = open(tty.c_str(), O_WRONLY);
if(tty_fd == -1) {
perror("Couldn't open tty");
perror("Couldn't open active tty (try running as root)");
} else {
write(tty_fd, "\033[?25l", 6);
}