summaryrefslogtreecommitdiff
path: root/app-misc/ckb/files/ckb-0.4.0-modprobe.patch
blob: 31dc3303b3283b028731f620431b25a58aad0c02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
 src/daemon/input_linux.c | 21 ++++++++++++++-------
 src/gui/mainwindow.cpp   | 14 ++++++++------
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/src/daemon/input_linux.c b/src/daemon/input_linux.c
index 0391243e..8489f5b5 100644
--- a/src/daemon/input_linux.c
+++ b/src/daemon/input_linux.c
@@ -55,13 +55,20 @@ int uinputopen(struct uinput_user_dev* indev, int mouse){
 ///
 /// Some tips on using [uinput_user_dev in](http://thiemonge.org/getting-started-with-uinput)
 int os_inputopen(usbdevice* kb){
-    /// First check whether the uinput module is loaded by the kernel.
-    ///
-    // Load the uinput module (if it's not loaded already)
-    if(system("modprobe uinput") != 0) {
-        ckb_fatal("Failed to load uinput module\n");
-        return 1;
+    /// Let's see if uinput is already available
+    int fd = open("/dev/uinput", O_RDWR);
+    if(fd < 0){
+        fd = open("/dev/input/uinput", O_RDWR);
+    }
+
+    // If not available, load the module
+    if(fd < 0){
+        if(system("modprobe uinput") != 0) {
+            ckb_fatal("Failed to load uinput module\n");
+            return 1;
+        }
     }
+    close(fd);
 
     if(IS_SINGLE_EP(kb)) {
         kb->uinput_kb = 0;
@@ -79,7 +86,7 @@ int os_inputopen(usbdevice* kb){
     indev.id.product = kb->product;
     indev.id.version = kb->fwversion;
     // Open keyboard
-    int fd = uinputopen(&indev, 0);
+    fd = uinputopen(&indev, 0);
     kb->uinput_kb = fd;
     if(fd <= 0)
         return 0;
diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp
index 968764e7..1eb95bda 100644
--- a/src/gui/mainwindow.cpp
+++ b/src/gui/mainwindow.cpp
@@ -282,14 +282,16 @@ void MainWindow::updateVersion(){
         if(kextstatOut.isEmpty())
             daemonWarning.append(tr("<br /><b>Warning:</b> System Extension by \"Fumihiko Takayama\" is not allowed in Security & Privacy. Please allow it and then unplug and replug your devices."));
 #elif defined(Q_OS_LINUX)
-            QProcess modprobe;
-            modprobe.start("modprobe", QStringList("uinput"));
+            if(!(QFileInfo("/dev/uinput").exists() || QFileInfo("/dev/input/uinput").exists())){
+                QProcess modprobe;
+                modprobe.start("modprobe", QStringList("uinput"));
 
-            if(!modprobe.waitForFinished())
-                qDebug() << "Modprobe error";
+                if(!modprobe.waitForFinished())
+                    qDebug() << "Modprobe error";
 
-            if(modprobe.exitCode())
-                daemonWarning.append(tr("<br /><b>Warning:</b> The uinput module could not be loaded. If this issue persists after rebooting, compile a kernel with CONFIG_INPUT_UINPUT=y."));
+                if(modprobe.exitCode())
+                    daemonWarning.append(tr("<br /><b>Warning:</b> The uinput module could not be loaded. If this issue persists after rebooting, compile a kernel with CONFIG_INPUT_UINPUT=y."));
+            }
 #endif
         settingsWidget->setStatus(tr("No devices connected") + daemonWarning);
     }