|
53 | 53 | #include "encoding.h" |
54 | 54 | #include <libvchan.h> |
55 | 55 | #include <poll.h> |
| 56 | +#include "unistr.h" |
56 | 57 |
|
57 | 58 |
|
58 | 59 | #include <linux/input.h> |
@@ -651,6 +652,27 @@ void send_wmname(Ghandles * g, XID window) |
651 | 652 | if (!get_net_wmname(g, window, msg.data, sizeof(msg.data))) |
652 | 653 | if (!getwmname_tochar(g, window, msg.data, sizeof(msg.data))) |
653 | 654 | return; |
| 655 | + if (strlen(msg.data) == sizeof(msg.data) - 1) { |
| 656 | + // Window title might had been longer than output buffer. |
| 657 | + // Trim at correct utf8 boundary and set end to . . . |
| 658 | + msg.data[sizeof(msg.data) - 7] = 0; |
| 659 | + for (int i=0; i < 4; i++) { |
| 660 | + uint8_t * last_byte = (uint8_t *)msg.data + strlen(msg.data) - 1; |
| 661 | + // check for valid 1, 2, 3 or 4 byte uft8 char at the end of string |
| 662 | + if ( |
| 663 | + !u8_check(last_byte, 1) || |
| 664 | + !u8_check(last_byte - 1, 2) || |
| 665 | + !u8_check(last_byte - 2, 3) || |
| 666 | + !u8_check(last_byte - 3, 4) |
| 667 | + ) { |
| 668 | + break; |
| 669 | + } else { |
| 670 | + // trim one invalid byte at end of string |
| 671 | + msg.data[strlen(msg.data) - 1] = 0; |
| 672 | + } |
| 673 | + } |
| 674 | + strncat(msg.data, " . . .", sizeof(msg.data) - 1); |
| 675 | + } |
654 | 676 | hdr.window = window; |
655 | 677 | hdr.type = MSG_WMNAME; |
656 | 678 | write_message(g->vchan, hdr, msg); |
|
0 commit comments