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

📄 xwin.c

📁 LInux 下的远程桌面工具 Rdesktop
💻 C
📖 第 1 页 / 共 5 页
字号:
	struct timeval now;	struct timeval nextsecond;	RD_BOOL got = False;	context.window = wnd;	context.serial = serial;	gettimeofday(&nextsecond, NULL);	nextsecond.tv_sec += 1;	do	{		if (XCheckIfEvent(g_display, &xevent, sw_configurenotify_p, (XPointer) & context))		{			got = True;			break;		}		usleep(100000);		gettimeofday(&now, NULL);	}	while (timercmp(&now, &nextsecond, <));	if (!got)	{		warning("Broken Window Manager: Timeout while waiting for ConfigureNotify\n");	}}/* Get the toplevel window, in case of reparenting */static Windowsw_get_toplevel(Window wnd){	Window root, parent;	Window *child_list;	unsigned int num_children;	while (1)	{		XQueryTree(g_display, wnd, &root, &parent, &child_list, &num_children);		if (root == parent)		{			break;		}		else if (!parent)		{			warning("Internal error: sw_get_toplevel called with root window\n");		}		wnd = parent;	}	return wnd;}/* Check if wnd is already behind a window wrt stacking order */static RD_BOOLsw_window_is_behind(Window wnd, Window behind){	Window dummy1, dummy2;	Window *child_list;	unsigned int num_children;	unsigned int i;	RD_BOOL found_behind = False;	RD_BOOL found_wnd = False;	wnd = sw_get_toplevel(wnd);	behind = sw_get_toplevel(behind);	XQueryTree(g_display, RootWindowOfScreen(g_screen), &dummy1, &dummy2, &child_list,		   &num_children);	for (i = num_children - 1; i >= 0; i--)	{		if (child_list[i] == behind)		{			found_behind = True;		}		else if (child_list[i] == wnd)		{			found_wnd = True;			break;		}	}	if (child_list)		XFree(child_list);	if (!found_wnd)	{		warning("sw_window_is_behind: Unable to find window 0x%lx\n", wnd);		if (!found_behind)		{			warning("sw_window_is_behind: Unable to find behind window 0x%lx\n",				behind);		}	}	return found_behind;}/* Test if the window manager correctly handles window restacking. In   particular, we are testing if it's possible to place a window   between two other windows. Many WMs such as Metacity can only stack   windows on the top or bottom. The window creation should mostly   match ui_seamless_create_window. */static voidseamless_restack_test(){	/* The goal is to have the middle window between top and	   bottom.  The middle window is initially at the top,	   though. */	Window wnds[3];		/* top, middle and bottom */	int i;	XEvent xevent;	XWindowChanges values;	unsigned long restack_serial;	for (i = 0; i < 3; i++)	{		char name[64];		wnds[i] =			XCreateSimpleWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, 20, 20,					    0, 0, 0);		snprintf(name, sizeof(name), "SeamlessRDP restack test - window %d", i);		XStoreName(g_display, wnds[i], name);		ewmh_set_wm_name(wnds[i], name);		/* Hide decorations. Often this means that no		   reparenting will be done, which makes the restack		   easier. Besides, we want to mimic our other		   seamless windows as much as possible. We must still		   handle the case with reparenting, though. */		mwm_hide_decorations(wnds[i]);		/* Prevent windows from appearing in task bar */		XSetTransientForHint(g_display, wnds[i], RootWindowOfScreen(g_screen));		ewmh_set_window_popup(wnds[i]);		/* We need to catch MapNotify/ConfigureNotify */		XSelectInput(g_display, wnds[i], StructureNotifyMask);	}	/* Map Windows. Currently, we assume that XMapRaised places	   the window on the top of the stack. Should be fairly safe;	   the window is configured before it's mapped. */	XMapRaised(g_display, wnds[2]);	/* bottom */	do	{		XWindowEvent(g_display, wnds[2], StructureNotifyMask, &xevent);	}	while (xevent.type != MapNotify);	XMapRaised(g_display, wnds[0]);	/* top */	do	{		XWindowEvent(g_display, wnds[0], StructureNotifyMask, &xevent);	}	while (xevent.type != MapNotify);	XMapRaised(g_display, wnds[1]);	/* middle */	do	{		XWindowEvent(g_display, wnds[1], StructureNotifyMask, &xevent);	}	while (xevent.type != MapNotify);	/* The stacking order should now be 1 - 0 - 2 */	if (!sw_window_is_behind(wnds[0], wnds[1]) || !sw_window_is_behind(wnds[2], wnds[1]))	{		/* Ok, technically a WM is allowed to stack windows arbitrarily, but... */		warning("Broken Window Manager: Unable to test window restacking\n");		g_seamless_broken_restack = True;		for (i = 0; i < 3; i++)			XDestroyWindow(g_display, wnds[i]);		return;	}	/* Restack, using XReconfigureWMWindow, which should correctly	   handle reparented windows as well as nonreparenting WMs. */	values.stack_mode = Below;	values.sibling = wnds[0];	restack_serial = XNextRequest(g_display);	XReconfigureWMWindow(g_display, wnds[1], DefaultScreen(g_display), CWStackMode | CWSibling,			     &values);	sw_wait_configurenotify(wnds[1], restack_serial);	/* Now verify that middle is behind top but not behind	   bottom */	if (!sw_window_is_behind(wnds[1], wnds[0]))	{		warning("Broken Window Manager: doesn't handle restack (restack request was ignored)\n");		g_seamless_broken_restack = True;	}	else if (sw_window_is_behind(wnds[1], wnds[2]))	{		warning("Broken Window Manager: doesn't handle restack (window was moved to bottom)\n");		g_seamless_broken_restack = True;	}	/* Destroy windows */	for (i = 0; i < 3; i++)		XDestroyWindow(g_display, wnds[i]);}#define SPLITCOLOUR15(colour, rv) \{ \	rv.red = ((colour >> 7) & 0xf8) | ((colour >> 12) & 0x7); \	rv.green = ((colour >> 2) & 0xf8) | ((colour >> 8) & 0x7); \	rv.blue = ((colour << 3) & 0xf8) | ((colour >> 2) & 0x7); \}#define SPLITCOLOUR16(colour, rv) \{ \	rv.red = ((colour >> 8) & 0xf8) | ((colour >> 13) & 0x7); \	rv.green = ((colour >> 3) & 0xfc) | ((colour >> 9) & 0x3); \	rv.blue = ((colour << 3) & 0xf8) | ((colour >> 2) & 0x7); \} \#define SPLITCOLOUR24(colour, rv) \{ \	rv.blue = (colour & 0xff0000) >> 16; \	rv.green = (colour & 0x00ff00) >> 8; \	rv.red = (colour & 0x0000ff); \}#define MAKECOLOUR(pc) \	((pc.red >> g_red_shift_r) << g_red_shift_l) \		| ((pc.green >> g_green_shift_r) << g_green_shift_l) \		| ((pc.blue >> g_blue_shift_r) << g_blue_shift_l) \#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); }#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \			x = (x << 16) | (x >> 16); }/* The following macros output the same octet sequences   on both BE and LE hosts: */#define BOUT16(o, x) { *(o++) = x >> 8; *(o++) = x; }#define BOUT24(o, x) { *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; }#define BOUT32(o, x) { *(o++) = x >> 24; *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; }#define LOUT16(o, x) { *(o++) = x; *(o++) = x >> 8; }#define LOUT24(o, x) { *(o++) = x; *(o++) = x >> 8; *(o++) = x >> 16; }#define LOUT32(o, x) { *(o++) = x; *(o++) = x >> 8; *(o++) = x >> 16; *(o++) = x >> 24; }static uint32translate_colour(uint32 colour){	PixelColour pc;	switch (g_server_depth)	{		case 15:			SPLITCOLOUR15(colour, pc);			break;		case 16:			SPLITCOLOUR16(colour, pc);			break;		case 24:		case 32:			SPLITCOLOUR24(colour, pc);			break;		default:			/* Avoid warning */			pc.red = 0;			pc.green = 0;			pc.blue = 0;			break;	}	return MAKECOLOUR(pc);}/* indent is confused by UNROLL8 *//* *INDENT-OFF* *//* repeat and unroll, similar to bitmap.c *//* potentialy any of the following translate *//* functions can use repeat but just doing *//* the most common ones */#define UNROLL8(stm) { stm stm stm stm stm stm stm stm }/* 2 byte output repeat */#define REPEAT2(stm) \{ \	while (out <= end - 8 * 2) \		UNROLL8(stm) \	while (out < end) \		{ stm } \}/* 3 byte output repeat */#define REPEAT3(stm) \{ \	while (out <= end - 8 * 3) \		UNROLL8(stm) \	while (out < end) \		{ stm } \}/* 4 byte output repeat */#define REPEAT4(stm) \{ \	while (out <= end - 8 * 4) \		UNROLL8(stm) \	while (out < end) \		{ stm } \}/* *INDENT-ON* */static voidtranslate8to8(const uint8 * data, uint8 * out, uint8 * end){	while (out < end)		*(out++) = (uint8) g_colmap[*(data++)];}static voidtranslate8to16(const uint8 * data, uint8 * out, uint8 * end){	uint16 value;	if (g_compatible_arch)	{		/* *INDENT-OFF* */		REPEAT2		(			*((uint16 *) out) = g_colmap[*(data++)];			out += 2;		)		/* *INDENT-ON* */	}	else if (g_xserver_be)	{		while (out < end)		{			value = (uint16) g_colmap[*(data++)];			BOUT16(out, value);		}	}	else	{		while (out < end)		{			value = (uint16) g_colmap[*(data++)];			LOUT16(out, value);		}	}}/* little endian - conversion happens when colourmap is built */static voidtranslate8to24(const uint8 * data, uint8 * out, uint8 * end){	uint32 value;	if (g_compatible_arch)	{		while (out < end)		{			value = g_colmap[*(data++)];			BOUT24(out, value);		}	}	else	{		while (out < end)		{			value = g_colmap[*(data++)];			LOUT24(out, value);		}	}}static voidtranslate8to32(const uint8 * data, uint8 * out, uint8 * end){	uint32 value;	if (g_compatible_arch)	{		/* *INDENT-OFF* */		REPEAT4		(			*((uint32 *) out) = g_colmap[*(data++)];			out += 4;		)		/* *INDENT-ON* */	}	else if (g_xserver_be)	{		while (out < end)		{			value = g_colmap[*(data++)];			BOUT32(out, value);		}	}	else	{		while (out < end)		{			value = g_colmap[*(data++)];			LOUT32(out, value);		}	}}static voidtranslate15to16(const uint16 * data, uint8 * out, uint8 * end){	uint16 pixel;	uint16 value;	PixelColour pc;	if (g_xserver_be)	{		while (out < end)		{			pixel = *(data++);			if (g_host_be)			{				BSWAP16(pixel);			}			SPLITCOLOUR15(pixel, pc);			value = MAKECOLOUR(pc);			BOUT16(out, value);		}	}	else	{		while (out < end)		{			pixel = *(data++);			if (g_host_be)			{				BSWAP16(pixel);			}			SPLITCOLOUR15(pixel, pc);			value = MAKECOLOUR(pc);			LOUT16(out, value);		}	}}static voidtranslate15to24(const uint16 * data, uint8 * out, uint8 * end){	uint32 value;	uint16 pixel;	PixelColour pc;	if (g_compatible_arch)	{		/* *INDENT-OFF* */		REPEAT3		(			pixel = *(data++);			SPLITCOLOUR15(pixel, pc);			*(out++) = pc.blue;			*(out++) = pc.green;			*(out++) = pc.red;		)		/* *INDENT-ON* */	}	else if (g_xserver_be)	{		while (out < end)		{			pixel = *(data++);			if (g_host_be)			{				BSWAP16(pixel);			}			SPLITCOLOUR15(pixel, pc);			value = MAKECOLOUR(pc);			BOUT24(out, value);		}	}	else	{		while (out < end)		{			pixel = *(data++);			if (g_host_be)			{				BSWAP16(pixel);			}			SPLITCOLOUR15(pixel, pc);			value = MAKECOLOUR(pc);			LOUT24(out, value);		}	}}static voidtranslate15to32(const uint16 * data, uint8 * out, uint8 * end){	uint16 pixel;	uint32 value;	PixelColour pc;	if (g_compatible_arch)	{		/* *INDENT-OFF* */		REPEAT4		(			pixel = *(data++);			SPLITCOLOUR15(pixel, pc);			*(out++) = pc.blue;			*(out++) = pc.green;			*(out++) = pc.red;			*(out++) = 0;		)		/* *INDENT-ON* */	}	else if (g_xserver_be)	{		while (out < end)		{			pixel = *(data++);			if (g_host_be)			{				BSWAP16(pixel);			}			SPLITCOLOUR15(pixel, pc);			value = MAKECOLOUR(pc);			BOUT32(out, value);		}	}	else	{		while (out < end)		{			pixel = *(data++);			if (g_host_be)			{				BSWAP16(pixel);			}			SPLITCOLOUR15(pixel, pc);			value = MAKECOLOUR(pc);			LOUT32(out, value);		}	}}static voidtranslate16to16(const uint16 * data, uint8 * out, uint8 * end){	uint16 pixel;	uint16 value;	PixelColour pc;	if (g_xserver_be)	{		if (g_host_be)		{			while (out < end)			{				pixel = *(data++);				BSWAP16(pixel);				SPLITCOLOUR16(pixel, pc);				value = MAKECOLOUR(pc);				BOUT16(out, value);			}		}		else		{			while (out < end)			{				pixel = *(data++);				SPLITCOLOUR16(pixel, pc);

⌨️ 快捷键说明

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