]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/linux/gamecontroller.cpp
Streamline iterators and loop constructs
[libs/gui.git] / source / input / linux / gamecontroller.cpp
index 3a2baa8a2a0cbe7f742d30da20eae2cc7fbd5444..58e4ef17325d2aa8d3b0a22447ccae4b30ac86da 100644 (file)
@@ -16,6 +16,7 @@ namespace Input {
 vector<string> GameController::Private::detected_controllers;
 
 GameController::GameController(unsigned index):
+       Device(GAME_CONTROLLER),
        event_disp(0)
 {
        if(!detect_done)
@@ -45,9 +46,9 @@ unsigned GameController::detect()
        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();
@@ -79,11 +80,11 @@ void GameController::tick()
                unsigned count = len/sizeof(js_event);
                for(unsigned i=0; i<count; ++i)
                {
-                       unsigned type = events[i].type&0x7F;
+                       unsigned etype = events[i].type&0x7F;
                        bool init = events[i].type&JS_EVENT_INIT;
-                       if(type==JS_EVENT_AXIS)
+                       if(etype==JS_EVENT_AXIS)
                                set_axis_value(events[i].number, events[i].value/32768.0f, !init);
-                       else if(type==JS_EVENT_BUTTON)
+                       else if(etype==JS_EVENT_BUTTON)
                                set_button_state(events[i].number, events[i].value, !init);
                }
 
@@ -123,12 +124,12 @@ string JsDevice::get_name() const
        return buf;
 }
 
-unsigned JsDevice::do_read(char *buf, unsigned size)
+size_t JsDevice::do_read(char *buf, size_t size)
 {
        return IO::sys_read(handle, buf, size);
 }
 
-unsigned JsDevice::do_write(const char *, unsigned)
+size_t JsDevice::do_write(const char *, size_t)
 {
        throw IO::invalid_access(IO::M_WRITE);
 }