3 #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)
23 focus_window = nullptr;
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(const Monitor &m: monitors)
36 if(m.desktop_settings.mode)
37 set_mode(*m.desktop_settings.mode, false);
40 const VideoMode *Display::find_mode(const VideoMode &mode, float rate_tolerance) const
42 const VideoMode *closest = nullptr;
43 float rate_diff = 0.0f;
45 float target_rate = mode.rate;
46 if(!target_rate && mode.monitor)
47 if(const VideoMode *current_mode = mode.monitor->current_settings.mode)
48 target_rate = current_mode->rate;
50 for(const VideoMode &m: modes)
52 if(mode.monitor && m.monitor!=mode.monitor)
54 // Only check rate tolerance against an explicitly requested rate
55 if(mode.rate && (m.rate<mode.rate-rate_tolerance || m.rate>mode.rate+rate_tolerance))
57 if(m.width!=mode.width || m.height!=mode.height)
60 float ref_rate = target_rate;
62 if(const VideoMode *current_mode = m.monitor->current_settings.mode)
63 ref_rate = current_mode->rate;
65 float d = abs(m.rate-ref_rate);
66 if(!closest || d<rate_diff)
76 const VideoMode *Display::find_mode(unsigned width, unsigned height) const
78 return find_mode(VideoMode(width, height));
81 void Display::window_got_focus(Window &w)
86 void Display::window_lost_focus()
88 focus_window = nullptr;
95 Window *old_focus = focus_window;
97 while(process_events()) ;
99 if(old_focus && !focus_window)
100 signal_lost_focus.emit();
101 else if(!old_focus && focus_window)
102 signal_got_focus.emit();
105 } // namespace Graphics