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

📄 xwin.c

📁 rdesktop是一个开放源码的Window NT中断服务器的客户端
💻 C
📖 第 1 页 / 共 4 页
字号:
		else		{			while (out < end)			{				pixel = *(data++);				SPLITCOLOUR16(pixel, pc);				value = MAKECOLOUR(pc);				LOUT24(out, value);			}		}	}}static voidtranslate16to32(const uint16 * data, uint8 * out, uint8 * end){	uint16 pixel;	uint32 value;	PixelColour pc;	if (g_arch_match)	{		/* *INDENT-OFF* */		REPEAT4		(			pixel = *(data++);			SPLITCOLOUR16(pixel, pc);			*(out++) = pc.blue;			*(out++) = pc.green;			*(out++) = pc.red;			*(out++) = 0;		)		/* *INDENT-ON* */	}	else if (g_xserver_be)	{		if (g_host_be)		{			while (out < end)			{				pixel = *(data++);				BSWAP16(pixel);				SPLITCOLOUR16(pixel, pc);				value = MAKECOLOUR(pc);				BOUT32(out, value);			}		}		else		{			while (out < end)			{				pixel = *(data++);				SPLITCOLOUR16(pixel, pc);				value = MAKECOLOUR(pc);				BOUT32(out, value);			}		}	}	else	{		if (g_host_be)		{			while (out < end)			{				pixel = *(data++);				BSWAP16(pixel);				SPLITCOLOUR16(pixel, pc);				value = MAKECOLOUR(pc);				LOUT32(out, value);			}		}		else		{			while (out < end)			{				pixel = *(data++);				SPLITCOLOUR16(pixel, pc);				value = MAKECOLOUR(pc);				LOUT32(out, value);			}		}	}}static voidtranslate24to16(const uint8 * data, uint8 * out, uint8 * end){	uint32 pixel = 0;	uint16 value;	PixelColour pc;	while (out < end)	{		pixel = *(data++) << 16;		pixel |= *(data++) << 8;		pixel |= *(data++);		SPLITCOLOUR24(pixel, pc);		value = MAKECOLOUR(pc);		if (g_xserver_be)		{			BOUT16(out, value);		}		else		{			LOUT16(out, value);		}	}}static voidtranslate24to24(const uint8 * data, uint8 * out, uint8 * end){	uint32 pixel;	uint32 value;	PixelColour pc;	if (g_xserver_be)	{		while (out < end)		{			pixel = *(data++) << 16;			pixel |= *(data++) << 8;			pixel |= *(data++);			SPLITCOLOUR24(pixel, pc);			value = MAKECOLOUR(pc);			BOUT24(out, value);		}	}	else	{		while (out < end)		{			pixel = *(data++) << 16;			pixel |= *(data++) << 8;			pixel |= *(data++);			SPLITCOLOUR24(pixel, pc);			value = MAKECOLOUR(pc);			LOUT24(out, value);		}	}}static voidtranslate24to32(const uint8 * data, uint8 * out, uint8 * end){	uint32 pixel;	uint32 value;	PixelColour pc;	if (g_arch_match)	{		/* *INDENT-OFF* */#ifdef NEED_ALIGN		REPEAT4		(			*(out++) = *(data++);			*(out++) = *(data++);			*(out++) = *(data++);			*(out++) = 0;		)#else		REPEAT4		(			*((uint32 *) out) = *((uint32 *) data);			out += 4;			data += 3;		)#endif		/* *INDENT-ON* */	}	else if (g_xserver_be)	{		while (out < end)		{			pixel = *(data++) << 16;			pixel |= *(data++) << 8;			pixel |= *(data++);			SPLITCOLOUR24(pixel, pc);			value = MAKECOLOUR(pc);			BOUT32(out, value);		}	}	else	{		while (out < end)		{			pixel = *(data++) << 16;			pixel |= *(data++) << 8;			pixel |= *(data++);			SPLITCOLOUR24(pixel, pc);			value = MAKECOLOUR(pc);			LOUT32(out, value);		}	}}static uint8 *translate_image(int width, int height, uint8 * data){	int size;	uint8 *out;	uint8 *end;	/* if server and xserver bpp match, */	/* and arch(endian) matches, no need to translate */	/* just return data */	if (g_arch_match)	{		if (g_depth == 15 && g_server_bpp == 15)			return data;		if (g_depth == 16 && g_server_bpp == 16)			return data;		if (g_depth == 24 && g_bpp == 24 && g_server_bpp == 24)			return data;	}	size = width * height * (g_bpp / 8);	out = (uint8 *) xmalloc(size);	end = out + size;	switch (g_server_bpp)	{		case 24:			switch (g_bpp)			{				case 32:					translate24to32(data, out, end);					break;				case 24:					translate24to24(data, out, end);					break;				case 16:					translate24to16(data, out, end);					break;			}			break;		case 16:			switch (g_bpp)			{				case 32:					translate16to32((uint16 *) data, out, end);					break;				case 24:					translate16to24((uint16 *) data, out, end);					break;				case 16:					translate16to16((uint16 *) data, out, end);					break;			}			break;		case 15:			switch (g_bpp)			{				case 32:					translate15to32((uint16 *) data, out, end);					break;				case 24:					translate15to24((uint16 *) data, out, end);					break;				case 16:					translate15to16((uint16 *) data, out, end);					break;			}			break;		case 8:			switch (g_bpp)			{				case 8:					translate8to8(data, out, end);					break;				case 16:					translate8to16(data, out, end);					break;				case 24:					translate8to24(data, out, end);					break;				case 32:					translate8to32(data, out, end);					break;			}			break;	}	return out;}BOOLget_key_state(unsigned int state, uint32 keysym){	int modifierpos, key, keysymMask = 0;	int offset;	KeyCode keycode = XKeysymToKeycode(g_display, keysym);	if (keycode == NoSymbol)		return False;	for (modifierpos = 0; modifierpos < 8; modifierpos++)	{		offset = g_mod_map->max_keypermod * modifierpos;		for (key = 0; key < g_mod_map->max_keypermod; key++)		{			if (g_mod_map->modifiermap[offset + key] == keycode)				keysymMask |= 1 << modifierpos;		}	}	return (state & keysymMask) ? True : False;}static voidcalculate_shifts(uint32 mask, int *shift_r, int *shift_l){	*shift_l = ffs(mask) - 1;	mask >>= *shift_l;	*shift_r = 8 - ffs(mask & ~(mask >> 1));}BOOLui_init(void){	XVisualInfo vi;	XPixmapFormatValues *pfm;	uint16 test;	int i, screen_num, nvisuals;	XVisualInfo *vmatches = NULL;	XVisualInfo template;	Bool TrueColorVisual = False;	g_display = XOpenDisplay(NULL);	if (g_display == NULL)	{		error("Failed to open display: %s\n", XDisplayName(NULL));		return False;	}	screen_num = DefaultScreen(g_display);	g_x_socket = ConnectionNumber(g_display);	g_screen = ScreenOfDisplay(g_display, screen_num);	g_depth = DefaultDepthOfScreen(g_screen);	/* Search for best TrueColor depth */	template.class = TrueColor;	vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);	nvisuals--;	while (nvisuals >= 0)	{		if ((vmatches + nvisuals)->depth > g_depth)		{			g_depth = (vmatches + nvisuals)->depth;		}		nvisuals--;		TrueColorVisual = True;	}	test = 1;	g_host_be = !(BOOL) (*(uint8 *) (&test));	g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);	if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))	{		/* we use a colourmap, so the default visual should do */		g_visual = DefaultVisualOfScreen(g_screen);		g_depth = DefaultDepthOfScreen(g_screen);		/* Do not allocate colours on a TrueColor visual */		if (g_visual->class == TrueColor)		{			g_owncolmap = False;		}	}	else	{		/* need a truecolour visual */		if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))		{			error("The display does not support true colour - high colour support unavailable.\n");			return False;		}		g_visual = vi.visual;		g_owncolmap = False;		calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);		calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);		calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);		/* if RGB video and everything is little endian */		if ((vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask) &&		    !g_xserver_be && !g_host_be)		{			if (g_depth <= 16 || (g_red_shift_l == 16 && g_green_shift_l == 8 &&					      g_blue_shift_l == 0))			{				g_arch_match = True;			}		}		if (g_arch_match)		{			DEBUG(("Architectures match, enabling little endian optimisations.\n"));		}	}	pfm = XListPixmapFormats(g_display, &i);	if (pfm != NULL)	{		/* Use maximum bpp for this depth - this is generally		   desirable, e.g. 24 bits->32 bits. */		while (i--)		{			if ((pfm[i].depth == g_depth) && (pfm[i].bits_per_pixel > g_bpp))			{				g_bpp = pfm[i].bits_per_pixel;			}		}		XFree(pfm);	}	if (g_bpp < 8)	{		error("Less than 8 bpp not currently supported.\n");		XCloseDisplay(g_display);		return False;	}	if (!g_owncolmap)	{		g_xcolmap =			XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,					AllocNone);		if (g_depth <= 8)			warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n");	}	if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))	{		warning("External BackingStore not available, using internal\n");		g_ownbackstore = True;	}	/*	 * Determine desktop size	 */	if (g_fullscreen)	{		g_width = WidthOfScreen(g_screen);		g_height = HeightOfScreen(g_screen);	}	else if (g_width < 0)	{		/* Percent of screen */		g_height = HeightOfScreen(g_screen) * (-g_width) / 100;		g_width = WidthOfScreen(g_screen) * (-g_width) / 100;	}	else if (g_width == 0)	{		/* Fetch geometry from _NET_WORKAREA */		uint32 x, y, cx, cy;		if (get_current_workarea(&x, &y, &cx, &cy) == 0)		{			g_width = cx;			g_height = cy;		}		else		{			warning("Failed to get workarea: probably your window manager does not support extended hints\n");			g_width = 800;			g_height = 600;		}	}	/* make sure width is a multiple of 4 */	g_width = (g_width + 3) & ~3;	g_mod_map = XGetModifierMapping(g_display);	xkeymap_init();	if (g_enable_compose)		g_IM = XOpenIM(g_display, NULL, NULL, NULL);	xclip_init();	DEBUG_RDP5(("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth));	return True;}voidui_deinit(void){	if (g_IM != NULL)		XCloseIM(g_IM);	if (g_null_cursor != NULL)		ui_destroy_cursor(g_null_cursor);	XFreeModifiermap(g_mod_map);	if (g_ownbackstore)		XFreePixmap(g_display, g_backstore);	XFreeGC(g_display, g_gc);	XCloseDisplay(g_display);	g_display = NULL;}BOOLui_create_window(void){	uint8 null_pointer_mask[1] = { 0x80 };	uint8 null_pointer_data[24] = { 0x00 };	XSetWindowAttributes attribs;	XClassHint *classhints;	XSizeHints *sizehints;	int wndwidth, wndheight;	long input_mask, ic_input_mask;	XEvent xevent;	wndwidth = g_fullscreen ? WidthOfScreen(g_screen) : g_width;	wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;	/* Handle -x-y portion of geometry string */	if (g_xpos < 0 || (g_xpos == 0 && (g_pos & 2)))		g_xpos = WidthOfScreen(g_screen) + g_xpos - g_width;	if (g_ypos < 0 || (g_ypos == 0 && (g_pos & 4)))		g_ypos = HeightOfScreen(g_screen) + g_ypos - g_height;	attribs.background_pixel = BlackPixelOfScreen(g_screen);	attribs.border_pixel = WhitePixelOfScreen(g_screen);	attribs.backing_store = g_ownbackstore ? NotUseful : Always;	attribs.override_redirect = g_fullscreen;	attribs.colormap = g_xcolmap;	g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), g_xpos, g_ypos, wndwidth,			      wndheight, 0, g_depth, InputOutput, g_visual,			      CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap |			      CWBorderPixel, &attribs);	if (g_gc == NULL)		g_gc = XCreateGC(g_display, g_wnd, 0, NULL);	if (g_create_bitmap_gc == NULL)		g_create_bitmap_gc = XCreateGC(g_display, g_wnd, 0, NULL);	if ((g_ownbackstore) && (g_backstore == 0))	{		g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);		/* clear to prevent rubbish being exposed at startup */		XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));		XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);	}	XStoreName(g_display, g_wnd, g_title);	if (g_hide_decorations)		mwm_hide_decorations();	classhints = XAllocClassHint();	if (classhints != NULL)	{		classhints->res_name = classhints->res_class = "rdesktop";		XSetClassHint(g_display, g_wnd, classhints);		XFree(classhints);	}	sizehints = XAllocSizeHints();	if (sizehints)	{		sizehints->flags = PMinSize | PMaxSize;		if (g_pos)			sizehints->flags |= PPosition;		sizehints->min_width = sizehints->max_width = g_width;		sizehints->min_height = sizehints->max_height = g_height;		XSetWMNormalHints(g_display, g_wnd, sizehints);		XFree(sizehints);	}	if (g_embed_wnd)	{		XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);	}	input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |		VisibilityChangeMask | FocusChangeMask;	if (g_sendmotion)		input_mask |= PointerMotionMask;	if (g_ownbackstore)		input_mask |= ExposureMask;	if (g_fullscreen || g_grab_keyboard)		input_mask |= EnterWindowMask;	if (g_grab_keyboard)		input_mask |= LeaveWindowMask;	if (g_IM != NULL)	{		g_IC = XCreateIC(g_IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),				 XNClientWindow, g_wnd, XNFocusWindow, g_wnd, NULL);		if ((g_IC != NULL)		    && (XGetICValues(g_IC, XNFilterEvents, &ic_input_mask, NULL) == NULL))			input_mask |= ic_input_mask;	}	XSelectInput(g_display, g_wnd, input_mask);	XMapWindow(g_display, g_wnd);	/* wait for VisibilityNotify */	do	{		XMaskEvent(g_display, VisibilityChangeMask, &xevent);	}	while (xevent.type != VisibilityNotify);	g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;	g_focused = False;	g_mouse_in_wnd = False;	/* handle the WM_DELETE_WINDOW protocol */	g_protocol_atom = XInternAtom(g_display, "WM_PROTOCOLS", True);	g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);	XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);	/* create invisible 1x1 cursor to be used as null cursor */	if (g_null_cursor == NULL)		g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);	return True;}voidui_resize_window(){	XSizeHints *sizehints;	Pixmap bs;

⌨️ 快捷键说明

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