cs349 - s10 - Lecture 2
CS349 -
Implementing User Interfaces - Spring 2010
Public Service Annoucements
- Course notes
- Assignments
Lecture 2 - Graphics Abstractions for User Interfaces
Hardware
An operating system provides, among other things, an abstraction of the
hardware in the form of
- an API (application programming interface), which is
- a set of function calls that exercise the hardware, as
if the abstraction is a complete description of the
hardware.
When there is a user interface, this includes the hardware that provides
the interface
- output
- visual display for graphics and text
- speakers for audio output
- force-generating devices for tactile output
- mechanical devices for proprioceptive output
- etc
- input
The base window system (BWS) provides the lowest level abstraction, which
consists of
- a display screen divided into a rectangular array of
pixels, which includes
- an audio device, which includes
- a collection of button devices
- each is either pressed or not pressed
- API
down = button-pressed( )
- a collection of pointing devices, each of which includes
- a coordinate system
- a location in the coordinate system
- API
x, y = where-is( )
The input devices, the last two, have an interesting feature
- time is taken for granted
- using the OS abstraction of time
- time = get-time-of-day( )
sequences of samples can be organized into trajectories
And one problematic feature
- It is hard to write application software without polling.
Events
To avoid the necessity for polling
- sometimes polling is desirable
most BWSs abstract input into a time-ordered sequence of events, usually
called the event queue.
Data structure
typedef struct{
int time;
Type type;
Whatever parameters;
} Event;
API
evt = get-next-event( );
- This is blocking, like
getch( )
The Event Loop
Basic code structure
evt = get-next-event( ) {
switch( evt.type ) {
case KEYSTROKE:
if ( evt.parameters.byte == 'q' ) exit( 0 );
...
}
This is made for an object-oriented programming style, which is why we
like Java.
X
X is a BWS based on a network. That is,
- The interface hardware may be connected to the application over the
internet.
- Thus, X is a protocol for transmitting I/O over a network
- which means, between two well-separated components
- the BWS, and
- the application program.
- On the BWS side
- the X-server creates and encodes events that are
sent to the application;
- the X-server receives encoded drawing commands and
draws on the display.
- On the application side
- the X-client uses an API that provides events and
accepts drawing commands
- Xlib provides the implementation of the API,
maintaining local state, and transmitting/receiving
X-protocol messages with the X-server.
Many properties of X are the side effects of reducing communication
bandwidth between the X-server and its clients.
Return to: