⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xtest1dd.c

📁 远程桌面连接工具
💻 C
📖 第 1 页 / 共 3 页
字号:
/* $XConsortium: xtest1dd.c,v 1.14 94/04/17 20:33:00 gildea Exp $ *//* $XFree86: xc/programs/Xserver/Xext/xtest1dd.c,v 3.0 1996/05/06 05:55:42 dawes Exp $ *//* *	File: xtest1dd.c * *	This file contains the device dependent parts of the input *	synthesis extension. *//*Copyright (c) 1986, 1987, 1988   X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.Copyright 1986, 1987, 1988 by Hewlett-Packard CorporationPermission to use, copy, modify, and distribute thissoftware and its documentation for any purpose and withoutfee is hereby granted, provided that the above copyrightnotice appear in all copies and that both that copyrightnotice and this permission notice appear in supportingdocumentation, and that the name of Hewlett-Packard not be used inadvertising or publicity pertaining to distribution of thesoftware without specific, written prior permission.Hewlett-Packard makes no representations about the suitability of this software for any purpose.  It is provided "as is" without express or implied warranty.This software is not subject to any license of the AmericanTelephone and Telegraph Company or of the Regents of theUniversity of California.*//*************************************************************** * include files ***************************************************************/#define	NEED_EVENTS#define	NEED_REPLIES#include <stdio.h>#include "Xos.h"#include "X.h"#include "Xmd.h"#include "Xproto.h"#include "misc.h"#include "dixstruct.h"#define  XTestSERVER_SIDE#include "xtestext1.h"	#include "xtest1dd.h"/*************************************************************** * defines ***************************************************************//* * the size of the fake input action array */#define ACTION_ARRAY_SIZE	100/*************************************************************** * externals ***************************************************************//* * Holds the xTestInputAction event type code. * This is defined in xtestext1di.c. */extern int			XTestInputActionType;/* * Holds the xTestFakeAck event type code. * This is defined in xtestext1di.c. */extern int			XTestFakeAckType;/* * used in the WriteReplyToClient macro */extern int			exclusive_steal;/*************************************************************** * variables ***************************************************************//* * array to hold fake input actions */struct {	/*	 * holds the action type, one of: XTestDELAY_ACTION,	 * XTestKEY_ACTION, XTestMOTION_ACTION, XTestJUMP_ACTION	 */	CARD8	type;		/*	 * holds the device type, in the range 0 to 15	 */	CARD8	device;	/*	 * for XTestKEY_ACTION type, holds the keycode	 */	CARD8	keycode;	/*	 * for XTestKEY_ACTION type, holds the key up/down state	 */	CARD8	keystate;	/*	 * for XTestMOTION_ACTION and XTestJUMP_ACTION types,	 * holds the x and y coordinates to move the mouse to	 */	int	x;	int	y;	/*	 * holds the time to delay (in milliseconds) before performing	 * the action	 */	CARD32	delay_time;}action_array[ACTION_ARRAY_SIZE];/* * write index for input action array */static int			write_index = 0;/* * read index for input action array */static int			read_index = 0;/* * this is where the input actions are accumulated until they are sent * to a client (in a wire event) */static xTestInputActionEvent	input_action_packet;/* * holds the index (in bytes) into the input actions buffer in the * current input action event */static int 			packet_index;/* * set to 1 when the input action event is full and needs to be sent to the  * client */static int			input_action_event_full = 0;/* * logical x position of the mouse during input action gathering */short				xtest_mousex;/* * logical y position of the mouse during input action gathering */short				xtest_mousey;/* * logical x position of the mouse during input action playback */static short			mx;/* * logical y position of the mouse during input action playback */static short			my;/* * logical x position of the mouse while we are reading fake input actions * from the client and putting them into the fake input action array */static short			pmousex;/* * logical y position of the mouse while we are reading fake input actions * from the client and putting them into the fake input action array */static short			pmousey;/* * The playback_on flag is set to 1 while there are input actions in the  * input action array.  It is set to 0 when the server has received all of * the user actions. */int			playback_on = 0;/* * identity of the client using XTestGetInput to get user input actions */ClientPtr 		current_xtest_client;/* * if 1 send multiple input actions per XTestInputAction event; * if 0 send one input action per XTestInputAction event */static char			packed_mode;/* * identity of the client using the XTestFakeInput function to send some * fake input actions to the server */ClientPtr		playback_client = NULL;/* * Set to 1 when the XTestFAKE_ACK_REQUEST flag is set in a XTestFakeInput * request.  Set back to 0 when all of the input actions have been sent * to the server. */static int			acknowledge = 0;/* * The server's idea of the current time is saved in these variables when * a XTestFakeInput request is received.  It is restored when all fake input * actions are sent to the server or when the playback client disconnects. */static int			saved_sec;static int			saved_usec;/* * Set to 1 when there is a valid time in saved_sec and saved_usec. */static int			time_saved = 0;/* * holds the extension's notion of what the current time is while it is  * sending input actions to a client */static struct timeval		current_time;/* * holds the time when the extension should place the next fake input action * into the server's normal events queue */static struct timeval		play_time;/* * set to 1 when play_time is first set, cleared to 0 when the * client using the extension disconnects, or when XTestReset is called */static char			play_clock = 0;/* * holds the amount of time left until the next input action from the * input action array can be sent to the server */static struct timeval		rtime;/* * Set to 1 after the extension is done waiting for the correct time delay * for an input action to be sent to the server.  Remains a 1 until the time * delay for the next input action is computed.  Then set to 0 if the * extension has to wait for the correct time delay. */static int			go_for_next = 1;/* * needed to restore waitime if playback is to be aborted */static struct timeval		*restorewait;/* * tmon special command key * * To use the test monitor program (called tmon) efficiently, it is * desirable to have the extension be able to recognize a special "trigger" * key.  If the extension did not do this, tmon would have to have the * extension send all keyboard user input actions exclusively to tmon, * only to have tmon send them right back if they were not the command key. * * If the extension can recognize the command key, then tmon can let the * extension handle keyboard user input actions normally until the command * key is pressed (and released), and only then have the extension start * sending keyboard user input actions exclusively to tmon. * * Any key on the keyboard can be used for this command key.  It is most * convenient if it is a low-frequency key.  If you want to generate a * normal occurrance of this key to a client, just hit it twice.  Tmon * will recognize the first occurrance of the key, take control of the input * actions, and wait for certain keys.  If it sees another occurrance of the * command key, it will send one occurrance of the command key to the * extension, and go back to waiting. * * set and also referenced in device layer * XXX there should be a way to set this through the protocol */KeyCode			xtest_command_key = 0;/*************************************************************** * function declarations ***************************************************************/static void	parse_key_fake(#if NeedFunctionPrototypes			XTestKeyInfo	* /* fkey */#endif			);static void	parse_motion_fake(#if NeedFunctionPrototypes			XTestMotionInfo	* /* fmotion */#endif			);static void	parse_jump_fake(#if NeedFunctionPrototypes			XTestJumpInfo	* /* fjump */#endif			);static void	parse_delay_fake(#if NeedFunctionPrototypes			XTestDelayInfo	* /* tevent */#endif			);static void	send_ack(#if NeedFunctionPrototypes			ClientPtr	 /* client */#endif			);static void	start_play_clock(#if NeedFunctionPrototypes			void#endif			);static void	compute_action_time(#if NeedFunctionPrototypes			struct timeval	* /* rtime */#endif			);static int	find_residual_time(#if NeedFunctionPrototypes			struct timeval	* /* rtime */#endif			);static CARD16	check_time_event(#if NeedFunctionPrototypes			void#endif			);static CARD32	current_ms(#if NeedFunctionPrototypes			struct timeval	* /* otime */#endif			);static int	there_is_room(#if NeedFunctionPrototypes			int	/* actsize */#endif			);/****************************************************************************** * * 	stop_stealing_input * *	Stop stealing input actions. */voidstop_stealing_input(){/* * put any code that you might need to stop stealing input actions here */	if (packet_index != 0) 	{		/*		 * if there is a partially full input action event waiting		 * when this function is called, send it to the client		 */		flush_input_actions();	}}/****************************************************************************** * * 	steal_input * *	Start stealing input actions and sending them to the passed-in client. */voidsteal_input(client, mode)/* * which client is to receive the input action events */ClientPtr	client;/* * what input action packing mode to use.  one of 0, XTestPACKED_MOTION, * or XTestPACKED_ACTIONS; optionally 'or'ed with XTestEXCLUSIVE, */CARD32		mode;{	if (packet_index != 0) 	{		/*		 * if there is a partially full input action event waiting		 * when this function is called, send it to the client		 */		flush_input_actions();	}	else	{			/*		 * otherwise, set up a new input action event		 */		input_action_packet.type = XTestInputActionType;		packet_index = 0;	}	/*	 * set up the new input action packing mode	 */	packed_mode = mode & ~(XTestEXCLUSIVE);	/*	 * keep track of where the mouse is	 */	XTestGetPointerPos(&xtest_mousex, &xtest_mousey);	/*	 * keep track of which client is getting input actions	 */	current_xtest_client = client;	/*	 * find out what time it is	 */	X_GETTIMEOFDAY(&current_time);	/*	 * jump to the initial position of the mouse, using a device type of 0.	 */	XTestStealJumpData(xtest_mousex, xtest_mousey, 0);}	/****************************************************************************** * *	flush_input_actions * *	Write the input actions event to the current requesting client *	and re-initialize the input action event. */voidflush_input_actions(){	/*	 * pointer to the input action event	 */	char			*rep;	/*	 * loop index	 */	int			i;	if (packet_index == 0)	{		/*		 * empty input actions event 		 */		return;	}	else if (packet_index < XTestACTIONS_SIZE)	{		/*		 * fill to the end of the input actions event with 0's		 */		for (i = packet_index; i <XTestACTIONS_SIZE; i++)		{			input_action_packet.actions[i] = 0;		}	}	rep = (char *) (&input_action_packet);	/*	 * set the serial number of the input action event	 */	input_action_packet.sequenceNumber = current_xtest_client->sequence;	/*	 * send the input action event to the client	 */	WriteEventsToClient(current_xtest_client, 1, (xEvent *) rep);	/*	 * re-initialize the input action event	 */	input_action_event_full = 0;	input_action_packet.type = XTestInputActionType; 	packet_index = 0;}	/****************************************************************************** * *	XTestStealJumpData * *	Create one or more input actions and put them in the input action *	event.  The input actions will be an (maybe) XTestDELAY_ACTION *	and an XTestJUMP_ACTION. */voidXTestStealJumpData(jx, jy, dev_type)/* * the x and y coordinates to jump to */short	jx;short	jy;/* * which device caused the jump */int	dev_type;{		XTestJumpInfo 	*jmp_ptr;	/*	 * time delta (in ms) from previous event	 */	CARD16			tchar;	/*	 * Get the time delta from the previous event.  If needed,	 * the check_time_event routine will put an XTestDELAY_ACTION	 * type action in the input action event.	 */	tchar = check_time_event();	if (!there_is_room(sizeof(XTestJumpInfo)))	{		/*		 * If there isn't room in the input action event for		 * an XTestJUMP_ACTION, then send that event to the		 * client and start filling an empty one.		 */		flush_input_actions();	}	/*	 * update the logical mouse position	 */	xtest_mousex = jx;	xtest_mousey = jy;	/*	 * point jmp_ptr to the correct place in the input action event	 */	jmp_ptr = (XTestJumpInfo *)		  &(input_action_packet.actions[packet_index]);	/*	 * compute the input action header	 */	jmp_ptr->header = (XTestPackDeviceID(dev_type) | XTestJUMP_ACTION);		/*	 * set the x and y coordinates to jump to in the input action	 */	jmp_ptr->jumpx = jx;	jmp_ptr->jumpy = jy;	/*	 * set the delay time in the input action	 */	jmp_ptr->delay_time = tchar;	/*	 * increment the packet index by the size of the input action	 */	packet_index = packet_index + sizeof(XTestJumpInfo);	if (packed_mode == 0)	{		/*		 * if input actions are not packed, send the input		 * action event to the client

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -