2000-04-26 04:03:38 -04:00
|
|
|
/*
|
2000-05-04 06:32:42 -04:00
|
|
|
screen.c : irssi
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "signals.h"
|
2000-06-01 19:30:40 -04:00
|
|
|
#include "misc.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
#include "screen.h"
|
|
|
|
#include "gui-readline.h"
|
2000-05-04 06:32:42 -04:00
|
|
|
#include "mainwindows.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#ifndef COLOR_PAIRS
|
|
|
|
#define COLOR_PAIRS 64
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MIN_SCREEN_WIDTH 20
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
static int scrx, scry;
|
|
|
|
static int use_colors;
|
|
|
|
static int freeze_refresh;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-15 17:47:51 -05:00
|
|
|
static int init_screen_int(void);
|
|
|
|
static void deinit_screen_int(void);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
#ifdef SIGWINCH
|
|
|
|
|
|
|
|
static void sig_winch(int p)
|
|
|
|
{
|
2001-01-15 17:47:51 -05:00
|
|
|
#if defined (TIOCGWINSZ) && defined (HAVE_CURSES_RESIZETERM)
|
|
|
|
struct winsize ws;
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
/* Get new window size */
|
|
|
|
if (ioctl(0, TIOCGWINSZ, &ws) < 0)
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
if (ws.ws_row == LINES && ws.ws_col == COLS) {
|
|
|
|
/* Same size, abort. */
|
|
|
|
return;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
if (ws.ws_col < MIN_SCREEN_WIDTH)
|
|
|
|
ws.ws_col = MIN_SCREEN_WIDTH;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
/* Resize curses terminal */
|
|
|
|
resizeterm(ws.ws_row, ws.ws_col);
|
2000-04-26 04:03:38 -04:00
|
|
|
#else
|
2001-01-15 17:47:51 -05:00
|
|
|
deinit_screen_int();
|
|
|
|
init_screen_int();
|
2000-08-10 16:01:32 -04:00
|
|
|
mainwindows_recreate();
|
2000-04-26 04:03:38 -04:00
|
|
|
#endif
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
mainwindows_resize(COLS, LINES);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-06-05 13:38:27 -04:00
|
|
|
static void read_signals(void)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-05-17 07:47:21 -04:00
|
|
|
#ifndef WIN32
|
|
|
|
int signals[] = {
|
|
|
|
SIGHUP, SIGINT, SIGQUIT, SIGTERM,
|
|
|
|
SIGALRM, SIGUSR1, SIGUSR2
|
|
|
|
};
|
|
|
|
char *signames[] = {
|
|
|
|
"hup", "int", "quit", "term",
|
|
|
|
"alrm", "usr1", "usr2"
|
|
|
|
};
|
|
|
|
|
2000-06-01 19:30:40 -04:00
|
|
|
const char *ignores;
|
2001-05-17 07:47:21 -04:00
|
|
|
struct sigaction act;
|
|
|
|
int n;
|
2000-06-01 19:30:40 -04:00
|
|
|
|
|
|
|
ignores = settings_get_str("ignore_signals");
|
2001-05-17 07:47:21 -04:00
|
|
|
|
|
|
|
sigemptyset (&act.sa_mask);
|
|
|
|
act.sa_flags = 0;
|
|
|
|
|
|
|
|
for (n = 0; n < sizeof(signals)/sizeof(signals[0]); n++) {
|
|
|
|
act.sa_handler = find_substr(ignores, signames[n]) ?
|
|
|
|
SIG_IGN : SIG_DFL;
|
|
|
|
sigaction(signals[n], &act, NULL);
|
|
|
|
}
|
2000-11-18 10:32:59 -05:00
|
|
|
#endif
|
2000-06-05 13:38:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void read_settings(void)
|
|
|
|
{
|
2000-07-03 20:44:45 -04:00
|
|
|
int old_colors = use_colors;
|
|
|
|
|
2000-06-05 13:38:27 -04:00
|
|
|
use_colors = settings_get_bool("colors");
|
|
|
|
read_signals();
|
2001-03-14 21:26:12 -05:00
|
|
|
if (use_colors && !has_colors())
|
|
|
|
use_colors = FALSE;
|
|
|
|
|
|
|
|
if (use_colors != old_colors)
|
|
|
|
irssi_redraw();
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-10-08 08:54:26 -04:00
|
|
|
static int init_curses(void)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-05-04 06:32:42 -04:00
|
|
|
char ansi_tab[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
|
|
|
|
int num;
|
2000-11-18 10:32:59 -05:00
|
|
|
#ifndef WIN32
|
2000-10-27 14:37:32 -04:00
|
|
|
struct sigaction act;
|
2000-11-18 10:32:59 -05:00
|
|
|
#endif
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-08 08:54:26 -04:00
|
|
|
if (!initscr())
|
|
|
|
return FALSE;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
if (COLS < MIN_SCREEN_WIDTH)
|
|
|
|
COLS = MIN_SCREEN_WIDTH;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-05-17 07:47:21 -04:00
|
|
|
#ifdef SIGWINCH
|
2000-10-27 14:37:32 -04:00
|
|
|
sigemptyset (&act.sa_mask);
|
|
|
|
act.sa_flags = 0;
|
|
|
|
act.sa_handler = sig_winch;
|
|
|
|
sigaction(SIGWINCH, &act, NULL);
|
2000-10-08 08:54:26 -04:00
|
|
|
#endif
|
2001-05-17 07:24:33 -04:00
|
|
|
raw(); noecho(); idlok(stdscr, 1);
|
2000-04-26 04:03:38 -04:00
|
|
|
#ifdef HAVE_CURSES_IDCOK
|
2000-05-04 06:32:42 -04:00
|
|
|
idcok(stdscr, 1);
|
2000-04-26 04:03:38 -04:00
|
|
|
#endif
|
2001-05-06 15:28:15 -04:00
|
|
|
intrflush(stdscr, FALSE); nodelay(stdscr, TRUE);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-10-08 08:54:26 -04:00
|
|
|
if (has_colors())
|
|
|
|
start_color();
|
2001-03-14 21:26:12 -05:00
|
|
|
else if (use_colors)
|
|
|
|
use_colors = FALSE;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_NCURSES_USE_DEFAULT_COLORS
|
2000-05-04 06:32:42 -04:00
|
|
|
/* this lets us to use the "default" background color for colors <= 7 so
|
|
|
|
background pixmaps etc. show up right */
|
|
|
|
use_default_colors();
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
for (num = 1; num < COLOR_PAIRS; num++)
|
|
|
|
init_pair(num, ansi_tab[num & 7], num <= 7 ? -1 : ansi_tab[num >> 3]);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
init_pair(63, 0, -1); /* hm.. not THAT good idea, but probably more
|
|
|
|
people want dark grey than white on white.. */
|
2000-04-26 04:03:38 -04:00
|
|
|
#else
|
2000-05-04 06:32:42 -04:00
|
|
|
for (num = 1; num < COLOR_PAIRS; num++)
|
|
|
|
init_pair(num, ansi_tab[num & 7], ansi_tab[num >> 3]);
|
|
|
|
init_pair(63, 0, 0);
|
2000-04-26 04:03:38 -04:00
|
|
|
#endif
|
|
|
|
|
2000-10-08 08:54:26 -04:00
|
|
|
clear();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-01-15 17:47:51 -05:00
|
|
|
static int init_screen_int(void)
|
2000-10-08 08:54:26 -04:00
|
|
|
{
|
|
|
|
use_colors = settings_get_bool("colors");
|
|
|
|
read_signals();
|
|
|
|
|
|
|
|
scrx = scry = 0;
|
2000-05-04 06:32:42 -04:00
|
|
|
freeze_refresh = 0;
|
2000-10-08 08:54:26 -04:00
|
|
|
|
2001-01-15 17:47:51 -05:00
|
|
|
return init_curses();
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-15 17:47:51 -05:00
|
|
|
static void deinit_screen_int(void)
|
|
|
|
{
|
|
|
|
endwin();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize screen, detect screen length */
|
|
|
|
int init_screen(void)
|
|
|
|
{
|
|
|
|
settings_add_bool("lookandfeel", "colors", TRUE);
|
|
|
|
settings_add_str("misc", "ignore_signals", "");
|
2000-05-04 06:32:42 -04:00
|
|
|
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
2001-01-15 17:47:51 -05:00
|
|
|
|
|
|
|
return init_screen_int();
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Deinitialize screen */
|
|
|
|
void deinit_screen(void)
|
|
|
|
{
|
2001-01-15 17:47:51 -05:00
|
|
|
deinit_screen_int();
|
2000-05-04 06:32:42 -04:00
|
|
|
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-07-26 19:29:34 -04:00
|
|
|
void set_color(WINDOW *window, int col)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-05-04 06:32:42 -04:00
|
|
|
int attr;
|
|
|
|
|
|
|
|
if (!use_colors)
|
|
|
|
attr = (col & 0x70) ? A_REVERSE : 0;
|
2001-02-10 05:19:47 -05:00
|
|
|
else if (col & ATTR_COLOR8)
|
|
|
|
attr = (A_DIM | COLOR_PAIR(63));
|
|
|
|
else if ((col & 0x77) == 0)
|
|
|
|
attr = A_NORMAL;
|
|
|
|
else
|
|
|
|
attr = (COLOR_PAIR((col&7) + (col&0x70)/2));
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
if (col & 0x08) attr |= A_BOLD;
|
|
|
|
if (col & 0x80) attr |= A_BLINK;
|
|
|
|
|
|
|
|
if (col & ATTR_UNDERLINE) attr |= A_UNDERLINE;
|
|
|
|
if (col & ATTR_REVERSE) attr |= A_REVERSE;
|
|
|
|
|
2000-07-26 19:29:34 -04:00
|
|
|
wattrset(window, attr);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-07-26 19:29:34 -04:00
|
|
|
void set_bg(WINDOW *window, int col)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-05-04 06:32:42 -04:00
|
|
|
int attr;
|
|
|
|
|
|
|
|
if (!use_colors)
|
|
|
|
attr = (col & 0x70) ? A_REVERSE : 0;
|
|
|
|
else {
|
|
|
|
attr = (col == 8) ?
|
|
|
|
(A_DIM | COLOR_PAIR(63)) :
|
|
|
|
(COLOR_PAIR((col&7) + (col&0x70)/2));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (col & 0x08) attr |= A_BOLD;
|
|
|
|
if (col & 0x80) attr |= A_BLINK;
|
|
|
|
|
2000-07-26 19:29:34 -04:00
|
|
|
wbkgdset(window, ' ' | attr);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
void move_cursor(int y, int x)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-05-04 06:32:42 -04:00
|
|
|
scry = y;
|
|
|
|
scrx = x;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void screen_refresh_freeze(void)
|
|
|
|
{
|
2000-05-04 06:32:42 -04:00
|
|
|
freeze_refresh++;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void screen_refresh_thaw(void)
|
|
|
|
{
|
2000-05-04 06:32:42 -04:00
|
|
|
if (freeze_refresh > 0) {
|
|
|
|
freeze_refresh--;
|
2000-07-26 19:29:34 -04:00
|
|
|
if (freeze_refresh == 0) screen_refresh(NULL);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-07-26 19:29:34 -04:00
|
|
|
void screen_refresh(WINDOW *window)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-07-26 19:29:34 -04:00
|
|
|
if (window != NULL)
|
|
|
|
wnoutrefresh(window);
|
2000-05-04 06:32:42 -04:00
|
|
|
if (freeze_refresh == 0) {
|
|
|
|
move(scry, scrx);
|
2000-07-26 19:29:34 -04:00
|
|
|
wnoutrefresh(stdscr);
|
|
|
|
doupdate();
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|