<commit_before>/* 
 *   2002 <NAME> <<EMAIL>>
 *     patches for fast scrolling, plam detection, dege motion, 
 *     hozizontal scrolling
 *
 *	 Copyright (C) 2001 <NAME> <<EMAIL>>
 *     start merging tpconfig and gpm code to a xfree-input modul
 *     adding some changes and extensions (ex. 3rd and 4th button)
 * 
 *   Copyright (c) 1999 <NAME> <<EMAIL>> for the 
 *     absolut to relative translation code (from the gpm-source)
 *     and some other ideas
 *
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU General Public License
 *   as published by the Free Software Foundation; either version 2
 *   of the License, or (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *
 * Trademarks are the property of their respective owners.
 *
 */


/*****************************************************************************
 *	Standard Headers
 ****************************************************************************/

#include <stdio.h>
#include <misc.h>
#include <xf86.h>
#define NEED_XF86_TYPES
#include <xf86_ansic.h>
#include <xf86_OSproc.h>
#include <xf86Xinput.h>
#include <xisb.h>
#include <exevents.h>			/* Needed for InitValuator/Proximity stuff	*/
#include "mipointer.h"
#include <xf86Optrec.h>  		/* needed for Options */ 


/*****************************************************************************
 *	Local Headers
 ****************************************************************************/
#define SYNAPTICS_PRIVATE
#include "synaptics.h"
#include "ps2comm.h"

/*****************************************************************************
 *	Variables without includable headers
 ****************************************************************************/

/*****************************************************************************
 *	Local Variables and Types
 ****************************************************************************/

typedef enum {
	BOTTOM_EDGE = 1,
	TOP_EDGE = 2,
	LEFT_EDGE = 4,
	RIGHT_EDGE = 8,
	LEFT_BOTTOM_EDGE = BOTTOM_EDGE | LEFT_EDGE,
	RIGHT_BOTTOM_EDGE = BOTTOM_EDGE | RIGHT_EDGE,
	RIGHT_TOP_EDGE = TOP_EDGE | RIGHT_EDGE,
	LEFT_TOP_EDGE = TOP_EDGE | LEFT_EDGE
} edge_type;

#define MAX(a, b) (((a)>(b))?(a):(b))
#define DIFF_TIME(a, b) (((a)>(b))?(a)-(b):(b)-(a))

#define VERSION "0.11.3p1"

/*****************************************************************************
 * Forward declaration
 ****************************************************************************/
static InputInfoPtr
SynapticsPreInit(InputDriverPtr drv, IDevPtr dev, int flags);


InputDriverRec SYNAPTICS = {
  1,
  "synaptics",
  NULL,
  SynapticsPreInit,
  /*SynapticsUnInit*/ NULL,
  NULL,
  0
};

#ifdef XFree86LOADER

static XF86ModuleVersionInfo VersionRec =
{
	"synaptics",
	MODULEVENDORSTRING,
	MODINFOSTRING1,
	MODINFOSTRING2,
	XF86_VERSION_CURRENT,
	1, 0, 0,
	ABI_CLASS_XINPUT,
	ABI_XINPUT_VERSION,
	MOD_CLASS_XINPUT,
	{0, 0, 0, 0}				/* signature, to be patched into the file by
								 * a tool */
};


static pointer
SetupProc(pointer module, pointer options, int *errmaj, int *errmin ) 
{
	xf86AddInputDriver(&SYNAPTICS, module, 0);
	return module;
}

XF86ModuleData synapticsModuleData = {&VersionRec, &SetupProc, NULL };

#endif /* XFree86LOADER */


/*****************************************************************************
 *	Function Definitions
 ****************************************************************************/

/*
 *  called by the module loader for initialtion       
 */
