summaryrefslogtreecommitdiff
path: root/framebuffer
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2009-02-14 12:49:21 +0000
committerVincent Sanders <vince@netsurf-browser.org>2009-02-14 12:49:21 +0000
commitd6cd92e0ccb2f78ec197e02ba714344951075a41 (patch)
tree1ee9363a747a65188c0f38831bf7d05eaab94748 /framebuffer
parentf90e43e2b05fef6bca65d086a78cec4cee3c0dec (diff)
downloadnetsurf-d6cd92e0ccb2f78ec197e02ba714344951075a41.tar.gz
netsurf-d6cd92e0ccb2f78ec197e02ba714344951075a41.tar.bz2
Fix resource handling buy copying the GTK approach
Cleanup mouse movement handlig svn path=/trunk/netsurf/; revision=6486
Diffstat (limited to 'framebuffer')
-rw-r--r--framebuffer/fb_cursor.c10
-rw-r--r--framebuffer/fb_cursor.h2
-rw-r--r--framebuffer/fb_findfile.c116
-rw-r--r--framebuffer/fb_findfile.h5
-rw-r--r--framebuffer/fb_frontend_sdl.c2
-rw-r--r--framebuffer/fb_gui.c25
-rw-r--r--framebuffer/fb_rootwindow.c13
-rw-r--r--framebuffer/fb_rootwindow.h2
8 files changed, 104 insertions, 71 deletions
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 <stdlib.h>
#include <string.h>
+#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);