XWindows 색깔바꾸기 예제

크리에이티브 커먼즈 라이선스
Creative Commons License





#include <X11/Xlib.h>
main(){
	Display *d;
	Window root, w, w1, w2, w3;
	Colormap CMap;
	XColor color, color_exact;
	unsigned long Black, White;
	char buf[33] = {0, };
	char color_name[33] = {0, };
	Window selected_window;

                d = XOpenDisplay(NULL);

	root = XDefaultRootWindow(d);
	Black = BlackPixel(d, 0);
	White = WhitePixel(d, 0);

	CMap = XDefaultColormap(d, 0);
	w = XCreateSimpleWindow(d, root, 300, 100, 500, 350, 2,
				Black, White);

	w1 = XCreateSimpleWindow(d, w, 200, 50, 100, 100, 2,
				Black, White);
	w2 = XCreateSimpleWindow(d, w, 100, 200, 100, 100, 2,
				Black, White);
	w3 = XCreateSimpleWindow(d, w, 300, 200, 100, 100, 2,
				Black, White);

	XMapWindow(d, w);
	XMapSubwindows(d, w);

	XFlush(d);

	while(1){
		fflush(0);
		printf("Enter box number to change color: ");
		scanf("%s", buf);
		switch(buf[0]){
			case '0':
				goto END;				
			case '1':
				selected_window = w1;
				break;
			case '2':
				selected_window = w2;
				break;
			case '3':
				selected_window = w3;
			break;
			default:
				printf("[!] Enter valid box number\n");
				continue;
			
		}
		printf("[*] Selected box %d\n", buf[0]-0x30);

		printf("Enter color name: ");
		fflush(0);
                	scanf("%s", color_name);

		XAllocNamedColor(d, CMap, color_name, &color, &color_exact);
		XSetWindowBackground(d, selected_window, color.pixel);
		XClearWindow(d, selected_window);
		XFlush(d);

		printf("[*] Changed box%d's color to %s\n", buf[0]-0x30, color_name);
	}
END:
	XDestroySubwindows(d, w);
	XDestroyWindow(d, w);
	XCloseDisplay(d);
} 

신고

'컴퓨터공부 > 엑스윈도우즈' 카테고리의 다른 글

XWindows 색깔바꾸기 예제  (0) 2014.03.08

설정

트랙백

댓글


티스토리 툴바