Changes in global.c [26ad412:8bba1ae]
Legend:
- Unmodified
- Added
- Removed
-
global.c
r26ad412 r8bba1ae 13 13 #endif 14 14 15 static void _owl_global_init_windows(owl_global *g); 16 15 17 void owl_global_init(owl_global *g) { 16 18 struct hostent *hent; … … 20 22 g->malloced=0; 21 23 g->freed=0; 24 25 g_type_init(); 22 26 23 27 gethostname(hostname, MAXHOSTNAMELEN); … … 29 33 } 30 34 35 g->lines=LINES; 36 g->cols=COLS; 37 /* We shouldn't need this if we initialize lines and cols before the first 38 * owl_window_get_screen, but to be safe, we synchronize. */ 39 owl_window_resize(owl_window_get_screen(), g->lines, g->cols); 40 31 41 g->context_stack = NULL; 32 owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL );42 owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL, NULL); 33 43 34 44 g->curmsg=0; 35 45 g->topmsg=0; 36 46 g->markedmsgid=-1; 37 g->needrefresh=1;38 47 g->startupargs=NULL; 39 48 40 49 owl_variable_dict_setup(&(g->vars)); 41 42 g->lines=LINES;43 g->cols=COLS;44 50 45 51 g->rightshift=0; … … 53 59 g->filterlist = NULL; 54 60 owl_list_create(&(g->puntlist)); 55 owl_list_create(&(g->messagequeue));61 g->messagequeue = g_queue_new(); 56 62 owl_dict_create(&(g->styledict)); 57 63 g->curmsg_vert_offset=0; 58 64 g->resizepending=0; 59 g->relayoutpending = 0;60 65 g->direction=OWL_DIRECTION_DOWNWARDS; 61 66 g->zaway=0; … … 79 84 g->nextmsgid=0; 80 85 81 _owl_global_setup_windows(g);82 83 86 /* Fill in some variables which don't have constant defaults */ 84 87 /* TODO: come back later and check passwd file first */ … … 92 95 93 96 owl_messagelist_create(&(g->msglist)); 94 owl_mainwin_init(&(g->mw)); 95 owl_popwin_init(&(g->pw));97 98 _owl_global_init_windows(g); 96 99 97 100 g->aim_screenname=NULL; … … 112 115 g->zaldlist = NULL; 113 116 g->pseudologin_notify = 0; 114 115 owl_obarray_init(&(g->obarray));116 117 117 118 owl_message_init_fmtext_cache(); … … 120 121 g->timerlist = NULL; 121 122 g->interrupted = FALSE; 123 } 124 125 static void _owl_global_init_windows(owl_global *g) 126 { 127 /* Create the main window */ 128 owl_mainpanel_init(&(g->mainpanel)); 129 130 /* Create the widgets */ 131 owl_mainwin_init(&(g->mw), g->mainpanel.recwin); 132 owl_popwin_init(&(g->pw)); 133 owl_msgwin_init(&(g->msgwin), g->mainpanel.msgwin); 134 owl_sepbar_init(g->mainpanel.sepwin); 135 136 owl_window_set_default_cursor(g->mainpanel.sepwin); 122 137 123 138 /* set up a pad for input */ … … 126 141 keypad(g->input_pad, 1); 127 142 meta(g->input_pad, 1); 143 } 144 145 void owl_global_sepbar_dirty(owl_global *g) 146 { 147 owl_window_dirty(g->mainpanel.sepwin); 128 148 } 129 149 … … 158 178 } 159 179 160 void _owl_global_setup_windows(owl_global *g) {161 int cols, typwin_lines;162 163 cols=g->cols;164 typwin_lines=owl_global_get_typwin_lines(g);165 166 /* set the new window sizes */167 g->recwinlines=g->lines-(typwin_lines+2);168 if (g->recwinlines<0) {169 /* gotta deal with this */170 g->recwinlines=0;171 }172 173 /* create the new windows */174 _owl_panel_set_window(&g->recpan, newwin(g->recwinlines, cols, 0, 0));175 _owl_panel_set_window(&g->seppan, newwin(1, cols, g->recwinlines, 0));176 _owl_panel_set_window(&g->msgpan, newwin(1, cols, g->recwinlines+1, 0));177 _owl_panel_set_window(&g->typpan, newwin(typwin_lines, cols, g->recwinlines+2, 0));178 179 if (g->tw)180 owl_editwin_set_curswin(g->tw, owl_global_get_curs_typwin(g), typwin_lines, g->cols);181 182 idlok(owl_global_get_curs_typwin(g), FALSE);183 idlok(owl_global_get_curs_recwin(g), FALSE);184 idlok(owl_global_get_curs_sepwin(g), FALSE);185 idlok(owl_global_get_curs_msgwin(g), FALSE);186 187 wmove(owl_global_get_curs_typwin(g), 0, 0);188 }189 190 180 owl_context *owl_global_get_context(owl_global *g) { 191 181 if (!g->context_stack) … … 194 184 } 195 185 196 static void owl_global_lookup_keymap(owl_global *g) { 197 owl_context *c = owl_global_get_context(g); 198 if (!c || !c->keymap) 186 static void owl_global_activate_context(owl_global *g, owl_context *c) { 187 if (!c) 199 188 return; 200 189 201 if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) { 202 owl_function_error("Unable to activate keymap '%s'", c->keymap); 203 } 204 } 205 206 void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap) { 190 if (c->keymap) { 191 if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) { 192 owl_function_error("Unable to activate keymap '%s'", c->keymap); 193 } 194 } 195 owl_window_set_cursor(c->cursor); 196 } 197 198 void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap, owl_window *cursor) { 207 199 owl_context *c; 208 200 if (!(mode & OWL_CTX_MODE_BITS)) … … 211 203 c->mode = mode; 212 204 c->data = data; 205 c->cursor = cursor ? g_object_ref(cursor) : NULL; 213 206 c->keymap = owl_strdup(keymap); 214 207 g->context_stack = g_list_prepend(g->context_stack, c); 215 owl_global_ lookup_keymap(g);208 owl_global_activate_context(g, owl_global_get_context(g)); 216 209 } 217 210 … … 223 216 g->context_stack = g_list_delete_link(g->context_stack, 224 217 g->context_stack); 218 if (c->cursor) 219 g_object_unref(c->cursor); 225 220 owl_free(c->keymap); 226 221 owl_free(c); 227 owl_global_ lookup_keymap(g);222 owl_global_activate_context(g, owl_global_get_context(g)); 228 223 } 229 224 … … 237 232 238 233 int owl_global_get_recwin_lines(const owl_global *g) { 239 return (g->recwinlines);234 return g->mainpanel.recwinlines; 240 235 } 241 236 … … 303 298 } 304 299 305 /* curses windows */ 306 307 WINDOW *owl_global_get_curs_recwin(const owl_global *g) { 308 return panel_window(g->recpan); 309 } 310 311 WINDOW *owl_global_get_curs_sepwin(const owl_global *g) { 312 return panel_window(g->seppan); 313 } 314 315 WINDOW *owl_global_get_curs_msgwin(const owl_global *g) { 316 return panel_window(g->msgpan); 317 } 318 319 WINDOW *owl_global_get_curs_typwin(const owl_global *g) { 320 return panel_window(g->typpan); 300 /* underlying owl_windows */ 301 302 owl_window *owl_global_get_typwin_window(const owl_global *g) { 303 return g->mainpanel.typwin; 321 304 } 322 305 … … 327 310 } 328 311 329 /* refresh */330 331 int owl_global_is_needrefresh(const owl_global *g) {332 if (g->needrefresh==1) return(1);333 return(0);334 }335 336 void owl_global_set_needrefresh(owl_global *g) {337 g->needrefresh=1;338 }339 340 void owl_global_set_noneedrefresh(owl_global *g) {341 g->needrefresh=0;342 }343 344 312 /* variable dictionary */ 345 313 … … 357 325 358 326 void owl_global_set_rightshift(owl_global *g, int i) { 359 g->rightshift=i; 327 g->rightshift = i; 328 owl_mainwin_redisplay(owl_global_get_mainwin(g)); 360 329 } 361 330 … … 372 341 owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d); 373 342 374 g->tw = owl_editwin_new(owl_global_get_curs_typwin(g), 343 if (g->typwin_erase_id) { 344 g_signal_handler_disconnect(owl_global_get_typwin_window(g), g->typwin_erase_id); 345 g->typwin_erase_id = 0; 346 } 347 348 g->tw = owl_editwin_new(owl_global_get_typwin_window(g), 375 349 owl_global_get_typwin_lines(g), 376 350 g->cols, … … 385 359 owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d); 386 360 387 werase(owl_global_get_curs_typwin(g)); 361 if (!g->typwin_erase_id) { 362 g->typwin_erase_id = 363 g_signal_connect(owl_global_get_typwin_window(g), "redraw", G_CALLBACK(owl_window_erase_cb), NULL); 364 } 365 owl_window_dirty(owl_global_get_typwin_window(g)); 366 388 367 g->tw = NULL; 389 368 } … … 393 372 void owl_global_set_resize_pending(owl_global *g) { 394 373 g->resizepending=1; 395 }396 397 void owl_global_set_relayout_pending(owl_global *g) {398 g->relayoutpending = 1;399 374 } 400 375 … … 476 451 * fail. 477 452 */ 478 static void _owl_global_get_size(int *lines, int *cols) {453 void owl_global_get_terminal_size(int *lines, int *cols) { 479 454 struct winsize size; 480 455 /* get the new size */ … … 493 468 } 494 469 495 void owl_global_ resize(owl_global *g, int x, int y) {496 /* resize the screen. If x or yis 0 use the terminal size */470 void owl_global_check_resize(owl_global *g) { 471 /* resize the screen. If lines or cols is 0 use the terminal size */ 497 472 if (!g->resizepending) return; 498 473 g->resizepending = 0; 499 474 500 _owl_global_get_size(&g->lines, &g->cols); 501 if (x != 0) { 502 g->lines = x; 503 } 504 if (y != 0) { 505 g->cols = y; 506 } 507 508 resizeterm(g->lines, g->cols); 475 owl_global_get_terminal_size(&g->lines, &g->cols); 476 owl_window_resize(owl_window_get_screen(), g->lines, g->cols); 509 477 510 478 owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols); 511 owl_global_set_relayout_pending(g);512 }513 514 void owl_global_relayout(owl_global *g) {515 owl_popwin *pw;516 owl_viewwin *vw;517 518 if (!g->relayoutpending) return;519 g->relayoutpending = 0;520 521 owl_function_debugmsg("Relayouting...");522 523 /* re-initialize the windows */524 _owl_global_setup_windows(g);525 526 /* in case any styles rely on the current width */527 owl_messagelist_invalidate_formats(owl_global_get_msglist(g));528 529 /* recalculate the topmsg to make sure the current message is on530 * screen */531 owl_function_calculate_topmsg(OWL_DIRECTION_NONE);532 533 /* recreate the popwin */534 pw = owl_global_get_popwin(g);535 if (owl_popwin_is_active(pw)) {536 /*537 * This is somewhat hacky; we probably want a proper windowing layer. We538 * destroy the popwin and recreate it. Then the viewwin is redirected to539 * the new window.540 */541 vw = owl_global_get_viewwin(g);542 owl_popwin_close(pw);543 owl_popwin_up(pw);544 owl_viewwin_set_curswin(vw, owl_popwin_get_curswin(pw),545 owl_popwin_get_lines(pw), owl_popwin_get_cols(pw));546 owl_viewwin_redisplay(vw);547 }548 549 /* refresh stuff */550 g->needrefresh=1;551 owl_mainwin_redisplay(&(g->mw));552 sepbar(NULL);553 if (g->tw)554 owl_editwin_redisplay(g->tw);555 else556 werase(owl_global_get_curs_typwin(g));557 558 owl_function_full_redisplay();559 560 owl_function_makemsg("");561 479 } 562 480 … … 628 546 629 547 void owl_global_set_curmsg_vert_offset(owl_global *g, int i) { 630 g->curmsg_vert_offset =i;548 g->curmsg_vert_offset = i; 631 549 } 632 550 … … 864 782 void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m) 865 783 { 866 owl_list_append_element(&(g->messagequeue), m);784 g_queue_push_tail(g->messagequeue, m); 867 785 } 868 786 … … 875 793 owl_message *out; 876 794 877 if ( owl_list_get_size(&(g->messagequeue))==0) return(NULL);878 out=owl_list_get_element(&(g->messagequeue), 0);879 o wl_list_remove_element(&(g->messagequeue), 0);880 return (out);795 if (g_queue_is_empty(g->messagequeue)) 796 return NULL; 797 out = g_queue_pop_head(g->messagequeue); 798 return out; 881 799 } 882 800 883 801 int owl_global_messagequeue_pending(owl_global *g) 884 802 { 885 if (owl_list_get_size(&(g->messagequeue))==0) return(0); 886 return(1); 803 return !g_queue_is_empty(g->messagequeue); 887 804 } 888 805 … … 1012 929 } 1013 930 1014 const char * owl_global_intern(owl_global *g, const char * string)1015 {1016 return owl_obarray_insert(&(g->obarray), string);1017 }1018 1019 931 owl_list *owl_global_get_io_dispatch_list(owl_global *g) 1020 932 { … … 1043 955 g->interrupted = 0; 1044 956 } 1045 1046 void owl_global_setup_default_filters(owl_global *g)1047 {1048 int i;1049 static const struct {1050 const char *name;1051 const char *desc;1052 } filters[] = {1053 { "personal",1054 "private ^true$ and ( not type ^zephyr$ or "1055 "( class ^message and ( instance ^personal$ or instance ^urgent$ ) ) )" },1056 { "trash",1057 "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" },1058 { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" },1059 { "ping", "opcode ^ping$" },1060 { "auto", "opcode ^auto$" },1061 { "login", "not login ^none$" },1062 { "reply-lockout", "class ^noc or class ^mail$" },1063 { "out", "direction ^out$" },1064 { "aim", "type ^aim$" },1065 { "zephyr", "type ^zephyr$" },1066 { "none", "false" },1067 { "all", "true" },1068 { NULL, NULL }1069 };1070 1071 owl_function_debugmsg("startup: creating default filters");1072 1073 for (i = 0; filters[i].name != NULL; i++)1074 owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name,1075 filters[i].desc));1076 }1077 1078 FILE *owl_global_get_debug_file_handle(owl_global *g) {1079 static char *open_file = NULL;1080 const char *filename = owl_global_get_debug_file(g);1081 if (g->debug_file == NULL ||1082 (open_file && strcmp(filename, open_file) != 0)) {1083 char *path;1084 int fd;1085 1086 if (g->debug_file)1087 fclose(g->debug_file);1088 1089 g->debug_file = NULL;1090 1091 path = owl_sprintf("%s.%d", filename, getpid());1092 fd = open(path, O_CREAT|O_WRONLY|O_EXCL, 0600);1093 owl_free(path);1094 1095 if (fd >= 0)1096 g->debug_file = fdopen(fd, "a");1097 1098 owl_free(open_file);1099 open_file = owl_strdup(filename);1100 }1101 return g->debug_file;1102 }
Note: See TracChangeset
for help on using the changeset viewer.