1 /* Copyright (c) 2008, 2009
2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4 * Micah Cowan (micah@cowan.name)
5 * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
6 * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
7 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
8 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
9 * Copyright (c) 1987 Oliver Laumann
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program (see the file COPYING); if not, see
23 * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 ****************************************************************
29 #include <sys/types.h>
33 # include <sys/ioctl.h>
41 static int CountChars
__P((int));
42 static int DoAddChar
__P((int));
43 static int BlankResize
__P((int, int));
44 static int CallRewrite
__P((int, int, int, int));
45 static void FreeCanvas
__P((struct canvas
*));
46 static void disp_readev_fn
__P((struct event
*, char *));
47 static void disp_writeev_fn
__P((struct event
*, char *));
49 static void disp_writeev_eagain
__P((struct event
*, char *));
51 static void disp_status_fn
__P((struct event
*, char *));
52 static void disp_hstatus_fn
__P((struct event
*, char *));
53 static void disp_blocked_fn
__P((struct event
*, char *));
54 static void cv_winid_fn
__P((struct event
*, char *));
56 static void disp_map_fn
__P((struct event
*, char *));
58 static void disp_idle_fn
__P((struct event
*, char *));
60 static void disp_blanker_fn
__P((struct event
*, char *));
62 static void WriteLP
__P((int, int));
63 static void INSERTCHAR
__P((int));
64 static void RAW_PUTCHAR
__P((int));
66 static void SetBackColor
__P((int));
68 static void FreePerp
__P((struct canvas
*));
69 static struct canvas
*AddPerp
__P((struct canvas
*));
72 extern struct layer
*flayer
;
73 extern struct win
*windows
, *fore
;
74 extern struct LayFuncs WinLf
;
76 extern int use_hardstatus
;
77 extern int MsgWait
, MsgMinWait
;
78 extern int Z0width
, Z1width
;
79 extern unsigned char *blank
, *null
;
80 extern struct mline mline_blank
, mline_null
, mline_old
;
81 extern struct mchar mchar_null
, mchar_blank
, mchar_so
;
82 extern struct NewWindow nwin_default
;
83 extern struct action idleaction
;
85 /* XXX shouldn't be here */
86 extern char *hstatusstring
;
87 extern char *captionstring
;
93 extern int pty_preopen
;
94 #if defined(TIOCSWINSZ) || defined(TIOCGWINSZ)
95 extern struct winsize glwz
;
98 extern int real_uid
, real_gid
;
102 * tputs needs this to calculate the padding
106 #endif /* NEED_OSPEED */
110 struct display
*display
, *displays
;
112 int attr2color
[8][4];
117 struct display TheDisplay
;
123 int defobuflimit
= OBUF_MAX
;
124 int defnonblock
= -1;
129 int hardstatusemu
= HSTATUS_IGNORE
;
131 int focusminwidth
, focusminheight
;
134 * Default layer management
138 DefProcess(bufp
, lenp
)
147 DefRedisplayLine(y
, xs
, xe
, isblank
)
148 int y
, xs
, xe
, isblank
;
150 if (isblank
== 0 && y
>= 0)
151 DefClearLine(y
, xs
, xe
, 0);
155 DefClearLine(y
, xs
, xe
, bce
)
158 LClearLine(flayer
, y
, xs
, xe
, bce
, (struct mline
*)0);
163 DefRewrite(y
, xs
, xe
, rend
, doit
)
181 LAY_DISPLAYS(flayer
, InsertMode(0));
182 /* ChangeScrollRegion(0, D_height - 1); */
183 LKeypadMode(flayer
, 0);
184 LCursorkeysMode(flayer
, 0);
185 LCursorVisibility(flayer
, 0);
186 LMouseMode(flayer
, 0);
187 LSetRendition(flayer
, &mchar_null
);
188 LSetFlow(flayer
, nwin_default
.flowflag
& FLOW_NOW
);
192 * Blank layer management
195 struct LayFuncs BlankLf
=
211 flayer
->l_width
= wi
;
212 flayer
->l_height
= he
;
218 * Generate new display, start with a blank layer.
219 * The termcap arrays are not initialised here.
220 * The new display is placed in the displays list.
224 MakeDisplay(uname
, utty
, term
, fd
, pid
, Mode
)
225 char *uname
, *utty
, *term
;
230 struct baud_values
*b
;
232 if (!*(u
= FindUserPtr(uname
)) && UserAdd(uname
, (char *)0, u
))
233 return 0; /* could not find or add user */
236 if ((display
= (struct display
*)calloc(1, sizeof(*display
))) == 0)
241 bzero((char *)&TheDisplay
, sizeof(TheDisplay
));
242 display
= &TheDisplay
;
244 display
->d_next
= displays
;
247 D_nonblock
= defnonblock
;
249 D_readev
.fd
= D_writeev
.fd
= fd
;
250 D_readev
.type
= EV_READ
;
251 D_writeev
.type
= EV_WRITE
;
252 D_readev
.data
= D_writeev
.data
= (char *)display
;
253 D_readev
.handler
= disp_readev_fn
;
254 D_writeev
.handler
= disp_writeev_fn
;
256 D_writeev
.condpos
= &D_obuflen
;
257 D_writeev
.condneg
= &D_obuffree
;
259 D_statusev
.type
= EV_TIMEOUT
;
260 D_statusev
.data
= (char *)display
;
261 D_statusev
.handler
= disp_status_fn
;
262 D_hstatusev
.type
= EV_TIMEOUT
;
263 D_hstatusev
.data
= (char *)display
;
264 D_hstatusev
.handler
= disp_hstatus_fn
;
265 D_blockedev
.type
= EV_TIMEOUT
;
266 D_blockedev
.data
= (char *)display
;
267 D_blockedev
.handler
= disp_blocked_fn
;
268 D_blockedev
.condpos
= &D_obuffree
;
269 D_blockedev
.condneg
= &D_obuflenmax
;
270 D_hstatusev
.handler
= disp_hstatus_fn
;
272 D_mapev
.type
= EV_TIMEOUT
;
273 D_mapev
.data
= (char *)display
;
274 D_mapev
.handler
= disp_map_fn
;
276 D_idleev
.type
= EV_TIMEOUT
;
277 D_idleev
.data
= (char *)display
;
278 D_idleev
.handler
= disp_idle_fn
;
280 D_blankerev
.type
= EV_READ
;
281 D_blankerev
.data
= (char *)display
;
282 D_blankerev
.handler
= disp_blanker_fn
;
286 D_status_obuffree
= -1;
287 Resize_obuf(); /* Allocate memory for buffer */
288 D_obufmax
= defobuflimit
;
289 D_obuflenmax
= D_obuflen
- D_obufmax
;
291 D_auto_nuke
= defautonuke
;
298 if ((b
= lookup_baud((int)cfgetospeed(&D_OldMode
.tio
))))
302 if ((b
= lookup_baud(D_OldMode
.tio
.c_cflag
& CBAUD
)))
305 D_dospeed
= (short)D_OldMode
.m_ttyb
.sg_ospeed
;
308 debug1("New displays ospeed = %d\n", D_dospeed
);
310 strncpy(D_usertty
, utty
, sizeof(D_usertty
) - 1);
311 D_usertty
[sizeof(D_usertty
) - 1] = 0;
312 strncpy(D_termname
, term
, sizeof(D_termname
) - 1);
313 D_termname
[sizeof(D_termname
) - 1] = 0;
315 D_processinput
= ProcessInput
;
325 struct display
*d
, **dp
;
339 SetTTY(D_userfd
, &D_OldMode
);
340 fcntl(D_userfd
, F_SETFL
, 0);
346 if (D_processinputdata
)
347 free(D_processinputdata
);
348 D_processinputdata
= 0;
373 if (bd
.bd_dpy
== display
)
375 bd
.bd_start_braille
= 0;
381 for (dp
= &displays
; (d
= *dp
) ; dp
= &d
->d_next
)
385 if (D_status_lastmsg
)
386 free(D_status_lastmsg
);
389 *dp
= display
->d_next
;
391 ASSERT(display
== displays
);
392 ASSERT(display
== &TheDisplay
);
396 while (D_canvas
.c_slperp
)
397 FreeCanvas(D_canvas
.c_slperp
);
400 for (p
= windows
; p
; p
= p
->w_next
)
402 if (p
->w_pdisplay
== display
)
404 if (p
->w_lastdisp
== display
)
406 if (p
->w_readev
.condneg
== &D_status
|| p
->w_readev
.condneg
== &D_obuflenmax
)
407 p
->w_readev
.condpos
= p
->w_readev
.condneg
= 0;
410 for (p
= windows
; p
; p
= p
->w_next
)
411 if (p
->w_zdisplay
== display
)
415 free((char *)display
);
424 cv
->c_blank
.l_cvlist
= cv
;
425 cv
->c_blank
.l_width
= cv
->c_xe
- cv
->c_xs
+ 1;
426 cv
->c_blank
.l_height
= cv
->c_ye
- cv
->c_ys
+ 1;
427 cv
->c_blank
.l_x
= cv
->c_blank
.l_y
= 0;
428 cv
->c_blank
.l_layfn
= &BlankLf
;
429 cv
->c_blank
.l_data
= 0;
430 cv
->c_blank
.l_next
= 0;
431 cv
->c_blank
.l_bottom
= &cv
->c_blank
;
432 cv
->c_blank
.l_blocking
= 0;
433 cv
->c_layer
= &cv
->c_blank
;
442 if ((cv
= (struct canvas
*)calloc(1, sizeof *cv
)) == 0)
445 cv
->c_xe
= D_width
- 1;
447 cv
->c_ye
= D_height
- 1 - (D_has_hstatus
== HSTATUS_LASTLINE
) - captionalways
;
448 debug2("MakeDefaultCanvas 0,0 %d,%d\n", cv
->c_xe
, cv
->c_ye
);
452 cv
->c_display
= display
;
458 cv
->c_slback
= &D_canvas
;
459 D_canvas
.c_slperp
= cv
;
460 D_canvas
.c_xs
= cv
->c_xs
;
461 D_canvas
.c_xe
= cv
->c_xe
;
462 D_canvas
.c_ys
= cv
->c_ys
;
463 D_canvas
.c_ye
= cv
->c_ye
;
464 cv
->c_slorient
= SLICE_UNKN
;
465 cv
->c_captev
.type
= EV_TIMEOUT
;
466 cv
->c_captev
.data
= (char *)cv
;
467 cv
->c_captev
.handler
= cv_winid_fn
;
473 RethinkDisplayViewports();
474 D_forecv
= cv
; /* default input focus */
478 static struct canvas
**
479 CreateCanvasChainRec(cv
, cvp
)
483 for (; cv
; cv
= cv
->c_slnext
)
486 cvp
= CreateCanvasChainRec(cv
->c_slperp
, cvp
);
497 RecreateCanvasChain()
500 cvp
= CreateCanvasChainRec(D_canvas
.c_slperp
, &D_cvlist
);
508 struct viewport
*vp
, *nvp
;
513 cv
->c_slprev
->c_slnext
= cv
->c_slnext
;
515 cv
->c_slnext
->c_slprev
= cv
->c_slprev
;
516 if (cv
->c_slback
&& cv
->c_slback
->c_slperp
== cv
)
517 cv
->c_slback
->c_slperp
= cv
->c_slnext
? cv
->c_slnext
: cv
->c_slprev
;
521 FreeCanvas(cv
->c_slperp
);
530 /* remove from canvas chain as SetCanvasWindow might call
531 * some layer function */
532 for (cvp
= &D_cvlist
; *cvp
; cvp
= &(*cvp
)->c_next
)
539 p
= cv
->c_layer
? Layer2Window(cv
->c_layer
) : 0;
540 SetCanvasWindow(cv
, 0);
542 WindowChanged(p
, 'u');
543 if (flayer
== cv
->c_layer
)
545 for (vp
= cv
->c_vplist
; vp
; vp
= nvp
)
552 evdeq(&cv
->c_captev
);
561 for (; cv
; cv
= cv
->c_slnext
)
567 for (cvp
= cv
->c_slperp
; cvp
; cvp
= cvp
->c_slnext
)
570 n
= CountCanvas(cvp
->c_slperp
);
588 for (cvp
= cv
->c_slperp
; cvp
; cvp
= cvp
->c_slnext
)
591 n
= CountCanvas(cvp
->c_slperp
);
599 EqualizeCanvas(cv
, gflag
)
604 for (; cv
; cv
= cv
->c_slnext
)
606 if (cv
->c_slperp
&& gflag
)
608 cv
->c_slweight
= CountCanvasPerp(cv
);
609 for (cv2
= cv
->c_slperp
; cv2
; cv2
= cv2
->c_slnext
)
611 EqualizeCanvas(cv2
->c_slperp
, gflag
);
622 struct canvas
*cv2
, *cvn
, *fcv
;
623 int nh
, i
, maxi
, hh
, m
, w
, wsum
;
633 debug2("ResizeCanvas: %d,%d", xs
, ys
);
634 debug2(" %d,%d\n", xe
, ye
);
637 if (cv
->c_slorient
== SLICE_UNKN
)
639 ASSERT(!cv
->c_slnext
&& !cv
->c_slperp
);
644 cv
->c_xoff
= cv
->c_xs
;
645 cv
->c_yoff
= cv
->c_ys
;
646 cv
->c_blank
.l_width
= cv
->c_xe
- cv
->c_xs
+ 1;
647 cv
->c_blank
.l_height
= cv
->c_ye
- cv
->c_ys
+ 1;
652 if (focusminwidth
|| focusminheight
)
654 debug("searching for focus canvas\n");
656 while (cv2
->c_slback
)
658 if (cv2
->c_slback
== cv
->c_slback
)
661 focusmin
= cv
->c_slorient
== SLICE_VERT
? focusminheight
: focusminwidth
;
664 else if (focusmin
< 0)
665 focusmin
= cv
->c_slorient
== SLICE_VERT
? ye
- ys
+ 2 : xe
- xs
+ 2;
666 debug1("found, focusmin=%d\n", focusmin
);
673 m
= CountCanvas(cv
) * 2;
674 nh
= cv
->c_slorient
== SLICE_VERT
? ye
- ys
+ 2 : xe
- xs
+ 2;
680 debug1("corrected to %d\n", focusmin
);
683 /* pass 1: calculate weight sum */
684 for (cv2
= cv
, wsum
= 0; cv2
; cv2
= cv2
->c_slnext
)
686 debug1(" weight %d\n", cv2
->c_slweight
);
687 wsum
+= cv2
->c_slweight
;
689 debug1("wsum = %d\n", wsum
);
694 /* pass 2: calculate need/excess space */
695 nh
= cv
->c_slorient
== SLICE_VERT
? ye
- ys
+ 2 : xe
- xs
+ 2;
696 for (cv2
= cv
, need
= got
= 0; cv2
; cv2
= cv2
->c_slnext
)
698 m
= cv2
->c_slperp
? CountCanvasPerp(cv2
) * 2 - 1 : 1;
701 hh
= cv2
->c_slweight
? nh
* cv2
->c_slweight
/ w
: 0;
702 w
-= cv2
->c_slweight
;
704 debug2(" should %d min %d\n", hh
, m
);
710 debug2("need: %d, got %d\n", need
, got
);
714 /* pass 3: distribute space */
715 nh
= cv
->c_slorient
== SLICE_VERT
? ye
- ys
+ 2 : xe
- xs
+ 2;
716 i
= cv
->c_slorient
== SLICE_VERT
? ys
: xs
;
717 maxi
= cv
->c_slorient
== SLICE_VERT
? ye
: xe
;
724 if (cv
->c_slprev
&& !cv
->c_slback
->c_slback
&& !cv
->c_slprev
->c_slperp
&& !cv
->c_slprev
->c_slprev
)
726 cv
->c_slprev
->c_slorient
= SLICE_UNKN
;
729 cv
->c_slback
->c_ye
++;
730 cv
->c_slprev
->c_ye
++;
733 SetCanvasWindow(cv
, 0);
737 m
= cv
->c_slperp
? CountCanvasPerp(cv
) * 2 - 1 : 1;
740 hh
= cv
->c_slweight
? nh
* cv
->c_slweight
/ w
: 0;
743 debug2(" should %d min %d\n", hh
, m
);
747 debug1(" -> %d\n", hh
);
751 int hx
= need
* (hh
- m
- 1) / got
;
752 debug3(" -> %d - %d = %d\n", hh
, hx
, hh
- hx
);
756 debug2(" now need=%d got=%d\n", need
, got
);
759 /* hh is window size plus pation line */
760 if (i
+ hh
> maxi
+ 2)
763 debug1(" not enough space, reducing to %d\n", hh
);
765 if (i
+ hh
== maxi
+ 1)
768 debug(" incrementing as no other canvas will fit\n");
770 if (cv
->c_slorient
== SLICE_VERT
)
775 cv
->c_ye
= i
+ hh
- 2;
782 cv
->c_xe
= i
+ hh
- 2;
788 cv
->c_xoff
= cv
->c_xs
;
789 cv
->c_yoff
= cv
->c_ys
;
790 cv
->c_blank
.l_width
= cv
->c_xe
- cv
->c_xs
+ 1;
791 cv
->c_blank
.l_height
= cv
->c_ye
- cv
->c_ys
+ 1;
795 if (!cv
->c_slperp
->c_slnext
)
797 debug("deleting perp node\n");
798 FreePerp(cv
->c_slperp
);
806 static struct canvas
*
811 debug("Creating new perp node\n");
813 if ((pcv
= (struct canvas
*)calloc(1, sizeof *cv
)) == 0)
816 pcv
->c_display
= cv
->c_display
;
817 pcv
->c_slnext
= cv
->c_slnext
;
818 pcv
->c_slprev
= cv
->c_slprev
;
820 pcv
->c_slback
= cv
->c_slback
;
821 if (cv
->c_slback
&& cv
->c_slback
->c_slperp
== cv
)
822 cv
->c_slback
->c_slperp
= pcv
;
823 pcv
->c_slorient
= cv
->c_slorient
;
826 pcv
->c_xs
= cv
->c_xs
;
827 pcv
->c_xe
= cv
->c_xe
;
828 pcv
->c_ys
= cv
->c_ys
;
829 pcv
->c_ye
= cv
->c_ye
;
831 pcv
->c_slnext
->c_slprev
= pcv
;
833 pcv
->c_slprev
->c_slnext
= pcv
;
834 pcv
->c_slweight
= cv
->c_slweight
;
835 CanvasInitBlank(pcv
);
841 cv
->c_slorient
= SLICE_UNKN
;
854 cv
->c_slprev
= pcv
->c_slprev
;
856 cv
->c_slprev
->c_slnext
= cv
;
857 cv
->c_slback
= pcv
->c_slback
;
858 if (cv
->c_slback
&& cv
->c_slback
->c_slperp
== pcv
)
859 cv
->c_slback
->c_slperp
= cv
;
860 cv
->c_slorient
= pcv
->c_slorient
;
861 cv
->c_slweight
= pcv
->c_slweight
;
865 cv
->c_slorient
= pcv
->c_slorient
;
866 cv
->c_slback
= pcv
->c_slback
;
867 cv
->c_slweight
= pcv
->c_slweight
;
869 cv
->c_slnext
= pcv
->c_slnext
;
871 cv
->c_slnext
->c_slprev
= cv
;
884 debug2("AddCanvas orient %d, forecv is %d\n", orient
, cv
->c_slorient
);
886 if (cv
->c_slorient
!= SLICE_UNKN
&& cv
->c_slorient
!= orient
)
891 xs
= cv
->c_slback
->c_xs
;
892 xe
= cv
->c_slback
->c_xe
;
893 ys
= cv
->c_slback
->c_ys
;
894 ye
= cv
->c_slback
->c_ye
;
895 if (!captionalways
&& cv
== D_canvas
.c_slperp
&& !cv
->c_slnext
)
896 ye
--; /* need space for caption */
897 debug2("Adding Canvas to slice %d,%d ", xs
, ys
);
898 debug2("%d,%d\n", xe
, ye
);
900 num
= CountCanvas(cv
->c_slback
->c_slperp
) + 1;
901 debug1("Num = %d\n", num
);
902 if (orient
== SLICE_VERT
)
909 return -1; /* can't fit in */
911 if ((cv
= (struct canvas
*)calloc(1, sizeof *cv
)) == 0)
914 D_forecv
->c_slback
->c_ye
= ye
; /* in case we modified it above */
915 D_forecv
->c_slorient
= orient
; /* in case it was UNKN */
916 cv
->c_slnext
= D_forecv
->c_slnext
;
917 cv
->c_slprev
= D_forecv
;
918 D_forecv
->c_slnext
= cv
;
920 cv
->c_slnext
->c_slprev
= cv
;
921 cv
->c_slorient
= orient
;
922 cv
->c_slback
= D_forecv
->c_slback
;
930 cv
->c_display
= display
;
932 cv
->c_captev
.type
= EV_TIMEOUT
;
933 cv
->c_captev
.data
= (char *)cv
;
934 cv
->c_captev
.handler
= cv_winid_fn
;
942 EqualizeCanvas(cv
->c_slperp
, 0);
944 RecreateCanvasChain();
945 RethinkDisplayViewports();
946 ResizeLayersToCanvases();
956 debug("RemCanvas\n");
958 if (cv
->c_slorient
== SLICE_UNKN
)
964 if (!cv
->c_slnext
->c_slnext
&& cv
->c_slback
->c_slback
)
966 /* two canvases in slice, kill perp node */
968 debug("deleting perp node\n");
969 FreePerp(cv
->c_slprev
? cv
->c_slprev
: cv
->c_slnext
);
970 FreePerp(cv
->c_slback
);
972 xs
= cv
->c_slback
->c_xs
;
973 xe
= cv
->c_slback
->c_xe
;
974 ys
= cv
->c_slback
->c_ys
;
975 ye
= cv
->c_slback
->c_ye
;
978 D_forecv
= cv
->c_slprev
;
980 D_forecv
= cv
->c_slnext
;
984 while (D_forecv
->c_slperp
)
985 D_forecv
= D_forecv
->c_slperp
;
987 /* if only one canvas left, set orient back to unknown */
988 if (!cv
->c_slnext
&& !cv
->c_slprev
&& !cv
->c_slback
->c_slback
&& !cv
->c_slperp
)
990 cv
->c_slorient
= SLICE_UNKN
;
992 cv
->c_slback
->c_ye
= ++ye
; /* caption line no longer needed */
995 EqualizeCanvas(cv
->c_slperp
, 0);
998 D_fore
= Layer2Window(D_forecv
->c_layer
);
999 flayer
= D_forecv
->c_layer
;
1001 RecreateCanvasChain();
1002 RethinkDisplayViewports();
1003 ResizeLayersToCanvases();
1009 struct canvas
*cv
= D_forecv
, *ocv
= 0;
1014 cv
->c_slprev
->c_slnext
= cv
->c_slnext
;
1019 cv
->c_slnext
->c_slprev
= cv
->c_slprev
;
1023 if (cv
->c_slback
&& cv
->c_slback
->c_slperp
== cv
)
1024 cv
->c_slback
->c_slperp
= ocv
;
1025 cv
->c_slorient
= SLICE_UNKN
;
1026 while (D_canvas
.c_slperp
)
1027 FreeCanvas(D_canvas
.c_slperp
);
1029 D_canvas
.c_slperp
= cv
;
1030 cv
->c_slback
= &D_canvas
;
1033 ASSERT(!cv
->c_slperp
);
1035 D_canvas
.c_ye
++; /* caption line no longer needed */
1036 ResizeCanvas(&D_canvas
);
1037 RecreateCanvasChain();
1038 RethinkDisplayViewports();
1039 ResizeLayersToCanvases();
1043 RethinkDisplayViewports()
1046 struct viewport
*vp
, *vpn
;
1048 /* free old viewports */
1049 for (cv
= display
->d_cvlist
; cv
; cv
= cv
->c_next
)
1051 for (vp
= cv
->c_vplist
; vp
; vp
= vpn
)
1055 bzero((char *)vp
, sizeof(*vp
));
1060 display
->d_vpxmin
= -1;
1061 display
->d_vpxmax
= -1;
1063 for (cv
= display
->d_cvlist
; cv
; cv
= cv
->c_next
)
1065 if ((vp
= (struct viewport
*)malloc(sizeof *vp
)) == 0)
1069 vp
->v_xs
= cv
->c_xs
;
1070 vp
->v_ys
= (cv
->c_ys
+ cv
->c_ye
) / 2;
1071 vp
->v_xe
= cv
->c_xe
;
1072 vp
->v_ye
= cv
->c_ye
;
1073 vp
->v_xoff
= cv
->c_xoff
;
1074 vp
->v_yoff
= cv
->c_yoff
;
1075 vp
->v_next
= cv
->c_vplist
;
1078 if ((vp
= (struct viewport
*)malloc(sizeof *vp
)) == 0)
1081 vp
->v_xs
= (cv
->c_xs
+ cv
->c_xe
) / 2;
1082 vp
->v_ys
= (3 * cv
->c_ys
+ cv
->c_ye
) / 4;
1083 vp
->v_xe
= cv
->c_xe
;
1084 vp
->v_ye
= (cv
->c_ys
+ cv
->c_ye
) / 2 - 1;
1085 vp
->v_xoff
= cv
->c_xoff
;
1086 vp
->v_yoff
= cv
->c_yoff
;
1087 vp
->v_next
= cv
->c_vplist
;
1090 if ((vp
= (struct viewport
*)malloc(sizeof *vp
)) == 0)
1093 vp
->v_xs
= cv
->c_xs
;
1094 vp
->v_ys
= (3 * cv
->c_ys
+ cv
->c_ye
) / 4;
1095 vp
->v_xe
= (3 * cv
->c_xs
+ cv
->c_xe
) / 4 - 1;
1096 vp
->v_ye
= (cv
->c_ys
+ cv
->c_ye
) / 2 - 1;
1097 vp
->v_xoff
= cv
->c_xoff
;
1098 vp
->v_yoff
= cv
->c_yoff
;
1099 vp
->v_next
= cv
->c_vplist
;
1102 if ((vp
= (struct viewport
*)malloc(sizeof *vp
)) == 0)
1105 vp
->v_xs
= cv
->c_xs
;
1106 vp
->v_ys
= cv
->c_ys
;
1107 vp
->v_xe
= cv
->c_xe
;
1108 vp
->v_ye
= (3 * cv
->c_ys
+ cv
->c_ye
) / 4 - 1;
1109 vp
->v_xoff
= cv
->c_xoff
;
1110 vp
->v_yoff
= cv
->c_yoff
;
1111 vp
->v_next
= cv
->c_vplist
;
1115 vp
->v_xs
= cv
->c_xs
;
1116 vp
->v_ys
= cv
->c_ys
;
1117 vp
->v_xe
= cv
->c_xe
;
1118 vp
->v_ye
= cv
->c_ye
;
1119 vp
->v_xoff
= cv
->c_xoff
;
1120 vp
->v_yoff
= cv
->c_yoff
;
1121 vp
->v_next
= cv
->c_vplist
;
1125 if (cv
->c_xs
< display
->d_vpxmin
|| display
->d_vpxmin
== -1)
1126 display
->d_vpxmin
= cv
->c_xs
;
1127 if (cv
->c_xe
> display
->d_vpxmax
|| display
->d_vpxmax
== -1)
1128 display
->d_vpxmax
= cv
->c_xe
;
1134 RethinkViewportOffsets(cv
)
1137 struct viewport
*vp
;
1139 for (vp
= cv
->c_vplist
; vp
; vp
= vp
->v_next
)
1141 vp
->v_xoff
= cv
->c_xoff
;
1142 vp
->v_yoff
= cv
->c_yoff
;
1147 * if the adaptflag is on, we keep the size of this display, else
1148 * we may try to restore our old window sizes.
1159 /* Check for toggle */
1160 if (D_IM
&& strcmp(D_IM
, D_EI
))
1167 /* Check for toggle */
1168 if (D_KS
&& strcmp(D_KS
, D_KE
))
1170 if (D_CCS
&& strcmp(D_CCS
, D_CCE
))
1178 D_rend
= mchar_null
;
1181 ResizeDisplay(D_defwidth
, D_defheight
);
1182 ChangeScrollRegion(0, D_height
- 1);
1186 debug1("we %swant to adapt all our windows to the display\n",
1187 (adapt
) ? "" : "don't ");
1188 /* In case the size was changed by a init sequence */
1189 CheckScreenSize((adapt
) ? 2 : 0);
1201 ResizeDisplay(D_defwidth
, D_defheight
);
1203 ChangeScrollRegion(0, D_height
- 1);
1206 CursorVisibility(0);
1208 SetRendition(&mchar_null
);
1215 ShowHStatus((char *)0);
1220 GotoPos(0, D_height
- 1);
1234 if (!D_insert
&& D_x
< D_width
- 1)
1248 RefreshLine(D_y
, D_x
, D_width
-1, 0);
1260 if (D_insert
&& D_x
< D_width
- 1)
1269 if (D_x
< D_width
- 1)
1276 if (D_CLP
|| D_y
!= D_bot
)
1281 GotoPos(D_width
- 1, y
);
1284 debug("PUTCHARLP: lp_missing!\n");
1289 /* XXX -> PutChar ? */
1293 D_lpchar
.image
= D_mbcs
;
1301 * RAW_PUTCHAR() is for all text that will be displayed.
1302 * NOTE: charset Nr. 0 has a conversion table, but c1, c2, ... don't.
1313 if (D_encoding
== UTF8
)
1315 c
= (c
& 255) | (unsigned char)D_rend
.font
<< 8;
1321 D_x
+= D_AM
? 1 : -1;
1324 else if (utf8_isdouble(c
))
1333 AddCStr2(D_CS0
, '0');
1343 if (is_dw_font(D_rend
.font
))
1353 if (D_x
== D_width
- 1)
1354 D_x
+= D_AM
? 1 : -1;
1359 # if defined(ENCODINGS) && defined(DW_CHARS)
1361 c
= PrepareEncodedChar(c
);
1366 if (D_xtable
&& D_xtable
[(int)(unsigned char)D_rend
.font
] && D_xtable
[(int)(unsigned char)D_rend
.font
][(int)(unsigned char)c
])
1367 AddStr(D_xtable
[(int)(unsigned char)D_rend
.font
][(int)(unsigned char)c
]);
1369 AddChar(D_rend
.font
!= '0' ? c
: D_c0_tab
[(int)(unsigned char)c
]);
1377 if (++D_x
>= D_width
)
1381 else if (!D_CLP
|| D_x
> D_width
)
1384 if (D_y
< D_height
-1 && D_y
!= D_bot
)
1402 /* this is for ESC-sequences only (AddChar is a macro) */
1411 if (display
&& s
&& *s
)
1414 tputs(s
, 1, DoAddChar
);
1423 if (display
&& s
&& *s
)
1426 tputs(tgoto(s
, 0, c
), 1, DoAddChar
);
1431 /* Insert mode is a toggle on some terminals, so we need this hack:
1437 if (display
&& on
!= D_insert
&& D_IM
)
1447 /* ...and maybe keypad application mode is a toggle, too:
1457 if (display
&& D_keypad
!= on
&& D_KS
)
1476 if (display
&& D_cursorkeys
!= on
&& D_CCS
)
1491 if (display
&& D_revvid
!= on
&& D_CVR
)
1505 if (display
&& D_curvis
!= v
)
1508 AddCStr(D_VE
); /* do this always, just to be safe */
1510 if (v
== -1 && D_VI
)
1512 else if (v
== 1 && D_VS
)
1524 if (display
&& D_mouse
!= mode
)
1531 sprintf(mousebuf
, "\033[?%dl", D_mouse
);
1536 sprintf(mousebuf
, "\033[?%dh", mode
);
1563 tputs(s
, 1, CountChars
);
1571 CallRewrite(y
, xs
, xe
, doit
)
1572 int y
, xs
, xe
, doit
;
1574 struct canvas
*cv
, *cvlist
, *cvlnext
;
1575 struct viewport
*vp
;
1576 struct layer
*oldflayer
;
1579 debug3("CallRewrite %d %d %d\n", y
, xs
, xe
);
1584 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
1586 if (y
< cv
->c_ys
|| y
> cv
->c_ye
|| xe
< cv
->c_xs
|| xs
> cv
->c_xe
)
1588 for (vp
= cv
->c_vplist
; vp
; vp
= vp
->v_next
)
1589 if (y
>= vp
->v_ys
&& y
<= vp
->v_ye
&& xe
>= vp
->v_xs
&& xs
<= vp
->v_xe
)
1597 flayer
= cv
->c_layer
;
1598 cvlist
= flayer
->l_cvlist
;
1599 cvlnext
= cv
->c_lnext
;
1600 flayer
->l_cvlist
= cv
;
1602 LayRewrite(y
- vp
->v_yoff
, xs
- vp
->v_xoff
, xe
- vp
->v_xoff
, &D_rend
, 1);
1603 flayer
->l_cvlist
= cvlist
;
1604 cv
->c_lnext
= cvlnext
;
1608 if (cv
== 0 || cv
->c_layer
== 0)
1609 return EXPENSIVE
; /* not found or nothing on it */
1610 if (xs
< vp
->v_xs
|| xe
> vp
->v_xe
)
1611 return EXPENSIVE
; /* crosses viewport boundaries */
1612 if (y
- vp
->v_yoff
< 0 || y
- vp
->v_yoff
>= cv
->c_layer
->l_height
)
1613 return EXPENSIVE
; /* line not on layer */
1614 if (xs
- vp
->v_xoff
< 0 || xe
- vp
->v_xoff
>= cv
->c_layer
->l_width
)
1615 return EXPENSIVE
; /* line not on layer */
1617 if (D_encoding
== UTF8
)
1621 flayer
= cv
->c_layer
;
1622 debug3("Calling Rewrite %d %d %d\n", y
- vp
->v_yoff
, xs
- vp
->v_xoff
, xe
- vp
->v_xoff
);
1623 cost
= LayRewrite(y
- vp
->v_yoff
, xs
- vp
->v_xoff
, xe
- vp
->v_xoff
, &D_rend
, 0);
1626 cost
+= D_EIcost
+ D_IMcost
;
1635 register int dy
, dx
, x1
, y1
;
1636 register int costx
, costy
;
1640 enum move_t xm
= M_NONE
, ym
= M_NONE
;
1651 x1
= -1; /* don't know how the terminal treats this */
1659 if (dy
== 0 && dx
== 0)
1661 debug2("GotoPos (%d,%d)", x1
, y1
);
1662 debug2(" -> (%d,%d)\n", x2
, y2
);
1663 if (!D_MS
) /* Safe to move ? */
1664 SetRendition(&mchar_null
);
1665 if (y1
< 0 /* don't know the y position */
1666 || (y2
> D_bot
&& y1
<= D_bot
) /* have to cross border */
1667 || (y2
< D_top
&& y1
>= D_top
)) /* of scrollregion ? */
1670 if (D_HO
&& !x2
&& !y2
)
1673 AddCStr(tgoto(D_CM
, x2
, y2
));
1679 /* some scrollregion implementations don't allow movements
1680 * away from the region. sigh.
1682 if ((y1
> D_bot
&& y2
> y1
) || (y1
< D_top
&& y2
< y1
))
1685 /* Calculate CMcost */
1686 if (D_HO
&& !x2
&& !y2
)
1689 s
= tgoto(D_CM
, x2
, y2
);
1690 CMcost
= CalcCost(s
);
1692 /* Calculate the cost to move the cursor to the right x position */
1694 if (x1
>= 0) /* relativ x positioning only if we know where we are */
1698 if (D_CRI
&& (dx
> 1 || !D_ND
))
1700 costx
= CalcCost(tgoto(D_CRI
, 0, dx
));
1703 if ((m
= D_NDcost
* dx
) < costx
)
1708 /* Speedup: dx <= LayRewrite() */
1709 if (dx
< costx
&& (m
= CallRewrite(y1
, x1
, x2
- 1, 0)) < costx
)
1717 if (D_CLE
&& (dx
< -1 || !D_BC
))
1719 costx
= CalcCost(tgoto(D_CLE
, 0, -dx
));
1722 if ((m
= -dx
* D_LEcost
) < costx
)
1731 /* Speedup: LayRewrite() >= x2 */
1732 if (x2
+ D_CRcost
< costx
&& (m
= (x2
? CallRewrite(y1
, 0, x2
- 1, 0) : 0) + D_CRcost
) < costx
)
1738 /* Check if it is already cheaper to do CM */
1739 if (costx
>= CMcost
)
1742 /* Calculate the cost to move the cursor to the right y position */
1746 if (D_CDO
&& dy
> 1) /* DO & NL are always != 0 */
1748 costy
= CalcCost(tgoto(D_CDO
, 0, dy
));
1751 if ((m
= dy
* ((x2
== 0) ? D_NLcost
: D_DOcost
)) < costy
)
1759 if (D_CUP
&& (dy
< -1 || !D_UP
))
1761 costy
= CalcCost(tgoto(D_CUP
, 0, -dy
));
1764 if ((m
= -dy
* D_UPcost
) < costy
)
1773 /* Finally check if it is cheaper to do CM */
1774 if (costx
+ costy
>= CMcost
)
1784 AddCStr2(D_CLE
, -dx
);
1791 AddCStr2(D_CRI
, dx
);
1800 (void) CallRewrite(y1
, x1
, x2
- 1, 1);
1813 AddCStr2(D_CUP
, -dy
);
1816 s
= (x2
== 0) ? D_NL
: D_DO
;
1821 AddCStr2(D_CDO
, dy
);
1834 ClearArea(0, 0, 0, D_width
- 1, D_width
- 1, D_height
- 1, 0, 0);
1838 ClearArea(x1
, y1
, xs
, xe
, x2
, y2
, bce
, uselayfn
)
1839 int x1
, y1
, xs
, xe
, x2
, y2
, bce
, uselayfn
;
1843 struct viewport
*vp
;
1845 debug2("Clear %d,%d", x1
, y1
);
1846 debug2(" %d-%d", xs
, xe
);
1847 debug2(" %d,%d", x2
, y2
);
1848 debug2(" uselayfn=%d bce=%d\n", uselayfn
, bce
);
1858 if (D_UT
) /* Safe to erase ? */
1859 SetRendition(&mchar_null
);
1864 if (D_lp_missing
&& y1
<= D_bot
&& xe
>= D_width
- 1)
1866 if (y2
> D_bot
|| (y2
== D_bot
&& x2
>= D_width
- 1))
1869 if (x2
== D_width
- 1 && (xs
== 0 || y1
== y2
) && xe
== D_width
- 1 && y2
== D_height
- 1 && (!bce
|| D_BE
))
1872 if (x1
== 0 && y1
== 0 && D_auto_nuke
)
1875 if (x1
== 0 && y1
== 0 && D_CL
)
1882 * Workaround a hp700/22 terminal bug. Do not use CD where CE
1883 * is also appropriate.
1885 if (D_CD
&& (y1
< y2
|| !D_CE
))
1892 if (x1
== 0 && xs
== 0 && (xe
== D_width
- 1 || y1
== y2
) && y1
== 0 && D_CCD
&& (!bce
|| D_BE
))
1899 for (y
= y1
; y
<= y2
; y
++, x1
= xs
)
1903 if (x1
== 0 && D_CB
&& (xxe
!= D_width
- 1 || (D_x
== xxe
&& D_y
== y
)) && (!bce
|| D_BE
))
1909 if (xxe
== D_width
- 1 && D_CE
&& (!bce
|| D_BE
))
1918 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
1920 if (y
< cv
->c_ys
|| y
> cv
->c_ye
|| xxe
< cv
->c_xs
|| x1
> cv
->c_xe
)
1922 for (vp
= cv
->c_vplist
; vp
; vp
= vp
->v_next
)
1923 if (y
>= vp
->v_ys
&& y
<= vp
->v_ye
&& xxe
>= vp
->v_xs
&& x1
<= vp
->v_xe
)
1928 if (cv
&& cv
->c_layer
&& x1
>= vp
->v_xs
&& xxe
<= vp
->v_xe
&&
1929 y
- vp
->v_yoff
>= 0 && y
- vp
->v_yoff
< cv
->c_layer
->l_height
&&
1930 xxe
- vp
->v_xoff
>= 0 && x1
- vp
->v_xoff
< cv
->c_layer
->l_width
)
1932 struct layer
*oldflayer
= flayer
;
1933 struct canvas
*cvlist
, *cvlnext
;
1934 flayer
= cv
->c_layer
;
1935 cvlist
= flayer
->l_cvlist
;
1936 cvlnext
= cv
->c_lnext
;
1937 flayer
->l_cvlist
= cv
;
1939 LayClearLine(y
- vp
->v_yoff
, x1
- vp
->v_xoff
, xxe
- vp
->v_xoff
, bce
);
1940 flayer
->l_cvlist
= cvlist
;
1941 cv
->c_lnext
= cvlnext
;
1946 ClearLine((struct mline
*)0, y
, x1
, xxe
, bce
);
1952 * if cur_only > 0, we only redisplay current line, as a full refresh is
1953 * too expensive over a low baud line.
1961 /* XXX do em all? */
1963 ChangeScrollRegion(0, D_height
- 1);
1966 CursorVisibility(0);
1968 SetRendition(&mchar_null
);
1975 if (cur_only
> 0 && D_fore
)
1976 RefreshArea(0, D_fore
->w_y
, D_width
- 1, D_fore
->w_y
, 1);
1980 CV_CALL(D_forecv
, LayRestore();LaySetCursor());
1984 RedisplayDisplays(cur_only
)
1987 struct display
*olddisplay
= display
;
1988 for (display
= displays
; display
; display
= display
->d_next
)
1989 Redisplay(cur_only
);
1990 display
= olddisplay
;
1996 ScrollH(y
, xs
, xe
, n
, bce
, oml
)
1997 int y
, xs
, xe
, n
, bce
;
2004 if (xe
!= D_width
- 1)
2006 RefreshLine(y
, xs
, xe
, 0);
2007 /* UpdateLine(oml, y, xs, xe); */
2012 SetRendition(&mchar_null
);
2019 if (n
>= xe
- xs
+ 1)
2021 if (D_CDC
&& !(n
== 1 && D_DC
))
2030 RefreshLine(y
, xs
, xe
, 0);
2031 /* UpdateLine(oml, y, xs, xe); */
2037 if (-n
>= xe
- xs
+ 1)
2041 if (D_CIC
&& !(n
== -1 && D_IC
))
2042 AddCStr2(D_CIC
, -n
);
2051 SetRendition(&mchar_null
);
2057 bce
= 0; /* all done */
2061 /* UpdateLine(oml, y, xs, xe); */
2062 RefreshLine(y
, xs
, xe
, 0);
2068 SetRendition(&mchar_null
);
2074 bce
= 0; /* all done */
2080 ClearLine((struct mline
*)0, y
, xe
- n
+ 1, xe
, bce
);
2082 ClearLine((struct mline
*)0, y
, xs
, xs
- n
- 1, bce
);
2084 if (D_lp_missing
&& y
== D_bot
)
2087 WriteLP(D_width
- 1 - n
, y
);
2093 ScrollV(xs
, ys
, xe
, ye
, n
, bce
)
2094 int xs
, ys
, xe
, ye
, n
, bce
;
2099 int alok
, dlok
, aldlfaster
;
2105 if (n
>= ye
- ys
+ 1 || -n
>= ye
- ys
+ 1)
2107 ClearArea(xs
, ys
, xs
, xe
, xe
, ye
, bce
, 0);
2110 if (xs
> D_vpxmin
|| xe
< D_vpxmax
)
2112 RefreshArea(xs
, ys
, xe
, ye
, 0);
2118 if (D_bot
> ye
|| D_bot
< ys
)
2123 if (missy
> ye
|| missy
< ys
)
2134 if (n
>= ye
- ys
+ 1)
2139 if (ys
< D_top
|| D_bot
!= ye
)
2140 ChangeScrollRegion(ys
, ye
);
2141 alok
= (D_AL
|| D_CAL
|| (ys
>= D_top
&& ye
== D_bot
&& up
));
2142 dlok
= (D_DL
|| D_CDL
|| (ys
>= D_top
&& ye
== D_bot
&& !up
));
2143 if (D_top
!= ys
&& !(alok
&& dlok
))
2144 ChangeScrollRegion(ys
, ye
);
2148 (oldbot
== D_bot
&& up
&& D_top
== ys
&& D_bot
== ye
)))
2150 WriteLP(D_width
- 1, oldbot
);
2151 if (oldbot
== D_bot
) /* have scrolled */
2156 ChangeScrollRegion(oldtop, oldbot);
2159 ClearLine((struct mline
*)0, ye
, xs
, xe
, bce
);
2166 SetRendition(&mchar_null
);
2172 aldlfaster
= (n
> 1 && ys
>= D_top
&& ye
== D_bot
&& ((up
&& D_CDL
) || (!up
&& D_CAL
)));
2174 if ((up
|| D_SR
) && D_top
== ys
&& D_bot
== ye
&& !aldlfaster
)
2179 for(i
= n
; i
-- > 0; )
2180 AddCStr(D_NL
); /* was SF, I think NL is faster */
2185 for(i
= n
; i
-- > 0; )
2189 else if (alok
&& dlok
)
2191 if (up
|| ye
!= D_bot
)
2193 GotoPos(0, up
? ys
: ye
+1-n
);
2194 if (D_CDL
&& !(n
== 1 && D_DL
))
2200 if (!up
|| ye
!= D_bot
)
2202 GotoPos(0, up
? ye
+1-n
: ys
);
2203 if (D_CAL
&& !(n
== 1 && D_AL
))
2212 RefreshArea(xs
, ys
, xe
, ye
, 0);
2218 ClearArea(xs
, ye
- n
+ 1, xs
, xe
, xe
, ye
, bce
, 0);
2220 ClearArea(xs
, ys
, xs
, xe
, xe
, ys
+ n
- 1, bce
, 0);
2222 if (D_lp_missing
&& missy
!= D_bot
)
2223 WriteLP(D_width
- 1, missy
);
2225 ChangeScrollRegion(oldtop, oldbot);
2226 if (D_lp_missing && missy != D_bot)
2227 WriteLP(D_width - 1, missy);
2235 register int i
, j
, old
, typ
;
2237 if (!display
|| (old
= D_rend
.attr
) == new)
2240 D_col16change
= (old
^ new) & (A_BFG
| A_BBG
);
2241 new ^= D_col16change
;
2245 #if defined(TERMINFO) && defined(USE_SGR)
2251 tputs(tparm(D_SA
, new & A_SO
, new & A_US
, new & A_RV
, new & A_BL
,
2252 new & A_DI
, new & A_BD
, 0 , 0 ,
2258 rend_setdefault(&D_rend
);
2265 if ((new & old
) != old
)
2275 /* ansi attrib handling: \E[m resets color, too */
2277 rend_setdefault(&D_rend
);
2282 /* D_ME may also reset the alternate charset */
2294 for (i
= 0, j
= 1; old
&& i
< NATTR
; i
++, j
<<= 1)
2301 AddCStr(D_attrtab
[i
]);
2302 typ
|= D_attrtyp
[i
];
2313 int old
= D_rend
.font
;
2314 if (!display
|| old
== new)
2318 if (D_encoding
&& CanEncodeFont(D_encoding
, new))
2320 if (new == D_realfont
)
2324 if (D_xtable
&& D_xtable
[(int)(unsigned char)new] &&
2325 D_xtable
[(int)(unsigned char)new][256])
2327 AddCStr(D_xtable
[(int)(unsigned char)new][256]);
2331 if (!D_CG0
&& new != '0')
2350 AddCStr2(D_CS0
, new);
2365 jj
= (jj
- 232) / 6;
2366 jj
= (jj
& 1) << 3 | (jj
& 2 ? 7 : 0);
2374 min
= r
< g
? (r
< b
? r
: b
) : (g
< b
? g
: b
);
2375 max
= r
> g
? (r
> b
? r
: b
) : (g
> b
? g
: b
);
2377 jj
= ((max
+ 1) & 2) << 2 | ((max
+ 1) & 4 ? 7 : 0);
2379 jj
= (b
- min
) / (max
- min
) << 2 | (g
- min
) / (max
- min
) << 1 | (r
-
2380 min
) / (max
- min
) | (max
> 3 ? 8 : 0);
2393 return (jj
- 232) / 3 + 80;
2400 return ((r
+ 1) / 2) * 16 + ((g
+ 1) / 2) * 4 + ((b
+ 1) / 2) + 16;
2411 static unsigned char sftrans
[8] = {0,4,2,6,1,5,3,7};
2416 of
= rend_getfg(&D_rend
);
2417 ob
= rend_getbg(&D_rend
);
2420 /* intense default not invented yet */
2426 debug2("SetColor %d %d", coli2e(of
), coli2e(ob
));
2427 debug2(" -> %d %d\n", coli2e(f
), coli2e(b
));
2428 debug2("(%d %d", of
, ob
);
2429 debug2(" -> %d %d)\n", f
, b
);
2431 if (!D_CAX
&& D_hascolor
&& ((f
== 0 && f
!= of
) || (b
== 0 && b
!= ob
)))
2438 oattr
= D_rend
.attr
;
2439 AddCStr(D_ME
? D_ME
: "\033[m");
2443 /* D_ME may also reset the alternate charset */
2456 rend_setfg(&D_rend
, f
);
2457 rend_setbg(&D_rend
, b
);
2463 f
= f
? coli2e(f
) : -1;
2464 b
= b
? coli2e(b
) : -1;
2465 of
= of
? coli2e(of
) : -1;
2466 ob
= ob
? coli2e(ob
) : -1;
2468 if (f
!= of
&& f
> 15 && D_CCO
!= 256)
2469 f
= D_CCO
== 88 && D_CAF
? color256to88(f
) : color256to16(f
);
2470 if (f
!= of
&& f
> 15 && D_CAF
)
2475 if (b
!= ob
&& b
> 15 && D_CCO
!= 256)
2476 b
= D_CCO
== 88 && D_CAB
? color256to88(b
) : color256to16(b
);
2477 if (b
!= ob
&& b
> 15 && D_CAB
)
2483 if (f
!= of
&& f
!= (of
| 8))
2486 AddCStr("\033[39m"); /* works because AX is set */
2488 AddCStr2(D_CAF
, f
& 7);
2490 AddCStr2(D_CSF
, sftrans
[f
& 7]);
2492 if (b
!= ob
&& b
!= (ob
| 8))
2495 AddCStr("\033[49m"); /* works because AX is set */
2497 AddCStr2(D_CAB
, b
& 7);
2499 AddCStr2(D_CSB
, sftrans
[b
& 7]);
2502 if (f
!= of
&& D_CXT
&& (f
& 8) != 0 && f
!= -1)
2505 AddCStr2("\033[9%p1%dm", f
& 7);
2507 AddCStr2("\033[9%dm", f
& 7);
2510 if (b
!= ob
&& D_CXT
&& (b
& 8) != 0 && b
!= -1)
2513 AddCStr2("\033[10%p1%dm", b
& 7);
2515 AddCStr2("\033[10%dm", b
& 7);
2527 SetColor(rend_getfg(&D_rend
), new);
2538 if (nattr2color
&& D_hascolor
&& (mc
->attr
& nattr2color
) != 0)
2540 static struct mchar mmc
;
2543 for (i
= 0; i
< 8; i
++)
2544 if (attr2color
[i
] && (mc
->attr
& (1 << i
)) != 0)
2546 if (mc
->color
== 0 && attr2color
[i
][3])
2547 ApplyAttrColor(attr2color
[i
][3], &mmc
);
2548 else if ((mc
->color
& 0x0f) == 0 && attr2color
[i
][2])
2549 ApplyAttrColor(attr2color
[i
][2], &mmc
);
2550 else if ((mc
->color
& 0xf0) == 0 && attr2color
[i
][1])
2551 ApplyAttrColor(attr2color
[i
][1], &mmc
);
2553 ApplyAttrColor(attr2color
[i
][0], &mmc
);
2556 debug2("SetRendition: mapped to %02x %02x\n", (unsigned char)mc
->attr
, 0x99 - (unsigned char)mc
->color
);
2559 if (D_hascolor
&& D_CC8
&& (mc
->attr
& (A_BFG
|A_BBG
)))
2562 if ((mc
->attr
& A_BFG
) && D_MD
)
2564 if ((mc
->attr
& A_BBG
) && D_MB
)
2566 if (D_rend
.attr
!= a
)
2570 # endif /* COLORS16 */
2572 if (D_rend
.attr
!= mc
->attr
)
2576 if (D_rend
.color
!= mc
->color
2578 || D_rend
.colorx
!= mc
->colorx
2584 SetColor(rend_getfg(mc
), rend_getbg(mc
));
2587 if (D_rend
.font
!= mc
->font
)
2593 SetRenditionMline(ml
, x
)
2600 if (nattr2color
&& D_hascolor
&& (ml
->attr
[x
] & nattr2color
) != 0)
2603 copy_mline2mchar(&mc
, ml
, x
);
2608 if (D_hascolor
&& D_CC8
&& (ml
->attr
[x
] & (A_BFG
|A_BBG
)))
2610 int a
= ml
->attr
[x
];
2611 if ((ml
->attr
[x
] & A_BFG
) && D_MD
)
2613 if ((ml
->attr
[x
] & A_BBG
) && D_MB
)
2615 if (D_rend
.attr
!= a
)
2619 # endif /* COLORS16 */
2621 if (D_rend
.attr
!= ml
->attr
[x
])
2622 SetAttr(ml
->attr
[x
]);
2624 if (D_rend
.color
!= ml
->color
[x
]
2626 || D_rend
.colorx
!= ml
->colorx
[x
]
2634 copy_mline2mchar(&mc
, ml
, x
);
2635 SetColor(rend_getfg(&mc
), rend_getbg(&mc
));
2639 if (D_rend
.font
!= ml
->font
[x
])
2640 SetFont(ml
->font
[x
]);
2648 register char *s
, *t
;
2658 debug("tc not inited, just writing msg\n");
2659 if (D_processinputdata
)
2660 return; /* XXX: better */
2666 if (!use_hardstatus
|| !D_HS
)
2673 max
= D_WS
> 0 ? D_WS
: (D_width
- !D_CLP
);
2677 if (strcmp(msg
, D_status_lastmsg
) == 0)
2679 debug("same message - increase timeout");
2680 SetTimeout(&D_statusev
, MsgWait
);
2687 gettimeofday(&now
, NULL
);
2688 ti
= (now
.tv_sec
- D_status_time
.tv_sec
) * 1000 + (now
.tv_usec
- D_status_time
.tv_usec
) / 1000;
2689 if (ti
< MsgMinWait
)
2690 DisplaySleep1000(MsgMinWait
- ti
, 0);
2694 for (s
= t
= msg
; *s
&& t
- msg
< max
; ++s
)
2697 else if ((unsigned char)*s
>= ' ' && *s
!= 0177)
2702 if (t
- msg
>= D_status_buflen
)
2705 if (D_status_lastmsg
)
2706 buf
= realloc(D_status_lastmsg
, t
- msg
+ 1);
2708 buf
= malloc(t
- msg
+ 1);
2711 D_status_lastmsg
= buf
;
2712 D_status_buflen
= t
- msg
+ 1;
2715 if (t
- msg
< D_status_buflen
)
2716 strcpy(D_status_lastmsg
, msg
);
2717 D_status_len
= t
- msg
;
2718 D_status_lastx
= D_x
;
2719 D_status_lasty
= D_y
;
2720 if (!use_hardstatus
|| D_has_hstatus
== HSTATUS_IGNORE
|| D_has_hstatus
== HSTATUS_MESSAGE
)
2722 D_status
= STATUS_ON_WIN
;
2723 debug1("using STATLINE %d\n", STATLINE
);
2724 GotoPos(0, STATLINE
);
2725 SetRendition(&mchar_so
);
2728 if (D_status_len
< max
)
2730 /* Wayne Davison: add extra space for readability */
2732 SetRendition(&mchar_null
);
2734 if (D_status_len
< max
)
2746 D_status
= STATUS_ON_HS
;
2752 if (D_status
== STATUS_ON_WIN
)
2754 struct display
*olddisplay
= display
;
2755 struct layer
*oldflayer
= flayer
;
2757 ASSERT(D_obuffree
== D_obuflen
);
2758 /* this is copied over from RemoveStatus() */
2760 GotoPos(0, STATLINE
);
2761 RefreshLine(STATLINE
, 0, D_status_len
- 1, 0);
2762 GotoPos(D_status_lastx
, D_status_lasty
);
2763 flayer
= D_forecv
? D_forecv
->c_layer
: 0;
2766 display
= olddisplay
;
2768 D_status_obuflen
= D_obuflen
;
2769 D_status_obuffree
= D_obuffree
;
2770 D_obuffree
= D_obuflen
= 0;
2771 D_status
= STATUS_ON_WIN
;
2773 gettimeofday(&D_status_time
, NULL
);
2774 SetTimeout(&D_statusev
, MsgWait
);
2777 RefreshBraille(); /* let user see multiple Msg()s */
2784 struct display
*olddisplay
;
2785 struct layer
*oldflayer
;
2790 if (!(where
= D_status
))
2793 debug("RemoveStatus\n");
2794 if (D_status_obuffree
>= 0)
2796 D_obuflen
= D_status_obuflen
;
2797 D_obuffree
= D_status_obuffree
;
2798 D_status_obuffree
= -1;
2803 olddisplay
= display
;
2805 if (where
== STATUS_ON_WIN
)
2807 if (captionalways
|| (D_canvas
.c_slperp
&& D_canvas
.c_slperp
->c_slnext
))
2809 GotoPos(0, STATLINE
);
2810 RefreshLine(STATLINE
, 0, D_status_len
- 1, 0);
2811 GotoPos(D_status_lastx
, D_status_lasty
);
2816 flayer
= D_forecv
? D_forecv
->c_layer
: 0;
2819 display
= olddisplay
;
2823 /* refresh the display's hstatus line */
2830 if (D_status
== STATUS_ON_WIN
&& D_has_hstatus
== HSTATUS_LASTLINE
&& STATLINE
== D_height
-1)
2831 return; /* sorry, in use */
2835 if (D_HS
&& D_has_hstatus
== HSTATUS_HS
)
2837 if (!D_hstatus
&& (str
== 0 || *str
== 0))
2839 debug("ShowHStatus: using HS\n");
2840 SetRendition(&mchar_null
);
2845 if (str
== 0 || *str
== 0)
2848 max
= D_WS
> 0 ? D_WS
: (D_width
- !D_CLP
);
2849 if ((int)strlen(str
) > max
)
2856 else if (D_has_hstatus
== HSTATUS_LASTLINE
)
2858 debug("ShowHStatus: using last line\n");
2861 str
= str
? str
: "";
2865 GotoPos(0, D_height
- 1);
2866 SetRendition(captionalways
|| D_cvlist
== 0 || D_cvlist
->c_next
? &mchar_null
: &mchar_so
);
2867 PutWinMsg(str
, 0, l
);
2868 if (!captionalways
&& D_cvlist
&& !D_cvlist
->c_next
)
2869 while (l
++ < D_width
)
2872 ClearArea(l
, D_height
- 1, l
, D_width
- 1, D_width
- 1, D_height
- 1, 0, 0);
2873 if (ox
!= -1 && oy
!= -1)
2875 D_hstatus
= *str
? 1 : 0;
2876 SetRendition(&mchar_null
);
2878 else if (str
&& *str
&& D_has_hstatus
== HSTATUS_MESSAGE
)
2880 debug("ShowHStatus: using message\n");
2887 * Refreshes the harstatus of the fore window. Shouldn't be here...
2894 evdeq(&D_hstatusev
);
2895 if (D_status
== STATUS_ON_HS
)
2897 buf
= MakeWinMsgEv(hstatusstring
, D_fore
, '%', (D_HS
&& D_has_hstatus
== HSTATUS_HS
&& D_WS
> 0) ? D_WS
: D_width
- !D_CLP
, &D_hstatusev
, 0);
2901 if (D_has_hstatus
!= HSTATUS_IGNORE
&& D_hstatusev
.timeout
.tv_sec
)
2902 evenq(&D_hstatusev
);
2905 ShowHStatus((char *)0);
2908 /*********************************************************************/
2910 * Here come the routines that refresh an arbitrary part of the screen.
2920 debug("Signalling full refresh!\n");
2921 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
2923 CV_CALL(cv
, LayRedisplayLine(-1, -1, -1, isblank
));
2924 display
= cv
->c_display
; /* just in case! */
2926 RefreshArea(0, 0, D_width
- 1, D_height
- 1, isblank
);
2930 RefreshArea(xs
, ys
, xe
, ye
, isblank
)
2931 int xs
, ys
, xe
, ye
, isblank
;
2935 debug2("Refresh Area: %d,%d", xs
, ys
);
2936 debug3(" - %d,%d (isblank=%d)\n", xe
, ye
, isblank
);
2937 if (!isblank
&& xs
== 0 && xe
== D_width
- 1 && ye
== D_height
- 1 && (ys
== 0 || D_CD
))
2939 ClearArea(xs
, ys
, xs
, xe
, xe
, ye
, 0, 0);
2942 for (y
= ys
; y
<= ye
; y
++)
2943 RefreshLine(y
, xs
, xe
, isblank
);
2947 RefreshLine(y
, from
, to
, isblank
)
2948 int y
, from
, to
, isblank
;
2950 struct viewport
*vp
, *lvp
;
2951 struct canvas
*cv
, *lcv
, *cvlist
, *cvlnext
;
2952 struct layer
*oldflayer
;
2959 debug2("RefreshLine %d %d", y
, from
);
2960 debug2(" %d %d\n", to
, isblank
);
2962 if (D_status
== STATUS_ON_WIN
&& y
== STATLINE
)
2964 if (to
>= D_status_len
)
2965 D_status_len
= to
+ 1;
2966 return; /* can't refresh status */
2969 /* The following check makes plenty of sense. Unfortunately,
2970 vte-based terminals (notably gnome-terminal) experience a quirk
2971 that causes the final line not to update properly when it falls outside
2972 the scroll region; clearing the line with D_CE avoids the glitch,
2973 so we'll disable this perfectly sensible shortcut until such a time
2974 as widespread vte installations lack the glitch.
2976 See http://bugzilla.gnome.org/show_bug.cgi?id=542087 for current
2977 status of the VTE bug report, and
2978 https://savannah.gnu.org/bugs/index.php?23699 for the history from
2979 the Savannah BTS. */
2981 if (y
== D_height
- 1 && D_has_hstatus
== HSTATUS_LASTLINE
)
2988 if (isblank
== 0 && D_CE
&& to
== D_width
- 1 && from
< to
)
2992 SetRendition(&mchar_null
);
3000 for (cv
= display
->d_cvlist
; cv
; cv
= cv
->c_next
)
3002 if (y
== cv
->c_ye
+ 1 && from
>= cv
->c_xs
&& from
<= cv
->c_xe
)
3004 p
= Layer2Window(cv
->c_layer
);
3005 buf
= MakeWinMsgEv(captionstring
, p
, '%', cv
->c_xe
- cv
->c_xs
+ (cv
->c_xe
+ 1 < D_width
|| D_CLP
), &cv
->c_captev
, 0);
3006 if (cv
->c_captev
.timeout
.tv_sec
)
3007 evenq(&cv
->c_captev
);
3008 xx
= to
> cv
->c_xe
? cv
->c_xe
: to
;
3011 SetRendition(&mchar_so
);
3012 if (l
> xx
- cv
->c_xs
+ 1)
3013 l
= xx
- cv
->c_xs
+ 1;
3014 PutWinMsg(buf
, from
- cv
->c_xs
, l
);
3015 from
= cv
->c_xs
+ l
;
3016 for (; from
<= xx
; from
++)
3020 if (from
== cv
->c_xe
+ 1 && y
>= cv
->c_ys
&& y
<= cv
->c_ye
+ 1)
3023 SetRendition(&mchar_so
);
3028 if (y
< cv
->c_ys
|| y
> cv
->c_ye
|| to
< cv
->c_xs
|| from
> cv
->c_xe
)
3030 debug2("- canvas hit: %d %d", cv
->c_xs
, cv
->c_ys
);
3031 debug2(" %d %d\n", cv
->c_xe
, cv
->c_ye
);
3032 for (vp
= cv
->c_vplist
; vp
; vp
= vp
->v_next
)
3034 debug2(" - vp: %d %d", vp
->v_xs
, vp
->v_ys
);
3035 debug2(" %d %d\n", vp
->v_xe
, vp
->v_ye
);
3036 /* find leftmost overlapping vp */
3037 if (y
>= vp
->v_ys
&& y
<= vp
->v_ye
&& from
<= vp
->v_xe
&& to
>= vp
->v_xs
&& (lvp
== 0 || lvp
->v_xs
> vp
->v_xs
))
3045 continue; /* we advanced from */
3048 if (from
< lvp
->v_xs
)
3051 DisplayLine(&mline_null
, &mline_blank
, y
, from
, lvp
->v_xs
- 1);
3055 /* call LayRedisplayLine on canvas lcv viewport lvp */
3056 yy
= y
- lvp
->v_yoff
;
3057 xx
= to
< lvp
->v_xe
? to
: lvp
->v_xe
;
3059 if (lcv
->c_layer
&& yy
== lcv
->c_layer
->l_height
)
3062 SetRendition(&mchar_blank
);
3063 while (from
<= lvp
->v_xe
&& from
- lvp
->v_xoff
< lcv
->c_layer
->l_width
)
3068 if (from
>= lvp
->v_xe
+ 1)
3071 if (lcv
->c_layer
== 0 || yy
>= lcv
->c_layer
->l_height
|| from
- lvp
->v_xoff
>= lcv
->c_layer
->l_width
)
3074 DisplayLine(&mline_null
, &mline_blank
, y
, from
, lvp
->v_xe
);
3075 from
= lvp
->v_xe
+ 1;
3079 if (xx
- lvp
->v_xoff
>= lcv
->c_layer
->l_width
)
3080 xx
= lcv
->c_layer
->l_width
+ lvp
->v_xoff
- 1;
3082 flayer
= lcv
->c_layer
;
3083 cvlist
= flayer
->l_cvlist
;
3084 cvlnext
= lcv
->c_lnext
;
3085 flayer
->l_cvlist
= lcv
;
3087 LayRedisplayLine(yy
, from
- lvp
->v_xoff
, xx
- lvp
->v_xoff
, isblank
);
3088 flayer
->l_cvlist
= cvlist
;
3089 lcv
->c_lnext
= cvlnext
;
3094 if (!isblank
&& from
<= to
)
3095 DisplayLine(&mline_null
, &mline_blank
, y
, from
, to
);
3098 /*********************************************************************/
3100 /* clear lp_missing by writing the char on the screen. The
3101 * position must be safe.
3107 struct mchar oldrend
;
3110 ASSERT(D_lp_missing
);
3112 debug2("WriteLP(%d,%d)\n", x2
, y2
);
3119 D_lpchar
= mchar_blank
;
3122 /* Can't use PutChar */
3124 SetRendition(&D_lpchar
);
3125 PUTCHAR(D_lpchar
.image
);
3128 PUTCHAR(D_lpchar
.mbcs
);
3131 SetRendition(&oldrend
);
3135 ClearLine(oml
, y
, from
, to
, bce
)
3137 int from
, to
, y
, bce
;
3141 struct mchar bcechar
;
3144 debug3("ClearLine %d,%d-%d\n", y
, from
, to
);
3145 if (D_UT
) /* Safe to erase ? */
3146 SetRendition(&mchar_null
);
3151 if (from
== 0 && D_CB
&& (to
!= D_width
- 1 || (D_x
== to
&& D_y
== y
)) && (!bce
|| D_BE
))
3157 if (to
== D_width
- 1 && D_CE
&& (!bce
|| D_BE
))
3168 DisplayLine(oml
, &mline_blank
, y
, from
, to
);
3171 bcechar
= mchar_blank
;
3172 rend_setbg(&bcechar
, bce
);
3173 for (x
= from
; x
<= to
; x
++)
3174 copy_mchar2mline(&bcechar
, &mline_old
, x
);
3175 DisplayLine(oml
, &mline_old
, y
, from
, to
);
3177 DisplayLine(oml
, &mline_blank
, y
, from
, to
);
3182 DisplayLine(oml
, ml
, y
, from
, to
)
3183 struct mline
*oml
, *ml
;
3187 int last2flag
= 0, delete_lp
= 0;
3190 ASSERT(y
>= 0 && y
< D_height
);
3191 ASSERT(from
>= 0 && from
< D_width
);
3192 ASSERT(to
>= 0 && to
< D_width
);
3193 if (!D_CLP
&& y
== D_bot
&& to
== D_width
- 1)
3195 if (D_lp_missing
|| !cmp_mline(oml
, ml
, to
))
3198 if ((D_IC
|| D_IM
) && from
< to
&& !dw_left(ml
, to
, D_encoding
))
3200 if ((D_IC
|| D_IM
) && from
< to
)
3209 delete_lp
= !cmp_mchar_mline(&mchar_blank
, oml
, to
) && (D_CE
|| D_DC
|| D_CDC
);
3210 D_lp_missing
= !cmp_mchar_mline(&mchar_blank
, ml
, to
);
3211 copy_mline2mchar(&D_lpchar
, ml
, to
);
3219 /* finish dw-char (can happen after a wrap) */
3220 debug("DisplayLine finishing kanji\n");
3221 SetRenditionMline(ml
, from
);
3222 PUTCHAR(ml
->image
[from
]);
3226 for (x
= from
; x
<= to
; x
++)
3228 #if 0 /* no longer needed */
3229 if (x
|| D_x
!= D_width
|| D_y
!= y
- 1)
3232 if (x
< to
|| x
!= D_width
- 1 || ml
->image
[x
+ 1])
3233 if (cmp_mline(oml
, ml
, x
))
3238 if (dw_right(ml
, x
, D_encoding
))
3241 debug1("DisplayLine on right side of dw char- x now %d\n", x
);
3244 if (x
== to
&& dw_left(ml
, x
, D_encoding
))
3245 break; /* don't start new kanji */
3247 SetRenditionMline(ml
, x
);
3248 PUTCHAR(ml
->image
[x
]);
3250 if (dw_left(ml
, x
, D_encoding
))
3251 PUTCHAR(ml
->image
[++x
]);
3254 #if 0 /* not needed any longer */
3255 /* compare != 0 because ' ' can happen when clipping occures */
3256 if (to
== D_width
- 1 && y
< D_height
- 1 && D_x
== D_width
&& ml
->image
[to
+ 1])
3262 SetRenditionMline(ml
, x
+ 1);
3263 PUTCHAR(ml
->image
[x
+ 1]);
3265 SetRenditionMline(ml
, x
);
3266 INSERTCHAR(ml
->image
[x
]);
3271 SetRendition(&mchar_null
);
3288 PUTCHARLP(c
->image
);
3293 if (D_encoding
== UTF8
)
3302 InsChar(c
, x
, xe
, y
, oml
)
3308 if (y
== D_bot
&& !D_CLP
)
3310 if (x
== D_width
- 1)
3316 if (xe
== D_width
- 1)
3322 PUTCHARLP(c
->image
);
3325 if (!(D_IC
|| D_CIC
|| D_IM
) || xe
!= D_width
- 1)
3327 RefreshLine(y
, x
, xe
, 0);
3329 /* UpdateLine(oml, y, x, xe); */
3336 if (c
->mbcs
&& D_IC
)
3341 AddCStr2(D_CIC
, c
->mbcs
? 2 : 1);
3350 RAW_PUTCHAR(c
->image
);
3355 if (D_encoding
== UTF8
)
3358 if (D_x
== D_width
- 1)
3361 RAW_PUTCHAR(c
->mbcs
);
3367 WrapChar(c
, x
, y
, xs
, ys
, xe
, ye
, ins
)
3376 bce
= rend_getbg(c
);
3381 debug2(" x %d y %d", x
, y
);
3382 debug2(" Dx %d Dy %d", D_x
, D_y
);
3383 debug2(" xs %d ys %d", xs
, ys
);
3384 debug3(" xe %d ye %d ins %d\n", xe
, ye
, ins
);
3385 if (xs
!= 0 || x
!= D_width
|| !D_AM
)
3388 ScrollV(xs
, ys
, xe
, ye
, 1, bce
);
3389 else if (y
< D_height
- 1)
3392 InsChar(c
, xs
, xe
, y
, 0);
3397 if (y
== ye
) /* we have to scroll */
3399 debug("- scrolling\n");
3400 ChangeScrollRegion(ys
, ye
);
3401 if (D_bot
!= y
|| D_x
!= D_width
|| (!bce
&& !D_BE
))
3403 debug("- have to call ScrollV\n");
3404 ScrollV(xs
, ys
, xe
, ye
, 1, bce
);
3408 else if (y
== D_bot
) /* remove unusable region? */
3409 ChangeScrollRegion(0, D_height
- 1);
3410 if (D_x
!= D_width
|| D_y
!= y
)
3412 if (D_CLP
&& y
>= 0) /* don't even try if !LP */
3413 RefreshLine(y
, D_width
- 1, D_width
- 1, 0);
3414 debug2("- refresh last char -> x,y now %d,%d\n", D_x
, D_y
);
3415 if (D_x
!= D_width
|| D_y
!= y
) /* sorry, no bonus */
3418 ScrollV(xs
, ys
, xe
, ye
, 1, bce
);
3419 GotoPos(xs
, y
== ye
|| y
== D_height
- 1 ? y
: y
+ 1);
3422 debug("- writeing new char");
3423 if (y
!= ye
&& y
< D_height
- 1)
3425 if (ins
!= D_insert
)
3427 if (ins
&& !D_insert
)
3429 InsChar(c
, 0, xe
, y
, 0);
3430 debug2(" -> done with insert (%d,%d)\n", D_x
, D_y
);
3436 RAW_PUTCHAR(c
->image
);
3441 if (D_encoding
== UTF8
)
3444 RAW_PUTCHAR(c
->mbcs
);
3447 debug2(" -> done (%d,%d)\n", D_x
, D_y
);
3451 ResizeDisplay(wi
, he
)
3455 debug2("ResizeDisplay: to (%d,%d).\n", wi
, he
);
3456 if (D_width
== wi
&& D_height
== he
)
3458 debug("ResizeDisplay: No change\n");
3461 if (D_width
!= wi
&& (D_height
== he
|| !D_CWS
) && D_CZ0
&& (wi
== Z0width
|| wi
== Z1width
))
3463 debug("ResizeDisplay: using Z0/Z1\n");
3464 AddCStr(wi
== Z0width
? D_CZ0
: D_CZ1
);
3465 ChangeScreenSize(wi
, D_height
, 0);
3466 return (he
== D_height
) ? 0 : -1;
3470 debug("ResizeDisplay: using WS\n");
3471 AddCStr(tgoto(D_CWS
, wi
, he
));
3472 ChangeScreenSize(wi
, he
, 0);
3479 ChangeScrollRegion(newtop
, newbot
)
3484 if (newtop
== newbot
)
3485 return; /* xterm etc can't do it */
3489 newbot
= D_height
- 1;
3493 D_bot
= D_height
- 1;
3496 if (D_top
== newtop
&& D_bot
== newbot
)
3498 debug2("ChangeScrollRegion: (%d - %d)\n", newtop
, newbot
);
3499 AddCStr(tgoto(D_CS
, newbot
, newtop
));
3502 D_y
= D_x
= -1; /* Just in case... */
3511 static char oscs
[] = "1;\000\00020;\00039;\00049;\000";
3518 if (!D_xtermosc
[i
] && !*s
)
3521 s
= "screen"; /* always set icon name */
3523 s
= ""; /* no background */
3525 s
= "black"; /* black text */
3527 s
= "white"; /* on white background */
3530 AddStr(oscs
+ i
* 4);
3539 for (i
= 3; i
>= 0; i
--)
3545 * Output buffering routines
3557 if (D_encoding
== UTF8
)
3559 while ((c
= *str
++))
3560 AddUtf8((unsigned char)c
);
3564 while ((c
= *str
++))
3577 if (D_encoding
== UTF8
)
3579 while ((c
= *str
++) && n
-- > 0)
3580 AddUtf8((unsigned char)c
);
3584 while ((c
= *str
++) && n
-- > 0)
3597 l
= D_obufp
- D_obuf
;
3598 debug1("Flush(): %d\n", l
);
3601 ASSERT(l
+ D_obuffree
== D_obuflen
);
3609 if (fcntl(D_userfd
, F_SETFL
, 0))
3610 debug1("Warning: BLOCK fcntl failed: %d\n", errno
);
3614 wr
= write(D_userfd
, p
, l
);
3619 debug1("Writing to display: %d\n", errno
);
3630 if (fcntl(D_userfd
, F_SETFL
, FNBLOCK
))
3631 debug1("Warning: NBLOCK fcntl failed: %d\n", errno
);
3642 debug1("did freetty %d\n", D_userfd
);
3650 D_obuflenmax
= -D_obufmax
;
3656 * Asynchronous output routines by
3657 * Tim MacKenzie (tym@dibbler.cs.monash.edu.au)
3666 if (D_status_obuffree
>= 0)
3668 ASSERT(D_obuffree
== -1);
3673 gettimeofday(&now
, NULL
);
3674 ti
= (now
.tv_sec
- D_status_time
.tv_sec
) * 1000 + (now
.tv_usec
- D_status_time
.tv_usec
) / 1000;
3675 if (ti
< MsgMinWait
)
3676 DisplaySleep1000(MsgMinWait
- ti
, 0);
3679 if (--D_obuffree
> 0) /* redo AddChar decrement */
3682 if (D_obuflen
&& D_obuf
)
3684 ind
= D_obufp
- D_obuf
;
3686 D_obuffree
+= GRAIN
;
3687 D_obuf
= realloc(D_obuf
, D_obuflen
);
3694 D_obuf
= malloc(D_obuflen
);
3697 Panic(0, "Out of memory");
3698 D_obufp
= D_obuf
+ ind
;
3699 D_obuflenmax
= D_obuflen
- D_obufmax
;
3700 debug1("ResizeObuf: resized to %d\n", D_obuflen
);
3704 DisplaySleep1000(n
, eat
)
3716 debug("DisplaySleep has no display sigh\n");
3720 t
.tv_usec
= (n
% 1000) * 1000;
3721 t
.tv_sec
= n
/ 1000;
3723 FD_SET(D_userfd
, &r
);
3724 if (select(FD_SETSIZE
, &r
, (fd_set
*)0, (fd_set
*)0, &t
) > 0)
3726 debug("display activity stopped sleep\n");
3728 read(D_userfd
, &buf
, 1);
3730 debug2("DisplaySleep(%d) ending, eat was %d\n", n
, eat
);
3736 {/* Nuke pending output in current display, clear screen */
3738 int oldtop
= D_top
, oldbot
= D_bot
;
3739 struct mchar oldrend
;
3740 int oldkeypad
= D_keypad
, oldcursorkeys
= D_cursorkeys
;
3741 int oldcurvis
= D_curvis
;
3742 int oldmouse
= D_mouse
;
3745 len
= D_obufp
- D_obuf
;
3746 debug1("NukePending: nuking %d chars\n", len
);
3748 /* Throw away any output that we can... */
3750 tcflush(D_userfd
, TCOFLUSH
);
3753 (void) ioctl(D_userfd
, TCFLSH
, (char *) 1);
3762 /* Turn off all attributes. (Tim MacKenzie) */
3769 AddStr("\033[m"); /* why is D_ME not set? */
3774 /* Check for toggle */
3775 if (D_IM
&& strcmp(D_IM
, D_EI
))
3778 /* Check for toggle */
3780 if (D_KS
&& strcmp(D_KS
, D_KE
))
3782 if (D_CCS
&& strcmp(D_CCS
, D_CCE
))
3785 if (D_KS
&& strcmp(D_KS
, D_KE
))
3788 if (D_CCS
&& strcmp(D_CCS
, D_CCE
))
3793 D_rend
= mchar_null
;
3799 ChangeScrollRegion(oldtop
, oldbot
);
3800 SetRendition(&oldrend
);
3801 KeypadMode(oldkeypad
);
3802 CursorkeysMode(oldcursorkeys
);
3803 CursorVisibility(oldcurvis
);
3804 MouseMode(oldmouse
);
3807 debug("ResizeDisplay: using WS\n");
3808 AddCStr(tgoto(D_CWS
, D_width
, D_height
));
3810 else if (D_CZ0
&& (D_width
== Z0width
|| D_width
== Z1width
))
3812 debug("ResizeDisplay: using Z0/Z1\n");
3813 AddCStr(D_width
== Z0width
? D_CZ0
: D_CZ1
);
3816 #endif /* AUTO_NUKE */
3819 /* linux' select can't handle flow control, so wait 100ms if
3823 disp_writeev_eagain(ev
, data
)
3827 display
= (struct display
*)data
;
3829 D_writeev
.type
= EV_WRITE
;
3830 D_writeev
.handler
= disp_writeev_fn
;
3836 disp_writeev_fn(ev
, data
)
3840 int len
, size
= OUTPUT_BLOCK_SIZE
;
3842 display
= (struct display
*)data
;
3843 len
= D_obufp
- D_obuf
;
3847 size
= write(D_userfd
, D_obuf
, size
);
3853 bcopy(D_obuf
+ size
, D_obuf
, len
);
3854 debug2("ASYNC: wrote %d - remaining %d\n", size
, len
);
3860 D_blocked_fuzz
-= size
;
3861 if (D_blocked_fuzz
< 0)
3864 if (D_blockedev
.queued
)
3866 if (D_obufp
- D_obuf
> D_obufmax
/ 2)
3868 debug2("%s: resetting timeout to %g secs\n", D_usertty
, D_nonblock
/1000.);
3869 SetTimeout(&D_blockedev
, D_nonblock
);
3873 debug1("%s: deleting blocked timeout\n", D_usertty
);
3874 evdeq(&D_blockedev
);
3877 if (D_blocked
== 1 && D_obuf
== D_obufp
)
3879 /* empty again, restart output */
3880 debug1("%s: buffer empty, unblocking\n", D_usertty
);
3882 Activate(D_fore
? D_fore
->w_norefresh
: 0);
3883 D_blocked_fuzz
= D_obufp
- D_obuf
;
3889 /* linux flow control is badly broken */
3890 if (errno
== EAGAIN
)
3893 D_writeev
.type
= EV_TIMEOUT
;
3894 D_writeev
.handler
= disp_writeev_eagain
;
3895 SetTimeout(&D_writeev
, 100);
3899 if (errno
!= EINTR
&& errno
!= EAGAIN
)
3900 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
3901 if (errno
!= EWOULDBLOCK
)
3903 Msg(errno
, "Error writing output to display");
3908 disp_readev_fn(ev
, data
)
3916 display
= (struct display
*)data
;
3918 /* Hmmmm... a bit ugly... */
3920 for (cv
= D_forecv
->c_layer
->l_cvlist
; cv
; cv
= cv
->c_lnext
)
3922 display
= cv
->c_display
;
3923 if (D_status
== STATUS_ON_WIN
)
3927 display
= (struct display
*)data
;
3934 size
= sizeof(D_fore
->w_pwin
->p_inbuf
) - D_fore
->w_pwin
->p_inlen
;
3937 size
= sizeof(D_fore
->w_inbuf
) - D_fore
->w_inlen
;
3943 size
= 1; /* Always allow one char for command keys */
3945 size
= read(D_userfd
, buf
, size
);
3948 if (errno
== EINTR
|| errno
== EAGAIN
)
3950 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
3951 if (errno
== EWOULDBLOCK
)
3954 debug1("Read error: %d - hangup!\n", errno
);
3961 debug("Found EOF - hangup!\n");
3972 Activate(D_fore
? D_fore
->w_norefresh
: 0);
3977 if (D_blocked
> 1) /* 2, 3 */
3983 for (p
= windows
; p
; p
= p
->w_next
)
3984 if (p
->w_zdisplay
== display
)
3986 flayer
= &p
->w_layer
;
3989 LayProcess(&bufp
, &size
);
3992 debug("zmodem window gone, deblocking display");
3993 zmodem_abort(0, display
);
3999 D_fore
->w_lastdisp
= display
;
4000 if (D_mouse
&& D_forecv
)
4002 unsigned char *bp
= (unsigned char *)buf
;
4005 /* XXX this assumes that the string is read in as a whole... */
4006 for (i
= size
; i
> 0; i
--, bp
++)
4008 if (i
> 5 && bp
[0] == 033 && bp
[1] == '[' && bp
[2] == 'M')
4013 else if (i
< 5 || bp
[0] != 0233 || bp
[1] != 'M')
4017 if (x
>= D_forecv
->c_xs
&& x
<= D_forecv
->c_xe
&& y
>= D_forecv
->c_ys
&& y
<= D_forecv
->c_ye
)
4019 x
-= D_forecv
->c_xoff
;
4020 y
-= D_forecv
->c_yoff
;
4021 if (x
>= 0 && x
< D_forecv
->c_layer
->l_width
&& y
>= 0 && y
< D_forecv
->c_layer
->l_height
)
4032 bcopy((char *)bp
+ 1, (char *)bp
, i
);
4037 bcopy((char *)bp
+ 5, (char *)bp
, i
- 5);
4044 if (D_encoding
!= (D_forecv
? D_forecv
->c_layer
->l_encoding
: 0))
4047 char buf2
[IOSIZE
* 2 + 10];
4048 enc
= D_forecv
? D_forecv
->c_layer
->l_encoding
: 0;
4049 for (i
= j
= 0; i
< size
; i
++)
4051 c
= ((unsigned char *)buf
)[i
];
4052 c
= DecodeChar(c
, D_encoding
, &D_decodestate
);
4054 i
--; /* try char again */
4060 j
+= EncodeChar(buf2
+ j
, c
, enc
, &font
);
4061 j
+= EncodeChar(buf2
+ j
, -1, enc
, &font
);
4064 j
+= EncodeChar(buf2
+ j
, c
, enc
, 0);
4065 if (j
> (int)sizeof(buf2
) - 10) /* just in case... */
4068 (*D_processinput
)(buf2
, j
);
4072 (*D_processinput
)(buf
, size
);
4076 disp_status_fn(ev
, data
)
4080 display
= (struct display
*)data
;
4081 debug1("disp_status_fn for display %x\n", (int)display
);
4087 disp_hstatus_fn(ev
, data
)
4091 display
= (struct display
*)data
;
4092 if (D_status
== STATUS_ON_HS
)
4102 disp_blocked_fn(ev
, data
)
4108 display
= (struct display
*)data
;
4109 debug1("blocked timeout %s\n", D_usertty
);
4110 if (D_obufp
- D_obuf
> D_obufmax
+ D_blocked_fuzz
)
4112 debug("stopping output to display\n");
4114 /* re-enable all windows */
4115 for (p
= windows
; p
; p
= p
->w_next
)
4116 if (p
->w_readev
.condneg
== &D_obuflenmax
)
4118 debug1("freeing window #%d\n", p
->w_number
);
4119 p
->w_readev
.condpos
= p
->w_readev
.condneg
= 0;
4125 cv_winid_fn(ev
, data
)
4130 struct canvas
*cv
= (struct canvas
*)data
;
4132 display
= cv
->c_display
;
4133 if (D_status
== STATUS_ON_WIN
)
4141 if (cv
->c_ye
+ 1 < D_height
)
4142 RefreshLine(cv
->c_ye
+ 1, 0, D_width
- 1, 0);
4143 if (ox
!= -1 && oy
!= -1)
4149 disp_map_fn(ev
, data
)
4156 display
= (struct display
*)data
;
4157 debug("Flushing map sequence\n");
4160 p
= (char *)D_seqp
- l
;
4161 D_seqp
= D_kmaps
+ 3;
4163 if ((q
= D_seqh
) != 0)
4166 i
= q
[0] << 8 | q
[1];
4167 i
&= ~KMAP_NOTIMEOUT
;
4168 debug1("Mapping former hit #%d - ", i
);
4169 debug2("%d(%s) - ", q
[2], q
+ 3);
4171 ProcessInput2((char *)q
+ 3, q
[2]);
4184 disp_idle_fn(ev
, data
)
4188 struct display
*olddisplay
;
4189 display
= (struct display
*)data
;
4190 debug("idle timeout\n");
4191 if (idletimo
<= 0 || idleaction
.nr
== RC_ILLEGAL
)
4193 olddisplay
= display
;
4194 flayer
= D_forecv
->c_layer
;
4196 DoAction(&idleaction
, -1);
4197 if (idleaction
.nr
== RC_BLANKER
)
4199 for (display
= displays
; display
; display
= display
->d_next
)
4200 if (olddisplay
== display
)
4211 SetTimeout(&D_idleev
, idletimo
);
4212 if (!D_idleev
.queued
)
4223 disp_blanker_fn(ev
, data
)
4227 char buf
[IOSIZE
], *b
;
4230 display
= (struct display
*)data
;
4231 size
= read(D_blankerev
.fd
, buf
, IOSIZE
);
4234 evdeq(&D_blankerev
);
4235 close(D_blankerev
.fd
);
4236 D_blankerev
.fd
= -1;
4239 for (b
= buf
; size
; size
--)
4246 int oldtop
= D_top
, oldbot
= D_bot
;
4247 struct mchar oldrend
;
4249 if (D_blankerev
.fd
== -1)
4253 evdeq(&D_blankerev
);
4254 close(D_blankerev
.fd
);
4255 D_blankerev
.fd
= -1;
4256 Kill(D_blankerpid
, SIGHUP
);
4268 AddStr("\033[m\033[m"); /* why is D_ME not set? */
4275 D_rend
= mchar_null
;
4279 ChangeScrollRegion(oldtop
, oldbot
);
4280 SetRendition(&oldrend
);
4293 char libuf
[20], cobuf
[20];
4297 strcpy(termname
, "TERM=");
4298 strncpy(termname
+ 5, D_termname
, sizeof(termname
) - 6);
4299 termname
[sizeof(termname
) - 1] = 0;
4302 if ((D_blankerev
.fd
= OpenPTY(&m
)) == -1)
4304 Msg(0, "OpenPty failed");
4310 if ((slave
= open(m
, O_RDWR
|O_NOCTTY
)) == -1)
4312 Msg(errno
, "%s", m
);
4313 close(D_blankerev
.fd
);
4314 D_blankerev
.fd
= -1;
4319 switch (pid
= (int)fork())
4323 close(D_blankerev
.fd
);
4324 D_blankerev
.fd
= -1;
4329 if (dfp
&& dfp
!= stderr
)
4335 if (setgid(real_gid
) || setuid(real_uid
))
4336 Panic(errno
, "setuid/setgid");
4342 closeallfiles(slave
);
4343 if (open(m
, O_RDWR
))
4344 Panic(errno
, "Cannot open %s", m
);
4351 SetTTY(0, &D_OldMode
);
4356 glwz
.ws_col
= D_width
;
4357 glwz
.ws_row
= D_height
;
4358 (void)ioctl(0, TIOCSWINSZ
, (char *)&glwz
);
4360 sprintf(libuf
, "LINES=%d", D_height
);
4361 sprintf(cobuf
, "COLUMNS=%d", D_width
);
4366 signal(SIGPIPE
, SIG_DFL
);
4369 execvpe(*cmdv
, cmdv
, NewEnv
+ 3);
4370 Panic(errno
, "%s", *cmdv
);
4375 evenq(&D_blankerev
);
4382 struct layout
*layouts
;
4383 struct layout
*laytab
[MAXLAY
];
4384 struct layout
*layout_last
, layout_last_marker
;
4385 struct layout
*layout_attach
= &layout_last_marker
;
4391 struct canvas
*cnext
, *c
= cv
;
4392 for (; cv
; cv
= cnext
)
4396 FreeLayoutCv(cv
->c_slperp
);
4400 cnext
= cv
->c_slnext
;
4408 DupLayoutCv(cvf
, cvt
, save
)
4409 struct canvas
*cvf
, *cvt
;
4414 cvt
->c_slorient
= cvf
->c_slorient
;
4415 cvt
->c_slweight
= cvf
->c_slweight
;
4416 if (cvf
== D_forecv
)
4420 cvt
->c_display
= display
;
4423 cvt
->c_captev
.type
= EV_TIMEOUT
;
4424 cvt
->c_captev
.data
= (char *)cvt
;
4425 cvt
->c_captev
.handler
= cv_winid_fn
;
4426 cvt
->c_blank
.l_cvlist
= 0;
4427 cvt
->c_blank
.l_layfn
= &BlankLf
;
4428 cvt
->c_blank
.l_bottom
= &cvt
->c_blank
;
4430 cvt
->c_layer
= cvf
->c_layer
;
4434 struct win
*p
= cvf
->c_layer
? Layer2Window(cvf
->c_layer
) : 0;
4435 cvt
->c_layer
= p
? &p
->w_layer
: 0;
4439 cvt
->c_slperp
= (struct canvas
*)calloc(1, sizeof(struct canvas
));
4440 cvt
->c_slperp
->c_slback
= cvt
;
4441 CanvasInitBlank(cvt
->c_slperp
);
4442 DupLayoutCv(cvf
->c_slperp
, cvt
->c_slperp
, save
);
4446 cvt
->c_slnext
= (struct canvas
*)calloc(1, sizeof(struct canvas
));
4447 cvt
->c_slnext
->c_slprev
= cvt
;
4448 cvt
->c_slnext
->c_slback
= cvt
->c_slback
;
4449 CanvasInitBlank(cvt
->c_slnext
);
4451 cvf
= cvf
->c_slnext
;
4452 cvt
= cvt
->c_slnext
;
4461 for (; cv
; cv
= cv
->c_slnext
)
4465 PutWindowCv(cv
->c_slperp
);
4468 p
= cv
->c_layer
? (struct win
*)cv
->c_layer
->l_data
: 0;
4470 SetCanvasWindow(cv
, p
);
4475 CreateLayout(title
, startat
)
4482 if (startat
>= MAXLAY
|| startat
< 0)
4484 for (i
= startat
; ;)
4492 Msg(0, "No more layouts\n");
4496 lay
= (struct layout
*)calloc(1, sizeof(*lay
));
4497 lay
->lay_title
= SaveStr(title
);
4498 lay
->lay_autosave
= 1;
4499 lay
->lay_number
= i
;
4501 lay
->lay_next
= layouts
;
4507 SaveLayout(name
, cv
)
4513 for (lay
= layouts
; lay
; lay
= lay
->lay_next
)
4514 if (!strcmp(lay
->lay_title
, name
))
4517 FreeLayoutCv(&lay
->lay_canvas
);
4519 lay
= CreateLayout(name
, 0);
4523 DupLayoutCv(cv
, &lay
->lay_canvas
, 1);
4524 lay
->lay_forecv
= D_forecv
;
4534 if (!lay
|| !lay
->lay_autosave
)
4536 FreeLayoutCv(&lay
->lay_canvas
);
4538 DupLayoutCv(&D_canvas
, &lay
->lay_canvas
, 1);
4539 lay
->lay_forecv
= D_forecv
;
4550 for (i
= 0, s
= name
; *s
>= '0' && *s
<= '9'; s
++)
4551 i
= i
* 10 + (*s
- '0');
4552 if (!*s
&& s
!= name
&& i
>= 0 && i
< MAXLAY
)
4554 for (lay
= layouts
; lay
; lay
= lay
->lay_next
)
4555 if (!strcmp(lay
->lay_title
, name
))
4565 AutosaveLayout(D_layout
);
4568 while (D_canvas
.c_slperp
)
4569 FreeCanvas(D_canvas
.c_slperp
);
4570 MakeDefaultCanvas();
4571 SetCanvasWindow(D_forecv
, 0);
4575 while (D_canvas
.c_slperp
)
4576 FreeCanvas(D_canvas
.c_slperp
);
4578 D_forecv
= lay
->lay_forecv
;
4579 DupLayoutCv(&lay
->lay_canvas
, &D_canvas
, 0);
4580 D_canvas
.c_ye
= D_height
- 1 - ((D_canvas
.c_slperp
&& D_canvas
.c_slperp
->c_slnext
) || captionalways
) - (D_has_hstatus
== HSTATUS_LASTLINE
);
4581 ResizeCanvas(&D_canvas
);
4582 RecreateCanvasChain();
4583 RethinkDisplayViewports();
4584 PutWindowCv(&D_canvas
);
4585 ResizeLayersToCanvases();
4590 NewLayout(title
, startat
)
4597 lay
= CreateLayout(title
, startat
);
4600 LoadLayout(0, &D_canvas
);
4602 DupLayoutCv(&D_canvas
, &lay
->lay_canvas
, 1);
4603 lay
->lay_forecv
= D_forecv
;
4606 lay
->lay_autosave
= 1;
4610 AddLayoutsInfo(buf
, len
, where
)
4616 struct layout
*p
, **pp
;
4620 for (pp
= laytab
; pp
< laytab
+ MAXLAY
; pp
++)
4622 if (pp
- laytab
== where
&& ss
== buf
)
4630 if (s
- buf
+ l
> len
- 24)
4637 sprintf(s
, "%d", p
->lay_number
);
4638 if (p
->lay_number
== where
)
4641 if (display
&& p
== D_layout
)
4662 Msg(0, "No layouts defined\n");
4665 if (where
== -1 && D_layout
)
4666 where
= D_layout
->lay_number
;
4667 ss
= AddLayoutsInfo(buf
, sizeof(buf
), where
);
4668 s
= buf
+ strlen(buf
);
4669 if (ss
- buf
> D_width
/ 2)
4672 if (s
- ss
< D_width
)
4688 struct layout
**layp
= &layouts
;
4690 for (; *layp
; layp
= &(*layp
)->lay_next
)
4694 *layp
= lay
->lay_next
;
4698 laytab
[lay
->lay_number
] = (struct layout
*)0;
4700 if (display
&& D_layout
== lay
)
4701 D_layout
= (struct layout
*)0;
4703 FreeLayoutCv(&lay
->lay_canvas
);
4706 free(lay
->lay_title
);
4710 LoadLayout((display
&& D_layout
) ? D_layout
: *layp
? *layp
: layouts
,
4711 display
? &D_canvas
: (struct canvas
*)0);