From d6cd92e0ccb2f78ec197e02ba714344951075a41 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 14 Feb 2009 12:49:21 +0000 Subject: Fix resource handling buy copying the GTK approach Cleanup mouse movement handlig svn path=/trunk/netsurf/; revision=6486 --- Makefile | 1 - Makefile.config | 5 -- framebuffer/fb_cursor.c | 10 +--- framebuffer/fb_cursor.h | 2 - framebuffer/fb_findfile.c | 116 ++++++++++++++++++++++++------------------ framebuffer/fb_findfile.h | 5 +- framebuffer/fb_frontend_sdl.c | 2 +- framebuffer/fb_gui.c | 25 ++++++--- framebuffer/fb_rootwindow.c | 13 ++++- framebuffer/fb_rootwindow.h | 2 + nsfb | 25 +++++++++ 11 files changed, 129 insertions(+), 77 deletions(-) create mode 100755 nsfb diff --git a/Makefile b/Makefile index e419cf7fa..79f8d7d9e 100644 --- a/Makefile +++ b/Makefile @@ -467,7 +467,6 @@ ifeq ($(TARGET),framebuffer) NETSURF_FEATURE_GIF_CFLAGS := -DWITH_GIF CFLAGS += '-DNETSURF_FB_RESPATH="$(NETSURF_FB_RESPATH_$(NETSURF_FB_FRONTEND))"' - CFLAGS += '-DNETSURF_FB_HOMEPATH="$(NETSURF_FB_HOMEPATH_$(NETSURF_FB_FRONTEND))"' CFLAGS += -Dnsfb ifeq ($(NETSURF_FB_FRONTEND),linux) diff --git a/Makefile.config b/Makefile.config index 23e5d3d85..0a17205f7 100644 --- a/Makefile.config +++ b/Makefile.config @@ -219,11 +219,6 @@ ifeq ($(TARGET),framebuffer) NETSURF_FB_RESPATH_dummy := ./ NETSURF_FB_RESPATH_sdl := ./ - NETSURF_FB_HOMEPATH_linux := ~/.netsurf/ - NETSURF_FB_HOMEPATH_able := (tftpboot)/ - NETSURF_FB_HOMEPATH_dummy := ./ - NETSURF_FB_HOMEPATH_sdl := ~/.netsurf/ - endif # Include any local overrides diff --git a/framebuffer/fb_cursor.c b/framebuffer/fb_cursor.c index 97632caec..96e280223 100644 --- a/framebuffer/fb_cursor.c +++ b/framebuffer/fb_cursor.c @@ -137,8 +137,9 @@ static void fb_cursor_clear(framebuffer_t *fb) } +/* move cursor to absolute position */ void -fb_cursor_move_abs(framebuffer_t *fb, int x, int y) +fb_cursor_move(framebuffer_t *fb, int x, int y) { fb_cursor_clear(fb); @@ -152,13 +153,6 @@ fb_cursor_move_abs(framebuffer_t *fb, int x, int y) fb->cursor->x = fb->width; if (fb->cursor->y > fb->height) fb->cursor->y = fb->height; - -} - -void -fb_cursor_move(framebuffer_t *fb, int x, int y) -{ - fb_cursor_move_abs(fb, fb->cursor->x + x, fb->cursor->y + y); } void diff --git a/framebuffer/fb_cursor.h b/framebuffer/fb_cursor.h index 6451094fc..97cc5eb43 100644 --- a/framebuffer/fb_cursor.h +++ b/framebuffer/fb_cursor.h @@ -25,8 +25,6 @@ int fb_cursor_y(framebuffer_t *fb); void fb_cursor_move(struct framebuffer_s *fb, int x, int y); -void fb_cursor_move_abs(struct framebuffer_s *fb, int x, int y); - void fb_cursor_plot(struct framebuffer_s *fb); fb_cursor_t *fb_cursor_init(struct framebuffer_s *fb); diff --git a/framebuffer/fb_findfile.c b/framebuffer/fb_findfile.c index 2e0397e15..acfed41ca 100644 --- a/framebuffer/fb_findfile.c +++ b/framebuffer/fb_findfile.c @@ -23,65 +23,81 @@ #include #include +#include "utils/log.h" + #include "fb_findfile.h" -static bool -fb_findfile_exists(char *buffer, const char *base, const char *filename) +char *path_to_url(const char *path) { - if (base == NULL) - return false; - - if (*base == '~') { - snprintf(buffer, PATH_MAX, "%s/%s/%s", - getenv("HOME") ? getenv("HOME") : "", - base + 1, filename); - } else { - snprintf(buffer, PATH_MAX, "%s/%s", base, filename); - } - - return (access(buffer, R_OK) == 0); -} + char *r = malloc(strlen(path) + 7 + 1); -char * -fb_findfile(const char *filename) -{ - static char buffer[PATH_MAX]; - - /* Search sequence is: - * home/filename - * res-env/filename - * resources/filename - */ - - if (fb_findfile_exists(buffer, NETSURF_FB_HOMEPATH, filename)) - return buffer; - if (fb_findfile_exists(buffer, getenv("NETSURF_RES"), filename)) - return buffer; - if (fb_findfile_exists(buffer, NETSURF_FB_RESPATH, filename)) - return buffer; - - return NULL; + strcpy(r, "file://"); + strcat(r, path); + + return r; } -char * -fb_findfile_asurl(const char *filename) +/** + * Locate a shared resource file by searching known places in order. + * + * \param buf buffer to write to. must be at least PATH_MAX chars + * \param filename file to look for + * \param def default to return if file not found + * \return buf + * + * Search order is: ~/.netsurf/, $NETSURFRES/ (where NETSURFRES is an + * environment variable), and finally the path specified by NETSURF_FB_RESPATH + * from the Makefile + */ + +char *fb_find_resource(char *buf, const char *filename, const char *def) { - static char buffer[PATH_MAX]; - char *f; - - if (strncmp(filename, "http://", 5) == 0) - return strdup(filename); - - f = fb_findfile(filename); - - if (f == NULL) - return NULL; - - snprintf(buffer, PATH_MAX, "file://%s", f); - - return strdup(buffer); + char *cdir = getenv("HOME"); + char t[PATH_MAX]; + + if (cdir != NULL) { + strcpy(t, cdir); + strcat(t, "/.netsurf/"); + strcat(t, filename); + if (realpath(t, buf) != NULL) { + if (access(buf, R_OK) == 0) + return buf; + } + } + + cdir = getenv("NETSURFRES"); + + if (cdir != NULL) { + if (realpath(cdir, buf) != NULL) { + strcat(buf, "/"); + strcat(buf, filename); + if (access(buf, R_OK) == 0) + return buf; + } + } + + strcpy(t, NETSURF_FB_RESPATH); + strcat(t, filename); + if (realpath(t, buf) != NULL) { + if (access(buf, R_OK) == 0) + return buf; + } + + if (def[0] == '~') { + snprintf(t, PATH_MAX, "%s%s", getenv("HOME"), def + 1); + if (realpath(t, buf) == NULL) { + strcpy(buf, t); + } + } else { + if (realpath(def, buf) == NULL) { + strcpy(buf, def); + } + } + + return buf; } + /* * Local Variables: * c-basic-offset: 8 diff --git a/framebuffer/fb_findfile.h b/framebuffer/fb_findfile.h index c284f89a3..87b9a95e4 100644 --- a/framebuffer/fb_findfile.h +++ b/framebuffer/fb_findfile.h @@ -19,7 +19,8 @@ #ifndef NETSURF_FB_FINDFILE_H #define NETSURF_FB_FINDFILE_H -extern char *fb_findfile(const char *filename); -extern char *fb_findfile_asurl(const char *filename); +char *path_to_url(const char *path); + +extern char *fb_find_resource(char *buf, const char *filename, const char *def); #endif /* NETSURF_FB_FINDFILE_H */ diff --git a/framebuffer/fb_frontend_sdl.c b/framebuffer/fb_frontend_sdl.c index dd30f76ca..74c564a2e 100644 --- a/framebuffer/fb_frontend_sdl.c +++ b/framebuffer/fb_frontend_sdl.c @@ -139,7 +139,7 @@ void fb_os_input(struct gui_window *g, bool active) break; case SDL_MOUSEMOTION: - fb_rootwindow_move_abs(framebuffer, g, event.motion.x, event.motion.y); + fb_rootwindow_move(framebuffer, g, event.motion.x, event.motion.y, false); break; case SDL_MOUSEBUTTONDOWN: diff --git a/framebuffer/fb_gui.c b/framebuffer/fb_gui.c index 786fcae16..bc86ba11b 100644 --- a/framebuffer/fb_gui.c +++ b/framebuffer/fb_gui.c @@ -50,6 +50,7 @@ char *default_stylesheet_url; char *adblock_stylesheet_url; +char *options_file_location; struct gui_window *input_window = NULL; struct gui_window *search_current_window; struct gui_window *window_list = NULL; @@ -166,21 +167,33 @@ static void *myrealloc(void *ptr, size_t len, void *pw) void gui_init(int argc, char** argv) { + char buf[PATH_MAX]; + LOG(("argc %d, argv %p", argc, argv)); #ifdef WITH_HUBBUB - if (hubbub_initialise(fb_findfile("Aliases"), myrealloc, NULL) != + fb_find_resource(buf, "Aliases", "./framebuffer/res/Aliases"); + LOG(("Using '%s' as Aliases file", buf)); + if (hubbub_initialise(buf, myrealloc, NULL) != HUBBUB_OK) die("Unable to initialise HTML parsing library.\n"); #endif /* load browser messages */ - messages_load(fb_findfile("messages")); - + fb_find_resource(buf, "messages", "./framebuffer/res/messages"); + LOG(("Using '%s' as Messages file", buf)); + messages_load(buf); + /* load browser options */ - options_read(fb_findfile("Options")); - - default_stylesheet_url = fb_findfile_asurl("default.css"); + fb_find_resource(buf, "Options", "~/.netsurf/Options"); + LOG(("Using '%s' as Preferences file", buf)); + options_file_location = strdup(buf); + options_read(buf); + + /* set up stylesheet urls */ + fb_find_resource(buf, "default.css", "./framebuffer/res/default.css"); + default_stylesheet_url = path_to_url(buf); + LOG(("Using '%s' as Default CSS URL", default_stylesheet_url)); framebuffer = fb_os_init(argc, argv); diff --git a/framebuffer/fb_rootwindow.c b/framebuffer/fb_rootwindow.c index 723237137..f95053c23 100644 --- a/framebuffer/fb_rootwindow.c +++ b/framebuffer/fb_rootwindow.c @@ -426,11 +426,20 @@ fb_rootwindow_click(struct gui_window *g, browser_mouse_state st, int x, int y) void -fb_rootwindow_move_abs(framebuffer_t *fb, struct gui_window *g, int x, int y) +fb_rootwindow_move(framebuffer_t *fb, + struct gui_window *g, + int x, + int y, + bool relative) { struct fb_widget *widget; - fb_cursor_move_abs(fb, x, y); + if (relative) { + x += fb_cursor_x(fb); + y += fb_cursor_y(fb); + } + + fb_cursor_move(fb, x, y); widget = widget_list; while (widget != NULL) { diff --git a/framebuffer/fb_rootwindow.h b/framebuffer/fb_rootwindow.h index b6f17f0ae..62d9e61f2 100644 --- a/framebuffer/fb_rootwindow.h +++ b/framebuffer/fb_rootwindow.h @@ -24,6 +24,8 @@ typedef int (*fb_widget_mouseclick_t)(struct gui_window *g, browser_mouse_state void fb_rootwindow_click(struct gui_window *g, browser_mouse_state st , int x, int y); void fb_rootwindow_input(struct gui_window *g, int value); +void fb_rootwindow_move(framebuffer_t *fb, struct gui_window *g, int x, int y, bool relative); + void fb_rootwindow_status(const char* text); void fb_rootwindow_url(const char* text); diff --git a/nsfb b/nsfb new file mode 100755 index 000000000..7e2ded095 --- /dev/null +++ b/nsfb @@ -0,0 +1,25 @@ +#!/bin/sh +# This file is part of NetSurf, http://netsurf-browser.org/ +# Licensed under the GNU General Public License, +# http://www.opensource.org/licenses/gpl-license +# Copyright 2007 Rob Kendrick + +if [ -d ~/.netsurf ]; then + LOG=~/.netsurf/log.txt +elif [ -d /tmp ]; then + LOG=/tmp/netsurf-log.txt +else + LOG=netsurf-log.txt +fi + +if [ -x nsfb-sdl ]; then +TYPE=-sdl +elif [ -x nsfb-linux ]; then +TYPE=-linux +elif [ -x nsfb-dummy ]; then +TYPE=-dummy +fi + +NETSURFRES=$(dirname $0)/framebuffer/res/ +export NETSURFRES +exec $(dirname $0)/nsfb${TYPE} "$@" 2>$LOG -- cgit v1.2.3