1 | /* $Id: VBoxX11Helper.cpp 72678 2018-06-25 14:25:49Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - VBox X11 helper functions.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2018 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* Qt includes: */
|
---|
19 | #include <QString>
|
---|
20 | #include <QX11Info>
|
---|
21 |
|
---|
22 | /* GUI includes: */
|
---|
23 | #include "VBoxX11Helper.h"
|
---|
24 |
|
---|
25 | /* Other VBox includes: */
|
---|
26 | #include <iprt/cdefs.h>
|
---|
27 |
|
---|
28 | // WORKAROUND:
|
---|
29 | // rhel3 build hack
|
---|
30 | RT_C_DECLS_BEGIN
|
---|
31 | #include <X11/Xatom.h>
|
---|
32 | #include <X11/Xlib.h>
|
---|
33 | #include <X11/extensions/dpms.h>
|
---|
34 | RT_C_DECLS_END
|
---|
35 |
|
---|
36 |
|
---|
37 | static int gX11ScreenSaverTimeout;
|
---|
38 | static BOOL gX11ScreenSaverDpmsAvailable;
|
---|
39 | static BOOL gX11DpmsState;
|
---|
40 |
|
---|
41 | bool X11IsCompositingManagerRunning()
|
---|
42 | {
|
---|
43 | /* Get display: */
|
---|
44 | Display *pDisplay = QX11Info::display();
|
---|
45 | /* For each screen it manage, compositing manager MUST acquire ownership
|
---|
46 | * of a selection named _NET_WM_CM_Sn, where n is the screen number. */
|
---|
47 | Atom atom_property_name = XInternAtom(pDisplay, "_NET_WM_CM_S0", True);
|
---|
48 | return XGetSelectionOwner(pDisplay, atom_property_name);
|
---|
49 | }
|
---|
50 |
|
---|
51 | X11WMType X11WindowManagerType()
|
---|
52 | {
|
---|
53 | /* Get display: */
|
---|
54 | Display *pDisplay = QX11Info::display();
|
---|
55 | /* Prepare variables to be reused: */
|
---|
56 | Atom atom_property_name;
|
---|
57 | Atom atom_returned_type;
|
---|
58 | int iReturnedFormat;
|
---|
59 | unsigned long ulReturnedItemCount;
|
---|
60 | unsigned long ulDummy;
|
---|
61 | unsigned char *pcData = 0;
|
---|
62 | X11WMType wmType = X11WMType_Unknown;
|
---|
63 |
|
---|
64 | /* Ask if root-window supports check for WM name: */
|
---|
65 | atom_property_name = XInternAtom(pDisplay, "_NET_SUPPORTING_WM_CHECK", True);
|
---|
66 | if (XGetWindowProperty(pDisplay, QX11Info::appRootWindow(), atom_property_name,
|
---|
67 | 0, 512, False, XA_WINDOW, &atom_returned_type,
|
---|
68 | &iReturnedFormat, &ulReturnedItemCount, &ulDummy, &pcData) == Success)
|
---|
69 | {
|
---|
70 | Window WMWindow = None;
|
---|
71 | if (atom_returned_type == XA_WINDOW && iReturnedFormat == 32)
|
---|
72 | WMWindow = *((Window*)pcData);
|
---|
73 | if (pcData)
|
---|
74 | XFree(pcData);
|
---|
75 | if (WMWindow != None)
|
---|
76 | {
|
---|
77 | /* Ask root-window for WM name: */
|
---|
78 | atom_property_name = XInternAtom(pDisplay, "_NET_WM_NAME", True);
|
---|
79 | Atom utf8Atom = XInternAtom(pDisplay, "UTF8_STRING", True);
|
---|
80 | if (XGetWindowProperty(pDisplay, WMWindow, atom_property_name,
|
---|
81 | 0, 512, False, utf8Atom, &atom_returned_type,
|
---|
82 | &iReturnedFormat, &ulReturnedItemCount, &ulDummy, &pcData) == Success)
|
---|
83 | {
|
---|
84 | if (QString((const char*)pcData).contains("Compiz", Qt::CaseInsensitive))
|
---|
85 | wmType = X11WMType_Compiz;
|
---|
86 | else
|
---|
87 | if (QString((const char*)pcData).contains("GNOME Shell", Qt::CaseInsensitive))
|
---|
88 | wmType = X11WMType_GNOMEShell;
|
---|
89 | else
|
---|
90 | if (QString((const char*)pcData).contains("KWin", Qt::CaseInsensitive))
|
---|
91 | wmType = X11WMType_KWin;
|
---|
92 | else
|
---|
93 | if (QString((const char*)pcData).contains("Metacity", Qt::CaseInsensitive))
|
---|
94 | wmType = X11WMType_Metacity;
|
---|
95 | else
|
---|
96 | if (QString((const char*)pcData).contains("Mutter", Qt::CaseInsensitive))
|
---|
97 | wmType = X11WMType_Mutter;
|
---|
98 | else
|
---|
99 | if (QString((const char*)pcData).contains("Xfwm4", Qt::CaseInsensitive))
|
---|
100 | wmType = X11WMType_Xfwm4;
|
---|
101 | if (pcData)
|
---|
102 | XFree(pcData);
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|
106 | return wmType;
|
---|
107 | }
|
---|
108 |
|
---|
109 | void X11ScreenSaverSettingsInit()
|
---|
110 | {
|
---|
111 | int dummy;
|
---|
112 | Display *pDisplay = QX11Info::display();
|
---|
113 | gX11ScreenSaverDpmsAvailable = DPMSQueryExtension(pDisplay, &dummy, &dummy);
|
---|
114 | }
|
---|
115 |
|
---|
116 | void X11ScreenSaverSettingsSave()
|
---|
117 | {
|
---|
118 | /* Actually this is a big mess. By default the libSDL disables the screen saver
|
---|
119 | * during the SDL_InitSubSystem() call and restores the saved settings during
|
---|
120 | * the SDL_QuitSubSystem() call. This mechanism can be disabled by setting the
|
---|
121 | * environment variable SDL_VIDEO_ALLOW_SCREENSAVER to 1. However, there is a
|
---|
122 | * known bug in the Debian libSDL: If this environment variable is set, the
|
---|
123 | * screen saver is still disabled but the old state is not restored during
|
---|
124 | * SDL_QuitSubSystem()! So the only solution to overcome this problem is to
|
---|
125 | * save and restore the state prior and after each of these function calls. */
|
---|
126 |
|
---|
127 | int dummy;
|
---|
128 | CARD16 dummy2;
|
---|
129 | Display *pDisplay = QX11Info::display();
|
---|
130 |
|
---|
131 | XGetScreenSaver(pDisplay, &gX11ScreenSaverTimeout, &dummy, &dummy, &dummy);
|
---|
132 | if (gX11ScreenSaverDpmsAvailable)
|
---|
133 | DPMSInfo(pDisplay, &dummy2, &gX11DpmsState);
|
---|
134 | }
|
---|
135 |
|
---|
136 | void X11ScreenSaverSettingsRestore()
|
---|
137 | {
|
---|
138 | int iTimeout, iInterval, iPreferBlank, iAllowExp;
|
---|
139 | Display *pDisplay = QX11Info::display();
|
---|
140 |
|
---|
141 | XGetScreenSaver(pDisplay, &iTimeout, &iInterval, &iPreferBlank, &iAllowExp);
|
---|
142 | iTimeout = gX11ScreenSaverTimeout;
|
---|
143 | XSetScreenSaver(pDisplay, iTimeout, iInterval, iPreferBlank, iAllowExp);
|
---|
144 |
|
---|
145 | if (gX11DpmsState && gX11ScreenSaverDpmsAvailable)
|
---|
146 | DPMSEnable(pDisplay);
|
---|
147 | }
|
---|
148 |
|
---|
149 | SHARED_LIBRARY_STUFF bool X11CheckExtension(const char *extensionName)
|
---|
150 | {
|
---|
151 | Display *pDisplay = QX11Info::display();
|
---|
152 | int major_opcode;
|
---|
153 | int first_event;
|
---|
154 | int first_error;
|
---|
155 | return XQueryExtension(pDisplay, extensionName, &major_opcode, &first_event, &first_error);
|
---|
156 | }
|
---|