Esempio n. 1
0
static int
load_xkb_keyboard(KeycodeToVkcode map, char* kbd)
{
	char* pch;
	char *beg, *end;
	char* home;
	char buffer[1024] = "";
	char xkbfile[256] = "";
	char xkbfilepath[512] = "";
	char xkbmap[256] = "";
	char xkbinc[256] = "";

	FILE* fp;
	int kbdFound = 0;

	int i = 0;
	int keycode = 0;
	char keycodeString[32] = "";
	char vkcodeName[128] = "";

	beg = kbd;


	/* Extract file name and keymap name */
	if((end = strrchr(kbd, '(')) != NULL)
	{
		strncpy(xkbfile, &kbd[beg - kbd], end - beg);

		beg = end + 1;
		if((end = strrchr(kbd, ')')) != NULL)
		{
			strncpy(xkbmap, &kbd[beg - kbd], end - beg);
			xkbmap[end - beg] = '\0';
		}
	}
	else
	{
		/* The keyboard name is the same as the file name */
		strcpy(xkbfile, kbd);
		strcpy(xkbmap, kbd);
	}

	/* Get path to file relative to freerdp's directory */
	snprintf(xkbfilepath, sizeof(xkbfilepath), "keymaps/%s", xkbfile);
	DEBUG_KBD("Loading keymap %s, first trying %s", kbd, xkbfilepath);

	/*
	 *  Open the file for reading only
	 * It can happen that the same file is opened twice at the same time
	 * in order to load multiple keyboard maps from the same file, but
	 * it does not matter: files can be opened as many times as we want
	 * when it is for reading only.
	 */

	if((fp = fopen(xkbfilepath, "r")) == NULL)
	{
		/* Look first in path given at compile time (install path) */
		snprintf(xkbfilepath, sizeof(xkbfilepath), "%s/%s", KEYMAP_PATH, xkbfile);

		if((fp = fopen(xkbfilepath, "r")) == NULL)
		{
			/* If ran from the source tree, the keymaps will be in the parent directory */
			snprintf(xkbfilepath, sizeof(xkbfilepath), "../keymaps/%s", xkbfile);

			if((fp = fopen(xkbfilepath, "r")) == NULL)
			{
				/* File wasn't found in the source tree, try ~/.freerdp/ folder */
				if((home = getenv("HOME")) == NULL)
					return 0;

				/* Get path to file in ~/.freerdp/ folder */
				snprintf(xkbfilepath, sizeof(xkbfilepath), "%s/.freerdp/keymaps/%s", home, xkbfile);

				if((fp = fopen(xkbfilepath, "r")) == NULL)
				{
					/* Try /usr/share/freerdp folder */
					snprintf(xkbfilepath, sizeof(xkbfilepath), "/usr/share/freerdp/keymaps/%s", xkbfile);

					if((fp = fopen(xkbfilepath, "r")) == NULL)
					{
						/* Try /usr/local/share/freerdp folder */
						snprintf(xkbfilepath, sizeof(xkbfilepath), "/usr/local/share/freerdp/keymaps/%s", xkbfile);

						if((fp = fopen(xkbfilepath, "r")) == NULL)
						{
							/* Error: Could not find keymap */
							DEBUG_KBD("keymaps for %s not found", xkbfile);
							return 0;
						}
					}
				}
			}
		}
	}

	DEBUG_KBD("xkbfilepath: %s", xkbfilepath);

	while(fgets(buffer, sizeof(buffer), fp) != NULL)
	{
		if(buffer[0] == '#')
		{
			continue; /* Skip comments */
		}

		if(kbdFound)
		{
			/* Closing curly bracket and semicolon */
			if((pch = strstr(buffer, "};")) != NULL)
			{
				break;
			}
			else if((pch = strstr(buffer, "VK_")) != NULL)
			{
				/* The end is delimited by the first white space */
				end = strcspn(pch, " \t\n\0") + pch;

				/* We copy the virtual key code name in a string */
				beg = pch;
				strncpy(vkcodeName, beg, end - beg);
				vkcodeName[end - beg] = '\0';

				/* Now we want to extract the virtual key code itself which is in between '<' and '>' */
				if((beg = strchr(pch + 3, '<')) == NULL)
					break;
				else
					beg++;

				if((end = strchr(beg, '>')) == NULL)
					break;

				/* We copy the string representing the number in a string */
				strncpy(keycodeString, beg, end - beg);
				keycodeString[end - beg] = '\0';

				/* Convert the string representing the code to an integer */
				keycode = atoi(keycodeString);

				/* Make sure it is a valid keycode */
				if(keycode < 0 || keycode > 255)
					break;

				/* Load this key mapping in the keyboard mapping */
				for(i = 0; i < sizeof(virtualKeyboard) / sizeof(virtualKey); i++)
				{
					if(strcmp(vkcodeName, virtualKeyboard[i].name) == 0)
					{
						map[keycode] = i;
					}
				}
			}
			else if((pch = strstr(buffer, ": extends")) != NULL)
			{
				/*
				 * This map extends another keymap We extract its name
				 * and we recursively load the keymap we need to include.
				 */

				if((beg = strchr(pch + sizeof(": extends"), '"')) == NULL)
					break;
				beg++;

				if((end = strchr(beg, '"')) == NULL)
					break;

				strncpy(xkbinc, beg, end - beg);
				xkbinc[end - beg] = '\0';

				load_xkb_keyboard(map, xkbinc); /* Load included keymap */
			}
		}
		else if((pch = strstr(buffer, "keyboard")) != NULL)
		{
			/* Keyboard map identifier */
			if((beg = strchr(pch + sizeof("keyboard"), '"')) == NULL)
				break;
			beg++;

			if((end = strchr(beg, '"')) == NULL)
				break;

			pch = beg;
			buffer[end - beg] = '\0';

			/* Does it match our keymap name? */
			if(strncmp(xkbmap, pch, strlen(xkbmap)) == 0)
				kbdFound = 1;
		}
	}

	fclose(fp); /* Don't forget to close file */

	return 1;
}
Esempio n. 2
0
unsigned int detect_keyboard_layout_from_locale()
{
	int dot;
	int i, j, k;
	int underscore;
	char language[4];
	char country[10];

	/* LANG = <language>_<country>.<encoding> */
	char* envLang = getenv("LANG"); /* Get locale from environment variable LANG */

	if (envLang == NULL)
		return 0; /* LANG environment variable was not set */

	underscore = strcspn(envLang, "_");

	if (underscore > 3)
		return 0; /* The language name should not be more than 3 letters long */
	else
	{
		/* Get language code */
		strncpy(language, envLang, underscore);
		language[underscore] = '\0';
	}

	/*
	 * There is always the special case of "C" or "POSIX" as locale name
	 * In this case, use a U.S. keyboard and a U.S. keyboard layout
	 */

	if ((strcmp(language, "C") == 0) || (strcmp(language, "POSIX") == 0))
		return ENGLISH_UNITED_STATES; /* U.S. Keyboard Layout */

	dot = strcspn(envLang, ".");

	/* Get country code */
	if (dot > underscore)
	{
		strncpy(country, &envLang[underscore + 1], dot - underscore - 1);
		country[dot - underscore - 1] = '\0';
	}
	else
		return 0; /* Invalid locale */

	for (i = 0; i < sizeof(locales) / sizeof(locale); i++)
	{
		if ((strcmp(language, locales[i].language) == 0) && (strcmp(country, locales[i].country) == 0))
			break;
	}

	DEBUG_KBD("Found locale : %s_%s", locales[i].language, locales[i].country);

	for (j = 0; j < sizeof(defaultKeyboardLayouts) / sizeof(localeAndKeyboardLayout); j++)
	{
		if (defaultKeyboardLayouts[j].locale == locales[i].code)
		{
			/* Locale found in list of default keyboard layouts */
			for (k = 0; k < 5; k++)
			{
				if (defaultKeyboardLayouts[j].keyboardLayouts[k] == ENGLISH_UNITED_STATES)
				{
					continue; /* Skip, try to get a more localized keyboard layout */
				}
				else if (defaultKeyboardLayouts[j].keyboardLayouts[k] == 0)
				{
					break; /* No more keyboard layouts */
				}
				else
				{
					return defaultKeyboardLayouts[j].keyboardLayouts[k];
				}
			}

			/*
			 * If we skip the ENGLISH_UNITED_STATES keyboard layout but there are no
			 * other possible keyboard layout for the locale, we end up here with k > 1
			 */

			if (k >= 1)
				return ENGLISH_UNITED_STATES;
			else
				return 0;
		}
	}

	return 0; /* Could not detect the current keyboard layout from locale */
}
Esempio n. 3
0
int freerdp_detect_keyboard_layout_from_xkb(DWORD* keyboardLayoutId)
{
	char* pch;
	char* beg;
	char* end;
	FILE* xprop;
	char buffer[1024];
	char* layout = NULL;
	char* variant = NULL;

	/* We start by looking for _XKB_RULES_NAMES_BACKUP which appears to be used by libxklavier */

        xprop = popen("xprop -root _XKB_RULES_NAMES_BACKUP", "r");

	/* Sample output for "Canadian Multilingual Standard"
	 *
	 * _XKB_RULES_NAMES_BACKUP(STRING) = "xorg", "pc105", "ca", "multix", ""
	 * Where "xorg" is the set of rules
	 * "pc105" the keyboard type
	 * "ca" the keyboard layout
	 * "multi" the keyboard layout variant
	 */

	while (fgets(buffer, sizeof(buffer), xprop) != NULL)
	{
		if ((pch = strstr(buffer, "_XKB_RULES_NAMES_BACKUP(STRING) = ")) != NULL)
		{
			/* "rules" */
			pch = strchr(&buffer[34], ','); /* We assume it is xorg */
			pch += 1;

			/* "type" */
			pch = strchr(pch, ',');

			/* "layout" */
			beg = strchr(pch + 1, '"');
			beg += 1;

			end = strchr(beg, '"');
			*end = '\0';

			layout = beg;

			/* "variant" */
			beg = strchr(end + 1, '"');
			beg += 1;

			end = strchr(beg, '"');
			*end = '\0';

			variant = beg;
		}
	}

	pclose(xprop);

	DEBUG_KBD("_XKB_RULES_NAMES_BACKUP layout: %s, variant: %s", layout, variant);
	*keyboardLayoutId = find_keyboard_layout_in_xorg_rules(layout, variant);

	if (*keyboardLayoutId > 0)
		return 0;

	/* Check _XKB_RULES_NAMES if _XKB_RULES_NAMES_BACKUP fails */

	xprop = popen("xprop -root _XKB_RULES_NAMES", "r");

	while (fgets(buffer, sizeof(buffer), xprop) != NULL)
	{
		if ((pch = strstr(buffer, "_XKB_RULES_NAMES(STRING) = ")) != NULL)
		{
			/* "rules" */
			pch = strchr(&buffer[27], ','); // We assume it is xorg
			pch += 1;

			/* "type" */
			pch = strchr(pch, ',');

			/* "layout" */
			beg = strchr(pch + 1, '"');
			beg += 1;

			end = strchr(beg, '"');
			*end = '\0';

			layout = beg;

			/* "variant" */
			beg = strchr(end + 1, '"');
			beg += 1;

			end = strchr(beg, '"');
			*end = '\0';

			variant = beg;
		}
	}

	pclose(xprop);

	DEBUG_KBD("_XKB_RULES_NAMES layout: %s, variant: %s", layout, variant);
	*keyboardLayoutId = find_keyboard_layout_in_xorg_rules(layout, variant);

	if (*keyboardLayoutId > 0)
		return *keyboardLayoutId;

	return 0;
}
Esempio n. 4
0
LRESULT CALLBACK wf_ll_kbd_proc(int nCode, WPARAM wParam, LPARAM lParam)
{
	wfContext* wfc;
	DWORD rdp_scancode;
	rdpInput* input;
	PKBDLLHOOKSTRUCT p;

	DEBUG_KBD("Low-level keyboard hook, hWnd %X nCode %X wParam %X", g_focus_hWnd, nCode, wParam);

	if (g_focus_hWnd && (nCode == HC_ACTION))
	{
		switch (wParam)
		{
			case WM_KEYDOWN:
			case WM_SYSKEYDOWN:
			case WM_KEYUP:
			case WM_SYSKEYUP:
				wfc = (wfContext*) GetWindowLongPtr(g_focus_hWnd, GWLP_USERDATA);
				p = (PKBDLLHOOKSTRUCT) lParam;

				if (!wfc || !p)
					return 1;
				
				input = wfc->instance->input;
				rdp_scancode = MAKE_RDP_SCANCODE((BYTE) p->scanCode, p->flags & LLKHF_EXTENDED);

				DEBUG_KBD("keydown %d scanCode %04X flags %02X vkCode %02X",
					(wParam == WM_KEYDOWN), (BYTE) p->scanCode, p->flags, p->vkCode);

				if (wfc->fs_toggle &&
					((p->vkCode == VK_RETURN) || (p->vkCode == VK_CANCEL)) &&
					(GetAsyncKeyState(VK_CONTROL) & 0x8000) &&
					(GetAsyncKeyState(VK_MENU) & 0x8000)) /* could also use flags & LLKHF_ALTDOWN */
				{
					if (wParam == WM_KEYDOWN)
					{
						wf_toggle_fullscreen(wfc);
						return 1;
					}
				}

				if (rdp_scancode == RDP_SCANCODE_NUMLOCK_EXTENDED)
				{
					/* Windows sends NumLock as extended - rdp doesn't */
					DEBUG_KBD("hack: NumLock (x45) should not be extended");
					rdp_scancode = RDP_SCANCODE_NUMLOCK;
				}
				else if (rdp_scancode == RDP_SCANCODE_NUMLOCK)
				{
					/* Windows sends Pause as if it was a RDP NumLock (handled above).
					 * It must however be sent as a one-shot Ctrl+NumLock */
					if (wParam == WM_KEYDOWN)
					{
						DEBUG_KBD("Pause, sent as Ctrl+NumLock");
						freerdp_input_send_keyboard_event_ex(input, TRUE, RDP_SCANCODE_LCONTROL);
						freerdp_input_send_keyboard_event_ex(input, TRUE, RDP_SCANCODE_NUMLOCK);
						freerdp_input_send_keyboard_event_ex(input, FALSE, RDP_SCANCODE_LCONTROL);
						freerdp_input_send_keyboard_event_ex(input, FALSE, RDP_SCANCODE_NUMLOCK);
					}
					else
					{
						DEBUG_KBD("Pause up");
					}

					return 1;
				}
				else if (rdp_scancode == RDP_SCANCODE_RSHIFT_EXTENDED)
				{
					DEBUG_KBD("right shift (x36) should not be extended");
					rdp_scancode = RDP_SCANCODE_RSHIFT;
				}

				freerdp_input_send_keyboard_event_ex(input, !(p->flags & LLKHF_UP), rdp_scancode);

				if (p->vkCode == VK_CAPITAL)
					DEBUG_KBD("caps lock is processed on client side too to toggle caps lock indicator");
				else
					return 1;

				break;
		}
	}

	return CallNextHookEx(NULL, nCode, wParam, lParam);
}
Esempio n. 5
0
int freerdp_detect_keyboard_layout_from_system_locale(DWORD* keyboardLayoutId)
{
	int i, j;
	char language[4];
	char country[10];
	SYSTEM_LOCALE* locale;

	freerdp_get_system_language_and_country_codes(language, country);

	if ((strcmp(language, "C") == 0) || (strcmp(language, "POSIX") == 0))
	{
		*keyboardLayoutId = ENGLISH_UNITED_STATES; /* U.S. Keyboard Layout */
		return 0;
	}

	locale = freerdp_detect_system_locale();

	if (!locale)
		return -1;

	DEBUG_KBD("Found locale : %s_%s", locale->language, locale->country);

	for (i = 0; i < ARRAYSIZE(LOCALE_KEYBOARD_LAYOUTS_TABLE); i++)
	{
		if (LOCALE_KEYBOARD_LAYOUTS_TABLE[i].locale == locale->code)
		{
			/* Locale found in list of default keyboard layouts */

			for (j = 0; j < 5; j++)
			{
				if (LOCALE_KEYBOARD_LAYOUTS_TABLE[i].keyboardLayouts[j] == ENGLISH_UNITED_STATES)
				{
					continue; /* Skip, try to get a more localized keyboard layout */
				}
				else if (LOCALE_KEYBOARD_LAYOUTS_TABLE[i].keyboardLayouts[j] == 0)
				{
					break; /* No more keyboard layouts */
				}
				else
				{
					*keyboardLayoutId = LOCALE_KEYBOARD_LAYOUTS_TABLE[i].keyboardLayouts[j];
					return 0;
				}
			}

			/*
			 * If we skip the ENGLISH_UNITED_STATES keyboard layout but there are no
			 * other possible keyboard layout for the locale, we end up here with k > 1
			 */

			if (j >= 1)
			{
				*keyboardLayoutId = ENGLISH_UNITED_STATES;
				return 0;
			}
			else
			{
				return -1;
			}
		}
	}

	return -1; /* Could not detect the current keyboard layout from locale */
}
Esempio n. 6
0
void
ensure_remote_modifiers(uint32 ev_time, key_translation tr)
{
	/* If this key is a modifier, do nothing */
	if (is_modifier(tr.scancode))
		return;

	if (!g_numlock_sync)
	{
		/* NumLock */
		if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)
		    != MASK_HAS_BITS(remote_modifier_state, MapNumLockMask))
		{
			/* The remote modifier state is not correct */
			uint16 new_remote_state;

			if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask))
			{
				DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n"));
				new_remote_state = KBD_FLAG_NUMLOCK;
				remote_modifier_state = MapNumLockMask;
			}
			else
			{
				DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n"));
				new_remote_state = 0;
				remote_modifier_state = 0;
			}

			rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0);
		}
	}


	/* Shift. Left shift and right shift are treated as equal; either is fine. */
	if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)
	    != MASK_HAS_BITS(remote_modifier_state, MapShiftMask))
	{
		/* The remote modifier state is not correct */
		if (MASK_HAS_BITS(tr.modifiers, MapLeftShiftMask))
		{
			/* Needs left shift. Send down. */
			rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT);
		}
		else if (MASK_HAS_BITS(tr.modifiers, MapRightShiftMask))
		{
			/* Needs right shift. Send down. */
			rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RSHIFT);
		}
		else
		{
			/* Should not use this modifier. Send up for shift currently pressed. */
			if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask))
				/* Left shift is down */
				rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT);
			else
				/* Right shift is down */
				rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT);
		}
	}

	/* AltGr */
	if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask)
	    != MASK_HAS_BITS(remote_modifier_state, MapAltGrMask))
	{
		/* The remote modifier state is not correct */
		if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask))
		{
			/* Needs this modifier. Send down. */
			rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RALT);
		}
		else
		{
			/* Should not use this modifier. Send up. */
			rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT);
		}
	}


}
Esempio n. 7
0
LRESULT CALLBACK wf_event_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	LONG ptr;
	wfContext* wfc;
	int x, y, w, h;
	PAINTSTRUCT ps;
	rdpInput* input;
	BOOL processed;
	RECT windowRect;
	RECT clientRect;
	MINMAXINFO* minmax;
	SCROLLINFO si;

	processed = TRUE;
	ptr = GetWindowLongPtr(hWnd, GWLP_USERDATA);
	wfc = (wfContext*) ptr;

	if (wfc != NULL)
	{
		input = wfc->instance->input;

		switch (Msg)
		{
			case WM_MOVE:
				if (!wfc->disablewindowtracking)
				{
					int x = (int)(short) LOWORD(lParam);
					int y = (int)(short) HIWORD(lParam);
					wfc->client_x = x;
					wfc->client_y = y;
				}
				break;

			case WM_GETMINMAXINFO:
				if (wfc->instance->settings->SmartSizing)
				{
					processed = FALSE;
				}
				else
				{
					// Set maximum window size for resizing

					minmax = (MINMAXINFO*) lParam;
					wf_update_canvas_diff(wfc);

					if (!wfc->fullscreen)
					{
						// add window decoration
						minmax->ptMaxTrackSize.x = wfc->width + wfc->diff.x;
						minmax->ptMaxTrackSize.y = wfc->height + wfc->diff.y;
					}
				}
				break;

			case WM_SIZING:
				wf_sizing(wfc, lParam, wParam);
				break;
			
			case WM_SIZE:
				GetWindowRect(wfc->hwnd, &windowRect);
				
				if (!wfc->fullscreen)
				{
					wfc->client_width = LOWORD(lParam);
					wfc->client_height = HIWORD(lParam);
					wfc->client_x = windowRect.left;
					wfc->client_y = windowRect.top;
				}
				
				wf_size_scrollbars(wfc, LOWORD(lParam), HIWORD(lParam));

				// Workaround: when the window is maximized, the call to "ShowScrollBars" returns TRUE but has no effect.
				if (wParam == SIZE_MAXIMIZED && !wfc->fullscreen)
					SetWindowPos(wfc->hwnd, HWND_TOP, 0, 0, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, SWP_NOMOVE | SWP_FRAMECHANGED);

				break;

			case WM_EXITSIZEMOVE:
				wf_size_scrollbars(wfc, wfc->client_width, wfc->client_height);
				break;

			case WM_ERASEBKGND:
				/* Say we handled it - prevents flickering */
				return (LRESULT) 1;

			case WM_PAINT:
				hdc = BeginPaint(hWnd, &ps);

				x = ps.rcPaint.left;
				y = ps.rcPaint.top;
				w = ps.rcPaint.right - ps.rcPaint.left + 1;
				h = ps.rcPaint.bottom - ps.rcPaint.top + 1;

				wf_scale_blt(wfc, hdc, x, y, w, h, wfc->primary->hdc, x - wfc->offset_x + wfc->xCurrentScroll, y - wfc->offset_y + wfc->yCurrentScroll, SRCCOPY);

				EndPaint(hWnd, &ps);
				break;

			case WM_LBUTTONDOWN:
				wf_scale_mouse_event(wfc, input,PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1, X_POS(lParam) - wfc->offset_x, Y_POS(lParam) - wfc->offset_y);
				break;

			case WM_LBUTTONUP:
				wf_scale_mouse_event(wfc, input, PTR_FLAGS_BUTTON1, X_POS(lParam) - wfc->offset_x, Y_POS(lParam) - wfc->offset_y);
				break;

			case WM_RBUTTONDOWN:
				wf_scale_mouse_event(wfc, input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2, X_POS(lParam) - wfc->offset_x, Y_POS(lParam) - wfc->offset_y);
				break;

			case WM_RBUTTONUP:
				wf_scale_mouse_event(wfc, input, PTR_FLAGS_BUTTON2, X_POS(lParam) - wfc->offset_x, Y_POS(lParam) - wfc->offset_y);
				break;

			case WM_MOUSEMOVE:
				wf_scale_mouse_event(wfc, input, PTR_FLAGS_MOVE, X_POS(lParam) - wfc->offset_x, Y_POS(lParam) - wfc->offset_y);
				break;

			case WM_MOUSEWHEEL:
				wf_event_process_WM_MOUSEWHEEL(wfc, hWnd, Msg, wParam, lParam);
				break;

			case WM_SETCURSOR:
				if (LOWORD(lParam) == HTCLIENT)
					SetCursor(wfc->cursor);
				else
					DefWindowProc(hWnd, Msg, wParam, lParam);
				break;

			case WM_HSCROLL:
				{
					int xDelta;     // xDelta = new_pos - current_pos  
					int xNewPos;    // new position 
					int yDelta = 0; 
 
					switch (LOWORD(wParam)) 
					{ 
						// User clicked the scroll bar shaft left of the scroll box. 
						case SB_PAGEUP: 
							xNewPos = wfc->xCurrentScroll - 50;
							break; 
 
						// User clicked the scroll bar shaft right of the scroll box. 
						case SB_PAGEDOWN: 
							xNewPos = wfc->xCurrentScroll + 50;
							break; 
 
						// User clicked the left arrow. 
						case SB_LINEUP: 
							xNewPos = wfc->xCurrentScroll - 5;
							break; 
 
						// User clicked the right arrow. 
						case SB_LINEDOWN: 
							xNewPos = wfc->xCurrentScroll + 5;
							break; 
 
						// User dragged the scroll box. 
						case SB_THUMBPOSITION: 
							xNewPos = HIWORD(wParam); 

						// user is dragging the scrollbar
						case SB_THUMBTRACK :
							xNewPos = HIWORD(wParam); 
							break; 
 
						default: 
							xNewPos = wfc->xCurrentScroll;
					} 
 
					// New position must be between 0 and the screen width. 
					xNewPos = MAX(0, xNewPos); 
					xNewPos = MIN(wfc->xMaxScroll, xNewPos);
 
					// If the current position does not change, do not scroll.
					if (xNewPos == wfc->xCurrentScroll)
						break; 
 
					// Determine the amount scrolled (in pixels). 
					xDelta = xNewPos - wfc->xCurrentScroll;
 
					// Reset the current scroll position. 
					wfc->xCurrentScroll = xNewPos;
 
					// Scroll the window. (The system repaints most of the 
					// client area when ScrollWindowEx is called; however, it is 
					// necessary to call UpdateWindow in order to repaint the 
					// rectangle of pixels that were invalidated.) 
					ScrollWindowEx(wfc->hwnd, -xDelta, -yDelta, (CONST RECT *) NULL,
						(CONST RECT *) NULL, (HRGN) NULL, (PRECT) NULL, 
						SW_INVALIDATE); 
					UpdateWindow(wfc->hwnd);
 
					// Reset the scroll bar. 
					si.cbSize = sizeof(si); 
					si.fMask  = SIF_POS; 
					si.nPos   = wfc->xCurrentScroll;
					SetScrollInfo(wfc->hwnd, SB_HORZ, &si, TRUE);
				}
				break;

				case WM_VSCROLL: 
				{ 
					int xDelta = 0; 
					int yDelta;     // yDelta = new_pos - current_pos 
					int yNewPos;    // new position 
 
					switch (LOWORD(wParam)) 
					{ 
						// User clicked the scroll bar shaft above the scroll box. 
						case SB_PAGEUP: 
							yNewPos = wfc->yCurrentScroll - 50;
							break; 
 
						// User clicked the scroll bar shaft below the scroll box. 
						case SB_PAGEDOWN: 
							yNewPos = wfc->yCurrentScroll + 50;
							break; 
 
						// User clicked the top arrow. 
						case SB_LINEUP: 
							yNewPos = wfc->yCurrentScroll - 5;
							break; 
 
						// User clicked the bottom arrow. 
						case SB_LINEDOWN: 
							yNewPos = wfc->yCurrentScroll + 5;
							break; 
 
						// User dragged the scroll box. 
						case SB_THUMBPOSITION: 
							yNewPos = HIWORD(wParam); 
							break; 
 
						// user is dragging the scrollbar
						case SB_THUMBTRACK :
							yNewPos = HIWORD(wParam); 
							break; 

						default: 
							yNewPos = wfc->yCurrentScroll;
					} 
 
					// New position must be between 0 and the screen height. 
					yNewPos = MAX(0, yNewPos); 
					yNewPos = MIN(wfc->yMaxScroll, yNewPos);
 
					// If the current position does not change, do not scroll.
					if (yNewPos == wfc->yCurrentScroll)
						break; 
 
					// Determine the amount scrolled (in pixels). 
					yDelta = yNewPos - wfc->yCurrentScroll;
 
					// Reset the current scroll position. 
					wfc->yCurrentScroll = yNewPos;
 
					// Scroll the window. (The system repaints most of the 
					// client area when ScrollWindowEx is called; however, it is 
					// necessary to call UpdateWindow in order to repaint the 
					// rectangle of pixels that were invalidated.) 
					ScrollWindowEx(wfc->hwnd, -xDelta, -yDelta, (CONST RECT *) NULL,
						(CONST RECT *) NULL, (HRGN) NULL, (PRECT) NULL, 
						SW_INVALIDATE); 
					UpdateWindow(wfc->hwnd);
 
					// Reset the scroll bar. 
					si.cbSize = sizeof(si); 
					si.fMask  = SIF_POS; 
					si.nPos   = wfc->yCurrentScroll;
					SetScrollInfo(wfc->hwnd, SB_VERT, &si, TRUE);
				}
				break; 

				case WM_SYSCOMMAND:
				{
					if (wParam == SYSCOMMAND_ID_SMARTSIZING)
					{
						HMENU hMenu = GetSystemMenu(wfc->hwnd, FALSE);
						freerdp_set_param_bool(wfc->instance->settings, FreeRDP_SmartSizing, !wfc->instance->settings->SmartSizing);
						CheckMenuItem(hMenu, SYSCOMMAND_ID_SMARTSIZING, wfc->instance->settings->SmartSizing ? MF_CHECKED : MF_UNCHECKED);

					}
					else
					{
						processed = FALSE;
					}
				}
				break;

			default:
				processed = FALSE;
				break;
		}
	}
	else
	{
		processed = FALSE;
	}

	if (processed)
		return 0;

	switch (Msg)
	{
		case WM_DESTROY:
			PostQuitMessage(WM_QUIT);
			break;

		case WM_SETCURSOR:
			if (LOWORD(lParam) == HTCLIENT)
				SetCursor(wfc->hDefaultCursor);
			else
				DefWindowProc(hWnd, Msg, wParam, lParam);
			break;

		case WM_SETFOCUS:
			DEBUG_KBD("getting focus %X", hWnd);
			g_focus_hWnd = hWnd;
			break;

		case WM_KILLFOCUS:
			if (g_focus_hWnd == hWnd && wfc && !wfc->fullscreen)
			{
				DEBUG_KBD("loosing focus %X", hWnd);
				g_focus_hWnd = NULL;
			}
			break;

		case WM_ACTIVATE:
			{
				int activate = (int)(short) LOWORD(wParam);
				if (activate != WA_INACTIVE)
				{
					g_focus_hWnd = hWnd;
				}
				else
				{
					g_focus_hWnd = NULL;
				}
			}

		default:
			return DefWindowProc(hWnd, Msg, wParam, lParam);
			break;
	}

	return 0;
}
Esempio n. 8
0
static RD_BOOL
xkeymap_read(char *mapname)
{
	FILE *fp;
	char line[KEYMAP_MAX_LINE_LENGTH];
	unsigned int line_num = 0;
	unsigned int line_length = 0;
	char *keyname, *p;
	char *line_rest;
	uint8 scancode;
	uint16 modifiers;

	fp = xkeymap_open(mapname);
	if (fp == NULL)
	{
		error("Failed to open keymap %s\n", mapname);
		return False;
	}

	/* FIXME: More tolerant on white space */
	while (fgets(line, sizeof(line), fp) != NULL)
	{
		line_num++;

		/* Replace the \n with \0 */
		p = strchr(line, '\n');
		if (p != NULL)
			*p = 0;

		line_length = strlen(line);

		/* Completely empty line */
		if (strspn(line, " \t\n\r\f\v") == line_length)
		{
			continue;
		}

		/* Include */
		if (str_startswith(line, "include "))
		{
			if (!xkeymap_read(line + sizeof("include ") - 1))
				return False;
			continue;
		}

		/* map */
		if (str_startswith(line, "map "))
		{
			g_keylayout = strtoul(line + sizeof("map ") - 1, NULL, 16);
			DEBUG_KBD(("Keylayout 0x%x\n", g_keylayout));
			continue;
		}

		/* compose */
		if (str_startswith(line, "enable_compose"))
		{
			DEBUG_KBD(("Enabling compose handling\n"));
			g_enable_compose = True;
			continue;
		}

		/* sequence */
		if (str_startswith(line, "sequence"))
		{
			add_sequence(line + sizeof("sequence") - 1, mapname);
			continue;
		}

		/* keyboard_type */
		if (str_startswith(line, "keyboard_type "))
		{
			g_keyboard_type = strtol(line + sizeof("keyboard_type ") - 1, NULL, 16);
			DEBUG_KBD(("keyboard_type 0x%x\n", g_keyboard_type));
			continue;
		}

		/* keyboard_subtype */
		if (str_startswith(line, "keyboard_subtype "))
		{
			g_keyboard_subtype =
				strtol(line + sizeof("keyboard_subtype ") - 1, NULL, 16);
			DEBUG_KBD(("keyboard_subtype 0x%x\n", g_keyboard_subtype));
			continue;
		}

		/* keyboard_functionkeys */
		if (str_startswith(line, "keyboard_functionkeys "))
		{
			g_keyboard_functionkeys =
				strtol(line + sizeof("keyboard_functionkeys ") - 1, NULL, 16);
			DEBUG_KBD(("keyboard_functionkeys 0x%x\n", g_keyboard_functionkeys));
			continue;
		}

		/* Comment */
		if (line[0] == '#')
		{
			continue;
		}

		/* Normal line */
		keyname = line;
		p = strchr(line, ' ');
		if (p == NULL)
		{
			error("Bad line %d in keymap %s\n", line_num, mapname);
			continue;
		}
		else
		{
			*p = 0;
		}

		/* scancode */
		p++;
		scancode = strtol(p, &line_rest, 16);

		/* flags */
		/* FIXME: Should allow case-insensitive flag names. 
		   Fix by using lex+yacc... */
		modifiers = 0;
		if (strstr(line_rest, "altgr"))
		{
			MASK_ADD_BITS(modifiers, MapAltGrMask);
		}

		if (strstr(line_rest, "shift"))
		{
			MASK_ADD_BITS(modifiers, MapLeftShiftMask);
		}

		if (strstr(line_rest, "numlock"))
		{
			MASK_ADD_BITS(modifiers, MapNumLockMask);
		}

		if (strstr(line_rest, "localstate"))
		{
			MASK_ADD_BITS(modifiers, MapLocalStateMask);
		}

		if (strstr(line_rest, "inhibit"))
		{
			MASK_ADD_BITS(modifiers, MapInhibitMask);
		}

		add_to_keymap(keyname, scancode, modifiers, mapname);

		if (strstr(line_rest, "addupper"))
		{
			/* Automatically add uppercase key, with same modifiers 
			   plus shift */
			for (p = keyname; *p; p++)
				*p = toupper((int) *p);
			MASK_ADD_BITS(modifiers, MapLeftShiftMask);
			add_to_keymap(keyname, scancode, modifiers, mapname);
		}
	}

	fclose(fp);
	return True;
}
Esempio n. 9
0
key_translation
xkeymap_translate_key(uint32 keysym, unsigned int keycode, unsigned int state)
{
	key_translation tr = { 0, 0, 0, 0 };
	key_translation *ptr;

	ptr = keymap[keysym & KEYMAP_MASK];
	if (ptr)
	{
		tr = *ptr;
		if (tr.seq_keysym == 0)	/* Normal scancode translation */
		{
			if (MASK_HAS_BITS(tr.modifiers, MapInhibitMask))
			{
				DEBUG_KBD(("Inhibiting key\n"));
				tr.scancode = 0;
				return tr;
			}

			if (MASK_HAS_BITS(tr.modifiers, MapLocalStateMask))
			{
				/* The modifiers to send for this key should be obtained
				   from the local state. Currently, only shift is implemented. */
				if (MASK_HAS_BITS(state, ShiftMask))
				{
					tr.modifiers = MapLeftShiftMask;
				}
			}

			/* Windows interprets CapsLock+Ctrl+key
			   differently from Shift+Ctrl+key. Since we
			   are simulating CapsLock with Shifts, things
			   like Ctrl+f with CapsLock on breaks. To
			   solve this, we are releasing Shift if Ctrl
			   is on, but only if Shift isn't physically pressed. */
			if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)
			    && MASK_HAS_BITS(remote_modifier_state, MapCtrlMask)
			    && !MASK_HAS_BITS(state, ShiftMask))
			{
				DEBUG_KBD(("Non-physical Shift + Ctrl pressed, releasing Shift\n"));
				MASK_REMOVE_BITS(tr.modifiers, MapShiftMask);
			}

			DEBUG_KBD(("Found scancode translation, scancode=0x%x, modifiers=0x%x\n",
				   tr.scancode, tr.modifiers));
		}
	}
	else
	{
		if (keymap_loaded)
			warning("No translation for (keysym 0x%lx, %s)\n", keysym,
				get_ksname(keysym));

		/* not in keymap, try to interpret the raw scancode */
		if (((int) keycode >= min_keycode) && (keycode <= 0x60))
		{
			tr.scancode = keycode - min_keycode;

			/* The modifiers to send for this key should be
			   obtained from the local state. Currently, only
			   shift is implemented. */
			if (MASK_HAS_BITS(state, ShiftMask))
			{
				tr.modifiers = MapLeftShiftMask;
			}

			DEBUG_KBD(("Sending guessed scancode 0x%x\n", tr.scancode));
		}
		else
		{
			DEBUG_KBD(("No good guess for keycode 0x%x found\n", keycode));
		}
	}

	return tr;
}
Esempio n. 10
0
LRESULT CALLBACK wf_event_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	LONG ptr;
	wfInfo* wfi;
	int x, y, w, h;
	PAINTSTRUCT ps;
	rdpInput* input;
	boolean processed;

	processed = true;
	ptr = GetWindowLongPtr(hWnd, GWLP_USERDATA);
	wfi = (wfInfo*) ptr;

	if (wfi != NULL)
	{
		input = wfi->instance->input;

		switch (Msg)
		{
			case WM_PAINT:
				hdc = BeginPaint(hWnd, &ps);
				
				x = ps.rcPaint.left;
				y = ps.rcPaint.top;
				w = ps.rcPaint.right - ps.rcPaint.left + 1;
				h = ps.rcPaint.bottom - ps.rcPaint.top + 1;

				//printf("WM_PAINT: x:%d y:%d w:%d h:%d\n", x, y, w, h);

				BitBlt(hdc, x, y, w, h, wfi->primary->hdc, x, y, SRCCOPY);

				EndPaint(hWnd, &ps);
				break;

			case WM_LBUTTONDOWN:
				input->MouseEvent(input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1, X_POS(lParam), Y_POS(lParam));
				break;

			case WM_LBUTTONUP:
				input->MouseEvent(input, PTR_FLAGS_BUTTON1, X_POS(lParam), Y_POS(lParam));
				break;

			case WM_RBUTTONDOWN:
				input->MouseEvent(input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2, X_POS(lParam), Y_POS(lParam));
				break;

			case WM_RBUTTONUP:
				input->MouseEvent(input, PTR_FLAGS_BUTTON2, X_POS(lParam), Y_POS(lParam));
				break;

			case WM_MOUSEMOVE:
				input->MouseEvent(input, PTR_FLAGS_MOVE, X_POS(lParam), Y_POS(lParam));
				break;

			case WM_SETCURSOR:
				SetCursor(wfi->cursor);
				break;

			default:
				processed = false;
				break;
		}
	}
	else
	{
		processed = false;
	}

	if (processed)
		return 0;

	switch (Msg)
	{
		case WM_DESTROY:
			PostQuitMessage(WM_QUIT);
			break;

		case WM_SETCURSOR:
			SetCursor(g_default_cursor);
			break;

		case WM_SETFOCUS:
			DEBUG_KBD("getting focus %X", hWnd);
			g_focus_hWnd = hWnd;
			break;

		case WM_KILLFOCUS:
			DEBUG_KBD("loosing focus %X", hWnd);
			if (g_focus_hWnd == hWnd)
				g_focus_hWnd = NULL;
			break;

		default:
			return DefWindowProc(hWnd, Msg, wParam, lParam);
			break;
	}

	return 0;
}
Esempio n. 11
0
static BOOL
xkeymap_read(char *mapname)
{
	FILE *fp;
	char line[KEYMAP_MAX_LINE_LENGTH];
	char path[PATH_MAX], inplace_path[PATH_MAX];
	unsigned int line_num = 0;
	unsigned int line_length = 0;
	char *keyname, *p;
	char *line_rest;
	uint8 scancode;
	uint16 modifiers;


	strcpy(path, KEYMAP_PATH);
	strncat(path, mapname, sizeof(path) - sizeof(KEYMAP_PATH));

	fp = fopen(path, "r");
	if (fp == NULL)
	{
		/* in case we are running from the source tree */
		strcpy(inplace_path, "keymaps/");
		strncat(inplace_path, mapname, sizeof(inplace_path) - sizeof("keymaps/"));

		fp = fopen(inplace_path, "r");
		if (fp == NULL)
		{
			error("Failed to open keymap %s\n", path);
			return False;
		}
	}

	/* FIXME: More tolerant on white space */
	while (fgets(line, sizeof(line), fp) != NULL)
	{
		line_num++;

		/* Replace the \n with \0 */
		p = strchr(line, '\n');
		if (p != NULL)
			*p = 0;

		line_length = strlen(line);

		/* Completely empty line */
		if (strspn(line, " \t\n\r\f\v") == line_length)
		{
			continue;
		}

		/* Include */
		if (strncmp(line, "include ", 8) == 0)
		{
			if (!xkeymap_read(line + 8))
				return False;
			continue;
		}

		/* map */
		if (strncmp(line, "map ", 4) == 0)
		{
			keylayout = strtol(line + 4, NULL, 16);
			DEBUG_KBD(("Keylayout 0x%x\n", keylayout));
			continue;
		}

		/* compose */
		if (strncmp(line, "enable_compose", 15) == 0)
		{
			DEBUG_KBD(("Enabling compose handling\n"));
			enable_compose = True;
			continue;
		}

		/* Comment */
		if (line[0] == '#')
		{
			continue;
		}

		/* Normal line */
		keyname = line;
		p = strchr(line, ' ');
		if (p == NULL)
		{
			error("Bad line %d in keymap %s\n", line_num, mapname);
			continue;
		}
		else
		{
			*p = 0;
		}

		/* scancode */
		p++;
		scancode = strtol(p, &line_rest, 16);

		/* flags */
		/* FIXME: Should allow case-insensitive flag names. 
		   Fix by using lex+yacc... */
		modifiers = 0;
		if (strstr(line_rest, "altgr"))
		{
			MASK_ADD_BITS(modifiers, MapAltGrMask);
		}

		if (strstr(line_rest, "shift"))
		{
			MASK_ADD_BITS(modifiers, MapLeftShiftMask);
		}

		if (strstr(line_rest, "numlock"))
		{
			MASK_ADD_BITS(modifiers, MapNumLockMask);
		}

		if (strstr(line_rest, "localstate"))
		{
			MASK_ADD_BITS(modifiers, MapLocalStateMask);
		}

		if (strstr(line_rest, "inhibit"))
		{
			MASK_ADD_BITS(modifiers, MapInhibitMask);
		}

		add_to_keymap(keyname, scancode, modifiers, mapname);

		if (strstr(line_rest, "addupper"))
		{
			/* Automatically add uppercase key, with same modifiers 
			   plus shift */
			for (p = keyname; *p; p++)
				*p = toupper((int)*p);
			MASK_ADD_BITS(modifiers, MapLeftShiftMask);
			add_to_keymap(keyname, scancode, modifiers, mapname);
		}
	}

	fclose(fp);
	return True;
}
Esempio n. 12
0
uint32 freerdp_keyboard_init_x11(uint32 keyboardLayoutId)
{
	char* keymap;
	uint32 vkcode;
	uint32 keycode;
	uint32 scancode;
	boolean extended;
	char* xkb_layout;
	char* xkb_variant;
	uint32 keycode_to_vkcode[256];

	memset(keycode_to_vkcode, 0, sizeof(keycode_to_vkcode));
	memset(X11_KEYCODE_TO_RDP_SCANCODE, 0, sizeof(X11_KEYCODE_TO_RDP_SCANCODE));
	memset(RDP_SCANCODE_TO_X11_KEYCODE, 0, sizeof(RDP_SCANCODE_TO_X11_KEYCODE));

	if (keyboardLayoutId == 0)
	{
		keyboardLayoutId = freerdp_detect_keyboard_layout_from_system_locale();
		DEBUG_KBD("using keyboard layout: %X", keyboardLayoutId);
	}

	if (keyboardLayoutId == 0)
	{
		keyboardLayoutId = 0x0409;
		DEBUG_KBD("using default keyboard layout: %X", keyboardLayoutId);
	}

#ifdef __APPLE__
	/* Apple X11 breaks XKB detection */
	freerdp_keyboard_load_map(keycode_to_vkcode, "macosx(macosx)");
#else
	if (keyboardLayoutId == 0)
		keyboardLayoutId = freerdp_detect_keyboard_layout_from_xkb(&xkb_layout, &xkb_variant);

	keymap = freerdp_detect_keymap_from_xkb();

	if (keymap != NULL)
		freerdp_keyboard_load_maps(keycode_to_vkcode, keymap);
#endif

	for (keycode = 0; keycode < 256; keycode++)
	{
		vkcode = keycode_to_vkcode[keycode];

		if (!(vkcode > 0 && vkcode < 256))
			continue;

		scancode = VIRTUAL_KEY_CODE_TO_RDP_SCANCODE_TABLE[vkcode];
		extended = VIRTUAL_KEY_CODE_TO_DEFAULT_RDP_SCANCODE_TABLE[vkcode].extended;

		X11_KEYCODE_TO_RDP_SCANCODE[keycode].code = scancode;
		X11_KEYCODE_TO_RDP_SCANCODE[keycode].extended = extended;

		if (extended)
			RDP_SCANCODE_TO_X11_KEYCODE[scancode][1] = keycode;
		else
			RDP_SCANCODE_TO_X11_KEYCODE[scancode][0] = keycode;
	}

	return keyboardLayoutId;
}
Esempio n. 13
0
/* Handle special key combinations */
RD_BOOL
handle_special_keys(uint32 keysym, unsigned int state, uint32 ev_time, RD_BOOL pressed)
{
	DEBUG_KBD(("handle_special_keys (keysym 0x%x, %s state 0x%x, pressed %d)\n",
		   keysym, get_ksname(keysym), state, pressed));

	DEBUG_KBD(("Control_L %d, Control_R %d, Alt_L %d, Alt_R %d\n",
		   get_key_state(state, XK_Control_L),
		   get_key_state(state, XK_Control_R),
		   get_key_state(state, XK_Alt_L),
		   get_key_state(state, XK_Alt_R)));

	if (keysym == XK_Alt_L || keysym == XK_Alt_R
	    || keysym == XK_Control_L || keysym == XK_Control_R) {
		int new_state = state;

		if (pressed)
			new_state |= get_keysym_mask(keysym);
		else
			new_state &= ~get_keysym_mask(keysym);

		new_state &= ~get_keysym_mask(XK_Num_Lock);

		if (pressed) {
			if ((new_state & (get_keysym_mask(XK_Alt_L)
					  | get_keysym_mask(XK_Alt_R))) &&
			    (new_state & (get_keysym_mask(XK_Control_L)
					  | get_keysym_mask(XK_Control_R)))) {
				ctrl_alt_pressed = True;
				DEBUG_KBD(("Ctrl-Alt Pressed\n"));
			}
		} else {
			if (ctrl_alt_pressed && !new_state) {
				DEBUG_KBD(("Ctrl-Alt Released\n"));
				if (g_ungrab_on_ctrlalt)
					xwin_ungrab_keyboard();
			}
		}
	} else if (pressed) {
		ctrl_alt_pressed = False;
		if (!get_keysym_mask(keysym))
			xwin_grab_keyboard();
	}

	switch (keysym)
	{
		case XK_Return:
			if ((get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R))
			    && (get_key_state(state, XK_Control_L)
				|| get_key_state(state, XK_Control_R)))
			{
				/* Ctrl-Alt-Enter: toggle full screen */
				if (pressed)
					xwin_toggle_fullscreen();
				return True;
			}
			break;

		case XK_Break:
			/* Send Break sequence E0 46 E0 C6 */
			if (pressed)
			{
				rdp_send_scancode(ev_time, RDP_KEYPRESS,
						  (SCANCODE_EXTENDED | 0x46));
				rdp_send_scancode(ev_time, RDP_KEYPRESS,
						  (SCANCODE_EXTENDED | 0xc6));
			}
			/* No release sequence */
			return True;
			break;

		case XK_Pause:
			/* According to MS Keyboard Scan Code
			   Specification, pressing Pause should result
			   in E1 1D 45 E1 9D C5. I'm not exactly sure
			   of how this is supposed to be sent via
			   RDP. The code below seems to work, but with
			   the side effect that Left Ctrl stays
			   down. Therefore, we release it when Pause
			   is released. */
			if (pressed)
			{
				rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0);
				rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x1d, 0);
				rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x45, 0);
				rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0);
				rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x9d, 0);
				rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xc5, 0);
			}
			else
			{
				/* Release Left Ctrl */
				rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYRELEASE,
					       0x1d, 0);
			}
			return True;
			break;

		case XK_Meta_L:	/* Windows keys */
		case XK_Super_L:
		case XK_Hyper_L:
			send_winkey(ev_time, pressed, True);
			return True;
			break;

		case XK_Meta_R:
		case XK_Super_R:
		case XK_Hyper_R:
			send_winkey(ev_time, pressed, False);
			return True;
			break;

		case XK_space:
			/* Prevent access to the Windows system menu in single app mode */
			if (g_win_button_size
			    && (get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R)))
				return True;
			break;

		case XK_Num_Lock:
			/* Synchronize on key release */
			if (g_numlock_sync && !pressed)
				rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0,
					       ui_get_numlock_state(read_keyboard_state()), 0);

			/* Inhibit */
			return True;
			break;
		case XK_Overlay1_Enable:
			/* Toggle SeamlessRDP */
			if (pressed)
				ui_seamless_toggle();
			break;

	}
	return False;
}
Esempio n. 14
0
static void
add_sequence(char *rest, char *mapname)
{
	KeySym keysym;
	KeySym seq_keysym;
	key_translation_entry *entry;
	key_translation *tr, **prev_next;
	size_t chars;
	char keyname[KEYMAP_MAX_LINE_LENGTH];

	/* Skip over whitespace after the sequence keyword */
	chars = strspn(rest, " \t");
	rest += chars;

	/* Fetch the keysym name */
	chars = strcspn(rest, " \t\0");
	STRNCPY(keyname, rest, chars + 1);
	rest += chars;

	keysym = XStringToKeysym(keyname);
	if (keysym == NoSymbol)
	{
		DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring line)\n", keyname, mapname));
		return;
	}

	DEBUG_KBD(("Adding sequence for keysym (0x%lx, %s) -> ", keysym, keyname));

	entry = new_key_translation_entry(keysym);
	prev_next = &(entry->tr);

	while (*rest)
	{
		/* Skip whitespace */
		chars = strspn(rest, " \t");
		rest += chars;

		/* Fetch the keysym name */
		chars = strcspn(rest, " \t\0");
		STRNCPY(keyname, rest, chars + 1);
		rest += chars;

		/* Handle trailing whitespace */
		if (*keyname == 0)
			break;

		seq_keysym = XStringToKeysym(keyname);
		if (seq_keysym == NoSymbol)
		{
			DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring line)\n", keyname,
				   mapname));
			delete_key_translation_entry(keysym);
			return;
		}

		/* Allocate space for key_translation structure */
		tr = (key_translation *) xmalloc(sizeof(key_translation));
		memset(tr, 0, sizeof(key_translation));

		/* Do this straight away so the key_translation won't get orphaned on error */
		if (!entry->tr)
			entry->tr = tr;

		*prev_next = tr;
		prev_next = &tr->next;
		tr->seq_keysym = seq_keysym;

		DEBUG_KBD(("0x%x, ", (unsigned int) seq_keysym));
	}
	DEBUG_KBD(("\n"));
}