eterm/src/screen.h

312 lines
12 KiB
C
Raw Normal View History

/*--------------------------------*-C-*---------------------------------*
* File: screen.h
*
* This module is all new by Robert Nation
* <nation@rocket.sanders.lockheed.com>
*
* Additional modifications by mj olesen <olesen@me.QueensU.CA>
* No additional restrictions are applied.
*
* As usual, the author accepts no responsibility for anything, nor does
* he guarantee anything whatsoever.
*----------------------------------------------------------------------*/
#ifndef _SCREEN_H
#define _SCREEN_H
#include <X11/Xfuncproto.h>
#include "startup.h"
#ifndef XA_CLIPBOARD
# define XA_CLIPBOARD(d) XA_PRIMARY
#endif
/************ Macros and Definitions ************/
#define WRAP_CHAR (0xff)
#define PROP_SIZE 4096
#define TABSIZE 8 /* default tab size */
#define IS_SELECTION(a) (((a) == XA_PRIMARY) || ((a) == XA_SECONDARY) || ((a) == XA_CLIPBOARD(Xdisplay)))
#define IS_CUT_BUFFER(a) (((a) >= XA_CUT_BUFFER0) && ((a) <= XA_CUT_BUFFER7))
#define ZERO_SCROLLBACK do { \
Thu Feb 10 15:10:01 PST 2000 Michael Jennings <mej@eterm.org> This is the first public availability of the work thus far on Eterm 0.9.1. There's quite a bit of new stuff here. * Added scrollbar thumb support. * Completely redid the terminfo/termcap stuff. The terminfo file is now compiled (by tic) and installed by default (unless you specify --without-terminfo). The config files still say xterm, though, because some programs (like SLang and GNU mc) use the silly algorithm of "Is $TERM set to xterm?" to detect mouse reporting support in a terminal. =P But if you don't ever use xterm, you can use Eterm's termcap and just name it "xterm" instead. Thanks to Marius Gedminas <mgedmin@takas.lt> for his patch that started this whole revamp. * Added the kEsetroot script for KDE users from Dax Games <dgames@isoc.net>. * You can now configure the Home and End emulation via --with-home= and --with-end= options to configure. The --with-terminfo option is also new, and --enable-xim is now the default. * Added a new image state, disabled, for when Eterm loses focus. This is supported by all widgets (well, all those that could possibly be on screen when Eterm lost focus), even the background image. So you could actually have all your images darken on focus out and restore to normal on focus in. * Widget colors formerly dealt with as colors (menu text color, scrollbar color, etc.) are now handled by the imageclasses. Each image state can have a foreground and background color defined. The current exception is the background image; I hope to add that later. The foreground is the text color and the background is the object color (for solid color mode). So menu text color is set by the menu imageclass. And again, for unfocused colors, use the disabled state of the imageclass. * Proportionally-spaced fonts are now handled much better. They are still forced into evenly-spaced columns (it's a terminal for crying out loud!) but at least you don't end up with Eterm's wider than your screen. :-) * Home on refresh is gone, as is home on echo. It's now much simpler. There are two options: home on output, and home on input, the former being a combination of echo and refresh. Also, keypresses that don't necessarily have corresonding output can trigger a home on input, like Ctrl-End or whatever...ones that don't have special meaning. Credit to Darren Stuart Embry <dse@louisville.edu> for pointing out this issue and the one with "m-" in font names. * I finally got around to re-merging the new parser stuff from my work on the Not Game. Closed up some old potential behavior quirks with theme parsing. * Added a new escape sequence to fork-and-exec a program. Also added a scrollback search capability to highlight all occurances of a string in your scrollback buffer. Use the new "Etsearch" utility to access it. "Etsearch string" to search for a string, then "Etsearch" by itself to reset the highlighting. * And of course, the biggie. Eterm now supports a completely- customizeable buttonbar. Not a menubar, a buttonbar. It can have an arbitrary number of buttons, and each button can perform an action, just like a menuitem. So a button could bring up a menu (like a menubar) or launch a program (like a launchbar) or perform an operation (like a toolbar). Each button can have an icon, text, or both. And you can have buttons left- or right-justified in the buttonbar. You will eventually be able to have an arbitrary number of buttonbars, but I'm still working on that. As with any change this big, things could very easily be broken. So beware. :-) I have tested this myself, and everything seems to work, but I can't test every possibility. Let me know if you find anything that's broken, and enjoy! SVN revision: 2048
2000-02-10 16:25:07 -08:00
if (Options & Opt_home_on_output) TermWin.view_start = 0; \
} while (0)
#define REFRESH_ZERO_SCROLLBACK do { \
Thu Feb 10 15:10:01 PST 2000 Michael Jennings <mej@eterm.org> This is the first public availability of the work thus far on Eterm 0.9.1. There's quite a bit of new stuff here. * Added scrollbar thumb support. * Completely redid the terminfo/termcap stuff. The terminfo file is now compiled (by tic) and installed by default (unless you specify --without-terminfo). The config files still say xterm, though, because some programs (like SLang and GNU mc) use the silly algorithm of "Is $TERM set to xterm?" to detect mouse reporting support in a terminal. =P But if you don't ever use xterm, you can use Eterm's termcap and just name it "xterm" instead. Thanks to Marius Gedminas <mgedmin@takas.lt> for his patch that started this whole revamp. * Added the kEsetroot script for KDE users from Dax Games <dgames@isoc.net>. * You can now configure the Home and End emulation via --with-home= and --with-end= options to configure. The --with-terminfo option is also new, and --enable-xim is now the default. * Added a new image state, disabled, for when Eterm loses focus. This is supported by all widgets (well, all those that could possibly be on screen when Eterm lost focus), even the background image. So you could actually have all your images darken on focus out and restore to normal on focus in. * Widget colors formerly dealt with as colors (menu text color, scrollbar color, etc.) are now handled by the imageclasses. Each image state can have a foreground and background color defined. The current exception is the background image; I hope to add that later. The foreground is the text color and the background is the object color (for solid color mode). So menu text color is set by the menu imageclass. And again, for unfocused colors, use the disabled state of the imageclass. * Proportionally-spaced fonts are now handled much better. They are still forced into evenly-spaced columns (it's a terminal for crying out loud!) but at least you don't end up with Eterm's wider than your screen. :-) * Home on refresh is gone, as is home on echo. It's now much simpler. There are two options: home on output, and home on input, the former being a combination of echo and refresh. Also, keypresses that don't necessarily have corresonding output can trigger a home on input, like Ctrl-End or whatever...ones that don't have special meaning. Credit to Darren Stuart Embry <dse@louisville.edu> for pointing out this issue and the one with "m-" in font names. * I finally got around to re-merging the new parser stuff from my work on the Not Game. Closed up some old potential behavior quirks with theme parsing. * Added a new escape sequence to fork-and-exec a program. Also added a scrollback search capability to highlight all occurances of a string in your scrollback buffer. Use the new "Etsearch" utility to access it. "Etsearch string" to search for a string, then "Etsearch" by itself to reset the highlighting. * And of course, the biggie. Eterm now supports a completely- customizeable buttonbar. Not a menubar, a buttonbar. It can have an arbitrary number of buttons, and each button can perform an action, just like a menuitem. So a button could bring up a menu (like a menubar) or launch a program (like a launchbar) or perform an operation (like a toolbar). Each button can have an icon, text, or both. And you can have buttons left- or right-justified in the buttonbar. You will eventually be able to have an arbitrary number of buttonbars, but I'm still working on that. As with any change this big, things could very easily be broken. So beware. :-) I have tested this myself, and everything seems to work, but I can't test every possibility. Let me know if you find anything that's broken, and enjoy! SVN revision: 2048
2000-02-10 16:25:07 -08:00
if (Options & Opt_home_on_output) TermWin.view_start = 0; \
} while (0)
#define CHECK_SELECTION do { \
if (selection.op) selection_check(); \
} while (0)
#define CLEAR_SELECTION (selection.beg.row = selection.beg.col = selection.end.row = selection.end.col = 0)
#define CLEAR_ALL_SELECTION (selection.beg.row = selection.beg.col = selection.mark.row = selection.mark.col = selection.end.row = selection.end.col = 0)
#define scr_touch() (refresh_all = 1)
/*
* CLEAR_ROWS : clear <num> rows starting from row <row>
* CLEAR_CHARS: clear <num> chars starting from pixel position <x,y>
* ERASE_ROWS : set <num> rows starting from row <row> to the foreground color
*/
#define CLEAR_ROWS(row, num) do {if (buffer_pixmap) {XCopyArea(Xdisplay, pmap, buffer_pixmap, TermWin.gc, Col2Pixel(0), Row2Pixel(row), TermWin.width, Height2Pixel(num), \
Col2Pixel(0), Row2Pixel(row));} XClearArea(Xdisplay, TermWin.vt, Col2Pixel(0), Row2Pixel(row), TermWin.width, Height2Pixel(num), 0);} while (0)
#define CLEAR_CHARS(x, y, num) ((buffer_pixmap) \
? (XCopyArea(Xdisplay, pmap, buffer_pixmap, TermWin.gc, x, y, Width2Pixel(num), Height2Pixel(1), x, y)) \
: (XClearArea(Xdisplay, TermWin.vt, x, y, Width2Pixel(num), Height2Pixel(1), 0)))
Fri May 26 20:43:03 PDT 2000 Michael Jennings <mej@eterm.org> Okay, there are a few changes here. First off, I made multi-byte font support the default now, as long as you have ISO 10646 fonts. In order to do this, I made the default encoding type "Latin1" so as not to interfere with 8-bit ISO 8859-1 characters. This means that if you relied on the default multi-byte encoding method to be SJIS, you'll need to update your theme files. I also set it up so that Eterm will ignore SIGHUP, at least until I do something with it (like reloading the theme or something). I fixed the proportional font size algorithm. If there is more than a 3-pixel variance between the minimum and maximum sizes for glyphs in a proportional font, Eterm will set the size to 2 standard deviations above the average width. This is so that they won't look so spread out and ugly, but it still doesn't look perfect. Not much I can do on that front...terminals must have fixed-width columns. And then there's the biggie. I put in the ability to configure the now-infamous font effects. I left a black drop shadow in as the default, but you can now customize it via the --font-fx option or in the config file using "font effects <stuff>" in the attributes context. You can even use "fx" instead of "effects" for short. So what goes in the <stuff> part? Well, you have several options. To use a single-color outline, say "outline <color>". Likewise, a single-color drop shadow is "shadow [corner] <color>"; "bottom_right" is the default corner if you don't specify one. For a 3-D embossed look, "emboss <dark_color> <light_color>". The opposite, a carved- out look, can be had with "carved <dark_color> <light_color>". (Of course, with those last two, the 3-D look will only work if you choose the colors wisely.) Those are all the shortcuts. The long way is to specify a series of corner/color pairs, like "tl blue" for top-left blue, or "bottom_right green". You can abbreviate using "tl," "tr," "bl," or "br," or you can spell out "top_left," "top_right," "bottom_left," or "bottom_right." If you omit a corner name, the first one defaults to top-left, the second to top-right, and so on as listed above. SVN revision: 2714
2000-05-26 20:41:22 -07:00
#define CLEAR_RECT(x, y, w, h) ((buffer_pixmap) \
? (XCopyArea(Xdisplay, pmap, buffer_pixmap, TermWin.gc, x, y, w, h, x, y)) \
: (XClearArea(Xdisplay, TermWin.vt, x, y, w, h, 0)))
#define UPDATE_BOX(x1, y1, x2, y2) do {if (buffer_pixmap) {if (x1 < low_x) low_x = x1; if (x2 > high_x) high_x = x2; \
if (y1 < low_y) low_y = y1; if (y2 > high_y) high_y = y2;}} while (0)
#define ERASE_ROWS(row, num) do {XFillRectangle(Xdisplay, draw_buffer, TermWin.gc, Col2Pixel(0), Row2Pixel(row), TermWin.width, Height2Pixel(num)); \
if (buffer_pixmap) {XClearArea(Xdisplay, TermWin.vt, Col2Pixel(0), Row2Pixel(row), TermWin.width, Height2Pixel(num), 0);}} while (0)
#define DRAW_STRING(Func, x, y, str, len) Func(Xdisplay, draw_buffer, TermWin.gc, x, y, str, len)
#ifndef NO_BRIGHTCOLOR
# define MONO_BOLD(x) (((x) & RS_Bold) && fore == fgColor)
#else
# define MONO_BOLD(x) ((x) & (RS_Bold|RS_Blink))
#endif
/* Screen refresh methods */
#define NO_REFRESH 0 /* Window not visible at all! */
#define FAST_REFRESH (1<<1) /* Fully exposed window */
#define SLOW_REFRESH (1<<2) /* Partially exposed window */
#define SMOOTH_REFRESH (1<<3) /* Do sync'ing to make it smooth */
#define IGNORE 0
#define SAVE 's'
#define RESTORE 'r'
#define REVERT IGNORE
#define INVOKE RESTORE
/* flags for scr_gotorc() */
#define C_RELATIVE 1 /* col movement is relative */
#define R_RELATIVE 2 /* row movement is relative */
#define RELATIVE (R_RELATIVE|C_RELATIVE)
/* modes for scr_insdel_chars(), scr_insdel_lines() */
#define INSERT -1 /* don't change these values */
#define DELETE +1
#define ERASE +2
/* modes for scr_page() - scroll page. used by scrollbar window */
enum {
UP,
DN,
NO_DIR
};
/* arguments for scr_change_screen() */
enum {
PRIMARY,
SECONDARY
};
#define RS_None 0 /* Normal */
#define RS_Cursor 0x01000000u /* cursor location */
#define RS_Select 0x02000000u /* selected text */
#define RS_RVid 0x04000000u /* reverse video */
#define RS_Uline 0x08000000u /* underline */
#define RS_acsFont 0x10000000u /* ACS graphics character set */
#define RS_ukFont 0x20000000u /* UK character set */
#define RS_fontMask (RS_acsFont|RS_ukFont)
#ifdef MULTI_CHARSET
#define RS_multi0 0x40000000u /* only multibyte characters */
#define RS_multi1 0x80000000u /* multibyte 1st byte */
#define RS_multi2 (RS_multi0|RS_multi1) /* multibyte 2nd byte */
#define RS_multiMask (RS_multi0|RS_multi1) /* multibyte mask */
#endif
#define RS_fgMask 0x00001F00u /* 32 colors */
#define RS_Bold 0x00008000u /* bold */
#define RS_bgMask 0x001F0000u /* 32 colors */
#define RS_Blink 0x00800000u /* blink */
#define RS_attrMask (0xFF000000u|RS_Bold|RS_Blink)
/* how to build & extract colors and attributes */
#define GET_FGCOLOR(r) (((r) & RS_fgMask)>>8)
#define GET_BGCOLOR(r) (((r) & RS_bgMask)>>16)
#define GET_ATTR(r) (((r) & RS_attrMask))
#define GET_BGATTR(r) (((r) & (RS_attrMask | RS_bgMask)))
#define SET_FGCOLOR(r,fg) (((r) & ~RS_fgMask) | ((fg)<<8))
#define SET_BGCOLOR(r,bg) (((r) & ~RS_bgMask) | ((bg)<<16))
#define SET_ATTR(r,a) (((r) & ~RS_attrMask)| (a))
#define DEFAULT_RSTYLE (RS_None | (fgColor<<8) | (bgColor<<16))
/* screen_t flags */
#define Screen_Relative (1<<0) /* relative origin mode flag */
#define Screen_VisibleCursor (1<<1) /* cursor visible? */
#define Screen_Autowrap (1<<2) /* auto-wrap flag */
#define Screen_Insert (1<<3) /* insert mode (vs. overstrike) */
#define Screen_WrapNext (1<<4) /* need to wrap for next char? */
#define Screen_DefaultFlags (Screen_VisibleCursor|Screen_Autowrap)
/************ Structures ************/
/* General overview of the screen stuff:
TermWin.saveLines tells us how many lines are in the scrollback buffer.
There are a total of TermWin.saveLines + TermWin.nrow rows in the
screen buffer, with the scrollback coming before the on-screen data.
TermWin.nscrolled tells us how many lines of the scrollback buffer have
actually been used (i.e., allocated). TermWin.view_start tells us how
many lines back into the scrollback buffer the currently-visible data
is. (0 means we're at the bottom and not in scrollback.)
*/
typedef unsigned char text_t;
typedef unsigned int rend_t;
typedef enum {
SELECTION_CLEAR = 0,
SELECTION_INIT,
SELECTION_BEGIN,
SELECTION_CONT,
SELECTION_DONE
} selection_op_t;
typedef enum {
LATIN1 = 0, EUCJ, EUCKR = EUCJ, GB = EUCJ, SJIS, BIG5
} encoding_t;
typedef struct {
short row, col;
} row_col_t;
/* screen_t:
screen.text contains a 2-D array of the screen data. screen.rend contains
a matching 2-D array of rendering information (as 32-bit masks). They are
allocated together, so you can always be sure that screen.rend[r] will be
allocated if screen.text[r] is. You are also guaranteed that each row of
screen.text is TermWin.ncol + 1 columns long, and each row of screen.rend
is TermWin.ncol columns long. They both have (TermWin.nrow +
TermWin.saveLines) rows, but only TermWin.nrow + TermWin.nscrolled lines
are actually allocated. The extra column in the text array is for storing
line wrap information. It will either be the length of the line, or
WRAP_CHAR if the line wraps into the next line.
screen.row and screen.col contain the current cursor position. It is always
somewhere on the visible screen. screen.tscroll and screen.bscroll are the
top and bottom rows of the current scroll region. screen.charset is the
character set currently being used (0-3).
*/
typedef struct {
text_t **text;
rend_t **rend;
short row, col;
short tscroll, bscroll;
unsigned char charset:2;
unsigned char flags:5;
} screen_t;
/* A save_t object is used to save/restore the cursor position and other
relevant data when requested to do so by the application. */
typedef struct {
short row, col;
short charset;
char charset_char;
rend_t rstyle;
} save_t;
/* selection_t:
selection.text is a string containing the current selection text. It is
duplicated from the screen data. selection.len is the length of that string.
selection.op represents the current state, selection-wise. selection.screen
gives the number (0 or 1) of the current screen. selection.clicks tells how
many clicks created the current selection (0-3, or 4 if nothing is selected).
beg, mark, and end represent the row and column of the beginning of the
selection, the click that created the selection, and the end of the selection,
respectively.
-TermWin.nscrolled <= beg.row <= mark.row <= end.row < TermWin.nrow
*/
typedef struct {
text_t *text;
int len;
selection_op_t op;
unsigned short screen:1;
unsigned char clicks:3;
row_col_t beg, mark, end;
} selection_t;
/************ Variables ************/
#ifndef NO_BRIGHTCOLOR
extern unsigned int colorfgbg;
#endif
extern unsigned char refresh_all;
#ifdef MULTI_CHARSET
extern encoding_t encoding_method;
#endif
/************ Function Prototypes ************/
_XFUNCPROTOBEGIN
extern void blank_dline(text_t *, rend_t *, int, rend_t);
extern void blank_sline(text_t *, rend_t *, int);
extern void make_screen_mem(text_t **, rend_t **, int);
extern void scr_reset(void);
extern void scr_release(void);
extern void scr_poweron(void);
extern void scr_cursor(int);
extern int scr_change_screen(int);
extern void scr_color(unsigned int, unsigned int);
extern void scr_rendition(int, int);
extern int scroll_text(int, int, int, int);
extern void scr_add_lines(const unsigned char *, int, int);
extern void scr_backspace(void);
extern void scr_tab(int);
extern void scr_gotorc(int, int, int);
extern void scr_index(int);
extern void scr_erase_line(int);
extern void scr_erase_screen(int);
extern void scr_E(void);
extern void scr_insdel_lines(int, int);
extern void scr_insdel_chars(int, int);
extern void scr_scroll_region(int, int);
extern void scr_cursor_visible(int);
extern void scr_autowrap(int);
extern void scr_relative_origin(int);
extern void scr_insert_mode(int);
extern void scr_set_tab(int);
extern void scr_rvideo_mode(int);
extern void scr_report_position(void);
extern void set_font_style(void);
extern void scr_charset_choose(int);
extern void scr_charset_set(int, unsigned int);
extern void set_multichar_encoding(const char *);
extern int scr_get_fgcolor(void);
extern int scr_get_bgcolor(void);
extern void scr_expose(int, int, int, int);
extern int scr_move_to(int, int);
extern int scr_page(int, int);
extern void scr_bell(void);
extern void scr_printscreen(int);
extern void scr_refresh(int);
Thu Feb 10 15:10:01 PST 2000 Michael Jennings <mej@eterm.org> This is the first public availability of the work thus far on Eterm 0.9.1. There's quite a bit of new stuff here. * Added scrollbar thumb support. * Completely redid the terminfo/termcap stuff. The terminfo file is now compiled (by tic) and installed by default (unless you specify --without-terminfo). The config files still say xterm, though, because some programs (like SLang and GNU mc) use the silly algorithm of "Is $TERM set to xterm?" to detect mouse reporting support in a terminal. =P But if you don't ever use xterm, you can use Eterm's termcap and just name it "xterm" instead. Thanks to Marius Gedminas <mgedmin@takas.lt> for his patch that started this whole revamp. * Added the kEsetroot script for KDE users from Dax Games <dgames@isoc.net>. * You can now configure the Home and End emulation via --with-home= and --with-end= options to configure. The --with-terminfo option is also new, and --enable-xim is now the default. * Added a new image state, disabled, for when Eterm loses focus. This is supported by all widgets (well, all those that could possibly be on screen when Eterm lost focus), even the background image. So you could actually have all your images darken on focus out and restore to normal on focus in. * Widget colors formerly dealt with as colors (menu text color, scrollbar color, etc.) are now handled by the imageclasses. Each image state can have a foreground and background color defined. The current exception is the background image; I hope to add that later. The foreground is the text color and the background is the object color (for solid color mode). So menu text color is set by the menu imageclass. And again, for unfocused colors, use the disabled state of the imageclass. * Proportionally-spaced fonts are now handled much better. They are still forced into evenly-spaced columns (it's a terminal for crying out loud!) but at least you don't end up with Eterm's wider than your screen. :-) * Home on refresh is gone, as is home on echo. It's now much simpler. There are two options: home on output, and home on input, the former being a combination of echo and refresh. Also, keypresses that don't necessarily have corresonding output can trigger a home on input, like Ctrl-End or whatever...ones that don't have special meaning. Credit to Darren Stuart Embry <dse@louisville.edu> for pointing out this issue and the one with "m-" in font names. * I finally got around to re-merging the new parser stuff from my work on the Not Game. Closed up some old potential behavior quirks with theme parsing. * Added a new escape sequence to fork-and-exec a program. Also added a scrollback search capability to highlight all occurances of a string in your scrollback buffer. Use the new "Etsearch" utility to access it. "Etsearch string" to search for a string, then "Etsearch" by itself to reset the highlighting. * And of course, the biggie. Eterm now supports a completely- customizeable buttonbar. Not a menubar, a buttonbar. It can have an arbitrary number of buttons, and each button can perform an action, just like a menuitem. So a button could bring up a menu (like a menubar) or launch a program (like a launchbar) or perform an operation (like a toolbar). Each button can have an icon, text, or both. And you can have buttons left- or right-justified in the buttonbar. You will eventually be able to have an arbitrary number of buttonbars, but I'm still working on that. As with any change this big, things could very easily be broken. So beware. :-) I have tested this myself, and everything seems to work, but I can't test every possibility. Let me know if you find anything that's broken, and enjoy! SVN revision: 2048
2000-02-10 16:25:07 -08:00
extern int scr_strmatch(unsigned long, unsigned long, const char *);
extern void scr_search_scrollback(char *);
extern void scr_dump(void);
extern void scr_dump_to_file(const char *);
extern void selection_check(void);
extern void selection_write(unsigned char *, size_t);
extern void selection_fetch(Window, unsigned, int);
extern void selection_copy_string(Atom, char *, size_t);
extern void selection_copy(Atom);
extern void selection_paste(Atom);
extern void selection_reset(void);
extern void selection_clear(void);
extern void selection_setclr(int, int, int, int, int);
extern void selection_start(int, int);
extern void selection_start_colrow(int, int);
extern void selection_make(Time);
extern void selection_click(int, int, int);
extern void selection_delimit_word(int, int, row_col_t *, row_col_t *);
extern void selection_extend(int, int, int);
extern void selection_extend_colrow(int, int, int, int);
extern void selection_rotate(int, int);
extern void selection_send(XSelectionRequestEvent *);
extern void mouse_report(XButtonEvent *);
extern void mouse_tracking(int, int, int, int, int);
extern void debug_colors(void);
#ifdef MULTI_CHARSET
extern int scr_multi2(void);
extern int scr_multi1(void);
#endif /* MULTI_CHARSET */
_XFUNCPROTOEND
#endif