2 #include <sigc++/bind.h>
4 #include "display_private.h"
12 void Display::add_window(Window &wnd)
14 priv->windows[wnd.get_private().window] = &wnd;
15 wnd.signal_got_focus.connect(sigc::bind(sigc::mem_fun(this, &Display::window_got_focus), sigc::ref(wnd)));
16 wnd.signal_lost_focus.connect(sigc::mem_fun(this, &Display::window_lost_focus));
19 void Display::remove_window(Window &wnd)
21 priv->windows.erase(wnd.get_private().window);
22 if(&wnd==focus_window)
26 const VideoMode &Display::get_desktop_mode() const
28 if(!primary_monitor || !primary_monitor->desktop_settings.mode)
29 throw logic_error("no desktop mode");
30 return *primary_monitor->desktop_settings.mode;
33 void Display::restore_mode()
35 for(list<Monitor>::const_iterator i=monitors.begin(); i!=monitors.end(); ++i)
36 if(i->desktop_settings.mode)
37 set_mode(*i->desktop_settings.mode, false);
40 const VideoMode *Display::find_mode(const VideoMode &mode, float rate_tolerance) const
42 const VideoMode *closest = 0;
43 float rate_diff = mode.rate;
44 for(list<VideoMode>::const_iterator i=modes.begin(); i!=modes.end(); ++i)
46 if(mode.monitor && i->monitor!=mode.monitor)
48 if(mode.rate && (i->rate<mode.rate-rate_tolerance || i->rate>mode.rate+rate_tolerance))
50 if(i->width!=mode.width || i->height!=mode.height)
55 float d = abs(i->rate-mode.rate);
69 const VideoMode *Display::find_mode(unsigned width, unsigned height) const
71 return find_mode(VideoMode(width, height));
74 void Display::window_got_focus(Window &w)
79 void Display::window_lost_focus()
88 Window *old_focus = focus_window;
90 while(process_events()) ;
92 if(old_focus && !focus_window)
93 signal_lost_focus.emit();
94 else if(!old_focus && focus_window)
95 signal_got_focus.emit();
98 } // namespace Graphics