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 #ifndef REMOTING_HOST_LINUX_X11_UTIL_H_
6 #define REMOTING_HOST_LINUX_X11_UTIL_H_
8 // Xlib.h defines XErrorEvent as an anonymous struct, so we can't forward-
9 // declare it in this header. Since Xlib.h is not generally something you
10 // should #include into arbitrary code, please refrain from #including this
11 // header in another header.
14 #include "base/callback.h"
18 // Temporarily install an alternative handler for X errors. The default handler
19 // exits the process, which is not what we want.
21 // Note that X error handlers are global, which means that this class is not
23 class ScopedXErrorHandler
{
25 typedef base::Callback
<void(Display
*, XErrorEvent
*)> Handler
;
27 explicit ScopedXErrorHandler(const Handler
& handler
);
28 ~ScopedXErrorHandler();
30 // Return false if any X errors have been encountered in the scope of this
32 bool ok() const { return ok_
; }
34 // Basic handler that ignores X errors.
35 static Handler
Ignore();
38 static int HandleXErrors(Display
* display
, XErrorEvent
* error
);
41 int (*previous_handler_
)(Display
*, XErrorEvent
*);
44 DISALLOW_COPY_AND_ASSIGN(ScopedXErrorHandler
);
48 // Grab/release the X server within a scope. This can help avoid race
49 // conditions that would otherwise lead to X errors.
50 class ScopedXGrabServer
{
52 ScopedXGrabServer(Display
* display
);
58 DISALLOW_COPY_AND_ASSIGN(ScopedXGrabServer
);
61 } // namespace remoting
63 #endif // REMOTING_HOST_LINUX_X11_UTIL_H_