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

📄 mac_hid.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    0644, NULL, &proc_dointvec  },  {    DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE,    "mouse_button2_keycode", &mouse_button2_keycode, sizeof(int),    0644, NULL, &proc_dointvec  },  {    DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE,    "mouse_button3_keycode", &mouse_button3_keycode, sizeof(int),    0644, NULL, &proc_dointvec  },#endif  { 0 }};/* dir in /proc/sys/dev */ctl_table mac_hid_dir[] ={  { DEV_MAC_HID, "mac_hid", NULL, 0, 0555, mac_hid_files },  { 0 }};/* /proc/sys/dev itself, in case that is not there yet */ctl_table mac_hid_root_dir[] ={  { CTL_DEV, "dev", NULL, 0, 0555, mac_hid_dir },  { 0 }};static struct ctl_table_header *mac_hid_sysctl_header;#ifdef CONFIG_MAC_ADBKEYCODESstaticint mac_hid_sysctl_keycodes(ctl_table *ctl, int write, struct file * filp,			    void *buffer, size_t *lenp){	int val = keyboard_sends_linux_keycodes;	int ret = 0;	if (!write	    || (write && !keyboard_lock_keycodes))		ret = proc_dointvec(ctl, write, filp, buffer, lenp);	if (write	    && keyboard_sends_linux_keycodes != val) {		if (!keyboard_sends_linux_keycodes) {#ifdef CONFIG_MAGIC_SYSRQ			ppc_md.ppc_kbd_sysrq_xlate   = mac_hid_kbd_sysrq_xlate;			SYSRQ_KEY                = 0x69;#endif			memcpy(pc_key_maps_save, key_maps, sizeof(key_maps));			memcpy(key_maps, mac_key_maps_save, sizeof(key_maps));		} else {#ifdef CONFIG_MAGIC_SYSRQ			ppc_md.ppc_kbd_sysrq_xlate   = pckbd_sysrq_xlate;			SYSRQ_KEY                = 0x54;#endif			memcpy(mac_key_maps_save, key_maps, sizeof(key_maps));			memcpy(key_maps, pc_key_maps_save, sizeof(key_maps));		}	}	return ret;}#endif#endif /* endif CONFIG_SYSCTL */int mac_hid_kbd_translate(unsigned char scancode, unsigned char *keycode,			  char raw_mode){#ifdef CONFIG_MAC_ADBKEYCODES	if (!keyboard_sends_linux_keycodes) {		if (!raw_mode) {		/*		 * Convert R-shift/control/option to L version.		 */			switch (scancode) {			case 0x7b: scancode = 0x38; break; /* R-shift */			case 0x7c: scancode = 0x3a; break; /* R-option */			case 0x7d: scancode = 0x36; break; /* R-control */			}		}		*keycode = scancode;		return 1;	} else#endif	{		/* This code was copied from char/pc_keyb.c and will be		 * superflous when the input layer is fully integrated.		 * We don't need the high_keys handling, so this part		 * has been removed.		 */		static int prev_scancode = 0;		/* special prefix scancodes.. */		if (scancode == 0xe0 || scancode == 0xe1) {			prev_scancode = scancode;			return 0;		}		scancode &= 0x7f;		if (prev_scancode) {			if (prev_scancode != 0xe0) {				if (prev_scancode == 0xe1 && scancode == 0x1d) {					prev_scancode = 0x100;					return 0;				} else if (prev_scancode == 0x100 && scancode == 0x45) {					*keycode = KEY_PAUSE;					prev_scancode = 0;				} else {					if (!raw_mode)						printk(KERN_INFO "keyboard: unknown e1 escape sequence\n");					prev_scancode = 0;					return 0;				}			} else {				prev_scancode = 0;				if (scancode == 0x2a || scancode == 0x36)					return 0;			}			if (e0_keys[scancode])				*keycode = e0_keys[scancode];			else {				if (!raw_mode)					printk(KERN_INFO "keyboard: unknown scancode e0 %02x\n",					       scancode);				return 0;			}		} else {			switch (scancode) {			case  91: scancode = KEY_LINEFEED; break;			case  92: scancode = KEY_KPEQUAL; break;			case 125: scancode = KEY_INTL1; break;			}			*keycode = scancode;		}		return 1;	}}char mac_hid_kbd_unexpected_up(unsigned char keycode){	if (keyboard_sends_linux_keycodes && keycode == KEY_F13)		return 0;	else		return 0x80;}#ifdef CONFIG_MAC_ADBKEYCODESint mac_hid_keyboard_sends_linux_keycodes(void){	return keyboard_sends_linux_keycodes;}static int __init mac_hid_setup(char *str){	int ints[2];	str = get_options(str, ARRAY_SIZE(ints), ints);	if (ints[0] == 1) {		keyboard_sends_linux_keycodes = ints[1] != 0;		keyboard_lock_keycodes = 1;	}	return 1;}__setup("keyboard_sends_linux_keycodes=", mac_hid_setup);#endif#ifdef CONFIG_MAC_EMUMOUSEBTNint mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down){	switch (caller) {	case 1:		/* Called from keybdev.c */		if (mouse_emulate_buttons		    && (keycode == mouse_button2_keycode			|| keycode == mouse_button3_keycode)) {			if (mouse_emulate_buttons == 1) {			 	input_report_key(&emumousebtn,						 keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT,						 down);				return 1;			}			mouse_last_keycode = down ? keycode : 0;		}		break;	case 2:		/* Called from mousedev.c */		if (mouse_emulate_buttons == 2 && keycode == 0) {			if (mouse_last_keycode == mouse_button2_keycode)				return 1; /* map to middle button */			if (mouse_last_keycode == mouse_button3_keycode)				return 2; /* map to right button */		}		return keycode; /* keep button */	}	return 0;}static void emumousebtn_input_register(void){	emumousebtn.name = "Macintosh mouse button emulation";	emumousebtn.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);	emumousebtn.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);	emumousebtn.relbit[0] = BIT(REL_X) | BIT(REL_Y);	emumousebtn.idbus = BUS_ADB;	emumousebtn.idvendor = 0x0001;	emumousebtn.idproduct = 0x0001;	emumousebtn.idversion = 0x0100;	input_register_device(&emumousebtn);	printk(KERN_INFO "input%d: Macintosh mouse button emulation\n", emumousebtn.number);}#endifvoid __init mac_hid_init_hw(void){#ifdef CONFIG_MAC_ADBKEYCODES	memcpy(pc_key_maps_save, key_maps, sizeof(key_maps));	if (!keyboard_sends_linux_keycodes)		memcpy(key_maps, mac_key_maps_save, sizeof(key_maps));#endif#ifdef CONFIG_MAC_EMUMOUSEBTN	emumousebtn_input_register();#endif#if CONFIG_PPC	if (_machine != _MACH_Pmac)		pckbd_init_hw();#endif#if defined(CONFIG_SYSCTL) && (defined(CONFIG_MAC_ADBKEYCODES) || defined(CONFIG_MAC_EMUMOUSEBTN))	mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir, 1);#endif /* CONFIG_SYSCTL */}

⌨️ 快捷键说明

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