2 #include "display_private.h"
10 Display::Display(const string &):
15 static ErrorDialog err_dlg(0);
17 for(unsigned i=0;; ++i)
19 DISPLAY_DEVICE adapter_dev;
20 adapter_dev.cb = sizeof(adapter_dev);
21 if(!EnumDisplayDevices(0, i, &adapter_dev, 0))
24 if(adapter_dev.StateFlags&DISPLAY_DEVICE_MIRRORING_DRIVER)
27 monitors.push_back(Monitor());
28 Monitor &monitor = monitors.back();
29 monitor.index = monitors.size()-1;
30 monitor.name = adapter_dev.DeviceString;
31 priv->monitors.push_back(adapter_dev.DeviceName);
33 if(adapter_dev.StateFlags&DISPLAY_DEVICE_PRIMARY_DEVICE)
34 primary_monitor = &monitor;
37 bool have_current = EnumDisplaySettings(adapter_dev.DeviceName, ENUM_CURRENT_SETTINGS, ¤t);
39 for(unsigned j=0;; ++j)
42 if(!EnumDisplaySettings(adapter_dev.DeviceName, j, &info))
45 VideoMode mode(info.dmPelsWidth, info.dmPelsHeight);
46 mode.index = modes.size();
47 mode.monitor = &monitor;
48 mode.rate = info.dmDisplayFrequency;
52 modes.push_back(mode);
53 monitor.video_modes.push_back(&modes.back());
55 if(have_current && info.dmPelsWidth==current.dmPelsWidth && info.dmPelsHeight==current.dmPelsHeight && info.dmDisplayFrequency==current.dmDisplayFrequency)
56 monitor.desktop_settings.mode = &modes.back();
59 monitor.current_settings = monitor.desktop_settings;
68 void Display::set_mode(const VideoMode &requested_mode, bool)
70 const VideoMode *mode = find_mode(requested_mode);
72 throw unsupported_video_mode(requested_mode);
75 info.dmDeviceName[0] = 0;
76 info.dmSpecVersion = DM_SPECVERSION;
77 info.dmDriverVersion = 0;
78 info.dmSize = sizeof(DEVMODE);
79 info.dmDriverExtra = 0;
80 info.dmFields = DM_PELSWIDTH|DM_PELSHEIGHT;
81 info.dmPelsWidth = mode->width;
82 info.dmPelsHeight = mode->height;
83 if(requested_mode.rate)
85 info.dmFields |= DM_DISPLAYFREQUENCY;
86 info.dmDisplayFrequency = mode->rate;
89 LONG ret = ChangeDisplaySettingsEx(priv->monitors[mode->monitor->index].c_str(), &info, NULL, CDS_FULLSCREEN, NULL);
90 if(ret!=DISP_CHANGE_SUCCESSFUL)
91 throw unsupported_video_mode(requested_mode);
93 for(Monitor &m: monitors)
95 m.current_settings.mode = mode;
98 bool Display::process_events()
101 if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
103 TranslateMessage(&msg);
104 DispatchMessage(&msg);
111 void Display::check_error()
116 } // namespace Graphics