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.404 by root, Thu Jun 17 14:31:39 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);
636 XSetIOErrorHandler (rxvt_xioerror_handler); 634 XSetIOErrorHandler (rxvt_xioerror_handler);
637 635
638 XrmInitialize (); 636 XrmInitialize ();
639 637
640#if HAVE_PIXBUF 638#if HAVE_PIXBUF
639 #if !GLIB_CHECK_VERSION(2,36,0)
641 g_type_init (); 640 g_type_init ();
641 #endif
642#endif 642#endif
643} 643}
644 644
645/*----------------------------------------------------------------------*/ 645/*----------------------------------------------------------------------*/
646/* 646/*
941 941
942void 942void
943rxvt_term::set_window_color (int idx, const char *color) 943rxvt_term::set_window_color (int idx, const char *color)
944{ 944{
945#ifdef XTERM_COLOR_CHANGE 945#ifdef XTERM_COLOR_CHANGE
946 rxvt_color xcol;
947
948 if (color == NULL || *color == '\0') 946 if (color == NULL || *color == '\0')
949 return; 947 return;
950 948
951 color = strdup (color); 949 color = strdup (color);
952 allocated.push_back ((void *)color); 950 allocated.push_back ((void *)color);
958 int i = atoi (color); 956 int i = atoi (color);
959 957
960 if (i >= 8 && i <= 15) 958 if (i >= 8 && i <= 15)
961 { 959 {
962 /* bright colors */ 960 /* bright colors */
963 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i - 8]; 961 alias_color (idx, minBrightCOLOR + i - 8);
964 goto done; 962 goto done;
965 } 963 }
966 964
967 if (i >= 0 && i <= 7) 965 if (i >= 0 && i <= 7)
968 { 966 {
969 /* normal colors */ 967 /* normal colors */
970 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 968 alias_color (idx, minCOLOR + i);
971 goto done; 969 goto done;
972 } 970 }
973 } 971 }
974 972
975 set_color (xcol, color); 973 pix_colors_focused[idx].free (this);
976 974 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 975
984done: 976done:
985 /*TODO: handle Color_BD, scrollbar background, etc. */ 977 /*TODO: handle Color_BD, scrollbar background, etc. */
986 978
987 update_fade_color (idx); 979 update_fade_color (idx);
988 recolour_cursor (); 980 recolor_cursor ();
989 scr_recolour (); 981 scr_recolor ();
990#endif /* XTERM_COLOR_CHANGE */ 982#endif /* XTERM_COLOR_CHANGE */
991} 983}
992 984
993void 985void
994rxvt_term::recolour_cursor () 986rxvt_term::recolor_cursor ()
995{ 987{
996 XColor fg, bg; 988 XColor fg, bg;
997 989
998 (ISSET_PIXCOLOR (Color_pointer_fg) 990 (ISSET_PIXCOLOR (Color_pointer_fg)
999 ? pix_colors_focused[Color_pointer_fg] 991 ? pix_colors_focused[Color_pointer_fg]
1028 1020
1029 for (i = Color_Black; i <= Color_White; i++) 1021 for (i = Color_Black; i <= Color_White; i++)
1030 if (pix_colors[Color_bg] == pix_colors[i]) 1022 if (pix_colors[Color_bg] == pix_colors[i])
1031 { 1023 {
1032 sprintf (bstr, "%d", i - Color_Black); 1024 sprintf (bstr, "%d", i - Color_Black);
1033#if BG_IMAGE_FROM_FILE 1025#if HAVE_IMG
1034 xpmb = "default;"; 1026 xpmb = "default;";
1035#endif 1027#endif
1036 break; 1028 break;
1037 } 1029 }
1038 1030
1054} 1046}
1055 1047
1056void 1048void
1057rxvt_term::alias_color (int dst, int src) 1049rxvt_term::alias_color (int dst, int src)
1058{ 1050{
1051 pix_colors[dst].free (this);
1059 pix_colors[dst].set (this, rs[Rs_color + dst] = rs[Rs_color + src]); 1052 pix_colors[dst].set (this, rs[Rs_color + dst] = rs[Rs_color + src]);
1060} 1053}
1054
1055#ifdef SMART_RESIZE
1056static unsigned int
1057get_parent_bw (Display *dpy, Window w)
1058{
1059 int idummy;
1060 unsigned int udummy;
1061 Window wdummy, parent;
1062 Window *children;
1063 unsigned int nchildren, border_width;
1064
1065 XQueryTree (dpy, w, &wdummy, &parent, &children, &nchildren);
1066 XFree (children);
1067 XGetGeometry (dpy, parent, &wdummy, &idummy, &idummy,
1068 &udummy, &udummy, &border_width, &udummy);
1069
1070 return border_width;
1071}
1072#endif
1061 1073
1062/* -------------------------------------------------------------------- * 1074/* -------------------------------------------------------------------- *
1063 * - WINDOW RESIZING - * 1075 * - WINDOW RESIZING - *
1064 * -------------------------------------------------------------------- */ 1076 * -------------------------------------------------------------------- */
1065void 1077void
1101 * if display->root isn't the parent window, a WM will probably have offset 1113 * if display->root isn't the parent window, a WM will probably have offset
1102 * our position for handles and decorations. Counter it 1114 * our position for handles and decorations. Counter it
1103 */ 1115 */
1104 if (x1 != x || y1 != y) 1116 if (x1 != x || y1 != y)
1105 { 1117 {
1106 x -= x1; 1118 unsigned int border_width = get_parent_bw (dpy, parent);
1107 y -= y1; 1119
1120 x -= x1 + border_width;
1121 y -= y1 + border_width;
1108 } 1122 }
1109 1123
1110 x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2; 1124 x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2;
1111 y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2; 1125 y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2;
1112 dx = old_width - szHint.width; 1126 dx = old_width - szHint.width;
1142 XMoveResizeWindow (dpy, vt, 1156 XMoveResizeWindow (dpy, vt,
1143 window_vt_x, window_vt_y, 1157 window_vt_x, window_vt_y,
1144 vt_width, vt_height); 1158 vt_width, vt_height);
1145 1159
1146 HOOK_INVOKE ((this, HOOK_SIZE_CHANGE, DT_INT, newwidth, DT_INT, newheight, DT_END)); 1160 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 } 1161 }
1153 1162
1154 if (fix_screen || old_height == 0) 1163 if (fix_screen || old_height == 0)
1155 scr_reset (); 1164 scr_reset ();
1156 1165
1689{ 1698{
1690 Window cr; 1699 Window cr;
1691 XTranslateCoordinates (dpy, parent, display->root, 0, 0, &x, &y, &cr); 1700 XTranslateCoordinates (dpy, parent, display->root, 0, 0, &x, &y, &cr);
1692} 1701}
1693 1702
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) -----------------------*/ 1703/*----------------------- end-of-file (C source) -----------------------*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines