16ed5955d5c5be0e7961aa3898473bde50d365c6
[platform/framework/web/crosswalk.git] / src / ui / gfx / x / x11_error_tracker.cc
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/gfx/x/x11_error_tracker.h"
6
7 #include "ui/gfx/x/x11_types.h"
8
9 namespace {
10
11 unsigned char g_x11_error_code = 0;
12
13 int X11ErrorHandler(Display* display, XErrorEvent* error) {
14   g_x11_error_code = error->error_code;
15   return 0;
16 }
17 }
18
19 namespace gfx {
20
21 X11ErrorTracker::X11ErrorTracker() {
22   old_handler_ = XSetErrorHandler(X11ErrorHandler);
23 }
24
25 X11ErrorTracker::~X11ErrorTracker() { XSetErrorHandler(old_handler_); }
26
27 bool X11ErrorTracker::FoundNewError() {
28   XSync(GetXDisplay(), False);
29   unsigned char error = g_x11_error_code;
30   g_x11_error_code = 0;
31   return error != 0;
32 }
33
34 }  // namespace gfx