x window

38
1 X Window 제 10 제 : X Windows

Upload: helene

Post on 18-Jan-2016

44 views

Category:

Documents


0 download

DESCRIPTION

제 10 강 : X Windows. X Window. (3) User inputs $ startx command sh creates child (window) process 3 processes are active now parent (sh) is sleeping. Window is running. window. sh a.out. Operator Console Power Up Kernel creates sh (CUI**) - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: X  Window

1

X Window

제 10 강 : X Windows

Page 2: X  Window

2

(2) Operator Console Power Up

Kernel creates sh (CUI**)

Now two processes are active

sh

a.out

kernel

a.out(1) Initially only kernel runs

(3) User inputs $ startx

command

sh creates child (window) process

3 processes are active now

parent (sh) is sleeping.

Window is running

window

** Character User Interface

Page 3: X  Window

3

Linux Desktop EnvironmentsKDE & GNOME

Page 4: X  Window

4

sh

a.out

kernel

a.out

window

X window is just a plain application program

command (utility) child process of sh

Page 5: X  Window

5

Active process

(netscape)

Active process

(Web)

Active process

(ppt)

- 1 window per client process- local or remote process - iconized or de-iconized

Multiple Windowscommands

under /bin

Page 6: X  Window

6

sh

a.out

window

Window process is running

(parent sh is sleeping)

At windows, user clicks “mail”

(Window itself cannot create child process)

(Creating child command is sh’s job)

Window needs to communicate with sh

Window invokes IPC system call

Kernel provides IPC service

blocks Windows (caller)

move data from window to

sh

wakes up sh (callee)

kernel

a.out

Click mail program

IPC request

control &

data

createsmail

NOTE – child process can be a remote process, such as web server

Page 7: X  Window

7

I P C

Window sh

kernel(IPC)

mail editor

tell sh to createmail as a child create mail

sleep till doneWake up. I am done

create editorsleep till done

Wake up. I am done

Wake up. I am done

Page 8: X  Window

8

Root window(entire screen)

Root Window

Page 9: X  Window

9

Root window(entire screen)

Top level windows or Child windows(per each process)

Child Windows

Page 10: X  Window

10

X-Window Protocol

Page 11: X  Window

11

Local application

(Seoul) Remote

application

(Tokyo)

Local machineactual drawing

Remote applications request drawing

Question: Should remote application send all the bitmaps for every graph & character?

GUI involve a lot of drawing

Tokyo

Seoul

Page 12: X  Window

12

Protocol to minimize network traffic

• reduce network traffic• place most bitmaps on the tty side a priori• Communication protocol for outputs

• Communication protocol for inputs– keyboard (=code 3), – mouse click (=code 4), ….

called “resource”(bitmaps)

*****widgetsfont A A A a acolor

Page 13: X  Window

13

“widget 2”

“widget 3”

A font file font 1

A font file font 2

A font file font 3

X - Protocol

*****

Device Side

[actual drawing]

mapping

bitmap for widgets

bitmap for characters

code

Application Side

[ request by code]

resou

rce

Page 14: X  Window

14

X-Window Processes

Page 15: X  Window

15

2 kind of processes

X-ServerApplication

X-Client

requestdrawing

deliverevent

screenkeyboard

mouse

hardware

requestdrawing

Page 16: X  Window

16

Window Managera special client process

WindowManager

requestdrawing

deliverevent

screenkeyboard

mouse

X-Server

hardware

X-Clients

Page 17: X  Window

17

Role of Window Manager

WindowManager

X-Server

hardware

Interfacewith

Hardware

Interface with ApplicationControl appearance of

windows(arrange, resize, …)

Mediate between child windows

X-Clients(child windows)

Window library

functions

Page 18: X  Window

18

Window Manager• Manage window

– Decorate with standard look & feel – Control – move, ioconize, resize, ….

• Bookkeeping– DB of {N processes, N windows}– Stack, tile windows – hide/expose windows

• Mediates application’s competing requests

• Just a user level a.out (not kernel) – May have several -- twm fvwm ... – Select your choice

“move” “minimize”“resize” “full size”

Page 19: X  Window

19

X-server (Hardware side)• Just a user level a.out (not kernel)• [Input]

– event: HW kernel X server (daemon)– forwards to appropriate application process

• [Output]– message originates from applications (in X-window-

protocol)– decodes the X-window-protocol message (eg draw widget A) – calculates width of character, box, etc

• fonts are X-Server owned resource, font files are pre-loaded

– call low level functions to draw. (eg curses library)

“click”

“click”

“click”

hello

Too big to fit l

output request arrives in codewidget #3font #7

Page 20: X  Window

20

2 helping processes(1) X server process (for Display/Input Hardware)

