1 /* Copyright (C) 2000-2002 Damir Zucic */
2
3 /*=============================================================================
4
5 display_init.c
6
7 Purpose:
8 Display initializations: connect to X server, get default screen ID
9 and screen size. In addition, prepare the three graphics contexts.
10
11 Input:
12 (1) Pointer to GUIS structure (with GUI data).
13
14 Output:
15 (1) Data stored to GUIS structure.
16 (2) Return value.
17
18 Return value:
19 (1) Positive on success.
20 (2) Negative on failure (if attempt to connect to X server fails).
21
22 =============================================================================*/
23
24 #include <stdio.h>
25
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <X11/Xos.h>
29 #include <X11/Xatom.h>
30
31 #include "defines.h"
32 #include "typedefs.h"
33
34 /*======initialize display:==================================================*/
35
DisplayInit_(GUIS * guiSP)36 int DisplayInit_ (GUIS *guiSP)
37 {
38
39 /* Connect to X server: */
40 if ((guiSP->displaySP = XOpenDisplay (guiSP->display_nameP)) == NULL)
41 {
42 return -1;
43 }
44
45 /* Default screen for given display: */
46 guiSP->screenID = DefaultScreen (guiSP->displaySP);
47
48 /* Default screen size: */
49 guiSP->screen_width = DisplayWidth (guiSP->displaySP, guiSP->screenID);
50 guiSP->screen_height = DisplayHeight (guiSP->displaySP, guiSP->screenID);
51
52 /* Ten graphics contexts: */
53 guiSP->theGCA[0] = XCreateGC (guiSP->displaySP,
54 DefaultRootWindow (guiSP->displaySP),
55 0, NULL);
56 guiSP->theGCA[1] = XCreateGC (guiSP->displaySP,
57 DefaultRootWindow (guiSP->displaySP),
58 0, NULL);
59 guiSP->theGCA[2] = XCreateGC (guiSP->displaySP,
60 DefaultRootWindow (guiSP->displaySP),
61 0, NULL);
62 guiSP->theGCA[3] = XCreateGC (guiSP->displaySP,
63 DefaultRootWindow (guiSP->displaySP),
64 0, NULL);
65 guiSP->theGCA[4] = XCreateGC (guiSP->displaySP,
66 DefaultRootWindow (guiSP->displaySP),
67 0, NULL);
68 guiSP->theGCA[5] = XCreateGC (guiSP->displaySP,
69 DefaultRootWindow (guiSP->displaySP),
70 0, NULL);
71 guiSP->theGCA[6] = XCreateGC (guiSP->displaySP,
72 DefaultRootWindow (guiSP->displaySP),
73 0, NULL);
74 guiSP->theGCA[7] = XCreateGC (guiSP->displaySP,
75 DefaultRootWindow (guiSP->displaySP),
76 0, NULL);
77 guiSP->theGCA[8] = XCreateGC (guiSP->displaySP,
78 DefaultRootWindow (guiSP->displaySP),
79 0, NULL);
80 guiSP->theGCA[9] = XCreateGC (guiSP->displaySP,
81 DefaultRootWindow (guiSP->displaySP),
82 0, NULL);
83
84 guiSP->gca_createdF = 1;
85
86 /* Return positive value on success: */
87 return 1;
88 }
89
90 /*===========================================================================*/
91
92
93