r5422 dsilvers - in /branches/vince/netsurf-fb/framebuffer: fb_frontend_linuxfb.c fb_options.h

netsurf at semichrome.net netsurf at semichrome.net
Tue Sep 23 14:39:01 BST 2008


Author: dsilvers
Date: Tue Sep 23 08:39:00 2008
New Revision: 5422

URL: http://source.netsurf-browser.org?rev=5422&view=rev
Log:
Rework linux fb frontend to support scanning and opening all event devices for input

Modified:
    branches/vince/netsurf-fb/framebuffer/fb_frontend_linuxfb.c
    branches/vince/netsurf-fb/framebuffer/fb_options.h

Modified: branches/vince/netsurf-fb/framebuffer/fb_frontend_linuxfb.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_frontend_linuxfb.c?rev=5422&r1=5421&r2=5422&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_frontend_linuxfb.c (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_frontend_linuxfb.c Tue Sep 23 08:39:00 2008
@@ -31,6 +31,8 @@
 #include <sys/mman.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
+#include <dirent.h>
+#include <fnmatch.h>
 
 #include <linux/kd.h>
 #include <linux/vt.h>
@@ -75,8 +77,12 @@
 static unsigned short            ored[256], ogreen[256], oblue[256], otransp[256];
 static struct fb_cmap            ocmap = { 0, 256, ored, ogreen, oblue, otransp };
 
-int keyboardfd;
-int mousefd;
+typedef struct _input_dev {
+        struct _input_dev *next;
+        int fd;
+} fb_input_dev;
+
+static fb_input_dev *inputdevs = 0;
 
 /* -------------------------------------------------------------------- */
 /* devices                                                              */
@@ -110,6 +116,45 @@
                 devices = &devs_devfs;
         else
                 devices = &devs_default;
+}
+
+static char *
+fconcat(const char *base, const char *leaf)
+{
+        static char buffer[PATH_MAX];
+        snprintf(buffer, PATH_MAX, "%s/%s", base, leaf);
+        return buffer;
+}
+
+/* Input device opening */
+static void
+fb_open_input_devices(void)
+{
+        DIR *dir;
+        fb_input_dev *d;
+        struct dirent *de;
+        const char *basepath = option_fb_input_devpath ? option_fb_input_devpath : "/dev/input";
+        
+        dir = opendir(basepath);
+        
+        if (dir == NULL)
+                return;
+        
+        while ((de = readdir(dir)) != NULL) {
+                if (fnmatch(option_fb_input_glob ? option_fb_input_glob : "event*",
+                            de->d_name, 0) == 0) {
+                        char *cc = fconcat(basepath, de->d_name);
+                        int fd = open(cc, O_RDONLY | O_NONBLOCK);
+                        if (fd >= 0) {
+                                d = calloc(1, sizeof(fb_input_dev));
+                                d->next = inputdevs;
+                                inputdevs = d;
+                                d->fd = fd;
+                        }
+                }
+        }
+        
+        closedir(dir);
 }
 
 /* -------------------------------------------------------------------- */
@@ -536,17 +581,8 @@
         }
 
 
-
-        keyboardfd = open("/dev/input/event0", O_RDONLY | O_NONBLOCK);
-        if (keyboardfd < 0) {
-                fprintf(stderr, "Unable to open /dev/input/event0 no keyboard\n");                
-        } 
+        fb_open_input_devices();
         
-        mousefd = open("/dev/input/event2", O_RDONLY | O_NONBLOCK);
-        if (mousefd < 0) {
-                fprintf(stderr, "Unable to open /dev/input/event2 no mouse\n");                
-        } 
-
         return newfb;
 }
 
