Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Vanilla

Reply
 
Thread Tools Display Modes
Old May 15, 2007, 17:00   #1
CJNyfalt
Swordsman
 
Join Date: May 2007
Posts: 289
CJNyfalt is on a distinguished road
[ALL variants] Getting main-gcu to handle resizes.

I'm working on getting main-gcu.c to handle resizing of the term window. This is for S, but it should be relevant to all variants.

I have made a fair bit of progress, but I'm having some problems.

First, let's take a look at the NCURSES FAQ:
http://invisible-island.net/ncurses/...#handle_resize
Quote:
It is possible to make an application resize when running in a windowing environment (e.g., in an xterm). This is not a feature of standard SVr4 curses, though some curses implementations (e.g., HP-UX) support this.

Within ncurses, there are two ways to accomplish this. One relies on side-effects of the library functions, and is moderately portable. The other is an extension to SVr4 curses.

* endwin/refresh when invoked will briefly exit curses and reinitialize the display, picking up the new screen size. Ncurses will reallocate the WINDOW data (e.g., curscr, stdscr) to reflect the new limits.
* resizeterm can be invoked directly to make ncurses resize its WINDOW data. I use it in my directory editor ded to achieve flicker-free resizing via a signal handler for SIGWINCH. (The documentation for HP-UX curses implies that they use a similar approach; I have been unable to make it work.)

Ncurses 5.0 can be configured to establish its own SIGWINCH hander. In this configuration, the wgetch function will return a special keycode KEY_RESIZE when a resizing event is detected. The signal handler also calls resizeterm (Caveat: malloc and free are not guaranteed to be safe for use in a signal handler).
Now the first approach seems complicated, so I want to focus on the resizeterm one. The Ncurses 5.0 KEY_RESIZE approach seems also limiting because of the strict version requirement.

So, I should need the following:
- A signal handler for SIGWINCH - check.
- Check LINES & COLS for new size - check.
- Call resizeterm to set new size - check.
- Use wresize and Term_resize on the sub-windows - check.

But, it doesn't work!
I suspect that there's something work in the signal code itself, but I'm not sure.
Code:
/*
 * Handle signals -- term resize (SIGWINCH)  -CJN-
 */
static void handle_signal_resize(int sig)
{
	/* Protect errno from library calls in signal handler */
	int save_errno = errno;

	/* Disable handler */
	(void)(*signal_aux)(sig, SIG_IGN);

	/* React to changes */
	(void)Term_xtra(TERM_XTRA_REACT, 0);

	/* Restore handler */
	(void)(*signal_aux)(sig, handle_signal_resize);

	/* Restore errno */
	errno = save_errno;
}
Code:
#ifdef SIGWINCH
	(void)(*signal_aux)(SIGWINCH, handle_signal_resize);
#endif
Does anyone have had problems with the signals? Any hints at all?
CJNyfalt is offline   Reply With Quote
Old May 15, 2007, 17:43   #2
pav
Administrator
 
pav's Avatar
 
Join Date: Apr 2007
Location: Prague, Czech republic
Age: 37
Posts: 773
pav is on a distinguished road
Send a message via ICQ to pav
You need to add these two lines to your signal handler:

endwin();
refresh();

before you call off to Angband code. This will tell ncurses to reinit the screen and update it's idea of terminal dimensions. It got some screen flicker, but it works!
__________________
See the elves and everything! http://angband.oook.cz
pav is offline   Reply With Quote
Old May 15, 2007, 19:59   #3
Diego Gonzalez
Rookie
 
Join Date: May 2007
Posts: 23
Diego Gonzalez is on a distinguished road
I had the same problem when I was writing a Telnet client. Try with this

Code:
void handleSIGWINCH(int sig) 
{
        struct winsize ws;

        if (ioctl(1, TIOCGWINSZ, &ws) == -1)
        {
                perror("ioctl");
                return;
        }

        resize_term(ws.ws_row, ws.ws_col);
}
Diego Gonzalez is offline   Reply With Quote
Old May 15, 2007, 20:28   #4
pav
Administrator
 
pav's Avatar
 
Join Date: Apr 2007
Location: Prague, Czech republic
Age: 37
Posts: 773
pav is on a distinguished road
Send a message via ICQ to pav
Quote:
Originally Posted by Diego Gonzalez View Post
I had the same problem when I was writing a Telnet client. Try with this

Code:
void handleSIGWINCH(int sig) 
{
        struct winsize ws;

        if (ioctl(1, TIOCGWINSZ, &ws) == -1)
        {
                perror("ioctl");
                return;
        }

        resize_term(ws.ws_row, ws.ws_col);
}
How portable is this ioctl interface?

Tried it, same screen flicker as my method, so I'm not switching
__________________
See the elves and everything! http://angband.oook.cz
pav is offline   Reply With Quote
Old May 17, 2007, 10:54   #5
CJNyfalt
Swordsman
 
Join Date: May 2007
Posts: 289
CJNyfalt is on a distinguished road
Thanks for the help. However that doesn't fix the problem. I suspect that there's a bug somewhere in the general signnal handling code in Sangband.
I have had enough on working on the problem, and takes a break from it.
CJNyfalt is offline   Reply With Quote
Old May 27, 2007, 14:47   #6
CJNyfalt
Swordsman
 
Join Date: May 2007
Posts: 289
CJNyfalt is on a distinguished road
Quote:
Originally Posted by CJNyfalt View Post
Thanks for the help. However that doesn't fix the problem. I suspect that there's a bug somewhere in the general signnal handling code in Sangband.
I have had enough on working on the problem, and takes a break from it.
There's a version of main-gcu with my effort on writing the resize code in the latest Sangband in the src/unix directory, if someone wants to take a look at the effort, and hopefully figure out what's went wrong.
CJNyfalt is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 23:59.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.