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

Alan Coopersmith alan.coopersmith at sun.com
Wed Dec 16 16:46:51 PST 2009


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

Signed-off-by: Alan Coopersmith <alan.coopersmith at sun.com>
---

Only tested on OpenSolaris, assumes that BSD/Linux/SCO code copied to the
os-specific files for each OS will continue to work there.

Future refactoring work available for someone with access to multiple 
platforms (or the time and diskspace to install them all in virtual
machines) would be to reduce the duplication of most of the code between
VTSW_usl.c, VTSW_sco.c, VTSW_noop.c and bsd_VTsw.c.

 hw/xfree86/common/xf86Events.c           |   53 +++++++++++-------------------
 hw/xfree86/os-support/bsd/bsd_VTsw.c     |    9 +++++
 hw/xfree86/os-support/sco/VTsw_sco.c     |   10 ++++++
 hw/xfree86/os-support/shared/VTsw_noop.c |    6 +++
 hw/xfree86/os-support/shared/VTsw_usl.c  |   11 ++++++
 hw/xfree86/os-support/solaris/sun_VTsw.c |   17 +++++++++
 hw/xfree86/os-support/xf86_OSproc.h      |    1 +
 7 files changed, 73 insertions(+), 34 deletions(-)

diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index 8e6a15b..ebf03bf 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -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;
-	    }
 
-	    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
+	    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;
     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;
     }
diff --git a/hw/xfree86/os-support/bsd/bsd_VTsw.c b/hw/xfree86/os-support/bsd/bsd_VTsw.c
index 476a0e9..4842be5 100644
--- a/hw/xfree86/os-support/bsd/bsd_VTsw.c
+++ b/hw/xfree86/os-support/bsd/bsd_VTsw.c
@@ -92,3 +92,12 @@ xf86VTSwitchTo()
 #endif
 	return(TRUE);
 }
+
+Bool
+xf86VTActivate(int vtno)
+{
+	if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, vtno) < 0) {
+		return(FALSE);
+	}
+	return(TRUE);
+}
diff --git a/hw/xfree86/os-support/sco/VTsw_sco.c b/hw/xfree86/os-support/sco/VTsw_sco.c
index d126e78..0a59fb9 100644
--- a/hw/xfree86/os-support/sco/VTsw_sco.c
+++ b/hw/xfree86/os-support/sco/VTsw_sco.c
@@ -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);
+}
diff --git a/hw/xfree86/os-support/shared/VTsw_noop.c b/hw/xfree86/os-support/shared/VTsw_noop.c
index 78cbe0e..3425840 100644
--- a/hw/xfree86/os-support/shared/VTsw_noop.c
+++ b/hw/xfree86/os-support/shared/VTsw_noop.c
@@ -52,3 +52,9 @@ xf86VTSwitchTo(void)
 {
 	return(TRUE);
 }
+
+Bool
+xf86VTActivate(int vtno)
+{
+	return(TRUE);
+}
diff --git a/hw/xfree86/os-support/shared/VTsw_usl.c b/hw/xfree86/os-support/shared/VTsw_usl.c
index 9308640..393f1c0 100644
--- a/hw/xfree86/os-support/shared/VTsw_usl.c
+++ b/hw/xfree86/os-support/shared/VTsw_usl.c
@@ -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);
+}
diff --git a/hw/xfree86/os-support/solaris/sun_VTsw.c b/hw/xfree86/os-support/solaris/sun_VTsw.c
index 46fd3f2..c1ff7d7 100644
--- a/hw/xfree86/os-support/solaris/sun_VTsw.c
+++ b/hw/xfree86/os-support/solaris/sun_VTsw.c
@@ -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);
+}
diff --git a/hw/xfree86/os-support/xf86_OSproc.h b/hw/xfree86/os-support/xf86_OSproc.h
index c1a1173..f0cb768 100644
--- a/hw/xfree86/os-support/xf86_OSproc.h
+++ b/hw/xfree86/os-support/xf86_OSproc.h
@@ -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);
-- 
1.5.6.5



More information about the xorg-devel mailing list