3 * Copyright (C) 2007, Harbour, All rights reserved.
6 #include <F_Linux_Console_UI.H>
12 // ÏÓÔÁÌÓÑ ÐÏÓÌÅ probe()
15 // TODO: test if console in graphics mode (svgalib/etc.)
18 // ËÏÎÓÏÌØ ÄÏÌÖÎÁ ÉÍÅÔØ ÍÙÛØ É ËÌÁ×Õ - linux-2.6 input subsystem / gpm + kbd
21 // - 2 ÂÁÊÔÁ cursor position
22 // - char / attr array
24 void F_Linux_Console_UI::initial()
28 log("linux_console_ui", CHAT_LEVEL, "Gpm is missing.");
29 input = new F_Linux_Input;
31 log("linux_console_ui", CHAT_LEVEL, "Linux input subsystem is missing.");
32 // try to get working keyboard
34 input = new F_Linux_Keyboard;
36 log("linux_console_ui", CHAT_LEVEL, "Linux keyboard is missing, giving up.");
40 mouse->disable(); // we do not need double mouse events
41 // try to know screen width & height
44 if ((err = read(fileno(vcsa), &b, 2)) != 2) {
46 log("linux_console_ui", ALERT_LEVEL, "vcsa read error: %s",
49 log("linux_console_ui", ALERT_LEVEL, "short read from vcsa (%d) !", err);
52 log("linux_console_ui", CHAT_LEVEL, "w - %d, h - %d", b[1], b[0]);
53 display = new F_Linux_Console_Display(vcsa, b[1], b[0]);
54 // save display area to back_store
56 display->cursor(0); // cursor off
62 // ÓÏÂÉÒÁÅÍ ÓÏÂÙÔÉÑ ÏÔ ÕÓÔÒÏÊÓÔ× ÕÐÒÁ×ÌÅÎÉÑ É ÐÅÒÅÄÁÅÍ ÐÏ ÃÅÐÏÞËÅ
64 void F_Linux_Console_UI::run()
67 bool need_flush = false;
70 mouse->check_for_events();
71 input->check_for_events();
72 if (mouse->get_event(&iev))
73 event_queue.push_back(iev);
74 if (input->get_event(&iev))
75 event_queue.push_back(iev);
76 while (display->get_event(&iev)) {
77 event_queue.push_back(iev);
82 iev.type = F_DISPLAY_FLUSH;
83 iev.display.window = 0;
84 event_queue.push_back(iev);
87 if (event_queue.size()) {
88 while (event_queue.size()) { // process events
91 event_queue.erase(event_queue.begin());
98 bool F_Linux_Console_UI::exit_confirm(bool from_sighandler)
103 void F_Linux_Console_UI::refresh()
105 // refresh damaged windows
108 void F_Linux_Console_UI::sigcont()
110 debug("console continued");
115 void F_Linux_Console_UI::sigstop()
119 debug("console stopping");
122 void F_Linux_Console_UI::sigwinch()
124 exit_on_unimplemented("SIGWINCH");
127 #include <linux/vt.h>
128 #include <sys/ioctl.h>
130 bool F_Linux_Console_UI::probe()
132 if (strcmp(getenv("TERM"), "linux") && strcmp(getenv("TERM"), "linux"))
134 const char *tty = ttyname(fileno(stdout));
135 int tty_fd = open(tty, O_RDWR);
136 if (tty_fd < 0) { // can't open tty
137 debug("Can't open tty.");
141 if (ioctl(tty_fd, VT_GETMODE, &vtmode) < 0) {
143 debug("VT_GETMODE ioctl failed.");
146 if (!strstr(tty, "/dev/vc/")) {
147 debug("Looks like not a tty.");
150 char vcsa_n[32] = "/dev/vcsa";
151 strcat(vcsa_n, rindex(tty, '/') + 1);
152 vcsa = ::fopen(vcsa_n, "r+");
154 debug("Can't open /dev/vcsa.");
160 F_Linux_Console_UI::~F_Linux_Console_UI()