• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #include "tests/cefclient/browser/temp_window_x11.h"
6 
7 #include <X11/Xlib.h>
8 
9 #include "include/base/cef_logging.h"
10 #include "include/cef_app.h"
11 
12 namespace client {
13 
14 namespace {
15 
16 // Create the temp window.
CreateTempWindow()17 ::Window CreateTempWindow() {
18   ::Display* xdisplay = cef_get_xdisplay();
19   CHECK(xdisplay != 0);
20   ::Window parent_xwindow = DefaultRootWindow(xdisplay);
21 
22   XSetWindowAttributes swa;
23   memset(&swa, 0, sizeof(swa));
24   swa.background_pixmap = None;
25   swa.override_redirect = false;
26   return XCreateWindow(xdisplay, parent_xwindow, 0, 0, 1, 1,  // size (1x1px)
27                        0,                                     // border width
28                        CopyFromParent,                        // depth
29                        InputOutput,
30                        CopyFromParent,  // visual
31                        CWBackPixmap | CWOverrideRedirect, &swa);
32 }
33 
34 // Close the temp window.
CloseTempWindow(::Window xwindow)35 void CloseTempWindow(::Window xwindow) {
36   ::Display* xdisplay = cef_get_xdisplay();
37   CHECK(xdisplay != 0);
38   XDestroyWindow(xdisplay, xwindow);
39 }
40 
41 TempWindowX11* g_temp_window = nullptr;
42 
43 }  // namespace
44 
TempWindowX11()45 TempWindowX11::TempWindowX11() : xwindow_(kNullWindowHandle) {
46   DCHECK(!g_temp_window);
47   g_temp_window = this;
48 
49   xwindow_ = CreateTempWindow();
50   CHECK(xwindow_);
51 }
52 
~TempWindowX11()53 TempWindowX11::~TempWindowX11() {
54   g_temp_window = nullptr;
55   DCHECK(xwindow_);
56 
57   CloseTempWindow(xwindow_);
58 }
59 
60 // static
GetWindowHandle()61 CefWindowHandle TempWindowX11::GetWindowHandle() {
62   DCHECK(g_temp_window);
63   return g_temp_window->xwindow_;
64 }
65 
66 }  // namespace client
67