#define CAT(x,y) CAT2(x,y)
#define ASSERT(x) enum {CAT(assertion_,__LINE__) = 1 / (x)}
-#define NCOLOURS (lenof(((Config *)0)->colours))
+/* 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)
GdkAtom compound_text_atom, utf8_string_atom;
extern char **pty_argv; /* declared in pty.c */
extern int use_pty_argv;
+/*
+ * Timers are global across all sessions (even if we were handling
+ * multiple sessions, which we aren't), so the current timer ID is
+ * a global variable.
+ */
+static guint timer_id = 0;
+
struct gui_data {
GtkWidget *window, *area, *sbar;
GtkBox *hbox;
} fontinfo[4];
int xpos, ypos, gotpos, gravity;
GdkCursor *rawcursor, *textcursor, *blankcursor, *currcursor;
- GdkColor cols[NCOLOURS];
+ GdkColor cols[NALLCOLOURS];
GdkColormap *colmap;
wchar_t *pastein_data;
int direct_to_font;
void draw_backing_rect(struct gui_data *inst)
{
GdkGC *gc = gdk_gc_new(inst->area->window);
- gdk_gc_set_foreground(gc, &inst->cols[18]); /* default background */
+ 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);
show_mouseptr(inst, 0);
term_seen_key_event(inst->term);
- term_out(inst->term);
}
return TRUE;
exit(0);
}
-gint timer_func(gpointer data)
+void notify_remote_exit(void *frontend)
{
- struct gui_data *inst = (struct gui_data *)data;
+ struct gui_data *inst = (struct gui_data *)frontend;
int exitcode;
if (!inst->exited &&
}
gtk_widget_show(inst->restartitem);
}
+}
- term_update(inst->term);
- term_blink(inst->term, 0);
- return TRUE;
+static gint timer_trigger(gpointer data)
+{
+ long now = GPOINTER_TO_INT(data);
+ long next;
+ 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));
+ }
+
+ /*
+ * Never let a timer resume. If we need another one, we've
+ * asked for it explicitly above.
+ */
+ return FALSE;
+}
+
+void timer_change_notify(long next)
+{
+ long ticks;
+
+ if (timer_id)
+ gtk_timeout_remove(timer_id);
+
+ ticks = next - GETTICKCOUNT();
+ if (ticks <= 0)
+ ticks = 1; /* just in case */
+
+ timer_id = gtk_timeout_add(ticks, timer_trigger,
+ GINT_TO_POINTER(next));
}
void fd_input_func(gpointer data, gint sourcefd, GdkInputCondition condition)
gint focus_event(GtkWidget *widget, GdkEventFocus *event, gpointer data)
{
struct gui_data *inst = (struct gui_data *)data;
- inst->term->has_focus = event->in;
- term_out(inst->term);
+ term_set_focus(inst->term, event->in);
term_update(inst->term);
show_mouseptr(inst, 1);
return FALSE;
void set_window_background(struct gui_data *inst)
{
if (inst->area && inst->area->window)
- gdk_window_set_background(inst->area->window, &inst->cols[18]);
+ gdk_window_set_background(inst->area->window, &inst->cols[258]);
if (inst->window && inst->window->window)
- gdk_window_set_background(inst->window->window, &inst->cols[18]);
+ gdk_window_set_background(inst->window->window, &inst->cols[258]);
}
void palette_set(void *frontend, int n, int r, int g, int b)
{
struct gui_data *inst = (struct gui_data *)frontend;
- static const int first[21] = {
- 0, 2, 4, 6, 8, 10, 12, 14,
- 1, 3, 5, 7, 9, 11, 13, 15,
- 16, 17, 18, 20, 22
- };
- real_palette_set(inst, first[n], r, g, b);
- if (first[n] >= 18)
- real_palette_set(inst, first[n] + 1, r, g, b);
- if (first[n] == 18)
+ if (n >= 16)
+ n += 256 - 16;
+ if (n > NALLCOLOURS)
+ return;
+ real_palette_set(inst, n, r, g, b);
+ if (n == 258)
set_window_background(inst);
}
struct gui_data *inst = (struct gui_data *)frontend;
/* This maps colour indices in inst->cfg to those used in inst->cols. */
static const int ww[] = {
- 6, 7, 8, 9, 10, 11, 12, 13,
- 14, 15, 16, 17, 18, 19, 20, 21,
- 0, 1, 2, 3, 4, 5
+ 256, 257, 258, 259, 260, 261,
+ 0, 8, 1, 9, 2, 10, 3, 11,
+ 4, 12, 5, 13, 6, 14, 7, 15
};
- gboolean success[NCOLOURS];
+ gboolean success[NALLCOLOURS];
int i;
- assert(lenof(ww) == NCOLOURS);
+ assert(lenof(ww) == NCFGCOLOURS);
if (!inst->colmap) {
inst->colmap = gdk_colormap_get_system();
} else {
- gdk_colormap_free_colors(inst->colmap, inst->cols, NCOLOURS);
+ gdk_colormap_free_colors(inst->colmap, inst->cols, NALLCOLOURS);
}
- for (i = 0; i < NCOLOURS; i++) {
- inst->cols[i].red = inst->cfg.colours[ww[i]][0] * 0x0101;
- inst->cols[i].green = inst->cfg.colours[ww[i]][1] * 0x0101;
- inst->cols[i].blue = inst->cfg.colours[ww[i]][2] * 0x0101;
+ 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;
}
- gdk_colormap_alloc_colors(inst->colmap, inst->cols, NCOLOURS,
+ 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;
+ } else {
+ int shade = i - 216;
+ shade = (shade + 1) * 0xFFFF / (NEXTCOLOURS - 216 + 1);
+ 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);
- for (i = 0; i < NCOLOURS; 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],
*
* We are allowed to fiddle with the contents of `text'.
*/
-void do_text_internal(Context ctx, int x, int y, char *text, int len,
+void do_text_internal(Context ctx, int x, int y, wchar_t *text, int len,
unsigned long attr, int lattr)
{
struct draw_ctx *dctx = (struct draw_ctx *)ctx;
struct gui_data *inst = dctx->inst;
GdkGC *gc = dctx->gc;
-
+ int ncombining, combining;
int nfg, nbg, t, fontid, shadow, rlen, widefactor;
+ if (attr & TATTR_COMBINING) {
+ ncombining = len;
+ len = 1;
+ } else
+ ncombining = 1;
+
nfg = ((attr & ATTR_FGMASK) >> ATTR_FGSHIFT);
- nfg = 2 * (nfg & 0xF) + (nfg & 0x10 ? 1 : 0);
nbg = ((attr & ATTR_BGMASK) >> ATTR_BGSHIFT);
- nbg = 2 * (nbg & 0xF) + (nbg & 0x10 ? 1 : 0);
if (attr & ATTR_REVERSE) {
t = nfg;
nfg = nbg;
nbg = t;
}
- if (inst->cfg.bold_colour && (attr & ATTR_BOLD))
- nfg |= 1;
- if (inst->cfg.bold_colour && (attr & ATTR_BLINK))
- nbg |= 1;
+ if (inst->cfg.bold_colour && (attr & ATTR_BOLD)) {
+ if (nfg < 16) nfg |= 8;
+ else if (nfg >= 256) nfg |= 1;
+ }
+ if (inst->cfg.bold_colour && (attr & ATTR_BLINK)) {
+ if (nbg < 16) nbg |= 8;
+ else if (nbg >= 256) nbg |= 1;
+ }
if (attr & TATTR_ACTCURS) {
- nfg = NCOLOURS-2;
- nbg = NCOLOURS-1;
+ nfg = 260;
+ nbg = 261;
}
fontid = shadow = 0;
shadow = 1;
}
- if (lattr != LATTR_NORM) {
+ if ((lattr & LATTR_MODE) != LATTR_NORM) {
x *= 2;
if (x >= inst->term->cols)
return;
wchar_t *wcs;
int i;
- wcs = snewn(len+1, wchar_t);
- for (i = 0; i < len; i++) {
- wcs[i] = (wchar_t) ((attr & CSET_MASK) + (text[i] & CHAR_MASK));
+ wcs = snewn(len*ncombining+1, wchar_t);
+ for (i = 0; i < len*ncombining; i++) {
+ wcs[i] = text[i];
}
if (inst->fonts[fontid] == NULL) {
* FIXME: when we have a wide-char equivalent of
* from_unicode, use it instead of this.
*/
- for (i = 0; i <= len; i++)
- gwcs[i] = wcs[i];
- 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);
+ 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);
- wc_to_mb(inst->fontinfo[fontid].charset, 0,
- wcs, 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);
+ 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);
}
- 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,
- text, len);
- }
-
if (attr & ATTR_UNDER) {
int uheight = inst->fonts[0]->ascent + 1;
if (uheight >= inst->font_height)
y*inst->font_height + uheight + inst->cfg.window_border);
}
- if (lattr != LATTR_NORM) {
+ if ((lattr & LATTR_MODE) != LATTR_NORM) {
/*
* I can't find any plausible StretchBlt equivalent in the
* X server, so I'm going to do this the slow and painful
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,
- len * inst->font_width - i, inst->font_height);
+ len * widefactor * inst->font_width - i, inst->font_height);
}
len *= 2;
- if (lattr != LATTR_WIDE) {
+ if ((lattr & LATTR_MODE) != LATTR_WIDE) {
int dt, db;
/* Now stretch vertically, in the same way. */
- if (lattr == LATTR_BOT)
+ if ((lattr & LATTR_MODE) == LATTR_BOT)
dt = 0, db = 1;
else
dt = 1, db = 0;
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*widefactor*inst->font_width+inst->cfg.window_border,
+ x*inst->font_width+inst->cfg.window_border,
y*inst->font_height+inst->cfg.window_border+dt*(i+1),
- len * inst->font_width, inst->font_height-i-1);
+ len * widefactor * inst->font_width, inst->font_height-i-1);
}
}
}
}
-void do_text(Context ctx, int x, int y, char *text, int len,
+void do_text(Context ctx, int x, int y, wchar_t *text, int len,
unsigned long attr, int lattr)
{
struct draw_ctx *dctx = (struct draw_ctx *)ctx;
widefactor = 1;
}
- if (lattr != LATTR_NORM) {
+ if ((lattr & LATTR_MODE) != LATTR_NORM) {
x *= 2;
if (x >= inst->term->cols)
return;
len*widefactor*inst->font_width, inst->font_height);
}
-void do_cursor(Context ctx, int x, int y, char *text, int len,
+void do_cursor(Context ctx, int x, int y, wchar_t *text, int len,
unsigned long attr, int lattr)
{
struct draw_ctx *dctx = (struct draw_ctx *)ctx;
active = 0;
do_text_internal(ctx, x, y, text, len, attr, lattr);
+ if (attr & TATTR_COMBINING)
+ len = 1;
+
if (attr & ATTR_WIDE) {
widefactor = 2;
} else {
widefactor = 1;
}
- if (lattr != LATTR_NORM) {
+ if ((lattr & LATTR_MODE) != LATTR_NORM) {
x *= 2;
if (x >= inst->term->cols)
return;
* if it's passive.
*/
if (passive) {
- gdk_gc_set_foreground(gc, &inst->cols[NCOLOURS-1]);
+ 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,
- len*inst->font_width-1, inst->font_height-1);
+ len*widefactor*inst->font_width-1, inst->font_height-1);
}
} else {
int uheight;
int char_width;
- if ((attr & ATTR_WIDE) || lattr != LATTR_NORM)
+ if ((attr & ATTR_WIDE) || (lattr & LATTR_MODE) != LATTR_NORM)
char_width = 2*inst->font_width;
else
char_width = inst->font_width;
starty = y * inst->font_height + inst->cfg.window_border + uheight;
dx = 1;
dy = 0;
- length = len * char_width;
+ length = len * widefactor * char_width;
} else {
int xadjust = 0;
if (attr & TATTR_RIGHTCURS)
length = inst->font_height;
}
- gdk_gc_set_foreground(gc, &inst->cols[NCOLOURS-1]);
+ gdk_gc_set_foreground(gc, &inst->cols[NCFGCOLOURS-1]);
if (passive) {
for (i = 0; i < length; i++) {
if (i % 2 == 0) {
inst->font_width = gdk_char_width(inst->fonts[0], ' ');
inst->font_height = inst->fonts[0]->ascent + inst->fonts[0]->descent;
- inst->direct_to_font = init_ucs(&inst->ucsdata,
- inst->cfg.line_codepage, font_charset,
+ inst->direct_to_font = init_ucs(&inst->ucsdata, inst->cfg.line_codepage,
+ inst->cfg.utf8_override, font_charset,
inst->cfg.vtmode);
}
{
/* This maps colour indices in inst->cfg to those used in inst->cols. */
static const int ww[] = {
- 6, 7, 8, 9, 10, 11, 12, 13,
- 14, 15, 16, 17, 18, 19, 20, 21,
- 0, 1, 2, 3, 4, 5
+ 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;
+ assert(lenof(ww) == NCFGCOLOURS);
+
cfg2 = inst->cfg; /* structure copy */
if (do_config_box(title, &cfg2, 1)) {
* have to the new default, on the assumption that the user
* is most likely to want an immediate update.
*/
- for (i = 0; i < NCOLOURS; i++) {
- if (oldcfg.colours[ww[i]][0] != cfg2.colours[ww[i]][0] ||
- oldcfg.colours[ww[i]][1] != cfg2.colours[ww[i]][1] ||
- oldcfg.colours[ww[i]][2] != cfg2.colours[ww[i]][2]) {
- real_palette_set(inst, i, cfg2.colours[ww[i]][0],
- cfg2.colours[ww[i]][1],
- cfg2.colours[ww[i]][2]);
+ 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]);
/*
* If the default background has changed, we must
* repaint the space in between the window border
* and the text area.
*/
- if (i == 18) {
+ if (i == 258) {
set_window_background(inst);
draw_backing_rect(inst);
}
else
specials = NULL;
+ /* I believe this disposes of submenus too. */
gtk_container_foreach(GTK_CONTAINER(inst->specialsmenu),
(GtkCallback)gtk_widget_destroy, NULL);
if (specials) {
int i;
- GtkWidget *menuitem;
- for (i = 0; specials[i].name; i++) {
- if (*specials[i].name) {
+ GtkWidget *menu = inst->specialsmenu;
+ /* A lame "stack" for submenus that will do for now. */
+ GtkWidget *saved_menu = NULL;
+ int nesting = 1;
+ for (i = 0; nesting > 0; i++) {
+ GtkWidget *menuitem = NULL;
+ switch (specials[i].code) {
+ case TS_SUBMENU:
+ assert (nesting < 2);
+ saved_menu = menu; /* XXX lame stacking */
+ menu = gtk_menu_new();
+ menuitem = gtk_menu_item_new_with_label(specials[i].name);
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menu);
+ gtk_container_add(GTK_CONTAINER(saved_menu), menuitem);
+ gtk_widget_show(menuitem);
+ menuitem = NULL;
+ nesting++;
+ break;
+ case TS_EXITMENU:
+ nesting--;
+ if (nesting) {
+ menu = saved_menu; /* XXX lame stacking */
+ saved_menu = NULL;
+ }
+ break;
+ case TS_SEP:
+ menuitem = gtk_menu_item_new();
+ break;
+ default:
menuitem = gtk_menu_item_new_with_label(specials[i].name);
gtk_object_set_data(GTK_OBJECT(menuitem), "user-data",
GINT_TO_POINTER(specials[i].code));
gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
GTK_SIGNAL_FUNC(special_menuitem), inst);
- } else
- menuitem = gtk_menu_item_new();
- gtk_container_add(GTK_CONTAINER(inst->specialsmenu), menuitem);
- gtk_widget_show(menuitem);
+ break;
+ }
+ if (menuitem) {
+ gtk_container_add(GTK_CONTAINER(menu), menuitem);
+ gtk_widget_show(menuitem);
+ }
}
gtk_widget_show(inst->specialsitem1);
gtk_widget_show(inst->specialsitem2);
sfree(title);
}
inst->back->provide_logctx(inst->backhandle, inst->logctx);
- update_specials_menu(inst);
term_provide_resize_fn(inst->term, inst->back->size, inst->backhandle);
if (inst->cfg.scrollbar)
gtk_signal_connect(GTK_OBJECT(inst->sbar_adjust), "value_changed",
GTK_SIGNAL_FUNC(scrollbar_moved), inst);
- gtk_timeout_add(20, timer_func, inst);
gtk_widget_add_events(GTK_WIDGET(inst->area),
GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
inst->specialsitem1 = menuitem;
MKMENUITEM(NULL, NULL);
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);