3 #include "display_private.h"
10 Display::Display(const string &):
14 static ErrorDialog err_dlg(0);
16 for(unsigned i=0;; ++i)
18 DISPLAY_DEVICE adapter_dev;
19 adapter_dev.cb = sizeof(adapter_dev);
20 if(!EnumDisplayDevices(0, i, &adapter_dev, 0))
23 if(adapter_dev.StateFlags&DISPLAY_DEVICE_MIRRORING_DRIVER)
26 monitors.push_back(Monitor());
27 Monitor &monitor = monitors.back();
28 monitor.index = monitors.size()-1;
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_mode = &modes.back();
63 void Display::set_mode(const VideoMode &requested_mode, bool)
65 const VideoMode *mode = find_mode(requested_mode);
67 throw unsupported_video_mode(requested_mode);
70 info.dmDeviceName[0] = 0;
71 info.dmSpecVersion = DM_SPECVERSION;
72 info.dmDriverVersion = 0;
73 info.dmSize = sizeof(DEVMODE);
74 info.dmDriverExtra = 0;
75 info.dmFields = DM_PELSWIDTH|DM_PELSHEIGHT;
76 info.dmPelsWidth = mode->width;
77 info.dmPelsHeight = mode->height;
78 if(requested_mode.rate)
80 info.dmFields |= DM_DISPLAYFREQUENCY;
81 info.dmDisplayFrequency = mode->rate;
84 LONG ret = ChangeDisplaySettingsEx(priv->monitors[mode->monitor->index].c_str(), &info, NULL, CDS_FULLSCREEN, NULL);
85 if(ret!=DISP_CHANGE_SUCCESSFUL)
86 throw unsupported_video_mode(requested_mode);
88 for(list<Monitor>::iterator i=monitors.begin(); i!=monitors.end(); ++i)
89 if(&*i==mode->monitor)
90 i->current_mode = mode;
93 bool Display::process_events()
96 if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
98 TranslateMessage(&msg);
99 DispatchMessage(&msg);
106 void Display::check_error()
111 } // namespace Graphics