00001 /*************************************************************************** 00002 * Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider, * 00003 * Matthias Hardt, Guido Madaus * 00004 * * 00005 * Copyright (C) 2007-2008 BerLinux Solutions GbR * 00006 * Stefan Schwarzer & Guido Madaus * 00007 * * 00008 * Copyright (C) 2009-2013 BerLinux Solutions GmbH * 00009 * * 00010 * Authors: * 00011 * Stefan Schwarzer <stefan.schwarzer@diskohq.org>, * 00012 * Matthias Hardt <matthias.hardt@diskohq.org>, * 00013 * Jens Schneider <jens.schneider@diskohq.org>, * 00014 * Guido Madaus <guido.madaus@diskohq.org>, * 00015 * Patrick Helterhoff <patrick.helterhoff@diskohq.org>, * 00016 * René Bählkow <rene.baehlkow@diskohq.org> * 00017 * * 00018 * This library is free software; you can redistribute it and/or * 00019 * modify it under the terms of the GNU Lesser General Public * 00020 * License version 2.1 as published by the Free Software Foundation. * 00021 * * 00022 * This library is distributed in the hope that it will be useful, * 00023 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00025 * Lesser General Public License for more details. * 00026 * * 00027 * You should have received a copy of the GNU Lesser General Public * 00028 * License along with this library; if not, write to the * 00029 * Free Software Foundation, Inc., * 00030 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 00031 **************************************************************************/ 00032 00033 #include "mmsinput/mmsinputthread.h" 00034 #include "mmsinput/mmsinputdfbhandler.h" 00035 #include "mmsinput/mmsinputx11handler.h" 00036 #include "mmsinput/mmsinputlishandler.h" 00037 #include "mmsgui/fb/mmsfb.h" 00038 00039 extern MMSFB *mmsfb; 00040 00041 00042 MMSInputThread::MMSInputThread(class MMSInputManager *manager, MMS_INPUT_DEVICE device, int inputinterval) { 00043 this->manager = manager; 00044 this->handler = NULL; 00045 this->device = device; 00046 this->inputinterval = inputinterval; 00047 } 00048 00049 MMSInputThread::~MMSInputThread() { 00050 delete handler; 00051 } 00052 00053 void MMSInputThread::threadMain() { 00054 MMSInputEvent event, lastevent; 00055 time_t aclock; 00056 struct timeval tv; 00057 double currtime, lasttime = 0; 00058 int lkcnt = 0, skip = 0; 00059 00060 lastevent.type = MMSINPUTEVENTTYPE_NONE; 00061 lastevent.key = MMSKEY_UNKNOWN; 00062 00063 if (this->handler == NULL) { 00064 if (mmsfb->getBackend()==MMSFB_BE_DFB) { 00065 this->handler = new MMSInputDFBHandler(this->device); 00066 } 00067 else 00068 if ((mmsfb->getBackend()==MMSFB_BE_FBDEV) || (mmsfb->getBackend()==MMSFB_BE_KMS)) { 00069 this->handler = new MMSInputLISHandler(this->device); 00070 } 00071 else 00072 if (mmsfb->getBackend()==MMSFB_BE_X11) { 00073 this->handler = new MMSInputX11Handler(this->device); 00074 } 00075 00076 00077 /* if(config->getOutputType()!= MMS_OT_X11FB) { 00078 //create dfb input backend 00079 this->handler = new MMSInputDFBHandler(this->device); 00080 } else { 00081 #ifdef __HAVE_XLIB__ 00082 if(mmsfb->getBackend()==MMSFB_BACKEND_X11) { 00083 this->handler = new MMSInputX11Handler(this->device); 00084 } else { 00085 //allthough we have xlib directfb is used; 00086 this->handler = new MMSInputDFBHandler(this->device); 00087 } 00088 #else 00089 //we have no xlib so its dfb x11 00090 this->handler = new MMSInputDFBHandler(this->device); 00091 #endif 00092 } 00093 */ 00094 } 00095 00096 while (1) { 00097 this->handler->grabEvents(&event); 00098 00099 if (event.type == MMSINPUTEVENTTYPE_KEYPRESS) { 00100 if (this->inputinterval > 0) { 00101 /* here we stop to fast input devices */ 00102 00103 /* get time in milliseconds */ 00104 time(&aclock); 00105 gettimeofday(&tv, NULL); 00106 currtime = ((double) aclock) * 1000 + ((double) tv.tv_usec) / 1000; 00107 00108 if (event.key == lastevent.key) { 00109 /* check if input comes slow enough */ 00110 if (currtime < lasttime + ((!skip)?this->inputinterval:(this->inputinterval/2))) { 00111 /* to fast, ignore the input */ 00112 lkcnt++; 00113 continue; 00114 } 00115 } 00116 else 00117 lkcnt = 0; 00118 00119 /* save the last event */ 00120 lastevent = event; 00121 00122 /* check if the last input is to old */ 00123 skip=0; 00124 if (lkcnt > 0) { 00125 if (currtime > lasttime + this->inputinterval*2) 00126 /* to old */ 00127 lkcnt = 0; 00128 else 00129 /* the next loop we want the input faster */ 00130 skip = 1; 00131 } 00132 00133 /* save current time */ 00134 lasttime = currtime; 00135 } 00136 } 00137 00138 /* to the input manager */ 00139 this->manager->handleInput(&event); 00140 00141 /* call garbage handler */ 00142 callGarbageHandler(); 00143 } 00144 } 00145