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()
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;
}
}
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
private:
::Display *display;
std::list<VideoMode> modes;
+ VideoMode orig_mode;
std::map<WindowHandle, Window *> windows;
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();
XDestroyWindow(display.get_display(), window);
display.remove_window(this);
+
+ if(options.fullscreen)
+ display.restore_mode();
}
void Window::set_title(const string &title)
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();
}
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:;
}
}