Week 11 6/2/02 1 X11 Window System 6/2/02 2 Benefits of X n - - PDF document

week 11
SMART_READER_LITE
LIVE PREVIEW

Week 11 6/2/02 1 X11 Window System 6/2/02 2 Benefits of X n - - PDF document

Week 11 6/2/02 1 X11 Window System 6/2/02 2 Benefits of X n network transparency n clients on one host can use the display of another n is network independent n needs a reliable stream connection n device independence n X clients will work


slide-1
SLIDE 1

1

6/2/02 1

Week 11

6/2/02 2

X11 Window System

6/2/02 3

Benefits of X

n network transparency

n clients on one host can use the display of another

n is network independent

n needs a reliable stream connection

n device independence

n X clients will work with any X server

n is policy-free

n provides “mechanism without policy”

slide-2
SLIDE 2

2

6/2/02 4

X is policy-free

n the server provides minimal but complete

functionality

n the user interface is provided by the client

n Application Interface:

n the application is allocated a window n sends draw request to the server n gets events related to its own windows

n Management Interface:

n the server does not manage window placements n the manager client does this n changing window manager changes the management

interface

6/2/02 5

Drawbacks

n is HUGE n is hard to approach n is quiet COMPLICATED

6/2/02 6

screen

Xserver

keyboard mouse client client client X11 protocol device driver display

slide-3
SLIDE 3

3

6/2/02 7

The Server

n Runs on a host where the hardware is n Manages Input Devices

n pointers: Mouse/tablet n Keyboard

n Manages Output Devices

n Display Frame Buffer

n Process X Protocol requests from clients n send events to clients

6/2/02 8

a Client

n runs on any host that has connectivity to the

server

n is the Application, including the user interface

n Menus n Interaction techniques n Drawing n Handling input

n interprets the X Protocol

n sending requests n receiving events

6/2/02 9

Software Layers

X Protocol Xlib Xt Intrinsics Widgets

Application

slide-4
SLIDE 4

4

6/2/02 10

Software Layers …

1.

X Protocol: the actual byte stream that goes between the client & server

2.

Xlib: a C library interface to the X Protocol

3.

Xt Intrinsics: a C library for using & constructing widgets

4.

Widgets: a collection of user interface abstractions

  • widget: a reusable, configurable piece of code.
  • a collection of widgets is also called a toolkit

6/2/02 11

Event-Driven Programming

n X event

n is a data structure sent by the server that

describes something that just happened that may be of interest to the application.

6/2/02 12

Terminology

child window height width x y

parent window screen

slide-5
SLIDE 5

5

6/2/02 13

a Window

n is a rectangular area of the screen n may contain one or more child windows n a parent window clips all child windows n appears when it’s mapped n disappears when it’s unmapped

6/2/02 14

Window …

1.

parent: windows in an application form a tree.

  • a window lies within the coordinate space of its parent
  • all portions of a window that are beyond its parent’s boundary

are clipped

2.

window ID: an integer that identifies the window.

3.

position: the location of the upper left corner within the parent’s coordinate system.

4.

width, height and border width: measured in pixels

5.

coordinate system: each window has its own system.

6.

attributes: background/foreground color, border color, cursor …

6/2/02 15

Event

n is the means by which the server informs the client

  • f user input

n when the user does something - moves the mouse,

presses a key, … - the server translates these actions into events, and sends them to the appropriate client(s)

n events are only sent to clients which have

specifically asked to be informed of that type of event

n clients can force events to be sent to other clients n are typically reported relative to a window

slide-6
SLIDE 6

6

6/2/02 16

Widget

n a user interface abstraction

n implements some part of a user interface

n menu, scrollbar, text entry, …

n each widget has a window

n where it displays its information n where it reacts to user actions

6/2/02 17

shell widget command button widget text widget composite widget main application window or widget pop-up shell widget label widget

6/2/02 18

Widgets …

n Shell widgets:

n is used as the parent of all other application

widgets

n includes functionality that allows to interact

with the window manager

n is invisible

n popup dialog box:

n is a widget that appears temporarily on the

screen, until the user provides some input

slide-7
SLIDE 7

7

6/2/02 19

Resources

n is a named piece of data, usually part of a

widget

n the user or application can set value of a

widget

n mainly used to control widgets n the resource manager/resource database

n part of the xlib which is responsible to

manage/read/provide resource information.

6/2/02 20

Callbacks

n an application procedure associated

with a widget

n it’s called when something happens in

a widget

n button pressed, scrollbar moved

n main communication mechanism

between widget and application

