Only engage a GTK idle function when absolutely necessary, otherwise
[u/mdw/putty] / unix / pterm.c
index 03017ec..0c1dc7c 100644 (file)
@@ -38,6 +38,7 @@ struct gui_data {
     int pasteout_data_len;
     int font_width, font_height;
     int ignore_sbar;
+    guint term_paste_idle_id;
     GdkAtom compound_text_atom;
     char wintitle[sizeof(((Config *)0)->wintitle)];
 };
@@ -59,8 +60,10 @@ void ldisc_update(int echo, int edit)
 int askappend(char *filename)
 {
     /*
-     * FIXME: for the moment we just wipe the log file. Since I
-     * haven't yet enabled logging, this shouldn't matter yet!
+     * Logging in an xterm-alike is liable to be something you only
+     * do at serious diagnostic need. Hence, I'm going to take the
+     * easy option for now and assume we always want to overwrite
+     * log files. I can always make it properly configurable later.
      */
     return 2;
 }
@@ -193,6 +196,11 @@ gint configure_area(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
     struct gui_data *inst = (struct gui_data *)data;
     int w, h, need_size = 0;
 
+    /*
+     * Set up the colour map.
+     */
+    palette_reset();
+
     w = (event->width - 2*cfg.window_border) / inst->font_width;
     h = (event->height - 2*cfg.window_border) / inst->font_height;
 
@@ -226,11 +234,6 @@ gint configure_area(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
        term_size(h, w, cfg.savelines);
     }
 
-    /*
-     * Set up the colour map.
-     */
-    palette_reset();
-
     return TRUE;
 }
 
@@ -748,13 +751,6 @@ gint timer_func(gpointer data)
     return TRUE;
 }
 
-gint idle_func(gpointer data)
-{
-    /* struct gui_data *inst = (struct gui_data *)data; */
-    term_paste();
-    return TRUE;
-}
-
 void pty_input_func(gpointer data, gint sourcefd, GdkInputCondition condition)
 {
     /* struct gui_data *inst = (struct gui_data *)data; */
@@ -922,6 +918,8 @@ void request_paste(void)
                          GDK_SELECTION_TYPE_STRING, GDK_CURRENT_TIME);
 }
 
+gint idle_paste_func(gpointer data);   /* forward ref */
+
 void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
                        gpointer data)
 {
@@ -938,8 +936,24 @@ void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
             inst->pastein_data, inst->pastein_data_len);
 
     term_do_paste();
+
+    if (term_paste_pending())
+       inst->term_paste_idle_id = gtk_idle_add(idle_paste_func, inst);
+}
+
+gint idle_paste_func(gpointer data)
+{
+    struct gui_data *inst = (struct gui_data *)data;
+
+    if (term_paste_pending())
+       term_paste();
+    else
+       gtk_idle_remove(inst->term_paste_idle_id);
+
+    return TRUE;
 }
 
+
 void get_clip(wchar_t ** p, int *len)
 {
     if (p) {
@@ -1253,6 +1267,14 @@ int main(int argc, char **argv)
            } else
                err = 1, fprintf(stderr, "pterm: -T expects an argument\n");
        }
+       if (!strcmp(p, "-log")) {
+           if (--argc > 0) {
+               strncpy(cfg.logfilename, *++argv, sizeof(cfg.logfilename));
+               cfg.logfilename[sizeof(cfg.logfilename)-1] = '\0';
+               cfg.logtype = LGTYP_DEBUG;
+           } else
+               err = 1, fprintf(stderr, "pterm: -log expects an argument\n");
+       }
        if (!strcmp(p, "-hide")) {
            cfg.hide_mouseptr = 1;
        }
@@ -1335,7 +1357,6 @@ int main(int argc, char **argv)
                       GTK_SIGNAL_FUNC(selection_clear), inst);
     gtk_signal_connect(GTK_OBJECT(inst->sbar_adjust), "value_changed",
                       GTK_SIGNAL_FUNC(scrollbar_moved), inst);
-    gtk_idle_add(idle_func, inst);
     gtk_timeout_add(20, timer_func, inst);
     gdk_input_add(pty_master_fd, GDK_INPUT_READ, pty_input_func, inst);
     gtk_widget_add_events(GTK_WIDGET(inst->area),