]> git.tdb.fi Git - libs/gui.git/blobdiff - source/display.cpp
Bugfixes
[libs/gui.git] / source / display.cpp
index 724318a06af3d797efaee820c56e1e62c06cc066..3baf7c11a72e92eb1a1827666f247198d85e21aa 100644 (file)
@@ -6,8 +6,10 @@ Distributed under the LGPL
 */
 
 #include <iostream>
+#ifndef WIN32
 #include <X11/Xlib.h>
 #include <X11/extensions/xf86vmode.h>
+#endif
 #include <msp/core/except.h>
 #include <msp/strings/formatter.h>
 #include <msp/strings/lexicalcast.h>
@@ -21,6 +23,7 @@ namespace {
 bool error_flag=false;
 std::string error_msg;
 
+#ifndef WIN32
 int x_error_handler(Display *display, XErrorEvent *event)
 {
        char err[128];
@@ -42,6 +45,7 @@ int x_error_handler(Display *display, XErrorEvent *event)
 
        return 0;
 }
+#endif
 
 }
 
@@ -50,6 +54,7 @@ namespace Graphics {
 
 Display::Display(const string &disp_name)
 {
+#ifndef WIN32
        if(disp_name.empty())
                display=XOpenDisplay(0);
        else
@@ -59,25 +64,38 @@ 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);
        }
+
+       XFree(infos);
+
+       XF86VidModeModeLine modeline;
+       int dotclock;
+       XF86VidModeGetModeLine(display, screen, &dotclock, &modeline);
+       orig_mode=VideoMode(modeline.hdisplay, modeline.vdisplay);
+       orig_mode.rate=dotclock/(modeline.htotal*modeline.vtotal);
+#else
+       (void)disp_name;
+#endif
 }
 
 Display::~Display()
 {
+#ifndef WIN32
        XCloseDisplay(display);
        display=0;
+#endif
 }
 
 void Display::add_window(Window *wnd)
@@ -92,6 +110,7 @@ void Display::remove_window(Window *wnd)
 
 void Display::set_mode(const VideoMode &mode)
 {
+#ifndef WIN32
        int screen=DefaultScreen(display);
 
        int nmodes;
@@ -102,14 +121,18 @@ 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;
                }
        }
 
        throw InvalidParameterValue("Requested mode not supported");
+#else
+       (void)mode;
+#endif
 }
 
 void Display::tick()
@@ -118,6 +141,13 @@ void Display::tick()
 
        while(1)
        {
+#ifdef WIN32
+               MSG msg;
+               if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
+                       DispatchMessage(&msg);
+               else
+                       break;
+#else
                int pending=XPending(display);
                if(pending==0)
                        break;
@@ -133,6 +163,7 @@ void Display::tick()
                        if(j!=windows.end())
                                j->second->event(event);
                }
+#endif
        }
 }