X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/8df5b84fdf848119a9e2ba5e5a60846b6eab9886..f08a390fab250d5d200b3fbdc531916f388a0ef3:/unix/gtkwin.c diff --git a/unix/gtkwin.c b/unix/gtkwin.c index 03f28551..ee91a93e 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -31,6 +31,8 @@ #define PUTTY_DO_GLOBALS /* actually _define_ globals */ +#define MAY_REFER_TO_GTK_IN_HEADERS + #include "putty.h" #include "terminal.h" #include "gtkfont.h" @@ -1221,7 +1223,8 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) void input_method_commit_event(GtkIMContext *imc, gchar *str, gpointer data) { struct gui_data *inst = (struct gui_data *)data; - lpage_send(inst->ldisc, CS_UTF8, str, strlen(str), 1); + if (inst->ldisc) + lpage_send(inst->ldisc, CS_UTF8, str, strlen(str), 1); show_mouseptr(inst, 0); term_seen_key_event(inst->term); } @@ -1358,7 +1361,7 @@ void frontend_keypress(void *handle) * any keypress. */ if (inst->exited) - exit(0); + cleanup_exit(0); } static gint idle_exit_func(gpointer data) @@ -1377,13 +1380,11 @@ static gint idle_exit_func(gpointer data) ldisc_free(inst->ldisc); inst->ldisc = NULL; } - if (inst->back) { - inst->back->free(inst->backhandle); - inst->backhandle = NULL; - inst->back = NULL; - term_provide_resize_fn(inst->term, NULL, NULL); - update_specials_menu(inst); - } + 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_set_sensitive(inst->restartitem, TRUE); } @@ -1400,13 +1401,18 @@ void notify_remote_exit(void *frontend) static gint timer_trigger(gpointer data) { - long now = GPOINTER_TO_LONG(data); - long next; + unsigned long now = GPOINTER_TO_LONG(data); + unsigned long next, then; long ticks; if (run_timers(now, &next)) { - ticks = next - GETTICKCOUNT(); - timer_id = gtk_timeout_add(ticks > 0 ? ticks : 1, timer_trigger, + then = now; + now = GETTICKCOUNT(); + if (now - then > next - then) + ticks = 0; + else + ticks = next - now; + timer_id = gtk_timeout_add(ticks, timer_trigger, LONG_TO_GPOINTER(next)); } @@ -1417,7 +1423,7 @@ static gint timer_trigger(gpointer data) return FALSE; } -void timer_change_notify(long next) +void timer_change_notify(unsigned long next) { long ticks; @@ -1590,7 +1596,7 @@ void palette_set(void *frontend, int n, int r, int g, int b) struct gui_data *inst = (struct gui_data *)frontend; if (n >= 16) n += 256 - 16; - if (n > NALLCOLOURS) + if (n >= NALLCOLOURS) return; real_palette_set(inst, n, r, g, b); if (n == 258) { @@ -2587,6 +2593,13 @@ static void help(FILE *fp) { } } +static void version(FILE *fp) { + if(fprintf(fp, "%s: %s\n", appname, ver) < 0 || fflush(fp) < 0) { + perror("output error"); + exit(1); + } +} + int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch, struct gui_data *inst, Conf *conf) { @@ -2796,6 +2809,10 @@ int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch, help(stdout); exit(0); + } else if(!strcmp(p, "-version") || !strcmp(p, "--version")) { + version(stdout); + exit(0); + } else if (!strcmp(p, "-pgpfp")) { pgp_fingerprints(); exit(1); @@ -2845,69 +2862,74 @@ void frontend_net_error_pending(void) } } -void setup_fonts_ucs(struct gui_data *inst) +char *setup_fonts_ucs(struct gui_data *inst) { int shadowbold = conf_get_int(inst->conf, CONF_shadowbold); int shadowboldoffset = conf_get_int(inst->conf, CONF_shadowboldoffset); FontSpec *fs; - - if (inst->fonts[0]) - unifont_destroy(inst->fonts[0]); - if (inst->fonts[1]) - unifont_destroy(inst->fonts[1]); - if (inst->fonts[2]) - unifont_destroy(inst->fonts[2]); - if (inst->fonts[3]) - unifont_destroy(inst->fonts[3]); + unifont *fonts[4]; + int i; fs = conf_get_fontspec(inst->conf, CONF_font); - inst->fonts[0] = multifont_create(inst->area, fs->name, FALSE, FALSE, - shadowboldoffset, shadowbold); - if (!inst->fonts[0]) { - fprintf(stderr, "%s: unable to load font \"%s\"\n", appname, - fs->name); - exit(1); + fonts[0] = multifont_create(inst->area, fs->name, FALSE, FALSE, + shadowboldoffset, shadowbold); + if (!fonts[0]) { + return dupprintf("unable to load font \"%s\"", fs->name); } fs = conf_get_fontspec(inst->conf, CONF_boldfont); if (shadowbold || !fs->name[0]) { - inst->fonts[1] = NULL; + fonts[1] = NULL; } else { - inst->fonts[1] = multifont_create(inst->area, fs->name, FALSE, TRUE, - shadowboldoffset, shadowbold); - if (!inst->fonts[1]) { - fprintf(stderr, "%s: unable to load bold font \"%s\"\n", appname, - fs->name); - exit(1); + fonts[1] = multifont_create(inst->area, fs->name, FALSE, TRUE, + shadowboldoffset, shadowbold); + if (!fonts[1]) { + if (fonts[0]) + unifont_destroy(fonts[0]); + return dupprintf("unable to load bold font \"%s\"", fs->name); } } fs = conf_get_fontspec(inst->conf, CONF_widefont); if (fs->name[0]) { - inst->fonts[2] = multifont_create(inst->area, fs->name, TRUE, FALSE, - shadowboldoffset, shadowbold); - if (!inst->fonts[2]) { - fprintf(stderr, "%s: unable to load wide font \"%s\"\n", appname, - fs->name); - exit(1); + fonts[2] = multifont_create(inst->area, fs->name, TRUE, FALSE, + shadowboldoffset, shadowbold); + if (!fonts[2]) { + for (i = 0; i < 2; i++) + if (fonts[i]) + unifont_destroy(fonts[i]); + return dupprintf("%s: unable to load wide font \"%s\"", fs->name); } } else { - inst->fonts[2] = NULL; + fonts[2] = NULL; } fs = conf_get_fontspec(inst->conf, CONF_wideboldfont); if (shadowbold || !fs->name[0]) { - inst->fonts[3] = NULL; + fonts[3] = NULL; } else { - inst->fonts[3] = multifont_create(inst->area, fs->name, TRUE, TRUE, - shadowboldoffset, shadowbold); - if (!inst->fonts[3]) { - fprintf(stderr, "%s: unable to load wide bold font \"%s\"\n", appname, - fs->name); - exit(1); + fonts[3] = multifont_create(inst->area, fs->name, TRUE, TRUE, + shadowboldoffset, shadowbold); + if (!fonts[3]) { + for (i = 0; i < 3; i++) + if (fonts[i]) + unifont_destroy(fonts[i]); + return dupprintf("%s: unable to load wide bold font \"%s\"", + fs->name); } } + /* + * Now we've got past all the possible error conditions, we can + * actually update our state. + */ + + for (i = 0; i < 4; i++) { + if (inst->fonts[i]) + unifont_destroy(inst->fonts[i]); + inst->fonts[i] = fonts[i]; + } + inst->font_width = inst->fonts[0]->width; inst->font_height = inst->fonts[0]->height; @@ -2916,6 +2938,8 @@ void setup_fonts_ucs(struct gui_data *inst) conf_get_int(inst->conf, CONF_utf8_override), inst->fonts[0]->public_charset, conf_get_int(inst->conf, CONF_vtmode)); + + return NULL; } void set_geom_hints(struct gui_data *inst) @@ -2985,7 +3009,7 @@ void change_settings_menuitem(GtkMenuItem *item, gpointer data) 4, 12, 5, 13, 6, 14, 7, 15 }; struct gui_data *inst = (struct gui_data *)data; - char *title = dupcat(appname, " Reconfiguration", NULL); + char *title; Conf *oldconf, *newconf; int i, j, need_size; @@ -2996,6 +3020,8 @@ void change_settings_menuitem(GtkMenuItem *item, gpointer data) else inst->reconfiguring = TRUE; + title = dupcat(appname, " Reconfiguration", NULL); + oldconf = inst->conf; newconf = conf_copy(inst->conf); @@ -3009,9 +3035,10 @@ void change_settings_menuitem(GtkMenuItem *item, gpointer data) * Flush the line discipline's edit buffer in the case * where local editing has just been disabled. */ - ldisc_configure(inst->ldisc, inst->conf); - if (inst->ldisc) + if (inst->ldisc) { + ldisc_configure(inst->ldisc, inst->conf); ldisc_send(inst->ldisc, NULL, 0, 0); + } /* Pass new config data to the terminal */ term_reconfig(inst->term, inst->conf); /* Pass new config data to the back end */ @@ -3044,7 +3071,7 @@ void change_settings_menuitem(GtkMenuItem *item, gpointer data) * repaint the space in between the window border * and the text area. */ - if (i == 258) { + if (ww[i] == 258) { set_window_background(inst); draw_backing_rect(inst); } @@ -3081,6 +3108,7 @@ void change_settings_menuitem(GtkMenuItem *item, gpointer data) * Redo the whole tangled fonts and Unicode mess if * necessary. */ + need_size = FALSE; if (strcmp(conf_get_fontspec(oldconf, CONF_font)->name, conf_get_fontspec(newconf, CONF_font)->name) || strcmp(conf_get_fontspec(oldconf, CONF_boldfont)->name, @@ -3099,10 +3127,21 @@ void change_settings_menuitem(GtkMenuItem *item, gpointer data) conf_get_int(newconf, CONF_shadowbold) || conf_get_int(oldconf, CONF_shadowboldoffset) != conf_get_int(newconf, CONF_shadowboldoffset)) { - setup_fonts_ucs(inst); - need_size = 1; - } else - need_size = 0; + char *errmsg = setup_fonts_ucs(inst); + if (errmsg) { + char *msgboxtext = + dupprintf("Could not change fonts in terminal window: %s\n", + errmsg); + messagebox(inst->window, "Font setup error", msgboxtext, + string_width("Could not change fonts in terminal window:"), + "OK", 'o', +1, 1, + NULL); + sfree(msgboxtext); + sfree(errmsg); + } else { + need_size = TRUE; + } + } /* * Resize the window. @@ -3192,6 +3231,7 @@ void fork_and_exec_self(struct gui_data *inst, int fd_to_close, ...) pid = fork(); if (pid < 0) { perror("fork"); + sfree(args); return; } @@ -3225,6 +3265,7 @@ void fork_and_exec_self(struct gui_data *inst, int fd_to_close, ...) } else { int status; + sfree(args); waitpid(pid, &status, 0); } @@ -3303,6 +3344,7 @@ int read_dupsession_data(struct gui_data *inst, Conf *conf, char *arg) } size_used = conf_deserialise(conf, data, size); + sfree(data); if (use_pty_argv && size > size_used) { int n = 0; i = size_used; @@ -3582,7 +3624,7 @@ int pt_main(int argc, char **argv) if (argc > 1 && !strncmp(argv[1], "---", 3)) { read_dupsession_data(inst, inst->conf, argv[1]); /* Splatter this argument so it doesn't clutter a ps listing */ - memset(argv[1], 0, strlen(argv[1])); + smemclr(argv[1], strlen(argv[1])); } else { /* By default, we bring up the config dialog, rather than launching * a session. This gets set to TRUE if something happens to change @@ -3615,7 +3657,13 @@ int pt_main(int argc, char **argv) inst->imc = gtk_im_multicontext_new(); #endif - setup_fonts_ucs(inst); + { + char *errmsg = setup_fonts_ucs(inst); + if (errmsg) { + fprintf(stderr, "%s: %s\n", appname, errmsg); + exit(1); + } + } init_cutbuffers(); inst->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);