summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin@src.gnome.org>2002-12-10 22:36:29 +0000
committerNalin Dahyabhai <nalin@src.gnome.org>2002-12-10 22:36:29 +0000
commit18d3d0fbdb83a33107b92d77963a9e99e652e9df (patch)
tree27b16e15126452b7700a1f1c9dbb9779591dd371 /src
parentdd56e470ff18ce4e5c1d924c13b334a147465304 (diff)
centralize buffer length sanity checks, add some utility functions forvte_0_10_6
* src/buffer.c, src/buffer.h: centralize buffer length sanity checks, add some utility functions for stuffing things into buffers and pulling them back out. * src/debug.c, src/debug.h: add a lifecycle debug class, for tracking down initialization order weirdness. * src/pty.c: try to check that we can run the pty helper before trying to run it, to avoid SIGPIPE failures when it's not installed. * src/vte.c: never grab focus -- let the shell app deal with it. Return TRUE from mouse motion and press/release events to keep them from being passed up.
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c146
-rw-r--r--src/buffer.h25
-rw-r--r--src/debug.c3
-rw-r--r--src/debug.h7
-rw-r--r--src/iso2022.h2
-rw-r--r--src/pty.c4
-rw-r--r--src/reaper.h1
-rw-r--r--src/vte.c109
8 files changed, 258 insertions, 39 deletions
diff --git a/src/buffer.c b/src/buffer.c
index f3628f2..82fbe75 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -34,6 +34,14 @@ struct _vte_real_buffer {
size_t buf_used, buf_length;
};
+static void
+_vte_buffer_check(struct _vte_buffer *buffer, size_t length)
+{
+ struct _vte_real_buffer *buf = (struct _vte_real_buffer*) buffer;
+ g_assert(buf->buf_length >= length);
+ g_assert(buf->buf_length >= buf->buf_used);
+}
+
static size_t
_vte_buffer_calc_new_size(size_t minimum_length)
{
@@ -50,13 +58,22 @@ _vte_buffer_new(void)
return (struct _vte_buffer*) buf;
}
+struct _vte_buffer*
+_vte_buffer_new_with_data(gconstpointer data, size_t length)
+{
+ struct _vte_buffer *buf;
+ buf = _vte_buffer_new();
+ _vte_buffer_append(buf, data, length);
+ return buf;
+}
+
void
_vte_buffer_set_minimum_size(struct _vte_buffer *buffer, size_t length)
{
struct _vte_real_buffer *buf = (struct _vte_real_buffer*) buffer;
size_t size;
unsigned char *tmp;
- g_assert(buf->buf_length >= buf->buf_used);
+ _vte_buffer_check(buffer, 0);
if (length > buf->buf_length) {
size = _vte_buffer_calc_new_size(length);
tmp = g_malloc(size);
@@ -76,12 +93,12 @@ _vte_buffer_set_minimum_size(struct _vte_buffer *buffer, size_t length)
void
_vte_buffer_prepend(struct _vte_buffer *buffer,
- const unsigned char *bytes, size_t length)
+ gconstpointer bytes, size_t length)
{
struct _vte_real_buffer *buf = (struct _vte_real_buffer*) buffer;
size_t size;
unsigned char *tmp;
- g_assert(buf->buf_length >= buf->buf_used);
+ _vte_buffer_check(buffer, 0);
if (length > 0) {
if (buf->buf_used + length > buf->buf_length) {
size = _vte_buffer_calc_new_size(buf->buf_used +
@@ -104,12 +121,12 @@ _vte_buffer_prepend(struct _vte_buffer *buffer,
void
_vte_buffer_append(struct _vte_buffer *buffer,
- const unsigned char *bytes, size_t length)
+ gconstpointer bytes, size_t length)
{
struct _vte_real_buffer *buf = (struct _vte_real_buffer*) buffer;
size_t size;
unsigned char *tmp;
- g_assert(buf->buf_length >= buf->buf_used);
+ _vte_buffer_check(buffer, 0);
if (length > 0) {
if (buf->buf_used + length > buf->buf_length) {
size = _vte_buffer_calc_new_size(buf->buf_used +
@@ -133,8 +150,7 @@ void
_vte_buffer_consume(struct _vte_buffer *buffer, size_t length)
{
struct _vte_real_buffer *buf = (struct _vte_real_buffer*) buffer;
- g_assert(buf->buf_length >= buf->buf_used);
- g_assert(length <= buf->buf_used);
+ _vte_buffer_check(buffer, length);
if (length == buf->buf_used) {
buf->buf_used = 0;
} else
@@ -149,7 +165,7 @@ void
_vte_buffer_clear(struct _vte_buffer *buffer)
{
struct _vte_real_buffer *buf = (struct _vte_real_buffer*) buffer;
- g_assert(buf->buf_length >= buf->buf_used);
+ _vte_buffer_check(buffer, 0);
buf->buf_used = 0;
}
@@ -157,7 +173,7 @@ void
_vte_buffer_free(struct _vte_buffer *buffer)
{
struct _vte_real_buffer *buf = (struct _vte_real_buffer*) buffer;
- g_assert(buf->buf_length >= buf->buf_used);
+ _vte_buffer_check(buffer, 0);
g_free(buf->bytes);
g_free(buf);
}
@@ -166,6 +182,116 @@ size_t
_vte_buffer_length(struct _vte_buffer *buffer)
{
struct _vte_real_buffer *buf = (struct _vte_real_buffer*) buffer;
- g_assert(buf->buf_length >= buf->buf_used);
+ _vte_buffer_check(buffer, 0);
return buf->buf_used;
}
+
+void
+_vte_buffer_append_guint16(struct _vte_buffer *buffer, guint16 i)
+{
+ guint16 j;
+ j = g_htons(i);
+ _vte_buffer_append(buffer, (gpointer) &j, sizeof(j));
+}
+
+guint16
+_vte_buffer_peek_guint16(struct _vte_buffer *buffer)
+{
+ guint16 i;
+ _vte_buffer_check(buffer, sizeof(i));
+ memcpy(&i, buffer->bytes, sizeof(i));
+ return g_ntohs(i);
+}
+
+guint16
+_vte_buffer_read_guint16(struct _vte_buffer *buffer)
+{
+ guint16 ret;
+ ret = _vte_buffer_peek_guint16(buffer);
+ _vte_buffer_consume(buffer, sizeof(ret));
+ return ret;
+}
+
+void
+_vte_buffer_append_guint32(struct _vte_buffer *buffer, guint32 i)
+{
+ guint32 j;
+ j = g_htonl(i);
+ _vte_buffer_append(buffer, (gpointer) &j, sizeof(j));
+}
+
+guint32
+_vte_buffer_peek_guint32(struct _vte_buffer *buffer)
+{
+ guint32 i;
+ _vte_buffer_check(buffer, sizeof(i));
+ memcpy(&i, buffer->bytes, sizeof(i));
+ return g_ntohl(i);
+}
+
+guint32
+_vte_buffer_read_guint32(struct _vte_buffer *buffer)
+{
+ guint32 ret;
+ ret = _vte_buffer_peek_guint32(buffer);
+ _vte_buffer_consume(buffer, sizeof(ret));
+ return ret;
+}
+
+void
+_vte_buffer_append_gstring(struct _vte_buffer *buffer, const GString *s)
+{
+ _vte_buffer_append_guint32(buffer, s->len);
+ _vte_buffer_append(buffer, s->str, s->len);
+}
+
+GString *
+_vte_buffer_peek_gstring(struct _vte_buffer *buffer)
+{
+ GString *ret;
+ guint32 i;
+ i = _vte_buffer_peek_guint32(buffer);
+ _vte_buffer_check(buffer, sizeof(i) + i);
+ ret = g_string_new_len(buffer->bytes + sizeof(i), i);
+ return ret;
+}
+
+GString *
+_vte_buffer_read_gstring(struct _vte_buffer *buffer)
+{
+ GString *ret;
+ ret = _vte_buffer_peek_gstring(buffer);
+ _vte_buffer_consume(buffer, sizeof(guint32) + ret->len);
+ return ret;
+}
+
+void
+_vte_buffer_append_buffer(struct _vte_buffer *buffer, struct _vte_buffer *s)
+{
+ struct _vte_real_buffer *buf = (struct _vte_real_buffer*) s;
+ _vte_buffer_append_guint32(buffer, buf->buf_used);
+ _vte_buffer_append(buffer, buf->bytes, buf->buf_used);
+}
+
+struct _vte_buffer *
+_vte_buffer_peek_buffer(struct _vte_buffer *buffer)
+{
+ struct _vte_buffer *ret;
+ guint32 i;
+ i = _vte_buffer_peek_guint32(buffer);
+ _vte_buffer_check(buffer, sizeof(i) + i);
+ ret = _vte_buffer_new_with_data(buffer->bytes + sizeof(i), i);
+ return ret;
+}
+
+struct _vte_buffer *
+_vte_buffer_read_buffer(struct _vte_buffer *buffer)
+{
+ struct _vte_buffer *ret;
+ guint32 i;
+ i = _vte_buffer_read_guint32(buffer);
+ _vte_buffer_check(buffer, i);
+ ret = _vte_buffer_new_with_data(buffer->bytes, i);
+ _vte_buffer_consume(buffer, i);
+ return ret;
+}
diff --git a/src/buffer.h b/src/buffer.h
index 3252650..592934e 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -23,6 +23,8 @@
#ifndef vte_buffer_h_included
#define vte_buffer_h_included
+#ident "$Id$"
+
#include <sys/types.h>
G_BEGIN_DECLS
@@ -34,16 +36,35 @@ struct _vte_buffer {
};
struct _vte_buffer* _vte_buffer_new(void);
+struct _vte_buffer* _vte_buffer_new_with_data(gconstpointer data,
+ size_t length);
void _vte_buffer_free(struct _vte_buffer *buffer);
void _vte_buffer_prepend(struct _vte_buffer *buffer,
- const unsigned char *bytes, size_t length);
+ gconstpointer bytes, size_t length);
void _vte_buffer_append(struct _vte_buffer *buffer,
- const unsigned char *bytes, size_t length);
+ gconstpointer bytes, size_t length);
size_t _vte_buffer_length(struct _vte_buffer *buffer);
void _vte_buffer_consume(struct _vte_buffer *buffer, size_t length);
void _vte_buffer_clear(struct _vte_buffer *buffer);
void _vte_buffer_set_minimum_size(struct _vte_buffer *buffer, size_t length);
+void _vte_buffer_append_guint16(struct _vte_buffer *buffer, guint16 i);
+guint16 _vte_buffer_peek_guint16(struct _vte_buffer *buffer);
+guint16 _vte_buffer_read_guint16(struct _vte_buffer *buffer);
+
+void _vte_buffer_append_guint32(struct _vte_buffer *buffer, guint32 i);
+guint32 _vte_buffer_peek_guint32(struct _vte_buffer *buffer);
+guint32 _vte_buffer_read_guint32(struct _vte_buffer *buffer);
+
+void _vte_buffer_append_gstring(struct _vte_buffer *buffer, const GString *s);
+GString *_vte_buffer_peek_gstring(struct _vte_buffer *buffer);
+GString * _vte_buffer_read_gstring(struct _vte_buffer *buffer);
+
+void _vte_buffer_append_buffer(struct _vte_buffer *buffer,
+ struct _vte_buffer *s);
+struct _vte_buffer *_vte_buffer_peek_buffer(struct _vte_buffer *buffer);
+struct _vte_buffer *_vte_buffer_read_buffer(struct _vte_buffer *buffer);
+
G_END_DECLS
#endif
diff --git a/src/debug.c b/src/debug.c
index 3d40e0f..bd8d42d 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -70,6 +70,9 @@ _vte_debug_parse_string(const char *string)
} else
if (g_ascii_strcasecmp(flags[i], "KEYBOARD") == 0) {
_vte_debug_flags |= VTE_DEBUG_KEYBOARD;
+ } else
+ if (g_ascii_strcasecmp(flags[i], "LIFECYCLE") == 0) {
+ _vte_debug_flags |= VTE_DEBUG_LIFECYCLE;
}
}
g_strfreev(flags);
diff --git a/src/debug.h b/src/debug.h
index 033e65b..d311f3e 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -18,11 +18,11 @@
/* The interfaces in this file are subject to change at any time. */
-#ident "$Id$"
-
#ifndef vte_debug_h_included
#define vte_debug_h_included
+#ident "$Id$"
+
G_BEGIN_DECLS
typedef enum {
@@ -37,7 +37,8 @@ typedef enum {
VTE_DEBUG_RING = 1 << 8,
VTE_DEBUG_PTY = 1 << 9,
VTE_DEBUG_CURSOR = 1 << 10,
- VTE_DEBUG_KEYBOARD = 1 << 11
+ VTE_DEBUG_KEYBOARD = 1 << 11,
+ VTE_DEBUG_LIFECYCLE = 1 << 12
} VteDebugFlags;
void _vte_debug_parse_string(const char *string);
diff --git a/src/iso2022.h b/src/iso2022.h
index 012201a..19a634d 100644
--- a/src/iso2022.h
+++ b/src/iso2022.h
@@ -21,7 +21,7 @@
#ifndef vte_iso2022_h_included
#define vte_iso2022_h_included
-#ident "$Id"
+#ident "$Id$"
#include <glib.h>
#include <glib-object.h>
diff --git a/src/pty.c b/src/pty.c
index 6bb93a4..cfd19aa 100644
--- a/src/pty.c
+++ b/src/pty.c
@@ -787,6 +787,10 @@ static gboolean
_vte_pty_start_helper(void)
{
int i, tmp[2], tunnel;
+ /* Sanity check. */
+ if (access(LIBEXECDIR "/gnome-pty-helper", X_OK) != 0) {
+ return FALSE;
+ }
/* Create a communication link for use with the helper. */
tmp[0] = open("/dev/null", O_RDONLY);
if (tmp[0] == -1) {
diff --git a/src/reaper.h b/src/reaper.h
index 231c4ed..fb8521f 100644
--- a/src/reaper.h
+++ b/src/reaper.h
@@ -20,6 +20,7 @@
#define vte_reaper_h_included
#ident "$Id$"
+
#include <sys/wait.h>
#include <signal.h>
#include <glib.h>
diff --git a/src/vte.c b/src/vte.c
index 38a82fc..6cf5608 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -5732,6 +5732,12 @@ static struct {
GtkWidget *
vte_terminal_new(void)
{
+#ifdef VTE_DEBUG
+ if (_vte_debug_on(VTE_DEBUG_LIFECYCLE)) {
+ fprintf(stderr, "vte_terminal_new()\n");
+ }
+#endif
+
return GTK_WIDGET(g_object_new(vte_terminal_get_type(), NULL));
}
@@ -9155,11 +9161,6 @@ vte_terminal_motion_notify(GtkWidget *widget, GdkEventMotion *event)
/* Show the cursor. */
vte_terminal_set_pointer_visible(terminal, TRUE);
- /* Grab input focus. */
- if (!GTK_WIDGET_HAS_FOCUS(widget)) {
- gtk_widget_grab_focus(widget);
- }
-
/* Read the modifiers. */
if (gdk_event_get_state((GdkEvent*)event, &modifiers) == FALSE) {
modifiers = 0;
@@ -9226,7 +9227,7 @@ vte_terminal_motion_notify(GtkWidget *widget, GdkEventMotion *event)
terminal->pvt->mouse_last_x = event->x - VTE_PAD_WIDTH;
terminal->pvt->mouse_last_y = event->y - VTE_PAD_WIDTH;
- return FALSE;
+ return TRUE;
}
/* Read and handle a pointing device buttonpress event. */
@@ -9247,11 +9248,6 @@ vte_terminal_button_press(GtkWidget *widget, GdkEventButton *event)
delta = terminal->pvt->screen->scroll_delta;
vte_terminal_set_pointer_visible(terminal, TRUE);
- /* Grab input focus. */
- if (!GTK_WIDGET_HAS_FOCUS(widget)) {
- gtk_widget_grab_focus(widget);
- }
-
/* Read the modifiers. */
if (gdk_event_get_state((GdkEvent*)event, &modifiers) == FALSE) {
modifiers = 0;
@@ -9410,7 +9406,7 @@ vte_terminal_button_press(GtkWidget *widget, GdkEventButton *event)
terminal->pvt->mouse_last_x = event->x - VTE_PAD_WIDTH;
terminal->pvt->mouse_last_y = event->y - VTE_PAD_WIDTH;
- return FALSE;
+ return TRUE;
}
/* Read and handle a pointing device buttonrelease event. */
@@ -9425,11 +9421,6 @@ vte_terminal_button_release(GtkWidget *widget, GdkEventButton *event)
terminal = VTE_TERMINAL(widget);
vte_terminal_set_pointer_visible(terminal, TRUE);
- /* Grab input focus. */
- if (!GTK_WIDGET_HAS_FOCUS(widget)) {
- gtk_widget_grab_focus(widget);
- }
-
/* Disconnect from autoscroll requests. */
vte_terminal_stop_autoscroll(terminal);
@@ -9489,7 +9480,7 @@ vte_terminal_button_release(GtkWidget *widget, GdkEventButton *event)
terminal->pvt->mouse_last_x = event->x - VTE_PAD_WIDTH;
terminal->pvt->mouse_last_y = event->y - VTE_PAD_WIDTH;
- return FALSE;
+ return TRUE;
}
/* Handle receiving or losing focus. */
@@ -10904,6 +10895,12 @@ vte_terminal_init(VteTerminal *terminal, gpointer *klass)
struct timeval tv;
enum VteRenderMethod render_max;
+#ifdef VTE_DEBUG
+ if (_vte_debug_on(VTE_DEBUG_LIFECYCLE)) {
+ fprintf(stderr, "vte_terminal_init()\n");
+ }
+#endif
+
g_return_if_fail(VTE_IS_TERMINAL(terminal));
widget = GTK_WIDGET(terminal);
GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_FOCUS);
@@ -11217,6 +11214,12 @@ vte_terminal_size_request(GtkWidget *widget, GtkRequisition *requisition)
{
VteTerminal *terminal;
+#ifdef VTE_DEBUG
+ if (_vte_debug_on(VTE_DEBUG_LIFECYCLE)) {
+ fprintf(stderr, "vte_terminal_size_request()\n");
+ }
+#endif
+
g_return_if_fail(widget != NULL);
g_return_if_fail(VTE_IS_TERMINAL(widget));
terminal = VTE_TERMINAL(widget);
@@ -11252,6 +11255,12 @@ vte_terminal_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
VteTerminal *terminal;
glong width, height;
+#ifdef VTE_DEBUG
+ if (_vte_debug_on(VTE_DEBUG_LIFECYCLE)) {
+ fprintf(stderr, "vte_terminal_size_allocate()\n");
+ }
+#endif
+
g_return_if_fail(widget != NULL);
g_return_if_fail(VTE_IS_TERMINAL(widget));
@@ -11311,6 +11320,29 @@ vte_terminal_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
vte_invalidate_all(terminal);
}
+/* Show the window. */
+static void
+vte_terminal_show(GtkWidget *widget)
+{
+ GtkWidgetClass *widget_class;
+ VteTerminal *terminal;
+
+#ifdef VTE_DEBUG
+ if (_vte_debug_on(VTE_DEBUG_LIFECYCLE)) {
+ fprintf(stderr, "vte_terminal_show()\n");
+ }
+#endif
+
+ g_return_if_fail(widget != NULL);
+ g_return_if_fail(VTE_IS_TERMINAL(widget));
+ terminal = VTE_TERMINAL(widget);
+
+ widget_class = g_type_class_peek(GTK_TYPE_WIDGET);
+ if (GTK_WIDGET_CLASS(widget_class)->show) {
+ (GTK_WIDGET_CLASS(widget_class))->show(widget);
+ }
+}
+
/* The window is being destroyed. */
static void
vte_terminal_unrealize(GtkWidget *widget)
@@ -11323,6 +11355,12 @@ vte_terminal_unrealize(GtkWidget *widget)
Visual *visual;
int i;
+#ifdef VTE_DEBUG
+ if (_vte_debug_on(VTE_DEBUG_LIFECYCLE)) {
+ fprintf(stderr, "vte_terminal_unrealize()\n");
+ }
+#endif
+
g_return_if_fail(widget != NULL);
g_return_if_fail(VTE_IS_TERMINAL(widget));
terminal = VTE_TERMINAL(widget);
@@ -11428,6 +11466,12 @@ vte_terminal_finalize(GObject *object)
struct vte_match_regex *regex;
int i;
+#ifdef VTE_DEBUG
+ if (_vte_debug_on(VTE_DEBUG_LIFECYCLE)) {
+ fprintf(stderr, "vte_terminal_finalize()\n");
+ }
+#endif
+
g_return_if_fail(VTE_IS_TERMINAL(object));
terminal = VTE_TERMINAL(object);
object_class = G_OBJECT_GET_CLASS(G_OBJECT(object));
@@ -11679,6 +11723,12 @@ vte_terminal_realize(GtkWidget *widget)
GdkColor black = {0,0,0}, color;
int attributes_mask = 0, i;
+#ifdef VTE_DEBUG
+ if (_vte_debug_on(VTE_DEBUG_LIFECYCLE)) {
+ fprintf(stderr, "vte_terminal_realize()\n");
+ }
+#endif
+
g_return_if_fail(widget != NULL);
g_return_if_fail(VTE_IS_TERMINAL(widget));
terminal = VTE_TERMINAL(widget);
@@ -11788,11 +11838,6 @@ vte_terminal_realize(GtkWidget *widget)
&black, &black, 0, 0);
g_object_unref(G_OBJECT(pixmap));
g_object_unref(G_OBJECT(mask));
-
- /* Grab input focus. */
- if (!GTK_WIDGET_HAS_FOCUS(widget)) {
- gtk_widget_grab_focus(widget);
- }
}
static void
@@ -13366,6 +13411,12 @@ vte_terminal_paint(GtkWidget *widget, GdkRectangle *area)
XftDraw *ftdraw = NULL;
#endif
+#ifdef VTE_DEBUG
+ if (_vte_debug_on(VTE_DEBUG_LIFECYCLE)) {
+ fprintf(stderr, "vte_terminal_paint()\n");
+ }
+#endif
+
/* Make a few sanity checks. */
g_return_if_fail(widget != NULL);
g_return_if_fail(VTE_IS_TERMINAL(widget));
@@ -13786,6 +13837,12 @@ vte_terminal_class_init(VteTerminalClass *klass, gconstpointer data)
GQuark quark;
int i;
+#ifdef VTE_DEBUG
+ if (_vte_debug_on(VTE_DEBUG_LIFECYCLE)) {
+ fprintf(stderr, "vte_terminal_class_init()\n");
+ }
+#endif
+
bindtextdomain(PACKAGE, LOCALEDIR);
gobject_class = G_OBJECT_CLASS(klass);
@@ -13807,6 +13864,7 @@ vte_terminal_class_init(VteTerminalClass *klass, gconstpointer data)
widget_class->size_request = vte_terminal_size_request;
widget_class->size_allocate = vte_terminal_size_allocate;
widget_class->get_accessible = vte_terminal_get_accessible;
+ widget_class->show = vte_terminal_show;
/* Register some signals of our own. */
klass->eof_signal =
@@ -14085,6 +14143,11 @@ vte_terminal_get_type(void)
};
if (terminal_type == 0) {
+#ifdef VTE_DEBUG
+ if (_vte_debug_on(VTE_DEBUG_LIFECYCLE)) {
+ fprintf(stderr, "vte_terminal_get_type()\n");
+ }
+#endif
terminal_type = g_type_register_static(GTK_TYPE_WIDGET,
"VteTerminal",
&terminal_info,