4 Copyright (C) 2001 Timo Sirainen
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "mainwindows.h"
29 #ifdef HAVE_NL_LANGINFO
31 # include <langinfo.h>
34 #ifdef HAVE_SYS_IOCTL_H
35 # include <sys/ioctl.h>
40 #define MIN_SCREEN_WIDTH 20
42 int term_width, term_height, term_detached;
47 static int force_colors;
48 static int resize_dirty;
50 int term_get_size(int *width, int *height)
55 /* Get new window size */
56 if (ioctl(0, TIOCGWINSZ, &ws) < 0)
59 if (ws.ws_row == 0 && ws.ws_col == 0)
65 if (*width < MIN_SCREEN_WIDTH)
66 *width = MIN_SCREEN_WIDTH;
75 /* Resize the terminal if needed */
76 void term_resize_dirty(void)
85 if (!term_get_size(&width, &height))
88 if (height != term_height || width != term_width) {
89 term_resize(width, height);
90 mainwindows_resize(term_width, term_height);
91 term_resize_final(width, height);
96 static void sig_winch(int p)
103 static void cmd_resize(void)
109 static void read_settings(void)
112 int old_colors = term_use_colors;
113 int old_type = term_type;
115 term_auto_detach(settings_get_bool("term_auto_detach"));
117 /* set terminal type */
118 str = settings_get_str("term_type");
119 if (g_strcasecmp(str, "utf-8") == 0)
120 term_type = TERM_TYPE_UTF8;
121 else if (g_strcasecmp(str, "big5") == 0)
122 term_type = TERM_TYPE_BIG5;
124 term_type = TERM_TYPE_8BIT;
126 if (old_type != term_type)
127 term_set_input_type(term_type);
129 /* change color stuff */
130 if (force_colors != settings_get_bool("term_force_colors")) {
131 force_colors = settings_get_bool("term_force_colors");
132 term_force_colors(force_colors);
135 term_use_colors = settings_get_bool("colors") &&
136 (force_colors || term_has_colors());
138 if (term_use_colors != old_colors)
142 void term_common_init(void)
145 struct sigaction act;
147 settings_add_bool("lookandfeel", "colors", TRUE);
148 settings_add_bool("lookandfeel", "term_force_colors", FALSE);
149 settings_add_bool("lookandfeel", "term_auto_detach", FALSE);
150 settings_add_bool("lookandfeel", "mirc_blink_fix", FALSE);
151 settings_add_str("lookandfeel", "term_type", "8bit");
153 force_colors = FALSE;
154 term_use_colors = term_has_colors() && settings_get_bool("colors");
157 #if defined (HAVE_NL_LANGINFO) && defined(CODESET)
158 setlocale(LC_CTYPE, "");
159 if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0) {
160 term_type = TERM_TYPE_UTF8;
161 term_set_input_type(TERM_TYPE_UTF8);
165 signal_add("beep", (SIGNAL_FUNC) term_beep);
166 signal_add("setup changed", (SIGNAL_FUNC) read_settings);
167 command_bind("resize", NULL, (SIGNAL_FUNC) cmd_resize);
170 sigemptyset (&act.sa_mask);
172 act.sa_handler = sig_winch;
173 sigaction(SIGWINCH, &act, NULL);
177 void term_common_deinit(void)
179 command_unbind("resize", (SIGNAL_FUNC) cmd_resize);
180 signal_remove("beep", (SIGNAL_FUNC) term_beep);
181 signal_remove("setup changed", (SIGNAL_FUNC) read_settings);