X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=linux%2Foshide.c;fp=linux%2Fx11h.c;h=e66aaaee90462ad3001e33e65b1f05d23d87a7f4;hb=f6eaae4f09c6abab99692900a31c1df2a06b99af;hp=4ca5d30275427f8c0e7c84d9969c5586d7c48bce;hpb=0c9ae59222a6fa9af18dcc072fdfb06cfca124d6;p=libpicofe.git diff --git a/linux/x11h.c b/linux/oshide.c similarity index 64% rename from linux/x11h.c rename to linux/oshide.c index 4ca5d30..e66aaae 100644 --- a/linux/x11h.c +++ b/linux/oshide.c @@ -1,10 +1,22 @@ #include #include #include + #include #include #include +#include +#include +#include +#include +#include +#include +#include + +#define PFX "oshide: " +#define TERMIOS_DUMP_FILE "/tmp/pico_tios" + #define FPTR(f) typeof(f) * p##f #define FPTR_LINK(xf, dl, f) { \ xf.p##f = dlsym(dl, #f); \ @@ -92,13 +104,9 @@ static void *x11h_handler(void *arg) visual = DefaultVisual(display, 0); if (visual->class != TrueColor) - { - fprintf(stderr, "cannot handle non true color visual\n"); - xf.pXCloseDisplay(display); - goto fail2; - } + fprintf(stderr, PFX "warning: non true color visual\n"); - printf("x11h: X vendor: %s, rel: %d, display: %s, protocol ver: %d.%d\n", ServerVendor(display), + printf(PFX "X vendor: %s, rel: %d, display: %s, protocol ver: %d.%d\n", ServerVendor(display), VendorRelease(display), DisplayString(display), ProtocolVersion(display), ProtocolRevision(display)); @@ -106,7 +114,7 @@ static void *x11h_handler(void *arg) display_width = DisplayWidth(display, screen); display_height = DisplayHeight(display, screen); - printf("x11h: display is %dx%d\n", display_width, display_height); + printf(PFX "display is %dx%d\n", display_width, display_height); win = xf.pXCreateSimpleWindow(display, RootWindow(display, screen), @@ -155,21 +163,103 @@ fail: return NULL; } -int x11h_init(void) +static struct termios g_kbd_termios_saved; +static int g_kbdfd; + +static void hidecon_start(void) +{ + struct termios kbd_termios; + FILE *tios_f; + int mode; + + g_kbdfd = open("/dev/tty", O_RDWR); + if (g_kbdfd == -1) { + perror(PFX "open /dev/tty"); + return; + } + + if (ioctl(g_kbdfd, KDGETMODE, &mode) == -1) { + perror(PFX "(not hiding FB): KDGETMODE"); + goto fail; + } + + if (tcgetattr(g_kbdfd, &kbd_termios) == -1) { + perror(PFX "tcgetattr"); + goto fail; + } + + /* dump for picorestore */ + g_kbd_termios_saved = kbd_termios; + tios_f = fopen(TERMIOS_DUMP_FILE, "wb"); + if (tios_f) { + fwrite(&kbd_termios, sizeof(kbd_termios), 1, tios_f); + fclose(tios_f); + } + + kbd_termios.c_lflag &= ~(ICANON | ECHO); // | ISIG); + kbd_termios.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); + kbd_termios.c_cc[VMIN] = 0; + kbd_termios.c_cc[VTIME] = 0; + + if (tcsetattr(g_kbdfd, TCSAFLUSH, &kbd_termios) == -1) { + perror(PFX "tcsetattr"); + goto fail; + } + + if (ioctl(g_kbdfd, KDSETMODE, KD_GRAPHICS) == -1) { + perror(PFX "KDSETMODE KD_GRAPHICS"); + tcsetattr(g_kbdfd, TCSAFLUSH, &g_kbd_termios_saved); + goto fail; + } + + return; + +fail: + close(g_kbdfd); + g_kbdfd = -1; +} + +static void hidecon_end(void) +{ + if (g_kbdfd < 0) + return; + + if (ioctl(g_kbdfd, KDSETMODE, KD_TEXT) == -1) + perror(PFX "KDSETMODE KD_TEXT"); + + if (tcsetattr(g_kbdfd, TCSAFLUSH, &g_kbd_termios_saved) == -1) + perror(PFX "tcsetattr"); + + remove(TERMIOS_DUMP_FILE); + + close(g_kbdfd); + g_kbdfd = -1; +} + +int oshide_init(void) { pthread_t tid; int ret; ret = pthread_create(&tid, NULL, x11h_handler, NULL); if (ret != 0) { - fprintf(stderr, "x11h: failed to create thread: %d\n", ret); + fprintf(stderr, PFX "failed to create thread: %d\n", ret); return ret; } pthread_detach(tid); + hidecon_start(); + return 0; } +void oshide_finish(void) +{ + /* XXX: the X thread.. */ + + hidecon_end(); +} + #if 0 int main() {