From 8c0b328bbc429059a2b9462c9b5dcbbeb0d173e7 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 22 May 2014 18:54:32 +0000 Subject: GPLv3 --- src/callback.h | 420 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/encoding.C | 316 +++++++++++++++++++++++++++++++++++++ src/feature.h | 377 ++++++++++++++++++++++++++++++++++++++++++++ src/perl/bell-command | 51 ++++++ src/rxvt.C | 46 ++++++ src/rxvttoolkit.h | 414 +++++++++++++++++++++++++++++++++++++++++++++++++ src/scrollbar-plain.C | 71 +++++++++ src/scrollbar-rxvt.C | 222 ++++++++++++++++++++++++++ src/scrollbar-xterm.C | 89 +++++++++++ src/scrollbar.C | 285 ++++++++++++++++++++++++++++++++++ 10 files changed, 2291 insertions(+) create mode 100644 src/callback.h create mode 100644 src/encoding.C create mode 100644 src/feature.h create mode 100644 src/perl/bell-command create mode 100644 src/rxvt.C create mode 100644 src/rxvttoolkit.h create mode 100644 src/scrollbar-plain.C create mode 100644 src/scrollbar-rxvt.C create mode 100644 src/scrollbar-xterm.C create mode 100644 src/scrollbar.C (limited to 'src') diff --git a/src/callback.h b/src/callback.h new file mode 100644 index 0000000..1b04e56 --- /dev/null +++ b/src/callback.h @@ -0,0 +1,420 @@ +// THIS IS A GENERATED FILE: RUN callback.pl to regenerate it +// THIS IS A GENERATED FILE: callback.pl is part of the GVPE +// THIS IS A GENERATED FILE: distribution. + +/* + callback.h -- C++ callback mechanism + Copyright (C) 2003-2007 Marc Lehmann + + This file is part of GVPE. + + GVPE is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with gvpe; if not, write to the Free Software + Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef CALLBACK_H__ +#define CALLBACK_H__ + +#define CALLBACK_H_VERSION 3 + +template +struct callback; + +template +struct callback +{ + typedef R (*ptr_type)(void *self); + + template + void set (K *object) + { + self = object; + func = thunk; + } + + R call () const + { + return func (self); + } + + R operator ()() const + { + return call (); + } + +private: + + void *self; + ptr_type func; + + template + static R thunk (void *self) + { + klass *obj = static_cast(self); + return (obj->*method) (); + } +}; + +template +struct callback +{ + typedef R (*ptr_type)(void *self, A1); + + template + void set (K *object) + { + self = object; + func = thunk; + } + + R call (A1 a1) const + { + return func (self, a1); + } + + R operator ()(A1 a1) const + { + return call (a1); + } + +private: + + void *self; + ptr_type func; + + template + static R thunk (void *self, A1 a1) + { + klass *obj = static_cast(self); + return (obj->*method) (a1); + } +}; + +template +struct callback +{ + typedef R (*ptr_type)(void *self, A1, A2); + + template + void set (K *object) + { + self = object; + func = thunk; + } + + R call (A1 a1, A2 a2) const + { + return func (self, a1, a2); + } + + R operator ()(A1 a1, A2 a2) const + { + return call (a1, a2); + } + +private: + + void *self; + ptr_type func; + + template + static R thunk (void *self, A1 a1, A2 a2) + { + klass *obj = static_cast(self); + return (obj->*method) (a1, a2); + } +}; + +template +struct callback +{ + typedef R (*ptr_type)(void *self, A1, A2, A3); + + template + void set (K *object) + { + self = object; + func = thunk; + } + + R call (A1 a1, A2 a2, A3 a3) const + { + return func (self, a1, a2, a3); + } + + R operator ()(A1 a1, A2 a2, A3 a3) const + { + return call (a1, a2, a3); + } + +private: + + void *self; + ptr_type func; + + template + static R thunk (void *self, A1 a1, A2 a2, A3 a3) + { + klass *obj = static_cast(self); + return (obj->*method) (a1, a2, a3); + } +}; + +template +struct callback +{ + typedef R (*ptr_type)(void *self, A1, A2, A3, A4); + + template + void set (K *object) + { + self = object; + func = thunk; + } + + R call (A1 a1, A2 a2, A3 a3, A4 a4) const + { + return func (self, a1, a2, a3, a4); + } + + R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const + { + return call (a1, a2, a3, a4); + } + +private: + + void *self; + ptr_type func; + + template + static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4) + { + klass *obj = static_cast(self); + return (obj->*method) (a1, a2, a3, a4); + } +}; + +template +struct callback +{ + typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5); + + template + void set (K *object) + { + self = object; + func = thunk; + } + + R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const + { + return func (self, a1, a2, a3, a4, a5); + } + + R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const + { + return call (a1, a2, a3, a4, a5); + } + +private: + + void *self; + ptr_type func; + + template + static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) + { + klass *obj = static_cast(self); + return (obj->*method) (a1, a2, a3, a4, a5); + } +}; + +template +struct callback +{ + typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6); + + template + void set (K *object) + { + self = object; + func = thunk; + } + + R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const + { + return func (self, a1, a2, a3, a4, a5, a6); + } + + R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const + { + return call (a1, a2, a3, a4, a5, a6); + } + +private: + + void *self; + ptr_type func; + + template + static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) + { + klass *obj = static_cast(self); + return (obj->*method) (a1, a2, a3, a4, a5, a6); + } +}; + +template +struct callback +{ + typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7); + + template + void set (K *object) + { + self = object; + func = thunk; + } + + R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const + { + return func (self, a1, a2, a3, a4, a5, a6, a7); + } + + R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const + { + return call (a1, a2, a3, a4, a5, a6, a7); + } + +private: + + void *self; + ptr_type func; + + template + static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) + { + klass *obj = static_cast(self); + return (obj->*method) (a1, a2, a3, a4, a5, a6, a7); + } +}; + +template +struct callback +{ + typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8); + + template + void set (K *object) + { + self = object; + func = thunk; + } + + R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const + { + return func (self, a1, a2, a3, a4, a5, a6, a7, a8); + } + + R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const + { + return call (a1, a2, a3, a4, a5, a6, a7, a8); + } + +private: + + void *self; + ptr_type func; + + template + static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) + { + klass *obj = static_cast(self); + return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8); + } +}; + +template +struct callback +{ + typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9); + + template + void set (K *object) + { + self = object; + func = thunk; + } + + R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const + { + return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9); + } + + R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const + { + return call (a1, a2, a3, a4, a5, a6, a7, a8, a9); + } + +private: + + void *self; + ptr_type func; + + template + static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) + { + klass *obj = static_cast(self); + return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8, a9); + } +}; + +template +struct callback +{ + typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); + + template + void set (K *object) + { + self = object; + func = thunk; + } + + R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const + { + return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); + } + + R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const + { + return call (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); + } + +private: + + void *self; + ptr_type func; + + template + static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) + { + klass *obj = static_cast(self); + return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); + } +}; + + +#endif diff --git a/src/encoding.C b/src/encoding.C new file mode 100644 index 0000000..0b6d593 --- /dev/null +++ b/src/encoding.C @@ -0,0 +1,316 @@ +/*----------------------------------------------------------------------* + * File: encoding.C + *----------------------------------------------------------------------* + * + * All portions of code are copyright by their respective author/s. + * Copyright (c) 2003-2006 Marc Lehmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *----------------------------------------------------------------------*/ + +#include "../config.h" + +#include "encoding.h" +#include "rxvtutil.h" + +#include +#include + +static const struct n2cs { + const char *name; + codeset cs; +} n2cs[] = { + /* first one found is the normalized one */ + { "ISO88591", CS_ISO8859_1 }, + { "ISO8859PRIMARY", CS_ISO8859_1 }, // some stupid fonts use this (hi tigert) + { "ISO88592", CS_ISO8859_2 }, + { "ISO88593", CS_ISO8859_3 }, + { "ISO88594", CS_ISO8859_4 }, + { "ISO88595", CS_ISO8859_5 }, + { "ISO88596", CS_ISO8859_6 }, + { "ISO88597", CS_ISO8859_7 }, + { "ISO88598", CS_ISO8859_8 }, + { "ISO88599", CS_ISO8859_9 }, + { "ISO885910", CS_ISO8859_10 }, + { "ISO885911", CS_ISO8859_11 }, + { "ISO885913", CS_ISO8859_13 }, + { "ISO885914", CS_ISO8859_14 }, + { "ISO885915", CS_ISO8859_15 }, + { "FCD885915", CS_ISO8859_15 }, + { "ISO885916", CS_ISO8859_16 }, + + { "TIS620*", CS_ISO8859_11 }, // close enough + + { "ISO10646*", CS_UNICODE }, + { "UNICODE", CS_UNICODE }, + { "UTF8", CS_UNICODE }, + + { "ASCII", CS_US_ASCII }, + { "USASCII", CS_US_ASCII }, + { "ANSIX341968", CS_US_ASCII }, + { "ISO6461991IRV", CS_US_ASCII }, // older versions used the currency sign + + { "KOI8R*", CS_KOI8_R }, + { "GOST1976874*", CS_KOI8_R }, + { "KOI8RU", CS_KOI8_U }, + { "KOI8U", CS_KOI8_U }, + + { "VISCII*", CS_VISCII }, + + { "JISX0201*", CS_JIS0201_1976_0 }, + { "JISC6226*", CS_JIS0208_1990_0 }, // also wrongly matches -1987-0? (check Encode::JP) + { "JISX0208*", CS_JIS0208_1990_0 }, // also wrongly matches -1987-0? (check Encode::JP) + { "JISX0212*", CS_JIS0212_1990_0 }, + { "JISX021320001", CS_JIS0213_1 }, + { "JISX021320002", CS_JIS0213_2 }, + { "JISX0221*", CS_UNICODE }, // _very_ close + + { "KSC5601*", CS_KSC5601_1987_0 }, + { "KSX1001*", CS_KSC5601_1987_0 }, + { "KSC5700*", CS_UNICODE }, // unicode plus extensions + + { "BIG5P*", CS_BIG5_PLUS }, + { "BIG5ETEN*", CS_BIG5_EXT }, + { "BIG5*", CS_BIG5 }, + { "GB2312*", CS_GB2312_1980_0 }, + { "GBK*", CS_GBK_0 }, + { "GB6345*", CS_GB2312_1980_0 }, // slightly different to gb2312?? + { "GB8565*", CS_GB2312_1980_0 }, // a superset of gb2312?? + { "GB13000*", CS_UNICODE }, + { "CNS1164319921", CS_CNS11643_1992_1 }, + { "CNS1164319922", CS_CNS11643_1992_2 }, + { "CNS1164319923", CS_CNS11643_1992_3 }, + { "CNS1164319924", CS_CNS11643_1992_4 }, + { "CNS1164319925", CS_CNS11643_1992_5 }, + { "CNS1164319926", CS_CNS11643_1992_6 }, + { "CNS1164319927", CS_CNS11643_1992_7 }, + { "CNS116431992F", CS_CNS11643_1992_F }, + + { 0, CS_UNKNOWN } +}; + +static const char * +normalize_name (const char *name) +{ + static char res[16]; + char *r; + + for (r = res; *name && r < res + 15; name++) + if ((*name >= '0' && *name <= '9') + || (*name >= 'A' && *name <= 'Z')) + *r++ = *name; + else if (*name >= 'a' && *name <= 'z') + *r++ = *name - ('a' - 'A'); + + *r = 0; + + return res; +} + +codeset +codeset_from_name (const char *name) +{ + if (!name) + return CS_UNKNOWN; + + name = normalize_name (name); + + const struct n2cs *i = n2cs; + + do { + int len = strlen (i->name); + + if ((i->name[len - 1] == '*' + && !strncmp (name, i->name, len - 1)) + || !strcmp (name, i->name)) + return i->cs; + + } while ((++i)->name); + + return CS_UNKNOWN; +} + +static unicode_t cs_unknown_to_unicode (uint32_t enc) { return NOCHAR; } +static uint32_t cs_unknown_from_unicode (unicode_t unicode) { return NOCHAR; } + +static unicode_t cs_unicode_to_unicode (uint32_t enc) { return enc; } +static uint32_t cs_unicode_from_unicode (unicode_t unicode) { return unicode; } + +#define cs_us_ascii_to_unicode cs_unicode_to_unicode +static uint32_t cs_us_ascii_from_unicode (unicode_t unicode) { return unicode <= 127 ? unicode : NOCHAR; } + +#define cs_us_ascii_to_unicode_16 cs_unicode_to_unicode +static uint32_t cs_unicode_16_from_unicode (unicode_t unicode) { return unicode <= 65535 ? unicode : NOCHAR; } + +#define ENCODING_DEFAULT + +#include "table/iso8859_1.h" +#include "table/iso8859_15.h" + +//#define ENCODING_EU + +#include "table/iso8859_2.h" +#include "table/iso8859_3.h" +#include "table/iso8859_4.h" +#include "table/iso8859_5.h" +#include "table/iso8859_6.h" +#include "table/iso8859_7.h" +#include "table/iso8859_8.h" +#include "table/iso8859_9.h" +#include "table/iso8859_10.h" +#include "table/iso8859_11.h" +#include "table/iso8859_13.h" +#include "table/iso8859_14.h" +#include "table/iso8859_16.h" + +#include "table/koi8_r.h" +#include "table/koi8_u.h" + +//#define ENCODING_KR + +#include "table/ksc5601_1987_0.h" + +//#define ENCODING_ZH + +#include "table/big5.h" +#include "table/gbk_0.h" +#include "table/gb2312_1980_0.h" + +//#define ENCODING_ZH_EXT + +#include "table/cns11643_1992_1.h" +#include "table/cns11643_1992_2.h" +#include "table/cns11643_1992_3.h" +#include "table/cns11643_1992_4.h" +#include "table/cns11643_1992_5.h" +#include "table/cns11643_1992_6.h" +#include "table/cns11643_1992_7.h" +#include "table/cns11643_1992_f.h" +#include "table/big5_ext.h" +#include "table/big5_plus.h" + +//#define ENCODING_VN + +#include "table/viscii.h" + +//#define ENCODING_JP + +#include "table/jis0201_1976_0.h" +#include "table/jis0208_1990_0.h" +#include "table/jis0212_1990_0.h" + +//#define ENCODING_JP_EXT + +#include "table/jis0213_1.h" +#include "table/jis0213_2.h" + +#if ENCODING_TO_UNICODE +# define ENC(base) { cs_ ## base ## _from_unicode, cs_ ## base ## _to_unicode } +#else +# define ENC(base) { cs_ ## base ## _from_unicode } +#endif + + +// order must match table in encoding.h(!) +const rxvt_codeset_conv rxvt_codeset[NUM_CODESETS] = { + ENC (unknown), + + ENC (us_ascii), + + ENC (iso8859_1), + ENC (iso8859_2), + ENC (iso8859_3), + ENC (iso8859_4), + ENC (iso8859_5), + ENC (iso8859_6), + ENC (iso8859_7), + ENC (iso8859_8), + ENC (iso8859_9), + ENC (iso8859_10), + ENC (iso8859_11), + ENC (iso8859_13), + ENC (iso8859_14), + ENC (iso8859_15), + ENC (iso8859_16), + + ENC (koi8_r), + ENC (koi8_u), + + ENC (jis0201_1976_0), + ENC (jis0208_1990_0), + ENC (jis0212_1990_0), + + ENC (jis0213_1), + ENC (jis0213_2), + + ENC (ksc5601_1987_0), + + ENC (gb2312_1980_0), + ENC (gbk_0), + + ENC (cns11643_1992_1), + ENC (cns11643_1992_2), + ENC (cns11643_1992_3), + ENC (cns11643_1992_4), + ENC (cns11643_1992_5), + ENC (cns11643_1992_6), + ENC (cns11643_1992_7), + ENC (cns11643_1992_f), + ENC (big5), + ENC (big5_ext), + ENC (big5_plus), + + ENC (viscii), + + ENC (unicode_16), + ENC (unicode), +}; + +#if ENABLE_COMBINING +# define ENCODING_COMPOSE +#endif + +#include "table/compose.h" + +unicode_t +rxvt_compose (unicode_t c1, unicode_t c2) +{ + int l = 0; + int r = ecb_array_length (rxvt_compose_table) - 1; + int m; + + while (r >= l) + { + m = (l + r) / 2; + rxvt_compose_entry &c = rxvt_compose_table[m]; + + if (c.c1 < c1 || (c.c1 == c1 && c.c2 < c2)) + l = m + 1; + else if (c.c1 > c1 || (c.c1 == c1 && c.c2 > c2)) + r = m - 1; + else + return c.r; + } + + return NOCHAR; +} + +#include "table/category.h" + +bool unicode::is_space (unicode_t c) +{ + return IS_SPACE (c) + || c == 0x09; // exclude tabs, too, as we store them in the buffer +} diff --git a/src/feature.h b/src/feature.h new file mode 100644 index 0000000..39e080e --- /dev/null +++ b/src/feature.h @@ -0,0 +1,377 @@ +/* + * File: feature.h + * + * Compile-time configuration. + *----------------------------------------------------------------------- + * Copyright (c) 1997,1998 Oezguer Kesim + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + *----------------------------------------------------------------------*/ +#ifndef FEATURE_H +#define FEATURE_H + +#ifndef X11USRLIBDIR +# define X11USRLIBDIR "/usr/lib" +#endif +#ifndef X11LIBDIR +# define X11LIBDIR X11USRLIBDIR "/X11" +#endif +#ifndef XAPPLOADDIR +# define XAPPLOADDIR X11LIBDIR "/app-defaults" +# define XAPPLOADDIRLOCALE X11LIBDIR "/%s/app-defaults" +#endif + +/*-----------------------SCREEN OPTIONS AND COLOURS---------------------*/ + +/* + * NOTE: + * + * Some of these configuration options have not been tested within the new + * rxvt-unicode framework. Changing them should work, might have no effect, + * destroy your disks or have any other effects. You may freely try (and + * report bugs, too!), but don't _expect_ them to work. + */ + +/* + * The cursor blink interval, in seconds. + */ +#define CURSOR_BLINK_INTERVAL 0.5 + +/* + * The text blink interval, in seconds. + */ +#define TEXT_BLINK_INTERVAL CURSOR_BLINK_INTERVAL + +/* + * Avoid enabling the colour cursor (-cr, cursorColor, cursorColor2) + */ +/* #define NO_CURSORCOLOR */ + +/* + * Make colours match xterm colours instead of `traditional' rxvt colours + */ +#define XTERM_COLORS + +/* + * Disable separate colours for bold, underline and reverse video + */ +/* #define NO_BOLD_UNDERLINE_REVERSE */ + +/* + * Define maximum possible columns and rows + */ +#define MAX_COLS 10000 +#define MAX_ROWS 10000 + +/* + * Define maximum possible savelines + */ +#define MAX_SAVELINES 10000000 + +/* + * Define to remove support for XCopyArea () support. XCopyArea () is useful + * for scrolling on non-local X displays + */ +#define NO_SLOW_LINK_SUPPORT + +/* + * Allow 80/132 mode switching on startup + */ +/* #define ALLOW_132_MODE */ + +/*---------------------------------KEYS---------------------------------*/ + +/* + * Enable the keysym resource which allows you to define strings associated + * with various KeySyms (0xFF00 - 0xFFFF). + * Required by perl. + */ +#if ENABLE_FRILLS || ENABLE_PERL +# define KEYSYM_RESOURCE +#endif + +/* + * Modifier/s to use to allow up/down arrows and Prior/Next keys + * to scroll single or page-fulls + */ +#define SCROLL_ON_SHIFT +/* #define SCROLL_ON_CTRL */ +/* #define SCROLL_ON_META */ + +/* + * Allow scrolling with modifier+Up/Down keys, in addition + * to modifier+Prior/Next? (modifier is controlled with + * SCROLL_ON_* defines above.). + * Also for modifier+Home/End keys to move to top/bottom + */ +/* #define SCROLL_ON_UPDOWN_KEYS */ +/* #define SCROLL_ON_HOMEEND_KEYS */ + +/* + * Allow unshifted Next/Prior keys to scroll forward/back + * (in addition to shift+Next/shift+Prior) --pjh + */ +/* #define UNSHIFTED_SCROLLKEYS */ + +/* (Hops) Set to choose a number of lines of context between pages + * (rather than a proportion (1/5) of savedlines buffer) + * when paging the savedlines with SHIFT-{Prior,Next} keys. + */ +#define PAGING_CONTEXT_LINES 1 + +/* + * Have either Ctrl+Tab or Mod4+Tab emit \e\t + * Useful when window manager grabs Alt+Tab -- mg + */ +/* #define CTRL_TAB_MAKES_META */ +/* #define MOD4_TAB_MAKES_META */ + +/*--------------------------------MOUSE---------------------------------*/ +/* + * Disable sending escape sequences (up, down, page up/down) + * from the scrollbar when XTerm mouse reporting is enabled + */ +/* #define NO_SCROLLBAR_REPORT */ + +/* + * Have mouse reporting include double-click info for button1 + */ +/* #define MOUSE_REPORT_DOUBLECLICK */ + +/* + * Set delay between multiple click events [default: 500 milliseconds] + */ +/* #define MULTICLICK_TIME 500 */ + +/* + * Time factor to slow down a `jumpy' mouse. Motion isn't recognised until + * this long after the last mouse click [default: 50 milliseconds] + */ +#define MOUSE_THRESHOLD 50 + +/* + * Set delay periods for continuous scrolling with scrollbar buttons + */ +/* #define SCROLLBAR_INITIAL_DELAY 0.33 */ +/* #define SCROLLBAR_CONTINUOUS_DELAY 0.05 */ + +/* + * The speed of selection scrolling is proportional to the distance + * the mouse pointer is out of the text window. This is the max + * number of lines to scroll at a time. + */ +#define SELECTION_SCROLL_MAX_LINES 8 + +/* + * The number of lines (measured in character's heights, not pixels) + * the pointer must be out of the window for each increase in the + * number of lines scrolled. + */ +#define SELECTION_SCROLL_LINE_SPEEDUP 3 + +/*--------------------------------MISC----------------------------------*/ +/* + * Only log in wtmp and lastlog files when we're a login shell (-ls option) + */ +#define LOG_ONLY_ON_LOGIN + +/*--------------------------------BELL----------------------------------*/ +/* + * Disable all bell indications + */ +/* #define NO_BELL */ + +/* + * Disable automatic de-iconify when a bell is received + */ +/* #define NO_MAPALERT */ + +/* + * Have mapAlert behaviour selectable with mapAlert resource + */ +#define MAPALERT_OPTION + +/*-----------------------------SCROLL BAR-------------------------------*/ +/* + * Choose the rxvt style scrollbar width + * - should be an even number [default: 10] + */ +/* #define SB_WIDTH_RXVT 10 */ + +/* + * Minimum and maximum widths of the scrollbar (all styles) + */ +#define SB_WIDTH_MINIMUM 5 +#define SB_WIDTH_MAXIMUM 100 + +/* + * rxvt scrollbar shadow width in pixels, must be 1 or 2 + */ +#define SHADOW_WIDTH 1 + +/* + * clicking above or below the scrollbar slider (all styles minus + * xterm) will scroll by (height - 1) rather than (height / 4). + */ +#define RXVT_SCROLL_FULL 1 + +/* + * (Hops) draw an internal border line on inside edge of the rxvt scrollbar + */ +/* #define SB_BORDER */ + +/*---------------------------MULTILINGUAL-------------------------------*/ +/* + * Allow run-time selection of Meta (Alt) to set the 8th bit on + */ +#define META8_OPTION + +/*---------------------------DISPLAY OPTIONS----------------------------*/ +/* + * Force local connection to be socket (or other local) communication + */ +/* #define LOCAL_X_IS_UNIX */ + +/* + * Have DISPLAY environment variable & "\E[7n" transmit display with IP number + */ +/* #define DISPLAY_IS_IP */ + +/* + * Change what ESC Z transmits instead of the default "\E[?1;2c" + */ +/* #define ESCZ_ANSWER "\033[?1;2C" */ + +/* + * Allow foreground/background colour to be changed with xterm + * operating system commands. + */ +#define XTERM_COLOR_CHANGE + +/* + * Remove secondary screen's independent cursor position, a la xterm + */ +/* #define NO_SECONDARY_SCREEN_CURSOR */ + +/* + * Provide termcap/terminfo bw support (wrap backwards on cub1) + */ +#define TERMCAP_HAS_BW 1 + +/* + * The duration of the visual bell flash in s. The default of 20ms + * corresponds to the delay given in the terminfo flash code. + */ +#define VISUAL_BELL_DURATION .020 + +/*--------------------------------OTHER---------------------------------*/ + +/* + * Enable the linux yield/usleep hack, which can dramatically improve + * performance by working around the linux kernel tty ratelimit bug. + * Unfortunately, it seems screen is negatively affected by this on some + * machines, so it is disabled by default. Use freebsd or any other kernel + * that doesn't suffer from this bug and it will be fast either way. + * + * See command.C for details. + */ +#if __linux__ +# define LINUX_YIELD_HACK 0 +#endif + +/* DEFAULT RESOURCES VALUES */ + +/* + * Define default colours for certain items. If you have a low colour + * display, then consider using colours which are already pre-allocated: + * + * Black (#000000) + * Red3 (#CD0000) + * Green3 (#00CD00) + * Yellow3 (#CDCD00) + * Blue3 (#0000CD) + * Magenta3 (#CD00CD) + * Cyan3 (#00CDCD) + * AntiqueWhite (#FAEBD7) + * Grey25 (#404040) + * Red (#FF0000) + * Green (#00FF00) + * Yellow (#FFFF00) + * Blue (#0000FF) + * Magenta (#FF00FF) + * Cyan (#00FFFF) + * White (#FFFFFF) + */ +/* These colours MUST be defined */ +#define COLOR_FOREGROUND "rgb:00/00/00" +#define COLOR_BACKGROUND "rgb:ff/ff/ff" +#define COLOR_SCROLLBAR "rgb:b2/b2/b2" /* scrollColor match Netscape */ +#define COLOR_SCROLLTROUGH "rgb:96/96/96" + +/* + * The cursor colours are special. Be very careful about setting these: + * foreground/background colours may be modified by command line or resources + * prior to this allocation. Also, they are not valid if NO_CURSORCOLOR is + * defined + */ +#define COLOR_CURSOR_FOREGROUND NULL /* if NULL, use background colour */ +#define COLOR_CURSOR_BACKGROUND NULL /* if NULL, use foreground colour */ + +/* + * Printer pipe which will be used for emulation of attached vt100 printer + */ +#define PRINTPIPE "lpr" + +/* + * Define defaults for backspace and delete keys - unless they have been + * configured out with --disable-backspace-key / --disable-delete-key + */ +#define DEFAULT_BACKSPACE "DEC" /* SPECIAL */ +#define DEFAULT_DELETE "\033[3~" + +/* + * Default separating chars for multiple-click selection + * Space and tab are separate separating characters and are not settable + */ +#define CUTCHARS "\"&'()*,;<=>?@[\\]^`{|}" + +/* + * Width of the term internal border + */ +#define INTERNALBORDERWIDTH 2 + +/* + * Width of the term external border + */ +#define EXTERNALBORDERWIDTH 0 + +/* + * Default number of extra dots between lines + */ +#define LINESPACE 0 + +/* + * Default number of extra dots between columns + */ +#define LETTERSPACE 0 + +/* + * Default number of lines in the scrollback buffer + */ +#define SAVELINES 1000 + +#endif + diff --git a/src/perl/bell-command b/src/perl/bell-command new file mode 100644 index 0000000..d499ca5 --- /dev/null +++ b/src/perl/bell-command @@ -0,0 +1,51 @@ +#! perl + +# Copyright (C) 2011 Ryan Kavanagh +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +#:META:RESOURCE:%:string:the shell snippet to execute + +=head1 NAME + +bell-command - execute a command when the bell rings + +=head1 DESCRIPTION + +Runs the command specified by the C resource when +a bell event occurs. For example, the following pops up a notification +bubble with the text "Beep, Beep" using notify-send: + + URxvt.bell-command: notify-send "Beep, Beep" + +=cut + +sub on_start { + my ($self) = @_; + + $self->{bell_cmd} = $self->x_resource ("bell-command"); + + () +} + +sub on_bell { + my ($self) = @_; + + if (defined $self->{bell_cmd}) { + $self->exec_async ($self->{bell_cmd}); + } + + () +} diff --git a/src/rxvt.C b/src/rxvt.C new file mode 100644 index 0000000..32bc23a --- /dev/null +++ b/src/rxvt.C @@ -0,0 +1,46 @@ +/*----------------------------------------------------------------------* + * File: rxvt.C + *----------------------------------------------------------------------* + * + * All portions of code are copyright by their respective author/s. + * Copyright (c) 2003-2006 Marc Lehmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *----------------------------------------------------------------------*/ + +#include "../config.h" +#include "rxvt.h" + +#include +#include + +int +main (int argc, char *argv[]) +try + { + ptytty::init (); + rxvt_init (); + + rxvt_term *t = new rxvt_term; + t->init (argc, argv, environ); + ev_run (); + + return EXIT_SUCCESS; + } +catch (const class rxvt_failure_exception &e) + { + return EXIT_FAILURE; + } + diff --git a/src/rxvttoolkit.h b/src/rxvttoolkit.h new file mode 100644 index 0000000..56c9a3f --- /dev/null +++ b/src/rxvttoolkit.h @@ -0,0 +1,414 @@ +/*----------------------------------------------------------------------* + * File: rxvttoolkit.h - provide toolkit-functionality for rxvt. + *----------------------------------------------------------------------* + * + * All portions of code are copyright by their respective author/s. + * Copyright (c) 2003-2011 Marc Lehmann + * Copyright (c) 2011 Emanuele Giaquinta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *----------------------------------------------------------------------*/ + +#ifndef RXVT_TOOLKIT_H +#define RXVT_TOOLKIT_H + +#include + +#if XFT +# include +#endif + +#include "ev_cpp.h" + +#include "rxvtutil.h" + +#include "callback.h" + +// see rxvttoolkit.C:xa_names, which must be kept in sync +enum { + XA_TEXT, + XA_COMPOUND_TEXT, + XA_UTF8_STRING, + XA_MULTIPLE, + XA_TARGETS, + XA_TIMESTAMP, + XA_VT_SELECTION, + XA_INCR, + XA_WM_PROTOCOLS, + XA_WM_DELETE_WINDOW, + XA_CLIPBOARD, + XA_AVERAGE_WIDTH, + XA_WEIGHT_NAME, + XA_SLANT, + XA_CHARSET_REGISTRY, + XA_CHARSET_ENCODING, +#if ENABLE_FRILLS + XA_MOTIF_WM_HINTS, +#endif +#if ENABLE_EWMH + XA_NET_WM_PID, + XA_NET_WM_NAME, + XA_NET_WM_ICON_NAME, + XA_NET_WM_PING, + XA_NET_WM_ICON, +#endif +#if USE_XIM + XA_WM_LOCALE_NAME, + XA_XIM_SERVERS, +#endif +#if HAVE_IMG || ENABLE_PERL + XA_XROOTPMAP_ID, + XA_ESETROOT_PMAP_ID, +#endif +#if ENABLE_XEMBED + XA_XEMBED, + XA_XEMBED_INFO, +#endif +#if !ENABLE_MINIMAL + // these are usually allocated by other subsystems, but we do it + // here to avoid a server roundtrip. + XA_SCREEN_RESOURCES, + XA_XDCCC_LINEAR_RGB_CORRECTION, + XA_XDCCC_LINEAR_RGB_MATRICES, + XA_WM_COLORMAP_WINDOWS, + XA_WM_STATE, + XA_cursor, +# if USE_XIM + // various selection targets used by XIM + XA_TRANSPORT, + XA_LOCALES, + XA__XIM_PROTOCOL, + XA__XIM_XCONNECT, + XA__XIM_MOREDATA, +# endif +#endif + NUM_XA +}; + +struct rxvt_term; +struct rxvt_display; + +struct im_watcher; +struct xevent_watcher; + +template +struct event_vec : vector +{ + void erase_unordered (unsigned int pos) + { + watcher *w = (*this)[this->size () - 1]; + this->pop_back (); + + if (!this->empty ()) + if (((*this)[pos] = w)) // '=' is correct! + w->active = pos + 1; + } +}; + +struct rxvt_watcher +{ + int active; /* 0 == inactive, else index into respective vector */ + + bool is_active () { return active; } + + rxvt_watcher () : active (0) { } +}; + +struct refcounted +{ + int referenced; + char *id; + + refcounted (const char *id); + bool ref_init () { return false; } + void ref_next () { } + ~refcounted (); +}; + +template +struct refcache : vector +{ + T *get (const char *id); + void put (T *obj); + void clear (); + + ~refcache () + { + clear (); + } +}; + +///////////////////////////////////////////////////////////////////////////// + +struct rxvt_screen; + +struct rxvt_drawable +{ + rxvt_screen *screen; + Drawable drawable; + operator Drawable() { return drawable; } + +#if XFT + XftDraw *xftdrawable; + operator XftDraw *(); +#endif + + rxvt_drawable (rxvt_screen *screen, Drawable drawable) + : screen(screen), +#if XFT + xftdrawable(0), +#endif + drawable(drawable) + { } + +#if XFT + ~rxvt_drawable (); +#endif +}; + +///////////////////////////////////////////////////////////////////////////// + +#if USE_XIM +struct rxvt_xim : refcounted +{ + void destroy (); + rxvt_display *display; + +//public + XIM xim; + + rxvt_xim (const char *id) : refcounted (id) { } + bool ref_init (); + ~rxvt_xim (); +}; +#endif + +struct rxvt_screen +{ + rxvt_display *display; + Display *dpy; + int depth; + Visual *visual; + Colormap cmap; + +#if XFT + // scratch pixmap + rxvt_drawable *scratch_area; + int scratch_w, scratch_h; + + rxvt_drawable &scratch_drawable (int w, int h); + + rxvt_screen (); +#endif + + void set (rxvt_display *disp); + void select_visual (int id); + void select_depth (int bitdepth); // select visual by depth + void clear (); +}; + +enum +{ + DISPLAY_HAS_RENDER = 1 << 0, + DISPLAY_HAS_RENDER_CONV = 1 << 1, +}; + +struct rxvt_display : refcounted +{ + event_vec xw; + + ev::prepare flush_ev; void flush_cb (ev::prepare &w, int revents); + ev::io x_ev ; void x_cb (ev::io &w, int revents); + +#if USE_XIM + refcache xims; + vector imw; + + void im_change_cb (); + void im_change_check (); +#endif + +//public + Display *dpy; + int screen; + Window root; + rxvt_term *selection_owner; + rxvt_term *clipboard_owner; + Atom xa[NUM_XA]; + bool is_local; +#ifdef POINTER_BLANK + Cursor blank_cursor; +#endif + uint8_t flags; + + rxvt_display (const char *id); + XrmDatabase get_resources (bool refresh); + bool ref_init (); + void ref_next (); + ~rxvt_display (); + + void flush () + { + flush_ev.start (); + } + + Atom atom (const char *name); + Pixmap get_pixmap_property (Atom property); + void set_selection_owner (rxvt_term *owner, bool clipboard); + + void reg (xevent_watcher *w); + void unreg (xevent_watcher *w); + +#if USE_XIM + void reg (im_watcher *w); + void unreg (im_watcher *w); + + rxvt_xim *get_xim (const char *locale, const char *modifiers); + void put_xim (rxvt_xim *xim); +#endif +}; + +#if USE_XIM +struct im_watcher : rxvt_watcher, callback +{ + void start (rxvt_display *display) + { + display->reg (this); + } + + void stop (rxvt_display *display) + { + display->unreg (this); + } +}; +#endif + +struct xevent_watcher : rxvt_watcher, callback +{ + Window window; + + void start (rxvt_display *display, Window window) + { + this->window = window; + display->reg (this); + } + + void stop (rxvt_display *display) + { + display->unreg (this); + } +}; + +extern refcache displays; + +///////////////////////////////////////////////////////////////////////////// + +typedef unsigned long Pixel; + +struct rgba +{ + uint16_t r, g, b, a; + + enum { MIN_CC = 0x0000, MAX_CC = 0xffff }; + + rgba () + { } + + rgba (uint16_t r, uint16_t g, uint16_t b, uint16_t a = MAX_CC) + : r(r), g(g), b(b), a(a) + { } +}; + +struct rxvt_color +{ +#if XFT + XftColor c; +#else + XColor c; +#endif + + operator Pixel () const { return c.pixel; } + + bool operator == (const rxvt_color &b) const { return Pixel (*this) == Pixel (b); } + bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); } + + bool is_opaque () const + { +#if XFT + return c.color.alpha == rgba::MAX_CC; +#else + return 1; +#endif + } + + bool alloc (rxvt_screen *screen, const rgba &color); + void free (rxvt_screen *screen); + + operator rgba () const + { + rgba c; + get (c); + return c; + } + void get (rgba &color) const; + void get (XColor &color) const; + + bool set (rxvt_screen *screen, const char *name); + bool set (rxvt_screen *screen, const rgba &color); + + void fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to = rgba (0, 0, 0)); +}; + +#define Sel_normal 0x01 /* normal selection */ +#define Sel_incr 0x02 /* incremental selection */ +#define Sel_Primary 0x01 +#define Sel_Secondary 0x02 +#define Sel_Clipboard 0x03 +#define Sel_whereMask 0x0f +#define Sel_CompoundText 0x10 /* last request was COMPOUND_TEXT */ +#define Sel_UTF8String 0x20 /* last request was UTF8_STRING */ + +struct rxvt_selection +{ + rxvt_selection (rxvt_display *disp, int selnum, Time tm, Window win, Atom prop, rxvt_term *term); + void run (); + ~rxvt_selection (); + + rxvt_term *term; // terminal to paste to, may be 0 + void *cb_sv; // managed by perl + + rxvt_display *display; + Time request_time; + Window request_win; + Atom request_prop; + +private: + unsigned char selection_wait; + unsigned char selection_type; + + char *incr_buf; + size_t incr_buf_size, incr_buf_fill; + + void timer_cb (ev::timer &w, int revents); ev::timer timer_ev; + void x_cb (XEvent &xev); xevent_watcher x_ev; + + void finish (char *data = 0, unsigned int len = 0); + void stop (); + bool request (Atom target, int selnum); + void handle_selection (Window win, Atom prop, bool delete_prop); +}; + +#endif + diff --git a/src/scrollbar-plain.C b/src/scrollbar-plain.C new file mode 100644 index 0000000..cafc574 --- /dev/null +++ b/src/scrollbar-plain.C @@ -0,0 +1,71 @@ +/*----------------------------------------------------------------------* + * File: scrollbar-plain.C + *----------------------------------------------------------------------* + * + * Copyright (c) 1997,1998 mj olesen + * Copyright (c) 1999-2001 Geoff Wing + * Copyright (c) 2004-2006 Marc Lehmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *----------------------------------------------------------------------*/ + +#include "../config.h" /* NECESSARY */ +#include "rxvt.h" /* NECESSARY */ + +/*----------------------------------------------------------------------*/ +#if defined(PLAIN_SCROLLBAR) + +int +scrollBar_t::show_plain (int update) +{ + int xsb = 0; + int sbwidth = width - 1; + + if ((init & SB_STYLE_PLAIN) == 0) + { + XGCValues gcvalue; + + init |= SB_STYLE_PLAIN; + gcvalue.foreground = term->pix_colors_focused[Color_scroll]; + + pscrollbarGC = XCreateGC (term->dpy, win, GCForeground, &gcvalue); + } + + xsb = term->option (Opt_scrollBar_right) ? 1 : 0; + + if (update) + { + if (last_top < top) + XClearArea (term->dpy, win, + 0, last_top, + sbwidth + 1, top - last_top, False); + + if (bot < last_bot) + XClearArea (term->dpy, win, + 0, bot, + sbwidth + 1, last_bot - bot, False); + } + else + XClearWindow (term->dpy, win); + + /* scrollbar slider */ + XFillRectangle (term->dpy, win, pscrollbarGC, + 1 - xsb, top, sbwidth, bot - top); + + return 1; +} + +#endif + diff --git a/src/scrollbar-rxvt.C b/src/scrollbar-rxvt.C new file mode 100644 index 0000000..6359081 --- /dev/null +++ b/src/scrollbar-rxvt.C @@ -0,0 +1,222 @@ +/*----------------------------------------------------------------------* + * File: scrollbar-rxvt.C + *----------------------------------------------------------------------* + * + * Copyright (c) 1997,1998 mj olesen + * Copyright (c) 1999-2001 Geoff Wing + * Copyright (c) 2004-2006 Marc Lehmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *----------------------------------------------------------------------*/ + +#include "../config.h" /* NECESSARY */ +#include "rxvt.h" /* NECESSARY */ + +/*----------------------------------------------------------------------*/ +#if defined(RXVT_SCROLLBAR) + +static void +draw_shadow (scrollBar_t *sb, int x, int y, int w, int h) +{ + int shadow; + Drawable d = sb->win; + Display *dpy = sb->term->dpy; + + shadow = (w == 0 || h == 0) ? 1 : SHADOW_WIDTH; + w += x - 1; + h += y - 1; + + for (; shadow-- > 0; x++, y++, w--, h--) + { + XDrawLine (dpy, d, sb->topShadowGC, x, y, w , y ); + XDrawLine (dpy, d, sb->topShadowGC, x, y, x , h ); + XDrawLine (dpy, d, sb->botShadowGC, w, h, w , y + 1); + XDrawLine (dpy, d, sb->botShadowGC, w, h, x + 1, h ); + } +} + +/* draw triangular button with a shadow of 2 pixels */ +static void +draw_button (scrollBar_t *sb, int x, int y, int dirn) +{ + unsigned int sz, sz2; + XPoint pt[3]; + GC top, bot; + Drawable d = sb->win; + Display *dpy = sb->term->dpy; + + sz = sb->width; + sz2 = sz / 2; + + if ((dirn == UP && sb->state == SB_STATE_UP) + || (dirn == DN && sb->state == SB_STATE_DOWN)) + { + top = sb->botShadowGC; + bot = sb->topShadowGC; + } + else + { + top = sb->topShadowGC; + bot = sb->botShadowGC; + } + + /* fill triangle */ + pt[0].x = x; + pt[1].x = x + sz - 1; + pt[2].x = x + sz2; + + if (dirn == UP) + { + pt[0].y = pt[1].y = y + sz - 1; + pt[2].y = y; + } + else + { + pt[0].y = pt[1].y = y; + pt[2].y = y + sz - 1; + } + + XFillPolygon (dpy, d, sb->scrollbarGC, + pt, 3, Convex, CoordModeOrigin); + + /* draw base */ + XDrawLine (dpy, d, (dirn == UP ? bot : top), + pt[0].x, pt[0].y, pt[1].x, pt[1].y); + + /* draw shadow on left */ + pt[1].x = x + sz2 - 1; + pt[1].y = y + (dirn == UP ? 0 : sz - 1); + XDrawLine (dpy, d, top, + pt[0].x, pt[0].y, pt[1].x, pt[1].y); + +#if SHADOW_WIDTH > 1 + /* doubled */ + pt[0].x++; + + if (dirn == UP) + { + pt[0].y--; + pt[1].y++; + } + else + { + pt[0].y++; + pt[1].y--; + } + + XDrawLine (dpy, d, top, + pt[0].x, pt[0].y, pt[1].x, pt[1].y); +#endif + + /* draw shadow on right */ + pt[1].x = x + sz - 1; + /* pt[2].x = x + sz2; */ + pt[1].y = y + (dirn == UP ? sz - 1 : 0); + pt[2].y = y + (dirn == UP ? 0 : sz - 1); + XDrawLine (dpy, d, bot, + pt[2].x, pt[2].y, pt[1].x, pt[1].y); + +#if SHADOW_WIDTH > 1 + /* doubled */ + pt[1].x--; + if (dirn == UP) + { + pt[2].y++; + pt[1].y--; + } + else + { + pt[2].y--; + pt[1].y++; + } + + XDrawLine (dpy, d, bot, + pt[2].x, pt[2].y, pt[1].x, pt[1].y); +#endif +} + +int +scrollBar_t::show_rxvt (int update) +{ + int sbwidth = (int)width; + + if ((init & SB_STYLE_RXVT) == 0) + { + XGCValues gcvalue; + + init |= SB_STYLE_RXVT; + + gcvalue.foreground = term->pix_colors[Color_topShadow]; + topShadowGC = XCreateGC (term->dpy, term->vt, GCForeground, &gcvalue); + gcvalue.foreground = term->pix_colors[Color_bottomShadow]; + botShadowGC = XCreateGC (term->dpy, term->vt, GCForeground, &gcvalue); + gcvalue.foreground = term->pix_colors[ (term->depth <= 2 ? Color_fg : Color_scroll)]; + scrollbarGC = XCreateGC (term->dpy, term->vt, GCForeground, &gcvalue); + } + else + { + if (update) + { + if (last_top < top) + XClearArea (term->dpy, win, + shadow, last_top, + sbwidth, (top - last_top), + False); + + if (bot < last_bot) + XClearArea (term->dpy, win, + shadow, bot, + sbwidth, (last_bot - bot), + False); + } + else + XClearWindow (term->dpy, win); + } + + /* scrollbar slider */ +#ifdef SB_BORDER + { + int xofs; + + if (term->option (Opt_scrollBar_right)) + xofs = 0; + else + xofs = shadow ? sbwidth : sbwidth - 1; + + XDrawLine (term->dpy, win, botShadowGC, + xofs, 0, xofs, end + sbwidth); + } +#endif + + XFillRectangle (term->dpy, win, scrollbarGC, + shadow, top, sbwidth, + bot - top); + + if (shadow) + /* trough shadow */ + draw_shadow (this, 0, 0, sbwidth + 2 * shadow, end + (sbwidth + 1) + shadow); + + /* shadow for scrollbar slider */ + draw_shadow (this, shadow, top, sbwidth, bot - top); + + /* Redraw scrollbar arrows */ + draw_button (this, shadow, shadow, UP); + draw_button (this, shadow, end + 1, DN); + + return 1; +} +#endif /* RXVT_SCROLLBAR */ +/*----------------------- end-of-file (C source) -----------------------*/ + diff --git a/src/scrollbar-xterm.C b/src/scrollbar-xterm.C new file mode 100644 index 0000000..e37fe20 --- /dev/null +++ b/src/scrollbar-xterm.C @@ -0,0 +1,89 @@ +/*----------------------------------------------------------------------* + * File: scrollbar-xterm.C + *----------------------------------------------------------------------* + * + * Copyright (c) 1997,1998 mj olesen + * Copyright (c) 1999-2001 Geoff Wing + * Copyright (c) 2004-2006 Marc Lehmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *----------------------------------------------------------------------*/ + +#include "../config.h" /* NECESSARY */ +#include "rxvt.h" /* NECESSARY */ + +/*----------------------------------------------------------------------*/ +#if defined(XTERM_SCROLLBAR) + +#define x_stp_width 8 +#define x_stp_height 2 +const unsigned char x_stp_bits[] = { 0xaa, 0x55 }; + +int +scrollBar_t::show_xterm (int update) +{ + int xsb = 0; + int sbwidth = width - 1; + + if ((init & SB_STYLE_XTERM) == 0) + { + XGCValues gcvalue; + + init |= SB_STYLE_XTERM; + gcvalue.stipple = XCreateBitmapFromData (term->dpy, win, + (char *)x_stp_bits, x_stp_width, + x_stp_height); + if (!gcvalue.stipple) + rxvt_fatal ("can't create bitmap\n"); + + gcvalue.fill_style = FillOpaqueStippled; + gcvalue.foreground = term->pix_colors_focused[Color_scroll]; + gcvalue.background = term->pix_colors_focused[Color_bg]; + + xscrollbarGC = XCreateGC (term->dpy, win, + GCForeground | GCBackground + | GCFillStyle | GCStipple, &gcvalue); + gcvalue.foreground = term->pix_colors_focused[Color_border]; + ShadowGC = XCreateGC (term->dpy, win, GCForeground, &gcvalue); + } + + xsb = term->option (Opt_scrollBar_right) ? 1 : 0; + + if (update) + { + if (last_top < top) + XClearArea (term->dpy, win, + xsb, last_top, + sbwidth, (top - last_top), False); + + if (bot < last_bot) + XClearArea (term->dpy, win, + xsb, bot, + sbwidth, (last_bot - bot), False); + } + else + XClearWindow (term->dpy, win); + + /* scrollbar slider */ + XFillRectangle (term->dpy, win, xscrollbarGC, + xsb + 1, top, sbwidth - 2, bot - top); + + XDrawLine (term->dpy, win, ShadowGC, + xsb ? 0 : sbwidth, beg, + xsb ? 0 : sbwidth, end); + return 1; +} +#endif /* XTERM_SCROLLBAR */ +/*----------------------- end-of-file (C source) -----------------------*/ diff --git a/src/scrollbar.C b/src/scrollbar.C new file mode 100644 index 0000000..698c582 --- /dev/null +++ b/src/scrollbar.C @@ -0,0 +1,285 @@ +/*----------------------------------------------------------------------* + * File: scrollbar.C + *----------------------------------------------------------------------* + * + * Copyright (c) 1997,1998 mj olesen + * Copyright (c) 1998 Alfredo K. Kojima + * - N*XTstep like scrollbars + * Copyright (c) 1999-2001 Geoff Wing + * Copyright (c) 2004-2006 Marc Lehmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *----------------------------------------------------------------------*/ + +#include "../config.h" /* NECESSARY */ +#include "rxvt.h" /* NECESSARY */ + +/*----------------------------------------------------------------------*/ + +/* + * Map or unmap a scrollbar. Returns non-zero upon change of state + */ +void +scrollBar_t::map (int map) +{ + if (map) + { + state = SB_STATE_IDLE; + + if (!win) + resize (); + else + XMapWindow (term->dpy, win); + } + else + { + state = SB_STATE_OFF; + + if (win) + XUnmapWindow (term->dpy, win); + } +} + +void +scrollBar_t::resize () +{ + int delayed_init = 0; + int window_sb_x = 0; + + if (term->option (Opt_scrollBar_right)) + window_sb_x = term->szHint.width - total_width (); + + update_data (); + + if (!win) + { + /* create the scrollbar window */ + win = XCreateSimpleWindow (term->dpy, + term->parent, + window_sb_x, 0, + total_width (), + term->szHint.height, + 0, + term->pix_colors[Color_fg], + term->pix_colors[color ()]); + XDefineCursor (term->dpy, win, leftptr_cursor); + + XSelectInput (term->dpy, win, + ExposureMask | ButtonPressMask | ButtonReleaseMask + | Button1MotionMask | Button2MotionMask + | Button3MotionMask); + term->scrollbar_ev.start (term->display, win); + + delayed_init = 1; + } + else + XMoveResizeWindow (term->dpy, win, + window_sb_x, 0, + total_width (), term->szHint.height); + + show (1); + + if (delayed_init) + XMapWindow (term->dpy, win); +} + +/* + * Update current scrollbar view w.r.t. slider heights, etc. + */ +int +scrollBar_t::show (int refresh) +{ + int ret; + + if (!state) + return 0; + + if (refresh) + { + int sb_top = term->view_start - term->top_row; + int sb_bot = sb_top + (term->nrow - 1); + int sb_len = max (term->nrow - 1 - term->top_row, 1); + int n = min (min_height (), size ()); + + top = beg + (sb_top * (size () - n)) / sb_len; + bot = top + ecb_div_ru ((sb_bot - sb_top) * (size () - n), sb_len) + n; + /* no change */ + if (top == last_top + && bot == last_bot + && (state == last_state + || !(state == SB_STATE_UP || state == SB_STATE_DOWN))) + return 0; + } + + ret = (this->*update) (refresh); + + last_top = top; + last_bot = bot; + last_state = state; + + return ret; +} + +void +scrollBar_t::setup (rxvt_term *term) +{ + int i; + const char *scrollalign, *scrollstyle, *thickness; + + this->term = term; + scrollalign = term->rs[Rs_scrollBar_align]; + scrollstyle = term->rs[Rs_scrollstyle]; + thickness = term->rs[Rs_scrollBar_thickness]; + +# if defined(RXVT_SCROLLBAR) + style = SB_STYLE_RXVT; +# elif defined(XTERM_SCROLLBAR) + style = SB_STYLE_XTERM; +# elif defined(NEXT_SCROLLBAR) + style = SB_STYLE_NEXT; +# elif defined(PLAIN_SCROLLBAR) + style = SB_STYLE_PLAIN; +#else + style = SB_STYLE_RXVT; +# endif + +# if (defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR) || defined(PLAIN_SCROLLBAR)) + if (scrollstyle) + { +# ifdef NEXT_SCROLLBAR + if (strncasecmp (scrollstyle, "next", 4) == 0) + style = SB_STYLE_NEXT; +# endif +# ifdef XTERM_SCROLLBAR + if (strncasecmp (scrollstyle, "xterm", 5) == 0) + style = SB_STYLE_XTERM; +# endif +# ifdef PLAIN_SCROLLBAR + if (strncasecmp (scrollstyle, "plain", 5) == 0) + style = SB_STYLE_PLAIN; +# endif + + } +# endif + if (style == SB_STYLE_NEXT) + width = SB_WIDTH_NEXT; + else if (style == SB_STYLE_XTERM) + width = SB_WIDTH_XTERM; + else if (style == SB_STYLE_PLAIN) + width = SB_WIDTH_PLAIN; + else /* if (style == SB_STYLE_RXVT) */ + width = SB_WIDTH_RXVT; + + if (style != SB_STYLE_NEXT) /* dishonour request - for now */ + if (thickness && (i = atoi (thickness)) >= SB_WIDTH_MINIMUM) + width = min (i, SB_WIDTH_MAXIMUM); + +# ifdef RXVT_SCROLLBAR + if (! term->option (Opt_scrollBar_floating) && style == SB_STYLE_RXVT) + shadow = SHADOW_WIDTH; +# endif + + /* align = SB_ALIGN_CENTRE; */ + if (scrollalign) + { + if (strncasecmp (scrollalign, "top", 3) == 0) + align = SB_ALIGN_TOP; + else if (strncasecmp (scrollalign, "bottom", 6) == 0) + align = SB_ALIGN_BOTTOM; + } + last_state = SB_STATE_OFF; + /* cursor scrollBar: Black-on-White */ + leftptr_cursor = XCreateFontCursor (term->dpy, XC_left_ptr); +} + +void +scrollBar_t::destroy () +{ +#ifdef XTERM_SCROLLBAR + if (xscrollbarGC) XFreeGC (term->dpy, xscrollbarGC); + if (ShadowGC) XFreeGC (term->dpy, ShadowGC); +#endif +#ifdef PLAIN_SCROLLBAR + if (pscrollbarGC) XFreeGC (term->dpy, pscrollbarGC); +#endif +#ifdef NEXT_SCROLLBAR + if (blackGC) XFreeGC (term->dpy, blackGC); + if (whiteGC) XFreeGC (term->dpy, whiteGC); + if (grayGC) XFreeGC (term->dpy, grayGC); + if (darkGC) XFreeGC (term->dpy, darkGC); + if (stippleGC) XFreeGC (term->dpy, stippleGC); + if (dimple) XFreePixmap (term->dpy, dimple); + if (upArrow) XFreePixmap (term->dpy, upArrow); + if (downArrow) XFreePixmap (term->dpy, downArrow); + if (upArrowHi) XFreePixmap (term->dpy, upArrowHi); + if (downArrowHi) XFreePixmap (term->dpy, downArrowHi); +#endif +#ifdef RXVT_SCROLLBAR + if (topShadowGC) XFreeGC (term->dpy, topShadowGC); + if (botShadowGC) XFreeGC (term->dpy, botShadowGC); + if (scrollbarGC) XFreeGC (term->dpy, scrollbarGC); +#endif +} + +int +scrollBar_t::color () +{ +#ifdef RXVT_SCROLLBAR + if (style == SB_STYLE_RXVT && shadow) + return Color_trough; + else +#endif + return Color_border; +} + +void +scrollBar_t::update_data () +{ +#if defined(PLAIN_SCROLLBAR) + if (style == SB_STYLE_PLAIN) + { + beg = 0; + end = term->szHint.height; + update = &scrollBar_t::show_plain; + } +#endif +#if defined(XTERM_SCROLLBAR) + if (style == SB_STYLE_XTERM) + { + beg = 0; + end = term->szHint.height; + update = &scrollBar_t::show_xterm; + } +#endif +#if defined(NEXT_SCROLLBAR) + if (style == SB_STYLE_NEXT) + { + beg = 0; + end = term->szHint.height - (SB_BUTTON_TOTAL_HEIGHT + SB_PADDING); + update = &scrollBar_t::show_next; + } +#endif +#if defined(RXVT_SCROLLBAR) + if (style == SB_STYLE_RXVT) + { + beg = (width + 1) + shadow; + end = term->szHint.height - beg; + update = &scrollBar_t::show_rxvt; + } +#endif +} + +/*----------------------- end-of-file (C source) -----------------------*/ + -- cgit v1.2.3