1
/* $Id: VBoxX11Helper.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
4
* VBox frontends: Qt GUI ("VirtualBox"):
9
* Copyright (C) 2008 Oracle Corporation
11
* This file is part of VirtualBox Open Source Edition (OSE), as
12
* available from http://www.virtualbox.org. This file is free software;
13
* you can redistribute it and/or modify it under the terms of the GNU
14
* General Public License (GPL) as published by the Free Software
15
* Foundation, in version 2 as it comes in the "COPYING" file of the
16
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20
#include "VBoxX11Helper.h"
22
#include <iprt/cdefs.h>
23
#include <iprt/string.h>
26
/* rhel3 build hack */
28
#include <X11/Xatom.h>
30
#include <X11/extensions/dpms.h>
33
static int gX11ScreenSaverTimeout;
34
static BOOL gX11ScreenSaverDpmsAvailable;
35
static BOOL gX11DpmsState;
38
* Init the screen saver save/restore mechanism.
40
void X11ScreenSaverSettingsInit()
43
Display *display = QX11Info::display();
44
gX11ScreenSaverDpmsAvailable =
45
DPMSQueryExtension(display, &dummy, &dummy);
49
* Actually this is a big mess. By default the libSDL disables the screen
50
* saver during the SDL_InitSubSystem() call and restores the saved settings
51
* during the SDL_QuitSubSystem() call. This mechanism can be disabled by
52
* setting the environment variable SDL_VIDEO_ALLOW_SCREENSAVER to 1. However,
53
* there is a known bug in the Debian libSDL: If this environment variable is
54
* set, the screen saver is still disabled but the old state is not restored
55
* during SDL_QuitSubSystem()! So the only solution to overcome this problem
56
* is to save and restore the state prior and after each of these function
59
void X11ScreenSaverSettingsSave()
63
Display *display = QX11Info::display();
65
XGetScreenSaver(display, &gX11ScreenSaverTimeout, &dummy, &dummy, &dummy);
66
if (gX11ScreenSaverDpmsAvailable)
67
DPMSInfo(display, &dummy2, &gX11DpmsState);
71
* Restore previously saved screen saver settings.
73
void X11ScreenSaverSettingsRestore()
75
int timeout, interval, preferBlank, allowExp;
76
Display *display = QX11Info::display();
78
XGetScreenSaver(display, &timeout, &interval, &preferBlank, &allowExp);
79
timeout = gX11ScreenSaverTimeout;
80
XSetScreenSaver(display, timeout, interval, preferBlank, allowExp);
82
if (gX11DpmsState && gX11ScreenSaverDpmsAvailable)
87
* Determine if the current Window manager is KWin (KDE)
89
bool X11IsWindowManagerKWin()
94
unsigned long ulNitemsReturned;
95
unsigned long ulDummy;
96
unsigned char *pcData = NULL;
97
bool fIsKWinManaged = false;
98
Display *display = QX11Info::display();
100
Window WMWindow = None;
102
propNameAtom = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", True);
103
if (XGetWindowProperty(display, QX11Info::appRootWindow(), propNameAtom,
104
0, 512, False, XA_WINDOW, &typeReturned,
105
&formatReturned, &ulNitemsReturned, &ulDummy, &pcData)
109
if (typeReturned == XA_WINDOW && formatReturned == 32)
110
WMWindow = *((Window*) pcData);
113
if (WMWindow != None)
115
propNameAtom = XInternAtom(display, "_NET_WM_NAME", True);
116
utf8Atom = XInternAtom(display, "UTF8_STRING", True);
117
if (XGetWindowProperty(QX11Info::display(), WMWindow, propNameAtom,
118
0, 512, False, utf8Atom, &typeReturned,
119
&formatReturned, &ulNitemsReturned, &ulDummy, &pcData)
122
fIsKWinManaged = RTStrCmp((const char*)pcData, "KWin") == 0;
128
return fIsKWinManaged;