]> git.tdb.fi Git - libs/gui.git/commitdiff
Implement the rest of fullscreen mode (video mode switching, pointer grab)
authorMikko Rasa <tdb@tdb.fi>
Mon, 24 Dec 2007 23:06:24 +0000 (23:06 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 24 Dec 2007 23:06:24 +0000 (23:06 +0000)
source/display.cpp
source/display.h
source/window.cpp

index 724318a06af3d797efaee820c56e1e62c06cc066..b8e4fbe6119e1ea93645d4fbad9476b080c88040 100644 (file)
@@ -59,19 +59,25 @@ Display::Display(const string &disp_name)
 
        XSetErrorHandler(x_error_handler);
 
+       int screen=DefaultScreen(display);
+
        int nmodes;
        XF86VidModeModeInfo **infos;
-       XF86VidModeGetAllModeLines(display, DefaultScreen(display), &nmodes, &infos);
+       XF86VidModeGetAllModeLines(display, screen, &nmodes, &infos);
        for(int i=0; i<nmodes; ++i)
        {
                XF86VidModeModeInfo &info=*infos[i];
        
-               VideoMode mode;
-               mode.width=info.hdisplay;
-               mode.height=info.vdisplay;
+               VideoMode mode(info.hdisplay, info.vdisplay);
                mode.rate=info.dotclock/(info.htotal*info.vtotal);
                modes.push_back(mode);
        }
+
+       XF86VidModeModeLine modeline;
+       int dotclock;
+       XF86VidModeGetModeLine(display, screen, &dotclock, &modeline);
+       orig_mode=VideoMode(modeline.hdisplay, modeline.vdisplay);
+       orig_mode.rate=dotclock/(modeline.htotal*modeline.vtotal);
 }
 
 Display::~Display()
@@ -102,9 +108,10 @@ void Display::set_mode(const VideoMode &mode)
                XF86VidModeModeInfo &info=*infos[i];
 
                unsigned rate=info.dotclock/(info.htotal*info.vtotal);
-               if(info.hdisplay==mode.width && info.vdisplay==mode.height && rate==mode.rate)
+               if(info.hdisplay==mode.width && info.vdisplay==mode.height && (mode.rate==0 || rate==mode.rate))
                {
                        XF86VidModeSwitchToMode(display, screen, &info);
+                       XF86VidModeSetViewPort(display, screen, 0, 0);
                        return;
                }
        }
index 0433eab22404163996491fa5ca772732f750b09a..7397a785c309513e6459833cd4779162ea494a65 100644 (file)
@@ -23,6 +23,9 @@ struct VideoMode
        unsigned width;
        unsigned height;
        unsigned rate;
+
+       VideoMode(): width(0), height(0), rate(0) { }
+       VideoMode(unsigned w, unsigned h): width(w), height(h), rate(0) { }
 };
 
 class Display
@@ -30,6 +33,7 @@ class Display
 private:
        ::Display *display;
        std::list<VideoMode> modes;
+       VideoMode orig_mode;
        std::map<WindowHandle, Window *> windows;
 
 public:
@@ -43,6 +47,7 @@ public:
 
        const std::list<VideoMode> &get_modes() const { return modes; }
        void set_mode(const VideoMode &);
+       void restore_mode() { set_mode(orig_mode); }
 
        void tick();
        void check_error();
index f867faf6e58e3a775c08248f943eb17c1159b71e..224195605225f16a33427cec2762e3f77f690cb1 100644 (file)
@@ -48,6 +48,9 @@ Window::~Window()
                XDestroyWindow(display.get_display(), window);
 
        display.remove_window(this);
+
+       if(options.fullscreen)
+               display.restore_mode();
 }
 
 void Window::set_title(const string &title)
@@ -88,6 +91,12 @@ void Window::init()
 
        XSetWMProtocols(dpy, window, &wm_delete_window, 1);
 
+       if(options.fullscreen)
+       {
+               display.set_mode(VideoMode(options.width, options.height));
+               XWarpPointer(dpy, None, window, 0, 0, 0, 0, options.width/2, options.height/2);
+       }
+
        display.add_window(this);
        display.check_error();
 }
@@ -128,6 +137,10 @@ void Window::event(const XEvent &ev)
        case EnterNotify:
                XSetInputFocus(display.get_display(), window, RevertToParent, CurrentTime);
                break;
+       case MapNotify:
+               if(options.fullscreen)
+                       XGrabPointer(display.get_display(), window, true, None, GrabModeAsync, GrabModeAsync, window, None, CurrentTime);
+               break;
        default:;
        }
 }