Diff

Differences From Artifact [c0d8fc86cd]:

To Artifact [3aca7effcf]:


63
64
65
66
67
68
69

70
71
72
73
74
75
76
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77







+







    char icontitle[sizeof(((Config *)0)->wintitle)];
    int master_fd, master_func_id, exited;
    void *ldisc;
    Backend *back;
    void *backhandle;
    Terminal *term;
    void *logctx;
    Config cfg;
};

struct draw_ctx {
    GdkGC *gc;
    struct gui_data *inst;
};

299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
314
315
316
317
318
319
320
321


322
323

324
325
326
327
328
329


330
331
332
333
334
335
336
337
338
339




340
341
342
343
344
345


346
347
348
349
350

351
352
353
354
355
356
357
300
301
302
303
304
305
306

307
308
309
310
311
312
313
314
315
316
317
318
319
320


321
322
323

324
325
326
327
328


329
330
331
332
333
334
335
336




337
338
339
340
341
342
343
344


345
346
347
348
349
350

351
352
353
354
355
356
357
358







-
+













-
-
+
+

-
+




-
-
+
+






-
-
-
-
+
+
+
+




-
-
+
+




-
+







     * to.
     */
    return FALSE;
}

static void show_mouseptr(struct gui_data *inst, int show)
{
    if (!cfg.hide_mouseptr)
    if (!inst->cfg.hide_mouseptr)
	show = 1;
    if (show)
	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;

    w = (event->width - 2*cfg.window_border) / inst->font_width;
    h = (event->height - 2*cfg.window_border) / inst->font_height;
    w = (event->width - 2*inst->cfg.window_border) / inst->font_width;
    h = (event->height - 2*inst->cfg.window_border) / inst->font_height;

    if (w != cfg.width || h != cfg.height) {
    if (w != inst->cfg.width || h != inst->cfg.height) {
	if (inst->pixmap) {
	    gdk_pixmap_unref(inst->pixmap);
	    inst->pixmap = NULL;
	}
	cfg.width = w;
	cfg.height = h;
	inst->cfg.width = w;
	inst->cfg.height = h;
	need_size = 1;
    }
    if (!inst->pixmap) {
	GdkGC *gc;

	inst->pixmap = gdk_pixmap_new(widget->window,
				      (cfg.width * inst->font_width +
				       2*cfg.window_border),
				      (cfg.height * inst->font_height +
				       2*cfg.window_border), -1);
				      (inst->cfg.width * inst->font_width +
				       2*inst->cfg.window_border),
				      (inst->cfg.height * inst->font_height +
				       2*inst->cfg.window_border), -1);

	gc = gdk_gc_new(inst->area->window);
	gdk_gc_set_foreground(gc, &inst->cols[18]);   /* default background */
	gdk_draw_rectangle(inst->pixmap, gc, 1, 0, 0,
			   cfg.width * inst->font_width + 2*cfg.window_border,
			   cfg.height * inst->font_height + 2*cfg.window_border);
			   inst->cfg.width * inst->font_width + 2*inst->cfg.window_border,
			   inst->cfg.height * inst->font_height + 2*inst->cfg.window_border);
	gdk_gc_unref(gc);
    }

    if (need_size) {
	term_size(inst->term, h, w, cfg.savelines);
	term_size(inst->term, h, w, inst->cfg.savelines);
    }

    return TRUE;
}

