From 4d0e08beadd9dbdac6d704d4f3cab9704a5682e9 Mon Sep 17 00:00:00 2001 From: Lars Doelle Date: Tue, 1 Feb 2000 05:41:59 +0000 Subject: [PATCH] continuing keytrans changes svn path=/trunk/kdebase/konsole/; revision=39721 --- include/MakeDefaults | 6 ++ include/default.keytab.h | 15 ++-- include/keytrans.h | 13 +++- include/main.h | 2 + other/Makefile.am | 7 +- other/default.Keytab | 15 ++-- other/linux.keytab | 151 +++++++++++++++++++++++++++++++++++++++ other/nobshack.keytab | 151 +++++++++++++++++++++++++++++++++++++++ src/TEmuVt102.C | 4 +- src/keytrans.C | 55 ++++++++++++-- src/main.C | 20 ++++-- src/schema.C | 3 - 12 files changed, 410 insertions(+), 32 deletions(-) create mode 100755 include/MakeDefaults create mode 100644 other/linux.keytab create mode 100644 other/nobshack.keytab diff --git a/include/MakeDefaults b/include/MakeDefaults new file mode 100755 index 00000000..49c49c54 --- /dev/null +++ b/include/MakeDefaults @@ -0,0 +1,6 @@ +# [MakeDefaults] Quote default configuration files + +# TODO. We should convert both schema and sessions +# to the method demonstrated for keytrans. + +../tests/quote ../other/default.Keytab > default.keytab.h diff --git a/include/default.keytab.h b/include/default.keytab.h index 6dfe6fbf..43191e18 100644 --- a/include/default.keytab.h +++ b/include/default.keytab.h @@ -4,7 +4,7 @@ "#\n" "# --------------------------------------------------------------\n" "\n" - "hdr \"xterm keys\"\n" + "hdr \"xterm\"\n" "\n" "# --------------------------------------------------------------\n" "#\n" @@ -65,15 +65,20 @@ "key Return+Alt-NewLine : \"\\E\\r\" \n" "key Return+Alt+NewLine : \"\\E\\r\\n\"\n" "\n" + "# NOTE: we remove exactly stuff like this.\n" + "# by means of this file\n" + "#\n" "# Some desperately try to save the ^H.\n" "# The BsHack mode is set by regular\n" "# configurations means for convenience.\n" "\n" - "key Backspace-BsHack : \"\\x08\"\n" - "key Delete -BsHack : \"\\x7f\"\n" + "# key Backspace-BsHack : \"\\x08\"\n" + "# key Delete -BsHack : \"\\x7f\"\n" + "# key Backspace+BsHack : \"\\x7f\"\n" + "# key Delete +BsHack : \"\\E[3~\"\n" "\n" - "key Backspace+BsHack : \"\\x7f\"\n" - "key Delete +BsHack : \"\\E[3~\"\n" + "key Backspace : \"\\x7f\"\n" + "key Delete : \"\\E[3~\"\n" "\n" "# These codes are for the VT52 mode of VT100\n" "# The Ansi mode (i.e. VT100 mode) is set by\n" diff --git a/include/keytrans.h b/include/keytrans.h index 9228f811..f45665a7 100644 --- a/include/keytrans.h +++ b/include/keytrans.h @@ -43,10 +43,16 @@ public: ~KeyTrans(); static KeyTrans* defaultKeyTrans(); static KeyTrans* fromFile(const char* path); + static KeyTrans* find(int numb); + static KeyTrans* find(const char* path); +public: + static int count(); + static void loadAll(); public: bool findEntry(int key, int bits, int* cmd, const char** txt, int* len); private: - static KeyTrans* fromDevice(QIODevice &buf); + void addKeyTrans(); + static KeyTrans* fromDevice(QString path, QIODevice &buf); void addEntry(int key, int bits, int mask, int cmd, QString txt); private: class KeyEntry @@ -66,8 +72,11 @@ private: QString txt; }; private: - QString hdr; QList table; +public: //FIXME: we'd do better + QString hdr; + int numb; + QString path; }; #endif diff --git a/include/main.h b/include/main.h index 0e36e74b..d8bab56b 100644 --- a/include/main.h +++ b/include/main.h @@ -113,6 +113,8 @@ private: QPopupMenu* m_scrollbar; QPopupMenu* m_font; QPopupMenu* m_schema; + QPopupMenu* m_keytab; + QPopupMenu* m_codec; QPopupMenu* m_size; QPopupMenu* m_drop; // diff --git a/other/Makefile.am b/other/Makefile.am index ec5afdbe..ebb6fbb8 100644 --- a/other/Makefile.am +++ b/other/Makefile.am @@ -2,10 +2,11 @@ datadir = $(kde_datadir)/konsole data_DATA = BlackOnLightYellow.schema BlackOnWhite.schema \ Example.Schema GreenOnBlack.schema WhiteOnBlack.schema \ - default.Schema linux.desktop mc.desktop shell.desktop \ - syscolor.schema Linux.schema XTerm.schema vim.schema \ + default.Schema syscolor.schema Linux.schema XTerm.schema vim.schema \ DarkPicture.schema LightPicture.schema Transparent.schema GreenTint.schema \ - Transparent_MC.schema GreenTint_MC.schema su.desktop + Transparent_MC.schema GreenTint_MC.schema \ + linux.desktop mc.desktop shell.desktop su.desktop \ + linux.keytab nobshack.keytab KDE_ICON = konsole diff --git a/other/default.Keytab b/other/default.Keytab index 1388ce9f..0d119f00 100644 --- a/other/default.Keytab +++ b/other/default.Keytab @@ -2,7 +2,7 @@ # # -------------------------------------------------------------- -hdr "xterm keys" +hdr "xterm" # -------------------------------------------------------------- # @@ -63,15 +63,20 @@ key Return-Alt+NewLine : "\r\n" key Return+Alt-NewLine : "\E\r" key Return+Alt+NewLine : "\E\r\n" +# NOTE: we remove exactly stuff like this. +# by means of this file +# # Some desperately try to save the ^H. # The BsHack mode is set by regular # configurations means for convenience. -key Backspace-BsHack : "\x08" -key Delete -BsHack : "\x7f" +# key Backspace-BsHack : "\x08" +# key Delete -BsHack : "\x7f" +# key Backspace+BsHack : "\x7f" +# key Delete +BsHack : "\E[3~" -key Backspace+BsHack : "\x7f" -key Delete +BsHack : "\E[3~" +key Backspace : "\x7f" +key Delete : "\E[3~" # These codes are for the VT52 mode of VT100 # The Ansi mode (i.e. VT100 mode) is set by diff --git a/other/linux.keytab b/other/linux.keytab new file mode 100644 index 00000000..e8d643f9 --- /dev/null +++ b/other/linux.keytab @@ -0,0 +1,151 @@ +# [KeyTab] Konsole Keyboard Table +# +# -------------------------------------------------------------- + +hdr "(NOT FUNCTIONAL, YET) Linux" + +# -------------------------------------------------------------- +# +# This configuration table allows to customize the +# meaning of the keys. +# +# The syntax is that each entry has the form : +# +# "key" Keyname { ("+"|"-") Modename } ":" (String|Operation) +# +# Keynames are those defined in with the +# "Qt::Key_" removed. (We'd better insert the list here) +# +# Mode names are : +# +# - Shift +# - Alt +# - Control +# +# The VT100 emulation has two modes that can affect the +# sequences emitted by certain keys. These modes are +# under control of the client program. +# +# - Newline : effects Return and Enter key. +# - Application : effects Up and Down key. +# - Ansi : effects Up and Down key. +# +# konsole provides another mode that allows to configure +# the keyboard to do a backspace related trick. This mode +# can be changed by konsole's configuration menu. +# +# - BsHack : effects Backspace and Delete key. +# +# Operations are +# +# - scrollUpLine +# - scrollUpPage +# - scrollDownLine +# - scrollDownPage +# +# - emitSelection +# +# If the key is not found here, the text of the +# key event as provided by QT is emitted, possibly +# preceeded by ESC if the Alt key is pressed. +# +# -------------------------------------------------------------- + +key Escape : "\E" +key Tab : "\t" + +# VT100 can add an extra \n after return. +# The NewLine mode is set by an escape sequence. + +key Return-Alt-NewLine : "\r" +key Return-Alt+NewLine : "\r\n" + +key Return+Alt-NewLine : "\E\r" +key Return+Alt+NewLine : "\E\r\n" + +# Some desperately try to save the ^H. +# The BsHack mode is set by regular +# configurations means for convenience. + +key Backspace-BsHack : "\x08" +key Delete -BsHack : "\x7f" + +key Backspace+BsHack : "\x7f" +key Delete +BsHack : "\E[3~" + +# These codes are for the VT52 mode of VT100 +# The Ansi mode (i.e. VT100 mode) is set by +# an escape sequence + +key Up -Shift-Ansi : "\EA" +key Down -Shift-Ansi : "\EB" +key Right-Ansi : "\EC" +key Left -Ansi : "\ED" + +# VT100 emits a mode bit together +# with the arrow keys.The AppCuKeys +# mode is set by an escape sequence. + +key Up -Shift+Ansi+AppCuKeys : "\EOA" +key Down -Shift+Ansi+AppCuKeys : "\EOB" +key Right+Ansi+AppCuKeys : "\EOC" +key Left +Ansi+AppCuKeys : "\EOD" + +key Up -Shift+Ansi-AppCuKeys : "\E[A" +key Down -Shift+Ansi-AppCuKeys : "\E[B" +key Right+Ansi-AppCuKeys : "\E[C" +key Left +Ansi-AppCuKeys : "\E[D" + +# linux functions keys F1-F5 differ from xterm +# +# F1 : "\E[[A" +# F2 : "\E[[B" +# F3 : "\E[[C" +# F4 : "\E[[D" +# F5 : "\E[[E" + +# function keys + +key F1 : "\E[11~" +key F2 : "\E[12~" +key F3 : "\E[13~" +key F4 : "\E[14~" +key F5 : "\E[15~" +key F6 : "\E[17~" +key F7 : "\E[18~" +key F8 : "\E[19~" +key F9 : "\E[20~" +key F10 : "\E[21~" +key F11 : "\E[23~" +key F12 : "\E[24~" + +key Home : "\E[H" +key End : "\E[F" + +key Prior -Shift : "\E[5~" +key Next -Shift : "\E[6~" +key Insert-Shift : "\E[2~" + +# Keypad-Enter. See comment on Return above. + +key Enter+NewLine : "\r\n" +key Enter-NewLine : "\r" + +key Space +Control : "\x00" + +# some of keys are used by konsole. + +key Up +Shift : scrollLineUp +key Prior +Shift : scrollPageUp +key Down +Shift : scrollLineDown +key Next +Shift : scrollPageDown +key Insert+Shift : emitSelection + +#---------------------------------------------------------- + +# keypad characters as offered by Qt +# cannot be recognized as such. + +#---------------------------------------------------------- + +# Following other strings as emitted by konsole. diff --git a/other/nobshack.keytab b/other/nobshack.keytab new file mode 100644 index 00000000..43c3eb41 --- /dev/null +++ b/other/nobshack.keytab @@ -0,0 +1,151 @@ +# [KeyTab] Konsole Keyboard Table +# +# -------------------------------------------------------------- + +hdr "(NOT FUNCTIONAL, YET) BS sends BS" + +# -------------------------------------------------------------- +# +# This configuration table allows to customize the +# meaning of the keys. +# +# The syntax is that each entry has the form : +# +# "key" Keyname { ("+"|"-") Modename } ":" (String|Operation) +# +# Keynames are those defined in with the +# "Qt::Key_" removed. (We'd better insert the list here) +# +# Mode names are : +# +# - Shift +# - Alt +# - Control +# +# The VT100 emulation has two modes that can affect the +# sequences emitted by certain keys. These modes are +# under control of the client program. +# +# - Newline : effects Return and Enter key. +# - Application : effects Up and Down key. +# - Ansi : effects Up and Down key. +# +# konsole provides another mode that allows to configure +# the keyboard to do a backspace related trick. This mode +# can be changed by konsole's configuration menu. +# +# - BsHack : effects Backspace and Delete key. +# +# Operations are +# +# - scrollUpLine +# - scrollUpPage +# - scrollDownLine +# - scrollDownPage +# +# - emitSelection +# +# If the key is not found here, the text of the +# key event as provided by QT is emitted, possibly +# preceeded by ESC if the Alt key is pressed. +# +# -------------------------------------------------------------- + +key Escape : "\E" +key Tab : "\t" + +# VT100 can add an extra \n after return. +# The NewLine mode is set by an escape sequence. + +key Return-Alt-NewLine : "\r" +key Return-Alt+NewLine : "\r\n" + +key Return+Alt-NewLine : "\E\r" +key Return+Alt+NewLine : "\E\r\n" + +# Some desperately try to save the ^H. +# The BsHack mode is set by regular +# configurations means for convenience. + +key Backspace-BsHack : "\x08" +key Delete -BsHack : "\x7f" + +key Backspace+BsHack : "\x7f" +key Delete +BsHack : "\E[3~" + +# These codes are for the VT52 mode of VT100 +# The Ansi mode (i.e. VT100 mode) is set by +# an escape sequence + +key Up -Shift-Ansi : "\EA" +key Down -Shift-Ansi : "\EB" +key Right-Ansi : "\EC" +key Left -Ansi : "\ED" + +# VT100 emits a mode bit together +# with the arrow keys.The AppCuKeys +# mode is set by an escape sequence. + +key Up -Shift+Ansi+AppCuKeys : "\EOA" +key Down -Shift+Ansi+AppCuKeys : "\EOB" +key Right+Ansi+AppCuKeys : "\EOC" +key Left +Ansi+AppCuKeys : "\EOD" + +key Up -Shift+Ansi-AppCuKeys : "\E[A" +key Down -Shift+Ansi-AppCuKeys : "\E[B" +key Right+Ansi-AppCuKeys : "\E[C" +key Left +Ansi-AppCuKeys : "\E[D" + +# linux functions keys F1-F5 differ from xterm +# +# F1 : "\E[[A" +# F2 : "\E[[B" +# F3 : "\E[[C" +# F4 : "\E[[D" +# F5 : "\E[[E" + +# function keys + +key F1 : "\E[11~" +key F2 : "\E[12~" +key F3 : "\E[13~" +key F4 : "\E[14~" +key F5 : "\E[15~" +key F6 : "\E[17~" +key F7 : "\E[18~" +key F8 : "\E[19~" +key F9 : "\E[20~" +key F10 : "\E[21~" +key F11 : "\E[23~" +key F12 : "\E[24~" + +key Home : "\E[H" +key End : "\E[F" + +key Prior -Shift : "\E[5~" +key Next -Shift : "\E[6~" +key Insert-Shift : "\E[2~" + +# Keypad-Enter. See comment on Return above. + +key Enter+NewLine : "\r\n" +key Enter-NewLine : "\r" + +key Space +Control : "\x00" + +# some of keys are used by konsole. + +key Up +Shift : scrollLineUp +key Prior +Shift : scrollPageUp +key Down +Shift : scrollLineDown +key Next +Shift : scrollPageDown +key Insert+Shift : emitSelection + +#---------------------------------------------------------- + +# keypad characters as offered by Qt +# cannot be recognized as such. + +#---------------------------------------------------------- + +# Following other strings as emitted by konsole. diff --git a/src/TEmuVt102.C b/src/TEmuVt102.C index f0baef81..a1bd6228 100644 --- a/src/TEmuVt102.C +++ b/src/TEmuVt102.C @@ -68,9 +68,7 @@ TEmuVt102::TEmuVt102(TEWidget* gui) { QObject::connect(gui,SIGNAL(mouseSignal(int,int,int)), this,SLOT(onMouse(int,int,int))); - keytrans = KeyTrans::defaultKeyTrans(); -//FIXME: allow to set another keyboard translator -//keytrans = KeyTrans::fromFile("../other/default.KeyMap"); + keytrans = KeyTrans::find(0); //FIXME: go to proper config initTokenizer(); reset(); } diff --git a/src/keytrans.C b/src/keytrans.C index 9148f239..3b80d43f 100644 --- a/src/keytrans.C +++ b/src/keytrans.C @@ -27,7 +27,10 @@ #include #include #include +#include #include +#include +#include #include @@ -58,6 +61,8 @@ QString KeyTrans::KeyEntry::text() KeyTrans::KeyTrans() { + path = ""; + numb = 0; } KeyTrans::~KeyTrans() @@ -258,9 +263,10 @@ static KeyTransSymbols syms; - Comment :: '#' (any but \n)* */ -KeyTrans* KeyTrans::fromDevice(QIODevice &buf) +KeyTrans* KeyTrans::fromDevice(QString path, QIODevice &buf) { KeyTrans* kt = new KeyTrans; + kt->path = path; // Opening sequence @@ -358,13 +364,13 @@ KeyTrans* KeyTrans::defaultKeyTrans() #include "default.keytab.h" ; QBuffer buf(txt); - return fromDevice(buf); + return fromDevice("[buildin]",buf); } KeyTrans* KeyTrans::fromFile(const char* path) { QFile file(path); - return fromDevice(file); + return fromDevice(path,file); } // local symbol tables --------------------------------------------------------------------- @@ -488,8 +494,49 @@ KeyTransSymbols::KeyTransSymbols() defKeySyms(); } -// Debugging material ----------------------------------------------------------- +// Global material ----------------------------------------------------------- + +static int keytab_serial = 0; //FIXME: remove,localize + +static QIntDict numb2keymap; +static QDict path2keymap; + +KeyTrans* KeyTrans::find(int numb) +{ + KeyTrans* res = numb2keymap.find(numb); + return res ? res : numb2keymap.find(0); +} + +KeyTrans* KeyTrans::find(const char* path) +{ + KeyTrans* res = path2keymap.find(path); + return res ? res : numb2keymap.find(0); +} + +int KeyTrans::count() +{ + return numb2keymap.count(); +} + +void KeyTrans::addKeyTrans() +{ + this->numb = keytab_serial ++; + numb2keymap.insert(numb,this); + path2keymap.insert(path.data(),this); +} +void KeyTrans::loadAll() +{ + defaultKeyTrans()->addKeyTrans(); + QStringList lst = KGlobal::dirs()->findAllResources("appdata", "*.keytab"); + + for(QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { + KeyTrans* sc = KeyTrans::fromFile(*it); + if (sc) sc->addKeyTrans(); + } +} + +// Debugging material ----------------------------------------------------------- /* void TestTokenizer(QBuffer &buf) { diff --git a/src/main.C b/src/main.C index b52e7cde..1d48b016 100644 --- a/src/main.C +++ b/src/main.C @@ -183,7 +183,15 @@ Konsole::Konsole(const QString& name, m_schema->insertItem(s->title.data(),s->numb); } -//FIXME: we should build a complete session before running it. + // load schema ///////////////////////////////////////////////////////////// + + KeyTrans::loadAll(); + //FIXME: sort + for (int i = 0; i < KeyTrans::count(); i++) + { KeyTrans* s = KeyTrans::find(i); + assert( s ); + m_keytab->insertItem(s->hdr.data(),s->numb); + } // set global options /////////////////////////////////////////////////////// @@ -193,9 +201,8 @@ Konsole::Konsole(const QString& name, : QFrame::NoFrame ); te->setScrollbarLocation(n_scroll); -//FIXME: call newSession here, somehow, instead the stuff below. - // construct initial session /////////////////////////////////////////////// +//FIXME: call newSession here, somehow, instead the stuff below. TESession* initial = new TESession(this,te,pgm,args,"xterm"); @@ -413,12 +420,11 @@ void Konsole::makeMenu() m_schema->setCheckable(TRUE); connect(m_schema, SIGNAL(activated(int)), SLOT(schema_menu_activated(int))); - QPopupMenu* m_keytab = new QPopupMenu; + m_keytab = new QPopupMenu; m_keytab->setCheckable(TRUE); - m_keytab->insertItem( i18n("&xterm"), 1 ); - m_keytab->setItemChecked(1,TRUE); + m_keytab->setItemChecked(0,TRUE); - QPopupMenu* m_codec = new QPopupMenu; + m_codec = new QPopupMenu; m_codec->setCheckable(TRUE); m_codec->insertItem( i18n("&locale"), 1 ); m_codec->setItemChecked(1,TRUE); diff --git a/src/schema.C b/src/schema.C index 76d6563e..4646fe4e 100644 --- a/src/schema.C +++ b/src/schema.C @@ -20,9 +20,6 @@ static int schema_serial = 0; //FIXME: remove,localize -template class QIntDict; -template class QDict; - static QIntDict numb2schema; static QDict path2schema;