Top Banner
Windowing Systems (using X Windows as case study) GUI Architecture Base Window System Window Manager Windowing Systems 1
30

Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Jun 27, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Windowing Systems

(using X Windows as case study)

GUI Architecture

Base Window System

Window Manager

Windowing Systems 1

Page 2: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Windowing System

Handles input device events

- keyboard (text) and pointing (mouse/touchpage)

Exposes output methods to display graphics

- basic drawing primitives, bitmaps, text

Manages windows as a place for visual application content

- methods to resize, re-order, re-draw windows

- control what application has access to content area

A windowing system provides “low-level” input, output and window

management capabilities to the operating system.

Windowing Systems 2

Page 3: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

X Windows

Windowing Systems 3

X Windows

Developed in 1984 (based on MIT Athena project) by a consortium of

companies.

Standard windowing system for Unixes.

Free and cross-platform (OS, processor agnostic)

One of the most successful free-software projects, ever.

Page 4: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

X Windows

Unix standard Windowing System

- handles input, draws graphics, creates windows, …

- free and cross-platform (os, processor, form factor)

Essentially a protocol

- does not specify style of user interface

- not a “window manager” (no default look and feel)

A windowing system provides “low-level” input, output and window

management capabilities to the operating system.

Windowing Systems 4

Page 5: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

X Windows Design Criteria

Windowing Systems 5

Implementable on a variety of displays

Applications must be device independent

Must be network transparent

Support multiple, concurrent application displays

Support output to overlapping windows

(… even when partially obscured)

Support a hierarchy of resizable windows

(… an application can use many windows at once)

Support many different applications

High-performance, high-quality text, 2-D graphics, imaging

System should be extensible

Page 6: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

X Client-Server Architecture

Windowing Systems 6

Separate the user interface from applications:

- an X Client handles all application logic

- an X Server handles all display output and user input

Server handles request from client, process data as requested, and

returns results to client

X inverts conventional www server and client relationship

- (in www, web browser is the “client”, web site is the “server”)

Page 7: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Why Client-Server?

Windowing Systems 7

Goal was flexibility and economy

- Many X Clients (perhaps on multiple machines)

- One X Server that delivers the user interface

X Clients

X Server

Page 8: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

X Windows as MVC Architecture

Windowing Systems 8

X Client

X Server

Output

X Server

Input

notify

change

huh…?

translate

present

perceive

express

View

Controller

Model

Page 9: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Displays, Screens, Windows

Windowing Systems 9

A display may have multiple screens

A display may have multiple windows

A window may cross multiple screens

Page 10: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Structure of a Typical X Program

Windowing Systems 11

perform X Client initialization

connect to the X Server

perform X related initialization

event loop:

get next event from the X Server

handle the event:

if the event was a quit message, exit the loop

do any client-initiated work

send drawing requests to the X Server

close down the connection to the X Server

perform client cleanup

Page 11: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Xlib

Windowing Systems 12

library to wrap low level X Window protocol

- to avoid implementing message passing for every new program

uses buffered input and output queues

- need to flush them: XSync, XFlush

Xlib functions:

- connection operations: e.g. XOpenDisplay, XCloseDisplay, …

- connection operation requests: e.g. XCreateWindow, XCreateGC,…

- connection information requests: e.g. XGetWindowProperty, …

- local event queue operations: e.g. XNextEvent, XPeekEvent, …

- local data operations: e.g. XLookupKeysym, XParseGeometry,

XSetRegion, XCreateImage, XSaveContext, …

Xlib data types:

- e.g. Display, Window, GC, XSizeHints, XWhitePixel, XBlackPixel,

etc.

Page 12: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Running and Compiling X Windows Applications

Windowing Systems 13

Start X Server

- already running on Ubuntu VM

- need XQuartz (macOS) or XMing (Windows)

(assignment code must run on VM)

Test by running X demos (xeyes, xclock, …)

xeyes

Compile and run an X application, e.g.

g++ -o null null.cpp -L/usr/X11R6/lib -lX11 -lstdc++

./null

Page 13: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

null.min.cpp: opens and closes a “display”

Windowing Systems 14

#include <cstdlib>#include <iostream>#include <X11/Xlib.h> // main Xlib header

Display* display;

int main() {display = XOpenDisplay(""); // open using DISPLAY env varif (display == NULL) {

std::cout << "error\n";exit (-1);

} else {std::cout << "success!\n";

XCloseDisplay(display); // close display}

}

Page 14: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

openwindow.min.cpp: Display a Window

Windowing Systems 15

Display* display;Window window; // save the window id

int main( int argc, char* argv[] ) {display = XOpenDisplay(""); // open displayif (!display) exit (-1); // couldn't open, so bailint screen = DefaultScreen(display);// info about the displaywindow = XCreateSimpleWindow(

display, DefaultRootWindow(display), // window's parent10, 10, // location: x,y400, 300, // size: width, height2, // width of borderBlackPixel(display, screen), // foreground colourWhitePixel(display, screen)); // background colour

XMapRaised(display, window); // put window on screenXFlush(display); // flush the output bufferstd::cout << "ENTER"; std::cin.get(); // wait for inputXCloseDisplay(display);

}

