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.394 by root, Sat Dec 13 10:07:30 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),
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
227#ifdef HAVE_BG_PIXMAP
228 bg_destroy ();
229#endif
230
231#if HAVE_IMG 228#if HAVE_IMG
232 delete bg_img; 229 delete bg_img;
233#endif 230#endif
234 231
235 if (display) 232 if (display)
254 for (int i = 0; i < TOTAL_COLORS; i++) 251 for (int i = 0; i < TOTAL_COLORS; i++)
255 if (ISSET_PIXCOLOR (i)) 252 if (ISSET_PIXCOLOR (i))
256 { 253 {
257 pix_colors_focused [i].free (this); 254 pix_colors_focused [i].free (this);
258#if OFF_FOCUS_FADING 255#if OFF_FOCUS_FADING
256 if (rs[Rs_fade])
259 pix_colors_unfocused [i].free (this); 257 pix_colors_unfocused [i].free (this);
260#endif 258#endif
261 } 259 }
262 260
263 clear (); 261 clear ();
264 262
280 delete selection_req; 278 delete selection_req;
281 279
282 if (env && memcmp (env, envv->begin (), envv->size () * sizeof (char *))) 280 if (env && memcmp (env, envv->begin (), envv->size () * sizeof (char *)))
283 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");
284 282
285 delete env; 283 delete [] env;
286 284
287 delete envv; 285 delete envv;
288 delete argv; 286 delete argv;
289 287
290#ifdef KEYSYM_RESOURCE 288#ifdef KEYSYM_RESOURCE
325 { 323 {
326#if USE_XIM 324#if USE_XIM
327 im_ev.stop (display); 325 im_ev.stop (display);
328#endif 326#endif
329 scrollbar_ev.stop (display); 327 scrollbar_ev.stop (display);
330#if BG_IMAGE_FROM_ROOT || ENABLE_PERL 328#if ENABLE_PERL
331 rootwin_ev.stop (display); 329 rootwin_ev.stop (display);
332#endif 330#endif
333 termwin_ev.stop (display); 331 termwin_ev.stop (display);
334 vt_ev.stop (display); 332 vt_ev.stop (display);
335 } 333 }
362 360
363 delete this; 361 delete this;
364} 362}
365 363
366void 364void
367rxvt_term::set_option (uint8_t opt, bool set) NOTHROW 365rxvt_term::set_option (uint8_t opt, bool set) noexcept
368{ 366{
369 if (!opt) 367 if (!opt)
370 return; 368 return;
371 369
372 uint8_t mask = 1 << (opt & 7); 370 uint8_t mask = 1 << (opt & 7);
941 939
942void 940void
943rxvt_term::set_window_color (int idx, const char *color) 941rxvt_term::set_window_color (int idx, const char *color)
944{ 942{
945#ifdef XTERM_COLOR_CHANGE 943#ifdef XTERM_COLOR_CHANGE
946 rxvt_color xcol;
947
948 if (color == NULL || *color == '\0') 944 if (color == NULL || *color == '\0')
949 return; 945 return;
950 946
951 color = strdup (color); 947 color = strdup (color);
952 allocated.push_back ((void *)color); 948 allocated.push_back ((void *)color);
958 int i = atoi (color); 954 int i = atoi (color);
959 955
960 if (i >= 8 && i <= 15) 956 if (i >= 8 && i <= 15)
961 { 957 {
962 /* bright colors */ 958 /* bright colors */
963 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i - 8]; 959 alias_color (idx, minBrightCOLOR + i - 8);
964 goto done; 960 goto done;
965 } 961 }
966 962
967 if (i >= 0 && i <= 7) 963 if (i >= 0 && i <= 7)
968 { 964 {
969 /* normal colors */ 965 /* normal colors */
970 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 966 alias_color (idx, minCOLOR + i);
971 goto done; 967 goto done;
972 } 968 }
973 } 969 }
974 970
975 set_color (xcol, color); 971 pix_colors_focused[idx].free (this);
976 972 set_color (pix_colors_focused[idx], color);
977 /*
978 * FIXME: should free colors here, but no idea how to do it so instead,
979 * so just keep gobbling up the colormap
980 */
981
982 pix_colors_focused[idx] = xcol;
983 973
984done: 974done:
985 /*TODO: handle Color_BD, scrollbar background, etc. */ 975 /*TODO: handle Color_BD, scrollbar background, etc. */
986 976
987 update_fade_color (idx); 977 update_fade_color (idx);
988 recolour_cursor (); 978 recolor_cursor ();
989 scr_recolour (); 979 scr_recolor ();
990#endif /* XTERM_COLOR_CHANGE */ 980#endif /* XTERM_COLOR_CHANGE */
991} 981}
992 982
993void 983void
994rxvt_term::recolour_cursor () 984rxvt_term::recolor_cursor ()
995{ 985{
996 XColor fg, bg; 986 XColor fg, bg;
997 987
998 (ISSET_PIXCOLOR (Color_pointer_fg) 988 (ISSET_PIXCOLOR (Color_pointer_fg)
999 ? pix_colors_focused[Color_pointer_fg] 989 ? pix_colors_focused[Color_pointer_fg]
1028 1018
1029 for (i = Color_Black; i <= Color_White; i++) 1019 for (i = Color_Black; i <= Color_White; i++)
1030 if (pix_colors[Color_bg] == pix_colors[i]) 1020 if (pix_colors[Color_bg] == pix_colors[i])
1031 { 1021 {
1032 sprintf (bstr, "%d", i - Color_Black); 1022 sprintf (bstr, "%d", i - Color_Black);
1033#if BG_IMAGE_FROM_FILE 1023#if HAVE_IMG
1034 xpmb = "default;"; 1024 xpmb = "default;";
1035#endif 1025#endif
1036 break; 1026 break;
1037 } 1027 }
1038 1028
1054} 1044}
1055 1045
1056void 1046void
1057rxvt_term::alias_color (int dst, int src) 1047rxvt_term::alias_color (int dst, int src)
1058{ 1048{
1049 pix_colors[dst].free (this);
1059 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]);
1060} 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
1061 1071
1062/* -------------------------------------------------------------------- * 1072/* -------------------------------------------------------------------- *
1063 * - WINDOW RESIZING - * 1073 * - WINDOW RESIZING - *
1064 * -------------------------------------------------------------------- */ 1074 * -------------------------------------------------------------------- */
1065void 1075void
1101 * 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
1102 * our position for handles and decorations. Counter it 1112 * our position for handles and decorations. Counter it
1103 */ 1113 */
1104 if (x1 != x || y1 != y) 1114 if (x1 != x || y1 != y)
1105 { 1115 {
1106 x -= x1; 1116 unsigned int border_width = get_parent_bw (dpy, parent);
1107 y -= y1; 1117
1118 x -= x1 + border_width;
1119 y -= y1 + border_width;
1108 } 1120 }
1109 1121
1110 x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2; 1122 x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2;
1111 y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2; 1123 y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2;
1112 dx = old_width - szHint.width; 1124 dx = old_width - szHint.width;
1142 XMoveResizeWindow (dpy, vt, 1154 XMoveResizeWindow (dpy, vt,
1143 window_vt_x, window_vt_y, 1155 window_vt_x, window_vt_y,
1144 vt_width, vt_height); 1156 vt_width, vt_height);
1145 1157
1146 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));
1147
1148#ifdef HAVE_BG_PIXMAP
1149 if (bg_window_size_sensitive ())
1150 update_background ();
1151#endif
1152 } 1159 }
1153 1160
1154 if (fix_screen || old_height == 0) 1161 if (fix_screen || old_height == 0)
1155 scr_reset (); 1162 scr_reset ();
1156 1163
1689{ 1696{
1690 Window cr; 1697 Window cr;
1691 XTranslateCoordinates (dpy, parent, display->root, 0, 0, &x, &y, &cr); 1698 XTranslateCoordinates (dpy, parent, display->root, 0, 0, &x, &y, &cr);
1692} 1699}
1693 1700
1694#ifdef HAVE_BG_PIXMAP
1695
1696void
1697rxvt_term::update_background ()
1698{
1699 if (update_background_ev.is_active ())
1700 return;
1701
1702 ev_tstamp to_wait = 0.5 - (ev::now () - bg_valid_since);
1703
1704 if (to_wait <= 0.)
1705 bg_render ();
1706 else
1707 update_background_ev.start (to_wait);
1708}
1709
1710void
1711rxvt_term::update_background_cb (ev::timer &w, int revents)
1712{
1713 make_current ();
1714
1715 update_background_ev.stop ();
1716 bg_render ();
1717 refresh_check ();
1718}
1719
1720#endif /* HAVE_BG_PIXMAP */
1721
1722/*----------------------- end-of-file (C source) -----------------------*/ 1701/*----------------------- end-of-file (C source) -----------------------*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines