#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
+#include <gdk/gdkx.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
#define PUTTY_DO_GLOBALS /* actually _define_ globals */
#include "putty.h"
guint term_paste_idle_id;
GdkAtom compound_text_atom;
int alt_keycode;
+ int alt_digits;
char wintitle[sizeof(((Config *)0)->wintitle)];
char icontitle[sizeof(((Config *)0)->wintitle)];
int master_fd, master_func_id, exited;
+ void *ldisc;
+ Backend *back;
+ void *backhandle;
+ Terminal *term;
+ void *logctx;
+};
+
+struct draw_ctx {
+ GdkGC *gc;
+ struct gui_data *inst;
};
-static struct gui_data the_inst;
-static struct gui_data *inst = &the_inst; /* so we always write `inst->' */
static int send_raw_mouse;
-void ldisc_update(int echo, int edit)
+static char *app_name = "pterm";
+
+char *x_get_default(char *key)
+{
+ return XGetDefault(GDK_DISPLAY(), app_name, key);
+}
+
+void ldisc_update(void *frontend, int echo, int edit)
{
/*
* This is a stub in pterm. If I ever produce a Unix
*/
}
-int askappend(char *filename)
+int askappend(void *frontend, char *filename)
{
/*
* Logging in an xterm-alike is liable to be something you only
return 2;
}
-void logevent(char *string)
+void logevent(void *frontend, char *string)
{
/*
* This is not a very helpful function: events are logged
*/
}
-int font_dimension(int which) /* 0 for width, 1 for height */
+int font_dimension(void *frontend, int which)/* 0 for width, 1 for height */
{
+ struct gui_data *inst = (struct gui_data *)frontend;
+
if (which)
return inst->font_height;
else
* mouse or a means of faking it, and there is no need to switch
* buttons around at all.
*/
-Mouse_Button translate_button(Mouse_Button button)
+Mouse_Button translate_button(void *frontend, Mouse_Button button)
{
+ /* struct gui_data *inst = (struct gui_data *)frontend; */
+
if (button == MBT_LEFT)
return MBT_SELECT;
if (button == MBT_MIDDLE)
* Minimise or restore the window in response to a server-side
* request.
*/
-void set_iconic(int iconic)
+void set_iconic(void *frontend, int iconic)
{
/*
* GTK 1.2 doesn't know how to do this.
*/
#if GTK_CHECK_VERSION(2,0,0)
+ struct gui_data *inst = (struct gui_data *)frontend;
if (iconic)
gtk_window_iconify(GTK_WINDOW(inst->window));
else
/*
* Move the window in response to a server-side request.
*/
-void move_window(int x, int y)
+void move_window(void *frontend, int x, int y)
{
+ struct gui_data *inst = (struct gui_data *)frontend;
/*
* 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,
* Move the window to the top or bottom of the z-order in response
* to a server-side request.
*/
-void set_zorder(int top)
+void set_zorder(void *frontend, int top)
{
+ struct gui_data *inst = (struct gui_data *)frontend;
if (top)
gdk_window_raise(inst->window->window);
else
/*
* Refresh the window in response to a server-side request.
*/
-void refresh_window(void)
+void refresh_window(void *frontend)
{
- term_invalidate(term);
+ struct gui_data *inst = (struct gui_data *)frontend;
+ term_invalidate(inst->term);
}
/*
* Maximise or restore the window in response to a server-side
* request.
*/
-void set_zoomed(int zoomed)
+void set_zoomed(void *frontend, int zoomed)
{
/*
* GTK 1.2 doesn't know how to do this.
*/
#if GTK_CHECK_VERSION(2,0,0)
+ struct gui_data *inst = (struct gui_data *)frontend;
if (iconic)
gtk_window_maximize(GTK_WINDOW(inst->window));
else
/*
* Report whether the window is iconic, for terminal reports.
*/
-int is_iconic(void)
+int is_iconic(void *frontend)
{
+ struct gui_data *inst = (struct gui_data *)frontend;
return !gdk_window_is_viewable(inst->window->window);
}
/*
* Report the window's position, for terminal reports.
*/
-void get_window_pos(int *x, int *y)
+void get_window_pos(void *frontend, int *x, int *y)
{
+ struct gui_data *inst = (struct gui_data *)frontend;
/*
* 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,
/*
* Report the window's pixel size, for terminal reports.
*/
-void get_window_pixels(int *x, int *y)
+void get_window_pixels(void *frontend, int *x, int *y)
{
+ struct gui_data *inst = (struct gui_data *)frontend;
/*
* 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,
/*
* Return the window or icon title.
*/
-char *get_window_title(int icon)
+char *get_window_title(void *frontend, int icon)
{
+ struct gui_data *inst = (struct gui_data *)frontend;
return icon ? inst->wintitle : inst->icontitle;
}
return FALSE;
}
-void show_mouseptr(int show)
+static void show_mouseptr(struct gui_data *inst, int show)
{
if (!cfg.hide_mouseptr)
show = 1;
}
if (need_size) {
- term_size(term, h, w, cfg.savelines);
+ term_size(inst->term, h, w, cfg.savelines);
}
return TRUE;
gint expose_area(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
- /* struct gui_data *inst = (struct gui_data *)data; */
+ struct gui_data *inst = (struct gui_data *)data;
/*
* Pass the exposed rectangle to terminal.c, which will call us
gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
- /* struct gui_data *inst = (struct gui_data *)data; */
+ struct gui_data *inst = (struct gui_data *)data;
char output[32];
int start, end;
/*
* If Alt is being released after typing an Alt+numberpad
* sequence, we should generate the code that was typed.
+ *
+ * Note that we only do this if more than one key was actually
+ * pressed - I don't think Alt+NumPad4 should be ^D or that
+ * Alt+NumPad3 should be ^C, for example. There's no serious
+ * 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_keycode >= 0 && inst->alt_digits > 1) {
#ifdef KEY_DEBUGGING
printf("Alt key up, keycode = %d\n", inst->alt_keycode);
#endif
if ((event->keyval == GDK_Meta_L || event->keyval == GDK_Alt_L ||
event->keyval == GDK_Meta_R || event->keyval == GDK_Alt_R)) {
inst->alt_keycode = -1;
+ inst->alt_digits = 0;
goto done; /* this generates nothing else */
}
inst->alt_keycode = digit; /* one-digit code */
else
inst->alt_keycode = inst->alt_keycode * 10 + digit;
+ inst->alt_digits++;
#ifdef KEY_DEBUGGING
printf(" gives new code %d\n", inst->alt_keycode);
#endif
* at all.
*/
if (event->keyval == GDK_Page_Up && (event->state & GDK_SHIFT_MASK)) {
- term_scroll(term, 0, -cfg.height/2);
+ term_scroll(inst->term, 0, -cfg.height/2);
return TRUE;
}
if (event->keyval == GDK_Page_Down && (event->state & GDK_SHIFT_MASK)) {
- term_scroll(term, 0, +cfg.height/2);
+ term_scroll(inst->term, 0, +cfg.height/2);
return TRUE;
}
* Neither does Shift-Ins.
*/
if (event->keyval == GDK_Insert && (event->state & GDK_SHIFT_MASK)) {
- request_paste();
+ request_paste(inst);
return TRUE;
}
/*
* Application keypad mode.
*/
- if (term->app_keypad_keys && !cfg.no_applic_k) {
+ if (inst->term->app_keypad_keys && !cfg.no_applic_k) {
int xkey = 0;
switch (event->keyval) {
case GDK_Num_Lock: xkey = 'P'; break;
case GDK_KP_Decimal: case GDK_KP_Delete: xkey = 'n'; break;
}
if (xkey) {
- if (term->vt52_mode) {
+ if (inst->term->vt52_mode) {
if (xkey >= 'P' && xkey <= 'S')
end = 1 + sprintf(output+1, "\033%c", xkey);
else
if (cfg.funky_type == 3 && code <= 6)
code = "\0\2\1\4\5\3\6"[code];
- if (term->vt52_mode && code > 0 && code <= 6) {
+ if (inst->term->vt52_mode && code > 0 && code <= 6) {
end = 1 + sprintf(output+1, "\x1B%c", " HLMEIG"[code]);
goto done;
}
}
goto done;
}
- if ((term->vt52_mode || cfg.funky_type == 4) &&
+ if ((inst->term->vt52_mode || cfg.funky_type == 4) &&
code >= 11 && code <= 24) {
int offt = 0;
if (code > 15)
offt++;
if (code > 21)
offt++;
- if (term->vt52_mode)
+ if (inst->term->vt52_mode)
end = 1 + sprintf(output+1,
"\x1B%c", code + 'P' - 11 - offt);
else
goto done;
}
if (cfg.funky_type == 2 && code >= 11 && code <= 14) {
- if (term->vt52_mode)
+ if (inst->term->vt52_mode)
end = 1 + sprintf(output+1, "\x1B%c", code + 'P' - 11);
else
end = 1 + sprintf(output+1, "\x1BO%c", code + 'P' - 11);
* app cursor keys mode they do ESC O A instead.
* Ctrl toggles the two modes.
*/
- if (term->vt52_mode) {
+ if (inst->term->vt52_mode) {
end = 1 + sprintf(output+1, "\033%c", xkey);
- } else if (!term->app_cursor_keys ^
+ } else if (!inst->term->app_cursor_keys ^
!(event->state & GDK_CONTROL_MASK)) {
end = 1 + sprintf(output+1, "\033O%c", xkey);
} else {
printf("\n");
#endif
- ldisc_send(output+start, end-start, 1);
- show_mouseptr(0);
- term_seen_key_event(term);
- term_out(term);
+ ldisc_send(inst->ldisc, output+start, end-start, 1);
+ show_mouseptr(inst, 0);
+ term_seen_key_event(inst->term);
+ term_out(inst->term);
}
return TRUE;
struct gui_data *inst = (struct gui_data *)data;
int shift, ctrl, alt, x, y, button, act;
- show_mouseptr(1);
+ show_mouseptr(inst, 1);
if (event->button == 4 && event->type == GDK_BUTTON_PRESS) {
- term_scroll(term, 0, -5);
+ term_scroll(inst->term, 0, -5);
return TRUE;
}
if (event->button == 5 && event->type == GDK_BUTTON_PRESS) {
- term_scroll(term, 0, +5);
+ term_scroll(inst->term, 0, +5);
return TRUE;
}
x = (event->x - cfg.window_border) / inst->font_width;
y = (event->y - cfg.window_border) / inst->font_height;
- term_mouse(term, button, act, x, y, shift, ctrl, alt);
+ term_mouse(inst->term, button, act, x, y, shift, ctrl, alt);
return TRUE;
}
struct gui_data *inst = (struct gui_data *)data;
int shift, ctrl, alt, x, y, button;
- show_mouseptr(1);
+ show_mouseptr(inst, 1);
shift = event->state & GDK_SHIFT_MASK;
ctrl = event->state & GDK_CONTROL_MASK;
x = (event->x - cfg.window_border) / inst->font_width;
y = (event->y - cfg.window_border) / inst->font_height;
- term_mouse(term, button, MA_DRAG, x, y, shift, ctrl, alt);
+ term_mouse(inst->term, button, MA_DRAG, x, y, shift, ctrl, alt);
return TRUE;
}
gtk_input_remove(inst->master_func_id);
}
- if (!inst->exited && back->exitcode(backhandle) >= 0) {
- int exitcode = back->exitcode(backhandle);
+ if (!inst->exited && inst->back->exitcode(inst->backhandle) >= 0) {
+ int exitcode = inst->back->exitcode(inst->backhandle);
int clean;
clean = WIFEXITED(exitcode) && (WEXITSTATUS(exitcode) == 0);
" %d (%.400s)]\r\n", WTERMSIG(exitcode),
strsignal(WTERMSIG(exitcode)));
#endif
- from_backend((void *)term, 0, message, strlen(message));
+ from_backend((void *)inst->term, 0, message, strlen(message));
}
inst->exited = 1;
}
}
-void frontend_keypress(void)
+void frontend_keypress(void *handle)
{
+ struct gui_data *inst = (struct gui_data *)handle;
+
/*
* If our child process has exited but not closed, terminate on
* any keypress.
{
struct gui_data *inst = (struct gui_data *)data;
- if (back->exitcode(backhandle) >= 0) {
+ if (inst->back->exitcode(inst->backhandle) >= 0) {
/*
* The primary child process died. We could keep the
* terminal open for remaining subprocesses to output to,
done_with_pty(inst);
}
- term_update(term);
- term_blink(term, 0);
+ term_update(inst->term);
+ term_blink(inst->term, 0);
return TRUE;
}
perror("read pty master");
exit(1);
} else if (ret > 0)
- from_backend(term, 0, buf, ret);
- term_blink(term, 1);
- term_out(term);
+ from_backend(inst->term, 0, buf, ret);
+ term_blink(inst->term, 1);
+ term_out(inst->term);
}
void destroy(GtkWidget *widget, gpointer data)
gint focus_event(GtkWidget *widget, GdkEventFocus *event, gpointer data)
{
- term->has_focus = event->in;
- term_out(term);
- term_update(term);
- show_mouseptr(1);
+ struct gui_data *inst = (struct gui_data *)data;
+ inst->term->has_focus = event->in;
+ term_out(inst->term);
+ term_update(inst->term);
+ show_mouseptr(inst, 1);
return FALSE;
}
/*
* set or clear the "raw mouse message" mode
*/
-void set_raw_mouse_mode(int activate)
+void set_raw_mouse_mode(void *frontend, int activate)
{
+ struct gui_data *inst = (struct gui_data *)frontend;
activate = activate && !cfg.no_mouse_rep;
send_raw_mouse = activate;
if (send_raw_mouse)
inst->currcursor = inst->rawcursor;
else
inst->currcursor = inst->textcursor;
- show_mouseptr(inst->mouseptr_visible);
+ show_mouseptr(inst, inst->mouseptr_visible);
}
-void request_resize(int w, int h)
+void request_resize(void *frontend, int w, int h)
{
+ struct gui_data *inst = (struct gui_data *)frontend;
int large_x, large_y;
int offset_x, offset_y;
int area_x, area_y;
* bogus size request which guarantees to be bigger than the
* current size of the drawing area.
*/
- get_window_pixels(&large_x, &large_y);
+ get_window_pixels(inst, &large_x, &large_y);
large_x += 32;
large_y += 32;
#endif
}
-void real_palette_set(int n, int r, int g, int b)
+static void real_palette_set(struct gui_data *inst, int n, int r, int g, int b)
{
gboolean success[1];
n, r, g, b);
}
-void set_window_background(void)
+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->window->window, &inst->cols[18]);
}
-void palette_set(int n, int r, int g, int b)
+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(first[n], r, g, b);
+ real_palette_set(inst, first[n], r, g, b);
if (first[n] >= 18)
- real_palette_set(first[n] + 1, r, g, b);
+ real_palette_set(inst, first[n] + 1, r, g, b);
if (first[n] == 18)
- set_window_background();
+ set_window_background(inst);
}
-void palette_reset(void)
+void palette_reset(void *frontend)
{
+ struct gui_data *inst = (struct gui_data *)frontend;
/* This maps colour indices in cfg to those used in inst->cols. */
static const int ww[] = {
6, 7, 8, 9, 10, 11, 12, 13,
i, cfg.colours[i][0], cfg.colours[i][1], cfg.colours[i][2]);
}
- set_window_background();
+ set_window_background(inst);
}
-void write_clip(wchar_t * data, int len, int must_deselect)
+void write_clip(void *frontend, wchar_t * data, int len, int must_deselect)
{
+ struct gui_data *inst = (struct gui_data *)frontend;
if (inst->pasteout_data)
sfree(inst->pasteout_data);
inst->pasteout_data = smalloc(len);
void selection_get(GtkWidget *widget, GtkSelectionData *seldata,
guint info, guint time_stamp, gpointer data)
{
+ struct gui_data *inst = (struct gui_data *)data;
gtk_selection_data_set(seldata, GDK_SELECTION_TYPE_STRING, 8,
inst->pasteout_data, inst->pasteout_data_len);
}
gint selection_clear(GtkWidget *widget, GdkEventSelection *seldata,
gpointer data)
{
- term_deselect(term);
+ struct gui_data *inst = (struct gui_data *)data;
+ term_deselect(inst->term);
if (inst->pasteout_data)
sfree(inst->pasteout_data);
inst->pasteout_data = NULL;
return TRUE;
}
-void request_paste(void)
+void request_paste(void *frontend)
{
+ struct gui_data *inst = (struct gui_data *)frontend;
/*
* In Unix, pasting is asynchronous: all we can do at the
* moment is to call gtk_selection_convert(), and when the data
gint idle_paste_func(gpointer data); /* forward ref */
void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
- gpointer data)
+ guint time, gpointer data)
{
+ struct gui_data *inst = (struct gui_data *)data;
+
if (seldata->length <= 0 ||
seldata->type != GDK_SELECTION_TYPE_STRING)
return; /* Nothing happens. */
mb_to_wc(0, 0, seldata->data, seldata->length,
inst->pastein_data, inst->pastein_data_len);
- term_do_paste(term);
+ term_do_paste(inst->term);
- if (term_paste_pending(term))
+ if (term_paste_pending(inst->term))
inst->term_paste_idle_id = gtk_idle_add(idle_paste_func, inst);
}
{
struct gui_data *inst = (struct gui_data *)data;
- if (term_paste_pending(term))
- term_paste(term);
+ if (term_paste_pending(inst->term))
+ term_paste(inst->term);
else
gtk_idle_remove(inst->term_paste_idle_id);
}
-void get_clip(wchar_t ** p, int *len)
+void get_clip(void *frontend, wchar_t ** p, int *len)
{
+ struct gui_data *inst = (struct gui_data *)frontend;
+
if (p) {
*p = inst->pastein_data;
*len = inst->pastein_data_len;
}
}
-void set_title(char *title)
+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';
gtk_window_set_title(GTK_WINDOW(inst->window), inst->wintitle);
}
-void set_icon(char *title)
+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';
gdk_window_set_icon_name(inst->window->window, inst->icontitle);
}
-void set_sbar(int total, int start, int page)
+void set_sbar(void *frontend, int total, int start, int page)
{
+ struct gui_data *inst = (struct gui_data *)frontend;
if (!cfg.scrollbar)
return;
inst->sbar_adjust->lower = 0;
void scrollbar_moved(GtkAdjustment *adj, gpointer data)
{
+ struct gui_data *inst = (struct gui_data *)data;
+
if (!cfg.scrollbar)
return;
if (!inst->ignore_sbar)
- term_scroll(term, 1, (int)adj->value);
+ term_scroll(inst->term, 1, (int)adj->value);
}
-void sys_cursor(int x, int y)
+void sys_cursor(void *frontend, int x, int y)
{
/*
* This is meaningless under X.
*/
}
-void beep(int mode)
+/*
+ * This is still called when mode==BELL_VISUAL, even though the
+ * visual bell is handled entirely within terminal.c, because we
+ * may want to perform additional actions on any kind of bell (for
+ * example, taskbar flashing in Windows).
+ */
+void beep(void *frontend, int mode)
{
- gdk_beep();
+ if (mode != BELL_VISUAL)
+ gdk_beep();
}
-int CharWidth(Context ctx, int uc)
+int char_width(Context ctx, int uc)
{
/*
* Under X, any fixed-width font really _is_ fixed-width.
return 1;
}
-Context get_ctx(void)
+Context get_ctx(void *frontend)
{
- GdkGC *gc;
+ struct gui_data *inst = (struct gui_data *)frontend;
+ struct draw_ctx *dctx;
+
if (!inst->area->window)
return NULL;
- gc = gdk_gc_new(inst->area->window);
- return gc;
+
+ dctx = smalloc(sizeof(*dctx));
+ dctx->inst = inst;
+ dctx->gc = gdk_gc_new(inst->area->window);
+ return dctx;
}
void free_ctx(Context ctx)
{
- GdkGC *gc = (GdkGC *)ctx;
+ struct draw_ctx *dctx = (struct draw_ctx *)ctx;
+ /* struct gui_data *inst = dctx->inst; */
+ GdkGC *gc = dctx->gc;
gdk_gc_unref(gc);
+ sfree(dctx);
}
/*
void do_text_internal(Context ctx, int x, int y, char *text, int len,
unsigned long attr, int lattr)
{
- int nfg, nbg, t, fontid, shadow;
- GdkGC *gc = (GdkGC *)ctx;
+ struct draw_ctx *dctx = (struct draw_ctx *)ctx;
+ struct gui_data *inst = dctx->inst;
+ GdkGC *gc = dctx->gc;
+
+ int nfg, nbg, t, fontid, shadow, rlen;
/*
* NYI:
if (lattr != LATTR_NORM) {
x *= 2;
- if (x >= term->cols)
+ if (x >= inst->term->cols)
return;
- if (x + len*2 > term->cols)
- len = (term->cols-x)/2; /* trim to LH half */
+ if (x + len*2 > inst->term->cols)
+ len = (inst->term->cols-x)/2; /* trim to LH half */
+ rlen = len * 2;
+ } else
+ rlen = len;
+
+ {
+ GdkRectangle r;
+
+ r.x = x*inst->font_width+cfg.window_border;
+ r.y = y*inst->font_height+cfg.window_border;
+ r.width = rlen*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+cfg.window_border,
y*inst->font_height+cfg.window_border,
- len*inst->font_width, inst->font_height);
+ rlen*inst->font_width, inst->font_height);
gdk_gc_set_foreground(gc, &inst->cols[nfg]);
gdk_draw_text(inst->pixmap, inst->fonts[fontid], gc,
void do_text(Context ctx, int x, int y, char *text, int len,
unsigned long attr, int lattr)
{
- GdkGC *gc = (GdkGC *)ctx;
+ struct draw_ctx *dctx = (struct draw_ctx *)ctx;
+ struct gui_data *inst = dctx->inst;
+ GdkGC *gc = dctx->gc;
do_text_internal(ctx, x, y, text, len, attr, lattr);
if (lattr != LATTR_NORM) {
x *= 2;
- if (x >= term->cols)
+ if (x >= inst->term->cols)
return;
- if (x + len*2 > term->cols)
- len = (term->cols-x)/2; /* trim to LH half */
+ if (x + len*2 > inst->term->cols)
+ len = (inst->term->cols-x)/2; /* trim to LH half */
len *= 2;
}
void do_cursor(Context ctx, int x, int y, char *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 passive;
- GdkGC *gc = (GdkGC *)ctx;
if (attr & TATTR_PASCURS) {
attr &= ~TATTR_PASCURS;
if (lattr != LATTR_NORM) {
x *= 2;
- if (x >= term->cols)
+ if (x >= inst->term->cols)
return;
- if (x + len*2 > term->cols)
- len = (term->cols-x)/2; /* trim to LH half */
+ if (x + len*2 > inst->term->cols)
+ len = (inst->term->cols-x)/2; /* trim to LH half */
len *= 2;
}
len*inst->font_width, inst->font_height);
}
-GdkCursor *make_mouse_ptr(int cursor_val)
+GdkCursor *make_mouse_ptr(struct gui_data *inst, int cursor_val)
{
/*
* Truly hideous hack: GTK doesn't allow us to set the mouse
exit(1);
}
-char *get_x_display(void)
+char *get_x_display(void *frontend)
{
return gdk_get_display();
}
-char *app_name = "pterm";
+static void help(FILE *fp) {
+ if(fprintf(fp,
+"pterm option summary:\n"
+"\n"
+" --display DISPLAY Specify X display to use (note '--')\n"
+" -name PREFIX Prefix when looking up resources (default: pterm)\n"
+" -fn FONT Normal text font\n"
+" -fb FONT Bold text font\n"
+" -geometry WIDTHxHEIGHT Size of terminal in characters\n"
+" -sl LINES Number of lines of scrollback\n"
+" -fg COLOUR, -bg COLOUR Foreground/background colour\n"
+" -bfg COLOUR, -bbg COLOUR Foreground/background bold colour\n"
+" -cfg COLOUR, -bfg COLOUR Foreground/background cursor colour\n"
+" -T TITLE Window title\n"
+" -ut, +ut Do(default) or do not update utmp\n"
+" -ls, +ls Do(default) or do not make shell a login shell\n"
+" -sb, +sb Do(default) or do not display a scrollbar\n"
+" -log PATH Log all output to a file\n"
+" -nethack Map numeric keypad to hjklyubn direction keys\n"
+" -xrm RESOURCE-STRING Set an X resource\n"
+" -e COMMAND [ARGS...] Execute command (consumes all remaining args)\n"
+ ) < 0 || fflush(fp) < 0) {
+ perror("output error");
+ exit(1);
+ }
+}
int do_cmdline(int argc, char **argv, int do_everything)
{
extern char **pty_argv; /* declared in pty.c */
/*
- * Macros to make argument handling easier.
+ * Macros to make argument handling easier. Note that because
+ * they need to call `continue', they cannot be contained in
+ * the usual do {...} while (0) wrapper to make them
+ * syntactically single statements; hence it is not legal to
+ * use one of these macros as an unbraced statement between
+ * `if' and `else'.
*/
-#define EXPECTS_ARG do { \
+#define EXPECTS_ARG { \
if (--argc <= 0) { \
err = 1; \
fprintf(stderr, "pterm: %s expects an argument\n", p); \
+ continue; \
} else \
val = *++argv; \
-} while (0)
-#define SECOND_PASS_ONLY do { \
- if (!do_everything) continue; \
-} while (0)
+}
+#define SECOND_PASS_ONLY { if (!do_everything) continue; }
/*
* TODO:
EXPECTS_ARG;
provide_xrm_string(val);
+ } else if(!strcmp(p, "-help") || !strcmp(p, "--help")) {
+ help(stdout);
+ exit(0);
+
} else {
err = 1;
fprintf(stderr, "pterm: unrecognized option '%s'\n", p);
return err;
}
+static void block_signal(int sig, int block_it) {
+ sigset_t ss;
+
+ sigemptyset(&ss);
+ sigaddset(&ss, sig);
+ if(sigprocmask(block_it ? SIG_BLOCK : SIG_UNBLOCK, &ss, 0) < 0) {
+ perror("sigprocmask");
+ exit(1);
+ }
+}
+
int main(int argc, char **argv)
{
extern int pty_master_fd; /* declared in pty.c */
extern void pty_pre_init(void); /* declared in pty.c */
+ struct gui_data *inst;
+
+ /* defer any child exit handling until we're ready to deal with
+ * it */
+ block_signal(SIGCHLD, 1);
pty_pre_init();
exit(1);
/*
- * Initialise the whole instance structure to zeroes
+ * Create an instance structure and initialise to zeroes
*/
+ inst = smalloc(sizeof(*inst));
memset(inst, 0, sizeof(*inst));
+ inst->alt_keycode = -1; /* this one needs _not_ to be zero */
inst->fonts[0] = gdk_font_load(cfg.font);
if (!inst->fonts[0]) {
inst->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
if (cfg.wintitle[0])
- set_title(cfg.wintitle);
+ set_title(inst, cfg.wintitle);
else
- set_title("pterm");
+ set_title(inst, "pterm");
/*
* Set up the colour map.
*/
- palette_reset();
+ palette_reset(inst);
inst->area = gtk_drawing_area_new();
gtk_drawing_area_size(GTK_DRAWING_AREA(inst->area),
gtk_widget_show(GTK_WIDGET(inst->hbox));
gtk_widget_show(inst->window);
- set_window_background();
+ set_window_background(inst);
- inst->textcursor = make_mouse_ptr(GDK_XTERM);
- inst->rawcursor = make_mouse_ptr(GDK_LEFT_PTR);
- inst->blankcursor = make_mouse_ptr(-1);
- make_mouse_ptr(-2); /* clean up cursor font */
+ inst->textcursor = make_mouse_ptr(inst, GDK_XTERM);
+ inst->rawcursor = make_mouse_ptr(inst, GDK_LEFT_PTR);
+ inst->blankcursor = make_mouse_ptr(inst, -1);
+ make_mouse_ptr(inst, -2); /* clean up cursor font */
inst->currcursor = inst->textcursor;
- show_mouseptr(1);
+ show_mouseptr(inst, 1);
+
+ inst->term = term_init(&cfg, inst);
+ inst->logctx = log_init(inst);
+ term_provide_logctx(inst->term, inst->logctx);
- term = term_init();
+ inst->back = &pty_backend;
+ inst->back->init((void *)inst->term, &inst->backhandle, NULL, 0, NULL, 0);
+ inst->back->provide_logctx(inst->backhandle, inst->logctx);
- back = &pty_backend;
- back->init((void *)term, &backhandle, NULL, 0, NULL, 0);
+ term_provide_resize_fn(inst->term, inst->back->size, inst->backhandle);
- term_provide_resize_fn(term, back->size, backhandle);
+ term_size(inst->term, cfg.height, cfg.width, cfg.savelines);
- term_size(term, cfg.height, cfg.width, cfg.savelines);
- ldisc_send(NULL, 0, 0); /* cause ldisc to notice changes */
+ inst->ldisc =
+ ldisc_create(&cfg, inst->term, inst->back, inst->backhandle, inst);
+ ldisc_send(inst->ldisc, NULL, 0, 0);/* cause ldisc to notice changes */
inst->master_fd = pty_master_fd;
inst->exited = FALSE;
inst->master_func_id = gdk_input_add(pty_master_fd, GDK_INPUT_READ,
pty_input_func, inst);
+ /* now we're reday to deal with the child exit handler being
+ * called */
+ block_signal(SIGCHLD, 0);
+
gtk_main();
return 0;