CVS: winex/dlls/dinput/mouse main.c,1.71,1.72

[email protected]
Newsgroups gmane.comp.emulators.winex.cvs
Message-ID <[email protected]>
Subject: winex/dlls/dinput/mouse main.c,1.71,1.72Update of /var/lib/cvsd/cvsroot/winex/dlls/dinput/mouse
In directory agravaine:/tmp/cvs-serv28445/dlls/dinput/mouse

Modified Files:
	main.c 
Log Message:
- Adding support to read the "AbsoluteMouseSensitivity" option from a config file.  The default value is 1, so in any cases where this option isn't tweaked, its influence will have no effect on the mouse behaviour.
- Fixing an if-statement in the joystick/main.c file.


Index: main.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/dlls/dinput/mouse/main.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- main.c	30 Mar 2007 22:05:05 -0000	1.71
+++ main.c	30 Mar 2007 22:06:20 -0000	1.72
@@ -17,6 +17,7 @@
 #include "winuser.h"
 #include "winerror.h"
 #include "wine/winbase16.h"
+#include "winreg.h"
 #include "dinput.h"
 #include "user.h"
 
@@ -173,6 +174,68 @@
 static IDirectInputDevice8A* current_lock = NULL;
 
 
+
+/***********************************************************************
+ * get_config_key
+ *
+ * Get a config key from either the app-specific or the default config
+ */
+inline static DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
+                                    char *buffer, DWORD size )
+{
+    if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, buffer, &size ))
+        return 0;
+    return RegQueryValueExA( defkey, name, 0, NULL, buffer, &size );
+}
+
+/***********************************************************************
+ * setup_options
+ *
+ * read specific options
+ */
+
+static int  defaultAbsoluteMouseSensitivity = 1;
+static void setup_dinput_mouseoptions(void)
+{
+  static char mouseoptionsread = 0;
+
+  char buffer[MAX_PATH+16];
+  HKEY hkey, appkey = 0;
+  if (mouseoptionsread)
+        return;
+  if (RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\dinput", 0, NULL,
+                       REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL )) {
+    ERR("Cannot create config registry key\n");
+    return;
+  }
+
+  /* open the app-specific key */
+  if (GetModuleFileName16( GetCurrentTask(), buffer, MAX_PATH ) ||
+      GetModuleFileNameA( 0, buffer, MAX_PATH )) {
+    HKEY tmpkey;
+    char *p, *appname = buffer;
+    if ((p = strrchr( appname, '/' ))) appname = p + 1;
+    if ((p = strrchr( appname, '\\' ))) appname = p + 1;
+    strcat( appname, "\\dinput" );
+    if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\AppDefaults", &tmpkey ))
+    {
+        if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
+        RegCloseKey( tmpkey );
+    }
+  }
+
+  if (!get_config_key( hkey, appkey, "AbsoluteMouseSensitivity", buffer, sizeof(buffer) ))
+  {
+    int configAbsoluteMouseSensitivity = atoi( buffer );
+        if ((configAbsoluteMouseSensitivity >= 0) && (configAbsoluteMouseSensitivity <= 100))
+                defaultAbsoluteMouseSensitivity = configAbsoluteMouseSensitivity;
+  }
+  TRACE("defaultAbsoluteMouseSensitivity = (%d)\n", defaultAbsoluteMouseSensitivity);
+  mouseoptionsread = 1;
+}
+
+/***************************************************************************/
+
 static int mousedev_enum_device(IDirectInputImpl *dinput, DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD dwID)
 {
   if ((dwDevType != 0) && (dwDevType != DIDEVTYPE_MOUSE) &&
@@ -218,6 +281,7 @@
     CRITICAL_SECTION_NAME(&(newDevice->crit), "SysMouse");
     memcpy(&(newDevice->guid),rguid,sizeof(*rguid));
 
+    setup_dinput_mouseoptions();
     /* Per default, Wine uses its internal data format */
     newDevice->df = &Wine_InternalMouseFormat;
     memcpy(newDevice->offset_array, offset_array, WINE_INTERNALMOUSE_NUM_OBJS * sizeof(int));
@@ -488,13 +552,13 @@
 	  }
 	  if (hook->pt.x != This->prevX) {
 	    if (This->absolute)
-	      GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], This->m_state.lX, hook->time, (This->dinput->evsequence)++)
+	      GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], This->m_state.lX * defaultAbsoluteMouseSensitivity, hook->time, (This->dinput->evsequence)++)
 	    else
 	      GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->prevX, hook->time, (This->dinput->evsequence)++)
 	  }
 	  if (hook->pt.y != This->prevY) {
 	    if (This->absolute)
-	      GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], This->m_state.lY, hook->time, (This->dinput->evsequence)++)
+	      GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], This->m_state.lY * defaultAbsoluteMouseSensitivity, hook->time, (This->dinput->evsequence)++)
 	    else
 	      GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->prevY, hook->time, (This->dinput->evsequence)++)
 	  }
@@ -506,7 +570,6 @@
           RECT window_rect;
           BOOL do_abs_calc = TRUE;
           BOOL changed = FALSE;
-
           GetWindowRect(This->win, &window_rect);
           min_x = window_rect.left;
           min_y = window_rect.top;
@@ -541,7 +604,7 @@
 
 	  This->m_state.lX += hook->pt.x - This->prevX;
 	  This->m_state.lY += hook->pt.y - This->prevY;
-
+          
 #ifdef MOUSE_HACK
           if ((This->need_warp == WARP_DONE) &&
               (hook->pt.x == This->mapped_center.x) && (hook->pt.y == This->mapped_center.y))
@@ -554,14 +617,14 @@
 	  /* Relative mouse input with absolute mouse event : the real fun starts here... */
 	  if (hook->pt.x != This->prevX) {
 	    if (This->absolute)
-	      GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], This->m_state.lX, hook->time, (This->dinput->evsequence)++)
+	      GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], This->m_state.lX * defaultAbsoluteMouseSensitivity, hook->time, (This->dinput->evsequence)++)
 	    else
 	      GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->prevX, hook->time, (This->dinput->evsequence)++)
 	    changed = TRUE;
 	  }
 	  if (hook->pt.y != This->prevY) {
 	    if (This->absolute)
-	      GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], This->m_state.lY, hook->time, (This->dinput->evsequence)++)
+	      GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], This->m_state.lY * defaultAbsoluteMouseSensitivity, hook->time, (This->dinput->evsequence)++)
 	    else
 	      GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->prevY, hook->time, (This->dinput->evsequence)++)
 	    changed = TRUE;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.