ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/main.C
(Generate patch)

Comparing rxvt-unicode/src/main.C (file contents):
Revision 1.395 by root, Sat Dec 13 11:58:23 2014 UTC vs.
Revision 1.403 by root, Thu Jun 17 00:49:20 2021 UTC

12 * - extensive modifications 12 * - extensive modifications
13 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 13 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
14 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> 14 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
15 * - extensive modifications 15 * - extensive modifications
16 * Copyright (c) 2003-2014 Marc Lehmann <schmorp@schmorp.de> 16 * Copyright (c) 2003-2014 Marc Lehmann <schmorp@schmorp.de>
17 * Copyright (c) 2015 Emanuele Giaquinta <e.giaquinta@glauco.it>
17 * 18 *
18 * This program is free software; you can redistribute it and/or modify 19 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by 20 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 3 of the License, or 21 * the Free Software Foundation; either version 3 of the License, or
21 * (at your option) any later version. 22 * (at your option) any later version.
58rxvt_t rxvt_current_term; 59rxvt_t rxvt_current_term;
59 60
60static char curlocale[128], savelocale[128]; 61static char curlocale[128], savelocale[128];
61 62
62bool 63bool
63rxvt_set_locale (const char *locale) NOTHROW 64rxvt_set_locale (const char *locale) noexcept
64{ 65{
65 int size = strlen (locale) + 1; 66 int size = strlen (locale) + 1;
66 67
67 if (size > sizeof (curlocale)) 68 if (size > sizeof (curlocale))
68 rxvt_fatal ("locale string too long, aborting.\n"); 69 rxvt_fatal ("locale string too long, aborting.\n");
74 setlocale (LC_CTYPE, curlocale); 75 setlocale (LC_CTYPE, curlocale);
75 return true; 76 return true;
76} 77}
77 78
78void 79void
79rxvt_push_locale (const char *locale) NOTHROW 80rxvt_push_locale (const char *locale) noexcept
80{ 81{
81 strcpy (savelocale, curlocale); 82 strcpy (savelocale, curlocale);
82 rxvt_set_locale (locale); 83 rxvt_set_locale (locale);
83} 84}
84 85
85void 86void
86rxvt_pop_locale () NOTHROW 87rxvt_pop_locale () noexcept
87{ 88{
88 rxvt_set_locale (savelocale); 89 rxvt_set_locale (savelocale);
89} 90}
90 91
91#if ENABLE_COMBINING 92#if ENABLE_COMBINING
123 v.push_back (compose_char (c1, c2)); 124 v.push_back (compose_char (c1, c2));
124 125
125 return v.size () - 1 + COMPOSE_LO; 126 return v.size () - 1 + COMPOSE_LO;
126} 127}
127 128
129template<typename T>
128int rxvt_composite_vec::expand (unicode_t c, wchar_t *r) 130int rxvt_composite_vec::expand (unicode_t c, T *r)
129{ 131{
130 compose_char *cc = (*this)[c]; 132 compose_char *cc = (*this)[c];
131 133
132 if (!cc) 134 if (!cc)
133 { 135 {
144 len++; 146 len++;
145 if (r) *r++ = cc->c2; 147 if (r) *r++ = cc->c2;
146 } 148 }
147 149
148 return len; 150 return len;
149
150} 151}
152
153template int rxvt_composite_vec::expand<text_t> (unicode_t c, text_t *);
154template int rxvt_composite_vec::expand<wchar_t> (unicode_t c, wchar_t *);
151#endif 155#endif
152 156
153rxvt_term::rxvt_term () 157rxvt_term::rxvt_term ()
154{ 158{
155#if HAVE_BG_PIXMAP
156 update_background_ev.set<rxvt_term, &rxvt_term::update_background_cb> (this);
157#endif
158#ifdef CURSOR_BLINK 159#ifdef CURSOR_BLINK
159 cursor_blink_ev.set <rxvt_term, &rxvt_term::cursor_blink_cb> (this); cursor_blink_ev.set (0., CURSOR_BLINK_INTERVAL); 160 cursor_blink_ev.set <rxvt_term, &rxvt_term::cursor_blink_cb> (this); cursor_blink_ev.set (0., CURSOR_BLINK_INTERVAL);
160#endif 161#endif
161#ifdef TEXT_BLINK 162#ifdef TEXT_BLINK
162 text_blink_ev.set <rxvt_term, &rxvt_term::text_blink_cb> (this); text_blink_ev.set (0., TEXT_BLINK_INTERVAL); 163 text_blink_ev.set <rxvt_term, &rxvt_term::text_blink_cb> (this); text_blink_ev.set (0., TEXT_BLINK_INTERVAL);
168 sel_scroll_ev.set <rxvt_term, &rxvt_term::sel_scroll_cb> (this); 169 sel_scroll_ev.set <rxvt_term, &rxvt_term::sel_scroll_cb> (this);
169#endif 170#endif
170#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 171#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
171 slip_wheel_ev.set <rxvt_term, &rxvt_term::slip_wheel_cb> (this); 172 slip_wheel_ev.set <rxvt_term, &rxvt_term::slip_wheel_cb> (this);
172#endif 173#endif
173#if BG_IMAGE_FROM_ROOT || ENABLE_PERL 174#if ENABLE_PERL
174 rootwin_ev.set <rxvt_term, &rxvt_term::rootwin_cb> (this), 175 rootwin_ev.set <rxvt_term, &rxvt_term::rootwin_cb> (this),
175#endif 176#endif
176 scrollbar_ev.set <rxvt_term, &rxvt_term::x_cb> (this), 177 scrollbar_ev.set <rxvt_term, &rxvt_term::x_cb> (this),
177#if USE_XIM 178#if USE_XIM
178 im_ev.set <rxvt_term, &rxvt_term::im_cb> (this), 179 im_ev.set <rxvt_term, &rxvt_term::im_cb> (this),
221 for (int i = RS_styleCount; --i; ) 222 for (int i = RS_styleCount; --i; )
222 if (fontset[i] != fontset[0]) 223 if (fontset[i] != fontset[0])
223 delete fontset[i]; 224 delete fontset[i];
224#endif 225#endif
225 delete fontset[0]; 226 delete fontset[0];
226
227#ifdef HAVE_BG_PIXMAP
228 bg_destroy ();
229#endif
230 227
231#if HAVE_IMG 228#if HAVE_IMG
232 delete bg_img; 229 delete bg_img;
233#endif 230#endif
234 231
281 delete selection_req; 278 delete selection_req;
282 279
283 if (env && memcmp (env, envv->begin (), envv->size () * sizeof (char *))) 280 if (env && memcmp (env, envv->begin (), envv->size () * sizeof (char *)))
284 rxvt_warn ("env has been modified, probably as a result of a lib calling setenv.\n"); 281 rxvt_warn ("env has been modified, probably as a result of a lib calling setenv.\n");
285 282
286 delete env; 283 delete [] env;
287 284
288 delete envv; 285 delete envv;
289 delete argv; 286 delete argv;
290 287
291#ifdef KEYSYM_RESOURCE 288#ifdef KEYSYM_RESOURCE
326 { 323 {
327#if USE_XIM 324#if USE_XIM
328 im_ev.stop (display); 325 im_ev.stop (display);
329#endif 326#endif
330 scrollbar_ev.stop (display); 327 scrollbar_ev.stop (display);
331#if BG_IMAGE_FROM_ROOT || ENABLE_PERL 328#if ENABLE_PERL
332 rootwin_ev.stop (display); 329 rootwin_ev.stop (display);
333#endif 330#endif
334 termwin_ev.stop (display); 331 termwin_ev.stop (display);
335 vt_ev.stop (display); 332 vt_ev.stop (display);
336 } 333 }
363 360
364 delete this; 361 delete this;
365} 362}
366 363
367void 364void
368rxvt_term::set_option (uint8_t opt, bool set) NOTHROW 365rxvt_term::set_option (uint8_t opt, bool set) noexcept
369{ 366{
370 if (!opt) 367 if (!opt)
371 return; 368 return;
372 369
373 uint8_t mask = 1 << (opt & 7); 370 uint8_t mask = 1 << (opt & 7);
942 939
943void 940void
944rxvt_term::set_window_color (int idx, const char *color) 941rxvt_term::set_window_color (int idx, const char *color)
945{ 942{
946#ifdef XTERM_COLOR_CHANGE 943#ifdef XTERM_COLOR_CHANGE
947 rxvt_color xcol;
948
949 if (color == NULL || *color == '\0') 944 if (color == NULL || *color == '\0')
950 return; 945 return;
951 946
952 color = strdup (color); 947 color = strdup (color);
953 allocated.push_back ((void *)color); 948 allocated.push_back ((void *)color);
959 int i = atoi (color); 954 int i = atoi (color);
960 955
961 if (i >= 8 && i <= 15) 956 if (i >= 8 && i <= 15)
962 { 957 {
963 /* bright colors */ 958 /* bright colors */
964 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i - 8]; 959 alias_color (idx, minBrightCOLOR + i - 8);
965 goto done; 960 goto done;
966 } 961 }
967 962
968 if (i >= 0 && i <= 7) 963 if (i >= 0 && i <= 7)
969 { 964 {
970 /* normal colors */ 965 /* normal colors */
971 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 966 alias_color (idx, minCOLOR + i);
972 goto done; 967 goto done;
973 } 968 }
974 } 969 }
975 970
976 set_color (xcol, color); 971 pix_colors_focused[idx].free (this);
977 972 set_color (pix_colors_focused[idx], color);
978 /*
979 * FIXME: should free colors here, but no idea how to do it so instead,
980 * so just keep gobbling up the colormap
981 */
982
983 pix_colors_focused[idx] = xcol;
984 973
985done: 974done:
986 /*TODO: handle Color_BD, scrollbar background, etc. */ 975 /*TODO: handle Color_BD, scrollbar background, etc. */
987 976
988 update_fade_color (idx); 977 update_fade_color (idx);
989 recolour_cursor (); 978 recolor_cursor ();
990 scr_recolour (); 979 scr_recolor ();
991#endif /* XTERM_COLOR_CHANGE */ 980#endif /* XTERM_COLOR_CHANGE */
992} 981}
993 982
994void 983void
995rxvt_term::recolour_cursor () 984rxvt_term::recolor_cursor ()
996{ 985{
997 XColor fg, bg; 986 XColor fg, bg;
998 987
999 (ISSET_PIXCOLOR (Color_pointer_fg) 988 (ISSET_PIXCOLOR (Color_pointer_fg)
1000 ? pix_colors_focused[Color_pointer_fg] 989 ? pix_colors_focused[Color_pointer_fg]
1029 1018
1030 for (i = Color_Black; i <= Color_White; i++) 1019 for (i = Color_Black; i <= Color_White; i++)
1031 if (pix_colors[Color_bg] == pix_colors[i]) 1020 if (pix_colors[Color_bg] == pix_colors[i])
1032 { 1021 {
1033 sprintf (bstr, "%d", i - Color_Black); 1022 sprintf (bstr, "%d", i - Color_Black);
1034#if BG_IMAGE_FROM_FILE 1023#if HAVE_IMG
1035 xpmb = "default;"; 1024 xpmb = "default;";
1036#endif 1025#endif
1037 break; 1026 break;
1038 } 1027 }
1039 1028
1055} 1044}
1056 1045
1057void 1046void
1058rxvt_term::alias_color (int dst, int src) 1047rxvt_term::alias_color (int dst, int src)
1059{ 1048{
1049 pix_colors[dst].free (this);
1060 pix_colors[dst].set (this, rs[Rs_color + dst] = rs[Rs_color + src]); 1050 pix_colors[dst].set (this, rs[Rs_color + dst] = rs[Rs_color + src]);
1061} 1051}
1052
1053#ifdef SMART_RESIZE
1054static unsigned int
1055get_parent_bw (Display *dpy, Window w)
1056{
1057 int idummy;
1058 unsigned int udummy;
1059 Window wdummy, parent;
1060 Window *children;
1061 unsigned int nchildren, border_width;
1062
1063 XQueryTree (dpy, w, &wdummy, &parent, &children, &nchildren);
1064 XFree (children);
1065 XGetGeometry (dpy, parent, &wdummy, &idummy, &idummy,
1066 &udummy, &udummy, &border_width, &udummy);
1067
1068 return border_width;
1069}
1070#endif
1062 1071
1063/* -------------------------------------------------------------------- * 1072/* -------------------------------------------------------------------- *
1064 * - WINDOW RESIZING - * 1073 * - WINDOW RESIZING - *
1065 * -------------------------------------------------------------------- */ 1074 * -------------------------------------------------------------------- */
1066void 1075void
1102 * if display->root isn't the parent window, a WM will probably have offset 1111 * if display->root isn't the parent window, a WM will probably have offset
1103 * our position for handles and decorations. Counter it 1112 * our position for handles and decorations. Counter it
1104 */ 1113 */
1105 if (x1 != x || y1 != y) 1114 if (x1 != x || y1 != y)
1106 { 1115 {
1107 x -= x1; 1116 unsigned int border_width = get_parent_bw (dpy, parent);
1108 y -= y1; 1117
1118 x -= x1 + border_width;
1119 y -= y1 + border_width;
1109 } 1120 }
1110 1121
1111 x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2; 1122 x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2;
1112 y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2; 1123 y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2;
1113 dx = old_width - szHint.width; 1124 dx = old_width - szHint.width;
1143 XMoveResizeWindow (dpy, vt, 1154 XMoveResizeWindow (dpy, vt,
1144 window_vt_x, window_vt_y, 1155 window_vt_x, window_vt_y,
1145 vt_width, vt_height); 1156 vt_width, vt_height);
1146 1157
1147 HOOK_INVOKE ((this, HOOK_SIZE_CHANGE, DT_INT, newwidth, DT_INT, newheight, DT_END)); 1158 HOOK_INVOKE ((this, HOOK_SIZE_CHANGE, DT_INT, newwidth, DT_INT, newheight, DT_END));
1148
1149#ifdef HAVE_BG_PIXMAP
1150 if (bg_window_size_sensitive ())
1151 update_background ();
1152#endif
1153 } 1159 }
1154 1160
1155 if (fix_screen || old_height == 0) 1161 if (fix_screen || old_height == 0)
1156 scr_reset (); 1162 scr_reset ();
1157 1163
1690{ 1696{
1691 Window cr; 1697 Window cr;
1692 XTranslateCoordinates (dpy, parent, display->root, 0, 0, &x, &y, &cr); 1698 XTranslateCoordinates (dpy, parent, display->root, 0, 0, &x, &y, &cr);
1693} 1699}
1694 1700
1695#ifdef HAVE_BG_PIXMAP
1696
1697void
1698rxvt_term::update_background ()
1699{
1700 if (update_background_ev.is_active ())
1701 return;
1702
1703 ev_tstamp to_wait = 0.5 - (ev::now () - bg_valid_since);
1704
1705 if (to_wait <= 0.)
1706 bg_render ();
1707 else
1708 update_background_ev.start (to_wait);
1709}
1710
1711void
1712rxvt_term::update_background_cb (ev::timer &w, int revents)
1713{
1714 make_current ();
1715
1716 update_background_ev.stop ();
1717 bg_render ();
1718 refresh_check ();
1719}
1720
1721#endif /* HAVE_BG_PIXMAP */
1722
1723/*----------------------- end-of-file (C source) -----------------------*/ 1701/*----------------------- end-of-file (C source) -----------------------*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines