64
63
#define MAX_PIPES 4
65
64
//#define PIPE_BUFLEN 4096
76
static GPipe Pipes[MAX_PIPES];
78
#define die(s) do { printf("%s\n", s); exit(1); } while(0)
66
#define die(s) do { printf("%s\n", s); exit(1); } while (0)
80
68
unsigned int VideoCols = 80;
81
69
unsigned int VideoRows = 25;
330
319
ioctl(VtFd, KDSKBMODE, K_XLATE);
331
tmp = tcsetattr(VtFd, 0, &Save_termios);
332
if (tmp) fprintf(stderr, "tcsetattr = %d\n", tmp);
320
if ((tmp = tcsetattr(VtFd, 0, &Save_termios)))
321
fprintf(stderr, "tcsetattr = %d\n", tmp);
337
326
int ConSuspend() {
344
333
ioctl(VtFd, KDSKBMODE, K_XLATE);
345
334
tmp = tcsetattr(VtFd, 0, &Save_termios);
346
335
if (tmp) fprintf(stderr, "tcsetattr = %d\n", tmp);
350
339
int ConContinue() {
384
374
ConQuerySize(&X, &Y);
385
375
ConSetBox(0, 0, X, Y, Cell);
386
376
ConSetCursorPos(0, 0);
390
381
int ConSetTitle(const char */*Title*/, const char */*STitle*/) {
393
384
int ConGetTitle(char *Title, size_t MaxLen, char *STitle, size_t SMaxLen) {
394
385
strlcpy(Title, "", MaxLen);
395
386
strlcpy(STitle, "", SMaxLen);
399
391
int ConPutBox(int X, int Y, int W, int H, PCell Cell) {
402
394
conwrite(VcsFd, Cell, W, 4 + ((Y + i) * VideoCols + X) * 2);
403
395
if (LastMouseY == Y + i) mouseShow();
408
401
int ConGetBox(int X, int Y, int W, int H, PCell Cell) {
411
404
conread(VcsFd, Cell, W, 4 + ((Y + i) * VideoCols + X) * 2);
412
405
if (LastMouseY == Y + i) mouseShow();
417
411
int ConPutLine(int X, int Y, int W, int H, PCell Cell) {
419
413
for (int i = 0; i < H; ++i)
420
414
ConPutBox(X, Y + i, W, 1, Cell);
425
419
int ConSetBox(int X, int Y, int W, int H, TCell Cell) {
427
422
MoveCh(B, Cell.GetChar(), Cell.GetAttr(), W);
428
423
ConPutLine(X, Y, W, H, B);
432
428
int ConScroll(int Way, int X, int Y, int W, int H, TAttr Fill, int Count) {
434
430
if (Count == 0 || Count > H)
451
447
#ifdef USE_SCRNMAP
457
454
int ConSetSize(int /*X*/, int /*Y*/) {
461
458
int ConQuerySize(int *X, int *Y) {
462
459
if (X) *X = VideoCols;
463
460
if (Y) *Y = VideoRows;
467
465
int ConSetCursorPos(int X, int Y) {
497
497
int ConSetMousePos(int /*X*/, int /*Y*/) {
501
501
int ConQueryMousePos(int *X, int *Y) {
502
502
if (X) *X = LastMouseX;
503
503
if (Y) *Y = LastMouseY;
507
507
int ConShowMouse() {
511
511
int ConHideMouse() {
515
515
int ConMouseVisible() {
519
519
int ConQueryMouseButtons(int *ButtonCount) {
520
if (ButtonCount) *ButtonCount = 0;
524
526
static TEvent Prev = { evNone };
526
528
int ConGetEvent(TEventMask /*EventMask*/, TEvent *Event, int WaitTime, int Delete) {
528
struct timeval timeout;
530
529
if (Prev.What != evNone) {
532
531
if (Delete) Prev.What = evNone;
535
Event->What = evNone;
538
FD_SET(VtFd, &readfds);
535
switch (WaitFdPipeEvent(Event, VtFd,
541
FD_SET(GpmFd, &readfds);
543
for (int p = 0; p < MAX_PIPES; p++)
545
if (Pipes[p].fd != -1)
546
FD_SET(Pipes[p].fd, &readfds);
547
if (WaitTime == -1) {
548
if (select(sizeof(fd_set) * 8, &readfds, NULL, NULL, NULL) < 0) return -1;
550
timeout.tv_sec = WaitTime / 1000;
551
timeout.tv_usec = (WaitTime % 1000) * 1000;
552
if (select(sizeof(fd_set) * 8, &readfds, NULL, NULL, &timeout) < 0) return -1;
554
if (FD_ISSET(VtFd, &readfds)) {
555
547
GetKeyEvent(Event);
560
} else if (GpmFd != -1 && FD_ISSET(GpmFd, &readfds)) {
561
553
GetMouseEvent(Event);
567
for (int pp = 0; pp < MAX_PIPES; pp++) {
569
if (Pipes[pp].fd != -1)
570
if (FD_ISSET(Pipes[pp].fd, &readfds)) {
571
if (Pipes[pp].notify) {
572
Event->What = evNotify;
574
Event->Msg.Model = Pipes[pp].notify;
575
Event->Msg.Command = cmPipeRead;
576
Event->Msg.Param1 = pp;
577
Pipes[pp].stopped = 0;
579
//fprintf(stderr, "Pipe %d\n", Pipes[pp].fd);
588
561
int ConPutEvent(const TEvent& Event) {
593
566
int ConFlush() {return 0; }
835
808
for (size_t i = 0; i < FTE_ARRAY_SIZE(DeadTrans); ++i)
836
809
if (DeadTrans[i].KeySym == keysym) {
837
810
dead_key = DeadTrans[i].Diacr;
844
817
if (! (ShiftFlags & (kfAlt | kfCtrl)) && dead_key) {
845
818
for (unsigned i = 0; i < diacr_table.kb_cnt; ++i)
1049
int GUI::OpenPipe(const char *Command, EModel *notify) {
1052
for (i = 0; i < MAX_PIPES; i++) {
1053
if (Pipes[i].used == 0) {
1057
Pipes[i].notify = notify;
1058
Pipes[i].stopped = 1;
1060
if (pipe((int *)pfd) == -1)
1063
switch (Pipes[i].pid = fork()) {
1067
signal(SIGPIPE, SIG_DFL);
1068
VtFd = -1; // for atexit handler
1075
exit(system(Command));
1078
fcntl(pfd[0], F_SETFL, O_NONBLOCK);
1079
Pipes[i].fd = pfd[0];
1082
//fprintf(stderr, "Pipe Open: %d\n", i);
1089
int GUI::SetPipeView(int id, EModel *notify) {
1090
if (id < 0 || id > MAX_PIPES)
1092
if (Pipes[id].used == 0)
1094
//fprintf(stderr, "Pipe View: %d %08X\n", id, notify);
1095
Pipes[id].notify = notify;
1099
ssize_t GUI::ReadPipe(int id, void *buffer, size_t len) {
1102
if (id < 0 || id > MAX_PIPES)
1104
if (Pipes[id].used == 0)
1106
//fprintf(stderr, "Pipe Read: Get %d %d\n", id, len);
1108
rc = read(Pipes[id].fd, buffer, len);
1109
//fprintf(stderr, "Pipe Read: Got %d %d\n", id, len);
1111
close(Pipes[id].fd);
1116
Pipes[id].stopped = 1;
1122
int GUI::ClosePipe(int id) {
1125
if (id < 0 || id > MAX_PIPES)
1127
if (Pipes[id].used == 0)
1129
if (Pipes[id].fd != -1)
1130
close(Pipes[id].fd);
1131
kill(Pipes[id].pid, SIGHUP);
1133
waitpid(Pipes[id].pid, &status, 0);
1135
//fprintf(stderr, "Pipe Close: %d\n", id);
1137
return WEXITSTATUS(status);
1140
1023
int GUI::RunProgram(int /*mode*/, char *Command) {
1141
1024
int rc, W, H, W1, H1;
1165
1049
static size_t tablen = 0;
1168
if (getenv("ISOCONSOLE")) {
1052
if (getenv("ISOCONSOLE"))
1169
1053
tab = GetGUICharacters("Linux", "++++-|+++++>.*-^v :[>");
1171
1055
/* it's hard to pick usable chars between way to many fonts */
1172
1056
tab = GetGUICharacters("Linux", "\xDA\xBF\xC0\xD9\xC4\xB3\xC2\xC3\xB4\xC1\xC5\x1A.\x0A\xC4\x18\x19\xB1\xB0\x1B\x1A");
1173
1057
//tab = GetGUICharacters("Linux", "\xDA\xBF\xC0\xD9\xC4\xB3\xC2\xC3\xB4\xC1\xC5\x1A\xFA\x04\xC4\x18\x19\xB1\xB0\x1B\x1A");