57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
-
+
+
|
int mouseptr_visible;
guint term_paste_idle_id;
GdkAtom compound_text_atom, utf8_string_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;
int master_fd, master_func_id;
void *ldisc;
Backend *back;
void *backhandle;
Terminal *term;
void *logctx;
int exited;
struct unicode_data ucsdata;
Config cfg;
};
struct draw_ctx {
GdkGC *gc;
struct gui_data *inst;
|
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
|
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
-
-
+
-
-
-
-
+
-
-
-
-
+
+
-
+
-
-
-
-
+
+
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
|
term_mouse(inst->term, button, translate_button(button), MA_DRAG,
x, y, shift, ctrl, alt);
return TRUE;
}
void done_with_pty(struct gui_data *inst)
{
extern void pty_close(void);
if (inst->master_fd >= 0) {
pty_close();
inst->master_fd = -1;
gtk_input_remove(inst->master_func_id);
}
if (!inst->exited && inst->back->exitcode(inst->backhandle) >= 0) {
int exitcode = inst->back->exitcode(inst->backhandle);
int clean;
clean = WIFEXITED(exitcode) && (WEXITSTATUS(exitcode) == 0);
/*
* Terminate now, if the Close On Exit setting is
* appropriate.
*/
if (inst->cfg.close_on_exit == FORCE_ON ||
(inst->cfg.close_on_exit == AUTO && clean))
exit(0);
/*
* Otherwise, output an indication that the session has
* closed.
*/
{
char message[512];
if (WIFEXITED(exitcode))
sprintf(message, "\r\n[pterm: process terminated with exit"
" code %d]\r\n", WEXITSTATUS(exitcode));
else if (WIFSIGNALED(exitcode))
#ifdef HAVE_NO_STRSIGNAL
sprintf(message, "\r\n[pterm: process terminated on signal"
" %d]\r\n", WTERMSIG(exitcode));
#else
sprintf(message, "\r\n[pterm: process terminated on signal"
" %d (%.400s)]\r\n", WTERMSIG(exitcode),
strsignal(WTERMSIG(exitcode)));
#endif
from_backend((void *)inst->term, 0, message, strlen(message));
}
inst->exited = 1;
}
}
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.
*/
if (inst->exited)
exit(0);
}
gint timer_func(gpointer data)
{
struct gui_data *inst = (struct gui_data *)data;
int exitcode;
if (inst->back->exitcode(inst->backhandle) >= 0) {
if ((exitcode = inst->back->exitcode(inst->backhandle)) >= 0) {
/*
* The primary child process died. We could keep the
inst->exited = TRUE;
* terminal open for remaining subprocesses to output to,
* but conventional wisdom seems to feel that that's the
* Wrong Thing for an xterm-alike, so we bail out now
* (though we don't necessarily _close_ the window,
if (inst->cfg.close_on_exit == FORCE_ON ||
* depending on the state of Close On Exit). This would be
* easy enough to change or make configurable if necessary.
*/
done_with_pty(inst);
(inst->cfg.close_on_exit == AUTO && exitcode == 0))
exit(0); /* just go. */
}
term_update(inst->term);
term_blink(inst->term, 0);
return TRUE;
}
void pty_input_func(gpointer data, gint sourcefd, GdkInputCondition condition)
void fd_input_func(gpointer data, gint sourcefd, GdkInputCondition condition)
{
struct gui_data *inst = (struct gui_data *)data;
char buf[4096];
int ret;
select_result(sourcefd,
(condition == GDK_INPUT_READ ? 1 :
ret = read(sourcefd, buf, sizeof(buf));
condition == GDK_INPUT_WRITE ? 2 :
/*
* Clean termination condition is that either ret == 0, or ret
condition == GDK_INPUT_EXCEPTION ? 4 : -1));
* < 0 and errno == EIO. Not sure why the latter, but it seems
* to happen. Boo.
*/
if (ret == 0 || (ret < 0 && errno == EIO)) {
done_with_pty(inst);
} else if (ret < 0) {
perror("read pty master");
exit(1);
} else if (ret > 0)
from_backend(inst->term, 0, buf, ret);
term_blink(inst->term, 1);
term_out(inst->term);
}
void destroy(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}
|
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
|
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
|
+
+
+
+
+
+
+
+
+
+
+
+
-
|
sfree(encoding);
}
}
return retval;
}
int uxsel_input_add(int fd, int rwx) {
int flags = 0;
if (rwx & 1) flags |= GDK_INPUT_READ;
if (rwx & 2) flags |= GDK_INPUT_WRITE;
if (rwx & 4) flags |= GDK_INPUT_EXCEPTION;
return gdk_input_add(fd, flags, fd_input_func, NULL);
}
void uxsel_input_remove(int id) {
gdk_input_remove(id);
}
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;
int font_charset;
/* defer any child exit handling until we're ready to deal with
* it */
block_signal(SIGCHLD, 1);
|
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
|
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
|
+
+
-
-
-
-
-
-
+
+
+
|
make_mouse_ptr(inst, -2); /* clean up cursor font */
inst->currcursor = inst->textcursor;
show_mouseptr(inst, 1);
inst->term = term_init(&inst->cfg, &inst->ucsdata, inst);
inst->logctx = log_init(inst, &inst->cfg);
term_provide_logctx(inst->term, inst->logctx);
uxsel_init();
inst->back = &pty_backend;
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, inst->cfg.height, inst->cfg.width, inst->cfg.savelines);
inst->ldisc =
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);
/* now we're reday to deal with the child exit handler being
* called */
block_signal(SIGCHLD, 0);
inst->exited = FALSE;
gtk_main();
return 0;
}
|