… | |
… | |
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. |
… | |
… | |
58 | rxvt_t rxvt_current_term; |
59 | rxvt_t rxvt_current_term; |
59 | |
60 | |
60 | static char curlocale[128], savelocale[128]; |
61 | static char curlocale[128], savelocale[128]; |
61 | |
62 | |
62 | bool |
63 | bool |
63 | rxvt_set_locale (const char *locale) NOTHROW |
64 | rxvt_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 | |
78 | void |
79 | void |
79 | rxvt_push_locale (const char *locale) NOTHROW |
80 | rxvt_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 | |
85 | void |
86 | void |
86 | rxvt_pop_locale () NOTHROW |
87 | rxvt_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 | |
|
|
129 | template<typename T> |
128 | int rxvt_composite_vec::expand (unicode_t c, wchar_t *r) |
130 | int 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 | |
|
|
153 | template int rxvt_composite_vec::expand<text_t> (unicode_t c, text_t *); |
|
|
154 | template int rxvt_composite_vec::expand<wchar_t> (unicode_t c, wchar_t *); |
151 | #endif |
155 | #endif |
152 | |
156 | |
153 | rxvt_term::rxvt_term () |
157 | rxvt_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 | |
367 | void |
364 | void |
368 | rxvt_term::set_option (uint8_t opt, bool set) NOTHROW |
365 | rxvt_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 | |
943 | void |
940 | void |
944 | rxvt_term::set_window_color (int idx, const char *color) |
941 | rxvt_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 | |
985 | done: |
974 | done: |
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 | |
994 | void |
983 | void |
995 | rxvt_term::recolour_cursor () |
984 | rxvt_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 | |
… | |
… | |
1058 | rxvt_term::alias_color (int dst, int src) |
1047 | rxvt_term::alias_color (int dst, int src) |
1059 | { |
1048 | { |
1060 | pix_colors[dst].free (this); |
1049 | pix_colors[dst].free (this); |
1061 | 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]); |
1062 | } |
1051 | } |
|
|
1052 | |
|
|
1053 | #ifdef SMART_RESIZE |
|
|
1054 | static unsigned int |
|
|
1055 | get_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 |
1063 | |
1071 | |
1064 | /* -------------------------------------------------------------------- * |
1072 | /* -------------------------------------------------------------------- * |
1065 | * - WINDOW RESIZING - * |
1073 | * - WINDOW RESIZING - * |
1066 | * -------------------------------------------------------------------- */ |
1074 | * -------------------------------------------------------------------- */ |
1067 | void |
1075 | void |
… | |
… | |
1103 | * 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 |
1104 | * our position for handles and decorations. Counter it |
1112 | * our position for handles and decorations. Counter it |
1105 | */ |
1113 | */ |
1106 | if (x1 != x || y1 != y) |
1114 | if (x1 != x || y1 != y) |
1107 | { |
1115 | { |
1108 | x -= x1; |
1116 | unsigned int border_width = get_parent_bw (dpy, parent); |
1109 | y -= y1; |
1117 | |
|
|
1118 | x -= x1 + border_width; |
|
|
1119 | y -= y1 + border_width; |
1110 | } |
1120 | } |
1111 | |
1121 | |
1112 | x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2; |
1122 | x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2; |
1113 | y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2; |
1123 | y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2; |
1114 | dx = old_width - szHint.width; |
1124 | dx = old_width - szHint.width; |
… | |
… | |
1144 | XMoveResizeWindow (dpy, vt, |
1154 | XMoveResizeWindow (dpy, vt, |
1145 | window_vt_x, window_vt_y, |
1155 | window_vt_x, window_vt_y, |
1146 | vt_width, vt_height); |
1156 | vt_width, vt_height); |
1147 | |
1157 | |
1148 | 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)); |
1149 | |
|
|
1150 | #ifdef HAVE_BG_PIXMAP |
|
|
1151 | if (bg_window_size_sensitive ()) |
|
|
1152 | update_background (); |
|
|
1153 | #endif |
|
|
1154 | } |
1159 | } |
1155 | |
1160 | |
1156 | if (fix_screen || old_height == 0) |
1161 | if (fix_screen || old_height == 0) |
1157 | scr_reset (); |
1162 | scr_reset (); |
1158 | |
1163 | |
… | |
… | |
1691 | { |
1696 | { |
1692 | Window cr; |
1697 | Window cr; |
1693 | XTranslateCoordinates (dpy, parent, display->root, 0, 0, &x, &y, &cr); |
1698 | XTranslateCoordinates (dpy, parent, display->root, 0, 0, &x, &y, &cr); |
1694 | } |
1699 | } |
1695 | |
1700 | |
1696 | #ifdef HAVE_BG_PIXMAP |
|
|
1697 | |
|
|
1698 | void |
|
|
1699 | rxvt_term::update_background () |
|
|
1700 | { |
|
|
1701 | if (update_background_ev.is_active ()) |
|
|
1702 | return; |
|
|
1703 | |
|
|
1704 | ev_tstamp to_wait = 0.5 - (ev::now () - bg_valid_since); |
|
|
1705 | |
|
|
1706 | if (to_wait <= 0.) |
|
|
1707 | bg_render (); |
|
|
1708 | else |
|
|
1709 | update_background_ev.start (to_wait); |
|
|
1710 | } |
|
|
1711 | |
|
|
1712 | void |
|
|
1713 | rxvt_term::update_background_cb (ev::timer &w, int revents) |
|
|
1714 | { |
|
|
1715 | make_current (); |
|
|
1716 | |
|
|
1717 | update_background_ev.stop (); |
|
|
1718 | bg_render (); |
|
|
1719 | refresh_check (); |
|
|
1720 | } |
|
|
1721 | |
|
|
1722 | #endif /* HAVE_BG_PIXMAP */ |
|
|
1723 | |
|
|
1724 | /*----------------------- end-of-file (C source) -----------------------*/ |
1701 | /*----------------------- end-of-file (C source) -----------------------*/ |