r5323 vince - in /branches/vince/netsurf-fb/framebuffer: fb_gui.c fb_gui.h fb_init_able.c fb_init_linux.c

netsurf at semichrome.net netsurf at semichrome.net
Mon Sep 15 16:32:48 BST 2008


Author: vince
Date: Mon Sep 15 10:32:47 2008
New Revision: 5323

URL: http://source.netsurf-browser.org?rev=5323&view=rev
Log:
abstract out OS specific input

Modified:
    branches/vince/netsurf-fb/framebuffer/fb_gui.c
    branches/vince/netsurf-fb/framebuffer/fb_gui.h
    branches/vince/netsurf-fb/framebuffer/fb_init_able.c
    branches/vince/netsurf-fb/framebuffer/fb_init_linux.c

Modified: branches/vince/netsurf-fb/framebuffer/fb_gui.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_gui.c?rev=5323&r1=5322&r2=5323&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_gui.c (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_gui.c Mon Sep 15 10:32:47 2008
@@ -79,7 +79,7 @@
 
         option_max_cached_fetch_handles=1;
 
-        framebuffer = fb_init_os(argc, argv);
+        framebuffer = fb_os_init(argc, argv);
 
         //default_stylesheet_url = "file:/(cd0)/res/default.css";
         default_stylesheet_url = strdup("http://jennifer.kyllikki.org/~vince/res/default.css");
@@ -106,8 +106,6 @@
                 exit(1);
         }
 
-        /* set stdin to nonblocking */
-        fcntl(0, F_SETFL, O_NONBLOCK);
 
 }
 
@@ -131,34 +129,6 @@
 void gui_multitask(void)
 {
     //    LOG(("gui_multitask"));
-}
-
-static void fb_service_input(struct gui_window *g) 
-{
-        ssize_t amt;
-        char key;
-
-        amt = read(0, &key, 1);
-
-        if (amt > 0) {
-                if (key == 'j') {
-                        g->redraw_required = true;
-                        g->scrolly +=100;
-                }
-                if (key == 'k') {
-                        g->redraw_required = true;
-                        g->scrolly -=100;
-                        if (g->scrolly < 0)
-                                g->scrolly = 0;
-                }
-                if (key == 'q') {
-                        browser_window_destroy(g->bw);
-                }
-                if (key == 'd') {
-                        list_schedule();
-                }
-        }
-
 }
 
 void gui_poll(bool active)
@@ -169,7 +139,7 @@
     //LOG(("enter schedule run"));
     schedule_run();
 
-    fb_service_input(current_window);
+    fb_os_input(current_window);
 
     if (current_window && current_window->redraw_required)
             fb_redraw(current_window);
@@ -179,7 +149,7 @@
 void gui_quit(void)
 {
         LOG(("gui_quit"));
-        fb_quit_os(framebuffer);
+        fb_os_quit(framebuffer);
 }
 
 

Modified: branches/vince/netsurf-fb/framebuffer/fb_gui.h
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_gui.h?rev=5323&r1=5322&r2=5323&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_gui.h (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_gui.h Mon Sep 15 10:32:47 2008
@@ -36,6 +36,7 @@
     struct browser_window *bw; /* The browser window connected to this gui window */
 };
 
-extern framebuffer_t *fb_init_os(int argc, char** argv);
-extern void fb_quit_os(framebuffer_t *fb);
+extern framebuffer_t *fb_os_init(int argc, char** argv);
+extern void fb_os_quit(framebuffer_t *fb);
+extern void fb_os_input(struct gui_window *g);
 

Modified: branches/vince/netsurf-fb/framebuffer/fb_init_able.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_init_able.c?rev=5323&r1=5322&r2=5323&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_init_able.c (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_init_able.c Mon Sep 15 10:32:47 2008
@@ -62,11 +62,42 @@
         }
 
 
+        /* set stdin to nonblocking */
+        fcntl(0, F_SETFL, O_NONBLOCK);
+
         return newfb;
 }
 
 void fb_quit_os(framebuffer_t *fb)
 {
+}
+
+static void fb_service_input(struct gui_window *g) 
+{
+        ssize_t amt;
+        char key;
+
+        amt = read(0, &key, 1);
+
+        if (amt > 0) {
+                if (key == 'j') {
+                        g->redraw_required = true;
+                        g->scrolly +=100;
+                }
+                if (key == 'k') {
+                        g->redraw_required = true;
+                        g->scrolly -=100;
+                        if (g->scrolly < 0)
+                                g->scrolly = 0;
+                }
+                if (key == 'q') {
+                        browser_window_destroy(g->bw);
+                }
+                if (key == 'd') {
+                        list_schedule();
+                }
+        }
+
 }
 
 /*

Modified: branches/vince/netsurf-fb/framebuffer/fb_init_linux.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_init_linux.c?rev=5323&r1=5322&r2=5323&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_init_linux.c (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_init_linux.c Mon Sep 15 10:32:47 2008
@@ -18,6 +18,8 @@
 #include <linux/vt.h>
 #include <linux/fb.h>
 
+#include <linux/input.h>
+
 #include "css/css.h"
 #include "framebuffer/fb_gui.h"
 #include "framebuffer/fb_plotters.h"
@@ -47,6 +49,8 @@
 static struct fb_var_screeninfo  fb_ovar;
 static unsigned short            ored[256], ogreen[256], oblue[256], otransp[256];
 static struct fb_cmap            ocmap = { 0, 256, ored, ogreen, oblue, otransp };
+
+int inputfd;
 
 /* -------------------------------------------------------------------- */
 /* devices                                                              */
@@ -485,7 +489,7 @@
         exit(42);
 }
 
-framebuffer_t *fb_init_os(int argc, char** argv)
+framebuffer_t *fb_os_init(int argc, char** argv)
 {
         framebuffer_t *newfb;
 int ploop;
@@ -509,12 +513,56 @@
         }
 
 
+
+        inputfd = open("/dev/input/event0", O_RDONLY);
+        if (inputfd < 0) {
+                fprintf(stderr, "Unable to open /dev/input/event0 no keyboard\n");                
+        }
         return newfb;
 }
 
-void fb_quit_os(framebuffer_t *fb)
+void fb_os_quit(framebuffer_t *fb)
 {
         fb_cleanup();
+}
+
+void fb_os_input(struct gui_window *g) 
+{
+        ssize_t amt;
+        struct input_event event;       
+
+        if(inputfd < 0)
+                return;
+
+        amt = read(inputfd, &event, sizeof(struct input_event));
+
+        if (amt > 0) {
+                if (event.type != EV_KEY)
+                        return;
+
+                switch (event.code) {
+                case KEY_J:
+                        g->redraw_required = true;
+                        g->scrolly +=100;
+                        break;
+
+                case KEY_K:
+                        g->redraw_required = true;
+                        g->scrolly -=100;
+                        if (g->scrolly < 0)
+                                g->scrolly = 0;
+                        break;
+
+                case KEY_Q:
+                        browser_window_destroy(g->bw);
+                        break;
+
+                case KEY_D:
+                        list_schedule();
+                        break;
+                }
+        }
+
 }
 
 /*




More information about the netsurf-commits mailing list