aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2015-03-10 04:26:58 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2015-03-10 04:51:20 +0100
commite88f9bb28500bdf2bfe5106b565ab56a0b601239 (patch)
treec96410b63d2c63f42ab945b01d2d1b811bebbc5a
parent1d26dd19d09bf1fb764d1c5bef54eb05d1f4c2df (diff)
downloadsciteco-e88f9bb28500bdf2bfe5106b565ab56a0b601239.tar.gz
avoid frequent info line redraws in Curses and GTK+ UIs
* it is now redrawn once after each key press, even if the info line has not changed. * This is because Interface::update_info() is called very often in interactive mode, so it makes more sense to redraw it after user interaction (where even unnecessary delays are not noticed so easily), than thousands of times in a macro. * This is especially important since InterfaceCurses::update_info() now also sets the Window title on PDCurses - this is a very costly operation. * The same optimization was applied to InterfaceGtk where it is probably greatly responsible for the sluggishness of the UI. The GTK+ changes are currently UNTESTED.
-rw-r--r--src/interface-curses.cpp13
-rw-r--r--src/interface-gtk.cpp33
-rw-r--r--src/interface-gtk.h12
3 files changed, 38 insertions, 20 deletions
diff --git a/src/interface-curses.cpp b/src/interface-curses.cpp
index 7a242cd..be1bd21 100644
--- a/src/interface-curses.cpp
+++ b/src/interface-curses.cpp
@@ -248,8 +248,7 @@ InterfaceCurses::info_update_impl(const QRegister *reg)
info_current = g_strconcat(PACKAGE_NAME " - <QRegister> ",
name, NIL);
g_free(name);
-
- draw_info();
+ /* NOTE: drawn in event_loop_iter() */
}
void
@@ -259,8 +258,7 @@ InterfaceCurses::info_update_impl(const Buffer *buffer)
info_current = g_strconcat(PACKAGE_NAME " - <Buffer> ",
buffer->filename ? : UNNAMED_FILE,
buffer->dirty ? "*" : "", NIL);
-
- draw_info();
+ /* NOTE: drawn in event_loop_iter() */
}
void
@@ -577,6 +575,13 @@ event_loop_iter()
sigint_occurred = FALSE;
+ /*
+ * Info window is updated very often which is very
+ * costly, especially when using PDC_set_title(),
+ * so we redraw it here, where the overhead does
+ * not matter much.
+ */
+ interface.draw_info();
wnoutrefresh(interface.info_window);
/* FIXME: this does wrefresh() internally */
interface.current_view->refresh();
diff --git a/src/interface-gtk.cpp b/src/interface-gtk.cpp
index 900208c..3e1703e 100644
--- a/src/interface-gtk.cpp
+++ b/src/interface-gtk.cpp
@@ -90,6 +90,8 @@ InterfaceGtk::main_impl(int &argc, char **&argv)
vbox = gtk_vbox_new(FALSE, 0);
+ info_current = g_strdup(PACKAGE_NAME);
+
cmdline_widget = gtk_entry_new();
gtk_entry_set_has_frame(GTK_ENTRY(cmdline_widget), FALSE);
gtk_editable_set_editable(GTK_EDITABLE(cmdline_widget), FALSE);
@@ -168,28 +170,21 @@ InterfaceGtk::show_view_impl(ViewGtk *view)
void
InterfaceGtk::info_update_impl(const QRegister *reg)
{
- gchar *str;
gchar *name = String::canonicalize_ctl(reg->name);
- str = g_strconcat(PACKAGE_NAME " - <QRegister> ",
- name, NIL);
+ g_free(info_current);
+ info_current = g_strconcat(PACKAGE_NAME " - <QRegister> ",
+ name, NIL);
g_free(name);
-
- gtk_window_set_title(GTK_WINDOW(window), str);
- g_free(str);
}
void
InterfaceGtk::info_update_impl(const Buffer *buffer)
{
- gchar *str;
-
- str = g_strconcat(PACKAGE_NAME " - <Buffer> ",
- buffer->filename ? : UNNAMED_FILE,
- buffer->dirty ? "*" : "", NIL);
-
- gtk_window_set_title(GTK_WINDOW(window), str);
- g_free(str);
+ g_free(info_current);
+ info_current = g_strconcat(PACKAGE_NAME " - <Buffer> ",
+ buffer->filename ? : UNNAMED_FILE,
+ buffer->dirty ? "*" : "", NIL);
}
void
@@ -290,6 +285,7 @@ InterfaceGtk::widget_set_font(GtkWidget *widget, const gchar *font_name)
InterfaceGtk::~InterfaceGtk()
{
+ g_free(info_current);
if (popup_widget)
gtk_widget_destroy(popup_widget);
if (window)
@@ -376,6 +372,15 @@ handle_key_press(bool is_shift, bool is_ctl, guint keyval)
cmdline.keypress(key);
}
}
+
+ /*
+ * The info area is updated very often and setting the
+ * window title each time it is updated is VERY costly.
+ * So we set it here once after every keypress even if the
+ * info line did not change.
+ */
+ gtk_window_set_title(GTK_WINDOW(interface.window),
+ interface.info_current);
}
static gboolean
diff --git a/src/interface-gtk.h b/src/interface-gtk.h
index 4afac2f..389b096 100644
--- a/src/interface-gtk.h
+++ b/src/interface-gtk.h
@@ -67,8 +67,12 @@ public:
typedef class InterfaceGtk : public Interface<InterfaceGtk, ViewGtk> {
GtkWidget *window;
GtkWidget *vbox;
+
+ gchar *info_current;
+ GtkWidget *info_widget;
+
+ GtkWidget *message_widget;
GtkWidget *cmdline_widget;
- GtkWidget *info_widget, *message_widget;
GtkWidget *popup_widget;
@@ -78,8 +82,9 @@ public:
InterfaceGtk() : Interface(),
window(NULL),
vbox(NULL),
+ info_current(NULL), info_widget(NULL),
+ message_widget(NULL),
cmdline_widget(NULL),
- info_widget(NULL), message_widget(NULL),
popup_widget(NULL),
current_view_widget(NULL) {}
~InterfaceGtk();
@@ -140,6 +145,9 @@ private:
static void widget_set_font(GtkWidget *widget, const gchar *font_name);
void cmdline_insert_chr(gint &pos, gchar chr);
+
+ friend static inline void handle_key_press(bool is_shift, bool is_ctl,
+ guint keyval);
} InterfaceCurrent;
} /* namespace SciTECO */