[mythtv] patch to add native lirc support
Anduin Withers
awithers at anduin.com
Fri Aug 8 03:18:46 EDT 2003
Since the last patch wasn't applied (maybe a good thing) here is a new
patch. As it turns out it is a supremely bad idea to send an event that has
the potential to destroy a widget followed immediately by another event to
the same widget (think dialogs going away).
--
Anduin Withers
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lircevent.h
Type: application/octet-stream
Size: 619 bytes
Desc: not available
Url : http://mythtv.org/pipermail/mythtv-dev/attachments/20030808/c007d815/lircevent.obj
-------------- next part --------------
Index: lirc.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/lirc.cpp,v
retrieving revision 1.3
diff -u -r1.3 lirc.cpp
--- lirc.cpp 6 Aug 2003 21:20:01 -0000 1.3
+++ lirc.cpp 8 Aug 2003 09:09:12 -0000
@@ -9,6 +9,7 @@
using namespace std;
#include "lirc.h"
+#include "lircevent.h"
LircClient::LircClient(QObject *main_window)
{
@@ -61,62 +62,26 @@
int keycode = 0;
#if (QT_VERSION > 0x030100)
+ // Send a dummy keycode if we couldn't convert the key sequence.
+ // This is done so the main code can output a warning for bad
+ // mappings.
+ if (!a.count())
+ QApplication::postEvent(mainWindow,
+ new LircEvent::LircKeycodeEvent(code, keycode, true));
+
for (unsigned int i = 0; i < a.count(); i++)
{
keycode = a[i];
#else
keycode = a;
#endif
- if (keycode)
- {
- int mod = keycode & MODIFIER_MASK;
- int k = keycode & ~MODIFIER_MASK; /* trim off the mod */
- QString text(QChar(k >> 24));
- QKeyEvent *key_down = new QKeyEvent(QEvent::KeyPress, k,
- k >> 24, mod, text);
- QKeyEvent *key_up = new QKeyEvent(QEvent::KeyRelease, k,
- k >> 24, mod, text);
-
- // Make the key events go to the widgets almost
- // the same way Qt would.
- //
- // Note: You might be tempted to lock the app mutex, don't.
- // If you are unfortunate enough to be in the modal
- // processing loop your lock will block until that loop
- // is done.
- QObject *key_target = NULL;
- if (!key_target)
- key_target = QWidget::keyboardGrabber();
- if (!key_target)
- {
- QWidget *focus_widget = qApp->focusWidget();
- if (focus_widget && focus_widget->isEnabled())
- {
- key_target = focus_widget;
-
- // Yes this is special code for handling the
- // the escape key.
- if (key_down->key() == Key_Escape &&
- focus_widget->topLevelWidget())
- {
- key_target = focus_widget->topLevelWidget();
- }
- }
- }
- if (!key_target)
- key_target = mainWindow;
- QApplication::postEvent(key_target, key_down);
- QApplication::postEvent(key_target, key_up);
- }
+ QApplication::postEvent(mainWindow,
+ new LircEvent::LircKeycodeEvent(code, keycode, true));
+ QApplication::postEvent(mainWindow,
+ new LircEvent::LircKeycodeEvent(code, keycode, false));
#if (QT_VERSION > 0x030100)
}
#endif
- if (!keycode)
- {
- cerr << "LircClient warning: attempt to convert '"
- << code << "' to a key sequence failed. Fix your "
- "key mappings.\n";
- }
}
free(ir);
Index: mythdialogs.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythdialogs.cpp,v
retrieving revision 1.8
diff -u -r1.8 mythdialogs.cpp
--- mythdialogs.cpp 5 Aug 2003 05:42:33 -0000 1.8
+++ mythdialogs.cpp 8 Aug 2003 09:09:13 -0000
@@ -12,6 +12,7 @@
#ifdef USE_LIRC
#include <pthread.h>
#include "lirc.h"
+#include "lircevent.h"
#endif
#include "uitypes.h"
@@ -119,6 +120,57 @@
else
QDialog::keyPressEvent(e);
}
+
+#ifdef USE_LIRC
+void MythMainWindow::customEvent(QCustomEvent *ce)
+{
+ if (ce->type() == LircEvent::letKeycode) {
+ LircEvent::LircKeycodeEvent *lke = (LircEvent::LircKeycodeEvent *)ce;
+ int keycode = lke->getKeycode();
+
+ if (keycode) {
+ int mod = keycode & MODIFIER_MASK;
+ int k = keycode & ~MODIFIER_MASK; /* trim off the mod */
+ QString text(QChar(k >> 24));
+ QKeyEvent key(lke->isKeyDown() ? QEvent::KeyPress :
+ QEvent::KeyRelease, k, k >> 24, mod, text);
+
+ // Make the key events go to the widgets almost
+ // the same way Qt would.
+
+ QObject *key_target = NULL;
+ if (!key_target)
+ key_target = QWidget::keyboardGrabber();
+ if (!key_target)
+ {
+ QWidget *focus_widget = qApp->focusWidget();
+ if (focus_widget && focus_widget->isEnabled())
+ {
+ key_target = focus_widget;
+
+ // Yes this is special code for handling the
+ // the escape key.
+ if (key.key() == Key_Escape &&
+ focus_widget->topLevelWidget())
+ {
+ key_target = focus_widget->topLevelWidget();
+ }
+ }
+ }
+ if (!key_target)
+ key_target = this;
+
+ QApplication::sendEvent(key_target, &key);
+ }
+ else
+ {
+ cerr << "LircClient warning: attempt to convert '"
+ << lke->getLircText() << "' to a key sequence failed. Fix"
+ " your key mappings.\n";
+ }
+ }
+}
+#endif
MythDialog::MythDialog(MythMainWindow *parent, const char *name, bool setsize)
: QFrame(parent, name)
Index: mythdialogs.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythdialogs.h,v
retrieving revision 1.6
diff -u -r1.6 mythdialogs.h
--- mythdialogs.h 20 Jul 2003 02:29:41 -0000 1.6
+++ mythdialogs.h 8 Aug 2003 09:09:14 -0000
@@ -43,6 +43,10 @@
protected:
void keyPressEvent(QKeyEvent *e);
+#ifdef USE_LIRC
+ void customEvent(QCustomEvent *ce);
+#endif
+
float wmult, hmult;
int screenwidth, screenheight;
More information about the mythtv-dev
mailing list