X Window
description
Transcript of X Window
1
X Window
제 10 강 : X Windows
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
3
Linux Desktop EnvironmentsKDE & GNOME
4
sh
a.out
kernel
a.out
window
X window is just a plain application program
command (utility) child process of sh
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
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
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
8
Root window(entire screen)
Root Window
9
Root window(entire screen)
Top level windows or Child windows(per each process)
Child Windows
10
X-Window Protocol
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
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
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
14
X-Window Processes
15
2 kind of processes
X-ServerApplication
X-Client
requestdrawing
deliverevent
screenkeyboard
mouse
hardware
requestdrawing
16
Window Managera special client process
WindowManager
requestdrawing
deliverevent
screenkeyboard
mouse
X-Server
hardware
X-Clients
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
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”
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
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]
21
Window Programming
22
Widgets (Internal Window)inside child window
a
b
c
23
TopLevel
window(email)
TopLevel
window(word)
TopLevel
window(web)
Rootwindow
a
b
c
Internal windows (“widgets”)
Window Hierarchy Tree
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)
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
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 -
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
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)
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();}
30
IDE (Integrated Development Environment)
31
Curses library
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
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!
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]
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]
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
37
Starting X window
• startx command (script)
• Automatically during booting (graphic login)
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