3 #include "display_private.h"
10 Display::Display(const string &):
14 for(unsigned i=0;; ++i)
16 DISPLAY_DEVICE adapter_dev;
17 adapter_dev.cb = sizeof(adapter_dev);
18 if(!EnumDisplayDevices(0, i, &adapter_dev, 0))
21 if(adapter_dev.StateFlags&DISPLAY_DEVICE_MIRRORING_DRIVER)
24 monitors.push_back(Monitor());
25 Monitor &monitor = monitors.back();
26 monitor.index = monitors.size()-1;
27 priv->monitors.push_back(adapter_dev.DeviceName);
29 if(adapter_dev.StateFlags&DISPLAY_DEVICE_PRIMARY_DEVICE)
30 primary_monitor = &monitor;
33 bool have_current = EnumDisplaySettings(adapter_dev.DeviceName, ENUM_CURRENT_SETTINGS, ¤t);
35 for(unsigned j=0;; ++j)
38 if(!EnumDisplaySettings(adapter_dev.DeviceName, j, &info))
41 VideoMode mode(info.dmPelsWidth, info.dmPelsHeight);
42 mode.index = modes.size();
43 mode.monitor = &monitor;
44 mode.rate = info.dmDisplayFrequency;
45 if(find_matching_mode(mode))
48 modes.push_back(mode);
49 monitor.video_modes.push_back(&modes.back());
51 if(have_current && info.dmPelsWidth==current.dmPelsWidth && info.dmPelsHeight==current.dmPelsHeight && info.dmDisplayFrequency==current.dmDisplayFrequency)
52 monitor.desktop_mode = &modes.back();
61 void Display::set_mode(const VideoMode &requested_mode, bool)
63 const VideoMode *mode = find_matching_mode(requested_mode);
65 throw unsupported_video_mode(requested_mode);
68 info.dmSize = sizeof(DEVMODE);
69 info.dmFields = DM_PELSWIDTH|DM_PELSHEIGHT;
70 info.dmPelsWidth = mode->width;
71 info.dmPelsHeight = mode->height;
72 if(requested_mode.rate)
74 info.dmFields |= DM_DISPLAYFREQUENCY;
75 info.dmDisplayFrequency = mode->rate;
78 LONG ret = ChangeDisplaySettingsEx(priv->monitors[mode->monitor->index].c_str(), &info, NULL, CDS_FULLSCREEN, NULL);
79 if(ret!=DISP_CHANGE_SUCCESSFUL)
80 throw unsupported_video_mode(requested_mode);
83 bool Display::process_events()
86 if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
88 DispatchMessage(&msg);
95 void Display::check_error()
100 } // namespace Graphics