From 67b516688ebe28ebae23296ea72e11ae2fb52cf2 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Mon, 17 Mar 2008 23:41:28 +0000 Subject: [PATCH] Autodetect jogshuttle device, improve handling svn path=/branches/KDE4/; revision=2072 --- src/jogshuttle.cpp | 36 ++++---- src/kdenlivesettings.kcfg | 2 +- src/kdenlivesettingsdialog.cpp | 38 +++++++- src/kdenlivesettingsdialog.h | 2 + src/mainwindow.cpp | 2 +- src/widgets/configjogshuttle_ui.ui | 141 ++++++++++++++++------------- 6 files changed, 137 insertions(+), 84 deletions(-) diff --git a/src/jogshuttle.cpp b/src/jogshuttle.cpp index 6988045a..f53f4916 100644 --- a/src/jogshuttle.cpp +++ b/src/jogshuttle.cpp @@ -54,28 +54,23 @@ #define JOG_STOP 10009 -#include -#include -#include - -#include -#include #include #include #include +#include +#include +#include +#include +#include + + #include "jogshuttle.h" -/*unsigned short jogvalue = 0xffff; -int shuttlevalue = 0xffff; -struct timeval last_shuttle; -int need_synthetic_shuttle; -*/ - void ShuttleThread::init(QObject *parent, QString device) { m_parent = parent; m_device = device; @@ -92,18 +87,23 @@ bool ShuttleThread::isWorking() { void ShuttleThread::run() { kDebug() << "------- STARTING SHUTTLE: " << m_device; + const int fd = open((char *) m_device.toUtf8().data(), O_RDONLY); + if (fd < 0) { + fprintf(stderr, "Can't open Jog Shuttle FILE DESCRIPTOR\n"); + return;; + } EV ev; - FILE * fd = fopen((char *) m_device.toUtf8().data(), "r"); - if (!fd) { - fprintf(stderr, "Can't open file\n"); - exit(1); + if (ioctl(fd, EVIOCGRAB, 1) < 0) { + fprintf(stderr, "Can't get exclusive access on Jog Shuttle FILE DESCRIPTOR\n"); + return;; } while (!stop_me) { - while (fread(&ev, sizeof(ev), 1, fd) == 1) handle_event(ev); + read(fd, &ev, sizeof(ev)); + handle_event(ev); } - + close(fd); } diff --git a/src/kdenlivesettings.kcfg b/src/kdenlivesettings.kcfg index ff442bb7..144478af 100644 --- a/src/kdenlivesettings.kcfg +++ b/src/kdenlivesettings.kcfg @@ -129,7 +129,7 @@ - /dev/input/event0 + diff --git a/src/kdenlivesettingsdialog.cpp b/src/kdenlivesettingsdialog.cpp index 4a73a877..431f9170 100644 --- a/src/kdenlivesettingsdialog.cpp +++ b/src/kdenlivesettingsdialog.cpp @@ -18,10 +18,17 @@ ***************************************************************************/ #include +#include #include #include +#include +#include +#include +#include +#include + #include "profilesdialog.h" #include "kdenlivesettings.h" #include "kdenlivesettingsdialog.h" @@ -53,6 +60,9 @@ KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent): KConfigDialog( QWidget *p5 = new QWidget; m_configShuttle.setupUi(p5); + connect(m_configShuttle.kcfg_enableshuttle, SIGNAL(stateChanged(int)), this, SLOT(slotCheckShuttle(int))); + connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int))); + slotCheckShuttle(KdenliveSettings::enableshuttle()); page5 = addPage(p5, i18n("JogShuttle"), "input-mouse"); QStringList actions; @@ -78,7 +88,6 @@ KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent): KConfigDialog( m_configMisc.profiles_list->addItems(profilesNames); m_defaulfProfile = ProfilesDialog::getSettingsFromFile(KdenliveSettings::default_profile()).value("description"); if (profilesNames.contains(m_defaulfProfile)) m_configMisc.profiles_list->setCurrentItem(m_defaulfProfile); - slotUpdateDisplay(); connect(m_configMisc.profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay())); } @@ -86,6 +95,33 @@ KdenliveSettingsDialog::KdenliveSettingsDialog(QWidget * parent): KConfigDialog( KdenliveSettingsDialog::~KdenliveSettingsDialog() {} +void KdenliveSettingsDialog::slotCheckShuttle(int state) { + m_configShuttle.config_group->setEnabled(state); + if (m_configShuttle.shuttledevicelist->count() == 0) { + // parse devices + QString baseName = "/dev/input/event"; + int fd; + for (int i = 0; i < 30; i++) { + QString filename = baseName + QString::number(i); + kDebug() << "/// CHECKING OFR: " << filename; + + char name[256] = "unknown"; + fd = ::open((char *) filename.toUtf8().data(), O_RDONLY); + if (fd >= 0 && ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0) { + m_configShuttle.shuttledevicelist->addItem(name, filename); + } + ::close(fd); + } + if (KdenliveSettings::shuttledevice().isEmpty()) QTimer::singleShot(1500, this, SLOT(slotUpdateShuttleDevice())); + } +} + +void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix) { + QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString(); + //KdenliveSettings::setShuttledevice(device); + m_configShuttle.kcfg_shuttledevice->setText(device); +} + void KdenliveSettingsDialog::rebuildVideo4Commands() { QString captureCommand; if (!m_configCapture.kcfg_video4adevice->text().isEmpty()) captureCommand = "-f " + m_configCapture.kcfg_video4aformat->text() + " -i " + m_configCapture.kcfg_video4adevice->text(); diff --git a/src/kdenlivesettingsdialog.h b/src/kdenlivesettingsdialog.h index cd82bf13..c74e66c0 100644 --- a/src/kdenlivesettingsdialog.h +++ b/src/kdenlivesettingsdialog.h @@ -44,6 +44,8 @@ protected: private slots: void slotUpdateDisplay(); void rebuildVideo4Commands(); + void slotCheckShuttle(int state = 0); + void slotUpdateShuttleDevice(int ix = 0); private: KPageWidgetItem *page1; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 899ce884..4860a515 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -295,7 +295,7 @@ void MainWindow::slotShuttleButton(int code) { void MainWindow::slotShuttleAction(int code) { switch (code) { case 0: - return; + return; case 1: m_monitorManager->slotPlay(); break; diff --git a/src/widgets/configjogshuttle_ui.ui b/src/widgets/configjogshuttle_ui.ui index 0c2dafaa..9abb022f 100644 --- a/src/widgets/configjogshuttle_ui.ui +++ b/src/widgets/configjogshuttle_ui.ui @@ -5,12 +5,12 @@ 0 0 - 299 - 260 + 325 + 285 - - + + Enable Jog Shuttle device @@ -18,70 +18,85 @@ - - - Device path + + + false - - - - - - /dev/input/event1 + + Device configuration + + + + + Device + + + + + + + + + + + + + + + + + Button 1 + + + + + + + + + + Button 2 + + + + + + + + + + Button 3 + + + + + + + + + + Button 4 + + + + + + + + + + Button 5 + + + + + + + - - - Button 1 - - - - - - - - - - Button 2 - - - - - - - - - - Button 3 - - - - - - - - - - Button 4 - - - - - - - - - - Button 5 - - - - - - - Qt::Vertical -- 2.39.2