aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/events.c13
-rw-r--r--src/io.c87
-rw-r--r--src/io.h6
-rw-r--r--src/status-bar.c2
-rw-r--r--src/status-bar.h4
-rw-r--r--src/uzbl-core.c48
-rw-r--r--src/uzbl-core.h4
-rw-r--r--src/variables.c10
8 files changed, 80 insertions, 94 deletions
diff --git a/src/events.c b/src/events.c
index 198839b..081a942 100644
--- a/src/events.c
+++ b/src/events.c
@@ -312,6 +312,19 @@ get_modifier_mask(guint state) {
return g_string_free(modifiers, FALSE);
}
+/* backwards compatibility. */
+#if ! GTK_CHECK_VERSION (2, 22, 0)
+#define GDK_KEY_Shift_L GDK_Shift_L
+#define GDK_KEY_Shift_R GDK_Shift_R
+#define GDK_KEY_Control_L GDK_Control_L
+#define GDK_KEY_Control_R GDK_Control_R
+#define GDK_KEY_Alt_L GDK_Alt_L
+#define GDK_KEY_Alt_R GDK_Alt_R
+#define GDK_KEY_Super_L GDK_Super_L
+#define GDK_KEY_Super_R GDK_Super_R
+#define GDK_KEY_ISO_Level3_Shift GDK_ISO_Level3_Shift
+#endif
+
guint key_to_modifier(guint keyval) {
/* FIXME
* Should really use XGetModifierMapping and/or Xkb to get actual mod keys
diff --git a/src/io.c b/src/io.c
index 062a853..5600c79 100644
--- a/src/io.c
+++ b/src/io.c
@@ -26,8 +26,6 @@ build_stream_name(int type, const gchar* dir) {
gboolean
control_fifo(GIOChannel *gio, GIOCondition condition) {
- if (uzbl.state.verbose)
- printf("triggered\n");
gchar *ctl_line;
GIOStatus ret;
GError *err = NULL;
@@ -36,7 +34,7 @@ control_fifo(GIOChannel *gio, GIOCondition condition) {
g_error ("Fifo: Read end of pipe died!\n");
if(!gio)
- g_error ("Fifo: GIOChannel broke\n");
+ g_error ("Fifo: GIOChannel broke\n");
ret = g_io_channel_read_line(gio, &ctl_line, NULL, NULL, &err);
if (ret == G_IO_STATUS_ERROR) {
@@ -74,9 +72,10 @@ attach_fifo(gchar *path) {
}
-/*@null@*/ gchar*
-init_fifo(gchar *dir) { /* return dir or, on error, free dir and return NULL */
- if (uzbl.comm.fifo_path) { /* get rid of the old fifo if one exists */
+gboolean
+init_fifo(const gchar *dir) {
+ if (uzbl.comm.fifo_path) {
+ /* we're changing the fifo path, get rid of the old fifo if one exists */
if (unlink(uzbl.comm.fifo_path) == -1)
g_warning ("Fifo: Can't unlink old fifo at %s\n", uzbl.comm.fifo_path);
g_free(uzbl.comm.fifo_path);
@@ -85,32 +84,20 @@ init_fifo(gchar *dir) { /* return dir or, on error, free dir and return NULL */
gchar *path = build_stream_name(FIFO, dir);
- if (!file_exists(path)) {
- if (mkfifo (path, 0666) == 0 && attach_fifo(path)) {
- return dir;
- } else g_warning ("init_fifo: can't create %s: %s\n", path, strerror(errno));
- } else {
- /* the fifo exists. but is anybody home? */
- int fd = open(path, O_WRONLY|O_NONBLOCK);
- if(fd < 0) {
- /* some error occurred, presumably nobody's on the read end.
- * we can attach ourselves to it. */
- if(attach_fifo(path))
- return dir;
- else
- g_warning("init_fifo: can't attach to %s: %s\n", path, strerror(errno));
- } else {
- /* somebody's there, we can't use that fifo. */
- close(fd);
- /* whatever, this instance can live without a fifo. */
- g_warning ("init_fifo: can't create %s: file exists and is occupied\n", path);
- }
- }
+ /* if something exists at that path, try to delete it. */
+ if (file_exists(path) && unlink(path) == -1)
+ g_warning ("Fifo: Can't unlink old fifo at %s\n", path);
- /* if we got this far, there was an error; cleanup */
- g_free(dir);
+ if (mkfifo (path, 0666) == 0) {
+ if(attach_fifo(path))
+ return TRUE;
+ else
+ g_warning("init_fifo: can't attach to %s: %s\n", path, strerror(errno));
+ } else g_warning ("init_fifo: can't create %s: %s\n", path, strerror(errno));
+
+ /* if we got this far, there was an error; clean up */
g_free(path);
- return NULL;
+ return FALSE;
}
@@ -298,8 +285,8 @@ attach_socket(gchar *path, struct sockaddr_un *local) {
}
-/*@null@*/ gchar*
-init_socket(gchar *dir) { /* return dir or, on error, free dir and return NULL */
+gboolean
+init_socket(const gchar *dir) {
if (uzbl.comm.socket_path) { /* remove an existing socket should one exist */
if (unlink(uzbl.comm.socket_path) == -1)
g_warning ("init_socket: couldn't unlink socket at %s\n", uzbl.comm.socket_path);
@@ -308,40 +295,24 @@ init_socket(gchar *dir) { /* return dir or, on error, free dir and return NULL *
}
if (*dir == ' ') {
- g_free(dir);
- return NULL;
+ return FALSE;
}
- struct sockaddr_un local;
gchar *path = build_stream_name(SOCKET, dir);
+ /* if something exists at that path, try to delete it. */
+ if(file_exists(path) && unlink(path) == -1)
+ g_warning ("Fifo: Can't unlink old fifo at %s\n", path);
+
+ struct sockaddr_un local;
local.sun_family = AF_UNIX;
strcpy (local.sun_path, path);
- if(!file_exists(path) && attach_socket(path, &local)) {
- /* it's free for the taking. */
- return dir;
- } else {
- /* see if anybody's listening on the socket path we want. */
- int sock = socket (AF_UNIX, SOCK_STREAM, 0);
- if(connect(sock, (struct sockaddr *) &local, sizeof(local)) < 0) {
- /* some error occurred, presumably nobody's listening.
- * we can attach ourselves to it. */
- unlink(path);
- if(attach_socket(path, &local))
- return dir;
- else
- g_warning("init_socket: can't attach to existing socket %s: %s\n", path, strerror(errno));
- } else {
- /* somebody's there, we can't use that socket path. */
- close(sock);
- /* whatever, this instance can live without a socket. */
- g_warning ("init_socket: can't create %s: socket exists and is occupied\n", path);
- }
- }
+ if(attach_socket(path, &local)) {
+ return TRUE;
+ } else g_warning("init_socket: can't attach to %s: %s\n", path, strerror(errno));
/* if we got this far, there was an error; cleanup */
g_free(path);
- g_free(dir);
- return NULL;
+ return FALSE;
}
diff --git a/src/io.h b/src/io.h
index a6ea0a1..82b31e6 100644
--- a/src/io.h
+++ b/src/io.h
@@ -8,14 +8,12 @@ build_stream_name(int type, const gchar *dir);
gboolean control_fifo(GIOChannel *gio, GIOCondition condition);
-/*@null@*/ gchar*
-init_fifo(gchar *dir);
+gboolean init_fifo(const gchar *dir);
gboolean control_stdin(GIOChannel *gio, GIOCondition condition);
void create_stdin();
-/*@null@*/ gchar*
-init_socket(gchar *dir);
+gboolean init_socket(const gchar *dir);
gboolean control_socket(GIOChannel *chan);
gboolean control_client_socket(GIOChannel *chan);
diff --git a/src/status-bar.c b/src/status-bar.c
index 6d4541b..d80dd51 100644
--- a/src/status-bar.c
+++ b/src/status-bar.c
@@ -1,6 +1,6 @@
#include "status-bar.h"
-G_DEFINE_TYPE (UzblStatusBar, uzbl_status_bar, GTK_TYPE_HBOX)
+G_DEFINE_TYPE (UzblStatusBar, uzbl_status_bar, GTK_TYPE_BOX)
static void uzbl_status_bar_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
diff --git a/src/status-bar.h b/src/status-bar.h
index e972701..cae8905 100644
--- a/src/status-bar.h
+++ b/src/status-bar.h
@@ -14,14 +14,14 @@ typedef struct _UzblStatusBar UzblStatusBar;
typedef struct _UzblStatusBarClass UzblStatusBarClass;
struct _UzblStatusBar {
- GtkHBox hbox;
+ GtkBox box;
GtkWidget *left_label;
GtkWidget *right_label;
};
struct _UzblStatusBarClass {
- GtkHBoxClass parent_class;
+ GtkBoxClass parent_class;
};
GType uzbl_status_bar_get_type (void) G_GNUC_CONST;
diff --git a/src/uzbl-core.c b/src/uzbl-core.c
index b37582e..b233f8b 100644
--- a/src/uzbl-core.c
+++ b/src/uzbl-core.c
@@ -246,7 +246,7 @@ expand(const char* s, guint recurse) {
void
clean_up(void) {
if (uzbl.info.pid_str) {
- send_event (INSTANCE_EXIT, NULL, TYPE_INT, getpid(), NULL);
+ send_event (INSTANCE_EXIT, NULL, TYPE_INT, uzbl.info.pid, NULL);
g_free(uzbl.info.pid_str);
uzbl.info.pid_str = NULL;
}
@@ -1025,7 +1025,13 @@ initialize(int argc, char** argv) {
create_scrolled_win();
/* pack the window and the status bar */
+
+#if GTK_CHECK_VERSION(3,0,0)
+ uzbl.gui.vbox = gtk_box_new(FALSE, 0);
+ gtk_orientable_set_orientation(GTK_ORIENTABLE(uzbl.gui.vbox), GTK_ORIENTATION_VERTICAL);
+#else
uzbl.gui.vbox = gtk_vbox_new(FALSE, 0);
+#endif
gtk_box_pack_start(GTK_BOX(uzbl.gui.vbox), uzbl.gui.scrolled_win, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(uzbl.gui.vbox), uzbl.gui.status_bar, FALSE, TRUE, 0);
@@ -1036,30 +1042,26 @@ initialize(int argc, char** argv) {
/** -- MAIN -- **/
int
main (int argc, char* argv[]) {
+ Window xwin;
+
initialize(argc, argv);
- /* Embedded mode */
if (uzbl.state.plug_mode) {
+ /* Embedded mode */
uzbl.gui.plug = create_plug();
gtk_container_add (GTK_CONTAINER (uzbl.gui.plug), uzbl.gui.vbox);
- /* in xembed mode the window has no unique id and thus
- * socket/fifo names aren't unique either.
- * we use a custom randomizer to create a random id
- */
- struct timeval tv;
- gettimeofday(&tv, NULL);
- srand((unsigned int)tv.tv_sec*tv.tv_usec);
- uzbl.xwin = rand();
- }
-
- /* Windowed mode */
- else {
+ } else {
+ /* Windowed mode */
uzbl.gui.main_window = create_window();
gtk_container_add (GTK_CONTAINER (uzbl.gui.main_window), uzbl.gui.vbox);
+
/* We need to ensure there is a window, before we can get XID */
gtk_widget_realize (GTK_WIDGET (uzbl.gui.main_window));
+ xwin = GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (uzbl.gui.main_window)));
- uzbl.xwin = GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (uzbl.gui.main_window)));
+ gchar *xwin_str = g_strdup_printf("%d", (int)xwin);
+ g_setenv("UZBL_XID", xwin_str, TRUE);
+ g_free(xwin_str);
gtk_widget_grab_focus (GTK_WIDGET (uzbl.gui.web_view));
}
@@ -1078,17 +1080,14 @@ main (int argc, char* argv[]) {
"signal::changed", (GCallback)scroll_horiz_cb, NULL,
NULL);
- gchar *xwin = g_strdup_printf("%d", (int)uzbl.xwin);
- g_setenv("UZBL_XID", xwin, TRUE);
+ uzbl.info.pid = getpid();
+ uzbl.info.pid_str = g_strdup_printf("%d", uzbl.info.pid);
+ g_setenv("UZBL_PID", uzbl.info.pid_str, TRUE);
if(!uzbl.state.instance_name)
- uzbl.state.instance_name = g_strdup(xwin);
+ uzbl.state.instance_name = uzbl.info.pid_str;
- g_free(xwin);
-
- uzbl.info.pid_str = g_strdup_printf("%d", getpid());
- g_setenv("UZBL_PID", uzbl.info.pid_str, TRUE);
- send_event(INSTANCE_START, NULL, TYPE_INT, getpid(), NULL);
+ send_event(INSTANCE_START, NULL, TYPE_INT, uzbl.info.pid, NULL);
if (uzbl.state.plug_mode) {
send_event(PLUG_CREATED, NULL, TYPE_INT, gtk_plug_get_id (uzbl.gui.plug), NULL);
@@ -1145,13 +1144,12 @@ main (int argc, char* argv[]) {
if (uzbl.state.socket_id)
printf("plug_id %i\n", (int)gtk_plug_get_id(uzbl.gui.plug));
else
- printf("window_id %i\n",(int) uzbl.xwin);
+ printf("window_id %i\n",(int) xwin);
printf("pid %i\n", getpid ());
printf("name: %s\n", uzbl.state.instance_name);
printf("commit: %s\n", uzbl.info.commit);
}
-
gtk_main();
/* Cleanup and exit*/
diff --git a/src/uzbl-core.h b/src/uzbl-core.h
index 9aba992..b5afa3a 100644
--- a/src/uzbl-core.h
+++ b/src/uzbl-core.h
@@ -207,6 +207,8 @@ typedef struct {
int webkit_micro;
gchar* arch;
gchar* commit;
+
+ pid_t pid;
gchar* pid_str;
} Info;
@@ -219,8 +221,6 @@ typedef struct {
Behaviour behave;
Communication comm;
Info info;
-
- Window xwin;
} UzblCore;
extern UzblCore uzbl; /* Main Uzbl object */
diff --git a/src/variables.c b/src/variables.c
index a1063a0..5d770e6 100644
--- a/src/variables.c
+++ b/src/variables.c
@@ -465,12 +465,18 @@ set_current_encoding() {
void
cmd_fifo_dir() {
- uzbl.behave.fifo_dir = init_fifo(uzbl.behave.fifo_dir);
+ if(!init_fifo(uzbl.behave.fifo_dir)) {
+ g_free(uzbl.behave.fifo_dir);
+ uzbl.behave.fifo_dir = NULL;
+ }
}
void
cmd_socket_dir() {
- uzbl.behave.socket_dir = init_socket(uzbl.behave.socket_dir);
+ if(!init_socket(uzbl.behave.socket_dir)) {
+ g_free(uzbl.behave.socket_dir);
+ uzbl.behave.socket_dir = NULL;
+ }
}
void