int pasteout_data_len;
int font_width, font_height;
int ignore_sbar;
+ int mouseptr_visible;
+ guint term_paste_idle_id;
GdkAtom compound_text_atom;
char wintitle[sizeof(((Config *)0)->wintitle)];
+ char icontitle[sizeof(((Config *)0)->wintitle)];
};
static struct gui_data the_inst;
int askappend(char *filename)
{
/*
- * FIXME: for the moment we just wipe the log file. Since I
- * haven't yet enabled logging, this shouldn't matter yet!
+ * Logging in an xterm-alike is liable to be something you only
+ * do at serious diagnostic need. Hence, I'm going to take the
+ * easy option for now and assume we always want to overwrite
+ * log files. I can always make it properly configurable later.
*/
return 2;
}
*/
void set_iconic(int iconic)
{
- /* FIXME: currently ignored */
+ /*
+ * GTK 1.2 doesn't know how to do this.
+ */
+#if GTK_CHECK_VERSION(2,0,0)
+ if (iconic)
+ gtk_window_iconify(GTK_WINDOW(inst->window));
+ else
+ gtk_window_deiconify(GTK_WINDOW(inst->window));
+#endif
}
/*
*/
void move_window(int x, int y)
{
- /* FIXME: currently ignored */
+ /*
+ * I assume that when the GTK version of this call is available
+ * we should use it. Not sure how it differs from the GDK one,
+ * though.
+ */
+#if GTK_CHECK_VERSION(2,0,0)
+ gtk_window_move(GTK_WINDOW(inst->window), x, y);
+#else
+ gdk_window_move(inst->window->window, x, y);
+#endif
}
/*
*/
void set_zorder(int top)
{
- /* FIXME: currently ignored */
+ if (top)
+ gdk_window_raise(inst->window->window);
+ else
+ gdk_window_lower(inst->window->window);
}
/*
*/
void refresh_window(void)
{
- /* FIXME: currently ignored */
+ term_invalidate();
}
/*
*/
void set_zoomed(int zoomed)
{
- /* FIXME: currently ignored */
+ /*
+ * GTK 1.2 doesn't know how to do this.
+ */
+#if GTK_CHECK_VERSION(2,0,0)
+ if (iconic)
+ gtk_window_maximize(GTK_WINDOW(inst->window));
+ else
+ gtk_window_unmaximize(GTK_WINDOW(inst->window));
+#endif
}
/*
*/
int is_iconic(void)
{
- return 0; /* FIXME */
+ return !gdk_window_is_viewable(inst->window->window);
}
/*
*/
void get_window_pos(int *x, int *y)
{
- *x = 3; *y = 4; /* FIXME */
+ /*
+ * I assume that when the GTK version of this call is available
+ * we should use it. Not sure how it differs from the GDK one,
+ * though.
+ */
+#if GTK_CHECK_VERSION(2,0,0)
+ gtk_window_get_position(GTK_WINDOW(inst->window), x, y);
+#else
+ gdk_window_get_position(inst->window->window, x, y);
+#endif
}
/*
*/
void get_window_pixels(int *x, int *y)
{
- *x = 1; *y = 2; /* FIXME */
+ /*
+ * I assume that when the GTK version of this call is available
+ * we should use it. Not sure how it differs from the GDK one,
+ * though.
+ */
+#if GTK_CHECK_VERSION(2,0,0)
+ gtk_window_get_size(GTK_WINDOW(inst->window), x, y);
+#else
+ gdk_window_get_size(inst->window->window, x, y);
+#endif
}
/*
*/
char *get_window_title(int icon)
{
- return inst->wintitle;
+ return icon ? inst->wintitle : inst->icontitle;
}
gint delete_window(GtkWidget *widget, GdkEvent *event, gpointer data)
gdk_window_set_cursor(inst->area->window, inst->currcursor);
else
gdk_window_set_cursor(inst->area->window, inst->blankcursor);
+ inst->mouseptr_visible = show;
}
gint configure_area(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
struct gui_data *inst = (struct gui_data *)data;
int w, h, need_size = 0;
+printf("configure %d x %d\n", event->width, event->height);
w = (event->width - 2*cfg.window_border) / inst->font_width;
h = (event->height - 2*cfg.window_border) / inst->font_height;
+printf(" = %d x %d\n", w, h);
if (w != cfg.width || h != cfg.height) {
if (inst->pixmap) {
cfg.width = w;
cfg.height = h;
need_size = 1;
+printf("need size\n");
}
if (!inst->pixmap) {
GdkGC *gc;
term_size(h, w, cfg.savelines);
}
- /*
- * Set up the colour map.
- */
- if (!inst->colmap) {
- 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
- };
- gboolean success[NCOLOURS];
- int i;
-
- inst->colmap = gdk_colormap_get_system();
-
- assert(lenof(ww) == NCOLOURS);
-
- for (i = 0; i < NCOLOURS; i++) {
- inst->cols[i].red = cfg.colours[ww[i]][0] * 0x0101;
- inst->cols[i].green = cfg.colours[ww[i]][1] * 0x0101;
- inst->cols[i].blue = cfg.colours[ww[i]][2] * 0x0101;
- }
-
- gdk_colormap_alloc_colors(inst->colmap, inst->cols, NCOLOURS,
- FALSE, FALSE, success);
- for (i = 0; i < NCOLOURS; i++) {
- if (!success[i])
- g_error("pterm: couldn't allocate colour %d (#%02x%02x%02x)\n",
- i, cfg.colours[i][0], cfg.colours[i][1], cfg.colours[i][2]);
- }
- }
-
return TRUE;
}
/*
* NYI:
- * - nethack mode
* - alt+numpad
* - Compose key (!!! requires Unicode faff before even trying)
*/
inst->currcursor = inst->rawcursor;
else
inst->currcursor = inst->textcursor;
- show_mouseptr(1);
+ show_mouseptr(inst->mouseptr_visible);
}
void request_resize(int w, int h)
{
- /* FIXME: currently ignored */
+ gtk_drawing_area_size(GTK_DRAWING_AREA(inst->area),
+ inst->font_width * w + 2*cfg.window_border,
+ inst->font_height * h + 2*cfg.window_border);
+}
+
+void real_palette_set(int n, int r, int g, int b)
+{
+ gboolean success[1];
+
+ inst->cols[n].red = r * 0x0101;
+ inst->cols[n].green = g * 0x0101;
+ inst->cols[n].blue = b * 0x0101;
+
+ gdk_colormap_alloc_colors(inst->colmap, inst->cols + n, 1,
+ FALSE, FALSE, success);
+ if (!success[0])
+ g_error("pterm: couldn't allocate colour %d (#%02x%02x%02x)\n",
+ n, r, g, b);
}
void palette_set(int n, int r, int g, int b)
{
- /* FIXME: currently ignored */
+ 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(first[n], r, g, b);
+ if (first[n] >= 18)
+ real_palette_set(first[n] + 1, r, g, b);
}
+
void palette_reset(void)
{
- /* FIXME: currently ignored */
+ /* This maps colour indices in 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
+ };
+ gboolean success[NCOLOURS];
+ int i;
+
+ assert(lenof(ww) == NCOLOURS);
+
+ if (!inst->colmap) {
+ inst->colmap = gdk_colormap_get_system();
+ } else {
+ gdk_colormap_free_colors(inst->colmap, inst->cols, NCOLOURS);
+ }
+
+ for (i = 0; i < NCOLOURS; i++) {
+ inst->cols[i].red = cfg.colours[ww[i]][0] * 0x0101;
+ inst->cols[i].green = cfg.colours[ww[i]][1] * 0x0101;
+ inst->cols[i].blue = cfg.colours[ww[i]][2] * 0x0101;
+ }
+
+ gdk_colormap_alloc_colors(inst->colmap, inst->cols, NCOLOURS,
+ FALSE, FALSE, success);
+ for (i = 0; i < NCOLOURS; i++) {
+ if (!success[i])
+ g_error("pterm: couldn't allocate colour %d (#%02x%02x%02x)\n",
+ i, cfg.colours[i][0], cfg.colours[i][1], cfg.colours[i][2]);
+ }
}
void write_clip(wchar_t * data, int len, int must_deselect)
GDK_SELECTION_TYPE_STRING, GDK_CURRENT_TIME);
}
+gint idle_paste_func(gpointer data); /* forward ref */
+
void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
gpointer data)
{
inst->pastein_data, inst->pastein_data_len);
term_do_paste();
+
+ if (term_paste_pending())
+ inst->term_paste_idle_id = gtk_idle_add(idle_paste_func, inst);
+}
+
+gint idle_paste_func(gpointer data)
+{
+ struct gui_data *inst = (struct gui_data *)data;
+
+ if (term_paste_pending())
+ term_paste();
+ else
+ gtk_idle_remove(inst->term_paste_idle_id);
+
+ return TRUE;
}
+
void get_clip(wchar_t ** p, int *len)
{
if (p) {
void set_icon(char *title)
{
- /* FIXME: currently ignored */
+ strncpy(inst->icontitle, title, lenof(inst->icontitle));
+ inst->icontitle[lenof(inst->icontitle)-1] = '\0';
+ gdk_window_set_icon_name(inst->window->window, inst->icontitle);
}
void set_sbar(int total, int start, int page)
{
+ if (!cfg.scrollbar)
+ return;
inst->sbar_adjust->lower = 0;
inst->sbar_adjust->upper = total;
inst->sbar_adjust->value = start;
void scrollbar_moved(GtkAdjustment *adj, gpointer data)
{
+ if (!cfg.scrollbar)
+ return;
if (!inst->ignore_sbar)
term_scroll(1, (int)adj->value);
}
/*
* NYI:
* - Unicode, code pages, and ATTR_WIDE for CJK support.
- * - LATTR_* (ESC # 4 double-width and double-height stuff)
* - cursor shapes other than block
* - shadow bolding
*/
nbg = NCOLOURS-1;
}
+ if (lattr != LATTR_NORM) {
+ x *= 2;
+ if (x >= cols)
+ return;
+ if (x + len*2 > cols)
+ len = (cols-x)/2; /* trim to LH half */
+ }
+
gdk_gc_set_foreground(gc, &inst->cols[nbg]);
gdk_draw_rectangle(inst->pixmap, gc, 1,
x*inst->font_width+cfg.window_border,
y*inst->font_height + uheight + cfg.window_border);
}
+ if (lattr != 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
+ * way. This will involve repeated calls to
+ * gdk_draw_pixmap() to stretch the text horizontally. It's
+ * O(N^2) in time and O(N) in network bandwidth, but you
+ * try thinking of a better way. :-(
+ */
+ int i;
+ for (i = 0; i < len * inst->font_width; i++) {
+ gdk_draw_pixmap(inst->pixmap, gc, inst->pixmap,
+ x*inst->font_width+cfg.window_border + 2*i,
+ y*inst->font_height+cfg.window_border,
+ x*inst->font_width+cfg.window_border + 2*i+1,
+ y*inst->font_height+cfg.window_border,
+ len * inst->font_width - i, inst->font_height);
+ }
+ len *= 2;
+ if (lattr != LATTR_WIDE) {
+ int dt, db;
+ /* Now stretch vertically, in the same way. */
+ if (lattr == LATTR_BOT)
+ dt = 0, db = 1;
+ else
+ 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+cfg.window_border,
+ y*inst->font_height+cfg.window_border+dt*i+db,
+ x*inst->font_width+cfg.window_border,
+ y*inst->font_height+cfg.window_border+dt*(i+1),
+ len * inst->font_width, inst->font_height-i-1);
+ }
+ }
+ len *= 2;
+ }
+
gdk_draw_pixmap(inst->area->window, gc, inst->pixmap,
x*inst->font_width+cfg.window_border,
y*inst->font_height+cfg.window_border,
exit(1);
}
+char *get_x_display(void)
+{
+ return gdk_get_display();
+}
+
int main(int argc, char **argv)
{
extern int pty_master_fd; /* declared in pty.c */
} else
err = 1, fprintf(stderr, "pterm: -T expects an argument\n");
}
+ if (!strcmp(p, "-log")) {
+ if (--argc > 0) {
+ strncpy(cfg.logfilename, *++argv, sizeof(cfg.logfilename));
+ cfg.logfilename[sizeof(cfg.logfilename)-1] = '\0';
+ cfg.logtype = LGTYP_DEBUG;
+ } else
+ err = 1, fprintf(stderr, "pterm: -log expects an argument\n");
+ }
if (!strcmp(p, "-hide")) {
cfg.hide_mouseptr = 1;
}
+ if (!strcmp(p, "-ut-")) {
+ cfg.stamp_utmp = 0;
+ }
+ if (!strcmp(p, "-ls-")) {
+ cfg.login_shell = 0;
+ }
if (!strcmp(p, "-nethack")) {
cfg.nethack_keypad = 1;
}
+ if (!strcmp(p, "-sb-")) {
+ cfg.scrollbar = 0;
+ }
}
inst->fonts[0] = gdk_font_load(cfg.font);
init_ucs();
- back = &pty_backend;
- back->init(NULL, 0, NULL, 0);
-
inst->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
if (cfg.wintitle[0])
else
set_title("pterm");
+ /*
+ * Set up the colour map.
+ */
+ palette_reset();
+
inst->area = gtk_drawing_area_new();
gtk_drawing_area_size(GTK_DRAWING_AREA(inst->area),
inst->font_width * cfg.width + 2*cfg.window_border,
inst->font_height * cfg.height + 2*cfg.window_border);
- inst->sbar_adjust = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 0, 0, 0, 0));
- inst->sbar = gtk_vscrollbar_new(inst->sbar_adjust);
+ if (cfg.scrollbar) {
+ 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));
gtk_box_pack_start(inst->hbox, inst->area, TRUE, TRUE, 0);
- gtk_box_pack_end(inst->hbox, inst->sbar, FALSE, FALSE, 0);
+ if (cfg.scrollbar)
+ gtk_box_pack_start(inst->hbox, inst->sbar, FALSE, FALSE, 0);
+
+ gtk_window_set_policy(GTK_WINDOW(inst->window), FALSE, TRUE, TRUE);
gtk_container_add(GTK_CONTAINER(inst->window), GTK_WIDGET(inst->hbox));
GTK_SIGNAL_FUNC(selection_get), inst);
gtk_signal_connect(GTK_OBJECT(inst->area), "selection_clear_event",
GTK_SIGNAL_FUNC(selection_clear), inst);
- gtk_signal_connect(GTK_OBJECT(inst->sbar_adjust), "value_changed",
- GTK_SIGNAL_FUNC(scrollbar_moved), inst);
+ if (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);
- gdk_input_add(pty_master_fd, GDK_INPUT_READ, pty_input_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 |
GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK);
gtk_widget_show(inst->area);
- gtk_widget_show(inst->sbar);
+ if (cfg.scrollbar)
+ gtk_widget_show(inst->sbar);
gtk_widget_show(GTK_WIDGET(inst->hbox));
gtk_widget_show(inst->window);
inst->currcursor = inst->textcursor;
show_mouseptr(1);
+ back = &pty_backend;
+ back->init(NULL, 0, NULL, 0);
+
+ gdk_input_add(pty_master_fd, GDK_INPUT_READ, pty_input_func, inst);
+
term_init();
- term_size(24, 80, 2000);
+ term_size(cfg.height, cfg.width, cfg.savelines);
gtk_main();