2 #include "display_private.h"
10 Display::Display(const string &):
13 static ErrorDialog err_dlg(0);
15 for(unsigned i=0;; ++i)
17 DISPLAY_DEVICE adapter_dev;
18 adapter_dev.cb = sizeof(adapter_dev);
19 if(!EnumDisplayDevices(0, i, &adapter_dev, 0))
22 if(adapter_dev.StateFlags&DISPLAY_DEVICE_MIRRORING_DRIVER)
25 monitors.push_back(Monitor());
26 Monitor &monitor = monitors.back();
27 monitor.index = monitors.size()-1;
28 monitor.name = adapter_dev.DeviceString;
29 priv->monitors.push_back(adapter_dev.DeviceName);
31 if(adapter_dev.StateFlags&DISPLAY_DEVICE_PRIMARY_DEVICE)
32 primary_monitor = &monitor;
35 bool have_current = EnumDisplaySettings(adapter_dev.DeviceName, ENUM_CURRENT_SETTINGS, ¤t);
37 for(unsigned j=0;; ++j)
40 if(!EnumDisplaySettings(adapter_dev.DeviceName, j, &info))
43 VideoMode mode(info.dmPelsWidth, info.dmPelsHeight);
44 mode.index = modes.size();
45 mode.monitor = &monitor;
46 mode.rate = info.dmDisplayFrequency;
50 modes.push_back(mode);
51 monitor.video_modes.push_back(&modes.back());
53 if(have_current && info.dmPelsWidth==current.dmPelsWidth && info.dmPelsHeight==current.dmPelsHeight && info.dmDisplayFrequency==current.dmDisplayFrequency)
54 monitor.desktop_settings.mode = &modes.back();
57 monitor.current_settings = monitor.desktop_settings;
66 void Display::set_mode(const VideoMode &requested_mode, bool)
68 const VideoMode *mode = find_mode(requested_mode);
70 throw unsupported_video_mode(requested_mode);
73 info.dmDeviceName[0] = 0;
74 info.dmSpecVersion = DM_SPECVERSION;
75 info.dmDriverVersion = 0;
76 info.dmSize = sizeof(DEVMODE);
77 info.dmDriverExtra = 0;
78 info.dmFields = DM_PELSWIDTH|DM_PELSHEIGHT;
79 info.dmPelsWidth = mode->width;
80 info.dmPelsHeight = mode->height;
81 if(requested_mode.rate)
83 info.dmFields |= DM_DISPLAYFREQUENCY;
84 info.dmDisplayFrequency = mode->rate;
87 LONG ret = ChangeDisplaySettingsEx(priv->monitors[mode->monitor->index].c_str(), &info, NULL, CDS_FULLSCREEN, NULL);
88 if(ret!=DISP_CHANGE_SUCCESSFUL)
89 throw unsupported_video_mode(requested_mode);
91 for(Monitor &m: monitors)
93 m.current_settings.mode = mode;
96 bool Display::process_events()
99 if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
101 TranslateMessage(&msg);
102 DispatchMessage(&msg);
109 void Display::check_error()
114 } // namespace Graphics