MythTV  master
mythxdisplay.cpp
Go to the documentation of this file.
1 // MythTV
2 #include "mythlogging.h"
3 #include "mythxdisplay.h"
4 
6 {
7  public:
8  explicit MythXLocker(MythXDisplay* Disp)
9  : m_disp(Disp)
10  {
11  if (m_disp)
12  m_disp->Lock();
13  }
14 
16  {
17  if (m_disp)
18  m_disp->Unlock();
19  }
20 
21  private:
22  MythXDisplay* m_disp { nullptr };
23 };
24 
26 {
27  auto * display = new MythXDisplay();
28  if (display && display->Open())
29  return display;
30 
31  if (Warn)
32  LOG(VB_GENERAL, LOG_CRIT, "MythXOpenDisplay() failed");
33  delete display;
34  return nullptr;
35 }
36 
37 void MythXDisplay::SetQtX11Display(const QString& DisplayStr)
38 {
39  s_QtX11Display = DisplayStr;
40 }
41 
44 {
45  bool result = false;
46  if (auto * display = MythXDisplay::OpenMythXDisplay(false); display != nullptr)
47  {
48  QString displayname(DisplayString(display->GetDisplay()));
49 
50  // DISPLAY=:x or DISPLAY=unix:x are local
51  // DISPLAY=hostname:x is remote
52  // DISPLAY=/xxx/xxx/.../org.macosforge.xquartz:x is local OS X
53  // x can be numbers n or n.n
54  // Anything else including DISPLAY not set is assumed local,
55  // in that case we are probably not running under X11
56  if (!displayname.isEmpty() && !displayname.startsWith(":") &&
57  !displayname.startsWith("unix:") && !displayname.startsWith("/") &&
58  displayname.contains(':'))
59  {
60  result = true;
61  }
62  delete display;
63  }
64  return result;
65 }
66 
68 {
69  MythXLocker locker(this);
70  if (m_disp)
71  XCloseDisplay(m_disp);
72 }
73 
87 {
88  MythXLocker locker(this);
89 
91  const char *dispCStr = nullptr;
92  if (!m_displayName.isEmpty())
93  dispCStr = m_displayName.toLatin1().constData();
94 
95  m_disp = XOpenDisplay(dispCStr);
96  if (!m_disp)
97  return false;
98 
99  m_screenNum = DefaultScreen(m_disp);
100  m_screen = DefaultScreenOfDisplay(m_disp);
101  m_depth = DefaultDepthOfScreen(m_screen);
102  m_root = DefaultRootWindow(m_disp);
103 
104  return true;
105 }
106 
113 {
114  MythXLocker locker(this);
115  int displayWidthMM = DisplayWidthMM( m_disp, m_screenNum);
116  int displayHeightMM = DisplayHeightMM(m_disp, m_screenNum);
117  return { displayWidthMM, displayHeightMM };
118 }
119 
120 void MythXDisplay::Sync(bool Flush)
121 {
122  XLOCK(this, XSync(m_disp, Flush))
123 }
MythXDisplay::Lock
void Lock()
Definition: mythxdisplay.h:34
MythXLocker
Definition: mythxdisplay.cpp:5
MythXLocker::MythXLocker
MythXLocker(MythXDisplay *Disp)
Definition: mythxdisplay.cpp:8
MythXDisplay::~MythXDisplay
~MythXDisplay()
Definition: mythxdisplay.cpp:67
MythXDisplay::m_screen
Screen * m_screen
Definition: mythxdisplay.h:47
MythXDisplay::m_displayName
QString m_displayName
Definition: mythxdisplay.h:55
MythXDisplay::GetDisplayDimensions
QSize GetDisplayDimensions()
Return the size of the X Display in millimeters.
Definition: mythxdisplay.cpp:112
MythXDisplay::m_disp
Display * m_disp
Definition: mythxdisplay.h:45
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythXLocker::m_disp
MythXDisplay * m_disp
Definition: mythxdisplay.cpp:22
MythXDisplay::MythXDisplay
MythXDisplay()=default
MythXDisplay::OpenMythXDisplay
static MythXDisplay * OpenMythXDisplay(bool Warn=true)
Definition: mythxdisplay.cpp:25
MythXDisplay::m_root
Window m_root
Definition: mythxdisplay.h:49
mythlogging.h
MythXDisplay::Open
bool Open()
Open the display.
Definition: mythxdisplay.cpp:86
MythXDisplay::m_depth
int m_depth
Definition: mythxdisplay.h:48
MythXDisplay::DisplayIsRemote
static bool DisplayIsRemote()
Determine if we are running a remote X11 session.
Definition: mythxdisplay.cpp:43
MythXDisplay::s_QtX11Display
static QString s_QtX11Display
Definition: mythxdisplay.h:43
MythXDisplay::SetQtX11Display
static void SetQtX11Display(const QString &DisplayStr)
Definition: mythxdisplay.cpp:37
mythxdisplay.h
MythXDisplay::Unlock
void Unlock()
Definition: mythxdisplay.h:35
MythXDisplay::Sync
void Sync(bool Flush=false)
Definition: mythxdisplay.cpp:120
MythXLocker::~MythXLocker
~MythXLocker()
Definition: mythxdisplay.cpp:15
MythXDisplay::m_screenNum
int m_screenNum
Definition: mythxdisplay.h:46
MythXDisplay
Definition: mythxdisplay.h:21
XLOCK
#define XLOCK(dpy, arg)
Definition: mythxdisplay.h:19