2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
* Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
* documentation, and that the name of Thomas Roell not be used in
|
|
|
|
* advertising or publicity pertaining to distribution of the software without
|
|
|
|
* specific, written prior permission. Thomas Roell makes no representations
|
|
|
|
* about the suitability of this software for any purpose. It is provided
|
|
|
|
* "as is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
* EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1994-2003 by The XFree86 Project, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Except as contained in this notice, the name of the copyright holder(s)
|
|
|
|
* and author(s) shall not be used in advertising or otherwise to promote
|
|
|
|
* the sale, use or other dealings in this Software without prior written
|
|
|
|
* authorization from the copyright holder(s) and author(s).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* [JCH-96/01/21] Extended std reverse map to four buttons. */
|
|
|
|
|
|
|
|
#ifdef HAVE_XORG_CONFIG_H
|
|
|
|
#include <xorg-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xpoll.h>
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#include "misc.h"
|
|
|
|
#include "compiler.h"
|
|
|
|
#include "xf86.h"
|
|
|
|
#include "xf86Priv.h"
|
|
|
|
#define XF86_OS_PRIVS
|
|
|
|
#include "xf86_OSlib.h"
|
2009-09-06 13:44:18 -06:00
|
|
|
#include <X11/keysym.h>
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#ifdef XFreeXDGA
|
|
|
|
#include "dgaproc.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <X11/extensions/XI.h>
|
|
|
|
#include <X11/extensions/XIproto.h>
|
|
|
|
#include "inputstr.h"
|
|
|
|
#include "xf86Xinput.h"
|
|
|
|
|
|
|
|
#include "mi.h"
|
|
|
|
#include "mipointer.h"
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
#include "xkbsrv.h"
|
|
|
|
#include "xkbstr.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#ifdef DPMSExtension
|
2010-04-13 13:54:46 -06:00
|
|
|
#include <X11/extensions/dpmsconst.h>
|
2006-11-26 11:13:41 -07:00
|
|
|
#include "dpmsproc.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a toggling variable:
|
|
|
|
* FALSE = No VT switching keys have been pressed last time around
|
|
|
|
* TRUE = Possible VT switch Pending
|
|
|
|
* (DWH - 12/2/93)
|
|
|
|
*
|
|
|
|
* This has been generalised to work with Linux and *BSD+syscons (DHD)
|
|
|
|
*/
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
Bool VTSwitchEnabled = TRUE; /* Allows run-time disabling for
|
|
|
|
*BSD and for avoiding VT
|
|
|
|
switches when using the DRI
|
|
|
|
automatic full screen mode.*/
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
extern fd_set EnabledDevices;
|
|
|
|
|
|
|
|
#ifdef XF86PM
|
2012-06-10 07:21:05 -06:00
|
|
|
extern void (*xf86OSPMClose) (void);
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static void xf86VTSwitch(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow arbitrary drivers or other XFree86 code to register with our main
|
|
|
|
* Wakeup handler.
|
|
|
|
*/
|
|
|
|
typedef struct x_IHRec {
|
2012-06-10 07:21:05 -06:00
|
|
|
int fd;
|
|
|
|
InputHandlerProc ihproc;
|
|
|
|
pointer data;
|
|
|
|
Bool enabled;
|
|
|
|
struct x_IHRec *next;
|
2006-11-26 11:13:41 -07:00
|
|
|
} IHRec, *IHPtr;
|
|
|
|
|
|
|
|
static IHPtr InputHandlers = NULL;
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
Bool
|
|
|
|
LegalModifier(unsigned int key, DeviceIntPtr pDev)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
* TimeSinceLastInputEvent --
|
|
|
|
* Function used for screensaver purposes by the os module. Returns the
|
|
|
|
* time in milliseconds since there last was any input.
|
|
|
|
*/
|
|
|
|
int
|
2010-07-27 13:02:24 -06:00
|
|
|
TimeSinceLastInputEvent(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (xf86Info.lastEventTime == 0) {
|
|
|
|
xf86Info.lastEventTime = GetTimeInMillis();
|
|
|
|
}
|
|
|
|
return GetTimeInMillis() - xf86Info.lastEventTime;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SetTimeSinceLastInputEvent --
|
|
|
|
* Set the lastEventTime to now.
|
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
|
|
|
SetTimeSinceLastInputEvent(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
xf86Info.lastEventTime = GetTimeInMillis();
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ProcessInputEvents --
|
|
|
|
* Retrieve all waiting input events and pass them to DIX in their
|
|
|
|
* correct chronological order. Only reads from the system pointer
|
|
|
|
* and keyboard.
|
|
|
|
*/
|
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
ProcessInputEvents(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int x, y;
|
|
|
|
|
|
|
|
mieqProcessInputEvents();
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* FIXME: This is a problem if we have multiple pointers */
|
|
|
|
miPointerGetPosition(inputInfo.pointer, &x, &y);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
xf86SetViewport(xf86Info.currentScreen, x, y);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle keyboard events that cause some kind of "action"
|
|
|
|
* (i.e., server termination, video mode changes, VT switches, etc.)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xf86ProcessActionEvent(ActionEvent action, void *arg)
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
DebugF("ProcessActionEvent(%d,%x)\n", (int) action, arg);
|
2006-11-26 11:13:41 -07:00
|
|
|
switch (action) {
|
|
|
|
case ACTION_TERMINATE:
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!xf86Info.dontZap) {
|
2013-06-07 11:28:45 -06:00
|
|
|
xf86Msg(X_INFO, "Server zapped. Shutting down.\n");
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef XFreeXDGA
|
2012-06-10 07:21:05 -06:00
|
|
|
DGAShutdown();
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
GiveUp(0);
|
|
|
|
}
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
case ACTION_NEXT_MODE:
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!xf86Info.dontZoom)
|
|
|
|
xf86ZoomViewport(xf86Info.currentScreen, 1);
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
case ACTION_PREV_MODE:
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!xf86Info.dontZoom)
|
|
|
|
xf86ZoomViewport(xf86Info.currentScreen, -1);
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
case ACTION_SWITCHSCREEN:
|
2012-06-10 07:21:05 -06:00
|
|
|
if (VTSwitchEnabled && !xf86Info.dontVTSwitch && arg) {
|
|
|
|
int vtno = *((int *) arg);
|
|
|
|
|
|
|
|
if (vtno != xf86Info.vtno) {
|
|
|
|
if (!xf86VTActivate(vtno)) {
|
|
|
|
ErrorF("Failed to switch from vt%02d to vt%02d: %s\n",
|
|
|
|
xf86Info.vtno, vtno, strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
case ACTION_SWITCHSCREEN_NEXT:
|
2012-06-10 07:21:05 -06:00
|
|
|
if (VTSwitchEnabled && !xf86Info.dontVTSwitch) {
|
|
|
|
if (!xf86VTActivate(xf86Info.vtno + 1)) {
|
|
|
|
/* If first try failed, assume this is the last VT and
|
|
|
|
* try wrapping around to the first vt.
|
|
|
|
*/
|
|
|
|
if (!xf86VTActivate(1)) {
|
|
|
|
ErrorF("Failed to switch from vt%02d to next vt: %s\n",
|
|
|
|
xf86Info.vtno, strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
case ACTION_SWITCHSCREEN_PREV:
|
2012-06-10 07:21:05 -06:00
|
|
|
if (VTSwitchEnabled && !xf86Info.dontVTSwitch && xf86Info.vtno > 0) {
|
|
|
|
if (!xf86VTActivate(xf86Info.vtno - 1)) {
|
|
|
|
/* Don't know what the maximum VT is, so can't wrap around */
|
|
|
|
ErrorF("Failed to switch from vt%02d to previous vt: %s\n",
|
|
|
|
xf86Info.vtno, strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* xf86Wakeup --
|
|
|
|
* Os wakeup handler.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
void
|
|
|
|
xf86Wakeup(pointer blockData, int err, pointer pReadmask)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
fd_set *LastSelectMask = (fd_set *) pReadmask;
|
2006-11-26 11:13:41 -07:00
|
|
|
fd_set devicesWithInput;
|
|
|
|
InputInfoPtr pInfo;
|
|
|
|
|
|
|
|
if (err >= 0) {
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
XFD_ANDSET(&devicesWithInput, LastSelectMask, &EnabledDevices);
|
|
|
|
if (XFD_ANYSET(&devicesWithInput)) {
|
|
|
|
pInfo = xf86InputDevs;
|
|
|
|
while (pInfo) {
|
|
|
|
if (pInfo->read_input && pInfo->fd >= 0 &&
|
|
|
|
(FD_ISSET(pInfo->fd, &devicesWithInput) != 0)) {
|
2013-06-07 11:28:45 -06:00
|
|
|
OsBlockSIGIO();
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove the descriptior from the set because more than one
|
|
|
|
* device may share the same file descriptor.
|
|
|
|
*/
|
|
|
|
FD_CLR(pInfo->fd, &devicesWithInput);
|
|
|
|
|
|
|
|
pInfo->read_input(pInfo);
|
2013-06-07 11:28:45 -06:00
|
|
|
OsReleaseSIGIO();
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
pInfo = pInfo->next;
|
|
|
|
}
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (err >= 0) { /* we don't want the handlers called if select() */
|
2013-06-07 11:28:45 -06:00
|
|
|
IHPtr ih, ih_tmp; /* returned with an error condition, do we? */
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
nt_list_for_each_entry_safe(ih, ih_tmp, InputHandlers, next) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (ih->enabled && ih->fd >= 0 && ih->ihproc &&
|
|
|
|
(FD_ISSET(ih->fd, ((fd_set *) pReadmask)) != 0)) {
|
|
|
|
ih->ihproc(ih->fd, ih->data);
|
|
|
|
}
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (xf86VTSwitchPending())
|
|
|
|
xf86VTSwitch();
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* xf86SigioReadInput --
|
|
|
|
* signal handler for the SIGIO signal.
|
|
|
|
*/
|
|
|
|
static void
|
2010-07-27 13:02:24 -06:00
|
|
|
xf86SigioReadInput(int fd, void *closure)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2007-12-13 14:47:48 -07:00
|
|
|
int errno_save = errno;
|
2010-07-27 13:02:24 -06:00
|
|
|
InputInfoPtr pInfo = closure;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
pInfo->read_input(pInfo);
|
|
|
|
|
2007-12-13 14:47:48 -07:00
|
|
|
errno = errno_save;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* xf86AddEnabledDevice --
|
2007-11-24 12:04:00 -07:00
|
|
|
*
|
2006-11-26 11:13:41 -07:00
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
2006-11-26 11:13:41 -07:00
|
|
|
xf86AddEnabledDevice(InputInfoPtr pInfo)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!xf86InstallSIGIOHandler(pInfo->fd, xf86SigioReadInput, pInfo)) {
|
|
|
|
AddEnabledDevice(pInfo->fd);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* xf86RemoveEnabledDevice --
|
2007-11-24 12:04:00 -07:00
|
|
|
*
|
2006-11-26 11:13:41 -07:00
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
2006-11-26 11:13:41 -07:00
|
|
|
xf86RemoveEnabledDevice(InputInfoPtr pInfo)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!xf86RemoveSIGIOHandler(pInfo->fd)) {
|
|
|
|
RemoveEnabledDevice(pInfo->fd);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int *xf86SignalIntercept = NULL;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
2006-11-26 11:13:41 -07:00
|
|
|
xf86InterceptSignals(int *signo)
|
|
|
|
{
|
|
|
|
if ((xf86SignalIntercept = signo))
|
2012-06-10 07:21:05 -06:00
|
|
|
*signo = -1;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void (*xf86SigIllHandler) (void) = NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
xf86InterceptSigIll(void (*sigillhandler) (void))
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
xf86SigIllHandler = sigillhandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-07-27 13:02:24 -06:00
|
|
|
* xf86SigWrapper --
|
2006-11-26 11:13:41 -07:00
|
|
|
* Catch unexpected signals and exit or continue cleanly.
|
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
int
|
|
|
|
xf86SigWrapper(int signo)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if ((signo == SIGILL) && xf86SigIllHandler) {
|
|
|
|
(*xf86SigIllHandler) ();
|
|
|
|
return 0; /* continue */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xf86SignalIntercept && (*xf86SignalIntercept < 0)) {
|
|
|
|
*xf86SignalIntercept = signo;
|
|
|
|
return 0; /* continue */
|
|
|
|
}
|
|
|
|
|
|
|
|
xf86Info.caughtSignal = TRUE;
|
|
|
|
return 1; /* abort */
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/*
|
|
|
|
* xf86PrintBacktrace --
|
|
|
|
* Print a stack backtrace for debugging purposes.
|
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
2009-09-06 13:44:18 -06:00
|
|
|
xf86PrintBacktrace(void)
|
|
|
|
{
|
|
|
|
xorg_backtrace();
|
|
|
|
}
|
|
|
|
|
2007-11-24 12:04:00 -07:00
|
|
|
static void
|
|
|
|
xf86ReleaseKeys(DeviceIntPtr pDev)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
KeyClassPtr keyc;
|
2013-06-07 11:28:45 -06:00
|
|
|
int i;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
|
|
|
if (!pDev || !pDev->key)
|
|
|
|
return;
|
|
|
|
|
|
|
|
keyc = pDev->key;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hmm... here is the biggest hack of every time !
|
|
|
|
* It may be possible that a switch-vt procedure has finished BEFORE
|
|
|
|
* you released all keys neccessary to do this. That peculiar behavior
|
|
|
|
* can fool the X-server pretty much, cause it assumes that some keys
|
|
|
|
* were not released. TWM may stuck alsmost completly....
|
|
|
|
* OK, what we are doing here is after returning from the vt-switch
|
|
|
|
* exeplicitely unrelease all keyboard keys before the input-devices
|
|
|
|
* are reenabled.
|
|
|
|
*/
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
for (i = keyc->xkbInfo->desc->min_key_code;
|
2012-06-10 07:21:05 -06:00
|
|
|
i < keyc->xkbInfo->desc->max_key_code; i++) {
|
2010-12-05 08:36:02 -07:00
|
|
|
if (key_is_down(pDev, i, KEY_POSTED)) {
|
2013-06-07 11:28:45 -06:00
|
|
|
OsBlockSIGIO();
|
2011-11-05 07:32:40 -06:00
|
|
|
QueueKeyboardEvents(pDev, KeyRelease, i, NULL);
|
2013-06-07 11:28:45 -06:00
|
|
|
OsReleaseSIGIO();
|
2007-11-24 12:04:00 -07:00
|
|
|
}
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* xf86VTSwitch --
|
|
|
|
* Handle requests for switching the vt.
|
|
|
|
*/
|
|
|
|
static void
|
2010-07-27 13:02:24 -06:00
|
|
|
xf86VTSwitch(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int i;
|
|
|
|
static int prevSIGIO;
|
|
|
|
InputInfoPtr pInfo;
|
|
|
|
IHPtr ih;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
DebugF("xf86VTSwitch()\n");
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef XFreeXDGA
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!DGAVTSwitch())
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/*
|
|
|
|
* Since all screens are currently all in the same state it is sufficient
|
|
|
|
* check the first. This might change in future.
|
|
|
|
*/
|
|
|
|
if (xf86Screens[0]->vtSema) {
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
DebugF("xf86VTSwitch: Leaving, xf86Exiting is %s\n",
|
|
|
|
BOOLTOSTRING((dispatchException & DE_TERMINATE) ? TRUE : FALSE));
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef DPMSExtension
|
2012-06-10 07:21:05 -06:00
|
|
|
if (DPMSPowerLevel != DPMSModeOn)
|
|
|
|
DPMSSet(serverClient, DPMSModeOn);
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < xf86NumScreens; i++) {
|
|
|
|
if (!(dispatchException & DE_TERMINATE))
|
|
|
|
if (xf86Screens[i]->EnableDisableFBAccess)
|
2013-06-07 11:28:45 -06:00
|
|
|
(*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], FALSE);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/*
|
|
|
|
* Keep the order: Disable Device > LeaveVT
|
|
|
|
* EnterVT > EnableDevice
|
|
|
|
*/
|
|
|
|
for (ih = InputHandlers; ih; ih = ih->next)
|
|
|
|
xf86DisableInputHandler(ih);
|
|
|
|
for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) {
|
|
|
|
if (pInfo->dev) {
|
2013-06-07 11:28:45 -06:00
|
|
|
if (!pInfo->dev->enabled)
|
|
|
|
pInfo->flags |= XI86_DEVICE_DISABLED;
|
2012-06-10 07:21:05 -06:00
|
|
|
xf86ReleaseKeys(pInfo->dev);
|
|
|
|
ProcessInputEvents();
|
|
|
|
DisableDevice(pInfo->dev, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
OsBlockSIGIO();
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < xf86NumScreens; i++)
|
2013-06-07 11:28:45 -06:00
|
|
|
xf86Screens[i]->LeaveVT(xf86Screens[i]);
|
|
|
|
for (i = 0; i < xf86NumGPUScreens; i++)
|
|
|
|
xf86GPUScreens[i]->LeaveVT(xf86GPUScreens[i]);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
xf86AccessLeave(); /* We need this here, otherwise */
|
|
|
|
|
|
|
|
if (!xf86VTSwitchAway()) {
|
|
|
|
/*
|
|
|
|
* switch failed
|
|
|
|
*/
|
|
|
|
|
|
|
|
DebugF("xf86VTSwitch: Leave failed\n");
|
|
|
|
xf86AccessEnter();
|
|
|
|
for (i = 0; i < xf86NumScreens; i++) {
|
2013-06-07 11:28:45 -06:00
|
|
|
if (!xf86Screens[i]->EnterVT(xf86Screens[i]))
|
2012-06-10 07:21:05 -06:00
|
|
|
FatalError("EnterVT failed for screen %d\n", i);
|
|
|
|
}
|
2013-06-07 11:28:45 -06:00
|
|
|
for (i = 0; i < xf86NumGPUScreens; i++) {
|
|
|
|
if (!xf86GPUScreens[i]->EnterVT(xf86GPUScreens[i]))
|
|
|
|
FatalError("EnterVT failed for gpu screen %d\n", i);
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!(dispatchException & DE_TERMINATE)) {
|
|
|
|
for (i = 0; i < xf86NumScreens; i++) {
|
|
|
|
if (xf86Screens[i]->EnableDisableFBAccess)
|
2013-06-07 11:28:45 -06:00
|
|
|
(*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], TRUE);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
|
|
|
|
|
|
|
|
pInfo = xf86InputDevs;
|
|
|
|
while (pInfo) {
|
2013-06-07 11:28:45 -06:00
|
|
|
if (pInfo->dev && (pInfo->flags & XI86_DEVICE_DISABLED) == 0)
|
2012-06-10 07:21:05 -06:00
|
|
|
EnableDevice(pInfo->dev, TRUE);
|
2013-06-07 11:28:45 -06:00
|
|
|
pInfo->flags &= ~XI86_DEVICE_DISABLED;
|
2012-06-10 07:21:05 -06:00
|
|
|
pInfo = pInfo->next;
|
|
|
|
}
|
|
|
|
for (ih = InputHandlers; ih; ih = ih->next)
|
|
|
|
xf86EnableInputHandler(ih);
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
OsReleaseSIGIO();
|
2011-11-05 07:32:40 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef XF86PM
|
2012-06-10 07:21:05 -06:00
|
|
|
if (xf86OSPMClose)
|
|
|
|
xf86OSPMClose();
|
|
|
|
xf86OSPMClose = NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < xf86NumScreens; i++) {
|
|
|
|
/*
|
|
|
|
* zero all access functions to
|
|
|
|
* trap calls when switched away.
|
|
|
|
*/
|
|
|
|
xf86Screens[i]->vtSema = FALSE;
|
|
|
|
}
|
|
|
|
if (xorgHWAccess)
|
|
|
|
xf86DisableIO();
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
else {
|
|
|
|
DebugF("xf86VTSwitch: Entering\n");
|
|
|
|
if (!xf86VTSwitchTo())
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#ifdef XF86PM
|
2012-06-10 07:21:05 -06:00
|
|
|
xf86OSPMClose = xf86OSPMOpen();
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (xorgHWAccess)
|
|
|
|
xf86EnableIO();
|
|
|
|
xf86AccessEnter();
|
|
|
|
for (i = 0; i < xf86NumScreens; i++) {
|
|
|
|
xf86Screens[i]->vtSema = TRUE;
|
2013-06-07 11:28:45 -06:00
|
|
|
if (!xf86Screens[i]->EnterVT(xf86Screens[i]))
|
2012-06-10 07:21:05 -06:00
|
|
|
FatalError("EnterVT failed for screen %d\n", i);
|
|
|
|
}
|
2013-06-07 11:28:45 -06:00
|
|
|
for (i = 0; i < xf86NumGPUScreens; i++) {
|
|
|
|
xf86GPUScreens[i]->vtSema = TRUE;
|
|
|
|
if (!xf86GPUScreens[i]->EnterVT(xf86GPUScreens[i]))
|
|
|
|
FatalError("EnterVT failed for gpu screen %d\n", i);
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < xf86NumScreens; i++) {
|
|
|
|
if (xf86Screens[i]->EnableDisableFBAccess)
|
2013-06-07 11:28:45 -06:00
|
|
|
(*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], TRUE);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Turn screen saver off when switching back */
|
|
|
|
dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
pInfo = xf86InputDevs;
|
|
|
|
while (pInfo) {
|
2013-06-07 11:28:45 -06:00
|
|
|
if (pInfo->dev && (pInfo->flags & XI86_DEVICE_DISABLED) == 0)
|
2012-06-10 07:21:05 -06:00
|
|
|
EnableDevice(pInfo->dev, TRUE);
|
2013-06-07 11:28:45 -06:00
|
|
|
pInfo->flags &= ~XI86_DEVICE_DISABLED;
|
2012-06-10 07:21:05 -06:00
|
|
|
pInfo = pInfo->next;
|
|
|
|
}
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (ih = InputHandlers; ih; ih = ih->next)
|
|
|
|
xf86EnableInputHandler(ih);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
OsReleaseSIGIO();
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Input handler registration */
|
|
|
|
|
|
|
|
static pointer
|
|
|
|
addInputHandler(int fd, InputHandlerProc proc, pointer data)
|
|
|
|
{
|
|
|
|
IHPtr ih;
|
|
|
|
|
|
|
|
if (fd < 0 || !proc)
|
2012-06-10 07:21:05 -06:00
|
|
|
return NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
ih = calloc(sizeof(*ih), 1);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!ih)
|
2012-06-10 07:21:05 -06:00
|
|
|
return NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
ih->fd = fd;
|
|
|
|
ih->ihproc = proc;
|
|
|
|
ih->data = data;
|
|
|
|
ih->enabled = TRUE;
|
|
|
|
|
|
|
|
ih->next = InputHandlers;
|
|
|
|
InputHandlers = ih;
|
|
|
|
|
|
|
|
return ih;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
pointer
|
2006-11-26 11:13:41 -07:00
|
|
|
xf86AddInputHandler(int fd, InputHandlerProc proc, pointer data)
|
2007-11-24 12:04:00 -07:00
|
|
|
{
|
2006-11-26 11:13:41 -07:00
|
|
|
IHPtr ih = addInputHandler(fd, proc, data);
|
|
|
|
|
|
|
|
if (ih)
|
|
|
|
AddEnabledDevice(fd);
|
|
|
|
return ih;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
pointer
|
2006-11-26 11:13:41 -07:00
|
|
|
xf86AddGeneralHandler(int fd, InputHandlerProc proc, pointer data)
|
2007-11-24 12:04:00 -07:00
|
|
|
{
|
2006-11-26 11:13:41 -07:00
|
|
|
IHPtr ih = addInputHandler(fd, proc, data);
|
|
|
|
|
|
|
|
if (ih)
|
|
|
|
AddGeneralSocket(fd);
|
|
|
|
return ih;
|
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
/**
|
|
|
|
* Set the handler for the console's fd. Replaces (and returns) the previous
|
|
|
|
* handler or NULL, whichever appropriate.
|
|
|
|
* proc may be NULL if the server should not handle events on the console.
|
|
|
|
*/
|
|
|
|
InputHandlerProc
|
|
|
|
xf86SetConsoleHandler(InputHandlerProc proc, pointer data)
|
|
|
|
{
|
|
|
|
static IHPtr handler = NULL;
|
2013-06-07 11:28:45 -06:00
|
|
|
InputHandlerProc old_proc = NULL;
|
2011-11-05 07:32:40 -06:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
if (handler) {
|
|
|
|
old_proc = handler->ihproc;
|
|
|
|
xf86RemoveGeneralHandler(handler);
|
|
|
|
}
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
handler = xf86AddGeneralHandler(xf86Info.consoleFd, proc, data);
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
return old_proc;
|
2011-11-05 07:32:40 -06:00
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
static void
|
|
|
|
removeInputHandler(IHPtr ih)
|
|
|
|
{
|
|
|
|
IHPtr p;
|
|
|
|
|
|
|
|
if (ih == InputHandlers)
|
2012-06-10 07:21:05 -06:00
|
|
|
InputHandlers = ih->next;
|
2006-11-26 11:13:41 -07:00
|
|
|
else {
|
2012-06-10 07:21:05 -06:00
|
|
|
p = InputHandlers;
|
|
|
|
while (p && p->next != ih)
|
|
|
|
p = p->next;
|
|
|
|
if (ih)
|
|
|
|
p->next = ih->next;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
free(ih);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
int
|
2006-11-26 11:13:41 -07:00
|
|
|
xf86RemoveInputHandler(pointer handler)
|
|
|
|
{
|
|
|
|
IHPtr ih;
|
|
|
|
int fd;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!handler)
|
2012-06-10 07:21:05 -06:00
|
|
|
return -1;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
ih = handler;
|
|
|
|
fd = ih->fd;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if (ih->fd >= 0)
|
2012-06-10 07:21:05 -06:00
|
|
|
RemoveEnabledDevice(ih->fd);
|
2006-11-26 11:13:41 -07:00
|
|
|
removeInputHandler(ih);
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
int
|
2006-11-26 11:13:41 -07:00
|
|
|
xf86RemoveGeneralHandler(pointer handler)
|
|
|
|
{
|
|
|
|
IHPtr ih;
|
|
|
|
int fd;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!handler)
|
2012-06-10 07:21:05 -06:00
|
|
|
return -1;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
ih = handler;
|
|
|
|
fd = ih->fd;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if (ih->fd >= 0)
|
2012-06-10 07:21:05 -06:00
|
|
|
RemoveGeneralSocket(ih->fd);
|
2006-11-26 11:13:41 -07:00
|
|
|
removeInputHandler(ih);
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
2006-11-26 11:13:41 -07:00
|
|
|
xf86DisableInputHandler(pointer handler)
|
|
|
|
{
|
|
|
|
IHPtr ih;
|
|
|
|
|
|
|
|
if (!handler)
|
2012-06-10 07:21:05 -06:00
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
ih = handler;
|
|
|
|
ih->enabled = FALSE;
|
|
|
|
if (ih->fd >= 0)
|
2012-06-10 07:21:05 -06:00
|
|
|
RemoveEnabledDevice(ih->fd);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
2006-11-26 11:13:41 -07:00
|
|
|
xf86DisableGeneralHandler(pointer handler)
|
|
|
|
{
|
|
|
|
IHPtr ih;
|
|
|
|
|
|
|
|
if (!handler)
|
2012-06-10 07:21:05 -06:00
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
ih = handler;
|
|
|
|
ih->enabled = FALSE;
|
|
|
|
if (ih->fd >= 0)
|
2012-06-10 07:21:05 -06:00
|
|
|
RemoveGeneralSocket(ih->fd);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
2006-11-26 11:13:41 -07:00
|
|
|
xf86EnableInputHandler(pointer handler)
|
|
|
|
{
|
|
|
|
IHPtr ih;
|
|
|
|
|
|
|
|
if (!handler)
|
2012-06-10 07:21:05 -06:00
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
ih = handler;
|
|
|
|
ih->enabled = TRUE;
|
|
|
|
if (ih->fd >= 0)
|
2012-06-10 07:21:05 -06:00
|
|
|
AddEnabledDevice(ih->fd);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
void
|
2006-11-26 11:13:41 -07:00
|
|
|
xf86EnableGeneralHandler(pointer handler)
|
|
|
|
{
|
|
|
|
IHPtr ih;
|
|
|
|
|
|
|
|
if (!handler)
|
2012-06-10 07:21:05 -06:00
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
ih = handler;
|
|
|
|
ih->enabled = TRUE;
|
|
|
|
if (ih->fd >= 0)
|
2012-06-10 07:21:05 -06:00
|
|
|
AddGeneralSocket(ih->fd);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As used currently by the DRI, the return value is ignored.
|
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
2006-11-26 11:13:41 -07:00
|
|
|
xf86EnableVTSwitch(Bool new)
|
|
|
|
{
|
|
|
|
static Bool def = TRUE;
|
|
|
|
Bool old;
|
|
|
|
|
|
|
|
old = VTSwitchEnabled;
|
|
|
|
if (!new) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Disable VT switching */
|
|
|
|
def = VTSwitchEnabled;
|
|
|
|
VTSwitchEnabled = FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Restore VT switching to default */
|
|
|
|
VTSwitchEnabled = def;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
DDXRingBell(int volume, int pitch, int duration)
|
|
|
|
{
|
2007-11-24 12:04:00 -07:00
|
|
|
xf86OSRingBell(volume, pitch, duration);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|