Set a flag property on the root window to say if the X server VT is active

An X11 client may need to know whether the X server virtual terminal is
currently the active one.  This change adds a root window property which
provides that information.  Intended interface user: the VirtualBox Guest
Additions.

Signed-off-by: Michael Thayer <michael.thayer@oracle.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Michael Thayer 2014-03-31 11:19:16 +02:00 committed by Keith Packard
parent b851ca968b
commit 62ab410226
3 changed files with 47 additions and 1 deletions

View File

@ -56,6 +56,7 @@
#include <X11/X.h>
#include <X11/Xpoll.h>
#include <X11/Xproto.h>
#include <X11/Xatom.h>
#include "misc.h"
#include "compiler.h"
#include "xf86.h"
@ -431,6 +432,29 @@ xf86EnableInputDeviceForVTSwitch(InputInfoPtr pInfo)
pInfo->flags &= ~XI86_DEVICE_DISABLED;
}
/*
* xf86UpdateHasVTProperty --
* Update a flag property on the root window to say whether the server VT
* is currently the active one as some clients need to know this.
*/
static void
xf86UpdateHasVTProperty(Bool hasVT)
{
Atom property_name;
int32_t value = hasVT ? 1 : 0;
int i;
property_name = MakeAtom(HAS_VT_ATOM_NAME, sizeof(HAS_VT_ATOM_NAME) - 1,
FALSE);
if (property_name == BAD_RESOURCE)
FatalError("Failed to retrieve \"HAS_VT\" atom\n");
for (i = 0; i < xf86NumScreens; i++) {
ChangeWindowProperty(xf86ScrnToScreen(xf86Screens[i])->root,
property_name, XA_INTEGER, 32,
PropModeReplace, 1, &value, TRUE);
}
}
void
xf86VTLeave(void)
{
@ -490,6 +514,8 @@ xf86VTLeave(void)
if (xorgHWAccess)
xf86DisableIO();
xf86UpdateHasVTProperty(FALSE);
return;
switch_failed:
@ -574,6 +600,8 @@ xf86VTEnter(void)
xf86platformVTProbe();
#endif
xf86UpdateHasVTProperty(TRUE);
OsReleaseSIGIO();
}

View File

@ -387,6 +387,11 @@ InstallSignalHandlers(void)
}
}
/* The memory storing the initial value of the XFree86_has_VT root window
* property. This has to remain available until server start-up, so we just
* use a global. */
static CARD32 HasVTValue = 1;
/*
* InitOutput --
* Initialize screenInfo for all actually accessible framebuffers.
@ -731,7 +736,9 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
if (xf86Info.vtno >= 0) {
#define VT_ATOM_NAME "XFree86_VT"
Atom VTAtom = -1;
Atom HasVTAtom = -1;
CARD32 *VT = NULL;
CARD32 *HasVT = &HasVTValue;
int ret;
/* This memory needs to stay available until the screen has been
@ -744,6 +751,8 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
*VT = xf86Info.vtno;
VTAtom = MakeAtom(VT_ATOM_NAME, sizeof(VT_ATOM_NAME) - 1, TRUE);
HasVTAtom = MakeAtom(HAS_VT_ATOM_NAME,
sizeof(HAS_VT_ATOM_NAME) - 1, TRUE);
for (i = 0, ret = Success; i < xf86NumScreens && ret == Success;
i++) {
@ -751,9 +760,14 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
xf86RegisterRootWindowProperty(xf86Screens[i]->scrnIndex,
VTAtom, XA_INTEGER, 32, 1,
VT);
if (ret == Success)
ret = xf86RegisterRootWindowProperty(xf86Screens[i]
->scrnIndex,
HasVTAtom, XA_INTEGER,
32, 1, HasVT);
if (ret != Success)
xf86DrvMsg(xf86Screens[i]->scrnIndex, X_WARNING,
"Failed to register VT property\n");
"Failed to register VT properties\n");
}
}

View File

@ -163,4 +163,8 @@ typedef struct _RootWinProp {
#define WSCONS 32
#endif
/* Root window property to tell clients whether our VT is currently active.
* Name chosen to match the "XFree86_VT" property. */
#define HAS_VT_ATOM_NAME "XFree86_has_VT"
#endif /* _XF86PRIVSTR_H */