3 #include <X11/keysym.h>
8 _eglutNativeInitDisplay(void)
10 _eglut
->native_dpy
= XOpenDisplay(_eglut
->display_name
);
11 if (!_eglut
->native_dpy
)
12 _eglutFatal("failed to initialize native display");
14 _eglut
->surface_type
= EGL_WINDOW_BIT
;
18 _eglutNativeFiniDisplay(void)
20 XCloseDisplay(_eglut
->native_dpy
);
24 _eglutNativeInitWindow(struct eglut_window
*win
, const char *title
,
25 int x
, int y
, int w
, int h
)
27 XVisualInfo
*visInfo
, visTemplate
;
30 XSetWindowAttributes attr
;
34 if (!eglGetConfigAttrib(_eglut
->dpy
,
35 win
->config
, EGL_NATIVE_VISUAL_ID
, &vid
))
36 _eglutFatal("failed to get visual id");
38 /* The X window visual must match the EGL config */
39 visTemplate
.visualid
= vid
;
40 visInfo
= XGetVisualInfo(_eglut
->native_dpy
,
41 VisualIDMask
, &visTemplate
, &num_visuals
);
43 _eglutFatal("failed to get an visual of id 0x%x", vid
);
45 root
= RootWindow(_eglut
->native_dpy
, DefaultScreen(_eglut
->native_dpy
));
47 /* window attributes */
48 attr
.background_pixel
= 0;
49 attr
.border_pixel
= 0;
50 attr
.colormap
= XCreateColormap(_eglut
->native_dpy
,
51 root
, visInfo
->visual
, AllocNone
);
52 attr
.event_mask
= StructureNotifyMask
| ExposureMask
| KeyPressMask
;
53 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
55 xwin
= XCreateWindow(_eglut
->native_dpy
, root
, x
, y
, w
, h
,
56 0, visInfo
->depth
, InputOutput
, visInfo
->visual
, mask
, &attr
);
58 _eglutFatal("failed to create a window");
62 /* set hints and properties */
69 sizehints
.flags
= USSize
| USPosition
;
70 XSetNormalHints(_eglut
->native_dpy
, xwin
, &sizehints
);
71 XSetStandardProperties(_eglut
->native_dpy
, xwin
,
72 title
, title
, None
, (char **) NULL
, 0, &sizehints
);
75 XMapWindow(_eglut
->native_dpy
, xwin
);
77 win
->native
.u
.window
= xwin
;
78 win
->native
.width
= w
;
79 win
->native
.height
= h
;
83 _eglutNativeFiniWindow(struct eglut_window
*win
)
85 XDestroyWindow(_eglut
->native_dpy
, win
->native
.u
.window
);
89 lookup_keysym(KeySym sym
)
95 special
= EGLUT_KEY_F1
;
98 special
= EGLUT_KEY_F2
;
101 special
= EGLUT_KEY_F3
;
104 special
= EGLUT_KEY_F4
;
107 special
= EGLUT_KEY_F5
;
110 special
= EGLUT_KEY_F6
;
113 special
= EGLUT_KEY_F7
;
116 special
= EGLUT_KEY_F8
;
119 special
= EGLUT_KEY_F9
;
122 special
= EGLUT_KEY_F10
;
125 special
= EGLUT_KEY_F11
;
128 special
= EGLUT_KEY_F12
;
132 special
= EGLUT_KEY_LEFT
;
136 special
= EGLUT_KEY_UP
;
140 special
= EGLUT_KEY_RIGHT
;
144 special
= EGLUT_KEY_DOWN
;
155 next_event(struct eglut_window
*win
)
160 if (!XPending(_eglut
->native_dpy
)) {
166 XNextEvent(_eglut
->native_dpy
, &event
);
168 switch (event
.type
) {
172 case ConfigureNotify
:
173 win
->native
.width
= event
.xconfigure
.width
;
174 win
->native
.height
= event
.xconfigure
.height
;
176 win
->reshape_cb(win
->native
.width
, win
->native
.height
);
184 r
= XLookupString(&event
.xkey
,
185 buffer
, sizeof(buffer
), &sym
, NULL
);
186 if (r
&& win
->keyboard_cb
) {
187 win
->keyboard_cb(buffer
[0]);
189 else if (!r
&& win
->special_cb
) {
190 r
= lookup_keysym(sym
);
201 _eglut
->redisplay
= redraw
;
205 _eglutNativeEventLoop(void)
208 struct eglut_window
*win
= _eglut
->current
;
212 if (_eglut
->redisplay
) {
213 _eglut
->redisplay
= 0;
217 eglSwapBuffers(_eglut
->dpy
, win
->surface
);