📄 inputmanager.cpp
字号:
// vi:ts=4:shiftwidth=4:expandtab/*************************************************************************** inputmanager.cpp - description ------------------- begin : Sun Sep 9 2001 copyright : (C) 2001 by ejoy email : ejoy@users.sourceforge.net ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#ifdef HAVE_CONFIG_H#include <config.h>#endifusing namespace std;#include <unistd.h>#include <sys/time.h>#include <string>#include "global.h"#include "debug.h"#include "keymap.h"#include "console.h"#include "zhcon.h"#include "configfile.h"#include "inputserver.h"#include "inputclient.h"#include "nativeinputserver.h"#ifdef HAVE_UNICON_LIB #include "uniconinputserver.h"#endif#include "configserver.h"#include "nativebarclient.h"#include "overspotclient.h"#include "inputmanager.h"int InputManager::mConFd = -1;int InputManager::mConNo = -1;int InputManager::mTtyFd = -1;void InputManager::SetTty(int confd, int ttyno, int ttyfd) { mConFd = confd; mConNo = ttyno; mTtyFd = ttyfd;}InputManager::InputManager( Console * pCon, InputStyle style, string& OverSpotColors, string& NativeBarColors) : mpCon(pCon), mpInputServer(NULL), mpInputClient(NULL), mActive(false), mClientVisible(false), mpCurImm(NULL), mStyle(style), msOverSpotColors(OverSpotColors), msNativeBarColors(NativeBarColors), mpHelpWin(NULL) { assert(mTtyFd >= 0); if (mConNo >= 0) mMouse.Open(mpCon, mConFd, mConNo, mTtyFd); InputClient::SetConsole(pCon); if (mStyle == OverSpot) mpInputClient = new OverSpotClient(msOverSpotColors); else // if (mStyle == NativeBar) mpInputClient = new NativeBarClient(msNativeBarColors); KDSysSet(); Active(); // set VT size SetVtSize();}InputManager::~InputManager() { mMouse.Close(); //HelpHide(); may cause core dump if mpConsole is deleted first delete mpHelpWin; delete mpInputServer; delete mpInputClient; KDSysRestore(); KDInputRestore();}void InputManager::Process(InputEvt &evt) { evt.oper = InputEvt::Nothing; evt.sub = 0; const int BUFSIZE = 8192; char buf[BUFSIZE]; struct timeval tv; int count, rcved, shift; shift = GetShiftState(); if (shift != 0) { //printf("Shift stat %d\r\n", s); } // must use SetTty after construct assert(mConFd >= 0 && mTtyFd >= 0); FD_ZERO(&mFdSet); FD_SET(mConFd, &mFdSet); FD_SET(mTtyFd, &mFdSet);#ifdef HAVE_GPM_H if (mMouse.IsOpen()) FD_SET(mMouse.mFd, &mFdSet);#endif tv.tv_sec = 0; tv.tv_usec = 100000; /* 0.1 sec */ rcved = select(FD_SETSIZE, &mFdSet, NULL, NULL, &tv); if (rcved <= 0) return;#ifdef HAVE_GPM_H if (mMouse.IsOpen()) { if (FD_ISSET(mMouse.mFd, &mFdSet)) { mMouse.Process(); } }#endif if (FD_ISSET(mConFd, &mFdSet)) { count = read(mConFd, buf, BUFSIZE); if (count > 0) { for (int i = 0; i < count; i++) ProcessKey(buf[i], evt); } } if (FD_ISSET(mTtyFd, &mFdSet)) { count = read(mTtyFd, buf, BUFSIZE); if (count > 0) { mpCon->Write(buf, count); } }}int InputManager::GetShiftState(){ int shift = 0;#if defined(linux) int arg = 6; if (ioctl(mConFd, TIOCLINUX, &arg) != -1) { shift = arg; }#endif return shift;}void InputManager::ProcessKey(char c, InputEvt &evt) { if (c == ALT_SPACE) { // always useful if (mActive) DisActive(); else Active(); return ; } if (ProcessSysKey(c, evt)) // is sys keyb return ; HelpHide(); if (!mActive) { // not input mode, only Alt_Space WriteClient(c); return ; } if (ProcessInputKey(c)) // is sys keyb return ; if (mpInputClient->Visible() && mpInputServer) { bool isContinue; string s; isContinue = mpInputServer->ProcessKey(c, s); if (!isContinue) { // speical for ConfigServer DoCtrlSpace(); return; } if (!s.empty()) WriteClient(s); mpInputClient->Update(); return ; } WriteClient(c); //no imm active or prompt mode}//return true if a sys-key is processed//return false:no sys-key found!bool InputManager::ProcessSysKey(char c, InputEvt &evt) { bool r = true; switch (c) { case CTRL_F1: evt.oper = InputEvt::SetEnco; evt.sub = 1; break; case CTRL_F2: evt.oper = InputEvt::SetEnco; evt.sub = 2; break; case CTRL_F3: evt.oper = InputEvt::SetEnco; evt.sub = 3; break; case CTRL_F4: evt.oper = InputEvt::SetEnco; evt.sub = 4; break; case CTRL_F5: evt.oper = InputEvt::SetEnco; evt.sub = 5; break; case CTRL_F7: switch (mStyle) { case OverSpot: ChangeStyle(NativeBar); break; case NativeBar: ChangeStyle(OverSpot); break; } break; case CTRL_F8: //ChangeStyle(OverSpot); break; case CTRL_F9: evt.oper = InputEvt::AutoEncoSwitch; evt.sub = 0; break; case CTRL_F10: MenuMode(); break; case SHIFT_PAGEUP: mpCon->ScrollDelta(Console::PAGE_UP); break; case SHIFT_PAGEDOWN: mpCon->ScrollDelta(Console::PAGE_DOWN); break; case SHIFT_ARROWUP: mpCon->ScrollDelta(Console::LINE_UP); break; case SHIFT_ARROWDOWN: mpCon->ScrollDelta(Console::LINE_DOWN); break; case CTRL_ALT_H: if (mpHelpWin) HelpHide(); else HelpShow(); break; default: r = false; }//switch return r;}//return true if a sys-key is processed//return false:no sys-key found!bool InputManager::ProcessInputKey(char c) { bool r = true; switch (c) { case CTRL_ALT_0: PromptMode(); break; case CTRL_ALT_1: //fall through case CTRL_ALT_2: case CTRL_ALT_3: case CTRL_ALT_4: case CTRL_ALT_5: case CTRL_ALT_6: case CTRL_ALT_7: case CTRL_ALT_8: case CTRL_ALT_9: size_t i; i = c - CTRL_ALT_0; if (mImmTable.size() >= i) if (LoadImm(mImmTable[i - 1]) == false) Beep(); //need more error feedback here? break; //case CTRL_F7: //break; case CTRL_SPACE: DoCtrlSpace(); break; case CTRL_SHIFT: DoCtrlShift(); break; case CTRL_PERIOD: if (mpInputServer) { mpInputServer->SetFullComma(!mpInputServer->IsFullComma()); mpInputClient->Update(); } else r = false; break; case CTRL_COMMA: if (mpInputServer) { mpInputServer->SetFullChar(!mpInputServer->IsFullChar()); mpInputClient->Update(); } else r = false; break; default: r = false; }//switch return r;}void InputManager::WriteClient(char c) { write(mTtyFd, &c, 1);}void InputManager::WriteClient(string & s) { write(mTtyFd, s.c_str(), s.size());}void InputManager::Active() { mActive = true; if (mClientVisible) mpInputClient->Show(); // kb map set KDInputSet();}//hide all input win and restore some keymapvoid InputManager::DisActive() { mActive = false; mClientVisible = mpInputClient->Visible(); if (mpInputClient->Visible()) mpInputClient->Hide(); // kb map restore KDInputRestore();}//adjust vt size according to inputclientvoid InputManager::SetVtSize() { int ColDelta, RowDelta; ColDelta = RowDelta = 0; mpInputClient->VtSizeDelta(ColDelta, RowDelta); mpCon->VtSizeDelta(ColDelta, RowDelta); int cols, rows; mpCon->GetVtSize(cols, rows); struct winsize ws; ws.ws_col = cols; ws.ws_row = rows; // debug<<"Change VT size "<<cols<<","<<rows<<endl; ioctl(mTtyFd, TIOCSWINSZ, &ws);}//circle through available input methodsvoid InputManager::DoCtrlShift() { if (!mpInputClient->Visible() || mpCurImm == NULL) return ; for (size_t i = 0; i < mImmTable.size(); i++) if (mImmTable[i] == *mpCurImm) { if (++i == mImmTable.size()) i = 0; LoadImm(mImmTable[i]); break; }}bool InputManager::LoadImm(ImmInfo& rInfo) { if (mpCurImm && rInfo == *mpCurImm) return true; ImmInfo* pOld = mpCurImm; if (mpInputServer == NULL || mpInputServer->GetServerType() != rInfo.mType) { delete mpInputServer; if (rInfo.mType == "native") mpInputServer = new NativeInputServer();#ifdef HAVE_UNICON_LIB else if (rInfo.mType == "unicon") mpInputServer = new UniconInputServer();#endif else assert(!"unknown input server found!"); mpInputClient->Connect(mpInputServer); } if (mpInputServer->LoadImm(rInfo)) { mpCurImm = &rInfo; if (rInfo.mEncode != gpZhcon->mEncode) gpZhcon->SetEncode(rInfo.mEncode, rInfo.mEncode); mpInputClient->Update(); return true; } else { //restore old imm if (pOld) { mpCurImm = NULL; //force reload bool r = LoadImm(*pOld); assert(r); } return false; }}void InputManager::LoadImmInfo(ConfigFile& f) { ImmInfo t; string s; unsigned int ParmNo, Pos; unsigned int NextPos; string sVal; vector < string > v;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -