~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Frontends/VirtualBox/src/platform/x11/VBoxX11Helper.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: VBoxX11Helper.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
 
2
/** @file
 
3
 *
 
4
 * VBox frontends: Qt GUI ("VirtualBox"):
 
5
 * X11 helpers.
 
6
 */
 
7
 
 
8
/*
 
9
 * Copyright (C) 2008 Oracle Corporation
 
10
 *
 
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.
 
18
 */
 
19
 
 
20
#include "VBoxX11Helper.h"
 
21
 
 
22
#include <iprt/cdefs.h>
 
23
#include <iprt/string.h>
 
24
#include <QX11Info>
 
25
 
 
26
/* rhel3 build hack */
 
27
RT_C_DECLS_BEGIN
 
28
#include <X11/Xatom.h>
 
29
#include <X11/Xlib.h>
 
30
#include <X11/extensions/dpms.h>
 
31
RT_C_DECLS_END
 
32
 
 
33
static int  gX11ScreenSaverTimeout;
 
34
static BOOL gX11ScreenSaverDpmsAvailable;
 
35
static BOOL gX11DpmsState;
 
36
 
 
37
/**
 
38
 * Init the screen saver save/restore mechanism.
 
39
 */
 
40
void X11ScreenSaverSettingsInit()
 
41
{
 
42
    int     dummy;
 
43
    Display *display = QX11Info::display();
 
44
    gX11ScreenSaverDpmsAvailable =
 
45
        DPMSQueryExtension(display, &dummy, &dummy);
 
46
}
 
47
 
 
48
/**
 
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
 
57
 * calls.
 
58
 */
 
59
void X11ScreenSaverSettingsSave()
 
60
{
 
61
    int     dummy;
 
62
    CARD16  dummy2;
 
63
    Display *display = QX11Info::display();
 
64
 
 
65
    XGetScreenSaver(display, &gX11ScreenSaverTimeout, &dummy, &dummy, &dummy);
 
66
    if (gX11ScreenSaverDpmsAvailable)
 
67
        DPMSInfo(display, &dummy2, &gX11DpmsState);
 
68
}
 
69
 
 
70
/**
 
71
 * Restore previously saved screen saver settings.
 
72
 */
 
73
void X11ScreenSaverSettingsRestore()
 
74
{
 
75
    int     timeout, interval, preferBlank, allowExp;
 
76
    Display *display = QX11Info::display();
 
77
 
 
78
    XGetScreenSaver(display, &timeout, &interval, &preferBlank, &allowExp);
 
79
    timeout = gX11ScreenSaverTimeout;
 
80
    XSetScreenSaver(display, timeout, interval, preferBlank, allowExp);
 
81
 
 
82
    if (gX11DpmsState && gX11ScreenSaverDpmsAvailable)
 
83
        DPMSEnable(display);
 
84
}
 
85
 
 
86
/**
 
87
 * Determine if the current Window manager is KWin (KDE)
 
88
 */
 
89
bool X11IsWindowManagerKWin()
 
90
{
 
91
    Atom typeReturned;
 
92
    Atom utf8Atom;
 
93
    int formatReturned;
 
94
    unsigned long ulNitemsReturned;
 
95
    unsigned long ulDummy;
 
96
    unsigned char *pcData = NULL;
 
97
    bool fIsKWinManaged = false;
 
98
    Display *display = QX11Info::display();
 
99
    Atom propNameAtom;
 
100
    Window WMWindow = None;
 
101
 
 
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)
 
106
                            == Success)
 
107
    {
 
108
 
 
109
        if (typeReturned == XA_WINDOW && formatReturned == 32)
 
110
            WMWindow = *((Window*) pcData);
 
111
        if (pcData)
 
112
            XFree(pcData);
 
113
        if (WMWindow != None)
 
114
        {
 
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)
 
120
                    == Success)
 
121
            {
 
122
                fIsKWinManaged = RTStrCmp((const char*)pcData, "KWin") == 0;
 
123
                if (pcData)
 
124
                    XFree(pcData);
 
125
            }
 
126
        }
 
127
    }
 
128
    return fIsKWinManaged;
 
129
}
 
130