gint expose_area(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
475
476
477
478
479
480
481
482

483
484
485
486

487
488
489
490
491
492
493
476
477
478
479
480
481
482

483
484
485
486

487
488
489
490
491
492
493
494







-
+



-
+







	}

	/*
	 * Shift-PgUp and Shift-PgDn don't even generate keystrokes
	 * at all.
	 */
	if (event->keyval == GDK_Page_Up && (event->state & GDK_SHIFT_MASK)) {
	    term_scroll(inst->term, 0, -cfg.height/2);
	    term_scroll(inst->term, 0, -inst->cfg.height/2);
	    return TRUE;
	}
	if (event->keyval == GDK_Page_Down && (event->state & GDK_SHIFT_MASK)) {
	    term_scroll(inst->term, 0, +cfg.height/2);
	    term_scroll(inst->term, 0, +inst->cfg.height/2);
	    return TRUE;
	}

	/*
	 * Neither does Shift-Ins.
	 */
	if (event->keyval == GDK_Insert && (event->state & GDK_SHIFT_MASK)) {
537
538
539
540
541
542
543
544

545
546
547
548
549
550

551
552
553
554
555
556
557
558
559
560
561
562
563

564
565
566
567
568
569
570
538
539
540
541
542
543
544

545
546
547
548
549
550

551
552
553
554
555
556
557
558
559
560
561
562
563

564
565
566
567
568
569
570
571







-
+





-
+












-
+







	    output[1] = '\240';
	    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] = cfg.bksp_is_delete ? '\x7F' : '\x08';
	    output[1] = inst->cfg.bksp_is_delete ? '\x7F' : '\x08';
	    end = 2;
	}
	/* For Shift Backspace, do opposite of what is configured. */
	if (event->keyval == GDK_BackSpace &&
	    (event->state & GDK_SHIFT_MASK)) {
	    output[1] = cfg.bksp_is_delete ? '\x08' : '\x7F';
	    output[1] = inst->cfg.bksp_is_delete ? '\x08' : '\x7F';
	    end = 2;
	}

	/* Shift-Tab is ESC [ Z */
	if (event->keyval == GDK_ISO_Left_Tab ||
	    (event->keyval == GDK_Tab && (event->state & GDK_SHIFT_MASK))) {
	    end = 1 + sprintf(output+1, "\033[Z");
	}

	/*
	 * NetHack keypad mode.
	 */
	if (cfg.nethack_keypad) {
	if (inst->cfg.nethack_keypad) {
	    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;
582
583
584
585
586
587
588
589

590
591
592
593
594
595
596
597
598
599
600
601
602
603

604
605
606
607
608
609
610
583
584
585
586
587
588
589

590
591
592
593
594
595
596
597
598
599
600
601
602
603

604
605
606
607
608
609
610
611







-
+













-
+







		goto done;
	    }
	}

	/*
	 * Application keypad mode.
	 */
	if (inst->term->app_keypad_keys && !cfg.no_applic_k) {
	if (inst->term->app_keypad_keys && !inst->cfg.no_applic_k) {
	    int xkey = 0;
	    switch (event->keyval) {
	      case GDK_Num_Lock: xkey = 'P'; break;
	      case GDK_KP_Divide: xkey = 'Q'; break;
	      case GDK_KP_Multiply: xkey = 'R'; break;
	      case GDK_KP_Subtract: xkey = 'S'; break;
		/*
		 * Keypad + is tricky. It covers a space that would
		 * be taken up on the VT100 by _two_ keys; so we
		 * let Shift select between the two. Worse still,
		 * in xterm function key mode we change which two...
		 */
	      case GDK_KP_Add:
		if (cfg.funky_type == 2) {
		if (inst->cfg.funky_type == 2) {
		    if (event->state & GDK_SHIFT_MASK)
			xkey = 'l';
		    else
			xkey = 'k';
		} else if (event->state & GDK_SHIFT_MASK)
			xkey = 'm';
		else
725
726
727
728
729
730
731
732

733
734
735
736
737
738
739
740

741
742
743
744
745
746
747
726
727
728
729
730
731
732

733
734
735
736
737
738
739
740

741
742
743
744
745
746
747
748







-
+







-
+







		code = 5;
		break;
	      case GDK_Page_Down: case GDK_KP_Page_Down:
		code = 6;
		break;
	    }
	    /* Reorder edit keys to physical order */
	    if (cfg.funky_type == 3 && code <= 6)
	    if (inst->cfg.funky_type == 3 && code <= 6)
		code = "\0\2\1\4\5\3\6"[code];

	    if (inst->term->vt52_mode && code > 0 && code <= 6) {
		end = 1 + sprintf(output+1, "\x1B%c", " HLMEIG"[code]);
		goto done;
	    }

	    if (cfg.funky_type == 5 &&     /* SCO function keys */
	    if (inst->cfg.funky_type == 5 &&     /* SCO function keys */
		code >= 11 && code <= 34) {
		char codes[] = "MNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@[\\]^_`{";
		int index = 0;
		switch (event->keyval) {
		  case GDK_F1: index = 0; break;
		  case GDK_F2: index = 1; break;
		  case GDK_F3: index = 2; break;
756
757
758
759
760
761
762
763

764
765
766
767
768
769
770
771
772
773
774

775
776
777
778
779
780
781
782
783
784
785
786
787
788
789

790
791
792
793

794
795
796
797
798
799
800

801
802
803
804
805
806
807
757
758
759
760
761
762
763

764
765
766
767
768
769
770
771
772
773
774

775
776
777
778
779
780
781
782
783
784
785
786
787
788
789

790
791
792
793

794
795
796
797
798
799
800

801
802
803
804
805
806
807
808







-
+










-
+














-
+



-
+






-
+







		  case GDK_F12: index = 11; break;
		}
		if (event->state & GDK_SHIFT_MASK) index += 12;
		if (event->state & GDK_CONTROL_MASK) index += 24;
		end = 1 + sprintf(output+1, "\x1B[%c", codes[index]);
		goto done;
	    }
	    if (cfg.funky_type == 5 &&     /* SCO small keypad */
	    if (inst->cfg.funky_type == 5 &&     /* SCO small keypad */
		code >= 1 && code <= 6) {
		char codes[] = "HL.FIG";
		if (code == 3) {
		    output[1] = '\x7F';
		    end = 2;
		} else {
		    end = 1 + sprintf(output+1, "\x1B[%c", codes[code-1]);
		}
		goto done;
	    }
	    if ((inst->term->vt52_mode || cfg.funky_type == 4) &&
	    if ((inst->term->vt52_mode || inst->cfg.funky_type == 4) &&
		code >= 11 && code <= 24) {
		int offt = 0;
		if (code > 15)
		    offt++;
		if (code > 21)
		    offt++;
		if (inst->term->vt52_mode)
		    end = 1 + sprintf(output+1,
				      "\x1B%c", code + 'P' - 11 - offt);
		else
		    end = 1 + sprintf(output+1,
				      "\x1BO%c", code + 'P' - 11 - offt);
		goto done;
	    }
	    if (cfg.funky_type == 1 && code >= 11 && code <= 15) {
	    if (inst->cfg.funky_type == 1 && code >= 11 && code <= 15) {
		end = 1 + sprintf(output+1, "\x1B[[%c", code + 'A' - 11);
		goto done;
	    }
	    if (cfg.funky_type == 2 && code >= 11 && code <= 14) {
	    if (inst->cfg.funky_type == 2 && code >= 11 && code <= 14) {
		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);
		goto done;
	    }
	    if (cfg.rxvt_homeend && (code == 1 || code == 4)) {
	    if (inst->cfg.rxvt_homeend && (code == 1 || code == 4)) {
		end = 1 + sprintf(output+1, code == 1 ? "\x1B[H" : "\x1BOw");
		goto done;
	    }
	    if (code) {
		end = 1 + sprintf(output+1, "\x1B[%d~", code);
		goto done;
	    }
916
917
918
919
920
921
922
923

924
925
926
927
928


929
930
931
932
933
934
935
917
918
919
920
921
922
923

924
925
926
927


928
929
930
931
932
933
934
935
936







-
+



-
-
+
+







      case GDK_BUTTON_PRESS: act = MA_CLICK; break;
      case GDK_BUTTON_RELEASE: act = MA_RELEASE; break;
      case GDK_2BUTTON_PRESS: act = MA_2CLK; break;
      case GDK_3BUTTON_PRESS: act = MA_3CLK; break;
      default: return FALSE;	       /* don't know this event type */
    }

    if (send_raw_mouse && !(cfg.mouse_override && shift) &&
    if (send_raw_mouse && !(inst->cfg.mouse_override && shift) &&
	act != MA_CLICK && act != MA_RELEASE)
	return TRUE;		       /* we ignore these in raw mouse mode */

    x = (event->x - cfg.window_border) / inst->font_width;
    y = (event->y - cfg.window_border) / inst->font_height;
    x = (event->x - inst->cfg.window_border) / inst->font_width;
    y = (event->y - inst->cfg.window_border) / inst->font_height;

    term_mouse(inst->term, button, act, x, y, shift, ctrl, alt);

    return TRUE;
}

gint motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
947
948
949
950
951
952
953
954
955


956
957
958
959
960
961
962
948
949
950
951
952
953
954


955
956
957
958
959
960
961
962
963







-
-
+
+







    else if (event->state & GDK_BUTTON2_MASK)
	button = MBT_MIDDLE;
    else if (event->state & GDK_BUTTON3_MASK)
	button = MBT_RIGHT;
    else
	return FALSE;		       /* don't even know what button! */

    x = (event->x - cfg.window_border) / inst->font_width;
    y = (event->y - cfg.window_border) / inst->font_height;
    x = (event->x - inst->cfg.window_border) / inst->font_width;
    y = (event->y - inst->cfg.window_border) / inst->font_height;

    term_mouse(inst->term, button, MA_DRAG, x, y, shift, ctrl, alt);

    return TRUE;
}

void done_with_pty(struct gui_data *inst)
975
976
977
978
979
980
981
982
983


984
985
986
987
988
989
990
976
977
978
979
980
981
982


983
984
985
986
987
988
989
990
991







-
-
+
+








	clean = WIFEXITED(exitcode) && (WEXITSTATUS(exitcode) == 0);

	/*
	 * Terminate now, if the Close On Exit setting is
	 * appropriate.
	 */
	if (cfg.close_on_exit == COE_ALWAYS ||
	    (cfg.close_on_exit == COE_NORMAL && clean))
	if (inst->cfg.close_on_exit == COE_ALWAYS ||
	    (inst->cfg.close_on_exit == COE_NORMAL && clean))
	    exit(0);

	/*
	 * Otherwise, output an indication that the session has
	 * closed.
	 */
	{
1082
1083
1084
1085
1086
1087
1088
1089

1090
1091
1092
1093
1094
1095
1096
1083
1084
1085
1086
1087
1088
1089

1090
1091
1092
1093
1094
1095
1096
1097







-
+








/*
 * set or clear the "raw mouse message" mode
 */
void set_raw_mouse_mode(void *frontend, int activate)
{
    struct gui_data *inst = (struct gui_data *)frontend;
    activate = activate && !cfg.no_mouse_rep;
    activate = activate && !inst->cfg.no_mouse_rep;
    send_raw_mouse = activate;
    if (send_raw_mouse)
	inst->currcursor = inst->rawcursor;
    else
	inst->currcursor = inst->textcursor;
    show_mouseptr(inst, inst->mouseptr_visible);
}
1134
1135
1136
1137
1138
1139
1140
1141
1142


1143
1144
1145
1146
1147
1148
1149
1135
1136
1137
1138
1139
1140
1141


1142
1143
1144
1145
1146
1147
1148
1149
1150







-
-
+
+







#endif
    gtk_widget_size_request(inst->area, &inner);
    gtk_widget_size_request(inst->window, &outer);

    offset_x = outer.width - inner.width;
    offset_y = outer.height - inner.height;

    area_x = inst->font_width * w + 2*cfg.window_border;
    area_y = inst->font_height * h + 2*cfg.window_border;
    area_x = inst->font_width * w + 2*inst->cfg.window_border;
    area_y = inst->font_height * h + 2*inst->cfg.window_border;

    /*
     * Now we must set the size request on the drawing area back to
     * something sensible before we commit the real resize. Best
     * way to do this, I think, is to set it to what the size is
     * really going to end up being.
     */
1199
1200
1201
1202
1203
1204
1205
1206

1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226



1227
1228
1229
1230
1231
1232
1233
1234

1235
1236
1237
1238
1239
1240
1241
1200
1201
1202
1203
1204
1205
1206

1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224



1225
1226
1227
1228
1229
1230
1231
1232
1233
1234

1235
1236
1237
1238
1239
1240
1241
1242







-
+

















-
-
-
+
+
+







-
+







    if (first[n] == 18)
	set_window_background(inst);
}

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. */
    /* 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
    };
    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;
	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;
    }

    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]);
		    i, inst->cfg.colours[i][0], inst->cfg.colours[i][1], inst->cfg.colours[i][2]);
    }

    set_window_background(inst);
}

void write_clip(void *frontend, wchar_t * data, int len, int must_deselect)
{
1435
1436
1437
1438
1439
1440
1441
1442

1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459

1460
1461
1462
1463
1464
1465
1466
1436
1437
1438
1439
1440
1441
1442

1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459

1460
1461
1462
1463
1464
1465
1466
1467







-
+
















-
+







    inst->icontitle[lenof(inst->icontitle)-1] = '\0';
    gdk_window_set_icon_name(inst->window->window, inst->icontitle);
}

void set_sbar(void *frontend, int total, int start, int page)
{
    struct gui_data *inst = (struct gui_data *)frontend;
    if (!cfg.scrollbar)
    if (!inst->cfg.scrollbar)
	return;
    inst->sbar_adjust->lower = 0;
    inst->sbar_adjust->upper = total;
    inst->sbar_adjust->value = start;
    inst->sbar_adjust->page_size = page;
    inst->sbar_adjust->step_increment = 1;
    inst->sbar_adjust->page_increment = page/2;
    inst->ignore_sbar = TRUE;
    gtk_adjustment_changed(inst->sbar_adjust);
    inst->ignore_sbar = FALSE;
}

void scrollbar_moved(GtkAdjustment *adj, gpointer data)
{
    struct gui_data *inst = (struct gui_data *)data;

    if (!cfg.scrollbar)
    if (!inst->cfg.scrollbar)
	return;
    if (!inst->ignore_sbar)
	term_scroll(inst->term, 1, (int)adj->value);
}

void sys_cursor(void *frontend, int x, int y)
{
1532
1533
1534
1535
1536
1537
1538
1539

1540
1541

1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557

1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578


1579
1580
1581
1582
1583
1584
1585
1586
1587


1588
1589
1590
1591
1592
1593
1594
1533
1534
1535
1536
1537
1538
1539

1540
1541

1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557

1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577


1578
1579
1580
1581
1582
1583
1584
1585
1586


1587
1588
1589
1590
1591
1592
1593
1594
1595







-
+

-
+















-
+



















-
-
+
+







-
-
+
+







    nfg = 2 * ((attr & ATTR_FGMASK) >> ATTR_FGSHIFT);
    nbg = 2 * ((attr & ATTR_BGMASK) >> ATTR_BGSHIFT);
    if (attr & ATTR_REVERSE) {
	t = nfg;
	nfg = nbg;
	nbg = t;
    }
    if (cfg.bold_colour && (attr & ATTR_BOLD))
    if (inst->cfg.bold_colour && (attr & ATTR_BOLD))
	nfg++;
    if (cfg.bold_colour && (attr & ATTR_BLINK))
    if (inst->cfg.bold_colour && (attr & ATTR_BLINK))
	nbg++;
    if (attr & TATTR_ACTCURS) {
	nfg = NCOLOURS-2;
	nbg = NCOLOURS-1;
    }

    fontid = shadow = 0;

    if (attr & ATTR_WIDE) {
	widefactor = 2;
	fontid |= 2;
    } else {
	widefactor = 1;
    }

    if ((attr & ATTR_BOLD) && !cfg.bold_colour) {
    if ((attr & ATTR_BOLD) && !inst->cfg.bold_colour) {
	if (inst->fonts[fontid | 1])
	    fontid |= 1;
	else
	    shadow = 1;
    }

    if (lattr != LATTR_NORM) {
	x *= 2;
	if (x >= inst->term->cols)
	    return;
	if (x + len*2*widefactor > inst->term->cols)
	    len = (inst->term->cols-x)/2/widefactor;/* 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.x = x*inst->font_width+inst->cfg.window_border;
	r.y = y*inst->font_height+inst->cfg.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+cfg.window_border,
		       y*inst->font_height+cfg.window_border,
		       x*inst->font_width+inst->cfg.window_border,
		       y*inst->font_height+inst->cfg.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;
1626
1627
1628
1629
1630
1631
1632
1633
1634


1635
1636
1637
1638
1639
1640
1641
1642
1643


1644
1645
1646
1647
1648
1649
1650
1651
1652
1653


1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664




1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682




1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698




1699
1700
1701
1702
1703
1704
1705
1627
1628
1629
1630
1631
1632
1633


1634
1635
1636
1637
1638
1639
1640
1641
1642


1643
1644
1645
1646
1647
1648
1649
1650
1651
1652


1653
1654
1655
1656
1657
1658
1659
1660
1661




1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679




1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695




1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706







-
-
+
+







-
-
+
+








-
-
+
+







-
-
-
-
+
+
+
+














-
-
-
-
+
+
+
+












-
-
-
-
+
+
+
+







	    /*
	     * 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+cfg.window_border,
			     y*inst->font_height+cfg.window_border+inst->fonts[0]->ascent,
			     x*inst->font_width+inst->cfg.window_border,
			     y*inst->font_height+inst->cfg.window_border+inst->fonts[0]->ascent,
			     gwcs, len*2);
	    sfree(gwcs);
	} else {
	    gcs = smalloc(sizeof(GdkWChar) * (len+1));
	    wc_to_mb(inst->fontinfo[fontid].charset, 0,
		     wcs, len, gcs, len, ".", NULL);
	    gdk_draw_text(inst->pixmap, inst->fonts[fontid], gc,
			  x*inst->font_width+cfg.window_border,
			  y*inst->font_height+cfg.window_border+inst->fonts[0]->ascent,
			  x*inst->font_width+inst->cfg.window_border,
			  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+cfg.window_border + cfg.shadowboldoffset,
		      y*inst->font_height+cfg.window_border+inst->fonts[0]->ascent,
		      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)
	    uheight = inst->font_height - 1;
	gdk_draw_line(inst->pixmap, gc, x*inst->font_width+cfg.window_border,
		      y*inst->font_height + uheight + cfg.window_border,
		      (x+len)*widefactor*inst->font_width-1+cfg.window_border,
		      y*inst->font_height + uheight + cfg.window_border);
	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);
    }

    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 * widefactor * 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,
			    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,
			    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*widefactor*inst->font_width+cfg.window_border,
				y*inst->font_height+cfg.window_border+dt*(i+1),
				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,
				y*inst->font_height+inst->cfg.window_border+dt*(i+1),
				len * inst->font_width, inst->font_height-i-1);
	    }
	}
    }
}

void do_text(Context ctx, int x, int y, char *text, int len,
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734




1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752

1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772

1773
1774
1775
1776
1777
1778
1779
1780
1781
1782


1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796

1797
1798
1799
1800
1801
1802


1803
1804
1805
1806
1807
1808
1809
1810
1811


1812
1813
1814
1815
1816
1817
1818
1725
1726
1727
1728
1729
1730
1731




1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752

1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772

1773
1774
1775
1776
1777
1778
1779
1780
1781


1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796

1797
1798
1799
1800
1801


1802
1803
1804
1805
1806
1807
1808
1809
1810


1811
1812
1813
1814
1815
1816
1817
1818
1819







-
-
-
-
+
+
+
+

















-
+



















-
+








-
-
+
+













-
+




-
-
+
+







-
-
+
+







	    return;
	if (x + len*2*widefactor > inst->term->cols)
	    len = (inst->term->cols-x)/2/widefactor;/* trim to LH half */
	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,
		    x*inst->font_width+cfg.window_border,
		    y*inst->font_height+cfg.window_border,
		    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,
		    len*widefactor*inst->font_width, inst->font_height);
}

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, widefactor;

    if (attr & TATTR_PASCURS) {
	attr &= ~TATTR_PASCURS;
	passive = 1;
    } else
	passive = 0;
    if ((attr & TATTR_ACTCURS) && cfg.cursor_type != 0) {
    if ((attr & TATTR_ACTCURS) && inst->cfg.cursor_type != 0) {
	attr &= ~TATTR_ACTCURS;
    }
    do_text_internal(ctx, x, y, text, len, attr, lattr);

    if (attr & ATTR_WIDE) {
	widefactor = 2;
    } else {
	widefactor = 1;
    }

    if (lattr != LATTR_NORM) {
	x *= 2;
	if (x >= inst->term->cols)
	    return;
	if (x + len*2*widefactor > inst->term->cols)
	    len = (inst->term->cols-x)/2/widefactor;/* trim to LH half */
	len *= 2;
    }

    if (cfg.cursor_type == 0) {
    if (inst->cfg.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 it's passive.
	 */
	if (passive) {
	    gdk_gc_set_foreground(gc, &inst->cols[NCOLOURS-1]);
	    gdk_draw_rectangle(inst->pixmap, gc, 0,
			       x*inst->font_width+cfg.window_border,
			       y*inst->font_height+cfg.window_border,
			       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);
	}
    } else {
	int uheight;
	int startx, starty, dx, dy, length, i;

	int char_width;

	if ((attr & ATTR_WIDE) || lattr != LATTR_NORM)
	    char_width = 2*inst->font_width;
	else
	    char_width = inst->font_width;

	if (cfg.cursor_type == 1) {
	if (inst->cfg.cursor_type == 1) {
	    uheight = inst->fonts[0]->ascent + 1;
	    if (uheight >= inst->font_height)
		uheight = inst->font_height - 1;

	    startx = x * inst->font_width + cfg.window_border;
	    starty = y * inst->font_height + cfg.window_border + uheight;
	    startx = x * inst->font_width + inst->cfg.window_border;
	    starty = y * inst->font_height + inst->cfg.window_border + uheight;
	    dx = 1;
	    dy = 0;
	    length = len * char_width;
	} else {
	    int xadjust = 0;
	    if (attr & TATTR_RIGHTCURS)
		xadjust = char_width - 1;
	    startx = x * inst->font_width + cfg.window_border + xadjust;
	    starty = y * inst->font_height + cfg.window_border;
	    startx = x * inst->font_width + inst->cfg.window_border + xadjust;
	    starty = y * inst->font_height + inst->cfg.window_border;
	    dx = 0;
	    dy = 1;
	    length = inst->font_height;
	}

	gdk_gc_set_foreground(gc, &inst->cols[NCOLOURS-1]);
	if (passive) {
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836




1837
1838
1839
1840
1841
1842
1843
1827
1828
1829
1830
1831
1832
1833




1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844







-
-
-
-
+
+
+
+







	} else {
	    gdk_draw_line(inst->pixmap, gc, startx, starty,
			  startx + (length-1) * dx, starty + (length-1) * dy);
	}
    }

    gdk_draw_pixmap(inst->area->window, gc, inst->pixmap,
		    x*inst->font_width+cfg.window_border,
		    y*inst->font_height+cfg.window_border,
		    x*inst->font_width+cfg.window_border,
		    y*inst->font_height+cfg.window_border,
		    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,
		    len*widefactor*inst->font_width, inst->font_height);
}

GdkCursor *make_mouse_ptr(struct gui_data *inst, int cursor_val)
{
    /*
     * Truly hideous hack: GTK doesn't allow us to set the mouse
1968
1969
1970
1971
1972
1973
1974
1975

1976
1977
1978
1979
1980
1981
1982
1969
1970
1971
1972
1973
1974
1975

1976
1977
1978
1979
1980
1981
1982
1983







-
+







"  -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)
int do_cmdline(int argc, char **argv, int do_everything, Config *cfg)
{
    int err = 0;
    extern char **pty_argv;	       /* declared in pty.c */

    /*
     * Macros to make argument handling easier. Note that because
     * they need to call `continue', they cannot be contained in
2003
2004
2005
2006
2007
2008
2009
2010
2011


2012
2013
2014
2015
2016
2017


2018
2019
2020
2021
2022
2023


2024
2025
2026
2027
2028
2029


2030
2031
2032
2033
2034
2035


2036
2037
2038
2039
2040
2041
2042
2043
2044

2045
2046

2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059

2060
2061
2062
2063

2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077

2078
2079
2080
2081
2082



2083
2084
2085
2086
2087
2088
2089
2004
2005
2006
2007
2008
2009
2010


2011
2012
2013
2014
2015
2016


2017
2018
2019
2020
2021
2022


2023
2024
2025
2026
2027
2028


2029
2030
2031
2032
2033
2034


2035
2036
2037
2038
2039
2040
2041
2042
2043
2044

2045
2046

2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059

2060
2061
2062
2063

2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077

2078
2079
2080



2081
2082
2083
2084
2085
2086
2087
2088
2089
2090







-
-
+
+




-
-
+
+




-
-
+
+




-
-
+
+




-
-
+
+








-
+

-
+












-
+



-
+













-
+


-
-
-
+
+
+








    char *val;
    while (--argc > 0) {
	char *p = *++argv;
	if (!strcmp(p, "-fn") || !strcmp(p, "-font")) {
	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;
	    strncpy(cfg.font, val, sizeof(cfg.font));
	    cfg.font[sizeof(cfg.font)-1] = '\0';
	    strncpy(cfg->font, val, sizeof(cfg->font));
	    cfg->font[sizeof(cfg->font)-1] = '\0';

	} else if (!strcmp(p, "-fb")) {
	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;
	    strncpy(cfg.boldfont, val, sizeof(cfg.boldfont));
	    cfg.boldfont[sizeof(cfg.boldfont)-1] = '\0';
	    strncpy(cfg->boldfont, val, sizeof(cfg->boldfont));
	    cfg->boldfont[sizeof(cfg->boldfont)-1] = '\0';

	} else if (!strcmp(p, "-fw")) {
	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;
	    strncpy(cfg.widefont, val, sizeof(cfg.widefont));
	    cfg.widefont[sizeof(cfg.widefont)-1] = '\0';
	    strncpy(cfg->widefont, val, sizeof(cfg->widefont));
	    cfg->widefont[sizeof(cfg->widefont)-1] = '\0';

	} else if (!strcmp(p, "-fwb")) {
	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;
	    strncpy(cfg.wideboldfont, val, sizeof(cfg.wideboldfont));
	    cfg.wideboldfont[sizeof(cfg.wideboldfont)-1] = '\0';
	    strncpy(cfg->wideboldfont, val, sizeof(cfg->wideboldfont));
	    cfg->wideboldfont[sizeof(cfg->wideboldfont)-1] = '\0';

	} 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';
	    strncpy(cfg->line_codepage, val, sizeof(cfg->line_codepage));
	    cfg->line_codepage[sizeof(cfg->line_codepage)-1] = '\0';

	} else if (!strcmp(p, "-geometry")) {
	    int flags, x, y, w, h;
	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;

	    flags = XParseGeometry(val, &x, &y, &w, &h);
	    if (flags & WidthValue)
		cfg.width = w;
		cfg->width = w;
	    if (flags & HeightValue)
		cfg.height = h;
		cfg->height = h;

	    /*
	     * Apparently setting the initial window position is
	     * difficult in GTK 1.2. Not entirely sure why this
	     * should be. 2.0 has gtk_window_parse_geometry(),
	     * which would help... For the moment, though, I can't
	     * be bothered with this.
	     */

	} else if (!strcmp(p, "-sl")) {
	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;
	    cfg.savelines = atoi(val);
	    cfg->savelines = atoi(val);

	} else if (!strcmp(p, "-fg") || !strcmp(p, "-bg") ||
		   !strcmp(p, "-bfg") || !strcmp(p, "-bbg") ||
		   !strcmp(p, "-cfg") || !strcmp(p, "-cbg")) {
		   !strcmp(p, "-inst->cfg") || !strcmp(p, "-cbg")) {
	    GdkColor col;

	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;
	    if (!gdk_color_parse(val, &col)) {
		err = 1;
		fprintf(stderr, "pterm: unable to parse colour \"%s\"\n", val);
	    } else {
		int index;
		index = (!strcmp(p, "-fg") ? 0 :
			 !strcmp(p, "-bg") ? 2 :
			 !strcmp(p, "-bfg") ? 1 :
			 !strcmp(p, "-bbg") ? 3 :
			 !strcmp(p, "-cfg") ? 4 :
			 !strcmp(p, "-inst->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;
		cfg->colours[index][0] = col.red / 256;
		cfg->colours[index][1] = col.green / 256;
		cfg->colours[index][2] = col.blue / 256;
	    }

	} else if (!strcmp(p, "-e")) {
	    /* This option swallows all further arguments. */
	    if (!do_everything)
		break;

2097
2098
2099
2100
2101
2102
2103
2104
2105


2106
2107
2108
2109
2110
2111
2112



2113
2114
2115
2116

2117
2118
2119
2120

2121
2122
2123
2124

2125
2126
2127
2128

2129
2130
2131
2132

2133
2134
2135
2136

2137
2138
2139
2140

2141
2142
2143
2144
2145
2146
2147
2098
2099
2100
2101
2102
2103
2104


2105
2106
2107
2108
2109
2110



2111
2112
2113
2114
2115
2116

2117
2118
2119
2120

2121
2122
2123
2124

2125
2126
2127
2128

2129
2130
2131
2132

2133
2134
2135
2136

2137
2138
2139
2140

2141
2142
2143
2144
2145
2146
2147
2148







-
-
+
+




-
-
-
+
+
+



-
+



-
+



-
+



-
+



-
+



-
+



-
+







		break;		       /* finished command-line processing */
	    } else
		err = 1, fprintf(stderr, "pterm: -e expects an argument\n");

	} else if (!strcmp(p, "-T")) {
	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;
	    strncpy(cfg.wintitle, val, sizeof(cfg.wintitle));
	    cfg.wintitle[sizeof(cfg.wintitle)-1] = '\0';
	    strncpy(cfg->wintitle, val, sizeof(cfg->wintitle));
	    cfg->wintitle[sizeof(cfg->wintitle)-1] = '\0';

	} else if (!strcmp(p, "-log")) {
	    EXPECTS_ARG;
	    SECOND_PASS_ONLY;
	    strncpy(cfg.logfilename, val, sizeof(cfg.logfilename));
	    cfg.logfilename[sizeof(cfg.logfilename)-1] = '\0';
	    cfg.logtype = LGTYP_DEBUG;
	    strncpy(cfg->logfilename, val, sizeof(cfg->logfilename));
	    cfg->logfilename[sizeof(cfg->logfilename)-1] = '\0';
	    cfg->logtype = LGTYP_DEBUG;

	} else if (!strcmp(p, "-ut-") || !strcmp(p, "+ut")) {
	    SECOND_PASS_ONLY;
	    cfg.stamp_utmp = 0;
	    cfg->stamp_utmp = 0;

	} else if (!strcmp(p, "-ut")) {
	    SECOND_PASS_ONLY;
	    cfg.stamp_utmp = 1;
	    cfg->stamp_utmp = 1;

	} else if (!strcmp(p, "-ls-") || !strcmp(p, "+ls")) {
	    SECOND_PASS_ONLY;
	    cfg.login_shell = 0;
	    cfg->login_shell = 0;

	} else if (!strcmp(p, "-ls")) {
	    SECOND_PASS_ONLY;
	    cfg.login_shell = 1;
	    cfg->login_shell = 1;

	} else if (!strcmp(p, "-nethack")) {
	    SECOND_PASS_ONLY;
	    cfg.nethack_keypad = 1;
	    cfg->nethack_keypad = 1;

	} else if (!strcmp(p, "-sb-") || !strcmp(p, "+sb")) {
	    SECOND_PASS_ONLY;
	    cfg.scrollbar = 0;
	    cfg->scrollbar = 0;

	} else if (!strcmp(p, "-sb")) {
	    SECOND_PASS_ONLY;
	    cfg.scrollbar = 0;
	    cfg->scrollbar = 0;

	} else if (!strcmp(p, "-name")) {
	    EXPECTS_ARG;
	    app_name = val;

	} else if (!strcmp(p, "-xrm")) {
	    EXPECTS_ARG;
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257





2258
2259
2260
2261
2262
2263
2264
2265
2266

2267
2268

2269
2270
2271
2272
2273


2274
2275
2276

2277
2278
2279
2280
2281
2282
2283


2284
2285
2286

2287
2288
2289
2290
2291
2292
2293


2294
2295
2296

2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309

2310
2311
2312
2313
2314


2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327



2328
2329
2330
2331
2332
2333


2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345


2346
2347
2348


2349
2350
2351
2352
2353
2354
2355
2247
2248
2249
2250
2251
2252
2253





2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266

2267
2268

2269
2270
2271
2272


2273
2274
2275
2276

2277
2278
2279
2280
2281
2282


2283
2284
2285
2286

2287
2288
2289
2290
2291
2292


2293
2294
2295
2296

2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309

2310
2311
2312
2313


2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325



2326
2327
2328
2329
2330
2331
2332


2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344


2345
2346
2347


2348
2349
2350
2351
2352
2353
2354
2355
2356







-
-
-
-
-
+
+
+
+
+








-
+

-
+



-
-
+
+


-
+





-
-
+
+


-
+





-
-
+
+


-
+












-
+



-
-
+
+










-
-
-
+
+
+




-
-
+
+










-
-
+
+

-
-
+
+







     * it */
    block_signal(SIGCHLD, 1);

    pty_pre_init();

    gtk_init(&argc, &argv);

    if (do_cmdline(argc, argv, 0))     /* pre-defaults pass to get -class */
	exit(1);
    do_defaults(NULL, &cfg);
    if (do_cmdline(argc, argv, 1))     /* post-defaults, do everything */
	exit(1);
    if (do_cmdline(argc, argv, 0, &inst->cfg))
	exit(1);		       /* pre-defaults pass to get -class */
    do_defaults(NULL, &inst->cfg);
    if (do_cmdline(argc, argv, 1, &inst->cfg))
	exit(1);		       /* post-defaults, do everything */

    /*
     * 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);
    inst->fonts[0] = gdk_font_load(inst->cfg.font);
    if (!inst->fonts[0]) {
	fprintf(stderr, "pterm: unable to load font \"%s\"\n", cfg.font);
	fprintf(stderr, "pterm: unable to load font \"%s\"\n", inst->cfg.font);
	exit(1);
    }
    font_charset = set_font_info(inst, 0);
    if (cfg.boldfont[0]) {
	inst->fonts[1] = gdk_font_load(cfg.boldfont);
    if (inst->cfg.boldfont[0]) {
	inst->fonts[1] = gdk_font_load(inst->cfg.boldfont);
	if (!inst->fonts[1]) {
	    fprintf(stderr, "pterm: unable to load bold font \"%s\"\n",
		    cfg.boldfont);
		    inst->cfg.boldfont);
	    exit(1);
	}
	set_font_info(inst, 1);
    } else
	inst->fonts[1] = NULL;
    if (cfg.widefont[0]) {
	inst->fonts[2] = gdk_font_load(cfg.widefont);
    if (inst->cfg.widefont[0]) {
	inst->fonts[2] = gdk_font_load(inst->cfg.widefont);
	if (!inst->fonts[2]) {
	    fprintf(stderr, "pterm: unable to load wide font \"%s\"\n",
		    cfg.boldfont);
		    inst->cfg.boldfont);
	    exit(1);
	}
	set_font_info(inst, 2);
    } else
	inst->fonts[2] = NULL;
    if (cfg.wideboldfont[0]) {
	inst->fonts[3] = gdk_font_load(cfg.wideboldfont);
    if (inst->cfg.wideboldfont[0]) {
	inst->fonts[3] = gdk_font_load(inst->cfg.wideboldfont);
	if (!inst->fonts[3]) {
	    fprintf(stderr, "pterm: unable to load wide/bold font \"%s\"\n",
		    cfg.boldfont);
		    inst->cfg.boldfont);
	    exit(1);
	}
	set_font_info(inst, 3);
    } else
	inst->fonts[3] = NULL;

    inst->font_width = gdk_char_width(inst->fonts[0], ' ');
    inst->font_height = inst->fonts[0]->ascent + inst->fonts[0]->descent;

    inst->compound_text_atom = gdk_atom_intern("COMPOUND_TEXT", FALSE);
    inst->utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE);

    inst->direct_to_font = init_ucs(cfg.line_codepage, font_charset);
    inst->direct_to_font = init_ucs(inst->cfg.line_codepage, font_charset);

    inst->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    if (cfg.wintitle[0])
	set_title(inst, cfg.wintitle);
    if (inst->cfg.wintitle[0])
	set_title(inst, inst->cfg.wintitle);
    else
	set_title(inst, "pterm");

    /*
     * Set up the colour map.
     */
    palette_reset(inst);

    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);
    if (cfg.scrollbar) {
			  inst->font_width * inst->cfg.width + 2*inst->cfg.window_border,
			  inst->font_height * inst->cfg.height + 2*inst->cfg.window_border);
    if (inst->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));
    if (cfg.scrollbar) {
	if (cfg.scrollbar_on_left)
    if (inst->cfg.scrollbar) {
	if (inst->cfg.scrollbar_on_left)
	    gtk_box_pack_start(inst->hbox, inst->sbar, FALSE, FALSE, 0);
	else
	    gtk_box_pack_end(inst->hbox, inst->sbar, FALSE, FALSE, 0);
    }
    gtk_box_pack_start(inst->hbox, inst->area, TRUE, TRUE, 0);

    gtk_container_add(GTK_CONTAINER(inst->window), GTK_WIDGET(inst->hbox));

    {
	GdkGeometry geom;
	geom.min_width = inst->font_width + 2*cfg.window_border;
	geom.min_height = inst->font_height + 2*cfg.window_border;
	geom.min_width = inst->font_width + 2*inst->cfg.window_border;
	geom.min_height = inst->font_height + 2*inst->cfg.window_border;
	geom.max_width = geom.max_height = -1;
	geom.base_width = 2*cfg.window_border;
	geom.base_height = 2*cfg.window_border;
	geom.base_width = 2*inst->cfg.window_border;
	geom.base_height = 2*inst->cfg.window_border;
	geom.width_inc = inst->font_width;
	geom.height_inc = inst->font_height;
	geom.min_aspect = geom.max_aspect = 0;
	gtk_window_set_geometry_hints(GTK_WINDOW(inst->window), inst->area, &geom,
				      GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE |
				      GDK_HINT_RESIZE_INC);
    }
2378
2379
2380
2381
2382
2383
2384
2385

2386
2387
2388
2389
2390
2391
2392
2393
2394
2395

2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410


2411
2412
2413
2414

2415
2416
2417
2418
2419
2420

2421
2422
2423

2424
2425
2426
2427
2428
2429
2430
2379
2380
2381
2382
2383
2384
2385

2386
2387
2388
2389
2390
2391
2392
2393
2394
2395

2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409


2410
2411
2412
2413
2414

2415
2416
2417
2418
2419
2420

2421
2422
2423

2424
2425
2426
2427
2428
2429
2430
2431







-
+









-
+













-
-
+
+



-
+





-
+


-
+







		       GTK_SIGNAL_FUNC(motion_event), inst);
    gtk_signal_connect(GTK_OBJECT(inst->area), "selection_received",
		       GTK_SIGNAL_FUNC(selection_received), inst);
    gtk_signal_connect(GTK_OBJECT(inst->area), "selection_get",
		       GTK_SIGNAL_FUNC(selection_get), inst);
    gtk_signal_connect(GTK_OBJECT(inst->area), "selection_clear_event",
		       GTK_SIGNAL_FUNC(selection_clear), inst);
    if (cfg.scrollbar)
    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 |
			  GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK);

    gtk_widget_show(inst->area);
    if (cfg.scrollbar)
    if (inst->cfg.scrollbar)
	gtk_widget_show(inst->sbar);
    gtk_widget_show(GTK_WIDGET(inst->hbox));
    gtk_widget_show(inst->window);

    set_window_background(inst);

    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(inst, 1);

    inst->term = term_init(&cfg, inst);
    inst->logctx = log_init(inst, &cfg);
    inst->term = term_init(&inst->cfg, inst);
    inst->logctx = log_init(inst, &inst->cfg);
    term_provide_logctx(inst->term, inst->logctx);

    inst->back = &pty_backend;
    inst->back->init((void *)inst->term, &inst->backhandle, &cfg,
    inst->back->init((void *)inst->term, &inst->backhandle, &inst->cfg,
		     NULL, 0, NULL, 0);
    inst->back->provide_logctx(inst->backhandle, inst->logctx);

    term_provide_resize_fn(inst->term, inst->back->size, inst->backhandle);

    term_size(inst->term, cfg.height, cfg.width, cfg.savelines);
    term_size(inst->term, inst->cfg.height, inst->cfg.width, inst->cfg.savelines);

    inst->ldisc =
	ldisc_create(&cfg, inst->term, inst->back, inst->backhandle, inst);
	ldisc_create(&inst->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);