-rw-r--r-- | libopie2/opiecore/device/odevice_ipaq.cpp | 55 | ||||
-rw-r--r-- | libopie2/opiecore/device/odevice_simpad.cpp | 52 | ||||
-rw-r--r-- | libopie2/opiecore/okeyfilter.cpp | 119 | ||||
-rw-r--r-- | libopie2/opiecore/okeyfilter.h | 77 | ||||
-rw-r--r-- | libopie2/opiecore/opiecore.pro | 2 |
5 files changed, 255 insertions, 50 deletions
diff --git a/libopie2/opiecore/device/odevice_ipaq.cpp b/libopie2/opiecore/device/odevice_ipaq.cpp index 16c0538..791e409 100644 --- a/libopie2/opiecore/device/odevice_ipaq.cpp +++ b/libopie2/opiecore/device/odevice_ipaq.cpp @@ -1,58 +1,59 @@ /* - This file is part of the Opie Project - Copyright (C) The Opie Team <opie-devel@handhelds.org> + This file is part of the Opie Project + Copyright (C) The Opie Team <opie-devel@handhelds.org> =. .=l. - .>+-= - _;:, .> :=|. This program is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU Library General Public -.="- .-=="i, .._ License as published by the Free Software - - . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This program is distributed in the hope that - + . -:. = it will be useful, but WITHOUT ANY WARRANTY; - : .. .:, . . . without even the implied warranty of - =_ + =;=|` MERCHANTABILITY or FITNESS FOR A - _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU -..}^=.= = ; Library General Public License for more -++= -. .` .: details. - : = ...= . :.=- - -. .:....=;==+<; You should have received a copy of the GNU - -_. . . )=. = Library General Public License along with - -- :-=` this library; see the file COPYING.LIB. + .>+-= +_;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- +-. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "odevice_ipaq.h" /* QT */ #include <qapplication.h> #include <qfile.h> #include <qtextstream.h> #include <qwindowsystem_qws.h> /* OPIE */ #include <qpe/config.h> #include <qpe/resource.h> #include <qpe/sound.h> #include <qpe/qcopenvelope_qws.h> +#include <opie2/okeyfilter.h> /* STD */ #include <fcntl.h> #include <math.h> #include <stdlib.h> #include <signal.h> #include <sys/ioctl.h> #include <sys/time.h> #include <unistd.h> #ifndef QT_NO_SOUND #include <linux/soundcard.h> #endif using namespace Opie::Core; using namespace Opie::Core::Internal; @@ -154,34 +155,36 @@ void iPAQ::init(const QString& model) d->m_rotation = Rot270; break; } m_leds [0] = m_leds [1] = Led_Off; m_power_timer = 0; } void iPAQ::initButtons() { if ( d->m_buttons ) return; - if ( isQWS( ) ) - QWSServer::setKeyboardFilter ( this ); + if ( isQWS( ) ) { + Opie::Core::OKeyFilter::inst()->addPreHandler(this); + //QWSServer::setKeyboardFilter ( this ); + } d->m_buttons = new QValueList <ODeviceButton>; for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { i_button *ib = ipaq_buttons + i; ODeviceButton b; if (( ib->model & d->m_model ) == d->m_model ) { b. setKeycode ( ib->code ); b. setUserText ( QObject::tr ( "Button", ib->utext )); b. setPixmap ( Resource::loadPixmap ( ib->pix )); b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib->fpressedservice ), ib->fpressedaction )); b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib->fheldservice ), ib->fheldaction )); d->m_buttons->append ( b ); } @@ -258,42 +261,42 @@ bool iPAQ::setLedState ( OLed l, OLedState st ) bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) { int newkeycode = keycode; switch ( keycode ) { // H38xx/H39xx have no "Q" key anymore - this is now the Mail key case HardKey_Menu: { if (( d->m_model == Model_iPAQ_H38xx ) || ( d->m_model == Model_iPAQ_H39xx ) || ( d->m_model == Model_iPAQ_H5xxx)) { newkeycode = HardKey_Mail; } break; } - // Rotate cursor keys 180° or 270° + // Rotate cursor keys 180 or 270 case Key_Left : case Key_Right: case Key_Up : case Key_Down : { if (( d->m_model == Model_iPAQ_H31xx ) || ( d->m_model == Model_iPAQ_H38xx )) { newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; } - // Rotate the cursor keys by 270° + // Rotate the cursor keys by 270 // keycode - Key_Left = position of the button starting from left clockwise // add the rotation to it and modolo. No we've the original offset // add the offset to the Key_Left key if ( d-> m_model == Model_iPAQ_H5xxx ) newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4; break; } // map Power Button short/long press to F34/F35 case Key_SysReq: { if ( isPress ) { if ( m_power_timer ) killTimer ( m_power_timer ); m_power_timer = startTimer ( 500 ); } else if ( m_power_timer ) { @@ -397,33 +400,33 @@ bool iPAQ::setDisplayBrightness ( int bright ) FLITE_IN bl; bl. mode = 1; bl. pwr = bright ? 1 : 0; bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); ::close ( fd ); } return res; } int iPAQ::displayBrightnessResolution() const { switch ( model()) { case Model_iPAQ_H31xx: case Model_iPAQ_H36xx: case Model_iPAQ_H37xx: - return 128; // really 256, but >128 could damage the LCD + return 128; // really 256, but >128 could damage the LCD case Model_iPAQ_H38xx: case Model_iPAQ_H39xx: return 64; case Model_iPAQ_H5xxx: return 255; default: return 2; } } bool iPAQ::hasLightSensor() const { return true; diff --git a/libopie2/opiecore/device/odevice_simpad.cpp b/libopie2/opiecore/device/odevice_simpad.cpp index e62ea18..6c3253c 100644 --- a/libopie2/opiecore/device/odevice_simpad.cpp +++ b/libopie2/opiecore/device/odevice_simpad.cpp @@ -1,58 +1,59 @@ /* - This file is part of the Opie Project - Copyright (C) The Opie Team <opie-devel@handhelds.org> + This file is part of the Opie Project + Copyright (C) The Opie Team <opie-devel@handhelds.org> =. .=l. - .>+-= - _;:, .> :=|. This program is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU Library General Public -.="- .-=="i, .._ License as published by the Free Software - - . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This program is distributed in the hope that - + . -:. = it will be useful, but WITHOUT ANY WARRANTY; - : .. .:, . . . without even the implied warranty of - =_ + =;=|` MERCHANTABILITY or FITNESS FOR A - _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU -..}^=.= = ; Library General Public License for more -++= -. .` .: details. - : = ...= . :.=- - -. .:....=;==+<; You should have received a copy of the GNU - -_. . . )=. = Library General Public License along with - -- :-=` this library; see the file COPYING.LIB. + .>+-= +_;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- +-. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "odevice_simpad.h" /* QT */ #include <qapplication.h> #include <qfile.h> #include <qtextstream.h> #include <qwindowsystem_qws.h> /* OPIE */ #include <qpe/config.h> #include <qpe/resource.h> #include <qpe/sound.h> #include <qpe/qcopenvelope_qws.h> +#include <opie2/okeyfilter.h> /* STD */ #include <fcntl.h> #include <math.h> #include <stdlib.h> #include <signal.h> #include <sys/ioctl.h> #include <sys/time.h> #include <unistd.h> #ifndef QT_NO_SOUND #include <linux/soundcard.h> #endif using namespace Opie::Core; using namespace Opie::Core::Internal; @@ -132,34 +133,37 @@ void SIMpad::init(const QString&) break; } //Distribution detecting code is now in base class m_leds [0] = m_leds [1] = Led_Off; m_power_timer = 0; } void SIMpad::initButtons() { if ( d->m_buttons ) return; - if ( isQWS( ) ) - QWSServer::setKeyboardFilter ( this ); + if ( isQWS( ) ) { + Opie::Core::OKeyFilter::inst()->addPreHandler(this); +// QWSServer::setKeyboardFilter ( this ); + } + d->m_buttons = new QValueList <ODeviceButton>; for ( uint i = 0; i < ( sizeof( simpad_buttons ) / sizeof( s_button )); i++ ) { s_button *sb = simpad_buttons + i; ODeviceButton b; if (( sb->model & d->m_model ) == d->m_model ) { b. setKeycode ( sb->code ); b. setUserText ( QObject::tr ( "Button", sb->utext )); b. setPixmap ( Resource::loadPixmap ( sb->pix )); b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( sb->fpressedservice ), sb->fpressedaction )); b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( sb->fheldservice ), sb->fheldaction )); d->m_buttons->append ( b ); } @@ -205,33 +209,33 @@ QValueList <OLedState> SIMpad::ledStateList ( OLed l ) const { QValueList <OLedState> vl; if ( l == Led_Power ) //FIXME which LED is LED2 ? The green one or the amber one? vl << Led_Off << Led_On; //else if ( l == Led_Mail ) //TODO find out if LED1 is accessible anyway //vl << Led_Off; return vl; } OLedState SIMpad::ledState ( OLed l ) const { switch ( l ) { case Led_Power: return m_leds [0]; //case Led_Mail: - // return m_leds [1]; + // return m_leds [1]; default: return Led_Off; } } bool SIMpad::setLedState ( OLed l, OLedState st ) { #if 0 static int fd = ::open ( SIMPAD_BOARDCONTROL, O_RDWR | O_NONBLOCK ); /*TODO Implement this like that: read from cs3 && with SIMPAD_LED2_ON write to cs3 */ m_leds [0] = st; return true; diff --git a/libopie2/opiecore/okeyfilter.cpp b/libopie2/opiecore/okeyfilter.cpp new file mode 100644 index 0000000..d806dbd --- a/dev/null +++ b/libopie2/opiecore/okeyfilter.cpp @@ -0,0 +1,119 @@ +/* + This file is part of the Opie Project + =. Copyright (C) 2004 Rajko 'Alwin' Albrecht <alwin@handhelds.org> + .=l. Copyright (C) The Opie Team <opie-devel@handhelds.org> + .>+-= +_;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- +-. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include "okeyfilter.h" +#include "device/odevice.h" +#include "odebug.h" + +namespace Opie { +namespace Core { + +QValueList<QWSServer::KeyboardFilter*> OKeyFilter::filterList; +QValueList<QWSServer::KeyboardFilter*> OKeyFilter::preFilterList; + +OKeyFilter::OKeyFilter() + :QWSServer::KeyboardFilter() +{ + filterList.clear(); + preFilterList.clear(); + if ( isQWS( ) ) { + QWSServer::setKeyboardFilter ( this ); + } +} + +OKeyFilter::~OKeyFilter() +{ +} + +OKeyFilter* OKeyFilter::inst() +{ + static OKeyFilter*ofilter = 0; + if (!ofilter) { + ofilter = new OKeyFilter; + } + return ofilter; +} + +bool OKeyFilter::filter( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ) +{ + QValueList<QWSServer::KeyboardFilter*>::Iterator iter; + for (iter=preFilterList.begin();iter!=preFilterList.end();++iter) { + if ((*iter)->filter(unicode,keycode,modifiers,isPress,autoRepeat)) { + return true; + } + } + for (iter=filterList.begin();iter!=filterList.end();++iter) { + if ((*iter)->filter(unicode,keycode,modifiers,isPress,autoRepeat)) { + return true; + } + } + return false; +} + +void OKeyFilter::addHandler(QWSServer::KeyboardFilter*aF) +{ + if (filterList.find(aF)!=filterList.end()) { + return; + } + odebug << "adding a keyboard filter handler"<<oendl; + filterList.append(aF); +} + +void OKeyFilter::remHandler(QWSServer::KeyboardFilter*aF) +{ + QValueList<QWSServer::KeyboardFilter*>::Iterator iter; + if ( (iter=filterList.find(aF))==filterList.end() ) { + return; + } + odebug << "removing a keyboard filter handler"<<oendl; + filterList.remove(iter); +} + +void OKeyFilter::addPreHandler(QWSServer::KeyboardFilter*aF) +{ + if (preFilterList.find(aF)!=preFilterList.end()) { + return; + } + odebug << "adding a preferred keyboard filter handler"<<oendl; + preFilterList.append(aF); +} + +void OKeyFilter::remPreHandler(QWSServer::KeyboardFilter*aF) +{ + QValueList<QWSServer::KeyboardFilter*>::Iterator iter; + if ( (iter=preFilterList.find(aF))==preFilterList.end() ) { + return; + } + odebug << "removing a preferred keyboard filter handler"<<oendl; + preFilterList.remove(iter); +} + +/* namespace Core */ +} +/* namespace Opie */ +} diff --git a/libopie2/opiecore/okeyfilter.h b/libopie2/opiecore/okeyfilter.h new file mode 100644 index 0000000..3f9f744 --- a/dev/null +++ b/libopie2/opiecore/okeyfilter.h @@ -0,0 +1,77 @@ +/* + This file is part of the Opie Project + =. Copyright (C) 2004 Rajko 'Alwin' Albrecht <alwin@handhelds.org> + .=l. Copyright (C) The Opie Team <opie-devel@handhelds.org> + .>+-= +_;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- +-. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/* QT */ +#include <qwindowsystem_qws.h> +#include <qvaluelist.h> + +namespace Opie { +namespace Core { + class ODevice; +namespace Internal { + class iPAQ; + class SIMpad; +} + +/** + * A singleton which will manage all possible keyboard filters inside opie. + * It makes sure that key handlers of odevice are checked first than the + * keyfilters of software. + * @short a keyfilter proxy + * @see QWSServer::KeyboardFilter + * @author Rajko Albrecht + * @version 1.0 + */ +class OKeyFilter:public QWSServer::KeyboardFilter +{ + friend class Opie::Core::ODevice; + friend class Opie::Core::Internal::iPAQ; + friend class Opie::Core::Internal::SIMpad; + + static QValueList<QWSServer::KeyboardFilter*> filterList; + static QValueList<QWSServer::KeyboardFilter*> preFilterList; + + OKeyFilter(); + OKeyFilter(const OKeyFilter&):QWSServer::KeyboardFilter(){}; + +protected: + void addPreHandler(QWSServer::KeyboardFilter*); + void remPreHandler(QWSServer::KeyboardFilter*); + +public: + virtual ~OKeyFilter(); + virtual bool filter( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); + + void addHandler(QWSServer::KeyboardFilter*); + void remHandler(QWSServer::KeyboardFilter*); + + static OKeyFilter*inst(); +}; + +} +} diff --git a/libopie2/opiecore/opiecore.pro b/libopie2/opiecore/opiecore.pro index 5056d48..8189a7c 100644 --- a/libopie2/opiecore/opiecore.pro +++ b/libopie2/opiecore/opiecore.pro @@ -1,38 +1,40 @@ TEMPLATE = lib CONFIG += qt warn_on DESTDIR = $(OPIEDIR)/lib HEADERS = oapplication.h \ oconfig.h \ odebug.h \ oglobal.h \ oglobalsettings.h \ okeyconfigmanager.h \ + okeyfilter.h \ opluginloader.h \ oprocess.h \ oprocctrl.h \ osmartpointer.h \ ostorageinfo.h \ xmltree.h SOURCES = oapplication.cpp \ oconfig.cpp \ odebug.cpp \ oglobal.cpp \ oglobalsettings.cpp \ okeyconfigmanager.cpp \ + okeyfilter.cpp \ opluginloader.cpp \ oprocess.cpp \ oprocctrl.cpp \ ostorageinfo.cpp \ xmltree.cpp # The following files are currently not compileable on mac ! # Therfore I removed them from the build .. (eilers) CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) !contains( CONFTEST, y ) { HEADERS += ofilenotify.h SOURCES += ofilenotify.cpp } else { message( "ofilenotify is not available in a mac build !" ) |