Handles display output – manage window hierarchyHandles input (mouse, keyboard) events, forward to appropriate

processes

(2) Window Manager process (Mediate, Control Processes/Windows)

Displays decorative frame around top level window each with title allows users to manipulate top level windows

users can (move / resize / iconize / deiconize) windowsWindows layout

Mediates competing demands from many processes (hide, expose)

O Applications (User Program – excel, ppt, ..) Communicate with X server through X library -- create window, get

events Communicate with WM through X library -- specify title, …

[out][in]

[each]

[N]

Page 21: X  Window

21

Window Programming

Page 22: X  Window

22

Widgets (Internal Window)inside child window

a

b

c

Page 23: X  Window

23

TopLevel

window(email)

TopLevel

window(word)

TopLevel

window(web)

Rootwindow

a

b

c

Internal windows (“widgets”)

Window Hierarchy Tree

Page 24: X  Window

24

menu scrollbutton password

a

b

c Your password

*****

click drag click type in char2. Event:

1. Name:

3. Callback procedure: thread1() thread2() thread3() thread4()

(handler)

Widget classes(Internal windows)

Page 25: X  Window

25

Label Button

• Windows are made of widgets

• Each widget allows certain input events

• Each input events maps to handling function (callback procedure)

widget class example

Text

Page 26: X  Window

26

allowed events on widget classes

[widget name] [Description]-------------------------------------------------------------------Button - select by clickingScrollbar - user selects the region Textfield - user types textPassword - user types text but **** echoes Label - cannot receive inputMenu -

Page 27: X  Window

27

Event-driven programmingmain() /* eg word */{ W=XCreateWidget(); /* text-input */ XAdd_Callback(W, f1(), resource); /* register */ Xrealize_widget(); /* display */ XappMainLoop(); /* wait event*/}

Main_loop() /* handlers */{ case (keyboard_input) f1();

case (mouse_input) f2();}

NOTE-C compiler links with X Window library-library communicates with Window system during run

Page 28: X  Window

28

Window Library

WindowManager

X-Server

hardware

Interfacewith

Hardware

Interface with Application

X-Clients(child windows)

Window library

functions

Qt C++ library (KDE)GTK+ C library (GNOME)

Page 29: X  Window

29

Advanced window programming

Graphical front ends

automatically generates

Qt or GTK codesKdevelop

for Qt programs (KDE)

Gladefor GTK+ programs

(GNOME)

main() /* eg word */

{ ` W= XCreateWidget(); /* text-input */ XAdd_Callback(W, f1(), resource); /* register */

Xrealize_widget(); /* display */ XappMainLoop(); /* wait event*/}Main_loop() /* handlers */{ case (keyboard_input) f1();

case (mouse_input) f2();}

Page 30: X  Window

30

IDE (Integrated Development Environment)

Page 31: X  Window

31

Curses library

Page 32: X  Window

32

(1) Curses library – low leveleg draw a line move cursor create a window

(2) Window library – high level libraryeg draw menu widget resize child window event driven programming

Page 33: X  Window

33

Sample curses functions#include <curses.h>

main() {

initscr(); /* initialize a screen */

move(5, 15); /* move cursor to (x, y) position*/

printw(“%s”, “Hello!”); /* print a word at cursor position */

Hello!

Page 34: X  Window

34

OS kernel

HW

X-Server

(1) Mouse click

application program

(netscape)

Window Manager

(2)wake upX server

(3) deliver

Input

application program

(email)

[Hardware side] [Application side]

Page 35: X  Window

35

OS kernel

HW

X-Server

application program

(netscape)

Window

Managerapplication program

(word)

application program

(email)

application program

(vi)

(4) WM requestsdrawing

(1) generate output data call X library which sends data to WM

Output

(2) X library sends (as hints) to WM

(3) WM mediates requests

curseswrite(2)

draw(3)

Bitmap

[Hardware side] [Application side]

Page 36: X  Window

36

OS kernel

HW

X-Server

Hardware

X-Protocol

TCP/IP

Ethernet

[Display HW side][Application Process side]

local / remote

application program

OS kernel

X-library

X protocol is integrated with

TCP/IP

Page 37: X  Window

37

Starting X window

• startx command (script)

• Automatically during booting (graphic login)

Page 38: X  Window

38

OO can be …

• Kernel function– Slow – system call overhead– Hard to change (OS version)

• Library– Fastest (invocation overhead)– My program gets bigger

• Separate process (a.out, daemon, server)– Slowest (kernel IPC overhead, invocation overhead)– Flexible– kernel becomes smallest “micro-kernel”

• eg OO can be a command or kernel function or daemon

my kernel daemona.out a.out

Library Sys-call Process

OO