diff options
author | Robert Manea <gotmor@gmail.com> | 2009-10-02 11:15:13 +0200 |
---|---|---|
committer | Robert Manea <gotmor@gmail.com> | 2009-10-02 11:15:13 +0200 |
commit | 85bd94abb4fb507b5d230a06f5f7c2b4138110ca (patch) | |
tree | 1ac0d1443f3a7f7c0ad3b8a8ba5c2e13ab67befc /uzbl-core.c | |
parent | 93bcfb0d08807a68da314ef844c9cfc9afd07ae9 (diff) |
split source into multiple files
Diffstat (limited to 'uzbl-core.c')
-rw-r--r-- | uzbl-core.c | 176 |
1 files changed, 10 insertions, 166 deletions
diff --git a/uzbl-core.c b/uzbl-core.c index e86da21..71bc474 100644 --- a/uzbl-core.c +++ b/uzbl-core.c @@ -29,36 +29,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -#define LENGTH(x) (sizeof x / sizeof x[0]) -#define _POSIX_SOURCE - -#include <gtk/gtk.h> -#include <gdk/gdkx.h> -#include <gdk/gdkkeysyms.h> -#include <sys/socket.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/un.h> -#include <sys/utsname.h> -#include <sys/time.h> -#include <webkit/webkit.h> -#include <libsoup/soup.h> -#include <JavaScriptCore/JavaScript.h> - -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <stdlib.h> -#include <errno.h> -#include <fcntl.h> -#include <signal.h> -#include <assert.h> -#include <poll.h> -#include <sys/uio.h> -#include <sys/ioctl.h> -#include <assert.h> #include "uzbl-core.h" +#include "uzbl-events.h" #include "config.h" UzblCore uzbl; @@ -84,9 +56,17 @@ GOptionEntry entries[] = { NULL, 0, 0, 0, NULL, NULL, NULL } }; -enum ptr_type {TYPE_INT, TYPE_STR, TYPE_FLOAT}; +XDG_Var XDG[] = +{ + { "XDG_CONFIG_HOME", "~/.config" }, + { "XDG_DATA_HOME", "~/.local/share" }, + { "XDG_CACHE_HOME", "~/.cache" }, + { "XDG_CONFIG_DIRS", "/etc/xdg" }, + { "XDG_DATA_DIRS", "/usr/local/share/:/usr/share/" }, +}; /* associate command names to their properties */ +enum ptr_type {TYPE_INT, TYPE_STR, TYPE_FLOAT}; typedef struct { enum ptr_type type; union { @@ -183,38 +163,6 @@ const struct var_name_to_ptr_t { { NULL, {.ptr.s = NULL, .type = TYPE_INT, .dump = 0, .writeable = 0, .func = NULL}} }; - -/* Event id to name mapping - * Event names must be in the same - * order as in 'enum event_type' - * - * TODO: Add more useful events -*/ -const char *event_table[LAST_EVENT] = { - "LOAD_START" , - "LOAD_COMMIT" , - "LOAD_FINISH" , - "LOAD_ERROR" , - "KEY_PRESS" , - "KEY_RELEASE" , - "DOWNLOAD_REQUEST" , - "COMMAND_EXECUTED" , - "LINK_HOVER" , - "TITLE_CHANGED" , - "GEOMETRY_CHANGED" , - "WEBINSPECTOR" , - "NEW_WINDOW" , - "SELECTION_CHANGED", - "VARIABLE_SET" , - "FIFO_SET" , - "SOCKET_SET" , - "INSTANCE_START" , - "INSTANCE_EXIT" , - "LOAD_PROGRESS" , - "LINK_UNHOVER" -}; - - /* construct a hash from the var_name_to_ptr array for quick access */ void create_var_to_name_hash() { @@ -388,110 +336,6 @@ expand(const char *s, guint recurse) { return g_string_free(buf, FALSE); } -void -event_buffer_timeout(guint sec) { - struct itimerval t; - memset(&t, 0, sizeof t); - t.it_value.tv_sec = sec; - t.it_value.tv_usec = 0; - setitimer(ITIMER_REAL, &t, NULL); -} - - -void -send_event_socket(GString *msg) { - GError *error = NULL; - GString *tmp; - GIOStatus ret; - gsize len; - guint i=0; - - if(uzbl.comm.socket_path && - uzbl.comm.clientchan && - uzbl.comm.clientchan->is_writeable) { - - if(uzbl.state.event_buffer) { - event_buffer_timeout(0); - - while(i < uzbl.state.event_buffer->len) { - tmp = g_ptr_array_index(uzbl.state.event_buffer, i++); - ret = g_io_channel_write_chars (uzbl.comm.clientchan, - tmp->str, tmp->len, - &len, &error); - /* is g_ptr_array_free(uzbl.state.event_buffer, TRUE) enough? */ - //g_string_free(tmp, TRUE); - if (ret == G_IO_STATUS_ERROR) { - g_warning ("Error sending event to socket: %s", error->message); - } - g_io_channel_flush(uzbl.comm.clientchan, &error); - } - g_ptr_array_free(uzbl.state.event_buffer, TRUE); - uzbl.state.event_buffer = NULL; - } - if(msg) { - ret = g_io_channel_write_chars (uzbl.comm.clientchan, - msg->str, msg->len, - &len, &error); - - if (ret == G_IO_STATUS_ERROR) { - g_warning ("Error sending event to socket: %s", error->message); - } - g_io_channel_flush(uzbl.comm.clientchan, &error); - } - } - /* buffer events until a socket is set and connected - * or a timeout is encountered - */ - else { - if(!uzbl.state.event_buffer) - uzbl.state.event_buffer = g_ptr_array_new(); - g_ptr_array_add(uzbl.state.event_buffer, (gpointer)g_string_new(msg->str)); - } -} - -void -send_event_stdout(GString *msg) { - printf("%s", msg->str); - fflush(stdout); -} - -/* - * build event string and send over the supported interfaces - * custom_event == NULL indicates an internal event -*/ -void -send_event(int type, const gchar *details, const gchar *custom_event) { - GString *event_message = g_string_new(""); - gchar *buf, *p_val = NULL; - - /* expand shell vars */ - if(details) { - buf = g_strdup(details); - p_val = parseenv(g_strdup(buf ? g_strchug(buf) : " ")); - g_free(buf); - } - - /* check for custom events */ - if(custom_event) { - g_string_printf(event_message, "EVENT [%s] %s %s\n", - uzbl.state.instance_name, custom_event, p_val); - } - /* check wether we support the internal event */ - else if(type < LAST_EVENT) { - g_string_printf(event_message, "EVENT [%s] %s %s\n", - uzbl.state.instance_name, event_table[type], p_val); - } - - if(event_message->str) { - /* TODO: a means to select the interface to which events are sent */ - send_event_stdout(event_message); - send_event_socket(event_message); - - g_string_free(event_message, TRUE); - } - g_free(p_val); -} - char * itos(int val) { char tmp[20]; |