if(!get_event(priv->display, &event.cevent))
return false;
- map<WindowHandle, Window *>::iterator i = priv->windows.find(event.cevent.any.window);
+ auto i = priv->windows.find(event.cevent.any.window);
if(i!=priv->windows.end())
i->second->event(event);
void Display::restore_mode()
{
- for(list<Monitor>::const_iterator i=monitors.begin(); i!=monitors.end(); ++i)
- if(i->desktop_settings.mode)
- set_mode(*i->desktop_settings.mode, false);
+ for(const Monitor &m: monitors)
+ if(m.desktop_settings.mode)
+ set_mode(*m.desktop_settings.mode, false);
}
const VideoMode *Display::find_mode(const VideoMode &mode, float rate_tolerance) const
if(const VideoMode *current_mode = mode.monitor->current_settings.mode)
target_rate = current_mode->rate;
- for(list<VideoMode>::const_iterator i=modes.begin(); i!=modes.end(); ++i)
+ for(const VideoMode &m: modes)
{
- if(mode.monitor && i->monitor!=mode.monitor)
+ if(mode.monitor && m.monitor!=mode.monitor)
continue;
// Only check rate tolerance against an explicitly requested rate
- if(mode.rate && (i->rate<mode.rate-rate_tolerance || i->rate>mode.rate+rate_tolerance))
+ if(mode.rate && (m.rate<mode.rate-rate_tolerance || m.rate>mode.rate+rate_tolerance))
continue;
- if(i->width!=mode.width || i->height!=mode.height)
+ if(m.width!=mode.width || m.height!=mode.height)
continue;
float ref_rate = target_rate;
if(!ref_rate)
- if(const VideoMode *current_mode = i->monitor->current_settings.mode)
+ if(const VideoMode *current_mode = m.monitor->current_settings.mode)
ref_rate = current_mode->rate;
- float d = abs(i->rate-ref_rate);
+ float d = abs(m.rate-ref_rate);
if(!closest || d<rate_diff)
{
- closest = &*i;
+ closest = &m;
rate_diff = d;
}
}
bool ImageLoader::detect_signature(const std::string &sig)
{
Registry ®istry = get_registry();
- for(list<RegisterBase *>::const_iterator i=registry.loaders.begin(); i!=registry.loaders.end(); ++i)
- if((*i)->detect(sig))
+ for(const RegisterBase *r: registry.loaders)
+ if(r->detect(sig))
return true;
return false;
}
unsigned sig_len = io.read(&signature[0], signature.size());
ImageLoader *loader = 0;
- for(list<RegisterBase *>::const_iterator i=registry.loaders.begin(); (!loader && i!=registry.loaders.end()); ++i)
+ for(auto i=registry.loaders.begin(); (!loader && i!=registry.loaders.end()); ++i)
if((*i)->detect(signature))
loader = (*i)->create(io);
ImageLoader::Registry::~Registry()
{
- for(list<RegisterBase *>::iterator i=loaders.begin(); i!=loaders.end(); ++i)
- delete *i;
+ for(auto l: loaders)
+ delete l;
}
} // namespace Graphics
if(ret!=DISP_CHANGE_SUCCESSFUL)
throw unsupported_video_mode(requested_mode);
- for(list<Monitor>::iterator i=monitors.begin(); i!=monitors.end(); ++i)
- if(&*i==mode->monitor)
- i->current_settings.mode = mode;
+ for(Monitor &m: monitors)
+ if(&m==mode->monitor)
+ m.current_settings.mode = mode;
}
bool Display::process_events()
for(int j=0; j<output->nmode; ++j)
{
- map<RRMode, XRRModeInfo *>::iterator k = modes_by_id.find(output->modes[j]);
+ auto k = modes_by_id.find(output->modes[j]);
if(k==modes_by_id.end())
continue;
monitors.sort(monitor_x_compare);
Monitor *prev_enabled = 0;
- for(list<Monitor>::iterator i=monitors.begin(); i!=monitors.end(); ++i)
- if(i->desktop_settings.mode)
+ for(Monitor &m: monitors)
+ if(m.desktop_settings.mode)
{
- i->next_left = prev_enabled;
+ m.next_left = prev_enabled;
if(prev_enabled)
- prev_enabled->next_right = &*i;
- prev_enabled = &*i;
+ prev_enabled->next_right = &m;
+ prev_enabled = &m;
}
if(!primary_monitor || !primary_monitor->desktop_settings.mode)
{
// XRandR didn't give a sensible primary monitor. Try to guess one.
unsigned largest = 0;
- for(list<Monitor>::iterator i=monitors.begin(); i!=monitors.end(); ++i)
- if(const VideoMode *desktop_mode = i->desktop_settings.mode)
+ for(Monitor &m: monitors)
+ if(const VideoMode *desktop_mode = m.desktop_settings.mode)
{
unsigned size = desktop_mode->width*desktop_mode->height;
if(size>largest)
{
largest = size;
- primary_monitor = &*i;
+ primary_monitor = &m;
}
}
}
monitor->current_settings.y = 0;
// Disable other outputs for exclusive mode
- for(list<Monitor>::iterator i=monitors.begin(); i!=monitors.end(); ++i)
- if(&*i!=mode->monitor)
+ for(Monitor &m: monitors)
+ if(&m!=mode->monitor)
{
- XRROutputInfo *o = XRRGetOutputInfo(priv->display, res, priv->monitors[i->index]);
+ XRROutputInfo *o = XRRGetOutputInfo(priv->display, res, priv->monitors[m.index]);
if(o->crtc)
XRRSetCrtcConfig(priv->display, res, o->crtc, CurrentTime, 0, 0, 0, RR_Rotate_0, 0, 0);
XRRFreeOutputInfo(o);
- i->current_settings.mode = 0;
- i->current_settings.rotation = ROTATE_NORMAL;
- i->current_settings.x = 0;
- i->current_settings.y = 0;
+ m.current_settings.mode = 0;
+ m.current_settings.rotation = ROTATE_NORMAL;
+ m.current_settings.x = 0;
+ m.current_settings.y = 0;
}
}
else
check_error();
- map<WindowHandle, Window *>::iterator j = priv->windows.find(event.xevent.xany.window);
+ auto j = priv->windows.find(event.xevent.xany.window);
if(j!=priv->windows.end())
{
/* Filter keyboard autorepeat. If this packet is a KeyRelease and
+#include <algorithm>
#include <msp/strings/format.h>
#include "bindings.h"
#include "controlscheme.h"
{
vector<Device *> resolved_devs;
resolved_devs.reserve(devices.size());
- for(vector<DeviceRef>::const_iterator i=devices.begin(); i!=devices.end(); ++i)
+ for(const DeviceRef &d: devices)
{
- if(i->type!=UNSPECIFIED)
- resolved_devs.push_back(dev.find_subdevice(i->type));
- else if(!i->name.empty())
- resolved_devs.push_back(dev.find_subdevice(i->name));
+ if(d.type!=UNSPECIFIED)
+ resolved_devs.push_back(dev.find_subdevice(d.type));
+ else if(!d.name.empty())
+ resolved_devs.push_back(dev.find_subdevice(d.name));
else
resolved_devs.push_back(0);
}
bool Bindings::is_compatible(Device &dev) const
{
vector<Device *> resolved_devs = resolve_devices(dev);
- for(vector<Device *>::const_iterator i=resolved_devs.begin(); i!=resolved_devs.end(); ++i)
- if(!*i)
- return false;
- return true;
+ return all_of(resolved_devs.begin(), resolved_devs.end(), [](Device *d) -> bool { return d; });
}
bool Bindings::apply_to(ControlScheme &control_scheme, Device &dev)
{
vector<Device *> resolved_devs = resolve_devices(dev);
bool applied = false;
- for(vector<Binding>::const_iterator i=bindings.begin(); i!=bindings.end(); ++i)
+ for(const Binding &b: bindings)
{
- Control *ctrl = control_scheme.find(i->control);
- Device *bdev = (i->device<resolved_devs.size() ? resolved_devs[i->device] : 0);
+ Control *ctrl = control_scheme.find(b.control);
+ Device *bdev = (b.device<resolved_devs.size() ? resolved_devs[b.device] : 0);
if(ctrl && bdev)
{
- ctrl->set_source(*bdev, i->type, i->index);
+ ctrl->set_source(*bdev, b.type, b.index);
applied = true;
}
}
Control *ControlScheme::find(const string &name) const
{
- map<string, Control *>::const_iterator i = controls.find(name);
+ auto i = controls.find(name);
return (i!=controls.end() ? i->second : 0);
}
void ControlScheme::reset_edges()
{
- for(map<string, Control *>::const_iterator i=controls.begin(); i!=controls.end(); ++i)
- i->second->reset_edges();
+ for(const auto &kvp: controls)
+ kvp.second->reset_edges();
}
} // namespace Input
Device *Hub::find_subdevice(DeviceType t, unsigned n)
{
- for(vector<Device *>::const_iterator i=devices.begin(); i!=devices.end(); ++i)
- if(Device *dev = (*i)->find_subdevice(t, 0))
+ for(Device *d: devices)
+ if(Device *dev = d->find_subdevice(t, 0))
{
if(!n)
return dev;
{
if(n==name)
return this;
- for(vector<Device *>::const_iterator i=devices.begin(); i!=devices.end(); ++i)
- if(Device *dev = (*i)->find_subdevice(n))
+ for(Device *d: devices)
+ if(Device *dev = d->find_subdevice(n))
return dev;
return 0;
}
init_done = true;
}
- map<unsigned, unsigned>::const_iterator i = reverse_map.find(code);
+ auto i = reverse_map.find(code);
if(i!=reverse_map.end())
return i->second;
FS::Path dev_input = "/dev/input";
vector<string> devices = FS::list_filtered(dev_input, "^js[0-9]+");
sort(devices);
- for(vector<string>::const_iterator i=devices.begin(); i!=devices.end(); ++i)
+ for(const string &f: devices)
// TODO check permissions
- Private::detected_controllers.push_back((dev_input / *i).str());
+ Private::detected_controllers.push_back((dev_input/f).str());
detect_done = true;
n_detected_controllers = Private::detected_controllers.size();