An example code of another way to code main-xxx.c ------------------------------------------------- main-gtk.c by Robert Ruehlmann (rr9@angband.org) event handling code by pelpel (kazuo@sta.att.ne.jp) (On this file) This is NOT intended to be a replacement or improvement to main-gtk.c in Angband 2.9.3, but an illustration of another possible way to code main-xxx.c for event-callback based APIs, such as GTK+, Xt, Carbon Event Manager, and virtually all class libraries. I took main-gtk.c because it's the simplest of all, the GTK+ documents is freely and easily accessible, and above all, GTK programs are very readable unlike most window system APIs... It doesn't make any explicit calls to poll events, but let the main event loop function do that for you. A bonus of this approach is that the game blocks whenever appropriate on a multitasking environment. The basic idea is that callbacks call game's current context after performing main-xxx level actions. Since C doesn't have syntactical support for doing this, I used two cooperative threads, one for main and the other for game, again, implemented in open and well-documented pthread interface. Modal dialogues are always tricky, and they require suspension of game thread's execution. Please pay close attention to the use of the flags dont_yield_to_game and wait_for_event... (Misc modifications that can go into the real main-gtk.c) Since I don't have very modern ix86 machines, I also made it work on 8bpp X servers, without sacrificing colour accuracy on better video cards. In doing so, a support for the gamma correction code is brought in as well... Somewhat related to this, I removed pixmap's attached to each window and made update handling code similar to those in main-win.c and main-mac.c... // pelpel (kazuo@sta.att.ne.jp)