#include <stdio.h>
#include <time.h>
#include <errno.h>
+#include <locale.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
+#if GTK_CHECK_VERSION(2,0,0)
+#include <gtk/gtkimmodule.h>
+#endif
+
#define PUTTY_DO_GLOBALS /* actually _define_ globals */
+#define MAY_REFER_TO_GTK_IN_HEADERS
+
#include "putty.h"
#include "terminal.h"
#include "gtkfont.h"
#define CAT(x,y) CAT2(x,y)
#define ASSERT(x) enum {CAT(assertion_,__LINE__) = 1 / (x)}
+#if GTK_CHECK_VERSION(2,0,0)
+ASSERT(sizeof(long) <= sizeof(gsize));
+#define LONG_TO_GPOINTER(l) GSIZE_TO_POINTER(l)
+#define GPOINTER_TO_LONG(p) GPOINTER_TO_SIZE(p)
+#else /* Gtk 1.2 */
+ASSERT(sizeof(long) <= sizeof(gpointer));
+#define LONG_TO_GPOINTER(l) ((gpointer)(long)(l))
+#define GPOINTER_TO_LONG(p) ((long)(p))
+#endif
+
/* Colours come in two flavours: configurable, and xterm-extended. */
-#define NCFGCOLOURS (lenof(((Config *)0)->colours))
#define NEXTCOLOURS 240 /* 216 colour-cube plus 24 shades of grey */
#define NALLCOLOURS (NCFGCOLOURS + NEXTCOLOURS)
*restartitem;
GtkWidget *sessionsmenu;
GdkPixmap *pixmap;
+#if GTK_CHECK_VERSION(2,0,0)
+ GtkIMContext *imc;
+#endif
unifont *fonts[4]; /* normal, bold, wide, widebold */
int xpos, ypos, gotpos, gravity;
GdkCursor *rawcursor, *textcursor, *blankcursor, *waitcursor, *currcursor;
guint term_exit_idle_id;
int alt_keycode;
int alt_digits;
- char wintitle[sizeof(((Config *)0)->wintitle)];
- char icontitle[sizeof(((Config *)0)->wintitle)];
+ char *wintitle;
+ char *icontitle;
int master_fd, master_func_id;
void *ldisc;
Backend *back;
void *logctx;
int exited;
struct unicode_data ucsdata;
- Config cfg;
+ Conf *conf;
void *eventlogstuff;
char *progname, **gtkargvstart;
int ngtkargs;
guint32 input_event_time; /* Timestamp of the most recent input event. */
int reconfiguring;
+ /* Cached things out of conf that we refer to a lot */
+ int bold_style;
+ int window_border;
+ int cursor_type;
};
+static void cache_conf_values(struct gui_data *inst)
+{
+ inst->bold_style = conf_get_int(inst->conf, CONF_bold_style);
+ inst->window_border = conf_get_int(inst->conf, CONF_window_border);
+ inst->cursor_type = conf_get_int(inst->conf, CONF_cursor_type);
+}
+
struct draw_ctx {
GdkGC *gc;
struct gui_data *inst;
inst->exited = TRUE;
fatal_message_box(inst->window, msg);
sfree(msg);
- if (inst->cfg.close_on_exit == FORCE_ON)
+ if (conf_get_int(inst->conf, CONF_close_on_exit) == FORCE_ON)
cleanup_exit(1);
}
/*
* Default settings that are specific to pterm.
*/
-FontSpec platform_default_fontspec(const char *name)
+FontSpec *platform_default_fontspec(const char *name)
{
- FontSpec ret;
if (!strcmp(name, "Font"))
- strcpy(ret.name, "server:fixed");
+ return fontspec_new("server:fixed");
else
- *ret.name = '\0';
- return ret;
+ return fontspec_new("");
}
-Filename platform_default_filename(const char *name)
+Filename *platform_default_filename(const char *name)
{
- Filename ret;
if (!strcmp(name, "LogFileName"))
- strcpy(ret.path, "putty.log");
+ return filename_from_str("putty.log");
else
- *ret.path = '\0';
- return ret;
+ return filename_from_str("");
}
char *platform_default_s(const char *name)
return term_data_untrusted(inst->term, data, len);
}
+int from_backend_eof(void *frontend)
+{
+ return TRUE; /* do respond to incoming EOF with outgoing */
+}
+
int get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
{
struct gui_data *inst = (struct gui_data *)p->frontend;
gint delete_window(GtkWidget *widget, GdkEvent *event, gpointer data)
{
struct gui_data *inst = (struct gui_data *)data;
- if (!inst->exited && inst->cfg.warn_on_close) {
+ if (!inst->exited && conf_get_int(inst->conf, CONF_warn_on_close)) {
if (!reallyclose(inst))
return TRUE;
}
static void show_mouseptr(struct gui_data *inst, int show)
{
- if (!inst->cfg.hide_mouseptr)
+ if (!conf_get_int(inst->conf, CONF_hide_mouseptr))
show = 1;
inst->mouseptr_visible = show;
update_mouseptr(inst);
GdkGC *gc = gdk_gc_new(inst->area->window);
gdk_gc_set_foreground(gc, &inst->cols[258]); /* default background */
gdk_draw_rectangle(inst->pixmap, gc, 1, 0, 0,
- inst->cfg.width * inst->font_width + 2*inst->cfg.window_border,
- inst->cfg.height * inst->font_height + 2*inst->cfg.window_border);
+ inst->width * inst->font_width + 2*inst->window_border,
+ inst->height * inst->font_height + 2*inst->window_border);
gdk_gc_unref(gc);
}
* See if the terminal size has changed, in which case we must
* let the terminal know.
*/
- w = (event->width - 2*inst->cfg.window_border) / inst->font_width;
- h = (event->height - 2*inst->cfg.window_border) / inst->font_height;
+ w = (event->width - 2*inst->window_border) / inst->font_width;
+ h = (event->height - 2*inst->window_border) / inst->font_height;
if (w != inst->width || h != inst->height) {
- inst->cfg.width = inst->width = w;
- inst->cfg.height = inst->height = h;
+ inst->width = w;
+ inst->height = h;
+ conf_set_int(inst->conf, CONF_width, inst->width);
+ conf_set_int(inst->conf, CONF_height, inst->height);
need_size = 1;
}
}
inst->pixmap = gdk_pixmap_new(widget->window,
- (inst->cfg.width * inst->font_width +
- 2*inst->cfg.window_border),
- (inst->cfg.height * inst->font_height +
- 2*inst->cfg.window_border), -1);
+ (w * inst->font_width + 2*inst->window_border),
+ (h * inst->font_height + 2*inst->window_border), -1);
draw_backing_rect(inst);
if (need_size && inst->term) {
- term_size(inst->term, h, w, inst->cfg.savelines);
+ term_size(inst->term, h, w, conf_get_int(inst->conf, CONF_savelines));
}
if (inst->term)
term_invalidate(inst->term);
+#if GTK_CHECK_VERSION(2,0,0)
+ gtk_im_context_set_client_window(inst->imc, widget->window);
+#endif
+
return TRUE;
}
char output[256];
wchar_t ucsoutput[2];
int ucsval, start, end, special, output_charset, use_ucsoutput;
+ int nethack_mode, app_keypad_mode;
/* Remember the timestamp. */
inst->input_event_time = event->time;
* inconvenience in having to type a zero before a single-digit
* character code.
*/
- if (event->type == GDK_KEY_RELEASE &&
- (event->keyval == GDK_Meta_L || event->keyval == GDK_Alt_L ||
- event->keyval == GDK_Meta_R || event->keyval == GDK_Alt_R) &&
- inst->alt_keycode >= 0 && inst->alt_digits > 1) {
+ if (event->type == GDK_KEY_RELEASE) {
+ if ((event->keyval == GDK_Meta_L || event->keyval == GDK_Alt_L ||
+ event->keyval == GDK_Meta_R || event->keyval == GDK_Alt_R) &&
+ inst->alt_keycode >= 0 && inst->alt_digits > 1) {
#ifdef KEY_DEBUGGING
- printf("Alt key up, keycode = %d\n", inst->alt_keycode);
+ printf("Alt key up, keycode = %d\n", inst->alt_keycode);
+#endif
+ /*
+ * FIXME: we might usefully try to do something clever here
+ * about interpreting the generated key code in a way that's
+ * appropriate to the line code page.
+ */
+ output[0] = inst->alt_keycode;
+ end = 1;
+ goto done;
+ }
+#if GTK_CHECK_VERSION(2,0,0)
+ if (gtk_im_context_filter_keypress(inst->imc, event))
+ return TRUE;
#endif
- /*
- * FIXME: we might usefully try to do something clever here
- * about interpreting the generated key code in a way that's
- * appropriate to the line code page.
- */
- output[0] = inst->alt_keycode;
- end = 1;
- goto done;
}
if (event->type == GDK_KEY_PRESS) {
* at all.
*/
if (event->keyval == GDK_Page_Up && (event->state & GDK_SHIFT_MASK)) {
- term_scroll(inst->term, 0, -inst->cfg.height/2);
+ term_scroll(inst->term, 0, -inst->height/2);
return TRUE;
}
if (event->keyval == GDK_Page_Up && (event->state & GDK_CONTROL_MASK)) {
return TRUE;
}
if (event->keyval == GDK_Page_Down && (event->state & GDK_SHIFT_MASK)) {
- term_scroll(inst->term, 0, +inst->cfg.height/2);
+ term_scroll(inst->term, 0, +inst->height/2);
return TRUE;
}
if (event->keyval == GDK_Page_Down && (event->state & GDK_CONTROL_MASK)) {
special = FALSE;
use_ucsoutput = FALSE;
+ nethack_mode = conf_get_int(inst->conf, CONF_nethack_keypad);
+ app_keypad_mode = (inst->term->app_keypad_keys &&
+ !conf_get_int(inst->conf, CONF_no_applic_k));
+
/* ALT+things gives leading Escape. */
output[0] = '\033';
#if !GTK_CHECK_VERSION(2,0,0)
output_charset = CS_ISO8859_1;
strncpy(output+1, event->string, lenof(output)-1);
#else
+ /*
+ * Most things can now be passed to
+ * gtk_im_context_filter_keypress without breaking anything
+ * below this point. An exception is the numeric keypad if
+ * we're in Nethack or application mode: the IM will eat
+ * numeric keypad presses if Num Lock is on, but we don't want
+ * it to.
+ */
+ if (app_keypad_mode &&
+ (event->keyval == GDK_Num_Lock ||
+ event->keyval == GDK_KP_Divide ||
+ event->keyval == GDK_KP_Multiply ||
+ event->keyval == GDK_KP_Subtract ||
+ event->keyval == GDK_KP_Add ||
+ event->keyval == GDK_KP_Enter ||
+ event->keyval == GDK_KP_0 ||
+ event->keyval == GDK_KP_Insert ||
+ event->keyval == GDK_KP_1 ||
+ event->keyval == GDK_KP_End ||
+ event->keyval == GDK_KP_2 ||
+ event->keyval == GDK_KP_Down ||
+ event->keyval == GDK_KP_3 ||
+ event->keyval == GDK_KP_Page_Down ||
+ event->keyval == GDK_KP_4 ||
+ event->keyval == GDK_KP_Left ||
+ event->keyval == GDK_KP_5 ||
+ event->keyval == GDK_KP_Begin ||
+ event->keyval == GDK_KP_6 ||
+ event->keyval == GDK_KP_Right ||
+ event->keyval == GDK_KP_7 ||
+ event->keyval == GDK_KP_Home ||
+ event->keyval == GDK_KP_8 ||
+ event->keyval == GDK_KP_Up ||
+ event->keyval == GDK_KP_9 ||
+ event->keyval == GDK_KP_Page_Up ||
+ event->keyval == GDK_KP_Decimal ||
+ event->keyval == GDK_KP_Delete)) {
+ /* app keypad; do nothing */
+ } else if (nethack_mode &&
+ (event->keyval == GDK_KP_1 ||
+ event->keyval == GDK_KP_End ||
+ event->keyval == GDK_KP_2 ||
+ event->keyval == GDK_KP_Down ||
+ event->keyval == GDK_KP_3 ||
+ event->keyval == GDK_KP_Page_Down ||
+ event->keyval == GDK_KP_4 ||
+ event->keyval == GDK_KP_Left ||
+ event->keyval == GDK_KP_5 ||
+ event->keyval == GDK_KP_Begin ||
+ event->keyval == GDK_KP_6 ||
+ event->keyval == GDK_KP_Right ||
+ event->keyval == GDK_KP_7 ||
+ event->keyval == GDK_KP_Home ||
+ event->keyval == GDK_KP_8 ||
+ event->keyval == GDK_KP_Up ||
+ event->keyval == GDK_KP_9 ||
+ event->keyval == GDK_KP_Page_Up)) {
+ /* nethack mode; do nothing */
+ } else {
+ if (gtk_im_context_filter_keypress(inst->imc, event))
+ return TRUE;
+ }
+
/*
* GDK 2.0 arranges to have done some translation for us: in
* GDK 2.0, event->string is encoded in the current locale.
*
- * (However, it's also deprecated; we really ought to be
- * using a GTKIMContext.)
- *
* So we use the standard C library function mbstowcs() to
* convert from the current locale into Unicode; from there
* we can convert to whatever PuTTY is currently working in.
*/
output_charset = CS_UTF8;
{
- wchar_t widedata[32], *wp;
+ wchar_t widedata[32];
+ const wchar_t *wp;
int wlen;
int ulen;
/* We don't let GTK tell us what Backspace is! We know better. */
if (event->keyval == GDK_BackSpace &&
!(event->state & GDK_SHIFT_MASK)) {
- output[1] = inst->cfg.bksp_is_delete ? '\x7F' : '\x08';
+ output[1] = conf_get_int(inst->conf, CONF_bksp_is_delete) ?
+ '\x7F' : '\x08';
use_ucsoutput = FALSE;
end = 2;
special = TRUE;
/* For Shift Backspace, do opposite of what is configured. */
if (event->keyval == GDK_BackSpace &&
(event->state & GDK_SHIFT_MASK)) {
- output[1] = inst->cfg.bksp_is_delete ? '\x08' : '\x7F';
+ output[1] = conf_get_int(inst->conf, CONF_bksp_is_delete) ?
+ '\x08' : '\x7F';
use_ucsoutput = FALSE;
end = 2;
special = TRUE;
/*
* NetHack keypad mode.
*/
- if (inst->cfg.nethack_keypad) {
+ if (nethack_mode) {
char *keys = NULL;
switch (event->keyval) {
case GDK_KP_1: case GDK_KP_End: keys = "bB\002"; break;
/*
* Application keypad mode.
*/
- if (inst->term->app_keypad_keys && !inst->cfg.no_applic_k) {
+ if (app_keypad_mode) {
int xkey = 0;
switch (event->keyval) {
case GDK_Num_Lock: xkey = 'P'; break;
* in xterm function key mode we change which two...
*/
case GDK_KP_Add:
- if (inst->cfg.funky_type == FUNKY_XTERM) {
+ if (conf_get_int(inst->conf, CONF_funky_type) == FUNKY_XTERM) {
if (event->state & GDK_SHIFT_MASK)
xkey = 'l';
else
*/
{
int code = 0;
+ int funky_type = conf_get_int(inst->conf, CONF_funky_type);
switch (event->keyval) {
case GDK_F1:
code = (event->state & GDK_SHIFT_MASK ? 23 : 11);
break;
}
/* Reorder edit keys to physical order */
- if (inst->cfg.funky_type == FUNKY_VT400 && code <= 6)
+ if (funky_type == FUNKY_VT400 && code <= 6)
code = "\0\2\1\4\5\3\6"[code];
if (inst->term->vt52_mode && code > 0 && code <= 6) {
goto done;
}
- if (inst->cfg.funky_type == FUNKY_SCO && /* SCO function keys */
+ if (funky_type == FUNKY_SCO && /* SCO function keys */
code >= 11 && code <= 34) {
char codes[] = "MNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@[\\]^_`{";
int index = 0;
use_ucsoutput = FALSE;
goto done;
}
- if (inst->cfg.funky_type == FUNKY_SCO && /* SCO small keypad */
+ if (funky_type == FUNKY_SCO && /* SCO small keypad */
code >= 1 && code <= 6) {
char codes[] = "HL.FIG";
if (code == 3) {
use_ucsoutput = FALSE;
goto done;
}
- if ((inst->term->vt52_mode || inst->cfg.funky_type == FUNKY_VT100P) &&
+ if ((inst->term->vt52_mode || funky_type == FUNKY_VT100P) &&
code >= 11 && code <= 24) {
int offt = 0;
if (code > 15)
use_ucsoutput = FALSE;
goto done;
}
- if (inst->cfg.funky_type == FUNKY_LINUX && code >= 11 && code <= 15) {
+ if (funky_type == FUNKY_LINUX && code >= 11 && code <= 15) {
end = 1 + sprintf(output+1, "\x1B[[%c", code + 'A' - 11);
use_ucsoutput = FALSE;
goto done;
}
- if (inst->cfg.funky_type == FUNKY_XTERM && code >= 11 && code <= 14) {
+ if (funky_type == FUNKY_XTERM && code >= 11 && code <= 14) {
if (inst->term->vt52_mode)
end = 1 + sprintf(output+1, "\x1B%c", code + 'P' - 11);
else
use_ucsoutput = FALSE;
goto done;
}
- if (inst->cfg.rxvt_homeend && (code == 1 || code == 4)) {
+ if ((code == 1 || code == 4) &&
+ conf_get_int(inst->conf, CONF_rxvt_homeend)) {
end = 1 + sprintf(output+1, code == 1 ? "\x1B[H" : "\x1BOw");
use_ucsoutput = FALSE;
goto done;
case GDK_Begin: case GDK_KP_Begin: xkey = 'G'; break;
}
if (xkey) {
- /*
- * The arrow keys normally do ESC [ A and so on. In
- * app cursor keys mode they do ESC O A instead.
- * Ctrl toggles the two modes.
- */
- if (inst->term->vt52_mode) {
- end = 1 + sprintf(output+1, "\033%c", xkey);
- } else if (!inst->term->app_cursor_keys ^
- !(event->state & GDK_CONTROL_MASK)) {
- end = 1 + sprintf(output+1, "\033O%c", xkey);
- } else {
- end = 1 + sprintf(output+1, "\033[%c", xkey);
- }
+ end = 1 + format_arrow_key(output+1, inst->term, xkey,
+ event->state & GDK_CONTROL_MASK);
use_ucsoutput = FALSE;
goto done;
}
return TRUE;
}
+#if GTK_CHECK_VERSION(2,0,0)
+void input_method_commit_event(GtkIMContext *imc, gchar *str, gpointer data)
+{
+ struct gui_data *inst = (struct gui_data *)data;
+ if (inst->ldisc)
+ lpage_send(inst->ldisc, CS_UTF8, str, strlen(str), 1);
+ show_mouseptr(inst, 0);
+ term_seen_key_event(inst->term);
+}
+#endif
+
gboolean button_internal(struct gui_data *inst, guint32 timestamp,
GdkEventType type, guint ebutton, guint state,
gdouble ex, gdouble ey)
default: return FALSE; /* don't know this event type */
}
- if (send_raw_mouse && !(inst->cfg.mouse_override && shift) &&
+ if (send_raw_mouse && !(shift && conf_get_int(inst->conf,
+ CONF_mouse_override)) &&
act != MA_CLICK && act != MA_RELEASE)
return TRUE; /* we ignore these in raw mouse mode */
- x = (ex - inst->cfg.window_border) / inst->font_width;
- y = (ey - inst->cfg.window_border) / inst->font_height;
+ x = (ex - inst->window_border) / inst->font_width;
+ y = (ey - inst->window_border) / inst->font_height;
term_mouse(inst->term, button, translate_button(button), act,
x, y, shift, ctrl, alt);
else
return FALSE; /* don't even know what button! */
- x = (event->x - inst->cfg.window_border) / inst->font_width;
- y = (event->y - inst->cfg.window_border) / inst->font_height;
+ x = (event->x - inst->window_border) / inst->font_width;
+ y = (event->y - inst->window_border) / inst->font_height;
term_mouse(inst->term, button, translate_button(button), MA_DRAG,
x, y, shift, ctrl, alt);
* any keypress.
*/
if (inst->exited)
- exit(0);
+ cleanup_exit(0);
}
static gint idle_exit_func(gpointer data)
{
struct gui_data *inst = (struct gui_data *)data;
- int exitcode;
+ int exitcode, close_on_exit;
if (!inst->exited &&
(exitcode = inst->back->exitcode(inst->backhandle)) >= 0) {
inst->exited = TRUE;
- if (inst->cfg.close_on_exit == FORCE_ON ||
- (inst->cfg.close_on_exit == AUTO && exitcode == 0))
+ close_on_exit = conf_get_int(inst->conf, CONF_close_on_exit);
+ if (close_on_exit == FORCE_ON ||
+ (close_on_exit == AUTO && exitcode == 0))
gtk_main_quit(); /* just go */
if (inst->ldisc) {
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);
- }
- gtk_widget_show(inst->restartitem);
+ 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);
}
gtk_idle_remove(inst->term_exit_idle_id);
static gint timer_trigger(gpointer data)
{
- long now = GPOINTER_TO_INT(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,
- GINT_TO_POINTER(next));
+ 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));
}
/*
return FALSE;
}
-void timer_change_notify(long next)
+void timer_change_notify(unsigned long next)
{
long ticks;
ticks = 1; /* just in case */
timer_id = gtk_timeout_add(ticks, timer_trigger,
- GINT_TO_POINTER(next));
+ LONG_TO_GPOINTER(next));
}
void fd_input_func(gpointer data, gint sourcefd, GdkInputCondition condition)
void set_raw_mouse_mode(void *frontend, int activate)
{
struct gui_data *inst = (struct gui_data *)frontend;
- activate = activate && !inst->cfg.no_mouse_rep;
+ activate = activate && !conf_get_int(inst->conf, CONF_no_mouse_rep);
send_raw_mouse = activate;
update_mouseptr(inst);
}
offset_x = outer.width - inner.width;
offset_y = outer.height - inner.height;
- area_x = inst->font_width * w + 2*inst->cfg.window_border;
- area_y = inst->font_height * h + 2*inst->cfg.window_border;
+ area_x = inst->font_width * w + 2*inst->window_border;
+ area_y = inst->font_height * h + 2*inst->window_border;
/*
* Now we must set the size request on the drawing area back to
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) {
void palette_reset(void *frontend)
{
struct gui_data *inst = (struct gui_data *)frontend;
- /* This maps colour indices in inst->cfg to those used in inst->cols. */
+ /* This maps colour indices in inst->conf to those used in inst->cols. */
static const int ww[] = {
256, 257, 258, 259, 260, 261,
0, 8, 1, 9, 2, 10, 3, 11,
}
for (i = 0; i < NCFGCOLOURS; i++) {
- inst->cols[ww[i]].red = inst->cfg.colours[i][0] * 0x0101;
- inst->cols[ww[i]].green = inst->cfg.colours[i][1] * 0x0101;
- inst->cols[ww[i]].blue = inst->cfg.colours[i][2] * 0x0101;
+ inst->cols[ww[i]].red =
+ conf_get_int_int(inst->conf, CONF_colours, i*3+0) * 0x0101;
+ inst->cols[ww[i]].green =
+ conf_get_int_int(inst->conf, CONF_colours, i*3+1) * 0x0101;
+ inst->cols[ww[i]].blue =
+ conf_get_int_int(inst->conf, CONF_colours, i*3+2) * 0x0101;
}
for (i = 0; i < NEXTCOLOURS; i++) {
for (i = 0; i < NALLCOLOURS; i++) {
if (!success[i])
g_error("%s: couldn't allocate colour %d (#%02x%02x%02x)\n",
- appname, i, inst->cfg.colours[i][0],
- inst->cfg.colours[i][1], inst->cfg.colours[i][2]);
+ appname, i,
+ conf_get_int_int(inst->conf, CONF_colours, i*3+0),
+ conf_get_int_int(inst->conf, CONF_colours, i*3+1),
+ conf_get_int_int(inst->conf, CONF_colours, i*3+2));
}
/* Since Default Background may have changed, ensure that space
* if we aren't in direct-to-font mode using the D800 hack.
*/
if (!inst->direct_to_font) {
- wchar_t *tmp = data;
+ const wchar_t *tmp = data;
int tmplen = len;
XTextProperty tp;
char *list[1];
* is life.
*/
gtk_window_set_title(GTK_WINDOW(inst->window), inst->wintitle);
- if (!inst->cfg.win_name_always)
+ if (!conf_get_int(inst->conf, CONF_win_name_always))
gdk_window_set_icon_name(inst->window->window, inst->icontitle);
}
void set_title(void *frontend, char *title)
{
struct gui_data *inst = (struct gui_data *)frontend;
- strncpy(inst->wintitle, title, lenof(inst->wintitle));
- inst->wintitle[lenof(inst->wintitle)-1] = '\0';
+ sfree(inst->wintitle);
+ inst->wintitle = dupstr(title);
set_window_titles(inst);
}
void set_icon(void *frontend, char *title)
{
struct gui_data *inst = (struct gui_data *)frontend;
- strncpy(inst->icontitle, title, lenof(inst->icontitle));
- inst->icontitle[lenof(inst->icontitle)-1] = '\0';
+ sfree(inst->icontitle);
+ inst->icontitle = dupstr(title);
+ set_window_titles(inst);
+}
+
+void set_title_and_icon(void *frontend, char *title, char *icon)
+{
+ struct gui_data *inst = (struct gui_data *)frontend;
+ sfree(inst->wintitle);
+ inst->wintitle = dupstr(title);
+ sfree(inst->icontitle);
+ inst->icontitle = dupstr(icon);
set_window_titles(inst);
}
void set_sbar(void *frontend, int total, int start, int page)
{
struct gui_data *inst = (struct gui_data *)frontend;
- if (!inst->cfg.scrollbar)
+ if (!conf_get_int(inst->conf, CONF_scrollbar))
return;
inst->sbar_adjust->lower = 0;
inst->sbar_adjust->upper = total;
{
struct gui_data *inst = (struct gui_data *)data;
- if (!inst->cfg.scrollbar)
+ if (!conf_get_int(inst->conf, CONF_scrollbar))
return;
if (!inst->ignore_sbar)
term_scroll(inst->term, 1, (int)adj->value);
nfg = nbg;
nbg = t;
}
- if (inst->cfg.bold_colour && (attr & ATTR_BOLD)) {
+ if ((inst->bold_style & 2) && (attr & ATTR_BOLD)) {
if (nfg < 16) nfg |= 8;
else if (nfg >= 256) nfg |= 1;
}
- if (inst->cfg.bold_colour && (attr & ATTR_BLINK)) {
+ if ((inst->bold_style & 2) && (attr & ATTR_BLINK)) {
if (nbg < 16) nbg |= 8;
else if (nbg >= 256) nbg |= 1;
}
widefactor = 1;
}
- if ((attr & ATTR_BOLD) && !inst->cfg.bold_colour) {
+ if ((attr & ATTR_BOLD) && (inst->bold_style & 1)) {
bold = 1;
fontid |= 1;
} else {
{
GdkRectangle r;
- r.x = x*inst->font_width+inst->cfg.window_border;
- r.y = y*inst->font_height+inst->cfg.window_border;
+ r.x = x*inst->font_width+inst->window_border;
+ r.y = y*inst->font_height+inst->window_border;
r.width = rlen*widefactor*inst->font_width;
r.height = inst->font_height;
gdk_gc_set_clip_rectangle(gc, &r);
gdk_gc_set_foreground(gc, &inst->cols[nbg]);
gdk_draw_rectangle(inst->pixmap, gc, 1,
- x*inst->font_width+inst->cfg.window_border,
- y*inst->font_height+inst->cfg.window_border,
+ x*inst->font_width+inst->window_border,
+ y*inst->font_height+inst->window_border,
rlen*widefactor*inst->font_width, inst->font_height);
gdk_gc_set_foreground(gc, &inst->cols[nfg]);
- {
- gchar *gcs;
-
- /*
- * FIXME: this length is hardwired on the assumption that
- * conversions from wide to multibyte characters will
- * never generate more than 10 bytes for a single wide
- * character.
- */
- gcs = snewn(len*10+1, gchar);
-
- for (combining = 0; combining < ncombining; combining++) {
- int mblen = wc_to_mb(inst->fonts[fontid]->real_charset, 0,
- text + combining, len, gcs, len*10+1, ".",
- NULL, NULL);
- unifont_draw_text(inst->pixmap, gc, inst->fonts[fontid],
- x*inst->font_width+inst->cfg.window_border,
- y*inst->font_height+inst->cfg.window_border+inst->fonts[0]->ascent,
- gcs, mblen, widefactor > 1, bold, inst->font_width);
- }
-
- sfree(gcs);
+ for (combining = 0; combining < ncombining; combining++) {
+ unifont_draw_text(inst->pixmap, gc, inst->fonts[fontid],
+ x*inst->font_width+inst->window_border,
+ y*inst->font_height+inst->window_border+inst->fonts[0]->ascent,
+ text + combining, len, widefactor > 1,
+ bold, inst->font_width);
}
if (attr & ATTR_UNDER) {
int uheight = inst->fonts[0]->ascent + 1;
if (uheight >= inst->font_height)
uheight = inst->font_height - 1;
- gdk_draw_line(inst->pixmap, gc, x*inst->font_width+inst->cfg.window_border,
- y*inst->font_height + uheight + inst->cfg.window_border,
- (x+len)*widefactor*inst->font_width-1+inst->cfg.window_border,
- y*inst->font_height + uheight + inst->cfg.window_border);
+ gdk_draw_line(inst->pixmap, gc, x*inst->font_width+inst->window_border,
+ y*inst->font_height + uheight + inst->window_border,
+ (x+len)*widefactor*inst->font_width-1+inst->window_border,
+ y*inst->font_height + uheight + inst->window_border);
}
if ((lattr & LATTR_MODE) != LATTR_NORM) {
int i;
for (i = 0; i < len * widefactor * inst->font_width; i++) {
gdk_draw_pixmap(inst->pixmap, gc, inst->pixmap,
- x*inst->font_width+inst->cfg.window_border + 2*i,
- y*inst->font_height+inst->cfg.window_border,
- x*inst->font_width+inst->cfg.window_border + 2*i+1,
- y*inst->font_height+inst->cfg.window_border,
+ x*inst->font_width+inst->window_border + 2*i,
+ y*inst->font_height+inst->window_border,
+ x*inst->font_width+inst->window_border + 2*i+1,
+ y*inst->font_height+inst->window_border,
len * widefactor * inst->font_width - i, inst->font_height);
}
len *= 2;
dt = 1, db = 0;
for (i = 0; i < inst->font_height; i+=2) {
gdk_draw_pixmap(inst->pixmap, gc, inst->pixmap,
- x*inst->font_width+inst->cfg.window_border,
- y*inst->font_height+inst->cfg.window_border+dt*i+db,
- x*inst->font_width+inst->cfg.window_border,
- y*inst->font_height+inst->cfg.window_border+dt*(i+1),
+ x*inst->font_width+inst->window_border,
+ y*inst->font_height+inst->window_border+dt*i+db,
+ x*inst->font_width+inst->window_border,
+ y*inst->font_height+inst->window_border+dt*(i+1),
len * widefactor * inst->font_width, inst->font_height-i-1);
}
}
}
gdk_draw_pixmap(inst->area->window, gc, inst->pixmap,
- x*inst->font_width+inst->cfg.window_border,
- y*inst->font_height+inst->cfg.window_border,
- x*inst->font_width+inst->cfg.window_border,
- y*inst->font_height+inst->cfg.window_border,
+ x*inst->font_width+inst->window_border,
+ y*inst->font_height+inst->window_border,
+ x*inst->font_width+inst->window_border,
+ y*inst->font_height+inst->window_border,
len*widefactor*inst->font_width, inst->font_height);
}
passive = 1;
} else
passive = 0;
- if ((attr & TATTR_ACTCURS) && inst->cfg.cursor_type != 0) {
+ if ((attr & TATTR_ACTCURS) && inst->cursor_type != 0) {
attr &= ~TATTR_ACTCURS;
active = 1;
} else
len *= 2;
}
- if (inst->cfg.cursor_type == 0) {
+ if (inst->cursor_type == 0) {
/*
* An active block cursor will already have been done by
* the above do_text call, so we only need to do anything
if (passive) {
gdk_gc_set_foreground(gc, &inst->cols[261]);
gdk_draw_rectangle(inst->pixmap, gc, 0,
- x*inst->font_width+inst->cfg.window_border,
- y*inst->font_height+inst->cfg.window_border,
+ x*inst->font_width+inst->window_border,
+ y*inst->font_height+inst->window_border,
len*widefactor*inst->font_width-1, inst->font_height-1);
}
} else {
else
char_width = inst->font_width;
- if (inst->cfg.cursor_type == 1) {
+ if (inst->cursor_type == 1) {
uheight = inst->fonts[0]->ascent + 1;
if (uheight >= inst->font_height)
uheight = inst->font_height - 1;
- startx = x * inst->font_width + inst->cfg.window_border;
- starty = y * inst->font_height + inst->cfg.window_border + uheight;
+ startx = x * inst->font_width + inst->window_border;
+ starty = y * inst->font_height + inst->window_border + uheight;
dx = 1;
dy = 0;
length = len * widefactor * char_width;
int xadjust = 0;
if (attr & TATTR_RIGHTCURS)
xadjust = char_width - 1;
- startx = x * inst->font_width + inst->cfg.window_border + xadjust;
- starty = y * inst->font_height + inst->cfg.window_border;
+ startx = x * inst->font_width + inst->window_border + xadjust;
+ starty = y * inst->font_height + inst->window_border;
dx = 0;
dy = 1;
length = inst->font_height;
}
gdk_draw_pixmap(inst->area->window, gc, inst->pixmap,
- x*inst->font_width+inst->cfg.window_border,
- y*inst->font_height+inst->cfg.window_border,
- x*inst->font_width+inst->cfg.window_border,
- y*inst->font_height+inst->cfg.window_border,
+ x*inst->font_width+inst->window_border,
+ y*inst->font_height+inst->window_border,
+ x*inst->font_width+inst->window_border,
+ y*inst->font_height+inst->window_border,
len*widefactor*inst->font_width, inst->font_height);
+
+#if GTK_CHECK_VERSION(2,0,0)
+ {
+ GdkRectangle cursorrect;
+ cursorrect.x = x*inst->font_width+inst->window_border;
+ cursorrect.y = y*inst->font_height+inst->window_border;
+ cursorrect.width = len*widefactor*inst->font_width;
+ cursorrect.height = inst->font_height;
+ gtk_im_context_set_cursor_location(inst->imc, &cursorrect);
+ }
+#endif
}
GdkCursor *make_mouse_ptr(struct gui_data *inst, int cursor_val)
}
}
+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, Config *cfg)
+ struct gui_data *inst, Conf *conf)
{
int err = 0;
char *val;
p = "-title";
ret = cmdline_process_param(p, (argc > 1 ? argv[1] : NULL),
- do_everything ? 1 : -1, cfg);
+ do_everything ? 1 : -1, conf);
if (ret == -2) {
cmdline_error("option \"%s\" requires an argument", p);
}
if (!strcmp(p, "-fn") || !strcmp(p, "-font")) {
+ FontSpec *fs;
EXPECTS_ARG;
SECOND_PASS_ONLY;
- strncpy(cfg->font.name, val, sizeof(cfg->font.name));
- cfg->font.name[sizeof(cfg->font.name)-1] = '\0';
+ fs = fontspec_new(val);
+ conf_set_fontspec(conf, CONF_font, fs);
+ fontspec_free(fs);
} else if (!strcmp(p, "-fb")) {
+ FontSpec *fs;
EXPECTS_ARG;
SECOND_PASS_ONLY;
- strncpy(cfg->boldfont.name, val, sizeof(cfg->boldfont.name));
- cfg->boldfont.name[sizeof(cfg->boldfont.name)-1] = '\0';
+ fs = fontspec_new(val);
+ conf_set_fontspec(conf, CONF_boldfont, fs);
+ fontspec_free(fs);
} else if (!strcmp(p, "-fw")) {
+ FontSpec *fs;
EXPECTS_ARG;
SECOND_PASS_ONLY;
- strncpy(cfg->widefont.name, val, sizeof(cfg->widefont.name));
- cfg->widefont.name[sizeof(cfg->widefont.name)-1] = '\0';
+ fs = fontspec_new(val);
+ conf_set_fontspec(conf, CONF_widefont, fs);
+ fontspec_free(fs);
} else if (!strcmp(p, "-fwb")) {
+ FontSpec *fs;
EXPECTS_ARG;
SECOND_PASS_ONLY;
- strncpy(cfg->wideboldfont.name, val, sizeof(cfg->wideboldfont.name));
- cfg->wideboldfont.name[sizeof(cfg->wideboldfont.name)-1] = '\0';
+ fs = fontspec_new(val);
+ conf_set_fontspec(conf, CONF_wideboldfont, fs);
+ fontspec_free(fs);
} else if (!strcmp(p, "-cs")) {
EXPECTS_ARG;
SECOND_PASS_ONLY;
- strncpy(cfg->line_codepage, val, sizeof(cfg->line_codepage));
- cfg->line_codepage[sizeof(cfg->line_codepage)-1] = '\0';
+ conf_set_str(conf, CONF_line_codepage, val);
} else if (!strcmp(p, "-geometry")) {
int flags, x, y;
flags = XParseGeometry(val, &x, &y, &w, &h);
if (flags & WidthValue)
- cfg->width = (int)w;
+ conf_set_int(conf, CONF_width, w);
if (flags & HeightValue)
- cfg->height = (int)h;
+ conf_set_int(conf, CONF_height, h);
if (flags & (XValue | YValue)) {
inst->xpos = x;
} else if (!strcmp(p, "-sl")) {
EXPECTS_ARG;
SECOND_PASS_ONLY;
- cfg->savelines = atoi(val);
+ conf_set_int(conf, CONF_savelines, atoi(val));
} else if (!strcmp(p, "-fg") || !strcmp(p, "-bg") ||
!strcmp(p, "-bfg") || !strcmp(p, "-bbg") ||
!strcmp(p, "-cfg") ? 4 :
!strcmp(p, "-cbg") ? 5 : -1);
assert(index != -1);
- cfg->colours[index][0] = col.red / 256;
- cfg->colours[index][1] = col.green / 256;
- cfg->colours[index][2] = col.blue / 256;
+ conf_set_int_int(conf, CONF_colours, index*3+0, col.red / 256);
+ conf_set_int_int(conf, CONF_colours, index*3+1,col.green/ 256);
+ conf_set_int_int(conf, CONF_colours, index*3+2, col.blue/ 256);
}
} else if (use_pty_argv && !strcmp(p, "-e")) {
} else if (!strcmp(p, "-title")) {
EXPECTS_ARG;
SECOND_PASS_ONLY;
- strncpy(cfg->wintitle, val, sizeof(cfg->wintitle));
- cfg->wintitle[sizeof(cfg->wintitle)-1] = '\0';
+ conf_set_str(conf, CONF_wintitle, val);
} else if (!strcmp(p, "-log")) {
+ Filename *fn;
EXPECTS_ARG;
SECOND_PASS_ONLY;
- strncpy(cfg->logfilename.path, val, sizeof(cfg->logfilename.path));
- cfg->logfilename.path[sizeof(cfg->logfilename.path)-1] = '\0';
- cfg->logtype = LGTYP_DEBUG;
+ fn = filename_from_str(val);
+ conf_set_filename(conf, CONF_logfilename, fn);
+ conf_set_int(conf, CONF_logtype, LGTYP_DEBUG);
+ filename_free(fn);
} else if (!strcmp(p, "-ut-") || !strcmp(p, "+ut")) {
SECOND_PASS_ONLY;
- cfg->stamp_utmp = 0;
+ conf_set_int(conf, CONF_stamp_utmp, 0);
} else if (!strcmp(p, "-ut")) {
SECOND_PASS_ONLY;
- cfg->stamp_utmp = 1;
+ conf_set_int(conf, CONF_stamp_utmp, 1);
} else if (!strcmp(p, "-ls-") || !strcmp(p, "+ls")) {
SECOND_PASS_ONLY;
- cfg->login_shell = 0;
+ conf_set_int(conf, CONF_login_shell, 0);
} else if (!strcmp(p, "-ls")) {
SECOND_PASS_ONLY;
- cfg->login_shell = 1;
+ conf_set_int(conf, CONF_login_shell, 1);
} else if (!strcmp(p, "-nethack")) {
SECOND_PASS_ONLY;
- cfg->nethack_keypad = 1;
+ conf_set_int(conf, CONF_nethack_keypad, 1);
} else if (!strcmp(p, "-sb-") || !strcmp(p, "+sb")) {
SECOND_PASS_ONLY;
- cfg->scrollbar = 0;
+ conf_set_int(conf, CONF_scrollbar, 0);
} else if (!strcmp(p, "-sb")) {
SECOND_PASS_ONLY;
- cfg->scrollbar = 0;
+ conf_set_int(conf, CONF_scrollbar, 1);
} else if (!strcmp(p, "-name")) {
EXPECTS_ARG;
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);
} else if(p[0] != '-' && (!do_everything ||
- process_nonoption_arg(p, cfg,
+ process_nonoption_arg(p, conf,
allow_launch))) {
/* do nothing */
gdk_input_remove(id);
}
-void setup_fonts_ucs(struct gui_data *inst)
-{
- 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]);
-
- inst->fonts[0] = unifont_create(inst->area, inst->cfg.font.name,
- FALSE, FALSE,
- inst->cfg.shadowboldoffset,
- inst->cfg.shadowbold);
- if (!inst->fonts[0]) {
- fprintf(stderr, "%s: unable to load font \"%s\"\n", appname,
- inst->cfg.font.name);
- exit(1);
+int frontend_net_pending_error_idle_id;
+int frontend_got_net_pending_errors = FALSE;
+gboolean frontend_net_pending_errors(gpointer data)
+{
+ net_pending_errors();
+ gtk_idle_remove(frontend_net_pending_error_idle_id);
+ frontend_got_net_pending_errors = FALSE;
+ return FALSE;
+}
+void frontend_net_error_pending(void)
+{
+ if (!frontend_got_net_pending_errors) {
+ frontend_got_net_pending_errors = TRUE;
+ frontend_net_pending_error_idle_id =
+ gtk_idle_add(frontend_net_pending_errors, NULL);
+ }
+}
+
+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;
+ unifont *fonts[4];
+ int i;
+
+ fs = conf_get_fontspec(inst->conf, CONF_font);
+ fonts[0] = multifont_create(inst->area, fs->name, FALSE, FALSE,
+ shadowboldoffset, shadowbold);
+ if (!fonts[0]) {
+ return dupprintf("unable to load font \"%s\"", fs->name);
}
- if (inst->cfg.shadowbold || !inst->cfg.boldfont.name[0]) {
- inst->fonts[1] = NULL;
+ fs = conf_get_fontspec(inst->conf, CONF_boldfont);
+ if (shadowbold || !fs->name[0]) {
+ fonts[1] = NULL;
} else {
- inst->fonts[1] = unifont_create(inst->area, inst->cfg.boldfont.name,
- FALSE, TRUE,
- inst->cfg.shadowboldoffset,
- inst->cfg.shadowbold);
- if (!inst->fonts[1]) {
- fprintf(stderr, "%s: unable to load bold font \"%s\"\n", appname,
- inst->cfg.boldfont.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);
}
}
- if (inst->cfg.widefont.name[0]) {
- inst->fonts[2] = unifont_create(inst->area, inst->cfg.widefont.name,
- TRUE, FALSE,
- inst->cfg.shadowboldoffset,
- inst->cfg.shadowbold);
- if (!inst->fonts[2]) {
- fprintf(stderr, "%s: unable to load wide font \"%s\"\n", appname,
- inst->cfg.widefont.name);
- exit(1);
+ fs = conf_get_fontspec(inst->conf, CONF_widefont);
+ if (fs->name[0]) {
+ 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;
}
- if (inst->cfg.shadowbold || !inst->cfg.wideboldfont.name[0]) {
- inst->fonts[3] = NULL;
+ fs = conf_get_fontspec(inst->conf, CONF_wideboldfont);
+ if (shadowbold || !fs->name[0]) {
+ fonts[3] = NULL;
} else {
- inst->fonts[3] = unifont_create(inst->area,
- inst->cfg.wideboldfont.name, TRUE,
- TRUE, inst->cfg.shadowboldoffset,
- inst->cfg.shadowbold);
- if (!inst->fonts[3]) {
- fprintf(stderr, "%s: unable to load wide bold font \"%s\"\n", appname,
- inst->cfg.boldfont.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;
- inst->direct_to_font = init_ucs(&inst->ucsdata, inst->cfg.line_codepage,
- inst->cfg.utf8_override,
+ inst->direct_to_font = init_ucs(&inst->ucsdata,
+ conf_get_str(inst->conf, CONF_line_codepage),
+ conf_get_int(inst->conf, CONF_utf8_override),
inst->fonts[0]->public_charset,
- inst->cfg.vtmode);
+ conf_get_int(inst->conf, CONF_vtmode));
+
+ return NULL;
}
void set_geom_hints(struct gui_data *inst)
{
GdkGeometry geom;
- geom.min_width = inst->font_width + 2*inst->cfg.window_border;
- geom.min_height = inst->font_height + 2*inst->cfg.window_border;
+ geom.min_width = inst->font_width + 2*inst->window_border;
+ geom.min_height = inst->font_height + 2*inst->window_border;
geom.max_width = geom.max_height = -1;
- geom.base_width = 2*inst->cfg.window_border;
- geom.base_height = 2*inst->cfg.window_border;
+ geom.base_width = 2*inst->window_border;
+ geom.base_height = 2*inst->window_border;
geom.width_inc = inst->font_width;
geom.height_inc = inst->font_height;
geom.min_aspect = geom.max_aspect = 0;
void change_settings_menuitem(GtkMenuItem *item, gpointer data)
{
- /* This maps colour indices in inst->cfg to those used in inst->cols. */
+ /* This maps colour indices in inst->conf to those used in inst->cols. */
static const int ww[] = {
256, 257, 258, 259, 260, 261,
0, 8, 1, 9, 2, 10, 3, 11,
4, 12, 5, 13, 6, 14, 7, 15
};
struct gui_data *inst = (struct gui_data *)data;
- char *title = dupcat(appname, " Reconfiguration", NULL);
- Config cfg2, oldcfg;
- int i, need_size;
+ char *title;
+ Conf *oldconf, *newconf;
+ int i, j, need_size;
assert(lenof(ww) == NCFGCOLOURS);
else
inst->reconfiguring = TRUE;
- cfg2 = inst->cfg; /* structure copy */
+ title = dupcat(appname, " Reconfiguration", NULL);
- if (do_config_box(title, &cfg2, 1,
- inst->back?inst->back->cfg_info(inst->backhandle):0)) {
+ oldconf = inst->conf;
+ newconf = conf_copy(inst->conf);
- oldcfg = inst->cfg; /* structure copy */
- inst->cfg = cfg2; /* structure copy */
+ if (do_config_box(title, newconf, 1,
+ inst->back?inst->back->cfg_info(inst->backhandle):0)) {
+ inst->conf = newconf;
/* Pass new config data to the logging module */
- log_reconfig(inst->logctx, &cfg2);
+ log_reconfig(inst->logctx, inst->conf);
/*
* Flush the line discipline's edit buffer in the case
* where local editing has just been disabled.
*/
- 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, &cfg2);
+ term_reconfig(inst->term, inst->conf);
/* Pass new config data to the back end */
if (inst->back)
- inst->back->reconfig(inst->backhandle, &cfg2);
+ inst->back->reconfig(inst->backhandle, inst->conf);
+
+ cache_conf_values(inst);
/*
- * Just setting inst->cfg is sufficient to cause colour
+ * Just setting inst->conf is sufficient to cause colour
* setting changes to appear on the next ESC]R palette
* reset. But we should also check whether any colour
- * settings have been changed, and revert the ones that
- * have to the new default, on the assumption that the user
- * is most likely to want an immediate update.
+ * settings have been changed, and revert the ones that have
+ * to the new default, on the assumption that the user is
+ * most likely to want an immediate update.
*/
for (i = 0; i < NCFGCOLOURS; i++) {
- if (oldcfg.colours[i][0] != cfg2.colours[i][0] ||
- oldcfg.colours[i][1] != cfg2.colours[i][1] ||
- oldcfg.colours[i][2] != cfg2.colours[i][2]) {
- real_palette_set(inst, ww[i], cfg2.colours[i][0],
- cfg2.colours[i][1],
- cfg2.colours[i][2]);
+ for (j = 0; j < 3; j++)
+ if (conf_get_int_int(oldconf, CONF_colours, i*3+j) !=
+ conf_get_int_int(newconf, CONF_colours, i*3+j))
+ break;
+ if (j < 3) {
+ real_palette_set(inst, ww[i],
+ conf_get_int_int(newconf,CONF_colours,i*3+0),
+ conf_get_int_int(newconf,CONF_colours,i*3+1),
+ conf_get_int_int(newconf,CONF_colours,i*3+2));
/*
* If the default background has changed, we must
* 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);
}
* If the scrollbar needs to be shown, hidden, or moved
* from one end to the other of the window, do so now.
*/
- if (oldcfg.scrollbar != cfg2.scrollbar) {
- if (cfg2.scrollbar)
+ if (conf_get_int(oldconf, CONF_scrollbar) !=
+ conf_get_int(newconf, CONF_scrollbar)) {
+ if (conf_get_int(newconf, CONF_scrollbar))
gtk_widget_show(inst->sbar);
else
gtk_widget_hide(inst->sbar);
}
- if (oldcfg.scrollbar_on_left != cfg2.scrollbar_on_left) {
+ if (conf_get_int(oldconf, CONF_scrollbar_on_left) !=
+ conf_get_int(newconf, CONF_scrollbar_on_left)) {
gtk_box_reorder_child(inst->hbox, inst->sbar,
- cfg2.scrollbar_on_left ? 0 : 1);
+ conf_get_int(newconf, CONF_scrollbar_on_left)
+ ? 0 : 1);
}
/*
* Change the window title, if required.
*/
- if (strcmp(oldcfg.wintitle, cfg2.wintitle))
- set_title(inst, cfg2.wintitle);
+ if (strcmp(conf_get_str(oldconf, CONF_wintitle),
+ conf_get_str(newconf, CONF_wintitle)))
+ set_title(inst, conf_get_str(newconf, CONF_wintitle));
set_window_titles(inst);
/*
* Redo the whole tangled fonts and Unicode mess if
* necessary.
*/
- if (strcmp(oldcfg.font.name, cfg2.font.name) ||
- strcmp(oldcfg.boldfont.name, cfg2.boldfont.name) ||
- strcmp(oldcfg.widefont.name, cfg2.widefont.name) ||
- strcmp(oldcfg.wideboldfont.name, cfg2.wideboldfont.name) ||
- strcmp(oldcfg.line_codepage, cfg2.line_codepage) ||
- oldcfg.vtmode != cfg2.vtmode ||
- oldcfg.shadowbold != cfg2.shadowbold) {
- setup_fonts_ucs(inst);
- need_size = 1;
- } else
- need_size = 0;
+ 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,
+ conf_get_fontspec(newconf, CONF_boldfont)->name) ||
+ strcmp(conf_get_fontspec(oldconf, CONF_widefont)->name,
+ conf_get_fontspec(newconf, CONF_widefont)->name) ||
+ strcmp(conf_get_fontspec(oldconf, CONF_wideboldfont)->name,
+ conf_get_fontspec(newconf, CONF_wideboldfont)->name) ||
+ strcmp(conf_get_str(oldconf, CONF_line_codepage),
+ conf_get_str(newconf, CONF_line_codepage)) ||
+ conf_get_int(oldconf, CONF_utf8_override) !=
+ conf_get_int(newconf, CONF_utf8_override) ||
+ conf_get_int(oldconf, CONF_vtmode) !=
+ conf_get_int(newconf, CONF_vtmode) ||
+ conf_get_int(oldconf, CONF_shadowbold) !=
+ conf_get_int(newconf, CONF_shadowbold) ||
+ conf_get_int(oldconf, CONF_shadowboldoffset) !=
+ conf_get_int(newconf, CONF_shadowboldoffset)) {
+ 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.
*/
- if (oldcfg.width != cfg2.width || oldcfg.height != cfg2.height ||
- oldcfg.window_border != cfg2.window_border || need_size) {
+ if (conf_get_int(oldconf, CONF_width) !=
+ conf_get_int(newconf, CONF_width) ||
+ conf_get_int(oldconf, CONF_height) !=
+ conf_get_int(newconf, CONF_height) ||
+ conf_get_int(oldconf, CONF_window_border) !=
+ conf_get_int(newconf, CONF_window_border) ||
+ need_size) {
set_geom_hints(inst);
- request_resize(inst, cfg2.width, cfg2.height);
+ request_resize(inst, conf_get_int(newconf, CONF_width),
+ conf_get_int(newconf, CONF_height));
} else {
/*
* The above will have caused a call to term_size() for
* happened and we will need an explicit term_size()
* here.
*/
- if (oldcfg.savelines != cfg2.savelines)
+ if (conf_get_int(oldconf, CONF_savelines) !=
+ conf_get_int(newconf, CONF_savelines))
term_size(inst->term, inst->term->rows, inst->term->cols,
- cfg2.savelines);
+ conf_get_int(newconf, CONF_savelines));
}
term_invalidate(inst->term);
* border has been redrawn as well as the text area.
*/
gtk_widget_queue_draw(inst->area);
+
+ conf_free(oldconf);
+ } else {
+ conf_free(newconf);
}
sfree(title);
inst->reconfiguring = FALSE;
pid = fork();
if (pid < 0) {
perror("fork");
+ sfree(args);
return;
}
} else {
int status;
+ sfree(args);
waitpid(pid, &status, 0);
}
{
struct gui_data *inst = (struct gui_data *)gdata;
/*
- * For this feature we must marshal cfg and (possibly) pty_argv
+ * For this feature we must marshal conf and (possibly) pty_argv
* into a byte stream, create a pipe, and send this byte stream
* to the child through the pipe.
*/
- int i, ret, size;
+ int i, ret, sersize, size;
char *data;
char option[80];
int pipefd[2];
return;
}
- size = sizeof(inst->cfg);
+ size = sersize = conf_serialised_size(inst->conf);
if (use_pty_argv && pty_argv) {
for (i = 0; pty_argv[i]; i++)
size += strlen(pty_argv[i]) + 1;
}
data = snewn(size, char);
- memcpy(data, &inst->cfg, sizeof(inst->cfg));
+ conf_serialise(inst->conf, data);
if (use_pty_argv && pty_argv) {
- int p = sizeof(inst->cfg);
+ int p = sersize;
for (i = 0; pty_argv[i]; i++) {
strcpy(data + p, pty_argv[i]);
p += strlen(pty_argv[i]) + 1;
}
sprintf(option, "---[%d,%d]", pipefd[0], size);
- fcntl(pipefd[0], F_SETFD, 0);
+ noncloexec(pipefd[0]);
fork_and_exec_self(inst, pipefd[1], option, NULL);
close(pipefd[0]);
sfree(data);
}
-int read_dupsession_data(struct gui_data *inst, Config *cfg, char *arg)
+int read_dupsession_data(struct gui_data *inst, Conf *conf, char *arg)
{
- int fd, i, ret, size;
+ int fd, i, ret, size, size_used;
char *data;
if (sscanf(arg, "---[%d,%d]", &fd, &size) != 2) {
exit(1);
}
- memcpy(cfg, data, sizeof(Config));
- if (use_pty_argv && size > sizeof(Config)) {
+ size_used = conf_deserialise(conf, data, size);
+ if (use_pty_argv && size > size_used) {
int n = 0;
- i = sizeof(Config);
+ i = size_used;
while (i < size) {
while (i < size && data[i]) i++;
if (i >= size) {
pty_argv = snewn(n+1, char *);
pty_argv[n] = NULL;
n = 0;
- i = sizeof(Config);
+ i = size_used;
while (i < size) {
char *p = data + i;
while (i < size && data[i]) i++;
}
}
+ sfree(data);
+
return 0;
}
static void start_backend(struct gui_data *inst)
{
- extern Backend *select_backend(Config *cfg);
+ extern Backend *select_backend(Conf *conf);
char *realhost;
const char *error;
+ char *s;
- inst->back = select_backend(&inst->cfg);
+ inst->back = select_backend(inst->conf);
error = inst->back->init((void *)inst, &inst->backhandle,
- &inst->cfg, inst->cfg.host, inst->cfg.port,
- &realhost, inst->cfg.tcp_nodelay,
- inst->cfg.tcp_keepalives);
+ inst->conf,
+ conf_get_str(inst->conf, CONF_host),
+ conf_get_int(inst->conf, CONF_port),
+ &realhost,
+ conf_get_int(inst->conf, CONF_tcp_nodelay),
+ conf_get_int(inst->conf, CONF_tcp_keepalives));
if (error) {
char *msg = dupprintf("Unable to open connection to %s:\n%s",
- inst->cfg.host, error);
+ conf_get_str(inst->conf, CONF_host), error);
inst->exited = TRUE;
fatal_message_box(inst->window, msg);
sfree(msg);
exit(0);
}
- if (inst->cfg.wintitle[0]) {
- set_title(inst, inst->cfg.wintitle);
- set_icon(inst, inst->cfg.wintitle);
+ s = conf_get_str(inst->conf, CONF_wintitle);
+ if (s[0]) {
+ set_title_and_icon(inst, s, s);
} else {
char *title = make_default_wintitle(realhost);
- set_title(inst, title);
- set_icon(inst, title);
+ set_title_and_icon(inst, title, title);
sfree(title);
}
sfree(realhost);
term_provide_resize_fn(inst->term, inst->back->size, inst->backhandle);
inst->ldisc =
- ldisc_create(&inst->cfg, inst->term, inst->back, inst->backhandle,
+ ldisc_create(inst->conf, inst->term, inst->back, inst->backhandle,
inst);
- gtk_widget_hide(inst->restartitem);
+ gtk_widget_set_sensitive(inst->restartitem, FALSE);
}
int pt_main(int argc, char **argv)
{
- extern int cfgbox(Config *cfg);
+ extern int cfgbox(Conf *conf);
struct gui_data *inst;
+ setlocale(LC_CTYPE, "");
+
/*
* Create an instance structure and initialise to zeroes
*/
memset(inst, 0, sizeof(*inst));
inst->alt_keycode = -1; /* this one needs _not_ to be zero */
inst->busy_status = BUSY_NOT;
+ inst->conf = conf_new();
+ inst->wintitle = inst->icontitle = NULL;
/* defer any child exit handling until we're ready to deal with
* it */
}
if (argc > 1 && !strncmp(argv[1], "---", 3)) {
- read_dupsession_data(inst, &inst->cfg, argv[1]);
+ 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
* that (e.g., a hostname is specified on the command-line). */
int allow_launch = FALSE;
- if (do_cmdline(argc, argv, 0, &allow_launch, inst, &inst->cfg))
+ if (do_cmdline(argc, argv, 0, &allow_launch, inst, inst->conf))
exit(1); /* pre-defaults pass to get -class */
- do_defaults(NULL, &inst->cfg);
- if (do_cmdline(argc, argv, 1, &allow_launch, inst, &inst->cfg))
+ do_defaults(NULL, inst->conf);
+ if (do_cmdline(argc, argv, 1, &allow_launch, inst, inst->conf))
exit(1); /* post-defaults, do everything */
- cmdline_run_saved(&inst->cfg);
+ cmdline_run_saved(inst->conf);
if (loaded_session)
allow_launch = TRUE;
- if ((!allow_launch || !cfg_launchable(&inst->cfg)) &&
- !cfgbox(&inst->cfg))
+ if ((!allow_launch || !conf_launchable(inst->conf)) &&
+ !cfgbox(inst->conf))
exit(0); /* config box hit Cancel */
}
inst->area = gtk_drawing_area_new();
- setup_fonts_ucs(inst);
+#if GTK_CHECK_VERSION(2,0,0)
+ inst->imc = gtk_im_multicontext_new();
+#endif
+
+ {
+ 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);
+ {
+ const char *winclass = conf_get_str(inst->conf, CONF_winclass);
+ if (*winclass)
+ gtk_window_set_wmclass(GTK_WINDOW(inst->window),
+ winclass, winclass);
+ }
/*
* Set up the colour map.
*/
palette_reset(inst);
- inst->width = inst->cfg.width;
- inst->height = inst->cfg.height;
+ inst->width = conf_get_int(inst->conf, CONF_width);
+ inst->height = conf_get_int(inst->conf, CONF_height);
+ cache_conf_values(inst);
gtk_drawing_area_size(GTK_DRAWING_AREA(inst->area),
- inst->font_width * inst->cfg.width + 2*inst->cfg.window_border,
- inst->font_height * inst->cfg.height + 2*inst->cfg.window_border);
+ inst->font_width * inst->width + 2*inst->window_border,
+ inst->font_height * inst->height + 2*inst->window_border);
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));
* unwanted, so we can pop it up quickly if it suddenly becomes
* desirable.
*/
- if (inst->cfg.scrollbar_on_left)
+ if (conf_get_int(inst->conf, CONF_scrollbar_on_left))
gtk_box_pack_start(inst->hbox, inst->sbar, FALSE, FALSE, 0);
gtk_box_pack_start(inst->hbox, inst->area, TRUE, TRUE, 0);
- if (!inst->cfg.scrollbar_on_left)
+ if (!conf_get_int(inst->conf, CONF_scrollbar_on_left))
gtk_box_pack_start(inst->hbox, inst->sbar, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(inst->window), GTK_WIDGET(inst->hbox));
set_geom_hints(inst);
gtk_widget_show(inst->area);
- if (inst->cfg.scrollbar)
+ if (conf_get_int(inst->conf, CONF_scrollbar))
gtk_widget_show(inst->sbar);
else
gtk_widget_hide(inst->sbar);
GTK_SIGNAL_FUNC(selection_get), inst);
gtk_signal_connect(GTK_OBJECT(inst->area), "selection_clear_event",
GTK_SIGNAL_FUNC(selection_clear), inst);
- if (inst->cfg.scrollbar)
+#if GTK_CHECK_VERSION(2,0,0)
+ g_signal_connect(G_OBJECT(inst->imc), "commit",
+ G_CALLBACK(input_method_commit_event), inst);
+#endif
+ if (conf_get_int(inst->conf, CONF_scrollbar))
gtk_signal_connect(GTK_OBJECT(inst->sbar_adjust), "value_changed",
GTK_SIGNAL_FUNC(scrollbar_moved), inst);
gtk_widget_add_events(GTK_WIDGET(inst->area),
inst->menu = gtk_menu_new();
-#define MKMENUITEM(title, func) do { \
- menuitem = title ? gtk_menu_item_new_with_label(title) : \
- gtk_menu_item_new(); \
- gtk_container_add(GTK_CONTAINER(inst->menu), menuitem); \
- gtk_widget_show(menuitem); \
- if (func != NULL) \
- gtk_signal_connect(GTK_OBJECT(menuitem), "activate", \
- GTK_SIGNAL_FUNC(func), inst); \
-} while (0)
+#define MKMENUITEM(title, func) do \
+ { \
+ menuitem = gtk_menu_item_new_with_label(title); \
+ gtk_container_add(GTK_CONTAINER(inst->menu), menuitem); \
+ gtk_widget_show(menuitem); \
+ gtk_signal_connect(GTK_OBJECT(menuitem), "activate", \
+ GTK_SIGNAL_FUNC(func), inst); \
+ } while (0)
+
+#define MKSUBMENU(title) do \
+ { \
+ menuitem = gtk_menu_item_new_with_label(title); \
+ gtk_container_add(GTK_CONTAINER(inst->menu), menuitem); \
+ gtk_widget_show(menuitem); \
+ } while (0)
+
+#define MKSEP() do \
+ { \
+ menuitem = gtk_menu_item_new(); \
+ gtk_container_add(GTK_CONTAINER(inst->menu), menuitem); \
+ gtk_widget_show(menuitem); \
+ } while (0)
+
if (new_session)
- MKMENUITEM("New Session", new_session_menuitem);
+ MKMENUITEM("New Session...", new_session_menuitem);
MKMENUITEM("Restart Session", restart_session_menuitem);
inst->restartitem = menuitem;
- gtk_widget_hide(inst->restartitem);
+ gtk_widget_set_sensitive(inst->restartitem, FALSE);
MKMENUITEM("Duplicate Session", dup_session_menuitem);
if (saved_sessions) {
inst->sessionsmenu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem),
inst->sessionsmenu);
}
- MKMENUITEM(NULL, NULL);
- MKMENUITEM("Change Settings", change_settings_menuitem);
- MKMENUITEM(NULL, NULL);
+ MKSEP();
+ MKMENUITEM("Change Settings...", change_settings_menuitem);
+ MKSEP();
if (use_event_log)
MKMENUITEM("Event Log", event_log_menuitem);
- MKMENUITEM("Special Commands", NULL);
+ MKSUBMENU("Special Commands");
inst->specialsmenu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), inst->specialsmenu);
inst->specialsitem1 = menuitem;
- MKMENUITEM(NULL, NULL);
+ MKSEP();
inst->specialsitem2 = menuitem;
gtk_widget_hide(inst->specialsitem1);
gtk_widget_hide(inst->specialsitem2);
MKMENUITEM("Clear Scrollback", clear_scrollback_menuitem);
MKMENUITEM("Reset Terminal", reset_terminal_menuitem);
MKMENUITEM("Copy All", copy_all_menuitem);
- MKMENUITEM(NULL, NULL);
+ MKSEP();
s = dupcat("About ", appname, NULL);
MKMENUITEM(s, about_menuitem);
sfree(s);
#undef MKMENUITEM
+#undef MKSUBMENU
+#undef MKSEP
}
inst->textcursor = make_mouse_ptr(inst, GDK_XTERM);
inst->eventlogstuff = eventlogstuff_new();
- inst->term = term_init(&inst->cfg, &inst->ucsdata, inst);
- inst->logctx = log_init(inst, &inst->cfg);
+ inst->term = term_init(inst->conf, &inst->ucsdata, inst);
+ inst->logctx = log_init(inst, inst->conf);
term_provide_logctx(inst->term, inst->logctx);
uxsel_init();
- term_size(inst->term, inst->cfg.height, inst->cfg.width, inst->cfg.savelines);
+ term_size(inst->term, inst->height, inst->width,
+ conf_get_int(inst->conf, CONF_savelines));
start_backend(inst);