tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

XlibDisplay.h (1193B)


      1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef GFX_XLIBDISPLAY_H
      7 #define GFX_XLIBDISPLAY_H
      8 
      9 #include <X11/Xlib.h>
     10 #include "X11UndefineNone.h"
     11 
     12 #include <memory>
     13 
     14 namespace mozilla::gfx {
     15 
     16 // Represents an X11 display connection which may be either borrowed
     17 // (e.g., from GTK) or owned; in the latter case it will be closed
     18 // with this object becomes unreferenced.  See also the `EglDisplay`
     19 // class.
     20 class XlibDisplay final {
     21 public:
     22  ~XlibDisplay();
     23 
     24  // Explicit `->get()` may be needed with some `Xlib.h` macros that
     25  // expand to C-style pointer casts.
     26  Display* get() const { return mDisplay; }
     27  operator Display*() const { return mDisplay; }
     28 
     29  static std::shared_ptr<XlibDisplay> Borrow(Display* aDisplay);
     30  static std::shared_ptr<XlibDisplay> Open(const char* aDisplayName);
     31 
     32 private:
     33  Display* const mDisplay;
     34  bool const mOwned;
     35 
     36  XlibDisplay(Display*, bool);
     37 };
     38 
     39 }  // namespace mozilla::gfx
     40 
     41 #endif  // GFX_XLIBDISPLAY_H