Move OS-specific VT key handler code from common to os-support

Adds new function xf86Activate to the OS-specific *VTsw*.c files
and calls it from xf86ProcessActionEvent

Signed-off-by: Alan Coopersmith <alan.coopersmith@sun.com>
Tested-by: Tiago Vignatti <tiago.vignatti@nokia.com> (GNU/Linux)
This commit is contained in:
Alan Coopersmith 2009-12-15 19:07:38 -08:00
parent 15ca3312c0
commit 39ab474197
7 changed files with 73 additions and 34 deletions

View File

@ -194,55 +194,40 @@ xf86ProcessActionEvent(ActionEvent action, void *arg)
if (!xf86Info.dontZoom)
xf86ZoomViewport(xf86Info.currentScreen, -1);
break;
#if defined(VT_ACTIVATE)
case ACTION_SWITCHSCREEN:
if (VTSwitchEnabled && !xf86Info.dontVTSwitch && arg) {
int vtno = *((int *) arg);
#if defined(__SCO__) || defined(__UNIXWARE__)
vtno--;
#endif
#if defined(sun)
if (vtno == xf86Info.vtno) {
break;
} else {
struct vt_stat state;
if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &state) < 0)
break;
if ((state.v_state & (1 << vtno)) == 0)
break;
if (vtno != xf86Info.vtno) {
if (!xf86VTActivate(vtno)) {
ErrorF("Failed to switch from vt%02d to vt%02d: %s\n",
xf86Info.vtno, vtno, strerror(errno));
}
}
xf86Info.vtRequestsPending = TRUE;
xf86Info.vtPendingNum = vtno;
#else
if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, vtno) < 0)
ErrorF("Failed to switch consoles (%s)\n", strerror(errno));
#endif
}
break;
case ACTION_SWITCHSCREEN_NEXT:
if (VTSwitchEnabled && !xf86Info.dontVTSwitch) {
#if defined(__SCO__) || defined(__UNIXWARE__)
if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0)
#else
if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno + 1) < 0)
#endif
#if defined (__SCO__) || (defined(sun) && defined (__i386__) && defined (SVR4)) || defined(__UNIXWARE__)
if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 0) < 0)
#else
if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 1) < 0)
#endif
ErrorF("Failed to switch consoles (%s)\n", strerror(errno));
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;
case ACTION_SWITCHSCREEN_PREV:
if (VTSwitchEnabled && !xf86Info.dontVTSwitch && xf86Info.vtno > 0) {
if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno - 1) < 0)
ErrorF("Failed to switch consoles (%s)\n", strerror(errno));
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;
#endif
default:
break;
}

View File

@ -92,3 +92,12 @@ xf86VTSwitchTo()
#endif
return(TRUE);
}
Bool
xf86VTActivate(int vtno)
{
if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, vtno) < 0) {
return(FALSE);
}
return(TRUE);
}

View File

@ -115,3 +115,13 @@ xf86VTSwitchTo(void)
return TRUE;
}
}
Bool
xf86VTActivate(int vtno)
{
if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, vtno - 1) < 0) {
return(FALSE);
}
return(TRUE);
}

View File

@ -52,3 +52,9 @@ xf86VTSwitchTo(void)
{
return(TRUE);
}
Bool
xf86VTActivate(int vtno)
{
return(TRUE);
}

View File

@ -88,3 +88,14 @@ xf86VTSwitchTo(void)
return(TRUE);
}
}
Bool
xf86VTActivate(int vtno)
{
#ifdef VT_ACTIVATE
if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, vtno) < 0) {
return(FALSE);
}
#endif
return(TRUE);
}

View File

@ -118,3 +118,20 @@ xf86VTSwitchTo(void)
return(TRUE);
}
}
Bool
xf86VTActivate(int vtno)
{
struct vt_stat state;
if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &state) < 0)
return(FALSE);
if ((state.v_state & (1 << vtno)) == 0)
return(FALSE);
xf86Info.vtRequestsPending = TRUE;
xf86Info.vtPendingNum = vtno;
return(TRUE);
}

View File

@ -199,6 +199,7 @@ extern _X_EXPORT Bool xf86SIGIOSupported (void);
typedef void (*PMClose)(void);
extern _X_EXPORT void xf86OpenConsole(void);
extern _X_EXPORT void xf86CloseConsole(void);
extern _X_HIDDEN Bool xf86VTActivate(int vtno);
extern _X_EXPORT Bool xf86VTSwitchPending(void);
extern _X_EXPORT Bool xf86VTSwitchAway(void);
extern _X_EXPORT Bool xf86VTSwitchTo(void);