]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - unix/gtkwin.c
Better not forget to make sure GTK1 doesn't break.
[PuTTY.git] / unix / gtkwin.c
index c4c255aa5f74adec269e010ef7836f364d6fd0fd..3743672a5a0a3406fb569b6e561d2a69dbfd76e7 100644 (file)
@@ -327,7 +327,7 @@ void set_zoomed(void *frontend, int zoomed)
      */
 #if GTK_CHECK_VERSION(2,0,0)
     struct gui_data *inst = (struct gui_data *)frontend;
-    if (iconic)
+    if (zoomed)
        gtk_window_maximize(GTK_WINDOW(inst->window));
     else
        gtk_window_unmaximize(GTK_WINDOW(inst->window));
@@ -1205,6 +1205,7 @@ void notify_remote_exit(void *frontend)
            inst->back->free(inst->backhandle);
            inst->backhandle = NULL;
            inst->back = NULL;
+            term_provide_resize_fn(inst->term, NULL, NULL);
            update_specials_menu(inst);
        }
        gtk_widget_show(inst->restartitem);
@@ -1346,17 +1347,13 @@ void request_resize(void *frontend, int w, int h)
      */
 #if GTK_CHECK_VERSION(2,0,0)
     gtk_widget_set_size_request(inst->area, area_x, area_y);
+    _gtk_container_dequeue_resize_handler(GTK_CONTAINER(inst->window));
+    gtk_window_resize(GTK_WINDOW(inst->window),
+                     area_x + offset_x, area_y + offset_y);
 #else
     gtk_widget_set_usize(inst->area, area_x, area_y);
     gtk_drawing_area_size(GTK_DRAWING_AREA(inst->area), area_x, area_y);
-#endif
-
     gtk_container_dequeue_resize_handler(GTK_CONTAINER(inst->window));
-
-#if GTK_CHECK_VERSION(2,0,0)
-    gtk_window_resize(GTK_WINDOW(inst->window),
-                     area_x + offset_x, area_y + offset_y);
-#else
     gdk_window_resize(inst->window->window,
                      area_x + offset_x, area_y + offset_y);
 #endif
@@ -2285,8 +2282,11 @@ GdkCursor *make_mouse_ptr(struct gui_data *inst, int cursor_val)
        return NULL;
     }
 
-    if (cursor_val >= 0 && !cursor_font)
+    if (cursor_val >= 0 && !cursor_font) {
        cursor_font = gdk_font_load("cursor");
+       if (cursor_font)
+           gdk_font_ref(cursor_font);
+    }
 
     /*
      * Get the text extent of the cursor in question. We use the
@@ -2695,6 +2695,7 @@ int uxsel_input_add(int fd, int rwx) {
     if (rwx & 1) flags |= GDK_INPUT_READ;
     if (rwx & 2) flags |= GDK_INPUT_WRITE;
     if (rwx & 4) flags |= GDK_INPUT_EXCEPTION;
+    assert(flags);
     return gdk_input_add(fd, flags, fd_input_func, NULL);
 }
 
@@ -2775,6 +2776,7 @@ void setup_fonts_ucs(struct gui_data *inst)
                inst->cfg.font.name);
        exit(1);
     }
+    gdk_font_ref(inst->fonts[0]);
     font_charset = set_font_info(inst, 0);
 
     if (inst->cfg.shadowbold) {
@@ -2789,6 +2791,7 @@ void setup_fonts_ucs(struct gui_data *inst)
        }
        inst->fonts[1] = name ? gdk_font_load(name) : NULL;
        if (inst->fonts[1]) {
+           gdk_font_ref(inst->fonts[1]);
            set_font_info(inst, 1);
        } else if (!guessed) {
            fprintf(stderr, "%s: unable to load bold font \"%s\"\n", appname,
@@ -2808,6 +2811,7 @@ void setup_fonts_ucs(struct gui_data *inst)
     }
     inst->fonts[2] = name ? gdk_font_load(name) : NULL;
     if (inst->fonts[2]) {
+       gdk_font_ref(inst->fonts[2]);
        set_font_info(inst, 2);
     } else if (!guessed) {
        fprintf(stderr, "%s: unable to load wide font \"%s\"\n", appname,
@@ -2839,6 +2843,7 @@ void setup_fonts_ucs(struct gui_data *inst)
        }
        inst->fonts[3] = name ? gdk_font_load(name) : NULL;
        if (inst->fonts[3]) {
+           gdk_font_ref(inst->fonts[3]);
            set_font_info(inst, 3);
        } else if (!guessed) {
            fprintf(stderr, "%s: unable to load wide/bold font \"%s\"\n", appname,
@@ -2850,6 +2855,17 @@ void setup_fonts_ucs(struct gui_data *inst)
     }
 
     inst->font_width = gdk_char_width(inst->fonts[0], ' ');
+    if (!inst->font_width) {
+       /* Maybe this is a 16-bit font? If so, GDK 2 actually expects a
+        * pointer to an XChar2b. This is pretty revolting. Can Pango do
+        * this more neatly even for server-side fonts?
+        */
+       XChar2b space;
+       space.byte1 = 0;
+       space.byte2 = ' ';
+       inst->font_width = gdk_text_width(inst->fonts[0],
+                                         (const gchar *)&space, 2);
+    }
     inst->font_height = inst->fonts[0]->ascent + inst->fonts[0]->descent;
 
     inst->direct_to_font = init_ucs(&inst->ucsdata, inst->cfg.line_codepage,
@@ -3301,6 +3317,35 @@ static void update_savedsess_menu(GtkMenuItem *menuitem, gpointer data)
     get_sesslist(&sesslist, FALSE); /* free up */
 }
 
+void set_window_icon(GtkWidget *window, const char *const *const *icon,
+                    int n_icon)
+{
+    GdkPixmap *iconpm;
+#if GTK_CHECK_VERSION(2,0,0)
+    GList *iconlist;
+    int n;
+#endif
+
+    if (!n_icon)
+       return;
+
+    gtk_widget_realize(window);
+    iconpm = gdk_pixmap_create_from_xpm_d(window->window, NULL,
+                                         NULL, (gchar **)icon[0]);
+    gdk_window_set_icon(window->window, NULL, iconpm, NULL);
+
+#if GTK_CHECK_VERSION(2,0,0)
+    iconlist = NULL;
+    for (n = 0; n < n_icon; n++) {
+       iconlist =
+           g_list_append(iconlist,
+                         gdk_pixbuf_new_from_xpm_data((const gchar **)
+                                                      icon[n]));
+    }
+    gdk_window_set_icon_list(window->window, iconlist);
+#endif
+}
+
 void update_specials_menu(void *frontend)
 {
     struct gui_data *inst = (struct gui_data *)frontend;
@@ -3552,6 +3597,12 @@ int pt_main(int argc, char **argv)
                          GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
                          GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK);
 
+    {
+       extern const char *const *const main_icon[];
+       extern const int n_main_icon;
+       set_window_icon(inst->window, main_icon, n_main_icon);
+    }
+
     gtk_widget_show(inst->window);
 
     set_window_background(inst);