Page 15: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Makefiles

Windowing Systems 16

You need makefiles for all assignments

- re-use the one in the code demos by setting NAME

- learn more: http://www.oreilly.com/openbook/make3/book/

# super simple makefile# call it using 'make NAME=name_of_code_file_without_extension'# (assumes a .cpp extension)NAME = "null.min"

all:@echo "Compiling..."g++ -o $(NAME) $(NAME).cpp -L/usr/X11R6/lib -lX11 -lstdc++

run: all@echo "Running..."./$(NAME)

Page 16: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Lecture Code vs. Assignment Code

Windowing Systems 17

You can find Lecture Code

- https://git.uwaterloo.ca/kkatsura/cs349_w18_examples

All code examples tested on VM

- reasonably generic, but you may need to tweak some things if you

want to program on your own computer

… remember that all assignments must run on VM

Code examples use C, C-like C++, some OO C++

- you can use C or C++, but consider using <string>, <vector>,

<iostream>, bool instead of int, // for comments, define variables

near the place you first use them, etc.

Lecture code is terse, your code should be much cleaner, more

structured, and well commented

- TAs will look at your assignment source code

Page 17: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Code Review: openwindow.cpp

Windowing Systems 18

Same Functions/Macros and procedures as min verson:

- XOpenDisplay

- DefaultScreen

- XWhitePixel, XBlackPixel

- XCreateSimpleWindow

- XSetStandardProperties

- XMapRaised

- XFlush

Difference is cleaner coding practice, but longer code

Page 18: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

X Windows with Remote Client

Start local X Server (already running in Linux)

Connect to remote X Client machine

(-Y is needed for ssh forwarding)

ssh -Y [email protected]

Test by running X demos

xclock

when you run an X Client on a server,

it uses your local machine as the X Server!

Windowing Systems 19

Page 19: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Before Windowing Systems

Windowing Systems 20

Systems typically ran a single “full screen” application

Page 20: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

After Windowing Systems

Windowing Systems 21

Programs can run simultaneously, each with their own separate window.

Windows can exist side-by-side or overlap one another. Input is directed to the correct window by the windowing system.

Page 21: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Windowing System Architecture

Windowing Systems 22

xeyes xclockxclock xcalc

Page 22: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Base Window System (BWS)

Windowing Systems 23

Lowest level abstraction for windowing system

Routines for creating, destroying, managing windows

Routes mouse and keyboard input to correct window

- only one window “has focus” to receive input

Ensures only one application changing frame buffer (video memory)

at a time

- one reason why single-threaded / non-thread-safe GUI architectures

are popular

xeyes xclockxclock xcalc

Page 23: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

(o, o)

+x

+y

(o, o)+x

+y

Canvas Abstraction

Windowing Systems 24

BWS controls application’s access to window contents using a

“drawing canvas abstraction”

The application is shielded from details of frame buffer, visibility of

window, and all other application windows

Each window has its own coordinate system

- BWS transforms between global

(screen) and local (window)

coordinate systems

- Window doesn’t worry

where it is on screen; program

assumes its top-left is (0,0)

BWS provides access to graphics

routines for drawing

Page 24: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Window Manager

Windowing Systems 25

Provides conceptually different functionality

- Layered on top of Base Window System

- Provides interactive components for windows (menus, close box,

resize capabilities)

- Creates the “look and feel” of each window

Application ”owns” the contents of the window, but the WM “owns” the

application window itself!

xeyes xclockxclock xcalc

Page 25: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Window Manager

Windowing Systems 26

Window vs. Canvas

- the window manager owns the window (including its controls)

- the application owns the canvas

owned by

application

owned by window

manager

Page 26: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Why Separate BWS from Window Manager?

Windowing Systems 27

Enables alternative “look and feels” for windowing system

(i.e. “Desktops” like Unity, GNOME, KDE, Xfce…)

Enables different windowing paradigms

(i.e. Xmonad for tiled windows)

More robust, since BWS and WM are separate processes

Page 27: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

N-Windows - VR Virtual Desktop Prototype

- https://youtu.be/YoFmszqILd4

Windowing Systems 28

Page 28: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Separate vs. Combined Window Managers

Windowing Systems 29

macOS, Windows combine “BWS” and Window Manager together (or

at least, don’t distinguish)

Trade-offs in approaches?

- Look and feel…

- Window management possibilities…

Conceptually, on both platforms, there is a separation of canvas

(assigned to application) and window decoration/OS overlay handled

by window manager

- Lines do blur when combined, however

Page 29: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Modern GUI Architectures

Windowing Systems 30

X Windows was developed when computation was expensive

- large centralized server (the X Clients)

- low cost graphical terminals (the X Server)

When computation became cheap, assumptions changed:

- desktop computer acts as X Windows client and server

Now, web and mobile Applications are more like X Windows

- application “backend” and user interface “frontend”

Page 30: Basic Single-Window Xcs349/w18...X Client-Server Architecture Windowing Systems 6 Separate the user interface from applications:-an X Client handles all application logic-an X Server

Summary

Windowing Systems 31

X Windows architecture (client, server, network)

X Windows programming: opening, disposing

Base Window System and Window Manager