6/2/02 21

Widget Classes

n a widget set defines classes of widgets n all widgets belong to a widget class n all widgets in a class have:

n the same basic appearance n and behave in the same way

n are like objects and classes in oop

slide-8
SLIDE 8

8

6/2/02 22

Widget Sets/Toolkits

n a toolkit is a set of widgets that work

together

n there are many

n Athena n Motif n DCE n KDE n GNOME n …

6/2/02 23

#include <X11/Xlib.h> int main() { Display *dsp = XOpenDisplay(NULL); if(!dsp) { return 1; } int screenNumber = DefaultScreen(dsp); unsigned long white = WhitePixel(dsp,screenNumber); unsigned long black = BlackPixel(dsp,screenNumber); Window win = XCreateSimpleWindow(dsp, DefaultRootWindow(dsp), 50, 50, 200, 200, 0, black, white); XMapWindow(dsp, win); long eventMask = StructureNotifyMask; XSelectInput( dsp, win, eventMask ); XEvent evt; do { XNextEvent(dsp, &evt); } while(evt.type != MapNotify); GC gc = XCreateGC( dsp, win, 0, NULL ); XSetForeground( dsp, gc, black ); XDrawLine(dsp, win, gc, 10, 10,190,190); XDrawLine(dsp, win, gc, 10,190,190, 10); eventMask = ButtonPressMask|ButtonReleaseMask; XSelectInput(dsp, win, eventMask); do { XNextEvent( dsp, &evt ); } while(evt.type != ButtonRelease); XDestroyWindow(dsp, win); XCloseDisplay(dsp); return 0; }

6/2/02 24

#include <X11/Xlib.h> int main() { Display *dsp = XOpenDisplay(NULL); if(!dsp) { return 1; } int screenNumber = DefaultScreen(dsp); unsigned long white = WhitePixel(dsp, screenNumber); unsigned long black = BlackPixel(dsp, screenNumber); Window win = XCreateSimpleWindow(dsp, DefaultRootWindow(dsp), 50, 50, 200, 200, 0, black, white); XMapWindow(dsp, win); defines structures, macros, function prototypes

host:server.screen

x,y coordinates width, height width and color of the border color of the backgound

makes the window visible

slide-9
SLIDE 9

9

6/2/02 25

long eventMask = StructureNotifyMask; XSelectInput(dsp, win, eventMask ); XEvent evt; do { XNextEvent(dsp, &evt); } while(evt.type != MapNotify);

wait till the window gets mapped flushes all output buffers

6/2/02 26

GC gc = XCreateGC(dsp, win, 0, NULL); XSetForeground(dsp, gc, black); XDrawLine(dsp, win, gc, 10, 10, 190,190); XDrawLine(dsp, win, gc, 10,190, 190, 10);

  • Graphics Context:
  • information about appearance
  • color, linestyle, …

6/2/02 27

eventMask = ButtonPressMask|ButtonReleaseMask; XSelectInput(dsp, win, eventMask); do { XNextEvent(dsp, &evt); } while(evt.type != ButtonRelease); XDestroyWindow(dsp, win); XCloseDisplay(dsp); return 0; }

slide-10
SLIDE 10

10

6/2/02 28

#include <X11/Xlib.h> int main() { Display *dsp = XOpenDisplay(NULL); if(!dsp) { return 1; } int screenNumber = DefaultScreen(dsp); unsigned long white = WhitePixel(dsp,screenNumber); unsigned long black = BlackPixel(dsp,screenNumber); Window win = XCreateSimpleWindow(dsp, DefaultRootWindow(dsp), 50, 50, 200, 200, 0, black, white); XMapWindow(dsp, win); long eventMask = StructureNotifyMask; XSelectInput( dsp, win, eventMask ); XEvent evt; do { XNextEvent(dsp, &evt); } while(evt.type != MapNotify); GC gc = XCreateGC( dsp, win, 0, NULL ); XSetForeground( dsp, gc, black ); XDrawLine(dsp, win, gc, 10, 10,190,190); XDrawLine(dsp, win, gc, 10,190,190, 10); eventMask = ButtonPressMask|ButtonReleaseMask; XSelectInput(dsp, win, eventMask); do { XNextEvent( dsp, &evt ); } while(evt.type != ButtonRelease); XDestroyWindow(dsp, win); XCloseDisplay(dsp); return 0; }

6/2/02 29

tcl/tk

wm title . "two lines" canvas .c -width 200 -height 200 pack .c .c create line 10 10 190 190 .c create line 10 190 190 10 bind .c <Button> exit