#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 CAT2(x,y) x ## y
#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;
- GdkFont *fonts[4]; /* normal, bold, wide, widebold */
- struct {
- int charset;
- int is_wide;
- } fontinfo[4];
+#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;
GdkColor cols[NALLCOLOURS];
int mouseptr_visible;
int busy_status;
guint term_paste_idle_id;
+ 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, "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)
{
+ if (!strcmp(name, "SerialLine"))
+ return dupstr("/dev/ttyS0");
return NULL;
}
return def;
}
+/* Dummy routine, only required in plink. */
void ldisc_update(void *frontend, int echo, int edit)
{
- /*
- * This is a stub in pterm. If I ever produce a Unix
- * command-line ssh/telnet/rlogin client (i.e. a port of plink)
- * then it will require some termios manoeuvring analogous to
- * that in the Windows plink.c, but here it's meaningless.
- */
+}
+
+char *get_ttymode(void *frontend, const char *mode)
+{
+ struct gui_data *inst = (struct gui_data *)frontend;
+ return term_get_ttymode(inst->term, mode);
}
int from_backend(void *frontend, int is_stderr, const char *data, int len)
return term_data(inst->term, is_stderr, data, len);
}
+int from_backend_untrusted(void *frontend, const char *data, int len)
+{
+ struct gui_data *inst = (struct gui_data *)frontend;
+ 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;
+ int ret;
+ ret = cmdline_get_passwd_input(p, in, inlen);
+ if (ret == -1)
+ ret = term_get_userpass_input(inst->term, p, in, inlen);
+ return ret;
+}
+
void logevent(void *frontend, const char *string)
{
struct gui_data *inst = (struct gui_data *)frontend;
*/
#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));
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;
}
gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
struct gui_data *inst = (struct gui_data *)data;
- char output[32];
+ char output[256];
wchar_t ucsoutput[2];
- int ucsval, start, end, special, use_ucsoutput;
+ int ucsval, start, end, special, output_charset, use_ucsoutput;
+ int nethack_mode, app_keypad_mode;
/* Remember the timestamp. */
inst->input_event_time = event->time;
/* By default, nothing is generated. */
end = start = 0;
special = use_ucsoutput = FALSE;
+ output_charset = CS_ISO8859_1;
/*
* If Alt is being released after typing an Alt+numberpad
* 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
- 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';
- strncpy(output+1, event->string, 31);
- if (!*event->string &&
+#if !GTK_CHECK_VERSION(2,0,0)
+ /*
+ * In vanilla X, and hence also GDK 1.2, the string received
+ * as part of a keyboard event is assumed to be in
+ * ISO-8859-1. (Seems woefully shortsighted in i18n terms,
+ * but it's true: see the man page for XLookupString(3) for
+ * confirmation.)
+ */
+ 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.
+ *
+ * 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.
+ * (In fact I convert straight back to UTF-8 from
+ * wide-character Unicode, for the sake of simplicity: that
+ * way we can still use exactly the same code to manipulate
+ * the string, such as prefixing ESC.)
+ */
+ output_charset = CS_UTF8;
+ {
+ wchar_t widedata[32];
+ const wchar_t *wp;
+ int wlen;
+ int ulen;
+
+ wlen = mb_to_wc(DEFAULT_CODEPAGE, 0,
+ event->string, strlen(event->string),
+ widedata, lenof(widedata)-1);
+
+ wp = widedata;
+ ulen = charset_from_unicode(&wp, &wlen, output+1, lenof(output)-2,
+ CS_UTF8, NULL, NULL, 0);
+ output[1+ulen] = '\0';
+ }
+#endif
+
+ if (!output[1] &&
(ucsval = keysym_to_unicode(event->keyval)) >= 0) {
ucsoutput[0] = '\033';
ucsoutput[1] = ucsval;
use_ucsoutput = TRUE;
end = 2;
} else {
- output[31] = '\0';
+ output[lenof(output)-1] = '\0';
end = strlen(output);
}
if (event->state & GDK_MOD1_MASK) {
start = 1;
/* Control-` is the same as Control-\ (unless gtk has a better idea) */
- if (!event->string[0] && event->keyval == '`' &&
+ if (!output[1] && event->keyval == '`' &&
(event->state & GDK_CONTROL_MASK)) {
output[1] = '\x1C';
use_ucsoutput = FALSE;
end = 2;
}
- /* Control-Break is the same as Control-C */
+ /* Control-Break sends a Break special to the backend */
if (event->keyval == GDK_Break &&
(event->state & GDK_CONTROL_MASK)) {
- output[1] = '\003';
- use_ucsoutput = FALSE;
- end = 2;
- special = TRUE;
+ if (inst->back)
+ inst->back->special(inst->backhandle, TS_BRK);
+ return TRUE;
}
/* We handle Return ourselves, because it needs to be flagged as
}
/* Control-2, Control-Space and Control-@ are NUL */
- if (!event->string[0] &&
+ if (!output[1] &&
(event->keyval == ' ' || event->keyval == '2' ||
event->keyval == '@') &&
(event->state & (GDK_SHIFT_MASK |
}
/* Control-Shift-Space is 160 (ISO8859 nonbreaking space) */
- if (!event->string[0] && event->keyval == ' ' &&
+ if (!output[1] && event->keyval == ' ' &&
(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) ==
(GDK_SHIFT_MASK | GDK_CONTROL_MASK)) {
output[1] = '\240';
+ output_charset = CS_ISO8859_1;
use_ucsoutput = FALSE;
end = 2;
}
/* 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;
end = 1 + sprintf(output+1, "\033[Z");
use_ucsoutput = FALSE;
}
+ /* And normal Tab is Tab, if the keymap hasn't already told us.
+ * (Curiously, at least one version of the MacOS 10.5 X server
+ * doesn't translate Tab for us. */
+ if (event->keyval == GDK_Tab && end <= 1) {
+ output[1] = '\t';
+ end = 2;
+ }
/*
* 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"; break;
- case GDK_KP_2: case GDK_KP_Down: keys = "jJ"; break;
- case GDK_KP_3: case GDK_KP_Page_Down: keys = "nN"; break;
- case GDK_KP_4: case GDK_KP_Left: keys = "hH"; break;
- case GDK_KP_5: case GDK_KP_Begin: keys = ".."; break;
- case GDK_KP_6: case GDK_KP_Right: keys = "lL"; break;
- case GDK_KP_7: case GDK_KP_Home: keys = "yY"; break;
- case GDK_KP_8: case GDK_KP_Up: keys = "kK"; break;
- case GDK_KP_9: case GDK_KP_Page_Up: keys = "uU"; break;
+ case GDK_KP_1: case GDK_KP_End: keys = "bB\002"; break;
+ case GDK_KP_2: case GDK_KP_Down: keys = "jJ\012"; break;
+ case GDK_KP_3: case GDK_KP_Page_Down: keys = "nN\016"; break;
+ case GDK_KP_4: case GDK_KP_Left: keys = "hH\010"; break;
+ case GDK_KP_5: case GDK_KP_Begin: keys = "..."; break;
+ case GDK_KP_6: case GDK_KP_Right: keys = "lL\014"; break;
+ case GDK_KP_7: case GDK_KP_Home: keys = "yY\031"; break;
+ case GDK_KP_8: case GDK_KP_Up: keys = "kK\013"; break;
+ case GDK_KP_9: case GDK_KP_Page_Up: keys = "uU\025"; break;
}
if (keys) {
end = 2;
- if (event->state & GDK_SHIFT_MASK)
+ if (event->state & GDK_CONTROL_MASK)
+ output[1] = keys[2];
+ else if (event->state & GDK_SHIFT_MASK)
output[1] = keys[1];
else
output[1] = keys[0];
/*
* 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;
}
ldisc_send(inst->ldisc, output+start, -2, 1);
} else if (!inst->direct_to_font) {
if (!use_ucsoutput) {
- /*
- * The stuff we've just generated is assumed to be
- * ISO-8859-1! This sounds insane, but `man
- * XLookupString' agrees: strings of this type
- * returned from the X server are hardcoded to
- * 8859-1. Strictly speaking we should be doing
- * this using some sort of GtkIMContext, which (if
- * we're lucky) would give us our data directly in
- * Unicode; but that's not supported in GTK 1.2 as
- * far as I can tell, and it's poorly documented
- * even in 2.0, so it'll have to wait.
- */
if (inst->ldisc)
- lpage_send(inst->ldisc, CS_ISO8859_1, output+start,
+ lpage_send(inst->ldisc, output_charset, output+start,
end-start, 1);
} else {
/*
return TRUE;
}
-gint button_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
+#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)
+{
int shift, ctrl, alt, x, y, button, act;
/* Remember the timestamp. */
- inst->input_event_time = event->time;
+ inst->input_event_time = timestamp;
show_mouseptr(inst, 1);
- if (event->button == 4 && event->type == GDK_BUTTON_PRESS) {
+ if (ebutton == 4 && type == GDK_BUTTON_PRESS) {
term_scroll(inst->term, 0, -5);
return TRUE;
}
- if (event->button == 5 && event->type == GDK_BUTTON_PRESS) {
+ if (ebutton == 5 && type == GDK_BUTTON_PRESS) {
term_scroll(inst->term, 0, +5);
return TRUE;
}
- shift = event->state & GDK_SHIFT_MASK;
- ctrl = event->state & GDK_CONTROL_MASK;
- alt = event->state & GDK_MOD1_MASK;
+ shift = state & GDK_SHIFT_MASK;
+ ctrl = state & GDK_CONTROL_MASK;
+ alt = state & GDK_MOD1_MASK;
- if (event->button == 3 && ctrl) {
+ if (ebutton == 3 && ctrl) {
gtk_menu_popup(GTK_MENU(inst->menu), NULL, NULL, NULL, NULL,
- event->button, event->time);
+ ebutton, timestamp);
return TRUE;
}
- if (event->button == 1)
+ if (ebutton == 1)
button = MBT_LEFT;
- else if (event->button == 2)
+ else if (ebutton == 2)
button = MBT_MIDDLE;
- else if (event->button == 3)
+ else if (ebutton == 3)
button = MBT_RIGHT;
else
return FALSE; /* don't even know what button! */
- switch (event->type) {
+ switch (type) {
case GDK_BUTTON_PRESS: act = MA_CLICK; break;
case GDK_BUTTON_RELEASE: act = MA_RELEASE; break;
case GDK_2BUTTON_PRESS: act = MA_2CLK; break;
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 = (event->x - inst->cfg.window_border) / inst->font_width;
- y = (event->y - 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);
return TRUE;
}
+gboolean button_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
+{
+ struct gui_data *inst = (struct gui_data *)data;
+ return button_internal(inst, event->time, event->type, event->button,
+ event->state, event->x, event->y);
+}
+
+#if GTK_CHECK_VERSION(2,0,0)
+/*
+ * In GTK 2, mouse wheel events have become a new type of event.
+ * This handler translates them back into button-4 and button-5
+ * presses so that I don't have to change my old code too much :-)
+ */
+gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer data)
+{
+ struct gui_data *inst = (struct gui_data *)data;
+ guint button;
+
+ if (event->direction == GDK_SCROLL_UP)
+ button = 4;
+ else if (event->direction == GDK_SCROLL_DOWN)
+ button = 5;
+ else
+ return FALSE;
+
+ return button_internal(inst, event->time, GDK_BUTTON_PRESS,
+ button, event->state, event->x, event->y);
+}
+#endif
+
gint motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
{
struct gui_data *inst = (struct gui_data *)data;
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);
}
-void notify_remote_exit(void *frontend)
+static gint idle_exit_func(gpointer data)
{
- struct gui_data *inst = (struct gui_data *)frontend;
- int exitcode;
+ struct gui_data *inst = (struct gui_data *)data;
+ 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;
- 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);
+ return TRUE;
+}
+
+void notify_remote_exit(void *frontend)
+{
+ struct gui_data *inst = (struct gui_data *)frontend;
+
+ inst->term_exit_idle_id = gtk_idle_add(idle_exit_func, inst);
}
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
*/
#if GTK_CHECK_VERSION(2,0,0)
gtk_widget_set_size_request(inst->area, area_x, area_y);
+ 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
-
+ /*
+ * I can no longer remember what this call to
+ * gtk_container_dequeue_resize_handler is for. It was
+ * introduced in r3092 with no comment, and the commit log
+ * message was uninformative. I'm _guessing_ its purpose is to
+ * prevent gratuitous resize processing on the window given
+ * that we're about to resize it anyway, but I have no idea
+ * why that's so incredibly vital.
+ *
+ * I've tried removing the call, and nothing seems to go
+ * wrong. I've backtracked to r3092 and tried removing the
+ * call there, and still nothing goes wrong. So I'm going to
+ * adopt the working hypothesis that it's superfluous; I won't
+ * actually remove it from the GTK 1.2 code, but I won't
+ * attempt to replicate its functionality in the GTK 2 code
+ * above.
+ */
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
gdk_colormap_free_colors(inst->colmap, inst->cols + n, 1);
gdk_colormap_alloc_colors(inst->colmap, inst->cols + n, 1,
- FALSE, FALSE, success);
+ FALSE, TRUE, success);
if (!success[0])
g_error("%s: couldn't allocate colour %d (#%02x%02x%02x)\n", appname,
n, r, g, 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)
+ if (n == 258) {
+ /* Default Background changed. Ensure space between text area and
+ * window border is redrawn */
set_window_background(inst);
+ draw_backing_rect(inst);
+ gtk_widget_queue_draw(inst->area);
+ }
}
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++) {
if (i < 216) {
int r = i / 36, g = (i / 6) % 6, b = i % 6;
- inst->cols[i+16].red = r * 0x3333;
- inst->cols[i+16].green = g * 0x3333;
- inst->cols[i+16].blue = b * 0x3333;
+ inst->cols[i+16].red = r ? r * 0x2828 + 0x3737 : 0;
+ inst->cols[i+16].green = g ? g * 0x2828 + 0x3737 : 0;
+ inst->cols[i+16].blue = b ? b * 0x2828 + 0x3737 : 0;
} else {
int shade = i - 216;
- shade = (shade + 1) * 0xFFFF / (NEXTCOLOURS - 216 + 1);
+ shade = shade * 0x0a0a + 0x0808;
inst->cols[i+16].red = inst->cols[i+16].green =
inst->cols[i+16].blue = shade;
}
}
gdk_colormap_alloc_colors(inst->colmap, inst->cols, NALLCOLOURS,
- FALSE, FALSE, success);
+ FALSE, TRUE, success);
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
+ * between text area and window border is refreshed. */
set_window_background(inst);
+ if (inst->area && inst->area->window) {
+ draw_backing_rect(inst);
+ gtk_widget_queue_draw(inst->area);
+ }
}
/* Ensure that all the cut buffers exist - according to the ICCCM, we must
*/
void init_cutbuffers()
{
+ unsigned char empty[] = "";
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER0, XA_STRING, 8, PropModeAppend, "", 0);
+ XA_CUT_BUFFER0, XA_STRING, 8, PropModeAppend, empty, 0);
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER1, XA_STRING, 8, PropModeAppend, "", 0);
+ XA_CUT_BUFFER1, XA_STRING, 8, PropModeAppend, empty, 0);
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER2, XA_STRING, 8, PropModeAppend, "", 0);
+ XA_CUT_BUFFER2, XA_STRING, 8, PropModeAppend, empty, 0);
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER3, XA_STRING, 8, PropModeAppend, "", 0);
+ XA_CUT_BUFFER3, XA_STRING, 8, PropModeAppend, empty, 0);
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER4, XA_STRING, 8, PropModeAppend, "", 0);
+ XA_CUT_BUFFER4, XA_STRING, 8, PropModeAppend, empty, 0);
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER5, XA_STRING, 8, PropModeAppend, "", 0);
+ XA_CUT_BUFFER5, XA_STRING, 8, PropModeAppend, empty, 0);
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER6, XA_STRING, 8, PropModeAppend, "", 0);
+ XA_CUT_BUFFER6, XA_STRING, 8, PropModeAppend, empty, 0);
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
- XA_CUT_BUFFER7, XA_STRING, 8, PropModeAppend, "", 0);
+ XA_CUT_BUFFER7, XA_STRING, 8, PropModeAppend, empty, 0);
}
/* Store the data in a cut-buffer. */
return ptr;
}
-void write_clip(void *frontend, wchar_t * data, int len, int must_deselect)
+void write_clip(void *frontend, wchar_t * data, int *attr, int len, int must_deselect)
{
struct gui_data *inst = (struct gui_data *)frontend;
if (inst->pasteout_data)
* 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];
if (gtk_selection_owner_set(inst->area, GDK_SELECTION_PRIMARY,
inst->input_event_time)) {
+#if GTK_CHECK_VERSION(2,0,0)
+ gtk_selection_clear_targets(inst->area, GDK_SELECTION_PRIMARY);
+#endif
gtk_selection_add_target(inst->area, GDK_SELECTION_PRIMARY,
GDK_SELECTION_TYPE_STRING, 1);
if (inst->pasteout_data_ctext)
struct gui_data *inst = (struct gui_data *)data;
if (seldata->target == utf8_string_atom)
gtk_selection_data_set(seldata, seldata->target, 8,
- inst->pasteout_data_utf8,
+ (unsigned char *)inst->pasteout_data_utf8,
inst->pasteout_data_utf8_len);
else if (seldata->target == compound_text_atom)
gtk_selection_data_set(seldata, seldata->target, 8,
- inst->pasteout_data_ctext,
+ (unsigned char *)inst->pasteout_data_ctext,
inst->pasteout_data_ctext_len);
else
gtk_selection_data_set(seldata, seldata->target, 8,
- inst->pasteout_data, inst->pasteout_data_len);
+ (unsigned char *)inst->pasteout_data,
+ inst->pasteout_data_len);
}
gint selection_clear(GtkWidget *widget, GdkEventSelection *seldata,
* 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);
* may want to perform additional actions on any kind of bell (for
* example, taskbar flashing in Windows).
*/
-void beep(void *frontend, int mode)
+void do_beep(void *frontend, int mode)
{
- if (mode != BELL_VISUAL)
+ if (mode == BELL_DEFAULT)
gdk_beep();
}
* Under X, any fixed-width font really _is_ fixed-width.
* Double-width characters will be dealt with using a separate
* font. For the moment we can simply return 1.
+ *
+ * FIXME: but is that also true of Pango?
*/
return 1;
}
struct gui_data *inst = dctx->inst;
GdkGC *gc = dctx->gc;
int ncombining, combining;
- int nfg, nbg, t, fontid, shadow, rlen, widefactor;
+ int nfg, nbg, t, fontid, shadow, rlen, widefactor, bold;
+ int monochrome = gtk_widget_get_visual(inst->area)->depth == 1;
if (attr & TATTR_COMBINING) {
ncombining = len;
} else
ncombining = 1;
- nfg = ((attr & ATTR_FGMASK) >> ATTR_FGSHIFT);
- nbg = ((attr & ATTR_BGMASK) >> ATTR_BGSHIFT);
- if (attr & ATTR_REVERSE) {
+ nfg = ((monochrome ? ATTR_DEFFG : (attr & ATTR_FGMASK)) >> ATTR_FGSHIFT);
+ nbg = ((monochrome ? ATTR_DEFBG : (attr & ATTR_BGMASK)) >> ATTR_BGSHIFT);
+ if (!!(attr & ATTR_REVERSE) ^ (monochrome && (attr & TATTR_ACTCURS))) {
t = nfg;
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;
}
- if (attr & TATTR_ACTCURS) {
+ if ((attr & TATTR_ACTCURS) && !monochrome) {
nfg = 260;
nbg = 261;
}
widefactor = 1;
}
- if ((attr & ATTR_BOLD) && !inst->cfg.bold_colour) {
- if (inst->fonts[fontid | 1])
- fontid |= 1;
- else
- shadow = 1;
+ if ((attr & ATTR_BOLD) && (inst->bold_style & 1)) {
+ bold = 1;
+ fontid |= 1;
+ } else {
+ bold = 0;
+ }
+
+ if (!inst->fonts[fontid]) {
+ int i;
+ /*
+ * Fall back through font ids with subsets of this one's
+ * set bits, in order.
+ */
+ for (i = fontid; i-- > 0 ;) {
+ if (i & ~fontid)
+ continue; /* some other bit is set */
+ if (inst->fonts[i]) {
+ fontid = i;
+ break;
+ }
+ }
+ assert(inst->fonts[fontid]); /* we should at least have hit zero */
}
if ((lattr & LATTR_MODE) != LATTR_NORM) {
{
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]);
- {
- GdkWChar *gwcs;
- gchar *gcs;
- wchar_t *wcs;
- int i;
-
- wcs = snewn(len*ncombining+1, wchar_t);
- for (i = 0; i < len*ncombining; i++) {
- wcs[i] = text[i];
- }
-
- if (inst->fonts[fontid] == NULL) {
- /*
- * The font for this contingency does not exist.
- * Typically this means we've been given ATTR_WIDE
- * character and have no wide font. So we display
- * nothing at all; such is life.
- */
- } else if (inst->fontinfo[fontid].is_wide) {
- /*
- * At least one version of gdk_draw_text_wc() has a
- * weird bug whereby it reads `len' elements of the
- * input string, but only draws `len/2'. Hence I'm
- * going to make its input array twice as long as it
- * theoretically needs to be, and pass in twice the
- * actual number of characters. If a fixed gdk actually
- * takes the doubled length seriously, then (a) the
- * array will stand scrutiny up to the full length, (b)
- * the spare elements of the array are full of zeroes
- * which will probably be an empty glyph in the font,
- * and (c) the clip rectangle should prevent it causing
- * trouble anyway.
- */
- gwcs = snewn(len*2+1, GdkWChar);
- memset(gwcs, 0, sizeof(GdkWChar) * (len*2+1));
- /*
- * FIXME: when we have a wide-char equivalent of
- * from_unicode, use it instead of this.
- */
- for (combining = 0; combining < ncombining; combining++) {
- for (i = 0; i <= len; i++)
- gwcs[i] = wcs[i + combining];
- gdk_draw_text_wc(inst->pixmap, inst->fonts[fontid], gc,
- x*inst->font_width+inst->cfg.window_border,
- y*inst->font_height+inst->cfg.window_border+inst->fonts[0]->ascent,
- gwcs, len*2);
- if (shadow)
- gdk_draw_text_wc(inst->pixmap, inst->fonts[fontid], gc,
- x*inst->font_width+inst->cfg.window_border+inst->cfg.shadowboldoffset,
- y*inst->font_height+inst->cfg.window_border+inst->fonts[0]->ascent,
- gwcs, len*2);
- }
- sfree(gwcs);
- } else {
- gcs = snewn(len+1, gchar);
- for (combining = 0; combining < ncombining; combining++) {
- wc_to_mb(inst->fontinfo[fontid].charset, 0,
- wcs + combining, len, gcs, len, ".", NULL, NULL);
- gdk_draw_text(inst->pixmap, inst->fonts[fontid], gc,
- x*inst->font_width+inst->cfg.window_border,
- y*inst->font_height+inst->cfg.window_border+inst->fonts[0]->ascent,
- gcs, len);
- if (shadow)
- gdk_draw_text(inst->pixmap, inst->fonts[fontid], gc,
- x*inst->font_width+inst->cfg.window_border+inst->cfg.shadowboldoffset,
- y*inst->font_height+inst->cfg.window_border+inst->fonts[0]->ascent,
- gcs, len);
- }
- sfree(gcs);
- }
- sfree(wcs);
+ 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)
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
}
}
-int do_cmdline(int argc, char **argv, int do_everything,
- struct gui_data *inst, Config *cfg)
+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)
{
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, w, h;
+ int flags, x, y;
+ unsigned int w, h;
EXPECTS_ARG;
SECOND_PASS_ONLY;
flags = XParseGeometry(val, &x, &y, &w, &h);
if (flags & WidthValue)
- cfg->width = w;
+ conf_set_int(conf, CONF_width, w);
if (flags & HeightValue)
- cfg->height = 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 */
} else {
return err;
}
-/*
- * This function retrieves the character set encoding of a font. It
- * returns the character set without the X11 hack (in case the user
- * asks to use the font's own encoding).
- */
-static int set_font_info(struct gui_data *inst, int fontid)
-{
- GdkFont *font = inst->fonts[fontid];
- XFontStruct *xfs = GDK_FONT_XFONT(font);
- Display *disp = GDK_FONT_XDISPLAY(font);
- Atom charset_registry, charset_encoding;
- unsigned long registry_ret, encoding_ret;
- int retval = CS_NONE;
-
- charset_registry = XInternAtom(disp, "CHARSET_REGISTRY", False);
- charset_encoding = XInternAtom(disp, "CHARSET_ENCODING", False);
- inst->fontinfo[fontid].charset = CS_NONE;
- inst->fontinfo[fontid].is_wide = 0;
- if (XGetFontProperty(xfs, charset_registry, ®istry_ret) &&
- XGetFontProperty(xfs, charset_encoding, &encoding_ret)) {
- char *reg, *enc;
- reg = XGetAtomName(disp, (Atom)registry_ret);
- enc = XGetAtomName(disp, (Atom)encoding_ret);
- if (reg && enc) {
- char *encoding = dupcat(reg, "-", enc, NULL);
- retval = inst->fontinfo[fontid].charset =
- charset_from_xenc(encoding);
- /* FIXME: when libcharset supports wide encodings fix this. */
- if (!strcasecmp(encoding, "iso10646-1")) {
- inst->fontinfo[fontid].is_wide = 1;
- retval = CS_UTF8;
- }
-
- /*
- * Hack for X line-drawing characters: if the primary
- * font is encoded as ISO-8859-anything, and has valid
- * glyphs in the first 32 char positions, it is assumed
- * that those glyphs are the VT100 line-drawing
- * character set.
- *
- * Actually, we'll hack even harder by only checking
- * position 0x19 (vertical line, VT100 linedrawing
- * `x'). Then we can check it easily by seeing if the
- * ascent and descent differ.
- */
- if (inst->fontinfo[fontid].charset == CS_ISO8859_1) {
- int lb, rb, wid, asc, desc;
- gchar text[2];
-
- text[1] = '\0';
- text[0] = '\x12';
- gdk_string_extents(inst->fonts[fontid], text,
- &lb, &rb, &wid, &asc, &desc);
- if (asc != desc)
- inst->fontinfo[fontid].charset = CS_ISO8859_1_X11;
- }
-
- sfree(encoding);
- }
- }
-
- return retval;
-}
-
int uxsel_input_add(int fd, int rwx) {
int flags = 0;
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);
}
gdk_input_remove(id);
}
-char *guess_derived_font_name(GdkFont *font, int bold, int wide)
+int frontend_net_pending_error_idle_id;
+int frontend_got_net_pending_errors = FALSE;
+gboolean frontend_net_pending_errors(gpointer data)
{
- XFontStruct *xfs = GDK_FONT_XFONT(font);
- Display *disp = GDK_FONT_XDISPLAY(font);
- Atom fontprop = XInternAtom(disp, "FONT", False);
- unsigned long ret;
- if (XGetFontProperty(xfs, fontprop, &ret)) {
- char *name = XGetAtomName(disp, (Atom)ret);
- if (name && name[0] == '-') {
- char *strings[13];
- char *dupname, *extrafree = NULL, *ret;
- char *p, *q;
- int nstr;
-
- p = q = dupname = dupstr(name); /* skip initial minus */
- nstr = 0;
-
- while (*p && nstr < lenof(strings)) {
- if (*p == '-') {
- *p = '\0';
- strings[nstr++] = p+1;
- }
- p++;
- }
-
- if (nstr < lenof(strings))
- return NULL; /* XLFD was malformed */
-
- if (bold)
- strings[2] = "bold";
-
- if (wide) {
- /* 4 is `wideness', which obviously may have changed. */
- /* 5 is additional style, which may be e.g. `ja' or `ko'. */
- strings[4] = strings[5] = "*";
- strings[11] = extrafree = dupprintf("%d", 2*atoi(strings[11]));
- }
-
- ret = dupcat("-", strings[ 0], "-", strings[ 1], "-", strings[ 2],
- "-", strings[ 3], "-", strings[ 4], "-", strings[ 5],
- "-", strings[ 6], "-", strings[ 7], "-", strings[ 8],
- "-", strings[ 9], "-", strings[10], "-", strings[11],
- "-", strings[12], NULL);
- sfree(extrafree);
- sfree(dupname);
-
- return ret;
- }
+ 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);
}
- return NULL;
}
-void setup_fonts_ucs(struct gui_data *inst)
+char *setup_fonts_ucs(struct gui_data *inst)
{
- int font_charset;
- char *name;
- int guessed;
-
- if (inst->fonts[0])
- gdk_font_unref(inst->fonts[0]);
- if (inst->fonts[1])
- gdk_font_unref(inst->fonts[1]);
- if (inst->fonts[2])
- gdk_font_unref(inst->fonts[2]);
- if (inst->fonts[3])
- gdk_font_unref(inst->fonts[3]);
+ 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;
- inst->fonts[0] = gdk_font_load(inst->cfg.font.name);
- if (!inst->fonts[0]) {
- fprintf(stderr, "%s: unable to load font \"%s\"\n", appname,
- inst->cfg.font.name);
- exit(1);
+ 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);
}
- font_charset = set_font_info(inst, 0);
- if (inst->cfg.shadowbold) {
- inst->fonts[1] = NULL;
+ fs = conf_get_fontspec(inst->conf, CONF_boldfont);
+ if (shadowbold || !fs->name[0]) {
+ fonts[1] = NULL;
} else {
- if (inst->cfg.boldfont.name[0]) {
- name = inst->cfg.boldfont.name;
- guessed = FALSE;
- } else {
- name = guess_derived_font_name(inst->fonts[0], TRUE, FALSE);
- guessed = TRUE;
+ 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);
}
- inst->fonts[1] = name ? gdk_font_load(name) : NULL;
- if (inst->fonts[1]) {
- set_font_info(inst, 1);
- } else if (!guessed) {
- fprintf(stderr, "%s: unable to load bold font \"%s\"\n", appname,
- inst->cfg.boldfont.name);
- exit(1);
- }
- if (guessed)
- sfree(name);
}
- if (inst->cfg.widefont.name[0]) {
- name = inst->cfg.widefont.name;
- guessed = FALSE;
+ 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 {
- name = guess_derived_font_name(inst->fonts[0], FALSE, TRUE);
- guessed = TRUE;
- }
- inst->fonts[2] = name ? gdk_font_load(name) : NULL;
- if (inst->fonts[2]) {
- set_font_info(inst, 2);
- } else if (!guessed) {
- fprintf(stderr, "%s: unable to load wide font \"%s\"\n", appname,
- inst->cfg.widefont.name);
- exit(1);
+ fonts[2] = NULL;
}
- if (guessed)
- sfree(name);
- if (inst->cfg.shadowbold) {
- inst->fonts[3] = NULL;
+ fs = conf_get_fontspec(inst->conf, CONF_wideboldfont);
+ if (shadowbold || !fs->name[0]) {
+ fonts[3] = NULL;
} else {
- if (inst->cfg.wideboldfont.name[0]) {
- name = inst->cfg.wideboldfont.name;
- guessed = FALSE;
- } else {
- /*
- * Here we have some choices. We can widen the bold font,
- * bolden the wide font, or widen and bolden the standard
- * font. Try them all, in that order!
- */
- if (inst->cfg.widefont.name[0])
- name = guess_derived_font_name(inst->fonts[2], TRUE, FALSE);
- else if (inst->cfg.boldfont.name[0])
- name = guess_derived_font_name(inst->fonts[1], FALSE, TRUE);
- else
- name = guess_derived_font_name(inst->fonts[0], TRUE, TRUE);
- guessed = TRUE;
- }
- inst->fonts[3] = name ? gdk_font_load(name) : NULL;
- if (inst->fonts[3]) {
- set_font_info(inst, 3);
- } else if (!guessed) {
- fprintf(stderr, "%s: unable to load wide/bold font \"%s\"\n", appname,
- inst->cfg.wideboldfont.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);
}
- if (guessed)
- sfree(name);
}
- inst->font_width = gdk_char_width(inst->fonts[0], ' ');
- inst->font_height = inst->fonts[0]->ascent + inst->fonts[0]->descent;
+ /*
+ * 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,
+ conf_get_str(inst->conf, CONF_line_codepage),
+ conf_get_int(inst->conf, CONF_utf8_override),
+ inst->fonts[0]->public_charset,
+ conf_get_int(inst->conf, CONF_vtmode));
- inst->direct_to_font = init_ucs(&inst->ucsdata, inst->cfg.line_codepage,
- inst->cfg.utf8_override, font_charset,
- inst->cfg.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 reset_terminal_menuitem(GtkMenuItem *item, gpointer data)
{
struct gui_data *inst = (struct gui_data *)data;
- term_pwron(inst->term);
+ term_pwron(inst->term, TRUE);
if (inst->ldisc)
ldisc_send(inst->ldisc, NULL, 0, 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;
}
if (!inst->back) {
logevent(inst, "----- Session restarted -----");
+ term_pwron(inst->term, FALSE);
start_backend(inst);
inst->exited = FALSE;
}
(GtkCallback)gtk_widget_destroy, NULL);
get_sesslist(&sesslist, TRUE);
+ /* skip sesslist.sessions[0] == Default Settings */
for (i = 1; i < sesslist.nsessions; i++) {
GtkWidget *menuitem =
gtk_menu_item_new_with_label(sesslist.sessions[i]);
GTK_SIGNAL_FUNC(saved_session_freedata),
inst);
}
+ if (sesslist.nsessions <= 1) {
+ GtkWidget *menuitem =
+ gtk_menu_item_new_with_label("(No sessions)");
+ gtk_widget_set_sensitive(menuitem, FALSE);
+ gtk_container_add(GTK_CONTAINER(inst->sessionsmenu), menuitem);
+ gtk_widget_show(menuitem);
+ }
get_sesslist(&sesslist, FALSE); /* free up */
}
+void set_window_icon(GtkWidget *window, const char *const *const *icon,
+ int n_icon)
+{
+ GdkPixmap *iconpm;
+ GdkBitmap *iconmask;
+#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, &iconmask,
+ NULL, (gchar **)icon[0]);
+ gdk_window_set_icon(window->window, NULL, iconpm, iconmask);
+
+#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;
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);
+
inst->back->provide_logctx(inst->backhandle, inst->logctx);
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 {
- if (do_cmdline(argc, argv, 0, inst, &inst->cfg))
+ /* 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->conf))
exit(1); /* pre-defaults pass to get -class */
- do_defaults(NULL, &inst->cfg);
- if (do_cmdline(argc, argv, 1, 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 (!*inst->cfg.host && !cfgbox(&inst->cfg))
+ if ((!allow_launch || !conf_launchable(inst->conf)) &&
+ !cfgbox(inst->conf))
exit(0); /* config box hit Cancel */
}
if (!utf8_string_atom)
utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE);
- setup_fonts_ucs(inst);
+ inst->area = gtk_drawing_area_new();
+
+#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);
- inst->area = gtk_drawing_area_new();
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(button_event), inst);
gtk_signal_connect(GTK_OBJECT(inst->area), "button_release_event",
GTK_SIGNAL_FUNC(button_event), inst);
+#if GTK_CHECK_VERSION(2,0,0)
+ gtk_signal_connect(GTK_OBJECT(inst->area), "scroll_event",
+ GTK_SIGNAL_FUNC(scroll_event), inst);
+#endif
gtk_signal_connect(GTK_OBJECT(inst->area), "motion_notify_event",
GTK_SIGNAL_FUNC(motion_event), inst);
gtk_signal_connect(GTK_OBJECT(inst->area), "selection_received",
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),
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);
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);