Mercurial > pidgin
comparison console/libgnt/gntmain.c @ 14425:3a91ef295cbb
[gaim-migrate @ 17133]
If the window-title has wide-characters, and you go in move/resize mode,
then reversing the colors screws up the title. This is a fix for that.
It's a bit hackish, but that's the way it's gotta be for now.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 03 Sep 2006 02:12:26 +0000 |
parents | 553bbd68387e |
children | f3645fe3da47 |
comparison
equal
deleted
inserted
replaced
14424:c374f45f4c94 | 14425:3a91ef295cbb |
---|---|
1 #define _XOPEN_SOURCE | |
2 #define _XOPEN_SOURCE_EXTENDED | |
3 | |
1 #include "config.h" | 4 #include "config.h" |
2 | 5 |
3 #ifdef HAVE_NCURSESW_INC | 6 #ifdef HAVE_NCURSESW_INC |
4 #include <ncursesw/panel.h> | 7 #include <ncursesw/panel.h> |
5 #else | 8 #else |
25 #include <ctype.h> | 28 #include <ctype.h> |
26 #include <errno.h> | 29 #include <errno.h> |
27 | 30 |
28 #include <sys/types.h> | 31 #include <sys/types.h> |
29 #include <sys/wait.h> | 32 #include <sys/wait.h> |
33 | |
34 #include <wchar.h> | |
30 | 35 |
31 /** | 36 /** |
32 * Notes: Interesting functions to look at: | 37 * Notes: Interesting functions to look at: |
33 * scr_dump, scr_init, scr_restore: for workspaces | 38 * scr_dump, scr_init, scr_restore: for workspaces |
34 * | 39 * |
645 | 650 |
646 gnt_widget_clicked(ordered->data, event, x, y); | 651 gnt_widget_clicked(ordered->data, event, x, y); |
647 return FALSE; /* XXX: this should be TRUE */ | 652 return FALSE; /* XXX: this should be TRUE */ |
648 } | 653 } |
649 | 654 |
655 /* Returns the onscreen width of the character at the position */ | |
656 static int | |
657 reverse_char(WINDOW *d, int y, int x, gboolean set) | |
658 { | |
659 /* This is supposed to simply in_wch the cchar_t, set the attribute, | |
660 * and add_wch. But that doesn't currently work, possibly because of | |
661 * a bug in ncurses. This is an ugly hack to work around that. */ | |
662 cchar_t ch; | |
663 int wc = 1, j; | |
664 | |
665 #define DECIDE(ch) (set ? ((ch) | WA_REVERSE) : ((ch) & ~WA_REVERSE)) | |
666 | |
667 if (mvwin_wch(d, y, x, &ch) == OK) { | |
668 wc = wcswidth(ch.chars, CCHARW_MAX); | |
669 for (j = 0; j < wc; j++) | |
670 mvwdelch(d, y, x); | |
671 ch.attr = DECIDE(ch.attr); | |
672 mvwins_wch(d, y, x, &ch); | |
673 } | |
674 return wc; | |
675 } | |
676 | |
650 static void | 677 static void |
651 window_reverse(GntWidget *win, gboolean set) | 678 window_reverse(GntWidget *win, gboolean set) |
652 { | 679 { |
653 int i; | 680 int i; |
654 int w, h; | 681 int w, h; |
658 return; | 685 return; |
659 | 686 |
660 d = win->window; | 687 d = win->window; |
661 gnt_widget_get_size(win, &w, &h); | 688 gnt_widget_get_size(win, &w, &h); |
662 | 689 |
663 #define DECIDE(ch) (set ? ((ch) | A_REVERSE) : ((ch) & ~A_REVERSE)) | |
664 | |
665 /* the top and bottom */ | 690 /* the top and bottom */ |
666 for (i = 0; i < w; i++) { | 691 for (i = 0; i < w; i += reverse_char(d, 0, i, set)); |
667 chtype ch = mvwinch(d, 0, i); | 692 for (i = 0; i < w; i += reverse_char(d, h-1, i, set)); |
668 mvwaddch(win->window, 0, i, DECIDE(ch)); | 693 |
669 ch = mvwinch(d, h-1, i); | 694 /* the left and right */ |
670 mvwaddch(win->window, h-1, i, DECIDE(ch)); | 695 for (i = 0; i < h; i += reverse_char(d, i, 0, set)); |
671 } | 696 for (i = 0; i < h; i += reverse_char(d, i, w-1, set)); |
672 | |
673 /* the left an right */ | |
674 for (i = 0; i < h; i++) { | |
675 chtype ch = mvwinch(d, i, 0); | |
676 mvwaddch(win->window, i, 0, DECIDE(ch)); | |
677 ch = mvwinch(d, i, w-1); | |
678 mvwaddch(win->window, i, w-1, DECIDE(ch)); | |
679 } | |
680 | 697 |
681 wrefresh(win->window); | 698 wrefresh(win->window); |
682 } | 699 } |
683 | 700 |
684 static gboolean | 701 static gboolean |
852 } | 869 } |
853 } | 870 } |
854 else if (buffer[1] == 0) | 871 else if (buffer[1] == 0) |
855 { | 872 { |
856 mode = GNT_KP_MODE_NORMAL; | 873 mode = GNT_KP_MODE_NORMAL; |
857 changed = TRUE; | 874 window_reverse(widget, FALSE); |
858 gnt_widget_draw(widget); | |
859 } | 875 } |
860 | 876 |
861 if (changed) | 877 if (changed) |
862 { | 878 { |
863 gnt_screen_move_widget(widget, x, y); | 879 gnt_screen_move_widget(widget, x, y); |
962 pid = waitpid(-1, &status, WNOHANG); | 978 pid = waitpid(-1, &status, WNOHANG); |
963 } while (pid != 0 && pid != (pid_t)-1); | 979 } while (pid != 0 && pid != (pid_t)-1); |
964 | 980 |
965 if ((pid == (pid_t) - 1) && (errno != ECHILD)) { | 981 if ((pid == (pid_t) - 1) && (errno != ECHILD)) { |
966 char errmsg[BUFSIZ]; | 982 char errmsg[BUFSIZ]; |
967 snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); | 983 g_snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); |
968 perror(errmsg); | 984 perror(errmsg); |
969 } | 985 } |
970 } | 986 } |
971 | 987 |
972 static void | 988 static void |