pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r3071 - trunk/pingus/src/input


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3071 - trunk/pingus/src/input
Date: Mon, 3 Sep 2007 21:58:28 +0200

Author: grumbel
Date: 2007-09-03 21:58:27 +0200 (Mon, 03 Sep 2007)
New Revision: 3071

Modified:
   trunk/pingus/src/input/manager.cpp
   trunk/pingus/src/input/xinput_device.cpp
   trunk/pingus/src/input/xinput_driver.cpp
Log:
- some more work on XInputDriver

Modified: trunk/pingus/src/input/manager.cpp
===================================================================
--- trunk/pingus/src/input/manager.cpp  2007-09-03 17:17:58 UTC (rev 3070)
+++ trunk/pingus/src/input/manager.cpp  2007-09-03 19:58:27 UTC (rev 3071)
@@ -24,10 +24,13 @@
 #include "path_manager.hpp"
 #include "sdl_driver.hpp"
 #include "core_driver.hpp"
-#include "usbmouse_driver.hpp"
 #ifdef HAVE_CWIID
+#  include "usbmouse_driver.hpp"
 #  include "wiimote_driver.hpp"
 #endif 
+#ifndef WIN32
+#  include "xinput_driver.hpp"
+#endif
 #include "manager.hpp"
 
 namespace Input {
@@ -204,6 +207,8 @@
 #ifndef WIN32
       } else if (name == "usbmouse") {
         driver = new USBMouseDriver();
+      } else if (name == "xinput") {
+        driver = new XInputDriver();
 #endif
 #ifdef HAVE_CWIID
       } else if (name == "wiimote") {

Modified: trunk/pingus/src/input/xinput_device.cpp
===================================================================
--- trunk/pingus/src/input/xinput_device.cpp    2007-09-03 17:17:58 UTC (rev 
3070)
+++ trunk/pingus/src/input/xinput_device.cpp    2007-09-03 19:58:27 UTC (rev 
3071)
@@ -25,6 +25,9 @@
 
 #include "SDL_syswm.h"
 
+#include "debug.hpp"
+#include "globals.hpp"
+
 #include "xinput_driver.hpp"
 #include "xinput_device.hpp"
 
@@ -195,44 +198,64 @@
 
   device = XOpenDevice(dpy, info->id);
 
-  if (!device) {
-    fprintf(stderr, "unable to open device %s\n", dev_name);
-    return 0;
-  }
+  if (!device) 
+    {
+      fprintf(stderr, "unable to open device %s\n", dev_name);
+      return 0;
+    }
 
-  if (device->num_classes > 0) {
-    for (ip = device->classes, i=0; i<info->num_classes; ip++, i++) {
-      switch (ip->input_class) {
-        case KeyClass:
-          DeviceKeyPress  (device, key_press_type,   event_list[number]); 
number++;
-          DeviceKeyRelease(device, key_release_type, event_list[number]); 
number++;
-          break;
+  if (device->num_classes > 0) 
+    {
+      for (ip = device->classes, i=0; i<info->num_classes; ip++, i++) 
+        {
+          switch (ip->input_class) 
+            {
+              case KeyClass:
+                DeviceKeyPress  (device, key_press_type,   
event_list[number]); number++;
+                DeviceKeyRelease(device, key_release_type, 
event_list[number]); number++;
+                break;
 
-        case ButtonClass:
-          DeviceButtonPress  (device, button_press_type,   
event_list[number]); number++;
-          DeviceButtonRelease(device, button_release_type, 
event_list[number]); number++;
-          break;
+              case ButtonClass:
+                DeviceButtonPress  (device, button_press_type,   
event_list[number]); number++;
+                DeviceButtonRelease(device, button_release_type, 
event_list[number]); number++;
+                break;
 
-        case ValuatorClass:
-          DeviceMotionNotify(device, motion_type, event_list[number]); 
number++;
-          if (handle_proximity) {
-            ProximityIn (device, proximity_in_type,  event_list[number]); 
number++;
-            ProximityOut(device, proximity_out_type, event_list[number]); 
number++;
-          }
-          break;
+              case ValuatorClass:
+                DeviceMotionNotify(device, motion_type, event_list[number]); 
number++;
+                if (handle_proximity) {
+                  ProximityIn (device, proximity_in_type,  
event_list[number]); number++;
+                  ProximityOut(device, proximity_out_type, 
event_list[number]); number++;
+                }
+                break;
 
-        default:
-          fprintf(stderr, "unknown class\n");
-          break;
+              case FeedbackClass:
+                std::cout << "Error: XInputDevice: register_events: unhandled 
class: FeedbackClass" << std::endl;
+                break;
+
+              case ProximityClass:
+                std::cout << "Error: XInputDevice: register_events: unhandled 
class: ProximityClass" << std::endl;
+                break;
+
+              case FocusClass:
+                std::cout << "Error: XInputDevice: register_events: unhandled 
class: FocusClass" << std::endl;
+                break;
+
+              case OtherClass:
+                std::cout << "Error: XInputDevice: register_events: unhandled 
class: OtherClass" << std::endl;
+                break;
+
+              default:
+                std::cout << "Error: XInputDevice: register_events: unknown 
class: " << ip->input_class << std::endl;
+                break;
+            }
+        }
+
+      if (XSelectExtensionEvent(dpy, root_win, event_list, number)) {
+        fprintf(stderr, "error selecting extended events\n");
+        return 0;
       }
     }
 
-    if (XSelectExtensionEvent(dpy, root_win, event_list, number)) {
-      fprintf(stderr, "error selecting extended events\n");
-      return 0;
-    }
-  }
-
   //std::cout << "### Registered events: " << number << std::endl;
   return number;
 }
@@ -240,67 +263,85 @@
 void
 XInputDevice::get_info(XDeviceInfo* info)
 {
-  int   i,j;
-  XAnyClassPtr any;
-  XKeyInfoPtr  k;
-  XButtonInfoPtr b;
-  XValuatorInfoPtr v;
-  XAxisInfoPtr a;
-
   printf("\"%s\"\tid=%ld\t[%s]\n", info->name, info->id,
-     (info->use == IsXExtensionDevice) ? "XExtensionDevice" :
-      ((info->use == IsXPointer) ? "XPointer" : "XKeyboard"));
+         (info->use == IsXExtensionDevice) ? "XExtensionDevice" :
+         ((info->use == IsXPointer) ? "XPointer" : "XKeyboard"));
 
-  if (info->num_classes > 0) {
-    any = (XAnyClassPtr) (info->inputclassinfo);
-    for (i=0; i<info->num_classes; i++) {
-      switch (any->c_class) {
-        case KeyClass:
-          k = (XKeyInfoPtr) any;
+  XAnyClassPtr any = (XAnyClassPtr)(info->inputclassinfo);
+  std::cout << "Info->num_classes: " << info->num_classes << std::endl;
+  for (int i = 0; i < info->num_classes; ++i) 
+    {
+      switch (any->c_class) 
+        {
+          case KeyClass:
+            {
+              XKeyInfoPtr k = (XKeyInfoPtr)any;
   
-          printf("\tNum_keys is %d\n", k->num_keys);
-          printf("\tMin_keycode is %d\n", k->min_keycode);
-          printf("\tMax_keycode is %d\n", k->max_keycode);
+              printf("\tNum_keys is %d\n", k->num_keys);
+              printf("\tMin_keycode is %d\n", k->min_keycode);
+              printf("\tMax_keycode is %d\n", k->max_keycode);
 
-          num_keys = k->num_keys;
-          break;
+              num_keys = k->num_keys;
+            }
+            break;
 
-        case ButtonClass:
-          b = (XButtonInfoPtr)any;
-          printf("\tNum_buttons is %d\n", b->num_buttons);
+          case ButtonClass:
+            {
+              XButtonInfoPtr b = (XButtonInfoPtr)any;
+              printf("\tNum_buttons is %d\n", b->num_buttons);
 
-          buttons.resize(b->num_buttons, false);
-          break;
+              buttons.resize(b->num_buttons, false);
+            }
+            break;
 
-        case ValuatorClass:
-          v = (XValuatorInfoPtr)any;
-          a = (XAxisInfoPtr) ((char*)v +
-                              sizeof (XValuatorInfo));
+          case ValuatorClass:
+            {
+              XValuatorInfoPtr v = (XValuatorInfoPtr)any;
+              XAxisInfoPtr a = (XAxisInfoPtr) ((char*)v +
+                                               sizeof (XValuatorInfo));
 
-          printf("\tNum_axes is %d\n", v->num_axes);
-          printf("\tMode is %s\n", (v->mode == Absolute) ? "Absolute" : 
"Relative");
-          printf("\tMotion_buffer is %ld\n", v->motion_buffer);
+              printf("\tNum_axes is %d\n", v->num_axes);
+              printf("\tMode is %s\n", (v->mode == Absolute) ? "Absolute" : 
"Relative");
+              printf("\tMotion_buffer is %ld\n", v->motion_buffer);
 
-          absolute = (v->mode == Absolute);
+              absolute = (v->mode == Absolute);
 
-          for (j=0; j<v->num_axes; j++, a++)
-            {
-              printf("\tAxis %d :\n", j);
-              printf("\t\tMin_value is %d\n", a->min_value);
-              printf("\t\tMax_value is %d\n", a->max_value);
-              printf ("\t\tResolution is %d\n", a->resolution);
+              for (int j = 0; j < v->num_axes; ++j, ++a)
+                {
+                  printf("\tAxis %d :\n", j);
+                  printf("\t\tMin_value is %d\n", a->min_value);
+                  printf("\t\tMax_value is %d\n", a->max_value);
+                  printf ("\t\tResolution is %d\n", a->resolution);
 
-              axis.push_back(AxisInfo(a->min_value, a->max_value, 
a->resolution));
+                  axis.push_back(AxisInfo(a->min_value, a->max_value, 
a->resolution));
+                }
             }
+            break;
 
-          break;
+          case FeedbackClass:
+            std::cout << "Error: XInputDevice: get_info: unhandled class: 
FeedbackClass" << std::endl;
+            break;
 
-        default:
-          printf ("unknown class\n");
-      }
-      any = (XAnyClassPtr)((char*) any + any->length);
+          case ProximityClass:
+            std::cout << "Error: XInputDevice: get_info: unhandled class: 
ProximityClass" << std::endl;
+            break;
+
+          case FocusClass:
+            std::cout << "Error: XInputDevice: get_info: unhandled class: 
FocusClass" << std::endl;
+            break;
+
+          case OtherClass:
+            std::cout << "Error: XInputDevice: get_info: unhandled class: 
OtherClass" << std::endl;
+            break;
+
+          default:
+            std::cout << "Error: XInputDevice: get_info: unknown class: " << 
any->c_class << std::endl;
+            break;
+        }
+
+      std::cout << "AnyClass ptr: " << any->length << std::endl;
+      any = (XAnyClassPtr)((char*)any + any->length);
     }
-  }
 }
 
 } // namespace Input

Modified: trunk/pingus/src/input/xinput_driver.cpp
===================================================================
--- trunk/pingus/src/input/xinput_driver.cpp    2007-09-03 17:17:58 UTC (rev 
3070)
+++ trunk/pingus/src/input/xinput_driver.cpp    2007-09-03 19:58:27 UTC (rev 
3071)
@@ -25,6 +25,9 @@
 
 #include <iostream>
 
+#include "debug.hpp"
+#include "globals.hpp"
+
 #include "xinput_driver.hpp"
 #include "xinput_device.hpp"
 
@@ -71,14 +74,16 @@
     {
       int num_devices;
       XDeviceInfo* info = XListInputDevices(sys.info.x11.display, 
&num_devices);
-      for(int loop = 0; loop < num_devices; ++loop) 
+      for(int i = 0; i < num_devices; ++i) 
         {
-        // FIXME: Xinput isn't necesarrily a mouse, could be anything
-        if (info[loop].use == IsXExtensionDevice)
-          devices.push_back(new XInputDevice(this, info + loop));
-
-        XFreeDeviceList(info);
-      }
+          pout(PINGUS_DEBUG_INPUT) << "XInputDriver: Device name='" << 
info[i].name << "'" << std::endl;
+          // FIXME: Xinput isn't necesarrily a mouse, could be anything
+          //if (info[i].use == IsXExtensionDevice)
+          // {
+              devices.push_back(new XInputDevice(this, &info[i]));
+              // } 
+        }
+      XFreeDeviceList(info);
     }
 }
 
