• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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 "base/x11/x11_error_tracker.h"
6 
7 #include "base/message_loop/message_pump_x11.h"
8 
9 namespace {
10 
11 unsigned char g_x11_error_code = 0;
12 
X11ErrorHandler(Display * display,XErrorEvent * error)13 int X11ErrorHandler(Display* display, XErrorEvent* error) {
14   g_x11_error_code = error->error_code;
15   return 0;
16 }
17 
18 }
19 
20 namespace base {
21 
X11ErrorTracker()22 X11ErrorTracker::X11ErrorTracker() {
23   old_handler_ = XSetErrorHandler(X11ErrorHandler);
24 }
25 
~X11ErrorTracker()26 X11ErrorTracker::~X11ErrorTracker() {
27   XSetErrorHandler(old_handler_);
28 }
29 
FoundNewError()30 bool X11ErrorTracker::FoundNewError() {
31   XSync(MessagePumpForUI::GetDefaultXDisplay(), False);
32   unsigned char error = g_x11_error_code;
33   g_x11_error_code = 0;
34   return error != 0;
35 }
36 
37 }  // namespace ui
38