diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2018-03-08 17:39:27 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2018-04-12 14:22:33 +0800 |
commit | df01e4d4323e9138a6a7eb900e839cc154ce06bb (patch) | |
tree | eb9f8400bcde91629ec3e78785134cd777db85b4 | |
parent | 292a81fffc0ff0bb836f7e51514ccafc77aa475d (diff) | |
download | fbterm-df01e4d4323e9138a6a7eb900e839cc154ce06bb.tar.gz fbterm-df01e4d4323e9138a6a7eb900e839cc154ce06bb.zip |
input: move active-terminal detection to input code
When we're using a null input (ie, in write-only mode), it doesn't make
sense to interact with the VT switching, so we're always active.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rw-r--r-- | src/fbterm.cpp | 9 | ||||
-rw-r--r-- | src/input.cpp | 20 | ||||
-rw-r--r-- | src/input.h | 1 |
3 files changed, 22 insertions, 8 deletions
diff --git a/src/fbterm.cpp b/src/fbterm.cpp index 38d4014..2320ee2 100644 --- a/src/fbterm.cpp +++ b/src/fbterm.cpp @@ -25,7 +25,6 @@ #include <sys/stat.h> #include <sys/wait.h> #include <linux/vt.h> -#include <linux/kdev_t.h> #include "config.h" #include "fbterm.h" #include "fbshell.h" @@ -151,13 +150,7 @@ void FbTerm::init() static bool isActiveTerm() { - struct vt_stat vtstat; - ioctl(STDIN_FILENO, VT_GETSTATE, &vtstat); - - struct stat ttystat; - fstat(STDIN_FILENO, &ttystat); - - return vtstat.v_active == MINOR(ttystat.st_rdev); + return TtyInput::instance()->isActive(); } void FbTerm::run() diff --git a/src/input.cpp b/src/input.cpp index ea9dba7..1e81ace 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -23,9 +23,12 @@ #include <string.h> #include <termios.h> #include <sys/ioctl.h> +#include <sys/stat.h> #include <sys/vt.h> #include <linux/kd.h> +#include <linux/kdev_t.h> #include <linux/input.h> +#include <linux/vt.h> #include "input.h" #include "input_key.h" #include "fbshell.h" @@ -43,6 +46,7 @@ public: void switchVc(bool enter); void setRawMode(bool raw, bool force = false); void showInfo(bool verbose); + bool isActive(void); protected: TtyInputVT(); @@ -108,6 +112,11 @@ TtyInputVT::~TtyInputVT() tcsetattr(STDIN_FILENO, TCSAFLUSH, &oldTm); } +bool TtyInput::isActive(void) +{ + return true; +} + void TtyInputVT::showInfo(bool verbose) { if (keymapFailure) { @@ -348,6 +357,17 @@ void TtyInputVT::processRawKeys(s8 *buf, u32 len) if (shell && len > start) shell->keyInput(buf + start, len - start); } +bool TtyInputVT::isActive(void) +{ + struct vt_stat vtstat; + ioctl(STDIN_FILENO, VT_GETSTATE, &vtstat); + + struct stat ttystat; + fstat(STDIN_FILENO, &ttystat); + + return vtstat.v_active == MINOR(ttystat.st_rdev); +} + void TtyInputNull::switchVc(bool enter) { } diff --git a/src/input.h b/src/input.h index 0e2a798..13cd489 100644 --- a/src/input.h +++ b/src/input.h @@ -32,6 +32,7 @@ public: virtual void switchVc(bool enter) = 0; virtual void setRawMode(bool raw, bool force = false) = 0; virtual void showInfo(bool verbose) = 0; + virtual bool isActive(void); private: static TtyInput *createInstance(); static TtyInput *mpTtyInput; |