Added blinking cursor
This commit is contained in:
parent
de058121a7
commit
80ac137a6e
@ -156,17 +156,20 @@ void moo_term_invalidate_all (MooTerm *term)
|
||||
void moo_term_invalidate_rect (MooTerm *term,
|
||||
GdkRectangle *rect)
|
||||
{
|
||||
GdkRectangle r = {
|
||||
rect->x * term->priv->font_info->width,
|
||||
rect->y * term->priv->font_info->height,
|
||||
rect->width * term->priv->font_info->width,
|
||||
rect->height * term->priv->font_info->height
|
||||
};
|
||||
if (GTK_WIDGET_REALIZED (term))
|
||||
{
|
||||
GdkRectangle r = {
|
||||
rect->x * term->priv->font_info->width,
|
||||
rect->y * term->priv->font_info->height,
|
||||
rect->width * term->priv->font_info->width,
|
||||
rect->height * term->priv->font_info->height
|
||||
};
|
||||
|
||||
gdk_window_invalidate_rect (GTK_WIDGET(term)->window,
|
||||
&r, FALSE);
|
||||
moo_term_invalidate_content_rect (term, rect);
|
||||
add_update_timeout (term);
|
||||
gdk_window_invalidate_rect (GTK_WIDGET(term)->window,
|
||||
&r, FALSE);
|
||||
moo_term_invalidate_content_rect (term, rect);
|
||||
add_update_timeout (term);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -262,8 +265,6 @@ static void invalidate_screen_cell (MooTerm *term,
|
||||
small_rect.y = row + scrollback - top_line;
|
||||
|
||||
moo_term_invalidate_rect (term, &small_rect);
|
||||
|
||||
add_update_timeout (term);
|
||||
}
|
||||
|
||||
|
||||
@ -272,25 +273,22 @@ void moo_term_cursor_moved (MooTerm *term,
|
||||
{
|
||||
int new_row, new_col;
|
||||
|
||||
if (buf != term->priv->buffer || !term->priv->cursor_visible)
|
||||
if (buf != term->priv->buffer)
|
||||
return;
|
||||
|
||||
new_row = buf_cursor_row (buf);
|
||||
new_col = buf_cursor_col (buf);
|
||||
|
||||
invalidate_screen_cell (term,
|
||||
term->priv->cursor_row,
|
||||
term->priv->cursor_col);
|
||||
|
||||
if (new_row != (int) term->priv->cursor_row ||
|
||||
new_col != (int) term->priv->cursor_col)
|
||||
if (term->priv->_cursor_visible && term->priv->_blink_cursor_visible)
|
||||
{
|
||||
term->priv->cursor_col = new_col;
|
||||
term->priv->cursor_row = new_row;
|
||||
invalidate_screen_cell (term,
|
||||
term->priv->cursor_row,
|
||||
term->priv->cursor_col);
|
||||
invalidate_screen_cell (term, new_row, new_col);
|
||||
}
|
||||
|
||||
term->priv->cursor_col = new_col;
|
||||
term->priv->cursor_row = new_row;
|
||||
}
|
||||
|
||||
|
||||
@ -530,7 +528,7 @@ static void term_draw_range (MooTerm *term,
|
||||
g_assert (start + len <= term->priv->width);
|
||||
g_assert (abs_row < buf_total_height (term->priv->buffer));
|
||||
|
||||
if (term->priv->cursor_visible &&
|
||||
if (term->priv->_cursor_visible && term->priv->_blink_cursor_visible &&
|
||||
term->priv->cursor_row + buf_scrollback (term->priv->buffer) == abs_row)
|
||||
{
|
||||
guint cursor = buf_cursor_col (term->priv->buffer);
|
||||
@ -1034,18 +1032,41 @@ void moo_term_invert_colors (MooTerm *term,
|
||||
void moo_term_set_cursor_visible (MooTerm *term,
|
||||
gboolean visible)
|
||||
{
|
||||
if (term->priv->cursor_visible != visible)
|
||||
{
|
||||
term->priv->cursor_visible = visible;
|
||||
|
||||
if (visible)
|
||||
{
|
||||
term->priv->cursor_row = buf_cursor_row (term->priv->buffer);
|
||||
term->priv->cursor_col = buf_cursor_col (term->priv->buffer);
|
||||
}
|
||||
|
||||
invalidate_screen_cell (term,
|
||||
term->priv->cursor_row,
|
||||
term->priv->cursor_col);
|
||||
}
|
||||
term->priv->_cursor_visible = visible;
|
||||
invalidate_screen_cell (term,
|
||||
term->priv->cursor_row,
|
||||
term->priv->cursor_col);
|
||||
}
|
||||
|
||||
|
||||
static gboolean blink (MooTerm *term)
|
||||
{
|
||||
term->priv->_blink_cursor_visible =
|
||||
!term->priv->_blink_cursor_visible;
|
||||
invalidate_screen_cell (term,
|
||||
term->priv->cursor_row,
|
||||
term->priv->cursor_col);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
void moo_term_start_cursor_blinking (MooTerm *term)
|
||||
{
|
||||
if (!term->priv->_cursor_blink_timeout_id)
|
||||
term->priv->_cursor_blink_timeout_id =
|
||||
g_timeout_add (term->priv->_cursor_blink_time,
|
||||
(GSourceFunc) blink,
|
||||
term);
|
||||
}
|
||||
|
||||
|
||||
void moo_term_stop_cursor_blinking (MooTerm *term)
|
||||
{
|
||||
if (term->priv->_cursor_blink_timeout_id)
|
||||
g_source_remove (term->priv->_cursor_blink_timeout_id);
|
||||
|
||||
term->priv->_blink_cursor_visible = TRUE;
|
||||
invalidate_screen_cell (term,
|
||||
term->priv->cursor_row,
|
||||
term->priv->cursor_col);
|
||||
}
|
||||
|
@ -110,9 +110,14 @@ struct _MooTermPrivate {
|
||||
GdkGC *clip;
|
||||
gboolean font_changed;
|
||||
PangoLayout *layout;
|
||||
gboolean cursor_visible;
|
||||
guint pending_expose;
|
||||
gboolean colors_inverted;
|
||||
gboolean _cursor_visible;
|
||||
|
||||
gboolean _blink_cursor_visible;
|
||||
gboolean _cursor_blinks;
|
||||
guint _cursor_blink_time;
|
||||
guint _cursor_blink_timeout_id;
|
||||
|
||||
GdkGC *fg[MOO_TERM_COLOR_MAX + 1][3];
|
||||
GdkGC *bg[MOO_TERM_COLOR_MAX + 1][3];
|
||||
@ -210,6 +215,11 @@ void moo_term_invalidate_all (MooTerm *term);
|
||||
void moo_term_release_selection (MooTerm *term);
|
||||
void moo_term_grab_selection (MooTerm *term);
|
||||
|
||||
void moo_term_start_cursor_blinking (MooTerm *term);
|
||||
void moo_term_stop_cursor_blinking (MooTerm *term);
|
||||
void moo_term_set_cursor_blinks (MooTerm *term,
|
||||
gboolean blinks);
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* vt commands
|
||||
|
@ -22,17 +22,25 @@
|
||||
#include "mooutils/moomarshals.h"
|
||||
|
||||
|
||||
static void moo_term_class_init (MooTermClass *klass);
|
||||
static void moo_term_init (MooTerm *term);
|
||||
static void moo_term_finalize (GObject *object);
|
||||
static void moo_term_class_init (MooTermClass *klass);
|
||||
static void moo_term_init (MooTerm *term);
|
||||
static void moo_term_finalize (GObject *object);
|
||||
static void moo_term_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void moo_term_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
static void moo_term_realize (GtkWidget *widget);
|
||||
static void moo_term_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation);
|
||||
static void moo_term_realize (GtkWidget *widget);
|
||||
static void moo_term_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation);
|
||||
|
||||
static gboolean moo_term_popup_menu (GtkWidget *widget);
|
||||
static gboolean moo_term_scroll (GtkWidget *widget,
|
||||
GdkEventScroll *event);
|
||||
static gboolean moo_term_popup_menu (GtkWidget *widget);
|
||||
static gboolean moo_term_scroll (GtkWidget *widget,
|
||||
GdkEventScroll *event);
|
||||
|
||||
static void moo_term_set_scroll_adjustments (GtkWidget *widget,
|
||||
GtkAdjustment *hadj,
|
||||
@ -81,6 +89,7 @@ enum {
|
||||
|
||||
enum {
|
||||
PROP_0 = 0,
|
||||
PROP_CURSOR_BLINKS,
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
@ -135,6 +144,8 @@ static void moo_term_class_init (MooTermClass *klass)
|
||||
moo_term_parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
gobject_class->finalize = moo_term_finalize;
|
||||
gobject_class->set_property = moo_term_set_property;
|
||||
gobject_class->get_property = moo_term_get_property;
|
||||
|
||||
widget_class->realize = moo_term_realize;
|
||||
widget_class->size_allocate = moo_term_size_allocate;
|
||||
@ -149,6 +160,14 @@ static void moo_term_class_init (MooTermClass *klass)
|
||||
|
||||
klass->set_scroll_adjustments = moo_term_set_scroll_adjustments;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_CURSOR_BLINKS,
|
||||
g_param_spec_boolean ("cursor-blinks",
|
||||
"cursor-blinks",
|
||||
"cursor-blinks",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
|
||||
signals[SET_SCROLL_ADJUSTMENTS] =
|
||||
g_signal_new ("set-scroll-adjustments",
|
||||
G_OBJECT_CLASS_TYPE (gobject_class),
|
||||
@ -232,7 +251,11 @@ static void moo_term_init (MooTerm *term)
|
||||
|
||||
term->priv->selection = term_selection_new (term);
|
||||
|
||||
term->priv->cursor_visible = TRUE;
|
||||
term->priv->_cursor_visible = TRUE;
|
||||
term->priv->_blink_cursor_visible = TRUE;
|
||||
term->priv->_cursor_blinks = FALSE;
|
||||
term->priv->_cursor_blink_timeout_id = 0;
|
||||
term->priv->_cursor_blink_time = 530;
|
||||
|
||||
term->priv->settings.hide_pointer_on_keypress = TRUE;
|
||||
term->priv->settings.meta_sends_escape = TRUE;
|
||||
@ -297,6 +320,9 @@ static void moo_term_finalize (GObject *object)
|
||||
guint i, j;
|
||||
MooTerm *term = MOO_TERM (object);
|
||||
|
||||
if (term->priv->_cursor_blink_timeout_id)
|
||||
g_source_remove (term->priv->_cursor_blink_timeout_id);
|
||||
|
||||
moo_term_release_selection (term);
|
||||
|
||||
g_object_unref (term->priv->pt);
|
||||
@ -345,6 +371,50 @@ static void moo_term_finalize (GObject *object)
|
||||
}
|
||||
|
||||
|
||||
static void moo_term_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MooTerm *term = MOO_TERM (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_CURSOR_BLINKS:
|
||||
moo_term_set_cursor_blinks (term, g_value_get_boolean (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void moo_term_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MooTerm *term = MOO_TERM (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_CURSOR_BLINKS:
|
||||
g_value_set_boolean (value, term->priv->_cursor_blinks);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void moo_term_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
|
||||
static void moo_term_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation)
|
||||
{
|
||||
@ -1578,3 +1648,15 @@ void moo_term_release_selection (MooTerm *term)
|
||||
term->priv->owns_selection = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void moo_term_set_cursor_blinks (MooTerm *term,
|
||||
gboolean blinks)
|
||||
{
|
||||
term->priv->_cursor_blinks = blinks;
|
||||
if (blinks)
|
||||
moo_term_start_cursor_blinking (term);
|
||||
else
|
||||
moo_term_stop_cursor_blinking (term);
|
||||
g_object_notify (G_OBJECT (term), "cursor-blinks");
|
||||
}
|
||||
|
@ -33,7 +33,7 @@
|
||||
<kdevautoproject>
|
||||
<general>
|
||||
<activetarget>moo/libmoo.la</activetarget>
|
||||
<useconfiguration>gcc-4.0</useconfiguration>
|
||||
<useconfiguration>debug</useconfiguration>
|
||||
</general>
|
||||
<run>
|
||||
<mainprogram>tests/mterm</mainprogram>
|
||||
|
@ -63,7 +63,9 @@ int main (int argc, char *argv[])
|
||||
// GTK_POLICY_AUTOMATIC);
|
||||
GTK_POLICY_ALWAYS);
|
||||
|
||||
term = GTK_WIDGET (g_object_new (MOO_TYPE_TERM, NULL));
|
||||
term = GTK_WIDGET (g_object_new (MOO_TYPE_TERM,
|
||||
"cursor-blinks", TRUE,
|
||||
NULL));
|
||||
gtk_container_add (GTK_CONTAINER (swin), term);
|
||||
|
||||
gtk_widget_show_all (win);
|
||||
|
Loading…
x
Reference in New Issue
Block a user