@@ -95,18 +100,19 @@
   // FIXME: Not really needed could simply pass XDeviceInfo to the
   // constructor, might however make a nicer interface
   XDeviceInfo *devices;
-  int  loop;
   int  num_devices;
   int  len = strlen(name);
   Bool is_id = True;
   XID  id = 0;
 
-  for(loop=0; loop<len; loop++) {
-    if (!isdigit(name[loop])) {
-      is_id = False;
-      break;
+  for(int i = 0; i < len; ++i) 
+    {
+      if (!isdigit(name[i])) 
+        {
+          is_id = False;
+          break;
+        }
     }
-  }
 
   if (is_id) {
     id = atoi(name);
@@ -114,13 +120,14 @@
 
   devices = XListInputDevices(display, &num_devices);
 
-  for(loop=0; loop<num_devices; loop++) {
-    if ((!only_extended || (devices[loop].use == IsXExtensionDevice)) &&
-        ((!is_id && strcmp(devices[loop].name, name) == 0) ||
-         (is_id && devices[loop].id == id))) {
-      return &devices[loop];
+  for(int i = 0; i < num_devices; ++i) 
+    {
+      if ((!only_extended || (devices[i].use == IsXExtensionDevice)) &&
+          ((!is_id && strcmp(devices[i].name, name) == 0) ||
+           (is_id && devices[i].id == id))) {
+        return &devices[i];
+      }
     }
-  }
   return NULL;
 }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]