Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / remoting / host / linux / x11_util.cc
blob8857a6a86f181fe65b3cde00988af6d40c7a5284
1 // Copyright (c) 2012 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.
5 #include "remoting/host/linux/x11_util.h"
7 #include "base/bind.h"
9 namespace remoting {
11 static ScopedXErrorHandler* g_handler = nullptr;
13 ScopedXErrorHandler::ScopedXErrorHandler(const Handler& handler):
14 handler_(handler),
15 ok_(true) {
16 // This is a poor-man's check for incorrect usage. It doesn't handle the case
17 // where a mix of ScopedXErrorHandler and raw XSetErrorHandler calls are used,
18 // and it disallows nested ScopedXErrorHandlers on the same thread, despite
19 // these being perfectly safe.
20 DCHECK(g_handler == nullptr);
21 g_handler = this;
22 previous_handler_ = XSetErrorHandler(HandleXErrors);
25 ScopedXErrorHandler::~ScopedXErrorHandler() {
26 g_handler = nullptr;
27 XSetErrorHandler(previous_handler_);
30 namespace {
31 void IgnoreXErrors(Display* display, XErrorEvent* error) {}
32 } // namespace
34 // Static
35 ScopedXErrorHandler::Handler ScopedXErrorHandler::Ignore() {
36 return base::Bind(IgnoreXErrors);
39 int ScopedXErrorHandler::HandleXErrors(Display* display, XErrorEvent* error) {
40 DCHECK(g_handler != nullptr);
41 g_handler->ok_ = false;
42 g_handler->handler_.Run(display, error);
43 return 0;
47 ScopedXGrabServer::ScopedXGrabServer(Display* display)
48 : display_(display) {
49 XGrabServer(display_);
52 ScopedXGrabServer::~ScopedXGrabServer() {
53 XUngrabServer(display_);
54 XFlush(display_);
57 } // namespace remoting