[26714] | 1 | /* $Id: VBoxX11Helper.cpp 72678 2018-06-25 14:25:49Z vboxsync $ */
|
---|
[11429] | 2 | /** @file
|
---|
[71544] | 3 | * VBox Qt GUI - VBox X11 helper functions.
|
---|
[11429] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[71544] | 7 | * Copyright (C) 2008-2018 Oracle Corporation
|
---|
[11429] | 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 |
|
---|
[56929] | 18 | /* Qt includes: */
|
---|
[71544] | 19 | #include <QString>
|
---|
[56929] | 20 | #include <QX11Info>
|
---|
| 21 |
|
---|
| 22 | /* GUI includes: */
|
---|
[11429] | 23 | #include "VBoxX11Helper.h"
|
---|
| 24 |
|
---|
[56929] | 25 | /* Other VBox includes: */
|
---|
[11429] | 26 | #include <iprt/cdefs.h>
|
---|
| 27 |
|
---|
[71544] | 28 | // WORKAROUND:
|
---|
| 29 | // rhel3 build hack
|
---|
[20374] | 30 | RT_C_DECLS_BEGIN
|
---|
[26469] | 31 | #include <X11/Xatom.h>
|
---|
[11429] | 32 | #include <X11/Xlib.h>
|
---|
| 33 | #include <X11/extensions/dpms.h>
|
---|
[20374] | 34 | RT_C_DECLS_END
|
---|
[11429] | 35 |
|
---|
[71544] | 36 |
|
---|
[11429] | 37 | static int gX11ScreenSaverTimeout;
|
---|
| 38 | static BOOL gX11ScreenSaverDpmsAvailable;
|
---|
| 39 | static BOOL gX11DpmsState;
|
---|
| 40 |
|
---|
[58880] | 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 |
|
---|
[56929] | 51 | X11WMType X11WindowManagerType()
|
---|
[26469] | 52 | {
|
---|
[56928] | 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;
|
---|
[26469] | 60 | unsigned long ulDummy;
|
---|
[56928] | 61 | unsigned char *pcData = 0;
|
---|
[56929] | 62 | X11WMType wmType = X11WMType_Unknown;
|
---|
[26502] | 63 |
|
---|
[56928] | 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)
|
---|
[26469] | 69 | {
|
---|
[56928] | 70 | Window WMWindow = None;
|
---|
| 71 | if (atom_returned_type == XA_WINDOW && iReturnedFormat == 32)
|
---|
| 72 | WMWindow = *((Window*)pcData);
|
---|
[26469] | 73 | if (pcData)
|
---|
| 74 | XFree(pcData);
|
---|
| 75 | if (WMWindow != None)
|
---|
| 76 | {
|
---|
[56928] | 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)
|
---|
[26469] | 83 | {
|
---|
[57101] | 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
|
---|
[56929] | 90 | if (QString((const char*)pcData).contains("KWin", Qt::CaseInsensitive))
|
---|
| 91 | wmType = X11WMType_KWin;
|
---|
| 92 | else
|
---|
[65796] | 93 | if (QString((const char*)pcData).contains("Metacity", Qt::CaseInsensitive))
|
---|
| 94 | wmType = X11WMType_Metacity;
|
---|
| 95 | else
|
---|
[56929] | 96 | if (QString((const char*)pcData).contains("Mutter", Qt::CaseInsensitive))
|
---|
| 97 | wmType = X11WMType_Mutter;
|
---|
[56935] | 98 | else
|
---|
[57101] | 99 | if (QString((const char*)pcData).contains("Xfwm4", Qt::CaseInsensitive))
|
---|
| 100 | wmType = X11WMType_Xfwm4;
|
---|
[26469] | 101 | if (pcData)
|
---|
| 102 | XFree(pcData);
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
[56929] | 106 | return wmType;
|
---|
[26469] | 107 | }
|
---|
[26714] | 108 |
|
---|
[56930] | 109 | void X11ScreenSaverSettingsInit()
|
---|
| 110 | {
|
---|
| 111 | int dummy;
|
---|
[71544] | 112 | Display *pDisplay = QX11Info::display();
|
---|
| 113 | gX11ScreenSaverDpmsAvailable = DPMSQueryExtension(pDisplay, &dummy, &dummy);
|
---|
[56930] | 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;
|
---|
[71544] | 129 | Display *pDisplay = QX11Info::display();
|
---|
[56930] | 130 |
|
---|
[71544] | 131 | XGetScreenSaver(pDisplay, &gX11ScreenSaverTimeout, &dummy, &dummy, &dummy);
|
---|
[56930] | 132 | if (gX11ScreenSaverDpmsAvailable)
|
---|
[71544] | 133 | DPMSInfo(pDisplay, &dummy2, &gX11DpmsState);
|
---|
[56930] | 134 | }
|
---|
| 135 |
|
---|
| 136 | void X11ScreenSaverSettingsRestore()
|
---|
| 137 | {
|
---|
[71544] | 138 | int iTimeout, iInterval, iPreferBlank, iAllowExp;
|
---|
| 139 | Display *pDisplay = QX11Info::display();
|
---|
[56930] | 140 |
|
---|
[71544] | 141 | XGetScreenSaver(pDisplay, &iTimeout, &iInterval, &iPreferBlank, &iAllowExp);
|
---|
| 142 | iTimeout = gX11ScreenSaverTimeout;
|
---|
| 143 | XSetScreenSaver(pDisplay, iTimeout, iInterval, iPreferBlank, iAllowExp);
|
---|
[56930] | 144 |
|
---|
| 145 | if (gX11DpmsState && gX11ScreenSaverDpmsAvailable)
|
---|
[71544] | 146 | DPMSEnable(pDisplay);
|
---|
[56930] | 147 | }
|
---|
| 148 |
|
---|
[72678] | 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 | }
|
---|