Replaced g_io_channel_write_chars() with write(), added moo_term_paste_clipboard()

master
Yevgen Muntyan 2005-07-03 06:01:57 +00:00
parent bc857332a4
commit ac49a6447a
2 changed files with 39 additions and 29 deletions

View File

@ -672,7 +672,19 @@ void moo_term_copy_clipboard (MooTerm *term)
void moo_term_paste_clipboard (MooTerm *term) void moo_term_paste_clipboard (MooTerm *term)
{ {
g_warning ("%s: implement me", G_STRLOC); GtkClipboard *cb;
char *text;
g_return_if_fail (MOO_IS_TERM (term));
cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
text = gtk_clipboard_wait_for_text (cb);
if (text)
{
moo_term_vt_write (term->priv->vt, text, -1);
g_free (text);
}
} }

View File

@ -36,6 +36,7 @@
#define TERM_EMULATION "xterm" #define TERM_EMULATION "xterm"
#define READ_BUFSIZE 4096 #define READ_BUFSIZE 4096
#define CHUNK_SIZE 4096
#define POLL_TIME 5 #define POLL_TIME 5
#define POLL_NUM 1 #define POLL_NUM 1
@ -264,9 +265,6 @@ static void kill_child (MooTermVt *vt_gen)
{ {
MooTermVtUnix *vt = MOO_TERM_VT_UNIX (vt_gen); MooTermVtUnix *vt = MOO_TERM_VT_UNIX (vt_gen);
stop_writer (vt_gen);
vt_flush_pending_write (vt_gen);
if (vt->io_watch_id) if (vt->io_watch_id)
{ {
g_source_remove (vt->io_watch_id); g_source_remove (vt->io_watch_id);
@ -281,6 +279,9 @@ static void kill_child (MooTermVt *vt_gen)
vt->io = NULL; vt->io = NULL;
} }
stop_writer (vt_gen);
vt_flush_pending_write (vt_gen);
if (vt->master != -1) if (vt->master != -1)
{ {
_vte_pty_close (vt->master); _vte_pty_close (vt->master);
@ -459,39 +460,40 @@ static void feed_buffer (MooTermVtUnix *vt,
static gboolean do_write (MooTermVt *vt_gen, static gboolean do_write (MooTermVt *vt_gen,
const char **string, const char **string,
gsize *plen, gsize *plen,
GError **err) int *err)
{ {
GIOStatus status; gssize written;
gsize written = 0;
MooTermVtUnix *vt = MOO_TERM_VT_UNIX (vt_gen); MooTermVtUnix *vt = MOO_TERM_VT_UNIX (vt_gen);
g_return_val_if_fail (vt->io != NULL, FALSE); g_return_val_if_fail (vt->io != NULL, FALSE);
*err = NULL; written = write (vt->master, *string, *plen > CHUNK_SIZE ? CHUNK_SIZE : *plen);
status = g_io_channel_write_chars (vt->io, *string, *plen, if (written == -1)
&written, err);
if (written == *plen)
{ {
*string = NULL; *err = errno;
*plen = 0;
switch (errno)
{
case EAGAIN:
case EINTR:
g_warning ("%s", G_STRLOC);
return TRUE;
default:
return FALSE;
}
} }
else else
{ {
*string += written; *string += written;
*plen -= written; *plen -= written;
}
switch (status) if (!*plen)
{ *string = NULL;
case G_IO_STATUS_NORMAL:
case G_IO_STATUS_AGAIN: return TRUE;
return TRUE;
default:
return FALSE;
} }
} }
@ -539,7 +541,7 @@ static void vt_write (MooTermVt *vt,
while (data || !g_queue_is_empty (vt->priv->pending_write)) while (data || !g_queue_is_empty (vt->priv->pending_write))
{ {
GError *err = NULL; int err = 0;
const char *string; const char *string;
gsize len; gsize len;
GByteArray *freeme = NULL; GByteArray *freeme = NULL;
@ -589,11 +591,7 @@ static void vt_write (MooTermVt *vt,
{ {
g_message ("%s: stopping writing to child", G_STRLOC); g_message ("%s: stopping writing to child", G_STRLOC);
if (err) if (err)
{ g_message ("%s: %s", G_STRLOC, g_strerror (err));
g_message ("%s: %s", G_STRLOC, err->message);
g_error_free (err);
}
stop_writer (vt);
kill_child (vt); kill_child (vt);
} }
} }