OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/logging.h" | 5 #include "base/logging.h" |
6 #include "main.h" | 6 #include "main.h" |
7 #include "xlib_window.h" | 7 #include "xlib_window.h" |
8 | 8 |
9 | 9 |
10 Display *g_xlib_display = NULL; | 10 Display *g_xlib_display = NULL; |
11 Window g_xlib_window = 0; | 11 Window g_xlib_window = 0; |
12 XVisualInfo *g_xlib_visinfo = NULL; | |
13 | 12 |
14 GLint g_width = 512; | 13 GLint g_width = 512; |
15 GLint g_height = 512; | 14 GLint g_height = 512; |
16 bool g_override_redirect = true; | 15 bool g_override_redirect = true; |
17 | 16 |
18 | 17 |
19 bool XlibInit() { | 18 bool XlibInit() { |
20 g_xlib_display = XOpenDisplay(0); | 19 g_xlib_display = XOpenDisplay(0); |
21 if (!g_xlib_display) | 20 if (!g_xlib_display) |
22 return false; | 21 return false; |
23 | 22 |
24 int screen = DefaultScreen(g_xlib_display); | 23 int screen = DefaultScreen(g_xlib_display); |
25 Window root_window = RootWindow(g_xlib_display, screen); | 24 Window root_window = RootWindow(g_xlib_display, screen); |
26 | 25 |
27 XWindowAttributes attributes; | 26 XWindowAttributes attributes; |
28 XGetWindowAttributes(g_xlib_display, root_window, &attributes); | 27 XGetWindowAttributes(g_xlib_display, root_window, &attributes); |
29 | 28 |
30 g_width = g_width == -1 ? attributes.width : g_width; | 29 g_width = g_width == -1 ? attributes.width : g_width; |
31 g_height = g_height == -1 ? attributes.height : g_height; | 30 g_height = g_height == -1 ? attributes.height : g_height; |
32 | 31 XVisualInfo* xlib_visinfo = GetXVisual(); |
33 XVisualInfo vinfo_template; | |
34 memset(&vinfo_template, sizeof(vinfo_template), 0); | |
35 vinfo_template.visualid = GetVisualID(); | |
36 int nitems; | |
37 g_xlib_visinfo = XGetVisualInfo(g_xlib_display, | |
38 VisualIDMask, &vinfo_template, &nitems); | |
39 CHECK(nitems == 1); | |
40 | 32 |
41 unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | | 33 unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | |
42 CWOverrideRedirect; | 34 CWOverrideRedirect; |
43 XSetWindowAttributes attr; | 35 XSetWindowAttributes attr; |
44 attr.background_pixel = 0; | 36 attr.background_pixel = 0; |
45 attr.border_pixel = 0; | 37 attr.border_pixel = 0; |
46 attr.colormap = XCreateColormap(g_xlib_display, root_window, | 38 attr.colormap = XCreateColormap(g_xlib_display, root_window, |
47 g_xlib_visinfo->visual, AllocNone); | 39 xlib_visinfo->visual, AllocNone); |
48 attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; | 40 attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; |
49 attr.override_redirect = g_override_redirect ? True : False; | 41 attr.override_redirect = g_override_redirect ? True : False; |
50 g_xlib_window = XCreateWindow(g_xlib_display, root_window, | 42 g_xlib_window = XCreateWindow(g_xlib_display, root_window, |
51 0, 0, g_width, g_height, 0, | 43 0, 0, g_width, g_height, 0, |
52 g_xlib_visinfo->depth, InputOutput, | 44 xlib_visinfo->depth, InputOutput, |
53 g_xlib_visinfo->visual, mask, &attr); | 45 xlib_visinfo->visual, mask, &attr); |
54 | 46 |
55 XMapWindow(g_xlib_display, g_xlib_window); | 47 XMapWindow(g_xlib_display, g_xlib_window); |
56 XSync(g_xlib_display, True); | 48 XSync(g_xlib_display, True); |
57 | 49 |
58 XGetWindowAttributes(g_xlib_display, g_xlib_window, &attributes); | 50 XGetWindowAttributes(g_xlib_display, g_xlib_window, &attributes); |
59 g_width = attributes.width; | 51 g_width = attributes.width; |
60 g_height = attributes.height; | 52 g_height = attributes.height; |
61 | 53 |
| 54 XFree(xlib_visinfo); |
| 55 |
62 return true; | 56 return true; |
63 } | 57 } |
OLD | NEW |