• Non ci sono risultati.

Xlib Fundamentals the concept of windows in X

N/A
N/A
Protected

Academic year: 2022

Condividi "Xlib Fundamentals the concept of windows in X"

Copied!
12
0
0

Testo completo

(1)

Xlib Fundamentals

the concept of windows in X

(2)

Windows in X X Window Programming Lab

Xlib Fundamentals

 Xlib is a set of library routines used to implement the basic X calls.

 X toolkits not only provide all the functionality of Xlib rou- tines and is much easier to use.

 It is still important to understand how the Xlib works.

- Creating and displaying the window - Drawing with X

- Text - Color - Events

J. Park 1/11 CSE 180 (U Penn)

(3)

Windows in X X Window Programming Lab

Windows are what X is all about

 Each window is a data structure stored in the X server.

 Identi ed by an ID of Window type (usually an unsigned 32 bit integer).

 To create a single window application 1. Connect to the server

2. Check the environment 3. Create the window

4. Display the window

| !!!! |

N. Destroy window and close the display

J. Park 2/11 CSE 180 (U Penn)

(4)

Windows in X X Window Programming Lab

Connecting to the server and Checking the environment

 Make the initial connection: XOpenDisplay()

Display *display;

display = XOpenDisplay ( (char *) NULL);

 Determine which screen you are connected to: DefaultScreen()

int screen;

screen = DefaultScreen(display);

 Ask the X server what the characteristics of the screen are:

DisplayWidth (display,screen) DisplayHeight (display,screen) DefaultDepth (display,screen)

J. Park 3/11 CSE 180 (U Penn)

(5)

Windows in X X Window Programming Lab

Creating the window

 XCreateSimpleWindow(), XCreateWindow()

#include <X11/Xlib.h>

Display *display;

Window parent_window;

int x, y;

unsigned int width, height;

unsigned int border_width;

int depth;

unsigned int class;

Visual *visual;

unsigned long valuemask;

XSetWindowAttributes *attributes;

window = XCreateWindow (display, parent_window, x, y, width, height, border_width, depth, class, valuemask, attributes );

J. Park 4/11 CSE 180 (U Penn)

(6)

Windows in X X Window Programming Lab

XCreateWindow()

 Returns the widow ID

 parameters:

{

target display

{

parent's id

{

desired pixel location of the TLC of this new window

{

size of the window in pixels

{

how wide the window's border should be (in pixels)

J. Park 5/11 CSE 180 (U Penn)

(7)

Windows in X X Window Programming Lab

{

number of bit planes available

{

class: InputOutput, InputOnly or CopyFromParent

{

The attributes structure contains 15 elds related to the window. The valuemask variable is a bit mask, indicating which of the 15 elds you have actually speci ed.

 background pixel - the color of the window background

 border pixel - the color of the window border

 event mask - ask for window expose events

 override redirect - allows you to override the window manager

J. Park 6/11 CSE 180 (U Penn)

(8)

Windows in X X Window Programming Lab

#include <X11/Xlib.h>

#include <X11/Xutil.h>

Display *display;

int screen;

XSetWindowAttributes attributes;

unsigned long attr_mask;

attributes.background_pixel = WhitePixel(display, screen);

attributes.border_pixel = BlackPixel(display, screen);

attributes.event_mask = ExposureMask;

attributes.override_redirect = False;

attr_mask = CWBackPixel | CWBorderPixel | CWEventMask | CWOverrideRedirect;

J. Park 7/11 CSE 180 (U Penn)

(9)

Windows in X X Window Programming Lab

Getting ready to display the window

 Before we can display the window we need to provide some hints about it to the window manager: data structure

XSize- Hints

{

As with XSetAttributes, there is a mask, this time stored inside the structure in the eld ags (e.g.,

USPosition - user speci ed x, y

USSize - user speci ed width, height PPosition - program speci ed position PSize - program speci ed size

PMinSize - min size PMaxSize - max size

PAspect - min and max aspect ratios)

J. Park 8/11 CSE 180 (U Penn)

(10)

Windows in X X Window Programming Lab

 Once the size hints have been set up they are passed to thewindow manager using the

XSetNormalHints

function.

Display * display;

Window window;

XSizeHints hints;

XSetNormalHints(display, window, &hints);

 Initialize the window's name (before we actually display the window) to be shown in the windows title bar:

XStoreName

function

Display * display;

Window window;

char window_name [ ];

XStoreName (display, window, window_name);

J. Park 9/11 CSE 180 (U Penn)

(11)

Windows in X X Window Programming Lab

Displaying the window



XMapWindow(), XMapRaised()

Display * display;

Window window;

XMapWindow(display,window);

XMapRaised(display,window);

 To be sure that the window is displayed we must ush the cache.

XFlush(display);

J. Park 10/11 CSE 180 (U Penn)

(12)

Windows in X X Window Programming Lab

Cleaning up

 Once our program has nished we should destroy all windows and close the display.

XDestroyWindow(display, window);

XCloseDisplay(display);

J. Park 11/11 CSE 180 (U Penn)

Riferimenti

Documenti correlati

We show the existence and asymptotic behav- ior of a saddle solution on the entire plane, which has odd symme- try with respect to both axes, and even symmetry with respect to the

Quanti individui dovranno essere sottoposti all’analisi del DNA affinch´e, con prob- abilit`a maggiore o uguale di 0.75, almeno 40 di essi siano portatori della mutazione.. Qual `e

(b) Supponiamo che un secondo testimone abbia dichiarato che il taxi era giallo, e che la correttezza dell’identificazione corretta del colore da parte di questo testimone sia

esista, nel secondo

Per` o, dato un insieme numerabile A, la questione di trovare una esplicita funzione biettiva f : N → A, o, dati due insieme numerabili A e B, il trovare una esplicita funzione

Riassumiamo in un grafico lo studio

Tracciamento della retta in base al passaggio per 2 punti (si ricordi che con asse delle ascisse cartesiano e relativo alla variabile Y nulla cambia rispetto alla carta

[r]