1 / 19

X 윈도우 프로그래밍

X 윈도우 프로그래밍. 참고도서 Unix 운영체제, Kaare Christian, Susan Rihter 저, 석상기역, 희중당, 1997 X 윈도우 시스템 프로그래밍, 김충석저, 이한출판사, 1994 The X Window System Programming and Application with Xt, 2nd Ed., Douglas A. Young , Prentice Hall PTR , 1994

Télécharger la présentation

X 윈도우 프로그래밍

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. X 윈도우 프로그래밍 참고도서 Unix 운영체제, Kaare Christian, Susan Rihter저, 석상기역, 희중당, 1997 X 윈도우 시스템 프로그래밍, 김충석저, 이한출판사, 1994 The X Window System Programming and Application with Xt, 2nd Ed., Douglas A. Young, Prentice Hall PTR, 1994 한국어판 The X Window System Programming and Application with Xt 제 2판, Young 저, 박승규 외 4인 역, 대영사, 1996

  2. 윈도우 시스템이란? 멀티태스킹 편리한 사용자 인터페이스 그래픽 기능 MIT에서 개발한 X Window System이 X consortium에 의해 채택되어 표준화됨 윈도우 인터페이스 데스크톱(desktop) 또는 루트 윈도우(root window) 응용 윈도우(application window) 타이틀 바 크기 조정 제어(resizing control) 스크롤 바 서브윈도우 메뉴 대화 상자 에러 메시지 포인터(마우스) 포인터 초점(입력 초점) -> 활동 윈도우 메뉴 윈도우 연산 옮기기(moving) 윈도우 매니저(window manager)에게 이동 요청 마우스 따라 움직임 마우스 버튼을 놓으면 윈도우 매니저가 새 위치에 다시 그림 겹치기(overlapping) 윈도우 매니저가 덮이는 부분과 보이는 부분이 정확히 그려지도록 관리 다시 그리기(redrawing) 크기 조정(resizing) resize corner 닫기(closing) 아이콘화(iconifying) 열기(opening) 윈도우 시스템 (1) Unix

  3. X 서버와 클라이언트 비트맵 디스플레이 상의 윈도우를 위한 장치 독립적이고 네트워크로 연결된 시스템 모든 구조가 클라이언트-서버 모델 최소장비 비트맵 모니터 키보드 마우스 X terminal : 그래픽 처리 잘하는 CPU 가진 터미널 -> X manager(http://www.netsarang.co.kr) X network protocol 요청 : s/w -> h/w 이벤트 : h/w -> s/w X s/w : p339 그림16.3 참조 X 윈도우 시스템의 구조: p339 그림16.3 (1) 베이스 X 소프트웨어(The Base X Software) h/w와 직접통신 디스플레이 가진 호스트에서 실행 (2) X 네트워크 프로토콜 라이브러리(X Network Protocol Library): X의 기계어 X 프로토콜 요청을 h/w 명령으로 번역 (3) Xlib: X의 어셈블리어 클라이언트 요청을 X 프로토콜 메시지로 번역 (4) 내장 라이브러리(Intrinsic Library) 객체 지향 루틴, Xt(X toolkit) (5) 위젯(Widget) 버튼누르기, 스크롤바, 윈도우 편집, 팝업 메뉴 등 (6) 위젯 집합(Widget Set) Athena 위젯 집합: Xaw OSF Motif: Xm AT&T OPEN LOOK: OLIT (7) 툴킷(Toolkit): X의 고급 언어 고급 프로그래밍 라이브러리 내장 라이브러리 + 위젯 집합 OSF Motif: Xm AT&T OPEN LOOK: OLIT (8) X 서버(X server) 다른 호스트와의 통신 담당 베이스 X 소프트웨어 X 네트워크 프로토콜 라이브러리 (9) 윈도우 매니저(Window Manger) 윈도우 치장 조정 타이틀바, 스크롤바, 폰트, 버튼모양 등 (10) 어플리케이션(또는 클라이언트) 윈도우 디스플레이 내용 조정 윈도우 시스템 (2) Unix

  4. 오 픈 시스템 철학 무정책(Policy-free) 네트워크 투명성(Network-transparent) 장치독립성(Device-independent) 분산 윈도우 시스템 실제 프로그램 실행과 X 윈도우의 출력 디스플레이가 다른 기계에 있을 수 있음 GUI(Graphical User Interface) Open Software Foundation의 Motif SunSoft의 OPEN LOOK X 서버와 디스플레이 연결 X 서버 X 윈도우 매니저, 디스플레이, 입력장치 초기화 X 세션 동안 항상 가동 디스플레이 연결: X 클라이언트 프로그램과 X 서버 사이에 p344 그림 16.5 참조 어플리케이션(X 클라이언트) terminal emulator: tty를 가상 윈도우 매니저 특별한 X 클라이언트 모든 다른 응용 윈도우를 관리 디스플레이 연결 전후의 X 프로토콜 요청 및 이벤트 가로채 GUI 변경 항상 가동 장식 담당 호환성: ICCCM Motif 윈도우 매니저 상에서 OPEN LOOK 어플리케이션 실행 가능 클라이언트 사이의 통신 윈도우 매니저와 어플리케이션 ICCCM(Inter-Client Communication Conventions Manual) 표준으로 윈도우 시스템 (3) Unix

  5. X의 시작 xinit 프로그램으로 X 환경 초기화 구성파일 홈 디렉토리의 .xinitrc(run command): p346 그림 16.6 참조 xterm: 가상 터미널 xbiff: 메일 알람 관리기 cm: 달력 관리 프로그램 xmh: 메일 관리기 xclock: 시계/날짜 프로그램 시스템 /usr/openwin/lib/Xinitrc 가 default olwm dsdm(drop site database manager) Solaris 2.6 이상에서는 .dtprofile 에 환경 초기화 부팅시 /usr/openwin/bin/X로 X 기동 X -> ./Xsun CDE : /usr/dt, /etc/rc2.d/s00dtlogin xdm(X display manager)로도 X 서버 기동 가능: X 터미널에서 윈도우 시스템 (4) • X 구성하기(Customizing X) • X 응용을 위한 공통 명령행 옵션(p349 표 16.1 참조) -display $ -display unix:0 -geometry $ xclock -geometry -277+7 -digital & -fg, -bg $ showrgb -font $ xlsfont • X 자원(X Reseorces) • 자원: 색상, 폰트, 버튼 모양 • 자원 지정: 홈디렉토리 .Xdefaults 또는 시스템 /usr/openwin/lib/Xdefaults • mwm*client*title*foreground=black • 검색 순서 • 시스템 Xdefaults(/usr/openwin/lib/Xdefaults) • 특정 프로그램위한 app-defaults 파일 • 사용자 자신의 app-defaults 파일(/usr/openwin/lib/X11/app-defaults) • 명령행 옵션으로 지정된 자원 Unix

  6. X 자원 검사 도구 xwininfo: 특정 윈도우 정보 Appres: X 어플리케이션 환경 정보 Editres: 위젯 트리 검사 xprop: 윈도우 매니저 관점의 윈도우 정보 X 디스플레이 p354 그림 참조 nathasha:0 rocky:0.0., rocky:0.1 boris:0, boris:1 unix:0 디스플레이 허가 X 서버 시작된 후에 xhost 명령으로 $ xhost + rocky $ xhost - rocky $ xhost 윈도우 매니저 구성 파일 Motif IBM Presentation Manager와 MS Windows와 유사 p357표16.2, p357그림 16.12a,b 참조 OPEN LOOK 구분 OPEN LOOK: AT&T -> USL(Unix System Laboratories) OpenWindows: Sun의 모든 OLIT 기반 윈도우 패키지 OPEN LOOK Window Manager(olwm): AT&T OPEN LOOK 기반, 클라이언트 간 통신 강화 툴킷 Xview: Sun의 SunView 응용을 X로 전환하기위해 마련 OLIT(Open Look Interface Toolkit): Sun의 주력 윈도우 시스템 OpenWindows의 기초가 됨 p360표16.3, p361그림16.13a,b 참조 twm(Tabbed Window Manager) p363표16.4, p363그림16.14a,b 참조 윈도우 시스템 (5) Unix

  7. simple.c /* gcc –o simple simple.c –lX11 */ #include <X11/Xlib.h> #include <X11/Xutil.h> #include <stdio.h> main() { Display *d; Window w; d = XOpenDisplay (NULL); w = XCreateSimpleWindow (d, DefaultRootWindow (d), 50, 50, 400, 300, 2, BlackPixel (d, 0), WhitePixel (d, 0)); XMapWindow (d, w); XFlush (d); getchar (); XCloseDisplay (d); } simple.c Unix

  8. text.c #include <X11/Xlib.h> #include <stdio.h> main() { Display *d; Window w; Font f; GC gc; XSetWindowAttributes a; a.override_redirect = 1; d = XOpenDisplay(NULL); w =XCreateSimpleWindow(d,DefaultRootWindow(d),100,300,400,150,2,BlackPixel(d,0), WhitePixel(d,0)); XMapWindow(d,w); gc = XCreateGC(d,w,0,0); f = XLoadFont(d,"kor.12*24"); XSetFont(d,gc,f); XDrawString(d,w,gc,100,100,"Apple",5); XFlush(d); getchar(); } Unix

  9. label.c /* gcc –o label label.c –lX11 –lXm –lXt */ #include <stdio.h> #include <Xm/Label.h> Widget topShell; main(int argc, char* argv[]) { Widget label; topShell = XtInitialize(argv[0],"",NULL,0,&argc, argv); label = XmCreateLabel(topShell, "This is a Label",NULL,0); XtManageChild(label); XtRealizeWidget(topShell); XtMainLoop(); } Unix

  10. pushbutton.c /* gcc –o pushbutton pushbutton.c –lX11 –lXm –lXt */ #include <stdio.h> #include <Xm/PushB.h> Widget topShell; void handle_button(); main(int argc, char* argv[]) { Widget button; topShell = XtInitialize(argv[0],"",NULL,0,&argc, argv); button = XmCreatePushButton(topShell, "Hello",NULL,0); XtManageChild(button); XtAddCallback(button, XmNactivateCallback, handle_button,NULL); XtRealizeWidget(topShell); XtMainLoop(); } void handle_button(Widget w, XtPointer client_data, PushButtonCallbackStruct *call_data) { printf("Button Pushed \n"); } Unix

  11. /* gcc –o attribute attribute.c –lX11 –lXm –lXt */ #include <stdio.h> #include <Xm/PushB.h> #include <Xm/BulletinB.h> // 여러개의 위젯을 포함하기위해 BulletinBoard가 필요 Widget topShell; main(int argc, char* argv[]) { Widget button, bb; // 속성(크기, 위치)를 정하기 위해서 선언 // 자세한 내용은 marvel.inchon.ac.kr -> imformation -> xwindow programming 참고 Arg args[10]; // 속성을 저장할 배열 int nargs = 0; // 배열의 첨자로 사용될 변수 topShell = XtInitialize(argv[0],"",NULL,0,&argc, argv); // 초기화 // 속성을 설정한다. 설정된 속성은 다른 위젯에도 적용할 수 있다. XtSetArg(args[nargs] ,XmNwidth, 500); nargs++; XtSetArg(args[nargs] ,XmNheight, 400); nargs++; // 이속성을 윈도우에 적용해 보도록 하겠다. XtSetValues(topShell, args, nargs); // 여러개의 위젯을 포함하기 위해 BulletinBoard를 만들어 붙인다. bb = XmCreateBulletinBoard(topShell,"bb",NULL,0); XtManageChild(bb); attribute.c (1) Unix

  12. attribute.c (2) // 이제는 버튼에 위치와 크기를 설정해서 적용해 보도록 하자. // 설정하는 속성들이 배열로 저장되고 // 적용할때는 이배열에서 값을 하나씩 꺼내어 적용한다. // 일단 배열의 첨자를 처음으로 옮기고... nargs = 0; // 이러한 속성 값들은 <Xm/StrDefs.h> 에 정의되어 있다. XtSetArg(args[nargs], XmNx, 100); nargs++; // x-coordinate XtSetArg(args[nargs], XmNy, 200); nargs++; // y-coordinate XtSetArg(args[nargs] ,XmNwidth, 100); nargs++; // 폭을 지정 XtSetArg(args[nargs] ,XmNheight, 20); nargs++; // height // 버튼을 하나 만들는데 위에서 지정한 속성을 사용한다. // 이때 버튼을 BulletinBoard에 붙인다. button = XmCreatePushButton(bb, "Hello",args,nargs); XtManageChild(button); XtRealizeWidget(topShell); XtMainLoop(); } Unix

  13. linedit.c #include <X11/Intrinsic.h> #include <X11/StringDefs.h> #include <Xm/Xm.h> #include <Xm/Text.h> main(int argc, char * argv[]) { Widget toplevel , text; toplevel = XtInitialize(argv[0],"TextWidget",NULL,0,&argc,argv); text = XmCreateText(toplevel,"Text", NULL, 0); XtManageChild(text); XtRealizeWidget(toplevel); XtMainLoop(); } Unix

  14. editor.c #include <X11/Intrinsic.h> #include <X11/StringDefs.h> #include <Xm/Xm.h> #include <Xm/Text.h> main(int argc, char * argv[]) { Arg wargs[10]; int n; Dimension x,y; Widget toplevel , scrolled_text; toplevel = XtInitialize(argv[0],"TextWidget",NULL,0,&argc,argv); n = 0; XtSetArg(wargs[n], XmNeditable, True); n++; XtSetArg(wargs[n], XmNeditMode , XmMULTI_LINE_EDIT); n++; XtSetArg(wargs[n], XmNcolumns, 23); n++; XtSetArg(wargs[n], XmNrows , 5); n++; XtSetArg(wargs[n], XmNx, 15); n++; XtSetArg(wargs[n], XmNy, 15); n++; XtSetArg(wargs[n], XmNscrollVertical, True); n++; XtSetArg(wargs[n], XmNscrollHorizontal, True); n++; XtSetArg(wargs[n], XmNscrollLeftSide, False); n++; XtSetArg(wargs[n], XmNscrollTopSide, False); n++; scrolled_text = XmCreateScrolledText(toplevel,"ScrolledText", wargs, n); XtManageChild(scrolled_text); XtRealizeWidget(toplevel); XtMainLoop(); } Unix

  15. 콜백과 이벤트 핸들러 XtMainLoop() : 클라이언트가 요구한 이벤트가 발생하여 서버로부터 통보가 올때까지 무한 루프에서 대기하는 함수 서버는 입력 이벤트를 감지하면 XtMainLoop() 위해 이벤트 큐에 저장 Xt가 사용자가 지정한 이벤트가 발생했을 때 수행될 함수나 프로시주어 기술 방법 지원 콜백: 지정된 형태의 이벤트 처리 이벤트 핸들러 : 지정된 형태 이외의 이벤트 처리 콜백(Callback) 지정된 위젯에 지정된 콜백 함수 (예) PushButton 위젯의 3 콜백 형태 XmNactivateCallback (버튼안에서 뗄 때) XmNarmCallback (눌렀을 때) XmNdisarmCallback (뗄 때) XtAddCallback() XtRemoveCallback() XtRemoveAllCallback() 이벤트 핸들러(event handler) 콜백으로 지정된 형태 이외의 이벤트를 처리하고 싶을 때 XtAddEventHandler() eventhandle.c 예제 참조 이벤트 관리 큐 XtMainLoop() 함수가 이벤트 큐에 있는 이벤트 꺼내서 위젯에 알려줌 XtPending() : 큐에 이벤트 있는 지 조사 XtPeekEvent(&event) : 큐 맨 앞 이벤트를 프로그램의 이벤트 구조에복사 XtMainLoop()과 같은 기능 if(XtPending()) { XtNextEvent(&event); XtDispatchEvent(&event); } else { … } 콜백과 이벤트 핸들러 Unix

  16. event.c static void ButtonPushed(w,client_data,event) Widget w; caddr_t client_data; XEvent *event; { printf("You just pressed the hello button ... \n"); sleep(3); printf("Good Bye ! \n"); XtCloseDisplay(XtDisplay(topShell)); exit(0); } #include <stdio.h> #include <Xm/Xm.h> #include <Xm/PushB.h> Widget topShell; static void ButtonPushed(); main(argc,argv) Cardinal argc; String argv[]; { Widget myButton; topShell = XtInitialize(argv[0],"Pwu1302",NULL,0,&argc,argv); myButton = XmCreatePushButton(topShell, "hello", NULL, 0); XtAddEventHandler(myButton,ButtonPressMask,FALSE,ButtonPushed,NULL); XtManageChild(myButton); XtRealizeWidget(topShell); XtMainLoop(); } Unix

  17. X 클라이언트-서버 모델 서버 모든 입출력 장치에 대해 서비스 front-end server (cf.) 일반적: back-end server 클라이언트 서버 제공 기능 이용하는 모든 응용 프로그램 서버와 비동기적 바이트 스트림(byte stream) 프로토콜로 통신 = X 프로토콜 1 서버 <-> N 클라이언트 1 클라이언트 <-> N 서버 X 프로토콜 구현 Unix 스트림또는 소켓 TCP/IP, 이더넷, 광 케이블 Unix 클라이언트, MS-DOS 서버 VMS DECNet X 프로토콜 Request: C -> S 윈도우 생성, 조작, 출력 등의 요구 Reply: S -> C Request에 대한 서버의 메시지, 클라이언트는 Request후 Reply 대기 Event: S -> C 서버에서 비동기적으로 발생하는 사건에 대하여 클라이언트에게 알리는 메시지 Error: S -> C 서버측 에러 발생을 클라이언트에 알리는 메시지 X 디스플레이 display 이름 = host 이름: display 번호. Screen 번호 (예)host1:0.0 host2:1 host3:0.2 Null로 하면 환경변수 DISPLAY의 값 윈도우 시스템(보충.) Unix

  18. 윈도우 매니저(window manager) 화면 구성 및 장식 담당 윈도우 이동 크기 조정 초점 윈도우 변경 등 하나의 X 클라이언트 Xlib + 특수 위젯 집합 X 라이브러리 호출 관리 특권 종류 uwm: The Universal Window Manager awm: The Athena Window Manager twm: Tom’s Window Manager mwm: The Motif Window Manager olwm: The Open Look Window Manager 윈도우 계층구조와 스택 순서 스택으로 윈도우 관리 최상위 윈도우가 스택의 top 형제 윈도우 사이에는 생성 순서로 윈도우 시스템 표준 도구: /usr/X/bin에 xterm: VT100/Tecktronix emulator xclock: 시계 xedit: 편집기 xcalc: 계산 xlsfonts: 폰트 리스트 xwd: 화면 덤프 xfig: 도형 편집(?) X 윈도우 프로그램 참고자료 http://marvel.inchon.ac.kr의 Information의 X Window에 관한 정보 man 안되면 .cshrc에 추가 setenv MANPATH /usr/local/man:/usr/share/man:/usr/openwin/man 윈도우 시스템(보충..) Unix

  19. X 윈도우 프로그램 실습 과제 • 과제 1 • 자기 이름이 나타나 있는 버튼을 하나 만들고 버튼을 누르면 자신의 홈페이지 주소 또는 e-mail 주소가 적힌 레이블이 나오게 하는 X 윈도우 프로그램을 작성하라. • 제출: ~ 11/12 (금) • segmentation fault 나오면 자기 홈디렉토리의 .cshrc에서 #setenv DISPLAY `hostname`:0.0 (코멘트 문으로 만들어 실행되지 않게 함) • 과제 2 • 아래의 사이트에 제공된 텍스트 윈도우를 출력하는 두 개의 X 윈도우 프로그램 lineedit.c와 editor.c를 실행해 보고 이 프로그램을 응용하여 채팅 창에 입력한 내용이 텍스트 창에 나타나도록 프로그램을 수정해 보라. • Ftp 사이트: 210.126.35.10 • login ID: anonymous • 제출: ~ 11/19 (금) • 참조 함수: sprintf(s, XmTextGetString(text)); • 참조 헤더 파일: /usr/include/Xm/Text.h Unix

More Related