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

Comparing rxvt-unicode/src/command.C (file contents):
Revision 1.582 by sf-exg, Thu Jul 14 05:33:26 2016 UTC vs.
Revision 1.602 by sf-exg, Sat May 6 08:01:35 2023 UTC

25 * - extensive modifications 25 * - extensive modifications
26 * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org> 26 * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org>
27 * Copyright (c) 2001 Marius Gedminas 27 * Copyright (c) 2001 Marius Gedminas
28 * - Ctrl/Mod4+Tab works like Meta+Tab (options) 28 * - Ctrl/Mod4+Tab works like Meta+Tab (options)
29 * Copyright (c) 2003 Rob McMullen <robm@flipturn.org> 29 * Copyright (c) 2003 Rob McMullen <robm@flipturn.org>
30 * Copyright (c) 2003-2014 Marc Lehmann <schmorp@schmorp.de> 30 * Copyright (c) 2003-2021 Marc Lehmann <schmorp@schmorp.de>
31 * Copyright (c) 2007,2015 Emanuele Giaquinta <e.giaquinta@glauco.it> 31 * Copyright (c) 2007,2015 Emanuele Giaquinta <e.giaquinta@glauco.it>
32 * 32 *
33 * This program is free software; you can redistribute it and/or modify 33 * This program is free software; you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License as published by 34 * it under the terms of the GNU General Public License as published by
35 * the Free Software Foundation; either version 3 of the License, or 35 * the Free Software Foundation; either version 3 of the License, or
168 int len; 168 int len;
169 169
170# if ENABLE_COMBINING 170# if ENABLE_COMBINING
171 if (IS_COMPOSE (ch)) 171 if (IS_COMPOSE (ch))
172 { 172 {
173 len = rxvt_composite.expand (ch, 0); 173 len = rxvt_composite.expand (ch);
174 alloc = chr = new wchar_t[len]; 174 alloc = chr = new wchar_t[len];
175 rxvt_composite.expand (ch, chr); 175 rxvt_composite.expand (ch, chr);
176 } 176 }
177 else 177 else
178# endif 178# endif
1016/* checks whether a refresh is requested and starts the refresh timer */ 1016/* checks whether a refresh is requested and starts the refresh timer */
1017void 1017void
1018rxvt_term::refresh_check () 1018rxvt_term::refresh_check ()
1019{ 1019{
1020 if (want_refresh && !flush_ev.is_active ()) 1020 if (want_refresh && !flush_ev.is_active ())
1021 flush_ev.start (1. / 60.); // refresh at max. 60 Hz normally 1021 flush_ev.start ();
1022 1022
1023 display->flush (); 1023 display->flush ();
1024} 1024}
1025 1025
1026void 1026void
1277#endif 1277#endif
1278 1278
1279void 1279void
1280rxvt_term::mouse_report (XButtonEvent &ev) 1280rxvt_term::mouse_report (XButtonEvent &ev)
1281{ 1281{
1282 int button_number, key_state = 0; 1282 int button_number, state = 0;
1283 int x, y; 1283 int x, y;
1284 int code = 32; 1284 bool release = ev.type == ButtonRelease;
1285 1285
1286 x = Pixel2Col (ev.x) + 1; 1286 x = 1 + clamp (Pixel2Col (ev.x), 0, ncol - 1);
1287 y = Pixel2Row (ev.y) + 1; 1287 y = 1 + clamp (Pixel2Row (ev.y), 0, nrow - 1);
1288 1288
1289 if (ev.type == MotionNotify) 1289 if (ev.type == MotionNotify)
1290 { 1290 {
1291 if (x == mouse_row && y == mouse_col) 1291 if (x == mouse_row && y == mouse_col)
1292 return; 1292 return;
1293 1293
1294 mouse_row = x; 1294 mouse_row = x;
1295 mouse_col = y; 1295 mouse_col = y;
1296 code += 32; 1296 state += 32;
1297 }
1298
1299 if (MEvent.button == AnyButton)
1300 button_number = 3;
1301 else
1302 { 1297 }
1298
1303 button_number = MEvent.button - Button1; 1299 button_number = MEvent.button - Button1;
1304 /* add 0x3D for wheel events, like xterm does */ 1300 if (button_number > 10)
1301 return;
1302 else if (button_number >= 7)
1303 button_number += 128 - 7;
1305 if (button_number >= 3) 1304 else if (button_number >= 3)
1306 button_number += 64 - 3; 1305 button_number += 64 - 3;
1307 }
1308 1306
1309 if (priv_modes & PrivMode_MouseX10) 1307 if (priv_modes & PrivMode_MouseX10)
1310 { 1308 {
1311 /* 1309 /*
1312 * do not report ButtonRelease 1310 * do not report ButtonRelease
1313 * no state info allowed 1311 * no state info allowed
1314 */ 1312 */
1315 key_state = 0; 1313 if (release)
1316 if (button_number == 3)
1317 return; 1314 return;
1318 } 1315 }
1319 else 1316 else
1320 { 1317 {
1321 /* XTerm mouse reporting needs these values: 1318 /* XTerm mouse reporting needs these values:
1323 * 8 = Meta 1320 * 8 = Meta
1324 * 16 = Control 1321 * 16 = Control
1325 * plus will add in our own Double-Click reporting 1322 * plus will add in our own Double-Click reporting
1326 * 32 = Double Click 1323 * 32 = Double Click
1327 */ 1324 */
1328 key_state = ((MEvent.state & ShiftMask) ? 4 : 0) 1325 state += ((MEvent.state & ShiftMask) ? 4 : 0)
1329 + ((MEvent.state & ModMetaMask) ? 8 : 0) 1326 + ((MEvent.state & ModMetaMask) ? 8 : 0)
1330 + ((MEvent.state & ControlMask) ? 16 : 0); 1327 + ((MEvent.state & ControlMask) ? 16 : 0);
1331#ifdef MOUSE_REPORT_DOUBLECLICK 1328#ifdef MOUSE_REPORT_DOUBLECLICK
1332 key_state += ((MEvent.clicks > 1) ? 32 : 0); 1329 state += ((MEvent.clicks > 1) ? 32 : 0);
1333#endif 1330#endif
1334 } 1331 }
1332
1333 int code = 32 + (release ? 3 : button_number) + state;
1335 1334
1336#if DEBUG_MOUSEREPORT 1335#if DEBUG_MOUSEREPORT
1337 fprintf (stderr, "Mouse ["); 1336 fprintf (stderr, "Mouse [");
1338 if (key_state & 16) 1337 if (state & 16)
1339 fputc ('C', stderr); 1338 fputc ('C', stderr);
1340 if (key_state & 4) 1339 if (state & 4)
1341 fputc ('S', stderr); 1340 fputc ('S', stderr);
1342 if (key_state & 8) 1341 if (state & 8)
1343 fputc ('A', stderr); 1342 fputc ('A', stderr);
1344 if (key_state & 32) 1343 if (state & 32)
1345 fputc ('2', stderr); 1344 fputc ('2', stderr);
1346 fprintf (stderr, "]: <%d>, %d/%d\n", 1345 fprintf (stderr, "]: <%d>, %d/%d\n",
1347 button_number, 1346 button_number,
1348 x, 1347 x,
1349 y); 1348 y);
1350#endif 1349#endif
1351 1350
1352#if ENABLE_FRILLS 1351#if ENABLE_FRILLS
1353 if (priv_modes & PrivMode_ExtMouseRight) 1352 if (priv_modes & PrivMode_ExtMouseSGR)
1353 tt_printf ("\033[<%d;%d;%d%c",
1354 button_number + state,
1355 x,
1356 y,
1357 release ? 'm' : 'M');
1358 else if (priv_modes & PrivMode_ExtMouseUrxvt)
1354 tt_printf ("\033[%d;%d;%dM", 1359 tt_printf ("\033[%d;%d;%dM",
1355 code + button_number + key_state, 1360 code,
1356 x, 1361 x,
1357 y); 1362 y);
1358 else if (priv_modes & PrivMode_ExtModeMouse) 1363 else if (priv_modes & PrivMode_ExtMouseUTF8)
1364 if (code < 128)
1359 tt_printf ("\033[M%c%lc%lc", 1365 tt_printf ("\033[M%c%lc%lc",
1360 code + button_number + key_state, 1366 code,
1361 wint_t (32 + x), 1367 wint_t (32 + x),
1362 wint_t (32 + y)); 1368 wint_t (32 + y));
1369 else
1370 tt_printf ("\033[M%c%c%lc%lc",
1371 0xc0 + (code >> 6),
1372 0x80 + (code & 0x3f),
1373 wint_t (32 + x),
1374 wint_t (32 + y));
1363 else 1375 else
1364#endif 1376#endif
1365 tt_printf ("\033[M%c%c%c", 1377 tt_printf ("\033[M%c%c%c",
1366 code + button_number + key_state, 1378 code,
1367 32 + x, 1379 32 + x,
1368 32 + y); 1380 32 + y);
1369} 1381}
1370 1382
1371/*{{{ process an X event */ 1383/*{{{ process an X event */
2139 2151
2140 if (reportmode) 2152 if (reportmode)
2141 { 2153 {
2142 /* mouse report from vt window */ 2154 /* mouse report from vt window */
2143 /* don't report release of wheel "buttons" */ 2155 /* don't report release of wheel "buttons" */
2144 if (ev.button >= 4) 2156 if (ev.button >= 4 && ev.button <= 7)
2145 return; 2157 return;
2146#ifdef MOUSE_REPORT_DOUBLECLICK 2158#ifdef MOUSE_REPORT_DOUBLECLICK
2147 /* only report the release of 'slow' single clicks */ 2159 /* only report the release of 'slow' single clicks */
2148 if (MEvent.button != AnyButton 2160 if (MEvent.button != AnyButton
2149 && (ev.button != MEvent.button 2161 && (ev.button != MEvent.button
2150 || (ev.time - MEvent.time 2162 || (ev.time - MEvent.time
2151 > multiClickTime / 2))) 2163 > multiClickTime / 2)))
2152 { 2164 {
2153 MEvent.clicks = 0; 2165 MEvent.clicks = 0;
2154 MEvent.button = AnyButton; 2166 MEvent.button = ev.button;
2155 mouse_report (ev); 2167 mouse_report (ev);
2156 } 2168 }
2157#else /* MOUSE_REPORT_DOUBLECLICK */ 2169#else /* MOUSE_REPORT_DOUBLECLICK */
2158 MEvent.button = AnyButton; 2170 MEvent.button = ev.button;
2159 mouse_report (ev); 2171 mouse_report (ev);
2160#endif /* MOUSE_REPORT_DOUBLECLICK */ 2172#endif /* MOUSE_REPORT_DOUBLECLICK */
2161 return; 2173 return;
2162 } 2174 }
2163 2175
2350 } 2362 }
2351} 2363}
2352 2364
2353// read the next character 2365// read the next character
2354wchar_t ecb_hot 2366wchar_t ecb_hot
2355rxvt_term::next_char () NOTHROW 2367rxvt_term::next_char () noexcept
2356{ 2368{
2357 while (cmdbuf_ptr < cmdbuf_endp) 2369 while (cmdbuf_ptr < cmdbuf_endp)
2358 { 2370 {
2359 // assume 7-bit to be ascii ALWAYS 2371 // assume 7-bit to be ascii ALWAYS (always true in POSIX)
2360 if (ecb_likely ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)) 2372 if (ecb_likely ((unsigned char)*cmdbuf_ptr <= 0x7f))
2361 return *cmdbuf_ptr++; 2373 return *cmdbuf_ptr++;
2362 2374
2363 wchar_t wc; 2375 wchar_t wc;
2364 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 2376 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2365 2377
2386 return NOCHAR; 2398 return NOCHAR;
2387} 2399}
2388 2400
2389// read the next octet 2401// read the next octet
2390uint32_t ecb_hot 2402uint32_t ecb_hot
2391rxvt_term::next_octet () NOTHROW 2403rxvt_term::next_octet () noexcept
2392{ 2404{
2393 return cmdbuf_ptr < cmdbuf_endp 2405 return cmdbuf_ptr < cmdbuf_endp
2394 ? (unsigned char)*cmdbuf_ptr++ 2406 ? (unsigned char)*cmdbuf_ptr++
2395 : NOCHAR; 2407 : NOCHAR;
2396} 2408}
2397 2409
2398static class out_of_input out_of_input; 2410static class out_of_input out_of_input;
2399 2411
2400wchar_t ecb_hot 2412wchar_t ecb_hot
2401rxvt_term::cmd_getc () THROW ((class out_of_input)) 2413rxvt_term::cmd_getc ()
2402{ 2414{
2403 wchar_t c = next_char (); 2415 wchar_t c = next_char ();
2404 2416
2405 if (c == NOCHAR) 2417 if (c == NOCHAR)
2406 throw out_of_input; 2418 throw out_of_input;
2407 2419
2408 return c; 2420 return c;
2409} 2421}
2410 2422
2411uint32_t ecb_hot 2423uint32_t ecb_hot
2412rxvt_term::cmd_get8 () THROW ((class out_of_input)) 2424rxvt_term::cmd_get8 ()
2413{ 2425{
2414 uint32_t c = next_octet (); 2426 uint32_t c = next_octet ();
2415 2427
2416 if (c == NOCHAR) 2428 if (c == NOCHAR)
2417 throw out_of_input; 2429 throw out_of_input;
2690 wchar_t nlcr[] = { C0_LF, C0_CR }; 2702 wchar_t nlcr[] = { C0_LF, C0_CR };
2691 scr_add_lines (nlcr, ecb_array_length (nlcr), 1); 2703 scr_add_lines (nlcr, ecb_array_length (nlcr), 1);
2692 } 2704 }
2693 break; 2705 break;
2694 2706
2707#if 0 // disabled because embedded newlines can make exploits easier
2695 /* kidnapped escape sequence: Should be 8.3.48 */ 2708 /* kidnapped escape sequence: Should be 8.3.48 */
2696 case C1_ESA: /* ESC G */ 2709 case C1_ESA: /* ESC G */
2697 // used by original rxvt for rob nations own graphics mode 2710 // used by original rxvt for rob nations own graphics mode
2698 if (cmd_getc () == 'Q') 2711 if (cmd_getc () == 'Q' && option (Opt_insecure))
2699 tt_printf ("\033G0\012"); /* query graphics - no graphics */ 2712 tt_printf ("\033G0\012"); /* query graphics - no graphics */
2700 break; 2713 break;
2714#endif
2701 2715
2702 /* 8.3.63: CHARACTER TABULATION SET */ 2716 /* 8.3.63: CHARACTER TABULATION SET */
2703 case C1_HTS: /* ESC H */ 2717 case C1_HTS: /* ESC H */
2704 scr_set_tab (1); 2718 scr_set_tab (1);
2705 break; 2719 break;
2863 break; 2877 break;
2864 2878
2865 case '?': 2879 case '?':
2866 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 2880 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
2867 process_terminal_mode (ch, priv, nargs, arg); 2881 process_terminal_mode (ch, priv, nargs, arg);
2882 if (prev_ch == '$' && ch == 'p')
2883 process_terminal_mode (ch, priv, nargs, arg);
2868 break; 2884 break;
2869 2885
2870 case '!': 2886 case '!':
2871 if (ch == CSI_70) 2887 if (ch == CSI_70)
2872 { 2888 {
2873 /* DECSTR: soft terminal reset, used by our terminfo since 9.06 */ 2889 /* DECSTR: soft terminal reset, used by our terminfo since 9.06 */
2874 scr_soft_reset (); 2890 scr_soft_reset ();
2875 2891
2876 static const int pm_h[] = { 7, 25 }; 2892 static const int pm_h[] = { 7, 25 };
2877 static const int pm_l[] = { 1, 3, 4, 5, 6, 9, 66, 1000, 1001, 1005, 1015, 1049 }; 2893 static const int pm_l[] = { 1, 3, 4, 5, 6, 9, 66, 1000, 1001, 1005, 1006, 1015, 1049 };
2878 2894
2879 process_terminal_mode ('h', 0, ecb_array_length (pm_h), pm_h); 2895 process_terminal_mode ('h', 0, ecb_array_length (pm_h), pm_h);
2880 process_terminal_mode ('l', 0, ecb_array_length (pm_l), pm_l); 2896 process_terminal_mode ('l', 0, ecb_array_length (pm_l), pm_l);
2881 } 2897 }
2882 break; 2898 break;
2912 case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */ 2928 case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */
2913 scr_gotorc (arg[0], 0, RELATIVE); 2929 scr_gotorc (arg[0], 0, RELATIVE);
2914 break; 2930 break;
2915 2931
2916 case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */ 2932 case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */
2917 case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */ 2933 case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */
2918#ifdef ISO6429 2934#ifdef ISO6429
2919 arg[0] = -arg[0]; 2935 arg[0] = -arg[0];
2920#else /* emulate common DEC VTs */ 2936#else /* emulate common DEC VTs */
2921 arg[0] = arg[0] ? -arg[0] : -1; 2937 arg[0] = arg[0] ? -arg[0] : -1;
2922#endif 2938#endif
3013 case 7: /* unofficial extension */ 3029 case 7: /* unofficial extension */
3014 if (option (Opt_insecure)) 3030 if (option (Opt_insecure))
3015 tt_printf ("%-.250s\012", rs[Rs_display_name]); 3031 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3016 break; 3032 break;
3017 case 8: /* unofficial extension */ 3033 case 8: /* unofficial extension */
3034 {
3035 string_term st;
3036 st.v[0] = CHAR_ST;
3037 st.v[1] = '\0';
3018 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 3038 process_xterm_seq (XTerm_title, (char *)RESNAME "-" VERSION, st); // char * cast verified
3019 break; 3039 break;
3040 }
3020 } 3041 }
3021 break; 3042 break;
3022 3043
3023 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */ 3044 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */
3024 switch (arg[0]) 3045 switch (arg[0])
3209/* 3230/*
3210 * get input up until STRING TERMINATOR (or BEL) 3231 * get input up until STRING TERMINATOR (or BEL)
3211 * ends_how is terminator used. returned input must be free()'d 3232 * ends_how is terminator used. returned input must be free()'d
3212 */ 3233 */
3213char * 3234char *
3214rxvt_term::get_to_st (unicode_t &ends_how) 3235rxvt_term::get_to_st (string_term &st)
3215{ 3236{
3216 unicode_t ch; 3237 unicode_t ch;
3217 bool seen_esc = false; 3238 bool seen_esc = false;
3218 unsigned int n = 0; 3239 unsigned int n = 0;
3219 wchar_t string[CBUFSIZ]; 3240 wchar_t string[CBUFSIZ];
3248 string[n++] = ch; 3269 string[n++] = ch;
3249 } 3270 }
3250 3271
3251 string[n++] = '\0'; 3272 string[n++] = '\0';
3252 3273
3253 ends_how = (ch == 0x5c ? C0_ESC : ch); 3274 n = 0;
3275 if (ch == 0x5c)
3276 st.v[n++] = C0_ESC;
3277 st.v[n++] = ch;
3278 st.v[n] = '\0';
3254 3279
3255 return rxvt_wcstombs (string); 3280 return rxvt_wcstombs (string);
3256} 3281}
3257 3282
3258/*----------------------------------------------------------------------*/ 3283/*----------------------------------------------------------------------*/
3264{ 3289{
3265 /* 3290 /*
3266 * Not handled yet 3291 * Not handled yet
3267 */ 3292 */
3268 3293
3269 unicode_t eh; 3294 string_term st;
3270 char *s = get_to_st (eh); 3295 char *s = get_to_st (st);
3271 if (s) 3296 if (s)
3272 free (s); 3297 free (s);
3273 3298
3274 return; 3299 return;
3275} 3300}
3287 for (arg = 0; isdigit (ch); ch = cmd_getc ()) 3312 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3288 arg = arg * 10 + (ch - '0'); 3313 arg = arg * 10 + (ch - '0');
3289 3314
3290 if (ch == ';') 3315 if (ch == ';')
3291 { 3316 {
3292 unicode_t eh; 3317 string_term st;
3293 char *s = get_to_st (eh); 3318 char *s = get_to_st (st);
3294 3319
3295 if (s) 3320 if (s)
3296 { 3321 {
3297 process_xterm_seq (arg, s, eh); 3322 process_xterm_seq (arg, s, st);
3298 free (s); 3323 free (s);
3299 } 3324 }
3300 } 3325 }
3301} 3326}
3302 3327
3326 b &= 0xff; 3351 b &= 0xff;
3327 a &= 0xff; 3352 a &= 0xff;
3328 3353
3329 uint32_t color = (a << 24) | (r << 16) | (g << 8) | b; 3354 uint32_t color = (a << 24) | (r << 16) | (g << 8) | b;
3330 3355
3331 unsigned int idx_r = r * (Red_levels - 1) / 0xff;
3332 unsigned int idx_g = g * (Green_levels - 1) / 0xff;
3333 unsigned int idx_b = b * (Blue_levels - 1) / 0xff;
3334 unsigned int idx = colorcube_index (idx_r, idx_g, idx_b);
3335
3336 /* we allow one of the 6 directly neighbouring colours */ 3356 /* we allow one of the 6 closest neighbouring colours */
3337 /* to replace the current color, if they not used recently */ 3357 /* to replace the current color, if they not used recently */
3358 #if 0
3338 static const signed char dxyz[][3] = { 3359 static const unsigned char dxyz[][3] = {
3339 0, 0, 0, 3360 0, 0, 0,
3340 0, 0, +1, 3361 0, 0, 4,
3341 0, 0, -1, 3362 0, 4, 4,
3363 4, 4, 0,
3364 4, 0, 4,
3342 0, +1, 0, 3365 0, 4, 0,
3343 0, -1, 0,
3344 +1, 0, 0, 3366 4, 0, 0,
3345 -1, 0, 0,
3346 }; 3367 };
3368 #else
3369 // silly compressed verlapping triplets version of above
3370 static const unsigned char dxyz[] = {
3371 0, 0, 0, 4, 4, 0, 4, 0, 0,
3372 };
3373 #endif
3347 3374
3375 static const unsigned char color_level[8][32] = {
3376 // neighbour index
3377 {0, 0, 1, 0, 0, 1, 1, 2, 2, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3},
3378 {0, 1, 0, 1, 1, 2, 1, 1, 2, 2, 3, 3, 2, 2, 2, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4},
3379 {0, 0, 1, 2, 1, 1, 2, 3, 3, 2, 2, 3, 3, 4, 4, 3, 3, 3, 4, 4, 5, 5, 5, 4, 4, 4, 5, 5, 5, 5, 5, 5},
3380 {0, 0, 2, 1, 2, 3, 2, 2, 3, 4, 4, 3, 3, 4, 4, 5, 5, 4, 4, 5, 5, 5, 6, 6, 5, 5, 5, 6, 6, 6, 6, 6},
3381 // Red_levels/Green_levels/Blue_levels index
3382 {0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
3383 {0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
3384 {0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5},
3385 {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6},
3386 };
3387
3388 unsigned int idx;
3389
3348 for (int n = 0; n < ecb_array_length (dxyz); ++n) 3390 for (int n = 0; n < ecb_array_length (dxyz) - 2; ++n)
3349 { 3391 {
3350 int r = idx_r + dxyz[n][0]; 3392 unsigned int idx_r = color_level[ Red_levels - dxyz[n + 0]][r / 8];
3351 int g = idx_g + dxyz[n][1]; 3393 unsigned int idx_g = color_level[Green_levels - dxyz[n + 1]][g / 8];
3352 int b = idx_b + dxyz[n][2]; 3394 unsigned int idx_b = color_level[ Blue_levels - dxyz[n + 2]][b / 8];
3353
3354 if (!IN_RANGE_EXC (r, 0, Red_levels )) continue;
3355 if (!IN_RANGE_EXC (g, 0, Green_levels)) continue;
3356 if (!IN_RANGE_EXC (b, 0, Blue_levels )) continue;
3357
3358 unsigned int index = colorcube_index (r, g, b); 3395 unsigned int index = colorcube_index (idx_r, idx_g, idx_b);
3396
3397 if (n == 0)
3398 idx = index;
3359 3399
3360 if (rgb24_color[index] == color) 3400 if (rgb24_color[index] == color)
3361 { 3401 {
3362 rgb24_seqno[index] = ++rgb24_sequence; 3402 rgb24_seqno[index] = ++rgb24_sequence;
3363 return index + minTermCOLOR24; 3403 return index + minTermCOLOR24;
3369 idx = index; 3409 idx = index;
3370 goto update; 3410 goto update;
3371 } 3411 }
3372 3412
3373 // like (rgb24_seqno[idx] > rgb24_seqno[index]) 3413 // like (rgb24_seqno[idx] > rgb24_seqno[index])
3374 // but also handles wrap around values good enough 3414 // but also handles wrap around values well enough
3375 if ((uint16_t)(rgb24_seqno[idx] - rgb24_seqno[index]) < 0x7fff) 3415 if ((uint16_t)(rgb24_seqno[idx] - rgb24_seqno[index]) < 0x8000)
3376 idx = index; 3416 idx = index;
3377 } 3417 }
3378 3418
3379update: 3419update:
3380 rgb24_color[idx] = color; 3420 rgb24_color[idx] = color;
3387 3427
3388 return idx; 3428 return idx;
3389} 3429}
3390 3430
3391void 3431void
3392rxvt_term::process_color_seq (int report, int color, const char *str, char resp) 3432rxvt_term::process_color_seq (int report, int color, const char *str, string_term &st)
3393{ 3433{
3394 if (str[0] == '?' && !str[1]) 3434 if (str[0] == '?' && !str[1])
3395 { 3435 {
3396 rgba c; 3436 rgba c;
3397 pix_colors_focused[color].get (c); 3437 pix_colors_focused[color].get (c);
3438 char rgba_str[32];
3398 3439
3399#if XFT 3440#if XFT
3400 if (c.a != rgba::MAX_CC) 3441 if (c.a != rgba::MAX_CC)
3401 tt_printf ("\033]%d;rgba:%04x/%04x/%04x/%04x%c", report, c.r, c.g, c.b, c.a, resp); 3442 snprintf (rgba_str, sizeof (rgba_str), "rgba:%04x/%04x/%04x/%04x", c.r, c.g, c.b, c.a);
3402 else 3443 else
3403#endif 3444#endif
3404 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, c.r, c.g, c.b, resp); 3445 snprintf (rgba_str, sizeof (rgba_str), "rgb:%04x/%04x/%04x", c.r, c.g, c.b);
3446
3447 if (IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
3448 tt_printf ("\033]%d;%d;%s%s", report, color - minCOLOR, rgba_str, st.v);
3449 else
3450 tt_printf ("\033]%d;%s%s", report, rgba_str, st.v);
3405 } 3451 }
3406 else 3452 else
3407 set_window_color (color, str); 3453 set_window_color (color, str);
3408} 3454}
3409 3455
3410/* 3456/*
3411 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3457 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3412 */ 3458 */
3413void 3459void
3414rxvt_term::process_xterm_seq (int op, char *str, char resp) 3460rxvt_term::process_xterm_seq (int op, char *str, string_term &st)
3415{ 3461{
3416 int color; 3462 int color;
3417 char *buf, *name; 3463 char *buf, *name;
3418 bool query = str[0] == '?' && !str[1]; 3464 bool query = str[0] == '?' && !str[1];
3419 int saveop = op; 3465 int saveop = op;
3454 &nitems, &bytes_after, &value) == Success 3500 &nitems, &bytes_after, &value) == Success
3455 && actual_type != None 3501 && actual_type != None
3456 && actual_format == 8) 3502 && actual_format == 8)
3457 str = (const char *)(value); 3503 str = (const char *)(value);
3458 3504
3459 tt_printf ("\033]%d;%s%c", op, option (Opt_insecure) ? str : "", resp); 3505 tt_printf ("\033]%d;%s%s", op, option (Opt_insecure) ? str : "", st.v);
3460 3506
3461 XFree (value); 3507 XFree (value);
3462 } 3508 }
3463 else 3509 else
3464 { 3510 {
3488 break; 3534 break;
3489 3535
3490 if ((buf = strchr (name, ';')) != NULL) 3536 if ((buf = strchr (name, ';')) != NULL)
3491 *buf++ = '\0'; 3537 *buf++ = '\0';
3492 3538
3493 process_color_seq (op, color, name, resp); 3539 process_color_seq (op, color, name, st);
3494 } 3540 }
3495 break; 3541 break;
3496 case Rxvt_restoreFG: 3542 case Rxvt_restoreFG:
3497 case XTerm_Color00: 3543 case XTerm_Color00:
3498 process_color_seq (op, Color_fg, str, resp); 3544 process_color_seq (op, Color_fg, str, st);
3499 break; 3545 break;
3500 case Rxvt_restoreBG: 3546 case Rxvt_restoreBG:
3501 case XTerm_Color01: 3547 case XTerm_Color01:
3502 process_color_seq (op, Color_bg, str, resp); 3548 process_color_seq (op, Color_bg, str, st);
3503 break; 3549 break;
3504#ifndef NO_CURSORCOLOR 3550#ifndef NO_CURSORCOLOR
3505 case XTerm_Color_cursor: 3551 case XTerm_Color_cursor:
3506 process_color_seq (op, Color_cursor, str, resp); 3552 process_color_seq (op, Color_cursor, str, st);
3507 break; 3553 break;
3508#endif 3554#endif
3509 case XTerm_Color_pointer_fg: 3555 case XTerm_Color_pointer_fg:
3510 process_color_seq (op, Color_pointer_fg, str, resp); 3556 process_color_seq (op, Color_pointer_fg, str, st);
3511 break; 3557 break;
3512 case XTerm_Color_pointer_bg: 3558 case XTerm_Color_pointer_bg:
3513 process_color_seq (op, Color_pointer_bg, str, resp); 3559 process_color_seq (op, Color_pointer_bg, str, st);
3514 break; 3560 break;
3515#ifdef OPTION_HC 3561#ifdef OPTION_HC
3516 case XTerm_Color_HC: 3562 case XTerm_Color_HC:
3517 process_color_seq (op, Color_HC, str, resp); 3563 process_color_seq (op, Color_HC, str, st);
3518 break; 3564 break;
3519 case XTerm_Color_HTC: 3565 case XTerm_Color_HTC:
3520 process_color_seq (op, Color_HTC, str, resp); 3566 process_color_seq (op, Color_HTC, str, st);
3521 break; 3567 break;
3522#endif 3568#endif
3523#ifndef NO_BOLD_UNDERLINE_REVERSE 3569#ifndef NO_BOLD_UNDERLINE_REVERSE
3524 case URxvt_Color_BD: 3570 case URxvt_Color_BD:
3525 process_color_seq (op, Color_BD, str, resp); 3571 process_color_seq (op, Color_BD, str, st);
3526 break; 3572 break;
3527 case URxvt_Color_UL: 3573 case URxvt_Color_UL:
3528 process_color_seq (op, Color_UL, str, resp); 3574 process_color_seq (op, Color_UL, str, st);
3529 break; 3575 break;
3530 case URxvt_Color_IT: 3576 case URxvt_Color_IT:
3531 process_color_seq (op, Color_IT, str, resp); 3577 process_color_seq (op, Color_IT, str, st);
3532 break; 3578 break;
3533#endif 3579#endif
3534 case URxvt_Color_border: 3580 case URxvt_Color_border:
3535 process_color_seq (op, Color_border, str, resp); 3581 process_color_seq (op, Color_border, str, st);
3536 break; 3582 break;
3537 3583
3538 case XTerm_logfile: 3584 case XTerm_logfile:
3539 // TODO, when secure mode? 3585 // TODO, when secure mode?
3540 break; 3586 break;
3558 case URxvt_boldFont: 3604 case URxvt_boldFont:
3559 case URxvt_italicFont: 3605 case URxvt_italicFont:
3560 case URxvt_boldItalicFont: 3606 case URxvt_boldItalicFont:
3561#endif 3607#endif
3562 if (query) 3608 if (query)
3563 tt_printf ("\33]%d;%-.250s%c", saveop, 3609 tt_printf ("\33]%d;%-.250s%s", saveop,
3564 option (Opt_insecure) && fontset[op - URxvt_font]->fontdesc 3610 option (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3565 ? fontset[op - URxvt_font]->fontdesc : "", 3611 ? fontset[op - URxvt_font]->fontdesc : "",
3566 resp); 3612 st.v);
3567 else 3613 else
3568 { 3614 {
3569 const char *&res = rs[Rs_font + (op - URxvt_font)]; 3615 const char *&res = rs[Rs_font + (op - URxvt_font)];
3570 3616
3571 res = strdup (str); 3617 res = strdup (str);
3574 } 3620 }
3575 break; 3621 break;
3576 3622
3577 case URxvt_version: 3623 case URxvt_version:
3578 if (query) 3624 if (query)
3579 tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%c", 3625 tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%s",
3580 op, 3626 op,
3581 rs[Rs_name], VERSION[0], VERSION[2], 3627 rs[Rs_name], VERSION[0], VERSION[2],
3582 resp); 3628 st.v);
3583 break; 3629 break;
3584 3630
3585#if !ENABLE_MINIMAL 3631#if !ENABLE_MINIMAL
3632 case URxvt_cellinfo:
3633 if (query)
3634 tt_printf ("\33]%d;%d;%d;%d%s", saveop,
3635 fwidth, fheight, fbase,
3636 st.v);
3637 break;
3638
3586 case URxvt_locale: 3639 case URxvt_locale:
3587 if (query) 3640 if (query)
3588 tt_printf ("\33]%d;%-.250s%c", op, option (Opt_insecure) ? locale : "", resp); 3641 tt_printf ("\33]%d;%-.250s%s", op, option (Opt_insecure) ? locale : "", st.v);
3589 else 3642 else
3590 { 3643 {
3591 set_locale (str); 3644 set_locale (str);
3592 pty->set_utf8_mode (enc_utf8); 3645 pty->set_utf8_mode (enc_utf8);
3593 init_xlocale (); 3646 init_xlocale ();
3608 break; 3661 break;
3609#endif 3662#endif
3610 3663
3611#if ENABLE_PERL 3664#if ENABLE_PERL
3612 case URxvt_perl: 3665 case URxvt_perl:
3613 HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_STR_LEN, &resp, 1, DT_END)); 3666 HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_STR, st.v, DT_END));
3614 break; 3667 break;
3615#endif 3668#endif
3616 } 3669 }
3617} 3670}
3618/*----------------------------------------------------------------------*/ 3671/*----------------------------------------------------------------------*/
3698 { 1000, PrivMode_MouseX11 }, 3751 { 1000, PrivMode_MouseX11 },
3699 { 1002, PrivMode_MouseBtnEvent }, 3752 { 1002, PrivMode_MouseBtnEvent },
3700 { 1003, PrivMode_MouseAnyEvent }, 3753 { 1003, PrivMode_MouseAnyEvent },
3701#if ENABLE_FRILLS 3754#if ENABLE_FRILLS
3702 { 1004, PrivMode_FocusEvent }, 3755 { 1004, PrivMode_FocusEvent },
3703 { 1005, PrivMode_ExtModeMouse }, 3756 { 1005, PrivMode_ExtMouseUTF8 },
3757 { 1006, PrivMode_ExtMouseSGR },
3704#endif 3758#endif
3705 { 1010, PrivMode_TtyOutputInh }, // rxvt extension 3759 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
3706 { 1011, PrivMode_Keypress }, // rxvt extension 3760 { 1011, PrivMode_Keypress }, // rxvt extension
3707#if ENABLE_FRILLS 3761#if ENABLE_FRILLS
3708 { 1015, PrivMode_ExtMouseRight }, // urxvt extension of 1005 3762 { 1015, PrivMode_ExtMouseUrxvt }, // urxvt extension of 1005
3709#endif 3763#endif
3710 // 1035 enable modifiers for alt, numlock NYI 3764 // 1035 enable modifiers for alt, numlock NYI
3711 // 1036 send ESC for meta keys NYI 3765 // 1036 send ESC for meta keys NYI
3712 // 1037 send DEL for keypad delete NYI 3766 // 1037 send DEL for keypad delete NYI
3713 { 1047, PrivMode_Screen }, 3767 { 1047, PrivMode_Screen },
3714 // 1048 save and restore cursor, implemented in code 3768 // 1048 save and restore cursor, implemented in code
3715 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */ 3769 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */
3716 // 1051, 1052, 1060, 1061 keyboard emulation NYI 3770 // 1051, 1052, 1060, 1061 keyboard emulation NYI
3771#if ENABLE_FRILLS
3717 { 2004, PrivMode_BracketPaste }, 3772 { 2004, PrivMode_BracketPaste },
3773#endif
3718 }; 3774 };
3719 3775
3720 if (nargs == 0) 3776 if (nargs == 0)
3721 return; 3777 return;
3778
3779 // DECRQM
3780 if (mode == 'p')
3781 {
3782 int status = 0;
3783 if (nargs != 1)
3784 return;
3785
3786 for (j = 0; j < ecb_array_length (argtopriv); j++)
3787 if (argtopriv[j].argval == arg[0])
3788 {
3789 status = (priv_modes & argtopriv[j].bit) ? 1 : 2;
3790 break;
3791 }
3792
3793 tt_printf ("\33[?%d;%d$y", arg[0], status);
3794 return;
3795 }
3722 3796
3723 /* make lo/hi boolean */ 3797 /* make lo/hi boolean */
3724 if (mode == 'l') 3798 if (mode == 'l')
3725 mode = 0; /* reset */ 3799 mode = 0; /* reset */
3726 else if (mode == 'h') 3800 else if (mode == 'h')
3977 case 38: // set fg color, ISO 8613-6 4051 case 38: // set fg color, ISO 8613-6
3978 case 48: // set bg color, ISO 8613-6 4052 case 48: // set bg color, ISO 8613-6
3979 { 4053 {
3980 unsigned int fgbg = arg[i] == 38 ? Color_fg : Color_bg; 4054 unsigned int fgbg = arg[i] == 38 ? Color_fg : Color_bg;
3981 unsigned int idx; 4055 unsigned int idx;
3982 4056
3983 if (nargs > i + 2 && arg[i + 1] == 5) 4057 if (nargs > i + 2 && arg[i + 1] == 5)
3984 { 4058 {
3985 idx = minCOLOR + arg[i + 2]; 4059 idx = minCOLOR + arg[i + 2];
3986 i += 2; 4060 i += 2;
3987 4061

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines