From 0b49a8f782ef178d5aa22f189e275cfbc43967f3 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 8 Jan 2012 17:57:52 +0200 Subject: frontend: oshide->xenv refactoring change merged from pandora's SDL project --- frontend/linux/oshide.c | 268 --------------------------------------------- frontend/linux/oshide.h | 3 - frontend/linux/xenv.c | 281 ++++++++++++++++++++++++++++++++++++++++++++++++ frontend/linux/xenv.h | 5 + frontend/plat_omap.c | 13 ++- 5 files changed, 295 insertions(+), 275 deletions(-) delete mode 100644 frontend/linux/oshide.c delete mode 100644 frontend/linux/oshide.h create mode 100644 frontend/linux/xenv.c create mode 100644 frontend/linux/xenv.h (limited to 'frontend') diff --git a/frontend/linux/oshide.c b/frontend/linux/oshide.c deleted file mode 100644 index 203691f..0000000 --- a/frontend/linux/oshide.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - * (C) Gražvydas "notaz" Ignotas, 2009-2010 - * - * This work is licensed under the terms of any of these licenses - * (at your option): - * - GNU GPL, version 2 or later. - * - GNU LGPL, version 2.1 or later. - * See the COPYING file in the top-level directory. - */ - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#define PFX "oshide: " - -#define FPTR(f) typeof(f) * p##f -#define FPTR_LINK(xf, dl, f) { \ - xf.p##f = dlsym(dl, #f); \ - if (xf.p##f == NULL) { \ - fprintf(stderr, "missing symbol: %s\n", #f); \ - goto fail; \ - } \ -} - -struct xfuncs { -FPTR(XCreateBitmapFromData); -FPTR(XCreatePixmapCursor); -FPTR(XFreePixmap); -FPTR(XOpenDisplay); -FPTR(XDisplayName); -FPTR(XCloseDisplay); -FPTR(XCreateSimpleWindow); -FPTR(XChangeWindowAttributes); -FPTR(XSelectInput); -FPTR(XMapWindow); -FPTR(XNextEvent); -FPTR(XCheckTypedEvent); -FPTR(XUnmapWindow); -FPTR(XGrabKeyboard); -}; - - -static Cursor transparent_cursor(struct xfuncs *xf, Display *display, Window win) -{ - Cursor cursor; - Pixmap pix; - XColor dummy; - char d = 0; - - memset(&dummy, 0, sizeof(dummy)); - pix = xf->pXCreateBitmapFromData(display, win, &d, 1, 1); - cursor = xf->pXCreatePixmapCursor(display, pix, pix, - &dummy, &dummy, 0, 0); - xf->pXFreePixmap(display, pix); - return cursor; -} - -static void *x11h_handler(void *arg) -{ - struct xfuncs xf; - unsigned int display_width, display_height; - XSetWindowAttributes attributes; - Window win; - XEvent report; - Display *display; - Visual *visual; - void *x11lib; - int screen; - - memset(&xf, 0, sizeof(xf)); - x11lib = dlopen("libX11.so.6", RTLD_LAZY); - if (x11lib == NULL) { - fprintf(stderr, "libX11.so load failed:\n%s\n", dlerror()); - goto fail; - } - FPTR_LINK(xf, x11lib, XCreateBitmapFromData); - FPTR_LINK(xf, x11lib, XCreatePixmapCursor); - FPTR_LINK(xf, x11lib, XFreePixmap); - FPTR_LINK(xf, x11lib, XOpenDisplay); - FPTR_LINK(xf, x11lib, XDisplayName); - FPTR_LINK(xf, x11lib, XCloseDisplay); - FPTR_LINK(xf, x11lib, XCreateSimpleWindow); - FPTR_LINK(xf, x11lib, XChangeWindowAttributes); - FPTR_LINK(xf, x11lib, XSelectInput); - FPTR_LINK(xf, x11lib, XMapWindow); - FPTR_LINK(xf, x11lib, XNextEvent); - FPTR_LINK(xf, x11lib, XCheckTypedEvent); - FPTR_LINK(xf, x11lib, XUnmapWindow); - FPTR_LINK(xf, x11lib, XGrabKeyboard); - - //XInitThreads(); - - display = xf.pXOpenDisplay(NULL); - if (display == NULL) - { - fprintf(stderr, "cannot connect to X server %s, X handling disabled.\n", - xf.pXDisplayName(NULL)); - goto fail2; - } - - visual = DefaultVisual(display, 0); - if (visual->class != TrueColor) - fprintf(stderr, PFX "warning: non true color visual\n"); - - printf(PFX "X vendor: %s, rel: %d, display: %s, protocol ver: %d.%d\n", ServerVendor(display), - VendorRelease(display), DisplayString(display), ProtocolVersion(display), - ProtocolRevision(display)); - - screen = DefaultScreen(display); - - display_width = DisplayWidth(display, screen); - display_height = DisplayHeight(display, screen); - printf(PFX "display is %dx%d\n", display_width, display_height); - - win = xf.pXCreateSimpleWindow(display, - RootWindow(display, screen), - 0, 0, display_width, display_height, 0, - BlackPixel(display, screen), - BlackPixel(display, screen)); - - attributes.override_redirect = True; - attributes.cursor = transparent_cursor(&xf, display, win); - xf.pXChangeWindowAttributes(display, win, CWOverrideRedirect | CWCursor, &attributes); - - xf.pXSelectInput(display, win, ExposureMask | FocusChangeMask | KeyPressMask | KeyReleaseMask); - xf.pXMapWindow(display, win); - xf.pXGrabKeyboard(display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime); - // XSetIOErrorHandler - - while (1) - { - xf.pXNextEvent(display, &report); - switch (report.type) - { - case Expose: - while (xf.pXCheckTypedEvent(display, Expose, &report)) - ; - break; - - case FocusOut: - // XFocusChangeEvent - // printf("focus out\n"); - // xf.pXUnmapWindow(display, win); - break; - - case KeyPress: - // printf("press %d\n", report.xkey.keycode); - break; - - default: - break; - } - } - -fail2: - dlclose(x11lib); -fail: - fprintf(stderr, "x11 handling disabled.\n"); - return NULL; -} - -static struct termios g_kbd_termios_saved; -static int g_kbdfd; - -static void hidecon_start(void) -{ - struct termios kbd_termios; - 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; - } - - g_kbd_termios_saved = kbd_termios; - 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"); - - 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, 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() -{ - x11h_init(); - sleep(5); -} -#endif diff --git a/frontend/linux/oshide.h b/frontend/linux/oshide.h deleted file mode 100644 index f661305..0000000 --- a/frontend/linux/oshide.h +++ /dev/null @@ -1,3 +0,0 @@ -int oshide_init(void); -void oshide_finish(void); - diff --git a/frontend/linux/xenv.c b/frontend/linux/xenv.c new file mode 100644 index 0000000..3de7628 --- /dev/null +++ b/frontend/linux/xenv.c @@ -0,0 +1,281 @@ +/* + * (C) Gražvydas "notaz" Ignotas, 2009-2011 + * + * This work is licensed under the terms of any of these licenses + * (at your option): + * - GNU GPL, version 2 or later. + * - GNU LGPL, version 2.1 or later. + * See the COPYING file in the top-level directory. + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define PFX "xenv: " + +#define FPTR(f) typeof(f) * p##f +#define FPTR_LINK(xf, dl, f) { \ + xf.p##f = dlsym(dl, #f); \ + if (xf.p##f == NULL) { \ + fprintf(stderr, "missing symbol: %s\n", #f); \ + goto fail; \ + } \ +} + +struct xstuff { + Display *display; + FPTR(XCreateBitmapFromData); + FPTR(XCreatePixmapCursor); + FPTR(XFreePixmap); + FPTR(XOpenDisplay); + FPTR(XDisplayName); + FPTR(XCloseDisplay); + FPTR(XCreateSimpleWindow); + FPTR(XChangeWindowAttributes); + FPTR(XSelectInput); + FPTR(XMapWindow); + FPTR(XNextEvent); + FPTR(XCheckTypedEvent); + FPTR(XUnmapWindow); + FPTR(XGrabKeyboard); + FPTR(XPending); + FPTR(XLookupKeysym); + FPTR(XkbSetDetectableAutoRepeat); +}; + +static struct xstuff g_xstuff; + +static Cursor transparent_cursor(struct xstuff *xf, Display *display, Window win) +{ + Cursor cursor; + Pixmap pix; + XColor dummy; + char d = 0; + + memset(&dummy, 0, sizeof(dummy)); + pix = xf->pXCreateBitmapFromData(display, win, &d, 1, 1); + cursor = xf->pXCreatePixmapCursor(display, pix, pix, + &dummy, &dummy, 0, 0); + xf->pXFreePixmap(display, pix); + return cursor; +} + +static int x11h_init(void) +{ + unsigned int display_width, display_height; + Display *display; + XSetWindowAttributes attributes; + Window win; + Visual *visual; + void *x11lib; + int screen; + + memset(&g_xstuff, 0, sizeof(g_xstuff)); + x11lib = dlopen("libX11.so.6", RTLD_LAZY); + if (x11lib == NULL) { + fprintf(stderr, "libX11.so load failed:\n%s\n", dlerror()); + goto fail; + } + FPTR_LINK(g_xstuff, x11lib, XCreateBitmapFromData); + FPTR_LINK(g_xstuff, x11lib, XCreatePixmapCursor); + FPTR_LINK(g_xstuff, x11lib, XFreePixmap); + FPTR_LINK(g_xstuff, x11lib, XOpenDisplay); + FPTR_LINK(g_xstuff, x11lib, XDisplayName); + FPTR_LINK(g_xstuff, x11lib, XCloseDisplay); + FPTR_LINK(g_xstuff, x11lib, XCreateSimpleWindow); + FPTR_LINK(g_xstuff, x11lib, XChangeWindowAttributes); + FPTR_LINK(g_xstuff, x11lib, XSelectInput); + FPTR_LINK(g_xstuff, x11lib, XMapWindow); + FPTR_LINK(g_xstuff, x11lib, XNextEvent); + FPTR_LINK(g_xstuff, x11lib, XCheckTypedEvent); + FPTR_LINK(g_xstuff, x11lib, XUnmapWindow); + FPTR_LINK(g_xstuff, x11lib, XGrabKeyboard); + FPTR_LINK(g_xstuff, x11lib, XPending); + FPTR_LINK(g_xstuff, x11lib, XLookupKeysym); + FPTR_LINK(g_xstuff, x11lib, XkbSetDetectableAutoRepeat); + + //XInitThreads(); + + g_xstuff.display = display = g_xstuff.pXOpenDisplay(NULL); + if (display == NULL) + { + fprintf(stderr, "cannot connect to X server %s, X handling disabled.\n", + g_xstuff.pXDisplayName(NULL)); + goto fail2; + } + + visual = DefaultVisual(display, 0); + if (visual->class != TrueColor) + fprintf(stderr, PFX "warning: non true color visual\n"); + + printf(PFX "X vendor: %s, rel: %d, display: %s, protocol ver: %d.%d\n", ServerVendor(display), + VendorRelease(display), DisplayString(display), ProtocolVersion(display), + ProtocolRevision(display)); + + screen = DefaultScreen(display); + + display_width = DisplayWidth(display, screen); + display_height = DisplayHeight(display, screen); + printf(PFX "display is %dx%d\n", display_width, display_height); + + win = g_xstuff.pXCreateSimpleWindow(display, + RootWindow(display, screen), + 0, 0, display_width, display_height, 0, + BlackPixel(display, screen), + BlackPixel(display, screen)); + + attributes.override_redirect = True; + attributes.cursor = transparent_cursor(&g_xstuff, display, win); + g_xstuff.pXChangeWindowAttributes(display, win, CWOverrideRedirect | CWCursor, &attributes); + + g_xstuff.pXSelectInput(display, win, ExposureMask | FocusChangeMask | KeyPressMask | KeyReleaseMask); + g_xstuff.pXMapWindow(display, win); + g_xstuff.pXGrabKeyboard(display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime); + g_xstuff.pXkbSetDetectableAutoRepeat(display, 1, NULL); + // XSetIOErrorHandler + + return 0; +fail2: + dlclose(x11lib); +fail: + g_xstuff.display = NULL; + fprintf(stderr, "x11 handling disabled.\n"); + return -1; +} + +static int x11h_update(int *is_down) +{ + XEvent evt; + + while (g_xstuff.pXPending(g_xstuff.display)) + { + g_xstuff.pXNextEvent(g_xstuff.display, &evt); + switch (evt.type) + { + case Expose: + while (g_xstuff.pXCheckTypedEvent(g_xstuff.display, Expose, &evt)) + ; + break; + + case KeyPress: + *is_down = 1; + return g_xstuff.pXLookupKeysym(&evt.xkey, 0); + + case KeyRelease: + *is_down = 0; + return g_xstuff.pXLookupKeysym(&evt.xkey, 0); + // printf("press %d\n", evt.xkey.keycode); + } + } + + return NoSymbol; +} + +static struct termios g_kbd_termios_saved; +static int g_kbdfd = -1; + +static int tty_init(void) +{ + struct termios kbd_termios; + int mode; + + g_kbdfd = open("/dev/tty", O_RDWR); + if (g_kbdfd == -1) { + perror(PFX "open /dev/tty"); + return -1; + } + + 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; + } + + g_kbd_termios_saved = kbd_termios; + 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 0; + +fail: + close(g_kbdfd); + g_kbdfd = -1; + return -1; +} + +static void tty_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"); + + close(g_kbdfd); + g_kbdfd = -1; +} + +int xenv_init(void) +{ + int ret; + + ret = x11h_init(); + if (ret == 0) + return 0; + + ret = tty_init(); + if (ret == 0) + return 0; + + fprintf(stderr, PFX "error: both x11h_init and tty_init failed\n"); + return -1; +} + +int xenv_update(int *is_down) +{ + if (g_xstuff.display) + return x11h_update(is_down); + + // TODO: read tty? + return -1; +} + +void xenv_finish(void) +{ + // TODO: cleanup X? + tty_end(); +} diff --git a/frontend/linux/xenv.h b/frontend/linux/xenv.h new file mode 100644 index 0000000..948381e --- /dev/null +++ b/frontend/linux/xenv.h @@ -0,0 +1,5 @@ + +int xenv_init(void); +int xenv_update(int *is_down); +void xenv_finish(void); + diff --git a/frontend/plat_omap.c b/frontend/plat_omap.c index bee0912..b529cfa 100644 --- a/frontend/plat_omap.c +++ b/frontend/plat_omap.c @@ -16,7 +16,7 @@ #include "common/menu.h" #include "linux/fbdev.h" -#include "linux/oshide.h" +#include "linux/xenv.h" #include "plugin_lib.h" #include "pl_gun_ts.h" #include "omap.h" @@ -90,10 +90,15 @@ int omap_enable_layer(int enabled) void plat_video_menu_enter(int is_rom_loaded) { + int dummy; + g_menuscreen_ptr = vout_fbdev_resize(main_fb, g_menuscreen_w, g_menuscreen_h, 16, 0, 0, 0, 0, 3); if (g_menuscreen_ptr == NULL) fprintf(stderr, "warning: vout_fbdev_resize failed\n"); + + // hmh + xenv_update(&dummy); } void plat_video_menu_begin(void) @@ -153,7 +158,7 @@ void plat_init(void) exit(1); } - oshide_init(); + xenv_init(); w = h = 0; main_fb = vout_fbdev_init(main_fb_name, &w, &h, 16, 2); @@ -167,7 +172,7 @@ void plat_init(void) g_menuscreen_ptr = vout_fbdev_flip(main_fb); w = 640; - h = 512; // ?? + h = 512; layer_fb = vout_fbdev_init(layer_fb_name, &w, &h, 16, 3); if (layer_fb == NULL) { fprintf(stderr, "couldn't init fb: %s\n", layer_fb_name); @@ -198,6 +203,6 @@ void plat_finish(void) omap_enable_layer(0); vout_fbdev_finish(layer_fb); vout_fbdev_finish(main_fb); - oshide_finish(); + xenv_finish(); } -- cgit v1.2.3