@@ -559,76 +595,55 @@
 {
         ssize_t amt;
         struct input_event event;       
-
-        if (keyboardfd >= 0) {
-
-                amt = read(keyboardfd, &event, sizeof(struct input_event));
-
+        fb_input_dev *d;
+        
+        for (d = inputdevs; d != NULL; d = d->next) {
+                amt = read(d->fd, &event, sizeof(struct input_event));
+                
                 if (amt > 0) {
-                        if (event.type != EV_KEY)
-                                return;
-
-                        if (event.value == 0)
-                                return;
-
-                        switch (event.code) {
-                        case KEY_J:
-				fb_window_scroll(g, 0, 100);
-                                break;
-
-                        case KEY_K:
-				fb_window_scroll(g, 0, -100);
-                                break;
-
-                        case KEY_Q:
-                                browser_window_destroy(g->bw);
-                                break;
-
-                        case KEY_D:
-                                list_schedule();
-                                break;
-
-                        case KEY_UP:
-                                fb_cursor_move(framebuffer, 0, -1);
-                                break;
-
-                        case KEY_DOWN:
-                                fb_cursor_move(framebuffer, 0, 1);
-                                break;
-
-                        case KEY_LEFT:
-                                fb_cursor_move(framebuffer, -1, 0);
-                                break;
-
-                        case KEY_RIGHT:
-                                fb_cursor_move(framebuffer, 1, 0);
-                                break;
-                        }
-                }
-        }
-
-        if (mousefd >= 0) {
-
-                while((amt = read(mousefd, 
-                                  &event, 
-                                  sizeof(struct input_event))) > 0) {
-
-                        switch (event.type) {
-                        case EV_KEY:
-                                if (event.value != 0)
-                                        break;
-
+                        if (event.type == EV_KEY) {
+                                if (event.value == 0)
+                                        return;
+                                
                                 switch (event.code) {
+                                case KEY_J:
+                                        fb_window_scroll(g, 0, 100);
+                                        break;
+                                        
+                                case KEY_K:
+                                        fb_window_scroll(g, 0, -100);
+                                        break;
+                                        
+                                case KEY_Q:
+                                        browser_window_destroy(g->bw);
+                                        break;
+                                        
+                                case KEY_D:
+                                        list_schedule();
+                                        break;
+                                        
+                                case KEY_UP:
+                                        fb_cursor_move(framebuffer, 0, -1);
+                                        break;
+                                        
+                                case KEY_DOWN:
+                                        fb_cursor_move(framebuffer, 0, 1);
+                                        break;
+                                        
+                                case KEY_LEFT:
+                                        fb_cursor_move(framebuffer, -1, 0);
+                                        break;
+                                        
+                                case KEY_RIGHT:
+                                        fb_cursor_move(framebuffer, 1, 0);
+                                        break;
                                 case BTN_LEFT:
                                         fb_cursor_click(framebuffer,
                                                         g, 
                                                         BROWSER_MOUSE_CLICK_1);
                                         break;
                                 }
-                                break;
-
-                        case EV_REL:
-				
+                        } else if (event.type == EV_REL) {
                                 switch (event.code) {
 				case 0:
                                         fb_cursor_move(framebuffer, 
@@ -646,11 +661,10 @@
 					fb_window_scroll(g, 0, event.value * -100);
 					break;
                                 }
-                                break;
                         }
-                }
-        }
-
+                        
+                }
+        }
 }
 
 void

Modified: branches/vince/netsurf-fb/framebuffer/fb_options.h
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_options.h?rev=5422&r1=5421&r2=5422&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_options.h (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_options.h Tue Sep 23 08:39:00 2008
@@ -23,13 +23,19 @@
 
 extern char *option_fb_mode;
 extern char *option_fb_device;
+extern char *option_fb_input_devpath;
+extern char *option_fb_input_glob;
 
-#define EXTRA_OPTION_DEFINE \
-char *option_fb_mode = 0; \
-char *option_fb_device = 0;
+#define EXTRA_OPTION_DEFINE                     \
+  char *option_fb_mode = 0;                     \
+  char *option_fb_device = 0;                   \
+  char *option_fb_input_devpath = 0;            \
+  char *option_fb_input_glob = 0;
 
 #define EXTRA_OPTION_TABLE \
   { "fb_mode", OPTION_STRING,	&option_fb_mode },      \
-  { "fb_device", OPTION_STRING, &option_fb_device },
+  { "fb_device", OPTION_STRING, &option_fb_device },    \
+  { "fb_input_devpath", OPTION_STRING, &option_fb_input_devpath },      \
+  { "fb_input_glob", OPTION_STRING, &option_fb_input_glob },
 
 #endif




More information about the netsurf-commits mailing list