*/
#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>
bool error_flag=false;
std::string error_msg;
+#ifndef WIN32
int x_error_handler(Display *display, XErrorEvent *event)
{
char err[128];
return 0;
}
+#endif
}
Display::Display(const string &disp_name)
{
+#ifndef WIN32
if(disp_name.empty())
display=XOpenDisplay(0);
else
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)
void Display::set_mode(const VideoMode &mode)
{
+#ifndef WIN32
int screen=DefaultScreen(display);
int nmodes;
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()
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;
if(j!=windows.end())
j->second->event(event);
}
+#endif
}
}