MythTV master
mythxdisplay.cpp
Go to the documentation of this file.
1// MythTV
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
37void 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
120void MythXDisplay::Sync(bool Flush)
121{
122 Lock();
123 XSync(m_disp, Flush);
124 Unlock();
125}
Display * m_disp
Definition: mythxdisplay.h:39
Window m_root
Definition: mythxdisplay.h:43
MythXDisplay()=default
Screen * m_screen
Definition: mythxdisplay.h:41
void Unlock()
Definition: mythxdisplay.h:29
void Sync(bool Flush=false)
QSize GetDisplayDimensions()
Return the size of the X Display in millimeters.
static bool DisplayIsRemote()
Determine if we are running a remote X11 session.
static QString s_QtX11Display
Definition: mythxdisplay.h:37
static void SetQtX11Display(const QString &DisplayStr)
bool Open()
Open the display.
QString m_displayName
Definition: mythxdisplay.h:45
static MythXDisplay * OpenMythXDisplay(bool Warn=true)
MythXDisplay * m_disp
MythXLocker(MythXDisplay *Disp)
Definition: mythxdisplay.cpp:8
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39