limited minimize support
authornotaz <notasas@gmail.com>
Mon, 9 Apr 2012 22:27:55 +0000 (01:27 +0300)
committernotaz <notasas@gmail.com>
Mon, 9 Apr 2012 23:59:50 +0000 (02:59 +0300)
might not work with multiple SDL apps at once

src/video/omapdss/linux/fbdev.c
src/video/omapdss/linux/fbdev.h
src/video/omapdss/linux/xenv.c
src/video/omapdss/linux/xenv.h
src/video/omapdss/osdl.h
src/video/omapdss/osdl_input.c
src/video/omapdss/osdl_video.c
src/video/omapdss/sdlif.c

index afd5531..ec3d5c7 100644 (file)
@@ -22,6 +22,8 @@
 
 #include "fbdev.h"
 
+#define PFX "fbdev: "
+
 struct vout_fbdev {
        int     fd;
        void    *mem;
@@ -32,6 +34,8 @@ struct vout_fbdev {
        int     fb_size;
        int     buffer_count;
        int     top_border, bottom_border;
+       void    *mem_saved;
+       size_t  mem_saved_size;
 };
 
 void *vout_fbdev_flip(struct vout_fbdev *fbdev)
@@ -83,7 +87,7 @@ void *vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h, int bpp,
        {
                if (fbdev->fbvar_new.bits_per_pixel != bpp ||
                                w != fbdev->fbvar_new.xres || h != fbdev->fbvar_new.yres)
-                       printf(switching to %dx%d@%d\n", w, h, bpp);
+                       printf(PFX "switching to %dx%d@%d\n", w, h, bpp);
 
                fbdev->fbvar_new.xres = w;
                fbdev->fbvar_new.yres = h;
@@ -105,12 +109,12 @@ void *vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h, int bpp,
                        fbdev->fbvar_new.yres_virtual = h_total;
                        ret = ioctl(fbdev->fd, FBIOPUT_VSCREENINFO, &fbdev->fbvar_new);
                        if (ret == -1) {
-                               perror("FBIOPUT_VSCREENINFO ioctl");
+                               perror(PFX "FBIOPUT_VSCREENINFO ioctl");
                                return NULL;
                        }
                        fbdev->buffer_count = 1;
                        fbdev->buffer_write = 0;
-                       fprintf(stderr, "Warning: failed to increase virtual resolution, "
+                       fprintf(stderr, PFX "Warning: failed to increase virtual resolution, "
                                        "multibuffering disabled\n");
                }
 
@@ -129,7 +133,7 @@ void *vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h, int bpp,
 
        fbdev->mem = mmap(0, mem_size, PROT_WRITE|PROT_READ, MAP_SHARED, fbdev->fd, 0);
        if (fbdev->mem == MAP_FAILED && fbdev->buffer_count > 1) {
-               fprintf(stderr, "Warning: can't map %zd bytes, doublebuffering disabled\n", mem_size);
+               fprintf(stderr, PFX "Warning: can't map %zd bytes, doublebuffering disabled\n", mem_size);
                fbdev->buffer_count = 1;
                fbdev->buffer_write = 0;
                mem_size = fbdev->fb_size;
@@ -138,7 +142,7 @@ void *vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h, int bpp,
        if (fbdev->mem == MAP_FAILED) {
                fbdev->mem = NULL;
                fbdev->mem_size = 0;
-               perror("mmap framebuffer");
+               perror(PFX "mmap framebuffer");
                return NULL;
        }
 
@@ -184,14 +188,14 @@ struct vout_fbdev *vout_fbdev_init(const char *fbdev_name, int *w, int *h, int b
 
        fbdev->fd = open(fbdev_name, O_RDWR);
        if (fbdev->fd == -1) {
-               fprintf(stderr, "%s: ", fbdev_name);
+               fprintf(stderr, PFX "%s: ", fbdev_name);
                perror("open");
                goto fail_open;
        }
 
        ret = ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->fbvar_old);
        if (ret == -1) {
-               perror("FBIOGET_VSCREENINFO ioctl");
+               perror(PFX "FBIOGET_VSCREENINFO ioctl");
                goto fail;
        }
 
@@ -208,8 +212,8 @@ struct vout_fbdev *vout_fbdev_init(const char *fbdev_name, int *w, int *h, int b
        if (pret == NULL)
                goto fail;
 
-       printf("%s: %ix%i@%d\n", fbdev_name, fbdev->fbvar_new.xres, fbdev->fbvar_new.yres,
-               fbdev->fbvar_new.bits_per_pixel);
+       printf(PFX "%s: %ix%i@%d\n", fbdev_name, fbdev->fbvar_new.xres,
+               fbdev->fbvar_new.yres, fbdev->fbvar_new.bits_per_pixel);
        *w = fbdev->fbvar_new.xres;
        *h = fbdev->fbvar_new.yres;
 
@@ -219,7 +223,7 @@ struct vout_fbdev *vout_fbdev_init(const char *fbdev_name, int *w, int *h, int b
        ret = 0;
        ret = ioctl(fbdev->fd, FBIO_WAITFORVSYNC, &ret);
        if (ret != 0)
-               fprintf(stderr, "Warning: vsync doesn't seem to be supported\n");
+               fprintf(stderr, PFX "Warning: vsync doesn't seem to be supported\n");
 
        if (fbdev->buffer_count > 1) {
                fbdev->buffer_write = 0;
@@ -227,7 +231,7 @@ struct vout_fbdev *vout_fbdev_init(const char *fbdev_name, int *w, int *h, int b
                ret = ioctl(fbdev->fd, FBIOPAN_DISPLAY, &fbdev->fbvar_new);
                if (ret != 0) {
                        fbdev->buffer_count = 1;
-                       fprintf(stderr, "Warning: can't pan display, doublebuffering disabled\n");
+                       fprintf(stderr, PFX "Warning: can't pan display, doublebuffering disabled\n");
                }
        }
 
@@ -241,14 +245,66 @@ fail_open:
        return NULL;
 }
 
-void vout_fbdev_finish(struct vout_fbdev *fbdev)
+static void vout_fbdev_release(struct vout_fbdev *fbdev)
 {
        ioctl(fbdev->fd, FBIOPUT_VSCREENINFO, &fbdev->fbvar_old);
        if (fbdev->mem != MAP_FAILED)
                munmap(fbdev->mem, fbdev->mem_size);
+       fbdev->mem = NULL;
+}
+
+int vout_fbdev_save(struct vout_fbdev *fbdev)
+{
+       void *tmp;
+
+       if (fbdev == NULL || fbdev->mem == NULL || fbdev->mem == MAP_FAILED) {
+               fprintf(stderr, PFX "bad args for save\n");
+               return -1;
+       }
+
+       if (fbdev->mem_saved_size < fbdev->mem_size) {
+               tmp = realloc(fbdev->mem_saved, fbdev->mem_size);
+               if (tmp == NULL)
+                       return -1;
+               fbdev->mem_saved = tmp;
+       }
+       memcpy(fbdev->mem_saved, fbdev->mem, fbdev->mem_size);
+       fbdev->mem_saved_size = fbdev->mem_size;
+
+       vout_fbdev_release(fbdev);
+       return 0;
+}
+
+int vout_fbdev_restore(struct vout_fbdev *fbdev)
+{
+       int ret;
+
+       if (fbdev == NULL || fbdev->mem != NULL) {
+               fprintf(stderr, PFX "bad args/state for restore\n");
+               return -1;
+       }
+
+       fbdev->mem = mmap(0, fbdev->mem_size, PROT_WRITE|PROT_READ, MAP_SHARED, fbdev->fd, 0);
+       if (fbdev->mem == MAP_FAILED) {
+               perror(PFX "restore: memory restore failed");
+               return -1;
+       }
+       memcpy(fbdev->mem, fbdev->mem_saved, fbdev->mem_size);
+
+       ret = ioctl(fbdev->fd, FBIOPUT_VSCREENINFO, &fbdev->fbvar_new);
+       if (ret == -1) {
+               perror(PFX "restore: FBIOPUT_VSCREENINFO");
+               return -1;
+       }
+
+       return 0;
+}
+
+void vout_fbdev_finish(struct vout_fbdev *fbdev)
+{
+       vout_fbdev_release(fbdev);
        if (fbdev->fd >= 0)
                close(fbdev->fd);
-       fbdev->mem = NULL;
        fbdev->fd = -1;
        free(fbdev);
 }
index 2db9163..88cd519 100644 (file)
@@ -9,4 +9,6 @@ void *vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h, int bpp,
 void  vout_fbdev_clear(struct vout_fbdev *fbdev);
 void  vout_fbdev_clear_lines(struct vout_fbdev *fbdev, int y, int count);
 int   vout_fbdev_get_fd(struct vout_fbdev *fbdev);
+int   vout_fbdev_save(struct vout_fbdev *fbdev);
+int   vout_fbdev_restore(struct vout_fbdev *fbdev);
 void  vout_fbdev_finish(struct vout_fbdev *fbdev);
index c2cd603..40bf92c 100644 (file)
@@ -25,6 +25,8 @@
 #include <termios.h>
 #include <linux/kd.h>
 
+#include "xenv.h"
+
 #define PFX "xenv: "
 
 #define FPTR(f) typeof(f) * p##f
@@ -38,6 +40,7 @@
 
 struct xstuff {
        Display *display;
+       Window window;
        FPTR(XCreateBitmapFromData);
        FPTR(XCreatePixmapCursor);
        FPTR(XFreePixmap);
@@ -50,11 +53,17 @@ struct xstuff {
        FPTR(XMapWindow);
        FPTR(XNextEvent);
        FPTR(XCheckTypedEvent);
-       FPTR(XUnmapWindow);
+       FPTR(XWithdrawWindow);
        FPTR(XGrabKeyboard);
        FPTR(XPending);
        FPTR(XLookupKeysym);
        FPTR(XkbSetDetectableAutoRepeat);
+       FPTR(XStoreName);
+       FPTR(XIconifyWindow);
+       FPTR(XMoveResizeWindow);
+       FPTR(XInternAtom);
+       FPTR(XSetWMHints);
+       FPTR(XSync);
 };
 
 static struct xstuff g_xstuff;
@@ -74,13 +83,14 @@ static Cursor transparent_cursor(struct xstuff *xf, Display *display, Window win
        return cursor;
 }
 
-static int x11h_init(void)
+static int x11h_init(int *xenv_flags, const char *window_title)
 {
        unsigned int display_width, display_height;
        Display *display;
        XSetWindowAttributes attributes;
        Window win;
        Visual *visual;
+       long evt_mask;
        void *x11lib;
        int screen;
 
@@ -102,11 +112,17 @@ static int x11h_init(void)
        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, XWithdrawWindow);
        FPTR_LINK(g_xstuff, x11lib, XGrabKeyboard);
        FPTR_LINK(g_xstuff, x11lib, XPending);
        FPTR_LINK(g_xstuff, x11lib, XLookupKeysym);
        FPTR_LINK(g_xstuff, x11lib, XkbSetDetectableAutoRepeat);
+       FPTR_LINK(g_xstuff, x11lib, XStoreName);
+       FPTR_LINK(g_xstuff, x11lib, XIconifyWindow);
+       FPTR_LINK(g_xstuff, x11lib, XMoveResizeWindow);
+       FPTR_LINK(g_xstuff, x11lib, XInternAtom);
+       FPTR_LINK(g_xstuff, x11lib, XSetWMHints);
+       FPTR_LINK(g_xstuff, x11lib, XSync);
 
        //XInitThreads();
 
@@ -132,23 +148,30 @@ static int x11h_init(void)
        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));
+       g_xstuff.window = 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 | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
+       if (window_title != NULL)
+               g_xstuff.pXStoreName(display, win, window_title);
+       evt_mask = ExposureMask | FocusChangeMask | PropertyChangeMask;
+       if (xenv_flags && (*xenv_flags & XENV_CAP_KEYS))
+               evt_mask |= KeyPressMask | KeyReleaseMask;
+       if (xenv_flags && (*xenv_flags & XENV_CAP_MOUSE))
+               evt_mask |= ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
+       g_xstuff.pXSelectInput(display, win, evt_mask);
        g_xstuff.pXMapWindow(display, win);
        g_xstuff.pXGrabKeyboard(display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
        g_xstuff.pXkbSetDetectableAutoRepeat(display, 1, NULL);
        // XSetIOErrorHandler
 
+       // we don't know when event dispatch will be called, so sync now
+       g_xstuff.pXSync(display, False);
+
        return 0;
 fail2:
        dlclose(x11lib);
@@ -208,6 +231,86 @@ static void x11h_update(int (*key_cb)(void *cb_arg, int kc, int is_pressed),
        }
 }
 
+static void x11h_wait_vmstate(void)
+{
+       Atom wm_state = g_xstuff.pXInternAtom(g_xstuff.display, "WM_STATE", False);
+       XEvent evt;
+       int i;
+
+       usleep(20000);
+
+       for (i = 0; i < 20; i++) {
+               while (g_xstuff.pXPending(g_xstuff.display)) {
+                       g_xstuff.pXNextEvent(g_xstuff.display, &evt);
+                       // printf("w event %d\n", evt.type);
+                       if (evt.type == PropertyNotify && evt.xproperty.atom == wm_state)
+                               return;
+               }
+               usleep(200000);
+       }
+
+       fprintf(stderr, PFX "timeout waiting for wm_state change\n");
+}
+
+static int x11h_minimize(void)
+{
+       XSetWindowAttributes attributes;
+       Display *display = g_xstuff.display;
+       Window window = g_xstuff.window;
+       int screen = DefaultScreen(g_xstuff.display);
+       int display_width, display_height;
+       XWMHints wm_hints;
+       XEvent evt;
+
+       g_xstuff.pXWithdrawWindow(display, window, screen);
+
+       attributes.override_redirect = False;
+       g_xstuff.pXChangeWindowAttributes(display, window,
+               CWOverrideRedirect, &attributes);
+
+       wm_hints.flags = StateHint;
+       wm_hints.initial_state = IconicState;
+       g_xstuff.pXSetWMHints(display, window, &wm_hints);
+
+       g_xstuff.pXMapWindow(display, window);
+
+       while (g_xstuff.pXNextEvent(display, &evt) == 0)
+       {
+               // printf("m event %d\n", evt.type);
+               switch (evt.type)
+               {
+                       case FocusIn:
+                               goto out;
+                       default:
+                               break;
+               }
+       }
+
+out:
+       g_xstuff.pXWithdrawWindow(display, window, screen);
+
+       // must wait for some magic vmstate property change before setting override_redirect
+       x11h_wait_vmstate();
+
+       attributes.override_redirect = True;
+       g_xstuff.pXChangeWindowAttributes(display, window,
+               CWOverrideRedirect, &attributes);
+
+       // fixup window after resize on override_redirect loss
+       display_width = DisplayWidth(display, screen);
+       display_height = DisplayHeight(display, screen);
+       g_xstuff.pXMoveResizeWindow(display, window, 0, 0, display_width, display_height);
+
+       g_xstuff.pXMapWindow(display, window);
+       g_xstuff.pXGrabKeyboard(display, window, False, GrabModeAsync, GrabModeAsync, CurrentTime);
+       g_xstuff.pXkbSetDetectableAutoRepeat(display, 1, NULL);
+
+       // we don't know when event dispatch will be called, so sync now
+       g_xstuff.pXSync(display, False);
+
+       return 0;
+}
+
 static struct termios g_kbd_termios_saved;
 static int g_kbdfd = -1;
 
@@ -272,17 +375,16 @@ static void tty_end(void)
        g_kbdfd = -1;
 }
 
-int xenv_init(int *have_mouse_events)
+int xenv_init(int *xenv_flags, const char *window_title)
 {
-       int have_mouse = 0;
        int ret;
 
-       ret = x11h_init();
-       if (ret == 0) {
-               have_mouse = 1;
+       ret = x11h_init(xenv_flags, window_title);
+       if (ret == 0)
                goto out;
-       }
 
+       if (xenv_flags != NULL)
+               *xenv_flags &= ~(XENV_CAP_KEYS | XENV_CAP_MOUSE); /* TODO? */
        ret = tty_init();
        if (ret == 0)
                goto out;
@@ -290,8 +392,6 @@ int xenv_init(int *have_mouse_events)
        fprintf(stderr, PFX "error: both x11h_init and tty_init failed\n");
        ret = -1;
 out:
-       if (have_mouse_events != NULL)
-               *have_mouse_events = have_mouse;
        return ret;
 }
 
@@ -309,8 +409,47 @@ int xenv_update(int (*key_cb)(void *cb_arg, int kc, int is_pressed),
        return -1;
 }
 
+/* blocking minimize until user maximizes again */
+int xenv_minimize(void)
+{
+       int ret;
+
+       if (g_xstuff.display) {
+               xenv_update(NULL, NULL, NULL, NULL);
+               ret = x11h_minimize();
+               xenv_update(NULL, NULL, NULL, NULL);
+               return ret;
+       }
+
+       return -1;
+}
+
 void xenv_finish(void)
 {
        // TODO: cleanup X?
        tty_end();
 }
+
+#if 0
+int main()
+{
+       int i, r, d;
+
+       xenv_init("just a test");
+
+       for (i = 0; i < 5; i++) {
+               while ((r = xenv_update(&d)) > 0)
+                       printf("%d %x %d\n", d, r, r);
+               sleep(1);
+
+               if (i == 1)
+                       xenv_minimize();
+               printf("ll %d\n", i);
+       }
+
+       printf("xenv_finish..\n");
+       xenv_finish();
+
+       return 0;
+}
+#endif
index 4c5281c..6abda19 100644 (file)
@@ -1,5 +1,10 @@
 
-int  xenv_init(int *have_mouse_events);
+#define XENV_CAP_KEYS  (1<<0)
+#define XENV_CAP_MOUSE (1<<1)
+
+/* xenv_flags specify if we need keys and mouse,
+ * on return, flag is removed if input is not available */
+int  xenv_init(int *xenv_flags, const char *window_title);
 
 /* read events from X, calling key_cb for key, mouseb_cb for mouse button
  * and mousem_cb for mouse motion events */
@@ -8,5 +13,6 @@ int  xenv_update(int (*key_cb)(void *cb_arg, int kc, int is_pressed),
                 int (*mousem_cb)(void *cb_arg, int x, int y),
                 void *cb_arg);
 
+int  xenv_minimize(void);
 void xenv_finish(void);
 
index 2fc418c..3ca1bf5 100644 (file)
@@ -48,9 +48,11 @@ struct SDL_PrivateVideoData {
 
 void *osdl_video_set_mode(struct SDL_PrivateVideoData *pdata,
                          int border_l, int border_r, int border_t, int border_b,
-                         int width, int height, int bpp, int *doublebuf);
+                         int width, int height, int bpp, int *doublebuf,
+                         const char *wm_title);
 void *osdl_video_flip(struct SDL_PrivateVideoData *pdata);
 int   osdl_video_detect_screen(struct SDL_PrivateVideoData *pdata);
+int   osdl_video_pause(struct SDL_PrivateVideoData *pdata, int is_pause);
 void  osdl_video_finish(struct SDL_PrivateVideoData *pdata);
 
 void omapsdl_input_init(void);
index 94994d1..e6fb1f7 100644 (file)
@@ -625,8 +625,8 @@ int omapsdl_input_get_events(int timeout_ms,
                                        break;
                                }
 
-                               if (ev.type != EV_KEY)
-                                       continue; /* not key event */
+                               if (ev.type != EV_KEY || key_cb == NULL)
+                                       continue; /* not key event or not needed */
                                if ((unsigned int)ev.value > 1)
                                        continue; /* not key up/down */
                                if ((unsigned int)ev.code >= ARRAY_SIZE(osdl_evdev_map))
index 9379cab..b6abb93 100644 (file)
 #include "linux/fbdev.h"
 #include "linux/xenv.h"
 
-struct omapfb_saved_layer {
+struct omapfb_state {
        struct omapfb_plane_info pi;
        struct omapfb_mem_info mi;
+       struct omapfb_plane_info pi_old;
+       struct omapfb_mem_info mi_old;
 };
 
 static const char *get_fb_device(void)
@@ -36,8 +38,8 @@ static const char *get_fb_device(void)
        return fbname;
 }
 
-static int osdl_setup_omapfb(int fd, int enabled, int x, int y, int w, int h,
-       int mem, int *buffer_count)
+static int osdl_setup_omapfb(struct omapfb_state *ostate, int fd, int enabled,
+       int x, int y, int w, int h, int mem, int *buffer_count)
 {
        struct omapfb_plane_info pi;
        struct omapfb_mem_info mi;
@@ -95,6 +97,8 @@ static int osdl_setup_omapfb(int fd, int enabled, int x, int y, int w, int h,
                return -1;
        }
 
+       ostate->pi = pi;
+       ostate->mi = mi;
        return 0;
 }
 
@@ -274,18 +278,18 @@ static int osdl_setup_omap_layer(struct SDL_PrivateVideoData *pdata,
 
        /* FIXME: assuming layer doesn't change here */
        if (pdata->saved_layer == NULL) {
-               struct omapfb_saved_layer *slayer;
+               struct omapfb_state *slayer;
                slayer = calloc(1, sizeof(*slayer));
                if (slayer == NULL)
                        goto out;
 
-               ret = ioctl(fd, OMAPFB_QUERY_PLANE, &slayer->pi);
+               ret = ioctl(fd, OMAPFB_QUERY_PLANE, &slayer->pi_old);
                if (ret != 0) {
                        err_perror("QUERY_PLANE");
                        goto out;
                }
 
-               ret = ioctl(fd, OMAPFB_QUERY_MEM, &slayer->mi);
+               ret = ioctl(fd, OMAPFB_QUERY_MEM, &slayer->mi_old);
                if (ret != 0) {
                        err_perror("QUERY_MEM");
                        goto out;
@@ -316,7 +320,7 @@ static int osdl_setup_omap_layer(struct SDL_PrivateVideoData *pdata,
 
        x = screen_w / 2 - w / 2;
        y = screen_h / 2 - h / 2;
-       ret = osdl_setup_omapfb(fd, 1, x, y, w, h,
+       ret = osdl_setup_omapfb(pdata->saved_layer, fd, 1, x, y, w, h,
                                width * height * ((bpp + 7) / 8), buffer_count);
        if (ret == 0) {
                pdata->layer_x = x;
@@ -333,7 +337,8 @@ out:
 
 void *osdl_video_set_mode(struct SDL_PrivateVideoData *pdata,
                          int border_l, int border_r, int border_t, int border_b,
-                         int width, int height, int bpp, int *doublebuf)
+                         int width, int height, int bpp, int *doublebuf,
+                         const char *wm_title)
 {
        int buffers_try, buffers_set;
        const char *fbname;
@@ -373,11 +378,11 @@ void *osdl_video_set_mode(struct SDL_PrivateVideoData *pdata,
                goto fail;
 
        if (!pdata->xenv_up) {
-               int xenv_mouse = 0;
-               ret = xenv_init(&xenv_mouse);
+               int xenv_flags = XENV_CAP_KEYS | XENV_CAP_MOUSE;
+               ret = xenv_init(&xenv_flags, wm_title);
                if (ret == 0) {
                        pdata->xenv_up = 1;
-                       pdata->xenv_mouse = xenv_mouse;
+                       pdata->xenv_mouse = (xenv_flags & XENV_CAP_MOUSE) ? 1 : 0;
                }
        }
 
@@ -409,6 +414,69 @@ void *osdl_video_flip(struct SDL_PrivateVideoData *pdata)
        return ret;
 }
 
+int osdl_video_pause(struct SDL_PrivateVideoData *pdata, int is_pause)
+{
+       struct omapfb_state *state = pdata->saved_layer;
+       struct omapfb_plane_info pi;
+       struct omapfb_mem_info mi;
+       int enabled;
+       int fd = -1;
+       int ret;
+
+       if (pdata->fbdev != NULL)
+               fd = vout_fbdev_get_fd(pdata->fbdev);
+       if (fd == -1) {
+               err("bad fd %d", fd);
+               return -1;
+       }
+       if (state == NULL) {
+               err("missing layer state\n");
+               return -1;
+       }
+
+       if (is_pause) {
+               ret = vout_fbdev_save(pdata->fbdev);
+               if (ret != 0)
+                       return ret;
+               pi = state->pi_old;
+               mi = state->mi_old;
+               enabled = pi.enabled;
+       } else {
+               pi = state->pi;
+               mi = state->mi;
+               enabled = 1;
+       }
+       pi.enabled = 0;
+       ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
+       if (ret != 0) {
+               err_perror("SETUP_PLANE");
+               return -1;
+       }
+
+       ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi);
+       if (ret != 0)
+               err_perror("SETUP_MEM");
+
+       if (!is_pause) {
+               ret = vout_fbdev_restore(pdata->fbdev);
+               if (ret != 0) {
+                       err("fbdev_restore failed\n");
+                       return ret;
+               }
+       }
+
+       if (enabled) {
+               pi.enabled = 1;
+               ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
+               if (ret != 0) {
+                       err_perror("SETUP_PLANE");
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
 void osdl_video_finish(struct SDL_PrivateVideoData *pdata)
 {
        static const char *fbname;
@@ -421,20 +489,20 @@ void osdl_video_finish(struct SDL_PrivateVideoData *pdata)
 
        /* restore the OMAP layer */
        if (pdata->saved_layer != NULL) {
-               struct omapfb_saved_layer *slayer = pdata->saved_layer;
+               struct omapfb_state *slayer = pdata->saved_layer;
                int fd;
 
                fd = open(fbname, O_RDWR);
                if (fd != -1) {
-                       int enabled = slayer->pi.enabled;
+                       int enabled = slayer->pi_old.enabled;
 
                        /* be sure to disable while setting up */
-                       slayer->pi.enabled = 0;
-                       ioctl(fd, OMAPFB_SETUP_PLANE, &slayer->pi);
-                       ioctl(fd, OMAPFB_SETUP_MEM, &slayer->mi);
+                       slayer->pi_old.enabled = 0;
+                       ioctl(fd, OMAPFB_SETUP_PLANE, &slayer->pi_old);
+                       ioctl(fd, OMAPFB_SETUP_MEM, &slayer->mi_old);
                        if (enabled) {
-                               slayer->pi.enabled = enabled;
-                               ioctl(fd, OMAPFB_SETUP_PLANE, &slayer->pi);
+                               slayer->pi_old.enabled = enabled;
+                               ioctl(fd, OMAPFB_SETUP_PLANE, &slayer->pi_old);
                        }
                        close(fd);
                }
index 5818462..b367c3a 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <X11/XF86keysym.h>
 
 #include "../SDL_sysvideo.h"
 #include "../SDL_pixels_c.h"
@@ -135,7 +136,7 @@ static SDL_Surface *omap_SetVideoMode(SDL_VideoDevice *this, SDL_Surface *curren
        doublebuf = (flags & SDL_DOUBLEBUF) ? 1 : 0;
        fbmem = osdl_video_set_mode(pdata,
                pdata->border_l, pdata->border_r, pdata->border_t, pdata->border_b,
-               width, height, bpp, &doublebuf);
+               width, height, bpp, &doublebuf, this->wm_title);
        if (fbmem == NULL) {
                err("failing on mode %dx%d@%d, doublebuf %s, border %d,%d,%d,%d",
                    width, height, bpp, (flags & SDL_DOUBLEBUF) ? "on" : "off",
@@ -276,7 +277,7 @@ static int ts_event_cb(void *cb_arg, int x, int y, unsigned int pressure)
                SDL_PrivateMouseMotion(0, 0, x, y);
 }
 
-static int mouseb_event_cb(void *cb_arg, int x, int y, int button, int is_pressed)
+static int xmouseb_event_cb(void *cb_arg, int x, int y, int button, int is_pressed)
 {
        SDL_VideoDevice *this = cb_arg;
        struct SDL_PrivateVideoData *pdata = this->hidden;
@@ -285,7 +286,7 @@ static int mouseb_event_cb(void *cb_arg, int x, int y, int button, int is_presse
        SDL_PrivateMouseButton(is_pressed ? SDL_PRESSED : SDL_RELEASED, button, x, y);
 }
 
-static int mousem_event_cb(void *cb_arg, int x, int y)
+static int xmousem_event_cb(void *cb_arg, int x, int y)
 {
        SDL_VideoDevice *this = cb_arg;
        struct SDL_PrivateVideoData *pdata = this->hidden;
@@ -294,6 +295,22 @@ static int mousem_event_cb(void *cb_arg, int x, int y)
        SDL_PrivateMouseMotion(0, 0, x, y);
 }
 
+static int xkey_cb(void *cb_arg, int kc, int is_pressed)
+{
+       SDL_VideoDevice *this = cb_arg;
+       struct SDL_PrivateVideoData *pdata = this->hidden;
+       int ret;
+
+       if (kc == XF86XK_MenuKB && is_pressed) {
+               ret = osdl_video_pause(pdata, 1);
+               if (ret == 0) {
+                       xenv_minimize();
+                       osdl_video_pause(pdata, 0);
+                       omapsdl_input_get_events(0, NULL, NULL, NULL);
+               }
+       }
+}
+
 static void omap_PumpEvents(SDL_VideoDevice *this) 
 {
        struct SDL_PrivateVideoData *pdata = this->hidden;
@@ -303,7 +320,7 @@ static void omap_PumpEvents(SDL_VideoDevice *this)
 
        if (pdata->xenv_up) {
                if (!pdata->cfg_ts_force_tslib) {
-                       xenv_update(NULL, mouseb_event_cb, mousem_event_cb, this);
+                       xenv_update(xkey_cb, xmouseb_event_cb, xmousem_event_cb, this);
                        if (pdata->xenv_mouse)
                                read_tslib = 0;
                }