Resizing of pterm now works, and the size information is correctly
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 13 Oct 2002 12:44:01 +0000 (12:44 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 13 Oct 2002 12:44:01 +0000 (12:44 +0000)
sent on to the pty.

git-svn-id: svn://svn.tartarus.org/sgt/putty@2036 cda61777-01e9-0310-a592-d414129be87e

unix/pterm.c
unix/pty.c

index 7f632d6..374e641 100644 (file)
@@ -37,6 +37,7 @@ struct gui_data {
     char *pasteout_data;
     int pasteout_data_len;
     int font_width, font_height;
+    int ignore_sbar;
 };
 
 static struct gui_data the_inst;
@@ -175,18 +176,29 @@ gint delete_window(GtkWidget *widget, GdkEvent *event, gpointer data)
 gint configure_area(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
 {
     struct gui_data *inst = (struct gui_data *)data;
+    int w, h, need_size = 0;
 
-    if (inst->pixmap)
-       gdk_pixmap_unref(inst->pixmap);
+    w = (event->width - 2*cfg.window_border) / inst->font_width;
+    h = (event->height - 2*cfg.window_border) / inst->font_height;
 
-    inst->pixmap = gdk_pixmap_new(widget->window,
-                                 (cfg.width * inst->font_width +
-                                  2*cfg.window_border),
-                                 (cfg.height * inst->font_height +
-                                  2*cfg.window_border), -1);
-
-    {
+    if (w != cfg.width || h != cfg.height) {
+       if (inst->pixmap) {
+           gdk_pixmap_unref(inst->pixmap);
+           inst->pixmap = NULL;
+       }
+       cfg.width = w;
+       cfg.height = h;
+       need_size = 1;
+    }
+    if (!inst->pixmap) {
        GdkGC *gc;
+
+       inst->pixmap = gdk_pixmap_new(widget->window,
+                                     (cfg.width * inst->font_width +
+                                      2*cfg.window_border),
+                                     (cfg.height * inst->font_height +
+                                      2*cfg.window_border), -1);
+
        gc = gdk_gc_new(inst->area->window);
        gdk_gc_set_foreground(gc, &inst->cols[18]);   /* default background */
        gdk_draw_rectangle(inst->pixmap, gc, 1, 0, 0,
@@ -195,11 +207,14 @@ gint configure_area(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
        gdk_gc_unref(gc);
     }
 
+    if (need_size) {
+       term_size(h, w, cfg.savelines);
+    }
+
     /*
      * Set up the colour map.
      */
-    inst->colmap = gdk_colormap_get_system();
-    {
+    if (!inst->colmap) {
        static const int ww[] = {
            6, 7, 8, 9, 10, 11, 12, 13,
            14, 15, 16, 17, 18, 19, 20, 21,
@@ -208,6 +223,8 @@ gint configure_area(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
        gboolean success[NCOLOURS];
        int i;
 
+       inst->colmap = gdk_colormap_get_system();
+
        assert(lenof(ww) == NCOLOURS);
 
        for (i = 0; i < NCOLOURS; i++) {
@@ -851,12 +868,15 @@ void set_sbar(int total, int start, int page)
     inst->sbar_adjust->page_size = page;
     inst->sbar_adjust->step_increment = 1;
     inst->sbar_adjust->page_increment = page/2;
+    inst->ignore_sbar = TRUE;
     gtk_adjustment_changed(inst->sbar_adjust);
+    inst->ignore_sbar = FALSE;
 }
 
 void scrollbar_moved(GtkAdjustment *adj, gpointer data)
 {
-    term_scroll(1, (int)adj->value);
+    if (!inst->ignore_sbar)
+       term_scroll(1, (int)adj->value);
 }
 
 void sys_cursor(int x, int y)
@@ -1114,8 +1134,8 @@ int main(int argc, char **argv)
     inst->sbar_adjust = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 0, 0, 0, 0));
     inst->sbar = gtk_vscrollbar_new(inst->sbar_adjust);
     inst->hbox = GTK_BOX(gtk_hbox_new(FALSE, 0));
-    gtk_box_pack_start(inst->hbox, inst->area, FALSE, FALSE, 0);
-    gtk_box_pack_start(inst->hbox, inst->sbar, FALSE, FALSE, 0);
+    gtk_box_pack_start(inst->hbox, inst->area, TRUE, TRUE, 0);
+    gtk_box_pack_end(inst->hbox, inst->sbar, FALSE, FALSE, 0);
 
     gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(inst->hbox));
 
index 56d7d89..444fb65 100644 (file)
@@ -1,4 +1,5 @@
 #define _XOPEN_SOURCE
+#define _XOPEN_SOURCE_EXTENDED
 #include <features.h>
 
 #include <stdio.h>
@@ -6,6 +7,8 @@
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <termios.h>
+#include <sys/ioctl.h>
 
 #include "putty.h"
 
@@ -20,11 +23,6 @@ int pty_master_fd;
 
 static void pty_size(void);
 
-static void c_write(char *buf, int len)
-{
-    from_backend(0, buf, len);
-}
-
 /*
  * Called to set up the pty.
  * 
@@ -62,7 +60,7 @@ static char *pty_init(char *host, int port, char **realhost, int nodelay)
     slavefd = open(name, O_RDWR);
     if (slavefd < 0) {
        perror("slave pty: open");
-       return 1;
+       exit(1);
     }
 
     /*
@@ -71,7 +69,7 @@ static char *pty_init(char *host, int port, char **realhost, int nodelay)
     pid = fork();
     if (pid < 0) {
        perror("fork");
-       return 1;
+       exit(1);
     }
 
     if (pid == 0) {
@@ -136,7 +134,11 @@ static int pty_sendbuffer(void)
  */
 static void pty_size(void)
 {
-    /* FIXME: will need to do TIOCSWINSZ or whatever. */
+    struct winsize size;
+
+    size.ws_row = (unsigned short)rows;
+    size.ws_col = (unsigned short)cols;
+    ioctl(pty_master_fd, TIOCSWINSZ, (void *)&size);
     return;
 }