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"
11 static ScopedXErrorHandler
* g_handler
= nullptr;
13 ScopedXErrorHandler::ScopedXErrorHandler(const Handler
& handler
):
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);
22 previous_handler_
= XSetErrorHandler(HandleXErrors
);
25 ScopedXErrorHandler::~ScopedXErrorHandler() {
27 XSetErrorHandler(previous_handler_
);
31 void IgnoreXErrors(Display
* display
, XErrorEvent
* error
) {}
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
);
47 ScopedXGrabServer::ScopedXGrabServer(Display
* display
)
49 XGrabServer(display_
);
52 ScopedXGrabServer::~ScopedXGrabServer() {
53 XUngrabServer(display_
);
57 } // namespace remoting