comparison mcabber/src/screen.c @ 361:51ff319947c3

Code cleanup/optimization
author Mikael Berthe <mikael@lilotux.net>
date Sat, 23 Jul 2005 21:50:06 +0100
parents 6e4e667c5571
children 913915140ad2
comparison
equal deleted inserted replaced
360:20283b69db99 361:51ff319947c3
245 245
246 static window_entry_t *scr_SearchWindow(const char *winId) 246 static window_entry_t *scr_SearchWindow(const char *winId)
247 { 247 {
248 struct list_head *pos, *n; 248 struct list_head *pos, *n;
249 window_entry_t *search_entry = NULL; 249 window_entry_t *search_entry = NULL;
250
251 if (!winId) return NULL;
250 252
251 list_for_each_safe(pos, n, &window_list) { 253 list_for_each_safe(pos, n, &window_list) {
252 search_entry = window_entry(pos); 254 search_entry = window_entry(pos);
253 if (search_entry->name) { 255 if (search_entry->name) {
254 if (!strcasecmp(search_entry->name, winId)) { 256 if (!strcasecmp(search_entry->name, winId)) {
904 set_current_buddy(alternate_buddy); 906 set_current_buddy(alternate_buddy);
905 if (chatmode) 907 if (chatmode)
906 scr_ShowBuddyWindow(); 908 scr_ShowBuddyWindow();
907 } 909 }
908 910
909 // scr_ScrollUp() 911 // scr_ScrollUpDown()
910 // Scroll up the current buddy window, half a screen. 912 // Scroll up/down the current buddy window, half a screen.
911 void scr_ScrollUp(void) 913 // (up if updown == -1, down if updown == 1)
912 { 914 void scr_ScrollUpDown(int updown)
913 const gchar *jid; 915 {
914 window_entry_t *win_entry; 916 window_entry_t *win_entry;
915 int n, nblines; 917 int n, nblines;
916 GList *hbuf_top; 918 GList *hbuf_top;
917 919
918 // Get win_entry 920 // Get win_entry
919 if (!current_buddy) 921 if (!current_buddy) return;
920 return; 922 win_entry = scr_SearchWindow(CURRENT_JID);
921 jid = CURRENT_JID; 923 if (!win_entry) return;
922 if (!jid) 924
923 return; 925 // Scroll half a screen (or less)
924 win_entry = scr_SearchWindow(jid);
925 if (!win_entry)
926 return;
927
928 // Scroll up half a screen (or less)
929 nblines = CHAT_WIN_HEIGHT/2-1; 926 nblines = CHAT_WIN_HEIGHT/2-1;
930 hbuf_top = win_entry->top; 927 hbuf_top = win_entry->top;
931 if (!hbuf_top) { 928
932 hbuf_top = g_list_last(win_entry->hbuf); 929 if (updown == -1) { // UP
933 if (!win_entry->cleared) 930 if (!hbuf_top) {
934 nblines *= 3; 931 hbuf_top = g_list_last(win_entry->hbuf);
935 else 932 if (!win_entry->cleared)
936 win_entry->cleared = FALSE; 933 nblines *= 3;
937 } 934 else
938 935 win_entry->cleared = FALSE;
939 n = 0; 936 }
940 while (hbuf_top && n < nblines && g_list_previous(hbuf_top)) { 937 for (n=0 ; hbuf_top && n < nblines && g_list_previous(hbuf_top) ; n++)
941 hbuf_top = g_list_previous(hbuf_top); 938 hbuf_top = g_list_previous(hbuf_top);
942 n++; 939 win_entry->top = hbuf_top;
943 } 940 } else { // DOWN
944 win_entry->top = hbuf_top; 941 for (n=0 ; hbuf_top && n < nblines ; n++)
942 hbuf_top = g_list_next(hbuf_top);
943 win_entry->top = hbuf_top;
944 // Check if we are at the bottom
945 for (n=0 ; hbuf_top && n < CHAT_WIN_HEIGHT-1 ; n++)
946 hbuf_top = g_list_next(hbuf_top);
947 if (!hbuf_top)
948 win_entry->top = NULL; // End reached
949 }
945 950
946 // Refresh the window 951 // Refresh the window
947 scr_UpdateWindow(win_entry); 952 scr_UpdateWindow(win_entry);
948 953
949 // Finished :) 954 // Finished :)
950 update_panels(); 955 update_panels();
951 doupdate(); 956 doupdate();
952 } 957 }
953 958
954 // scr_ScrollDown() 959 // scr_Clear()
955 // Scroll down the current buddy window, half a screen. 960 // Clear the current buddy window (used for the /clear command)
956 void scr_ScrollDown(void) 961 void scr_Clear(void)
957 { 962 {
958 const gchar *jid;
959 window_entry_t *win_entry; 963 window_entry_t *win_entry;
960 int n, nblines;
961 GList *hbuf_top;
962 964
963 // Get win_entry 965 // Get win_entry
964 if (!current_buddy) 966 if (!current_buddy) return;
965 return; 967 win_entry = scr_SearchWindow(CURRENT_JID);
966 jid = CURRENT_JID; 968 if (!win_entry) return;
967 if (!jid) 969
968 return; 970 win_entry->cleared = TRUE;
969 win_entry = scr_SearchWindow(jid); 971 win_entry->top = NULL;
970 if (!win_entry)
971 return;
972
973 // Scroll down half a screen (or less)
974 nblines = CHAT_WIN_HEIGHT/2-1;
975 hbuf_top = win_entry->top;
976
977 for (n=0 ; hbuf_top && n < nblines ; n++)
978 hbuf_top = g_list_next(hbuf_top);
979 win_entry->top = hbuf_top;
980 // Check if we are at the bottom
981 for (n=0 ; hbuf_top && n < CHAT_WIN_HEIGHT-1 ; n++)
982 hbuf_top = g_list_next(hbuf_top);
983 if (!hbuf_top)
984 win_entry->top = NULL; // End reached
985 972
986 // Refresh the window 973 // Refresh the window
987 scr_UpdateWindow(win_entry); 974 scr_UpdateWindow(win_entry);
988 975
989 // Finished :) 976 // Finished :)
990 update_panels(); 977 update_panels();
991 doupdate(); 978 doupdate();
992 } 979 }
993 980
994 // scr_Clear() 981 // scr_BufferTopBottom()
995 // Clear the current buddy window (used for the /clear command) 982 // Jump to the head/tail of the current buddy window
996 void scr_Clear(void) 983 // (top if topbottom == -1, bottom topbottom == 1)
997 { 984 void scr_BufferTopBottom(int topbottom)
998 const gchar *jid; 985 {
999 window_entry_t *win_entry;
1000
1001 // Get win_entry
1002 if (!current_buddy)
1003 return;
1004 jid = CURRENT_JID;
1005 if (!jid)
1006 return;
1007 win_entry = scr_SearchWindow(jid);
1008 if (!win_entry)
1009 return;
1010
1011 win_entry->cleared = TRUE;
1012 win_entry->top = NULL;
1013
1014 // Refresh the window
1015 scr_UpdateWindow(win_entry);
1016
1017 // Finished :)
1018 update_panels();
1019 doupdate();
1020 }
1021
1022 // TODO Merge BufferTop & BufferBottom
1023 // scr_BufferTop()
1024 // Jump to the head of the current buddy window
1025 void scr_BufferTop(void)
1026 {
1027 const gchar *jid;
1028 window_entry_t *win_entry; 986 window_entry_t *win_entry;
1029 987
1030 // Get win_entry 988 // Get win_entry
1031 if (!current_buddy) return; 989 if (!current_buddy) return;
1032 jid = CURRENT_JID; 990 win_entry = scr_SearchWindow(CURRENT_JID);
1033 if (!jid) return;
1034 win_entry = scr_SearchWindow(jid);
1035
1036 if (!win_entry) return; 991 if (!win_entry) return;
1037 992
1038 win_entry->cleared = FALSE; 993 win_entry->cleared = FALSE;
1039 win_entry->top = g_list_first(win_entry->hbuf); 994 if (topbottom == 1)
1040 995 win_entry->top = NULL;
1041 // Refresh the window 996 else
1042 scr_UpdateWindow(win_entry); 997 win_entry->top = g_list_first(win_entry->hbuf);
1043
1044 // Finished :)
1045 update_panels();
1046 doupdate();
1047 }
1048
1049 // scr_BufferBottom()
1050 // Jump to the end of the current buddy window
1051 void scr_BufferBottom(void)
1052 {
1053 const gchar *jid;
1054 window_entry_t *win_entry;
1055
1056 // Get win_entry
1057 if (!current_buddy) return;
1058 jid = CURRENT_JID;
1059 if (!jid) return;
1060 win_entry = scr_SearchWindow(jid);
1061
1062 if (!win_entry) return;
1063
1064 win_entry->cleared = FALSE;
1065 win_entry->top = NULL;
1066 998
1067 // Refresh the window 999 // Refresh the window
1068 scr_UpdateWindow(win_entry); 1000 scr_UpdateWindow(win_entry);
1069 1001
1070 // Finished :) 1002 // Finished :)
1595 case KEY_EOL: 1527 case KEY_EOL:
1596 case 11: // Ctrl-k 1528 case 11: // Ctrl-k
1597 *ptr_inputline = 0; 1529 *ptr_inputline = 0;
1598 break; 1530 break;
1599 case 16: // Ctrl-p 1531 case 16: // Ctrl-p
1600 scr_ScrollUp(); 1532 scr_ScrollUpDown(-1);
1601 break; 1533 break;
1602 case 14: // Ctrl-n 1534 case 14: // Ctrl-n
1603 scr_ScrollDown(); 1535 scr_ScrollUpDown(1);
1604 break; 1536 break;
1605 case 17: // Ctrl-q 1537 case 17: // Ctrl-q
1606 scr_CheckAutoAway(TRUE); 1538 scr_CheckAutoAway(TRUE);
1607 scr_RosterUnreadMessage(1); // next unread message 1539 scr_RosterUnreadMessage(1); // next unread message
1608 break; 1540 break;