… | |
… | |
11 | * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA> |
11 | * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA> |
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-2007 Marc Lehmann <pcg@goof.com> |
16 | * Copyright (c) 2003-2008 Marc Lehmann <pcg@goof.com> |
17 | * |
17 | * |
18 | * This program is free software; you can redistribute it and/or modify |
18 | * 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 |
19 | * it under the terms of the GNU General Public License as published by |
20 | * the Free Software Foundation; either version 2 of the License, or |
20 | * the Free Software Foundation; either version 2 of the License, or |
21 | * (at your option) any later version. |
21 | * (at your option) any later version. |
… | |
… | |
172 | 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); |
173 | #endif |
173 | #endif |
174 | #if ENABLE_TRANSPARENCY || ENABLE_PERL |
174 | #if ENABLE_TRANSPARENCY || ENABLE_PERL |
175 | rootwin_ev.set <rxvt_term, &rxvt_term::rootwin_cb> (this), |
175 | rootwin_ev.set <rxvt_term, &rxvt_term::rootwin_cb> (this), |
176 | #endif |
176 | #endif |
177 | #ifdef HAVE_SCROLLBARS |
|
|
178 | scrollbar_ev.set <rxvt_term, &rxvt_term::x_cb> (this), |
177 | scrollbar_ev.set <rxvt_term, &rxvt_term::x_cb> (this), |
179 | #endif |
|
|
180 | #ifdef USE_XIM |
178 | #ifdef USE_XIM |
181 | im_ev.set <rxvt_term, &rxvt_term::im_cb> (this), |
179 | im_ev.set <rxvt_term, &rxvt_term::im_cb> (this), |
182 | #endif |
180 | #endif |
183 | #ifdef POINTER_BLANK |
181 | #ifdef POINTER_BLANK |
184 | pointer_ev.set <rxvt_term, &rxvt_term::pointer_cb> (this); |
182 | pointer_ev.set <rxvt_term, &rxvt_term::pointer_cb> (this); |
… | |
… | |
229 | delete fontset[0]; |
227 | delete fontset[0]; |
230 | |
228 | |
231 | #ifdef HAVE_BG_PIXMAP |
229 | #ifdef HAVE_BG_PIXMAP |
232 | bgPixmap.destroy (); |
230 | bgPixmap.destroy (); |
233 | #endif |
231 | #endif |
|
|
232 | #ifdef HAVE_AFTERIMAGE |
|
|
233 | if (asv) |
|
|
234 | destroy_asvisual (asv, 0); |
|
|
235 | if (asimman) |
|
|
236 | destroy_image_manager (asimman, 0); |
|
|
237 | #endif |
234 | |
238 | |
235 | if (display) |
239 | if (display) |
236 | { |
240 | { |
237 | selection_clear (); |
241 | selection_clear (); |
|
|
242 | selection_clear (true); |
238 | |
243 | |
239 | #ifdef USE_XIM |
244 | #ifdef USE_XIM |
240 | im_destroy (); |
245 | im_destroy (); |
241 | #endif |
246 | #endif |
242 | #ifdef XTERM_SCROLLBAR |
247 | scrollBar.destroy (); |
243 | if (xscrollbarGC) XFreeGC (dpy, xscrollbarGC); |
|
|
244 | if (ShadowGC) XFreeGC (dpy, ShadowGC); |
|
|
245 | #endif |
|
|
246 | #ifdef PLAIN_SCROLLBAR |
|
|
247 | if (pscrollbarGC) XFreeGC (dpy, pscrollbarGC); |
|
|
248 | #endif |
|
|
249 | #ifdef NEXT_SCROLLBAR |
|
|
250 | if (blackGC) XFreeGC (dpy, blackGC); |
|
|
251 | if (whiteGC) XFreeGC (dpy, whiteGC); |
|
|
252 | if (grayGC) XFreeGC (dpy, grayGC); |
|
|
253 | if (darkGC) XFreeGC (dpy, darkGC); |
|
|
254 | if (stippleGC) XFreeGC (dpy, stippleGC); |
|
|
255 | if (dimple) XFreePixmap (dpy, dimple); |
|
|
256 | if (upArrow) XFreePixmap (dpy, upArrow); |
|
|
257 | if (downArrow) XFreePixmap (dpy, downArrow); |
|
|
258 | if (upArrowHi) XFreePixmap (dpy, upArrowHi); |
|
|
259 | if (downArrowHi) XFreePixmap (dpy, downArrowHi); |
|
|
260 | #endif |
|
|
261 | #ifdef RXVT_SCROLLBAR |
|
|
262 | if (topShadowGC) XFreeGC (dpy, topShadowGC); |
|
|
263 | if (botShadowGC) XFreeGC (dpy, botShadowGC); |
|
|
264 | if (scrollbarGC) XFreeGC (dpy, scrollbarGC); |
|
|
265 | #endif |
|
|
266 | if (gc) XFreeGC (dpy, gc); |
248 | if (gc) XFreeGC (dpy, gc); |
267 | |
249 | |
268 | delete drawable; |
250 | delete drawable; |
269 | // destroy all windows |
251 | // destroy all windows |
270 | if (parent[0]) |
252 | if (parent[0]) |
… | |
… | |
290 | /* clear all resources */ |
272 | /* clear all resources */ |
291 | for (int i = 0; i < allocated.size (); i++) |
273 | for (int i = 0; i < allocated.size (); i++) |
292 | free (allocated [i]); |
274 | free (allocated [i]); |
293 | |
275 | |
294 | free (selection.text); |
276 | free (selection.text); |
|
|
277 | free (selection.clip_text); |
295 | // TODO: manage env vars in child only(!) |
278 | // TODO: manage env vars in child only(!) |
296 | free (env_display); |
279 | free (env_display); |
297 | free (env_term); |
280 | free (env_term); |
298 | free (locale); |
281 | free (locale); |
299 | free (v_buffer); |
282 | free (v_buffer); |
… | |
… | |
337 | if (display) |
320 | if (display) |
338 | { |
321 | { |
339 | #if USE_XIM |
322 | #if USE_XIM |
340 | im_ev.stop (display); |
323 | im_ev.stop (display); |
341 | #endif |
324 | #endif |
342 | #if HAVE_SCROLLBARS |
|
|
343 | scrollbar_ev.stop (display); |
325 | scrollbar_ev.stop (display); |
344 | #endif |
|
|
345 | #if ENABLE_TRANSPARENCY || ENABLE_PERL |
326 | #if ENABLE_TRANSPARENCY || ENABLE_PERL |
346 | rootwin_ev.stop (display); |
327 | rootwin_ev.stop (display); |
347 | #endif |
328 | #endif |
348 | incr_ev.stop (); |
329 | incr_ev.stop (); |
349 | termwin_ev.stop (display); |
330 | termwin_ev.stop (display); |
… | |
… | |
529 | */ |
510 | */ |
530 | void |
511 | void |
531 | rxvt_term::window_calc (unsigned int newwidth, unsigned int newheight) |
512 | rxvt_term::window_calc (unsigned int newwidth, unsigned int newheight) |
532 | { |
513 | { |
533 | short recalc_x, recalc_y; |
514 | short recalc_x, recalc_y; |
534 | int x, y, sb_w, flags; |
515 | int x, y, flags; |
535 | unsigned int w, h; |
516 | unsigned int w, h; |
536 | unsigned int max_width, max_height; |
517 | unsigned int max_width, max_height; |
537 | |
518 | |
538 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
519 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
539 | szHint.win_gravity = NorthWestGravity; |
520 | szHint.win_gravity = NorthWestGravity; |
… | |
… | |
549 | if (rs[Rs_geometry]) |
530 | if (rs[Rs_geometry]) |
550 | flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); |
531 | flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); |
551 | |
532 | |
552 | if (flags & WidthValue) |
533 | if (flags & WidthValue) |
553 | { |
534 | { |
|
|
535 | if (!w) |
|
|
536 | rxvt_fatal ("illegal window geometry (width and height must be non-zero), aborting.\n"); |
|
|
537 | |
554 | ncol = clamp (w, 0, std::numeric_limits<int16_t>::max ()); |
538 | ncol = clamp (w, 1, std::numeric_limits<int16_t>::max ()); |
555 | szHint.flags |= USSize; |
539 | szHint.flags |= USSize; |
556 | } |
540 | } |
557 | |
541 | |
558 | if (flags & HeightValue) |
542 | if (flags & HeightValue) |
559 | { |
543 | { |
|
|
544 | if (!h) |
|
|
545 | rxvt_fatal ("illegal window geometry (width and height must be non-zero), aborting.\n"); |
|
|
546 | |
560 | nrow = clamp (h, 0, std::numeric_limits<int16_t>::max ()); |
547 | nrow = clamp (h, 1, std::numeric_limits<int16_t>::max ()); |
561 | szHint.flags |= USSize; |
548 | szHint.flags |= USSize; |
562 | } |
549 | } |
563 | |
550 | |
564 | if (flags & XValue) |
551 | if (flags & XValue) |
565 | { |
552 | { |
… | |
… | |
596 | max_width = MAX_COLS * fwidth; |
583 | max_width = MAX_COLS * fwidth; |
597 | max_height = MAX_ROWS * fheight; |
584 | max_height = MAX_ROWS * fheight; |
598 | |
585 | |
599 | szHint.base_width = szHint.base_height = 2 * int_bwidth; |
586 | szHint.base_width = szHint.base_height = 2 * int_bwidth; |
600 | |
587 | |
601 | sb_w = 0; |
|
|
602 | window_vt_x = window_vt_y = int_bwidth; |
588 | window_vt_x = window_vt_y = int_bwidth; |
603 | |
589 | |
604 | if (scrollBar.state) |
590 | if (scrollBar.state) |
605 | { |
591 | { |
606 | sb_w = scrollbar_TotalWidth (); |
592 | int sb_w = scrollBar.total_width (); |
607 | szHint.base_width += sb_w; |
593 | szHint.base_width += sb_w; |
608 | |
594 | |
609 | if (!option (Opt_scrollBar_right)) |
595 | if (!option (Opt_scrollBar_right)) |
610 | window_vt_x += sb_w; |
596 | window_vt_x += sb_w; |
611 | } |
597 | } |
… | |
… | |
635 | { |
621 | { |
636 | min_it (height, max_height); |
622 | min_it (height, max_height); |
637 | szHint.height = szHint.base_height + height; |
623 | szHint.height = szHint.base_height + height; |
638 | } |
624 | } |
639 | |
625 | |
640 | if (scrollBar.state && option (Opt_scrollBar_right)) |
|
|
641 | window_sb_x = szHint.width - sb_w; |
|
|
642 | |
|
|
643 | if (recalc_x) |
626 | if (recalc_x) |
644 | szHint.x += DisplayWidth (dpy, display->screen) - szHint.width - 2 * ext_bwidth; |
627 | szHint.x += DisplayWidth (dpy, display->screen) - szHint.width - 2 * ext_bwidth; |
645 | |
628 | |
646 | if (recalc_y) |
629 | if (recalc_y) |
647 | szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth; |
630 | szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth; |
648 | |
631 | |
649 | ncol = width / fwidth; |
632 | ncol = width / fwidth; |
650 | nrow = height / fheight; |
633 | nrow = height / fheight; |
651 | } |
634 | } |
652 | |
635 | |
653 | /*----------------------------------------------------------------------*/ |
636 | /*----------------------------------------------------------------------*/ |
654 | /* |
637 | /* |
… | |
… | |
665 | |
648 | |
666 | ws.ws_col = ncol; |
649 | ws.ws_col = ncol; |
667 | ws.ws_row = nrow; |
650 | ws.ws_row = nrow; |
668 | ws.ws_xpixel = width; |
651 | ws.ws_xpixel = width; |
669 | ws.ws_ypixel = height; |
652 | ws.ws_ypixel = height; |
670 | (void)ioctl (pty->pty, TIOCSWINSZ, &ws); |
653 | ioctl (pty->pty, TIOCSWINSZ, &ws); |
671 | |
654 | |
672 | #if 0 |
655 | #if 0 |
673 | // TIOCSWINSZ is supposed to do this automatically and correctly |
656 | // TIOCSWINSZ is supposed to do this automatically and correctly |
674 | if (cmd_pid) /* force through to the command */ |
657 | if (cmd_pid) /* force through to the command */ |
675 | kill (-cmd_pid, SIGWINCH); |
658 | kill (-cmd_pid, SIGWINCH); |
… | |
… | |
707 | delete fontset[0]; |
690 | delete fontset[0]; |
708 | fontset[0] = fs; |
691 | fontset[0] = fs; |
709 | |
692 | |
710 | prop = (*fs)[1]->properties (); |
693 | prop = (*fs)[1]->properties (); |
711 | prop.height += lineSpace; |
694 | prop.height += lineSpace; |
|
|
695 | prop.width += letterSpace; |
712 | |
696 | |
713 | fs->set_prop (prop, false); |
697 | fs->set_prop (prop, false); |
714 | |
698 | |
715 | fwidth = prop.width; |
699 | fwidth = prop.width; |
716 | fheight = prop.height; |
700 | fheight = prop.height; |
… | |
… | |
805 | void |
789 | void |
806 | rxvt_term::set_window_color (int idx, const char *color) |
790 | rxvt_term::set_window_color (int idx, const char *color) |
807 | { |
791 | { |
808 | #ifdef XTERM_COLOR_CHANGE |
792 | #ifdef XTERM_COLOR_CHANGE |
809 | rxvt_color xcol; |
793 | rxvt_color xcol; |
810 | int i; |
|
|
811 | |
794 | |
812 | if (color == NULL || *color == '\0') |
795 | if (color == NULL || *color == '\0') |
813 | return; |
796 | return; |
814 | |
797 | |
815 | color = strdup (color); |
798 | color = strdup (color); |
… | |
… | |
817 | rs[Rs_color + idx] = color; |
800 | rs[Rs_color + idx] = color; |
818 | |
801 | |
819 | /* handle color aliases */ |
802 | /* handle color aliases */ |
820 | if (isdigit (*color)) |
803 | if (isdigit (*color)) |
821 | { |
804 | { |
822 | i = atoi (color); |
805 | int i = atoi (color); |
823 | |
806 | |
824 | if (i >= 8 && i <= 15) |
807 | if (i >= 8 && i <= 15) |
825 | { |
808 | { |
826 | /* bright colors */ |
809 | /* bright colors */ |
827 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i - 8]; |
810 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i - 8]; |
… | |
… | |
931 | int old_width = szHint.width; |
914 | int old_width = szHint.width; |
932 | int old_height = szHint.height; |
915 | int old_height = szHint.height; |
933 | |
916 | |
934 | window_calc (newwidth, newheight); |
917 | window_calc (newwidth, newheight); |
935 | |
918 | |
936 | if (!HOOK_INVOKE ((this, HOOK_RESIZE_ALL_WINDOWS, DT_INT, newwidth, DT_INT, newheight, DT_END))) |
919 | bool set_hint = !HOOK_INVOKE ((this, HOOK_RESIZE_ALL_WINDOWS, DT_INT, newwidth, DT_INT, newheight, DT_END)); |
|
|
920 | |
|
|
921 | // to avoid races between us and the wm, we clear the incremental size hints around the xresizewindow |
|
|
922 | if (set_hint) |
|
|
923 | { |
|
|
924 | szHint.flags &= ~(PBaseSize | PResizeInc); |
937 | XSetWMNormalHints (dpy, parent[0], &szHint); |
925 | XSetWMNormalHints (dpy, parent[0], &szHint); |
|
|
926 | szHint.flags |= PBaseSize | PResizeInc; |
|
|
927 | } |
938 | |
928 | |
939 | if (!ignoreparent) |
929 | if (!ignoreparent) |
940 | { |
930 | { |
941 | #ifdef SMART_RESIZE |
931 | #ifdef SMART_RESIZE |
942 | /* |
932 | /* |
… | |
… | |
982 | #else |
972 | #else |
983 | XResizeWindow (dpy, parent[0], szHint.width, szHint.height); |
973 | XResizeWindow (dpy, parent[0], szHint.width, szHint.height); |
984 | #endif |
974 | #endif |
985 | } |
975 | } |
986 | |
976 | |
|
|
977 | if (set_hint) |
|
|
978 | XSetWMNormalHints (dpy, parent[0], &szHint); |
|
|
979 | |
987 | fix_screen = ncol != prev_ncol || nrow != prev_nrow; |
980 | fix_screen = ncol != prev_ncol || nrow != prev_nrow; |
988 | |
981 | |
989 | if (fix_screen || newwidth != old_width || newheight != old_height) |
982 | if (fix_screen || newwidth != old_width || newheight != old_height) |
990 | { |
983 | { |
991 | if (scrollBar.state) |
984 | if (scrollBar.state) |
992 | { |
985 | scrollBar.resize (); |
993 | XMoveResizeWindow (dpy, scrollBar.win, |
|
|
994 | window_sb_x, 0, |
|
|
995 | scrollbar_TotalWidth (), szHint.height); |
|
|
996 | resize_scrollbar (); |
|
|
997 | } |
|
|
998 | |
986 | |
999 | XMoveResizeWindow (dpy, vt, |
987 | XMoveResizeWindow (dpy, vt, |
1000 | window_vt_x, window_vt_y, |
988 | window_vt_x, window_vt_y, |
1001 | width, height); |
989 | width, height); |
1002 | |
990 | |
1003 | #ifdef HAVE_BG_PIXMAP |
991 | #ifdef HAVE_BG_PIXMAP |
1004 | if (bgPixmap.window_size_sensitive ()) |
992 | if (bgPixmap.window_size_sensitive ()) |
1005 | update_background (); |
993 | update_background (); |
1006 | #endif |
994 | #endif |
1007 | |
|
|
1008 | scr_clear (); |
|
|
1009 | } |
995 | } |
1010 | |
996 | |
1011 | if (fix_screen || old_height == 0) |
997 | if (fix_screen || old_height == 0) |
1012 | scr_reset (); |
998 | scr_reset (); |
1013 | |
|
|
1014 | // TODO, with nvidia-8178, resizes kill the alpha channel, report if not fixed in newer version |
|
|
1015 | //scr_touch (false); |
|
|
1016 | |
999 | |
1017 | #ifdef HAVE_BG_PIXMAP |
1000 | #ifdef HAVE_BG_PIXMAP |
1018 | // TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ? |
1001 | // TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ? |
1019 | // if (bgPixmap.pixmap) |
1002 | // if (bgPixmap.pixmap) |
1020 | // scr_touch (false); |
1003 | // scr_touch (false); |
… | |
… | |
1092 | |
1075 | |
1093 | /* Checking whether input method is running. */ |
1076 | /* Checking whether input method is running. */ |
1094 | bool |
1077 | bool |
1095 | rxvt_term::IMisRunning () |
1078 | rxvt_term::IMisRunning () |
1096 | { |
1079 | { |
1097 | char *p; |
|
|
1098 | Atom atom; |
1080 | Atom atom; |
1099 | Window win; |
1081 | Window win; |
1100 | char server[IMBUFSIZ]; |
1082 | char server[IMBUFSIZ]; |
1101 | |
1083 | |
1102 | /* get current locale modifier */ |
1084 | /* get current locale modifier */ |
1103 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1085 | if (char *p = XSetLocaleModifiers (0)) |
1104 | { |
1086 | { |
1105 | strcpy (server, "@server="); |
1087 | strcpy (server, "@server="); |
1106 | strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
1088 | strncat (server, p + 4, IMBUFSIZ - 9); /* skip "@im=" */ |
1107 | |
1089 | |
1108 | if ((p = strchr (server + 1, '@')) != NULL) /* first one only */ |
1090 | if (p = strchr (server + 1, '@')) /* first one only */ |
1109 | *p = '\0'; |
1091 | *p = '\0'; |
1110 | |
1092 | |
1111 | atom = XInternAtom (dpy, server, False); |
1093 | atom = XInternAtom (dpy, server, False); |
1112 | win = XGetSelectionOwner (dpy, atom); |
1094 | win = XGetSelectionOwner (dpy, atom); |
1113 | |
1095 | |
… | |
… | |
1180 | |
1162 | |
1181 | term->make_current (); |
1163 | term->make_current (); |
1182 | |
1164 | |
1183 | if (text) |
1165 | if (text) |
1184 | { |
1166 | { |
1185 | void *str; |
1167 | wchar_t *str; |
1186 | |
1168 | |
1187 | if (!text->encoding_is_wchar && text->string.multi_byte) |
1169 | if (!text->encoding_is_wchar && text->string.multi_byte) |
1188 | { |
1170 | { |
1189 | // of course, X makes it ugly again |
1171 | // of course, X makes it ugly again |
1190 | if (term->rs[Rs_imLocale]) |
1172 | if (term->rs[Rs_imLocale]) |
1191 | SET_LOCALE (term->rs[Rs_imLocale]); |
1173 | SET_LOCALE (term->rs[Rs_imLocale]); |
1192 | |
1174 | |
1193 | str = rxvt_temp_buf ((text->length + 1) * sizeof (wchar_t)); |
1175 | str = rxvt_temp_buf<wchar_t> (text->length + 1); |
1194 | mbstowcs ((wchar_t *)str, text->string.multi_byte, text->length + 1); |
1176 | mbstowcs (str, text->string.multi_byte, text->length + 1); |
1195 | |
1177 | |
1196 | if (term->rs[Rs_imLocale]) |
1178 | if (term->rs[Rs_imLocale]) |
1197 | SET_LOCALE (term->locale); |
1179 | SET_LOCALE (term->locale); |
1198 | } |
1180 | } |
1199 | else |
1181 | else |
1200 | str = (void *)text->string.wide_char; |
1182 | str = text->string.wide_char; |
1201 | |
1183 | |
1202 | HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW, |
1184 | HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW, |
1203 | DT_INT, call_data->caret, |
1185 | DT_INT, call_data->caret, |
1204 | DT_INT, call_data->chg_first, |
1186 | DT_INT, call_data->chg_first, |
1205 | DT_INT, call_data->chg_length, |
1187 | DT_INT, call_data->chg_length, |