[mythtv] patch to add native lirc support
Anduin Withers
awithers at anduin.com
Thu Aug 7 01:22:00 EDT 2003
> I seem to have spoken too soon. There is still a focus problem with all
> widgets we use from Qt, the widgets that are implemented within mythtv
> do no have this problem.
Ah, my objective was different, I was looking to fix things when myth had
focus. The way key events filter from top to bottom not having an accurate
focus widget presents a problem.
The attached patch won't fix the problem you describe. However it is a lot
cleaner (thread wise) and will probably make a better jumping point.
What's in the patch?
Code to post a custom event to the main window, which handles it pretty much
the way it did before.
--
Anduin Withers
-------------- 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 7 Aug 2003 04:04:30 -0000
@@ -9,6 +9,7 @@
using namespace std;
#include "lirc.h"
+#include "lircevent.h"
LircClient::LircClient(QObject *main_window)
{
@@ -61,62 +62,24 @@
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));
+
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));
#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 7 Aug 2003 04:04:42 -0000
@@ -12,6 +12,7 @@
#ifdef USE_LIRC
#include <pthread.h>
#include "lirc.h"
+#include "lircevent.h"
#endif
#include "uitypes.h"
@@ -119,6 +120,58 @@
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_down(QEvent::KeyPress, k, k >> 24, mod, text);
+ QKeyEvent key_up(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_down.key() == Key_Escape &&
+ focus_widget->topLevelWidget())
+ {
+ key_target = focus_widget->topLevelWidget();
+ }
+ }
+ }
+ if (!key_target)
+ key_target = this;
+
+ QApplication::sendEvent(key_target, &key_down);
+ QApplication::sendEvent(key_target, &key_up);
+ }
+ 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 7 Aug 2003 04:04:48 -0000
@@ -43,6 +43,10 @@
protected:
void keyPressEvent(QKeyEvent *e);
+#ifdef USE_LIRC
+ void customEvent(QCustomEvent *ce);
+#endif
+
float wmult, hmult;
int screenwidth, screenheight;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lircevent.h
Type: application/octet-stream
Size: 497 bytes
Desc: not available
Url : http://mythtv.org/pipermail/mythtv-dev/attachments/20030807/a9886378/lircevent.obj
More information about the mythtv-dev
mailing list