static InputInfoPtr
SynapticsPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
{
	LocalDevicePtr local;
	SynapticsPrivatePtr priv;
	XF86OptionPtr optList; 
	char *str_par;
	int shmid;

	/* allocate memory for SynaticsPrivateRec */
	priv = xcalloc (1, sizeof (SynapticsPrivateRec));
	if (!priv)
		return NULL;

	/* Allocate a new InputInfoRec and add it to the head xf86InputDevs. */
	local = xf86AllocateInput(drv, 0);
	if (!local) 
	{
		xfree(priv);
		return NULL;
	}

	/* initialize the InputInfoRec */
	local->name                    = dev->identifier;
	local->type_name               = XI_MOUSE; /* XI_TOUCHPAD and KDE killed the X-Server at startup ? */
	local->device_control          = DeviceControl;
	local->read_input              = ReadInput;
	local->control_proc            = ControlProc;
	local->close_proc              = CloseProc;
	local->switch_mode             = SwitchMode;
	local->conversion_proc         = ConvertProc;
	local->reverse_conversion_proc = NULL;
	local->dev                     = NULL;
	local->private                 = priv;
	local->private_flags           = 0;
	local->flags                   = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS;
	local->conf_idev               = dev;
	local->motion_history_proc     = xf86GetMotionEvents;
	local->history_size            = 0;
	local->always_core_feedback    = 0;

	xf86CollectInputOptions(local, NULL, NULL);

	xf86OptionListReport(local->options);

	/* open the touchpad device */
	local->fd = xf86OpenSerial (local->options);
	if (local->fd == -1)
	{
		ErrorF ("Synaptics driver unable to open device\n");
		goto SetupProc_fail;
	}
	xf86ErrorFVerb( 6, "port opened successfully\n" );

	/* initialize variables */
	priv->repeat_timer = NULL;
	priv->repeatButtons = 0;

	/* install shared memory or normal memory for parameter */
	if(xf86SetBoolOption(local->options, "SHMConfig", FALSE)) 
	{
		xf86shmctl(SHM_SYNAPTICS, XF86IPC_RMID, NULL);
		if((shmid = xf86shmget(SHM_SYNAPTICS, sizeof(SynapticsSHM), 0777 | XF86IPC_CREAT)) == -1) 
		{
			xf86Msg(X_ERROR, "%s error shmget\n", local->name);
			goto SetupProc_fail;
		} 
		else if((priv->synpara = (SynapticsSHM*) xf86shmat(shmid, NULL, 0)) == NULL) 
		{
			xf86Msg(X_ERROR, "%s error shmat\n", local->name);
			goto SetupProc_fail;
		}
	} 
	else 
	{
		priv->synpara = xcalloc (1, sizeof (SynapticsSHM));
		if(!priv->synpara)
			goto SetupProc_fail;
	}

	/* read the parameter */
	priv->synpara->left_edge = xf86SetIntOption(local->options, "LeftEdge", 1900);<commit_msg>Fixed removal of old shared memory segment before trying to create the new segment. This made X server startup fail if the memory segment size had been changed. (The first argument to xf86shmget is an shmid, not a key.)<commit_after>/* 
 *   2002 <NAME> <<EMAIL>>
 *     patches for fast scrolling, plam detection, dege motion, 
 *     hozizontal scrolling
 *
 *	 Copyright (C) 2001 <NAME> <<EMAIL>>
 *     start merging tpconfig and gpm code to a xfree-input modul
 *     adding some changes and extensions (ex. 3rd and 4th button)
 * 
 *   Copyright (c) 1999 <NAME> <<EMAIL>> for the 
 *     absolut to relative translation code (from the gpm-source)
 *     and some other ideas
 *
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU General Public License
 *   as published by the Free Software Foundation; either version 2
 *   of the License, or (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *
 * Trademarks are the property of their respective owners.
 *
 */


/*****************************************************************************
 *	Standard Headers
 ****************************************************************************/

#include <stdio.h>
#include <misc.h>
#include <xf86.h>
#define NEED_XF86_TYPES
#include <xf86_ansic.h>
#include <xf86_OSproc.h>
#include <xf86Xinput.h>
#include <xisb.h>
#include <exevents.h>			/* Needed for InitValuator/Proximity stuff	*/
#include "mipointer.h"
#include <xf86Optrec.h>  		/* needed for Options */ 


/*****************************************************************************
 *	Local Headers
 ****************************************************************************/
#define SYNAPTICS_PRIVATE
#include "synaptics.h"
#include "ps2comm.h"

/*****************************************************************************
 *	Variables without includable headers
 ****************************************************************************/

/*****************************************************************************
 *	Local Variables and Types
 ****************************************************************************/

typedef enum {
	BOTTOM_EDGE = 1,
	TOP_EDGE = 2,
	LEFT_EDGE = 4,
	RIGHT_EDGE = 8,
	LEFT_BOTTOM_EDGE = BOTTOM_EDGE | LEFT_EDGE,
	RIGHT_BOTTOM_EDGE = BOTTOM_EDGE | RIGHT_EDGE,
	RIGHT_TOP_EDGE = TOP_EDGE | RIGHT_EDGE,
	LEFT_TOP_EDGE = TOP_EDGE | LEFT_EDGE
} edge_type;

#define MAX(a, b) (((a)>(b))?(a):(b))
#define DIFF_TIME(a, b) (((a)>(b))?(a)-(b):(b)-(a))

#define VERSION "0.11.3p1"

/*****************************************************************************
 * Forward declaration
 ****************************************************************************/
static InputInfoPtr
SynapticsPreInit(InputDriverPtr drv, IDevPtr dev, int flags);


InputDriverRec SYNAPTICS = {
  1,
  "synaptics",
  NULL,
  SynapticsPreInit,
  /*SynapticsUnInit*/ NULL,
  NULL,
  0
};

#ifdef XFree86LOADER

static XF86ModuleVersionInfo VersionRec =
{
	"synaptics",
	MODULEVENDORSTRING,
	MODINFOSTRING1,
	MODINFOSTRING2,
	XF86_VERSION_CURRENT,
	1, 0, 0,
	ABI_CLASS_XINPUT,
	ABI_XINPUT_VERSION,
	MOD_CLASS_XINPUT,
	{0, 0, 0, 0}				/* signature, to be patched into the file by
								 * a tool */
};


static pointer
SetupProc(pointer module, pointer options, int *errmaj, int *errmin ) 
{
	xf86AddInputDriver(&SYNAPTICS, module, 0);
	return module;
}

XF86ModuleData synapticsModuleData = {&VersionRec, &SetupProc, NULL };

#endif /* XFree86LOADER */


/*****************************************************************************
 *	Function Definitions
 ****************************************************************************/

/*
 *  called by the module loader for initialtion       
 */
static InputInfoPtr
SynapticsPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
{
	LocalDevicePtr local;
	SynapticsPrivatePtr priv;
	XF86OptionPtr optList; 
	char *str_par;
	int shmid;

	/* allocate memory for SynaticsPrivateRec */
	priv = xcalloc (1, sizeof (SynapticsPrivateRec));
	if (!priv)
		return NULL;

	/* Allocate a new InputInfoRec and add it to the head xf86InputDevs. */
	local = xf86AllocateInput(drv, 0);
	if (!local) 
	{
		xfree(priv);
		return NULL;
	}

	/* initialize the InputInfoRec */
	local->name                    = dev->identifier;
	local->type_name               = XI_MOUSE; /* XI_TOUCHPAD and KDE killed the X-Server at startup ? */
	local->device_control          = DeviceControl;
	local->read_input              = ReadInput;
	local->control_proc            = ControlProc;
	local->close_proc              = CloseProc;
	local->switch_mode             = SwitchMode;
	local->conversion_proc         = ConvertProc;
	local->reverse_conversion_proc = NULL;
	local->dev                     = NULL;
	local->private                 = priv;
	local->private_flags           = 0;
	local->flags                   = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS;
	local->conf_idev               = dev;
	local->motion_history_proc     = xf86GetMotionEvents;
	local->history_size            = 0;
	local->always_core_feedback    = 0;

	xf86CollectInputOptions(local, NULL, NULL);

	xf86OptionListReport(local->options);

	/* open the touchpad device */
	local->fd = xf86OpenSerial (local->options);
	if (local->fd == -1)
	{
		ErrorF ("Synaptics driver unable to open device\n");
		goto SetupProc_fail;
	}
	xf86ErrorFVerb( 6, "port opened successfully\n" );

	/* initialize variables */
	priv->repeat_timer = NULL;
	priv->repeatButtons = 0;

	/* install shared memory or normal memory for parameter */
	if(xf86SetBoolOption(local->options, "SHMConfig", FALSE)) 
	{
		if ((shmid = xf86shmget(SHM_SYNAPTICS, 0, 0)) != -1)
			xf86shmctl(shmid, XF86IPC_RMID, NULL);
		if((shmid = xf86shmget(SHM_SYNAPTICS, sizeof(SynapticsSHM), 0777 | XF86IPC_CREAT)) == -1) 
		{
			xf86Msg(X_ERROR, "%s error shmget\n", local->name);
			goto SetupProc_fail;
		} 
		else if((priv->synpara = (SynapticsSHM*) xf86shmat(shmid, NULL, 0)) == NULL) 
		{
			xf86Msg(X_ERROR, "%s error shmat\n", local->name);
			goto SetupProc_fail;
		}
	} 
	else 
	{
		priv->synpara = xcalloc (1, sizeof (SynapticsSHM));
		if(!priv->synpara)
			goto SetupProc_fail;
	}

	/* read the parameter */
	priv->synpara->left_edge = xf86SetIntOption(local->options, "LeftEdge", 1900);
{'fraction_non_alphanumeric': 0.23410054512416717, 'fraction_numerical': 0.01960932768019382, 'mean_word_length': 4.0882126348228045, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6759207', 'n_tokens_mistral': 4449, 'n_tokens_neox': 4004, 'n_words': 1095}