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
90 const char *dispCStr = nullptr;
91 if (!s_QtX11Display.isEmpty())
92 dispCStr = s_QtX11Display.toLatin1().constData();
93
94 m_disp = XOpenDisplay(dispCStr);
95 if (!m_disp)
96 return false;
97
98 m_screenNum = DefaultScreen(m_disp);
99 m_root = DefaultRootWindow(m_disp);
100
101 return true;
102}
103
104void MythXDisplay::Sync(bool Flush)
105{
106 Lock();
107 XSync(m_disp, Flush);
108 Unlock();
109}
Display * m_disp
Definition: mythxdisplay.h:35
Window m_root
Definition: mythxdisplay.h:37
MythXDisplay()=default
void Unlock()
Definition: mythxdisplay.h:27
void Sync(bool Flush=false)
static bool DisplayIsRemote()
Determine if we are running a remote X11 session.
static QString s_QtX11Display
Definition: mythxdisplay.h:33
static void SetQtX11Display(const QString &DisplayStr)
bool Open()
Open the display.
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