3
* Kevin P. Smith 6/11/89 Much modified by Jerry Frain and Joe Young
15
#include INC_SYS_SELECT
18
#include <X11/Xutil.h>
19
#include <X11/cursorfont.h>
20
#include <X11/Xatom.h>
21
#include <X11/keysym.h>
25
#include INC_SYS_TIMEB
30
#include "teams.bitmap"
31
#include "mapcursor.bitmap"
32
#include "localcursor.bitmap"
35
#include "x11window.h"
36
#include "x11sprite.h"
39
extern void terminate(int error);
43
#define MAX_TEXT_WIDTH 100
45
/* changes too good to risk leaving out, by Richard Caley (rjc@cstr.ed.ac.uk) */
46
/* Was #ifdef RJC, but now they're just part of the code */
49
#define NORMAL_FONT "5x7"
50
#define BOLD_FONT "5x7"
51
#define ITALIC_FONT "5x7"
52
#define IND_FONT "5x7"
54
#define NORMAL_FONT "6x10"
55
#define BOLD_FONT "-*-clean-bold-r-normal--10-100-75-75-c-60-*"
56
#define ITALIC_FONT "-*-clean-bold-r-normal--10-100-75-75-c-60-*"
57
#define IND_FONT "-*-clean-bold-r-normal--10-100-75-75-c-60-*"
60
#define BIG_FONT "-*-lucidatypewriter-*-*-*-*-40-*-*-*-*-*-*-*"
65
#define TTS_FONT "10x20"
66
extern void init_tts(void);
70
#define G_SET_WIDTH 0x1
71
#define G_SET_HEIGHT 0x2
76
static char *_nfonts[] =
79
"-*-clean-medium-r-normal--10-100-75-75-c-60-*",
83
static char *_bfonts[] =
86
"-*-clean-bold-r-normal--10-100-75-75-c-60-*",
90
static char *_ifonts[] =
93
"-*-clean-bold-r-normal--10-100-75-75-c-60-*",
97
static char *_bgfonts[] =
104
XFontStruct *find_font(char *oldf, char **fonts);
133
#define RaceDefaultOffset (C_ROM - RED)
135
extern int takeNearest;
140
static int three = 3;
150
W_Font W_BigFont = (W_Font) & zero, W_RegularFont = (W_Font) & one;
151
W_Font W_HighlightFont = (W_Font) & two, W_UnderlineFont = (W_Font) & three;
153
W_Color W_White = WHITE, W_Black = BLACK, W_Red = RED, W_Green = GREEN;
154
W_Color W_Yellow = YELLOW, W_Cyan = CYAN, W_Grey = GREY;
157
W_Color W_Ind = C_IND, W_Fed = C_FED, W_Rom = C_ROM, W_Kli = C_KLI, W_Ori = C_ORI;
160
int W_BigTextwidth, W_BigTextheight, W_Textwidth, W_Textheight;
161
char *getdefault(char *str);
163
int W_in_message = 0; /* jfy -- for Jerry's warp *
169
/* TTS: moved this out so we can use the 8th color */
171
static unsigned long planes[PLANES];
173
/* Scrollable message windows */
174
#define SCROLL_THUMB_WIDTH 5
175
static int scrollbar = 1;
176
static int scroll_thumb_width = SCROLL_THUMB_WIDTH;
177
static GC scroll_thumb_gc;
178
static Pixmap scroll_thumb_pixmap;
179
static int scroll_lines = 100; /* save 100 lines */
181
Atom wm_protocols, wm_delete_window;
183
extern W_Window baseWin;
184
static XClassHint class_hint =
189
static XWMHints wm_hint =
191
InputHint | StateHint,
206
static W_Event W_myevent;
207
static int W_isEvent = 0;
217
GC contexts[FONTS + 1];
218
GC insens_contexts[FONTS + 1];
238
static void changeMenuItem(struct window *win, int col, int n, char *str, W_Color color);
239
static void scrollUp(struct window *win, int y);
240
static void scrollDown(struct window *win, int y);
241
static void scrollPosition(struct window *win, int y);
242
static void scrollTo(struct window *win, struct scrollingWindow *sw, int topline);
243
static void scrollScrolling(W_Event * wevent);
244
static void configureScrolling(struct window *win, int x, int y, int width, int height);
245
static void AddToScrolling(struct window *win, W_Color color, W_Font font, char *str, int len);
246
static void drawThumb(struct window *win, struct scrollingWindow *sw);
247
static void redrawScrolling(struct window *win);
248
static int checkGeometry(char *name, int *x, int *y, int *width, int *height);
252
char string[MAX_TEXT_WIDTH];
255
struct stringList *next, *prev;
265
struct colors colortable[] =
288
struct window *window;
289
struct windowlist *next;
293
#define hash(x) (((int) (x)) % HASHSIZE)
295
struct windowlist *hashtable[HASHSIZE];
296
struct fontInfo fonts[FONTS];
298
struct window *newWindow(Window window, int type);
299
struct window *findWindow(Window window);
301
/* char *malloc (size_t); */
302
short *x11tox10bits();
304
struct window myroot;
306
#define NCOLORS (sizeof(colortable)/sizeof(colortable[0]))
307
#define W_Void2Window(win) ((win) ? ((struct window *) (win)) : (&myroot))
308
#define W_Window2Void(window) ((W_Window) (window))
309
#define W_Void2Icon(bit) ((struct icon *) (bit))
310
#define W_Icon2Void(bit) ((W_Icon) (bit))
311
#define fontNum(font) (*((int *) font))
314
#define WIN_EDGE 5 /* border on l/r edges of *
316
#define MENU_PAD 6 /* border on t/b edges of *
318
#define MENU_BAR 1 /* width of menu bar */
322
0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55,
323
0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55,
324
0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55,
325
0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55
328
static char striped[] =
330
0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
331
0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f,
332
0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00,
333
0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0
336
static char solid[] =
338
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
339
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
340
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
341
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
344
int full_screen_default, full_screen_enabled;
347
static void video_mode_off(void);
348
static int video_mode_initialise(void);
349
static void video_mode_on(void);
350
static void view_port_warp(W_Window window);
351
static void pointer_grab_on(W_Window window);
352
static void pointer_grab_off(W_Window window);
353
static void kde_fullscreen_on(W_Window window);
354
static void kde_fullscreen_off(W_Window window);
359
_myerror(Display * d, XErrorEvent * e)
361
fprintf(stderr, "netrek: x11window: _myerror\n");
365
void pastebuffer(void)
370
buff = XFetchBuffer(W_Display, &nbytes, 0);
371
for (x = 0; x < nbytes; x++)
379
WMXYHintMode_default(void)
381
static int fetched = 0;
382
static long WMXYHM_default;
383
char *hm_default_string;
387
hm_default_string = getdefault("WMXYHintMode");
388
if (!hm_default_string || strcmp(hm_default_string, "USPosition") == 0)
389
WMXYHM_default = USPosition;
391
WMXYHM_default = PPosition;
394
return WMXYHM_default;
399
W_Initialize(char *str)
404
printf("Initializing...\n");
407
for (i = 0; i < HASHSIZE; i++)
411
if ((W_Display = XOpenDisplay(str)) == NULL)
413
fprintf(stderr, "I can't open your display, twink!\n");
417
/* prevent X socket from being copied to forked exec'd process */
418
if (fcntl(ConnectionNumber(W_Display), F_SETFD, FD_CLOEXEC) < 0)
420
fprintf(stderr, "failed to set the X socket to close on exec(),\n"
421
"fcntl F_SETFD FD_CLOEXEC failure,\n'%s'",
425
// uncomment this to synchronise display for testing
426
// XSynchronize(W_Display, True);
428
// uncomment this to enable a fatal error handler
429
// XSetErrorHandler(_myerror);
431
wm_protocols = XInternAtom(W_Display, "WM_PROTOCOLS", False);
432
wm_delete_window = XInternAtom(W_Display, "WM_DELETE_WINDOW", False);
434
W_Root = DefaultRootWindow(W_Display);
435
W_Visual = DefaultVisual(W_Display, DefaultScreen(W_Display));
436
W_Screen = DefaultScreen(W_Display);
437
W_Colormap = DefaultColormap(W_Display, W_Screen);
438
myroot.window = W_Root;
439
myroot.type = WIN_GRAPH;
444
GetPixmaps(W_Display, &myroot);
447
/* display scroll thumb */
448
scrollbar = booleanDefault("ScrollBar", scrollbar);
449
scroll_lines = intDefault("ScrollSaveLines", scroll_lines);
450
scroll_thumb_width = intDefault("ScrollBarWidth", scroll_thumb_width);
455
W_FullScreenInitialise();
458
/* Make sure the font will work, ie: that it fits in the 6x10 character cell
460
void checkFont(XFontStruct * fontinfo, char *fontname)
464
if (fontinfo->max_bounds.width != 6 ||
465
fontinfo->min_bounds.width != 6 ||
466
fontinfo->descent + fontinfo->ascent != 10 ||
467
fontinfo->min_bounds.lbearing < 0 ||
468
fontinfo->max_bounds.rbearing > 6 ||
469
fontinfo->max_bounds.ascent > 8 ||
470
fontinfo->max_bounds.descent > 2)
472
fprintf(stderr, "Warning: font '%s'\ndoes not conform to 6x10 character cell rules.\n", fontname);
479
Font regular, italic, bold, big;
482
XFontStruct *fontinfo;
486
fontname = getdefault("font");
487
if (fontname == NULL)
488
fontname = NORMAL_FONT;
489
fontinfo = XLoadQueryFont(W_Display, fontname);
490
if (fontinfo == NULL)
492
fontinfo = find_font(fontname, _nfonts);
494
if (fontinfo == NULL)
496
printf("netrek: Can't find any fonts!\n");
499
checkFont(fontinfo, fontname);
500
regular = fontinfo->fid;
501
W_Textwidth = fontinfo->max_bounds.width;
502
W_Textheight = fontinfo->max_bounds.descent + fontinfo->max_bounds.ascent;
503
fonts[1].baseline = fontinfo->max_bounds.ascent;
505
fontname = getdefault("boldfont");
506
if (fontname == NULL)
507
fontname = BOLD_FONT;
508
fontinfo = XLoadQueryFont(W_Display, fontname);
509
if (fontinfo == NULL)
511
fontinfo = find_font(fontname, _bfonts);
513
if (fontinfo == NULL)
516
fonts[2].baseline = fonts[1].baseline;
520
checkFont(fontinfo, fontname);
521
bold = fontinfo->fid;
522
fonts[2].baseline = fontinfo->max_bounds.ascent;
523
if (fontinfo->max_bounds.width > W_Textwidth)
524
W_Textwidth = fontinfo->max_bounds.width;
525
if (fontinfo->max_bounds.descent + fontinfo->max_bounds.ascent > W_Textheight)
526
W_Textheight = fontinfo->max_bounds.descent + fontinfo->max_bounds.ascent;
529
fontname = getdefault("italicfont");
530
if (fontname == NULL)
531
fontname = ITALIC_FONT;
532
fontinfo = XLoadQueryFont(W_Display, fontname);
533
if (fontinfo == NULL)
535
fontinfo = find_font(fontname, _ifonts);
537
if (fontinfo == NULL)
540
fonts[3].baseline = fonts[1].baseline;
544
checkFont(fontinfo, fontname);
545
italic = fontinfo->fid;
546
fonts[3].baseline = fontinfo->max_bounds.ascent;
547
if (fontinfo->max_bounds.width > W_Textwidth)
548
W_Textwidth = fontinfo->max_bounds.width;
549
if (fontinfo->max_bounds.descent + fontinfo->max_bounds.ascent > W_Textheight)
550
W_Textheight = fontinfo->max_bounds.descent + fontinfo->max_bounds.ascent;
553
fontname = getdefault("bigfont");
554
if (fontname == NULL)
556
fontinfo = XLoadQueryFont(W_Display, fontname);
557
if (fontinfo == NULL)
559
fontinfo = find_font(fontname, _bgfonts);
561
if (fontinfo == NULL)
564
fonts[0].baseline = fonts[1].baseline;
565
W_BigTextwidth = W_Textwidth;
566
W_BigTextheight = W_Textheight;
571
fonts[0].baseline = fontinfo->max_bounds.ascent;
572
W_BigTextwidth = fontinfo->max_bounds.width;
573
W_BigTextheight = fontinfo->max_bounds.descent + fontinfo->max_bounds.ascent;
575
white = WhitePixel(W_Display, W_Screen);
576
black = BlackPixel(W_Display, W_Screen);
577
insens_tile = XCreatePixmapFromBitmapData(W_Display, W_Root, gray,
578
TILESIDE, TILESIDE, black, white, DefaultDepth(W_Display, W_Screen));
579
for (i = 0; i < NCOLORS; i++)
582
colortable[i].contexts[0] = XCreateGC(W_Display, W_Root, GCFont, &values);
583
XSetGraphicsExposures(W_Display, colortable[i].contexts[0], False);
584
values.font = regular;
585
colortable[i].contexts[1] = XCreateGC(W_Display, W_Root, GCFont, &values);
586
XSetGraphicsExposures(W_Display, colortable[i].contexts[1], False);
588
values.fill_style = FillTiled;
589
values.tile = insens_tile;
590
colortable[i].insens_contexts[1] = XCreateGC(W_Display, W_Root,
591
GCFont | GCFillStyle | GCTile, &values);
592
XSetGraphicsExposures(W_Display, colortable[i].insens_contexts[1],
595
colortable[i].contexts[2] = XCreateGC(W_Display, W_Root, GCFont, &values);
596
XSetGraphicsExposures(W_Display, colortable[i].contexts[2], False);
597
values.font = italic;
598
colortable[i].contexts[3] = XCreateGC(W_Display, W_Root, GCFont, &values);
599
XSetGraphicsExposures(W_Display, colortable[i].contexts[3], False);
603
XSetLineAttributes(W_Display, colortable[i].contexts[3],
604
0, LineOnOffDash, CapButt, JoinMiter);
605
XSetDashes(W_Display, colortable[i].contexts[3], 0, dl, 2);
607
values.function = GXor;
608
colortable[i].contexts[BITGC] = XCreateGC(W_Display, W_Root, GCFunction,
610
XSetGraphicsExposures(W_Display, colortable[i].contexts[BITGC], False);
614
find_font(char *oldf, char **fonts)
619
fprintf(stderr, "netrek: Can't find font %s. Trying others...\n",
621
for (f = fonts; *f; f++)
623
if (strcmp(*f, oldf) != 0)
625
if ((fi = XLoadQueryFont(W_Display, *f)))
632
static unsigned short extrared[COLORS] =
633
{0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xb0, 0xc0};
634
static unsigned short extragreen[COLORS] =
635
{0x40, 0x60, 0x80, 0xa0, 0xb0, 0xc0, 0x00, 0x20};
636
static unsigned short extrablue[COLORS] =
637
{0x80, 0xa0, 0xb0, 0xc0, 0x00, 0x20, 0x40, 0x60};
647
char defaultstring[100];
649
unsigned long extracolors[COLORS];
653
forceMono = booleanDefault("forcemono", forceMono); /* 11/14/91 TC */
655
if ((DisplayCells(W_Display, W_Screen) <= 2) || forceMono)
657
white = WhitePixel(W_Display, W_Screen);
658
black = BlackPixel(W_Display, W_Screen);
659
for (i = 0; i < NCOLORS; i++)
663
colortable[i].pixelValue = white;
667
colortable[i].pixelValue = black;
671
colortable[i].pixmap = XCreatePixmapFromBitmapData(W_Display,
672
W_Root, striped, TILESIDE, TILESIDE, white, black,
673
DefaultDepth(W_Display, W_Screen));
675
else if (i == W_Yellow)
677
colortable[i].pixmap = XCreatePixmapFromBitmapData(W_Display,
678
W_Root, gray, TILESIDE, TILESIDE, white, black,
679
DefaultDepth(W_Display, W_Screen));
683
colortable[i].pixmap = XCreatePixmapFromBitmapData(W_Display,
684
W_Root, solid, TILESIDE, TILESIDE,
685
colortable[i].pixelValue,
686
colortable[i].pixelValue,
687
DefaultDepth(W_Display, W_Screen));
689
/* We assume white is 0 or 1, and black is 0 or 1. We adjust * *
690
* graphics function based upon who is who. */
693
XSetFunction(W_Display, colortable[i].contexts[BITGC],
698
else if (W_Visual->class == PseudoColor)
700
if (!XAllocColorCells(W_Display, W_Colormap, False, planes, PLANES,
701
&pixel, 1) && !takeNearest)
703
/* couldn't allocate 3 planes, make a new colormap */
704
W_Colormap = XCreateColormap(W_Display, W_Root, W_Visual, AllocNone);
706
if (!XAllocColorCells(W_Display, W_Colormap, False, planes, PLANES,
709
fprintf(stderr, "Cannot create new colormap\n");
712
/* and fill it with at least 8 more colors so when mouse is inside
713
* * * netrek windows, use might be able to see his other windows */
714
if (XAllocColorCells(W_Display, W_Colormap, False, NULL, 0,
715
extracolors, COLORS))
717
colordef.flags = DoRed | DoGreen | DoBlue;
719
for (i = 0; i < COLORS; i++)
721
colordef.pixel = extracolors[i];
722
colordef.red = extrared[i] << 8;
723
colordef.green = extragreen[i] << 8;
724
colordef.blue = extrablue[i] << 8;
725
XStoreColor(W_Display, W_Colormap, &colordef);
730
for (i = 0; i < NCOLORS; i++)
732
sprintf(defaultstring, "color.%s", colortable[i].name);
733
defaults = getdefault(defaultstring);
735
if (defaults == NULL)
741
/* The default colour from the ROMS is the colour defined *
743
* * to be RED and not the colour which is actually RED. */
745
sprintf(defaultstring, "color.%s",
746
colortable[i - RaceDefaultOffset].name);
747
defaults = getdefault(defaultstring);
749
if (defaults == NULL)
750
defaults = colortable[i - RaceDefaultOffset].name;
755
defaults = colortable[i].name;
758
XParseColor(W_Display, W_Colormap, defaults, &foo);
765
foo.pixel = pixel | planes[0] | planes[1] | planes[2];
771
foo.pixel = pixel | planes[0];
774
foo.pixel = pixel | planes[1];
777
foo.pixel = pixel | planes[2];
780
foo.pixel = pixel | planes[0] | planes[1];
783
foo.pixel = pixel | planes[1] | planes[2];
787
* Choose colors so that when two ships overlap, things look
788
* ok. When players overlab, the bits are ORed together. */
790
/* Background color */
795
/* Alert colors (sum to grey usually) */
797
foo.pixel = pixel | planes[1] | planes[2];
800
foo.pixel = pixel | planes[1] | planes[3];
803
foo.pixel = pixel | planes[2] | planes[3];
806
foo.pixel = pixel | planes[1];
809
foo.pixel = pixel | planes[1] | planes[2] | planes[3];
814
foo.pixel = pixel | planes[0];
817
/* The color of other ships should dominate over your color * *
818
* and should sum to C_IND where possible. */
820
foo.pixel = pixel | planes[0] | planes[1] | planes[2];
823
foo.pixel = pixel | planes[0] | planes[1] | planes[3];
826
foo.pixel = pixel | planes[0] | planes[2] | planes[3];
829
foo.pixel = pixel | planes[0] | planes[1];
832
foo.pixel = pixel | planes[0] | planes[1] | planes[2] | planes[3];
837
XAllocColor(W_Display, W_Colormap, &foo);
839
XStoreColor(W_Display, W_Colormap, &foo);
840
colortable[i].pixelValue = foo.pixel;
841
colortable[i].pixmap = XCreatePixmapFromBitmapData(W_Display,
842
W_Root, solid, TILESIDE, TILESIDE, foo.pixel, foo.pixel,
843
DefaultDepth(W_Display, W_Screen));
846
else if (W_Visual->class >= TrueColor)
848
/* Stuff added by sheldon@iastate.edu 5/28/93 This is supposed to * *
849
* detect a TrueColor display, and then do a lookup of the colors in *
850
* * default colormap, instead of creating new colormap. */
851
for (i = 0; i < NCOLORS; i++)
853
sprintf(defaultstring, "color.%s", colortable[i].name);
855
defaults = getdefault(defaultstring);
856
if (defaults == NULL)
862
/* The default color from the ROMS is the color defined to
863
* * * be RED and not the color which is actually RED. */
865
sprintf(defaultstring, "color.%s",
866
colortable[i - RaceDefaultOffset].name);
867
defaults = getdefault(defaultstring);
869
if (defaults == NULL)
870
defaults = colortable[i - RaceDefaultOffset].name;
875
defaults = colortable[i].name;
879
XParseColor(W_Display, W_Colormap, defaults, &foo);
880
XAllocColor(W_Display, W_Colormap, &foo);
881
colortable[i].pixelValue = foo.pixel;
882
colortable[i].pixmap = XCreatePixmapFromBitmapData(W_Display,
883
W_Root, solid, TILESIDE, TILESIDE, foo.pixel, foo.pixel,
884
DefaultDepth(W_Display, W_Screen));
890
fprintf(stderr, "Don't know how to deal with a Class %d Visual\n",
892
fprintf(stderr, "Your X server is not supported at %d bpp!\n",
893
DefaultDepth(W_Display, W_Screen));
896
for (i = 0; i < NCOLORS; i++)
898
for (j = 0; j < FONTS + 1; j++)
900
XSetForeground(W_Display, colortable[i].contexts[j],
901
colortable[i].pixelValue);
902
XSetBackground(W_Display, colortable[i].contexts[j],
903
colortable[W_Black].pixelValue);
909
scroll_thumb_pixmap = XCreatePixmapFromBitmapData(W_Display,
910
W_Root, gray, TILESIDE, TILESIDE,
911
colortable[W_White].pixelValue,
912
colortable[W_Black].pixelValue,
913
DefaultDepth(W_Display, W_Screen));
915
values.fill_style = FillTiled;
916
values.tile = scroll_thumb_pixmap;
918
scroll_thumb_gc = XCreateGC(W_Display, W_Root,
919
GCFillStyle | GCTile, &values);
923
void W_RenameWindow(W_Window window, char *str)
925
struct window *win = W_Void2Window(window);
926
XStoreName(W_Display, win->window, str);
930
W_MakeWindow(char *name, int x, int y, int width, int height, W_Window parent, int border, W_Color color)
932
struct window *newwin;
934
XSetWindowAttributes attrs;
935
char *window_title = "Netrek", title_buff[257];
936
XSizeHints *sz_hints;
940
printf("New window...\n");
943
gcheck_result = checkGeometry(name, &x, &y, &width, &height);
944
/* printf("%s.geometry: %d %d %d %d %d\n", name, x, y, width, height, *
946
checkParent(name, &parent);
947
wparent = W_Void2Window(parent)->window;
948
attrs.border_pixel = colortable[color].pixelValue;
949
attrs.event_mask = KeyPressMask | ButtonPressMask | ExposureMask | LeaveWindowMask;
952
attrs.event_mask |= KeyReleaseMask;
956
attrs.event_mask |= ButtonMotionMask;
958
// if (!strcmp(name, "netrek")) {
959
// attrs.event_mask |= StructureNotifyMask;
963
if (strcmp(name, "netrek_icon") == 0) /* icon should not select *
965
attrs.event_mask = ExposureMask;
966
attrs.background_pixel = colortable[W_Black].pixelValue;
967
attrs.do_not_propagate_mask = KeyPressMask | ButtonPressMask | ExposureMask;
969
XCreateWindow(W_Display, wparent, x, y, width, height, border,
970
CopyFromParent, InputOutput, CopyFromParent,
971
CWBackPixel | CWEventMask |
976
if (!strcmp(name, "netrek")) {
977
if (full_screen_enabled) {
979
kde_fullscreen_on(W_Window2Void(newwin));
985
sz_hints = XAllocSizeHints();
986
if (strcmp(name, "netrek") == 0 || strcmp(name, "wait") == 0 ||
987
strcmp(name, "waitmotd") == 0)
989
if (!title && serverName)
991
if (strcmp(name, "wait") == 0)
992
strcpy(title_buff, serverName);
993
else if (strcmp(name, "waitmotd") == 0)
994
strcpy(title_buff, "Motd-[f]forward, [b]back, [space]unmap");
996
sprintf(title_buff, "Netrek @ %s", serverName);
997
window_title = title_buff;
1000
/* but title on command line will override */ if (title)
1001
window_title = title;
1002
sz_hints->min_width = width;
1003
sz_hints->max_width = width;
1004
sz_hints->min_height = height;
1005
sz_hints->max_height = height;
1006
sz_hints->flags = PMinSize | PMaxSize;
1008
#ifndef SMALL_SCREEN
1009
/* remove this check for SMALL_SCREEN;
1010
* otherwise root window may not be aligned with upper-left corner of screen */
1011
if (gcheck_result & G_SET_X || gcheck_result & G_SET_Y)
1014
sz_hints->flags |= WMXYHintMode_default();
1018
window_title = name;
1019
if (gcheck_result & G_SET_X || gcheck_result & G_SET_Y)
1020
sz_hints->flags |= WMXYHintMode_default();
1022
XStoreName(W_Display, newwin->window, window_title);
1023
XSetWMNormalHints(W_Display, newwin->window, sz_hints);
1024
class_hint.res_name = name;
1025
XSetClassHint(W_Display, newwin->window, &class_hint);
1026
XSetWMHints(W_Display, newwin->window, &wm_hint);
1028
if (wparent == W_Root && baseWin != NULL && strcmp(name, "wait") != 0
1029
&& strcmp(name, "waitmotd") != 0)
1030
XSetTransientForHint(W_Display, newwin->window, W_Void2Window(baseWin)->window);
1031
newwin->name = strdup(name);
1032
newwin->width = width;
1033
newwin->height = height;
1034
if (wparent != W_Root)
1035
if (checkMapped(name))
1036
W_MapWindow(W_Window2Void(newwin));
1039
printf("New graphics window %d, child of %d\n", newwin, parent);
1042
XSetWindowColormap(W_Display, newwin->window, W_Colormap);
1043
return W_Window2Void(newwin);
1047
W_ChangeBorder(W_Window window, int color)
1051
printf("Changing border of %d\n", window);
1054
/* fix inexplicable color bug */
1055
if ((DisplayCells(W_Display, W_Screen) <= 2) || forceMono)
1057
XSetWindowBorderPixmap(W_Display, W_Void2Window(window)->window,
1058
colortable[color].pixmap);
1060
XSetWindowBorder(W_Display, W_Void2Window(window)->window,
1061
colortable[color].pixelValue);
1067
W_MapWindow(W_Window window)
1072
printf("Mapping %d\n", window);
1075
win = W_Void2Window(window);
1079
XMapRaised(W_Display, win->window);
1083
W_UnmapWindow(W_Window window)
1088
printf("UnMapping %d\n", window);
1091
win = W_Void2Window(window);
1092
if (win->mapped == 0)
1095
XUnmapWindow(W_Display, win->window);
1099
W_IsMapped(W_Window window)
1103
win = W_Void2Window(window);
1110
W_FillArea(W_Window window, int x, int y, int width, int height, W_Color color)
1115
printf("Clearing (%d %d) x (%d %d) with %d on %d\n", x, y, width, height,
1119
win = W_Void2Window(window);
1123
XFillRectangle(W_Display, win->window, colortable[color].contexts[0],
1124
x, y, width, height);
1127
XFillRectangle(W_Display, win->window, colortable[color].contexts[0],
1128
WIN_EDGE + x * W_Textwidth,
1129
MENU_PAD + y * W_Textheight,
1130
width * W_Textwidth, height * W_Textheight);
1133
XFillRectangle(W_Display, win->window, colortable[color].contexts[0],
1134
WIN_EDGE + x * W_Textwidth, MENU_PAD + y * W_Textheight,
1135
width * W_Textwidth, height * W_Textheight);
1141
static XRectangle _rcache[MAXCACHE];
1142
static int _rcache_index;
1145
FlushClearAreaCache(Window win)
1147
XFillRectangles(W_Display, win, colortable[backColor].contexts[0],
1148
_rcache, _rcache_index);
1152
/* local window only */
1154
W_CacheClearArea(W_Window window, int x, int y, int width, int height)
1156
Window win = W_Void2Window(window)->window;
1157
register XRectangle *r;
1159
if (_rcache_index == MAXCACHE)
1160
FlushClearAreaCache(win);
1162
r = &_rcache[_rcache_index++];
1165
r->width = (unsigned short) width;
1166
r->height = (unsigned short) height;
1170
W_FlushClearAreaCache(W_Window window)
1172
Window win = W_Void2Window(window)->window;
1175
FlushClearAreaCache(win);
1178
/* XFIX: clears now instead of filling. */
1180
W_ClearArea(W_Window window, int x, int y, int width, int height)
1184
win = W_Void2Window(window);
1189
XClearArea(W_Display, win->window, x, y, width, height, False);
1192
XClearArea(W_Display, win->window, WIN_EDGE + x * W_Textwidth,
1193
MENU_PAD + y * W_Textheight,
1194
width * W_Textwidth, height * W_Textheight, False);
1198
XClearArea(W_Display, win->window, WIN_EDGE + x * W_Textwidth,
1199
MENU_PAD + y * W_Textheight, width * W_Textwidth, height * W_Textheight, False);
1205
W_ClearWindow(W_Window window)
1209
printf("Clearing %d\n", window);
1212
XClearWindow(W_Display, W_Void2Window(window)->window);
1218
return XPending(W_Display);
1222
W_EventsPending(void)
1226
while (XPending(W_Display))
1228
if (W_SpNextEvent(&W_myevent))
1238
W_NextEvent(W_Event * wevent)
1242
*wevent = W_myevent;
1246
while (W_SpNextEvent(wevent) == 0);
1249
static unsigned char sym_to_key(int sym)
1252
case XK_Up: return W_Key_Up;
1253
case XK_Down: return W_Key_Down;
1259
W_SpNextEvent(W_Event * wevent)
1263
XButtonEvent *button;
1264
XExposeEvent *expose;
1265
XConfigureEvent *configure;
1268
XMotionEvent *motion;
1269
static int prev_x, prev_y;
1274
int control_key = 0;
1285
key = (XKeyEvent *) & event;
1286
button = (XButtonEvent *) & event;
1287
expose = (XExposeEvent *) & event;
1288
configure = (XConfigureEvent *) & event;
1291
motion = (XMotionEvent *) & event;
1296
XNextEvent(W_Display, &event);
1299
printf(", read type=%d\n", event.type);
1301
win = findWindow(key->window);
1304
if (key->send_event == True && event.type != ClientMessage)
1305
return 0; /* event sent by another client */
1306
if ((event.type == KeyPress || event.type == ButtonPress) &&
1307
win->type == WIN_MENU)
1309
if (key->y % (W_Textheight + MENU_PAD * 2 + MENU_BAR) >=
1310
W_Textheight + MENU_PAD * 2)
1312
key->y = key->y / (W_Textheight + MENU_PAD * 2 + MENU_BAR);
1314
switch ((int) event.type)
1317
if (event.xclient.message_type == wm_protocols &&
1318
event.xclient.data.l[0] == wm_delete_window)
1320
W_UnmapWindow(W_Window2Void(win));
1321
wevent->type = W_EV_CLOSED;
1322
wevent->Window = W_Window2Void(win);
1323
wevent->key = wevent->x = wevent->y = 0;
1328
case LeaveNotify: /* for message window -- jfy */
1329
if (win == (struct window *) messagew)
1336
if ((key->state & LockMask) && !(key->state & ShiftMask) &&
1339
printf("Got a capslock!\n");
1340
key->state = key->state & ~LockMask;
1344
if (key->state & ControlMask && use_control_key)
1347
key->state = key->state & ~ControlMask;
1353
nch = XLookupString(key, (char *) &ch, 1, &sym, NULL);
1355
ch = sym_to_key(sym);
1356
if (ch == 0) return 0;
1358
#ifdef MOUSE_AS_SHIFT
1361
if (key->state & Button1Mask)
1363
wevent->modifier = W_LBUTTON;
1364
wevent->type = W_EV_MKEY;
1366
else if (key->state & Button2Mask)
1368
wevent->modifier = W_MBUTTON;
1369
wevent->type = W_EV_MKEY;
1371
else if (key->state & Button3Mask)
1373
wevent->modifier = W_RBUTTON;
1374
wevent->type = W_EV_MKEY;
1378
wevent->type = W_EV_KEY;
1382
wevent->type = W_EV_KEY;
1384
wevent->type = W_EV_KEY;
1387
wevent->Window = W_Window2Void(win);
1393
wevent->key = (unsigned char) (ch + 96);
1405
if (XLookupString(key, &ch, 1, NULL, NULL) > 0)
1407
wevent->type = W_EV_KEY_OFF;
1408
wevent->Window = W_Window2Void(win);
1416
#endif /* AUTOKEY */
1419
wevent->type = W_EV_BUTTON;
1420
wevent->Window = W_Window2Void(win);
1423
prev_x = wevent->x = button->x;
1424
prev_y = wevent->y = button->y;
1426
wevent->x = button->x;
1427
wevent->y = button->y;
1431
#ifdef MOUSE_AS_SHIFT
1432
if (mouse_as_shift &&
1433
(wevent->Window == mapw || wevent->Window == w))
1434
switch (button->button & 0xf)
1451
switch (button->button & 0xf)
1454
wevent->key = W_RBUTTON;
1457
wevent->key = W_LBUTTON;
1460
wevent->key = W_MBUTTON;
1464
wevent->key = W_WUBUTTON;
1469
wevent->key = W_WDBUTTON;
1474
wevent->key = W_X1BUTTON;
1479
wevent->key = W_X2BUTTON;
1484
#ifdef SHIFTED_MOUSE
1487
if (button->state & (ControlMask | ShiftMask))
1490
if (button->state & ShiftMask)
1492
wevent->key |= W_SHIFT_BUTTON;
1495
if (button->state & ControlMask)
1497
wevent->key |= W_CTRL_BUTTON;
1506
if (win->type == WIN_SCROLL)
1508
scrollScrolling(wevent);
1515
if (!motion_mouse ||
1516
(!motion_mouse_enablable && !motion_mouse_steering))
1518
wevent->type = W_EV_CM_BUTTON;
1519
wevent->Window = W_Window2Void(win);
1521
thresh = abs(prev_x - motion->x) + abs(prev_y - motion->y);
1523
if (thresh < user_motion_thresh)
1526
prev_x = wevent->x = motion->x;
1527
prev_y = wevent->y = motion->y;
1530
#ifdef MOUSE_AS_SHIFT
1531
if (mouse_as_shift &&
1532
(wevent->Window == mapw || wevent->Window == w))
1533
switch (button->button & 0xf)
1550
switch (button->button & 0xf)
1553
wevent->key = W_RBUTTON;
1556
wevent->key = W_LBUTTON;
1559
wevent->key = W_MBUTTON;
1563
wevent->key = W_WUBUTTON;
1568
wevent->key = W_WDBUTTON;
1573
wevent->key = W_X1BUTTON;
1578
wevent->key = W_X2BUTTON;
1583
#ifdef SHIFTED_MOUSE
1586
if (button->state & (ControlMask | ShiftMask))
1589
if (button->state & ShiftMask)
1591
wevent->key |= W_SHIFT_BUTTON;
1594
if (button->state & ControlMask)
1596
wevent->key |= W_CTRL_BUTTON;
1608
if (expose->count != 0)
1610
if (win->type == WIN_SCROLL)
1612
configureScrolling(win, expose->x, expose->y,
1613
expose->width, expose->height);
1614
redrawScrolling(win);
1617
if (win->type == WIN_MENU)
1623
wevent->type = W_EV_EXPOSE;
1624
wevent->Window = W_Window2Void(win);
1626
case ConfigureNotify:
1627
configureScrolling(win, configure->x, configure->y,
1628
configure->width, configure->height);
1638
W_MakeLine(W_Window window, int x0, int y0, int x1, int y1, W_Color color)
1643
printf("Line on %d\n", window);
1646
win = W_Void2Window(window)->window;
1647
XDrawLine(W_Display, win, colortable[color].contexts[0], x0, y0, x1, y1);
1652
static XSegment _lcache[NCOLORS][MAXCACHE];
1653
static int _lcache_index[NCOLORS];
1656
FlushLineCache(Window win, int color)
1658
XDrawSegments(W_Display, win, colortable[color].contexts[0],
1659
_lcache[color], _lcache_index[color]);
1660
_lcache_index[color] = 0;
1663
/* for local window only */
1665
W_CacheLine(W_Window window, int x0, int y0, int x1, int y1, int color)
1667
Window win = W_Void2Window(window)->window;
1668
register XSegment *s;
1670
if (_lcache_index[color] == MAXCACHE)
1671
FlushLineCache(win, color);
1673
s = &_lcache[color][_lcache_index[color]++];
1681
W_FlushLineCaches(W_Window window)
1683
Window win = W_Void2Window(window)->window;
1686
for (i = 0; i < NCOLORS; i++)
1688
if (_lcache_index[i])
1689
FlushLineCache(win, i);
1694
W_MakeTractLine(W_Window window, int x0, int y0, int x1, int y1, W_Color color)
1699
printf("Line on %d\n", window);
1702
win = W_Void2Window(window)->window;
1703
XDrawLine(W_Display, win, colortable[color].contexts[3], x0, y0, x1, y1);
1707
W_MakePhaserLine(W_Window window, int x0, int y0, int x1, int y1, W_Color color)
1712
printf("Line on %d\n", window);
1715
win = W_Void2Window(window)->window;
1716
XDrawLine(W_Display, win, colortable[color].contexts[1], x0, y0, x1, y1);
1719
void W_WriteCircle (W_Window window,
1725
struct window *win = W_Void2Window(window);
1727
XSetForeground(W_Display, colortable[color].contexts[0],
1728
colortable[color].pixelValue);
1729
XDrawArc(W_Display, win->window, colortable[color].contexts[0],
1730
x, y, r, r, 0, 23040);
1734
W_WriteTriangle(W_Window window, int x, int y, int s, int t, W_Color color)
1736
struct window *win = W_Void2Window(window);
1743
points[1].x = x + s;
1744
points[1].y = y - s;
1745
points[2].x = x - s;
1746
points[2].y = y - s;
1754
points[1].x = x + s;
1755
points[1].y = y + s;
1756
points[2].x = x - s;
1757
points[2].y = y + s;
1763
XDrawLines(W_Display, win->window, colortable[color].contexts[0],
1764
points, 4, CoordModeOrigin);
1768
W_WriteText(W_Window window, int x, int y, W_Color color, char *str, int len, W_Font font)
1774
printf("Text for %d @ (%d, %d) in %d: [%s]\n", window, x, y, color, str);
1778
font = W_RegularFont;
1779
win = W_Void2Window(window);
1784
addr = fonts[fontNum(font)].baseline;
1785
if (len < 0) len = strlen(str);
1786
XDrawImageString(W_Display, win->window,
1788
#ifdef SHORT_PACKETS
1790
colortable[color].insens_contexts[1] :
1791
colortable[color].contexts[fontNum(font)],
1793
colortable[color].contexts[fontNum(font)],
1796
x, y + addr, str, len);
1799
XCopyArea(W_Display, win->window, win->window,
1800
colortable[W_White].contexts[0], WIN_EDGE, MENU_PAD + W_Textheight,
1801
win->width * W_Textwidth, (win->height - 1) * W_Textheight,
1802
WIN_EDGE, MENU_PAD);
1803
XClearArea(W_Display, win->window,
1804
WIN_EDGE, MENU_PAD + W_Textheight * (win->height - 1),
1805
W_Textwidth * win->width, W_Textheight, False);
1806
if (len < 0) len = strlen(str);
1807
XDrawImageString(W_Display, win->window,
1809
#ifdef SHORT_PACKETS
1811
colortable[color].insens_contexts[1] :
1812
colortable[color].contexts[fontNum(font)],
1814
colortable[color].contexts[fontNum(font)],
1817
WIN_EDGE, MENU_PAD + W_Textheight * (win->height - 1) + fonts[fontNum(font)].baseline,
1819
AddToScrolling(win, color, font, str, len);
1822
changeMenuItem(win, x, y, str, color);
1825
addr = fonts[fontNum(font)].baseline;
1826
if (len < 0) len = strlen(str);
1827
XDrawImageString(W_Display, win->window,
1829
#ifdef SHORT_PACKETS
1831
colortable[color].insens_contexts[1] :
1832
colortable[color].contexts[fontNum(font)],
1834
colortable[color].contexts[fontNum(font)],
1837
x * W_Textwidth + WIN_EDGE, MENU_PAD + y * W_Textheight + addr,
1844
W_MaskText(W_Window window, int x, int y, W_Color color, char *str, int len, W_Font font)
1849
addr = fonts[fontNum(font)].baseline;
1852
printf("TextMask for %d @ (%d, %d) in %d: [%s]\n", window, x, y, color, str);
1855
win = W_Void2Window(window);
1856
XDrawString(W_Display, win->window,
1857
colortable[color].contexts[fontNum(font)], x, y + addr, str, len);
1861
W_StoreBitmap(int width, int height, char *data, W_Window window)
1863
struct icon *newicon;
1867
printf("Storing bitmap for %d (%d x %d)\n", window, width, height);
1871
win = W_Void2Window(window);
1872
newicon = (struct icon *) malloc(sizeof(struct icon));
1874
newicon->width = width;
1875
newicon->height = height;
1876
newicon->bitmap = XCreateBitmapFromData(W_Display, win->window,
1877
data, width, height);
1880
/* XFIX: changed to Pixmap */
1881
white = WhitePixel(W_Display, W_Screen);
1882
black = BlackPixel(W_Display, W_Screen);
1883
newicon->bitmap = XCreatePixmapFromBitmapData(W_Display, W_Root, data,
1884
width, height, white, black,
1885
DefaultDepth(W_Display,
1889
newicon->window = win->window;
1890
newicon->pixmap = 0;
1891
return W_Icon2Void(newicon);
1895
W_WriteBitmap(int x, int y, W_Icon bit, W_Color color)
1899
icon = W_Void2Icon(bit);
1902
printf("Writing bitmap to %d\n", icon->window);
1905
XCopyPlane(W_Display, icon->bitmap, icon->window,
1906
colortable[color].contexts[BITGC], 0, 0, icon->width, icon->height,
1910
/* XFIX : copyarea */
1911
XCopyArea(W_Display, icon->bitmap, icon->window,
1912
colortable[color].contexts[BITGC], 0, 0, icon->width, icon->height,
1919
W_TileWindow(W_Window window, W_Icon bit)
1925
printf("Tiling window %d\n", window);
1928
icon = W_Void2Icon(bit);
1929
win = W_Void2Window(window)->window;
1931
if (icon->pixmap == 0)
1933
icon->pixmap = XCreatePixmap(W_Display, W_Root,
1934
icon->width, icon->height, DefaultDepth(W_Display, W_Screen));
1935
XCopyPlane(W_Display, icon->bitmap, icon->pixmap,
1936
colortable[W_White].contexts[0], 0, 0, icon->width, icon->height,
1939
XSetWindowBackgroundPixmap(W_Display, win, icon->pixmap);
1940
XClearWindow(W_Display, win);
1942
/* if (icon->pixmap==0) { icon->pixmap=XMakePixmap(icon->bitmap, * *
1943
* colortable[W_White].pixelValue, colortable[W_Black].pixelValue); } * *
1944
* XChangeBackground(win, icon->pixmap); XClear(win); */
1948
W_UnTileWindow(W_Window window)
1953
printf("Untiling window %d\n", window);
1956
win = W_Void2Window(window)->window;
1958
XSetWindowBackground(W_Display, win, colortable[W_Black].pixelValue);
1959
XClearWindow(W_Display, win);
1963
W_MakeTextWindow(char *name, int x, int y, int width, int height, W_Window parent, int border)
1965
struct window *newwin;
1967
XSetWindowAttributes attrs;
1968
XSizeHints *sz_hints;
1972
printf("New window...\n");
1975
gcheck_result = checkGeometry(name, &x, &y, &width, &height);
1976
checkParent(name, &parent);
1977
attrs.border_pixel = colortable[W_White].pixelValue;
1978
attrs.event_mask = ExposureMask;
1981
attrs.event_mask |= KeyReleaseMask;
1982
#endif /* AUTOKEY */
1984
#ifdef SHORT_PACKETS
1985
attrs.event_mask |= ButtonPressMask;
1988
attrs.background_pixel = colortable[W_Black].pixelValue;
1989
attrs.do_not_propagate_mask = ExposureMask;
1990
wparent = W_Void2Window(parent)->window;
1992
XCreateWindow(W_Display, wparent, x, y,
1993
width * W_Textwidth + WIN_EDGE * 2, MENU_PAD * 2 + height * W_Textheight,
1994
border, CopyFromParent, InputOutput, CopyFromParent,
1995
CWBackPixel | CWEventMask |
1999
class_hint.res_name = name;
2000
sz_hints = XAllocSizeHints();
2001
sz_hints->min_width = WIN_EDGE * 2 + width * W_Textwidth;
2002
sz_hints->max_width = WIN_EDGE * 2 + width * W_Textwidth;
2003
sz_hints->base_width = WIN_EDGE * 2;
2004
sz_hints->width_inc = W_Textwidth;
2005
sz_hints->min_height = MENU_PAD * 2 + 3 * W_Textheight;
2006
sz_hints->max_height = MENU_PAD * 2 + height * W_Textheight;
2007
sz_hints->base_height = MENU_PAD * 2 + 2 * W_Textheight;
2008
sz_hints->height_inc = W_Textheight;
2009
sz_hints->flags = PResizeInc | PMinSize | PMaxSize | PBaseSize;
2010
if (gcheck_result & G_SET_X || gcheck_result & G_SET_Y)
2011
sz_hints->flags |= WMXYHintMode_default();
2012
XStoreName(W_Display, newwin->window, name);
2013
XSetWMNormalHints(W_Display, newwin->window, sz_hints);
2014
XSetClassHint(W_Display, newwin->window, &class_hint);
2015
XSetWMHints(W_Display, newwin->window, &wm_hint);
2016
if (wparent == W_Root && baseWin != NULL)
2017
XSetTransientForHint(W_Display, newwin->window, W_Void2Window(baseWin)->window);
2018
newwin->name = strdup(name);
2019
newwin->width = width;
2020
newwin->height = height;
2021
if (wparent != W_Root)
2022
if (checkMapped(name))
2023
W_MapWindow(W_Window2Void(newwin));
2026
printf("New text window %d, child of %d\n", newwin, parent);
2029
XSetWindowColormap(W_Display, newwin->window, W_Colormap);
2030
return W_Window2Void(newwin);
2034
newWindow(Window window, int type)
2036
struct window *newwin;
2038
XSetWMProtocols (W_Display, window, &wm_delete_window, 1);
2039
newwin = (struct window *) malloc(sizeof(struct window));
2041
newwin->window = window;
2042
newwin->type = type;
2044
newwin->handle_keydown = 0;
2045
newwin->handle_keyup = 0;
2046
newwin->handle_button = 0;
2047
newwin->handle_expose = 0;
2050
#ifdef SHORT_PACKETS
2051
newwin->insensitive = 0;
2054
newwin->cursor = (Cursor) 0; /* about the best I can do *
2061
findWindow(Window window)
2063
struct windowlist *entry;
2065
entry = hashtable[hash(window)];
2066
while (entry != NULL)
2068
if (entry->window->window == window)
2069
return entry->window;
2070
entry = entry->next;
2075
void addToHash(struct window * win)
2077
struct windowlist **new;
2080
printf("Adding to %d\n", hash(win->window));
2083
new = &hashtable[hash(win->window)];
2084
while (*new != NULL)
2086
new = &((*new)->next);
2088
*new = (struct windowlist *) malloc(sizeof(struct windowlist));
2090
(*new)->next = NULL;
2091
(*new)->window = win;
2095
W_MakeScrollingWindow(name, x, y, width, height, parent, border)
2097
int x, y, width, height;
2101
struct window *newwin;
2103
XSetWindowAttributes attrs;
2104
XSizeHints *sz_hints;
2106
struct scrollingWindow *sw;
2107
int scw = (scrollbar ? scroll_thumb_width : 0);
2110
printf("New window...\n");
2113
gcheck_result = checkGeometry(name, &x, &y, &width, &height);
2114
checkParent(name, &parent);
2115
wparent = W_Void2Window(parent)->window;
2116
attrs.border_pixel = colortable[W_White].pixelValue;
2117
attrs.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask;
2120
attrs.event_mask |= KeyReleaseMask;
2121
#endif /* AUTOKEY */
2123
attrs.background_pixel = colortable[W_Black].pixelValue;
2125
/* NOTE: CWDontPropagate seems to crash in OpenWindows */
2126
attrs.do_not_propagate_mask = ResizeRedirectMask | ExposureMask;
2128
XCreateWindow(W_Display, wparent, x, y,
2129
width * W_Textwidth + WIN_EDGE * 2 + scw,
2130
MENU_PAD * 2 + height * W_Textheight,
2131
border, CopyFromParent, InputOutput, CopyFromParent,
2132
CWBackPixel | CWEventMask |
2133
CWBorderPixel /* | CWDontPropagate */ ,
2134
&attrs), WIN_SCROLL);
2135
class_hint.res_name = name;
2136
sz_hints = XAllocSizeHints();
2137
sz_hints->width_inc = W_Textwidth;
2138
sz_hints->height_inc = W_Textheight;
2139
sz_hints->min_width = WIN_EDGE * 2 + W_Textwidth + scw;
2140
sz_hints->min_height = MENU_PAD * 2 + W_Textheight;
2141
sz_hints->base_width = WIN_EDGE * 2 + scw;
2142
sz_hints->base_height = MENU_PAD * 2;
2143
sz_hints->flags = PResizeInc | PMinSize | PBaseSize;
2144
if (gcheck_result & XValue || gcheck_result & YValue)
2145
sz_hints->flags |= WMXYHintMode_default();
2146
XStoreName(W_Display, newwin->window, name);
2147
XSetWMNormalHints(W_Display, newwin->window, sz_hints);
2148
XFree((void *) sz_hints);
2149
XSetClassHint(W_Display, newwin->window, &class_hint);
2150
XSetWMHints(W_Display, newwin->window, &wm_hint);
2151
if (wparent == W_Root && baseWin != NULL)
2152
XSetTransientForHint(W_Display, newwin->window, W_Void2Window(baseWin)->window);
2154
newwin->name = strdup(name);
2155
sw = (struct scrollingWindow *) malloc(sizeof(struct scrollingWindow));
2159
sw->head = sw->tail = sw->index = NULL;
2161
newwin->data = (char *) sw;
2162
newwin->width = width;
2163
newwin->height = height;
2164
if (wparent != W_Root)
2165
if (checkMapped(name))
2166
W_MapWindow(W_Window2Void(newwin));
2169
printf("New scroll window %d, child of %d\n", newwin, parent);
2172
XSetWindowColormap(W_Display, newwin->window, W_Colormap);
2173
return W_Window2Void(newwin);
2177
* Add a string to the string list of the scrolling window.
2180
AddToScrolling(win, color, font, str, len)
2187
struct scrollingWindow *sw;
2188
struct stringList *new;
2192
sw = (struct scrollingWindow *) win->data;
2193
if (sw->lines > 0 && sw->lines > scroll_lines /* some large number */ )
2197
sw->tail = new->prev;
2198
new->prev->next = NULL;
2200
new->next = sw->head;
2201
sw->head->prev = new;
2206
new = (struct stringList *) malloc(sizeof(struct stringList));
2208
new->next = sw->head;
2211
sw->head->prev = new;
2217
* printf("adding one line \"%s\" C:%d F:%d.\n", str, color,
2218
* fontNum(font)); */
2220
sw->index = sw->head; /* input forces to end of *
2224
sw->updated++; /* mark for *
2225
* W_FlushScrollingWindow */
2227
STRNCPY(new->string, str, MAX_TEXT_WIDTH - 1);
2231
if (len >= MAX_TEXT_WIDTH)
2233
new->string[MAX_TEXT_WIDTH - 1] = 0;
2237
/* we pad out the string with spaces so we don't have to clear the *
2239
memset(&new->string[len], ' ', MAX_TEXT_WIDTH - len - 1);
2240
new->string[MAX_TEXT_WIDTH - 1] = 0;
2245
W_FlushScrollingWindow(window)
2249
struct window *win = W_Void2Window(window);
2250
struct scrollingWindow *sw;
2254
if (win->type != WIN_SCROLL)
2256
fprintf(stderr, "bad window type in W_FlushScrollingWindow.\n");
2259
sw = (struct scrollingWindow *) win->data;
2266
struct stringList *item;
2269
if (win->height > sw->updated)
2271
XCopyArea(W_Display, win->window, win->window,
2272
colortable[W_White].contexts[0],
2273
WIN_EDGE, MENU_PAD + sw->updated * W_Textheight,
2274
win->width * W_Textwidth,
2275
(win->height - sw->updated) * W_Textheight,
2276
WIN_EDGE, MENU_PAD);
2280
y = (win->height - 1) * W_Textheight + fonts[1].baseline;
2282
for (item = sw->index; item && y > 0 && sw->updated; item = item->next,
2286
XDrawImageString(W_Display, win->window,
2287
colortable[item->color].contexts[fontNum(item->font)],
2288
WIN_EDGE, MENU_PAD + y, item->string,
2296
redrawScrolling(win);
2304
struct scrollingWindow *sw;
2307
int savedlines, maxrow, thumbTop, thumbHeight, totalHeight, winheight;
2310
* savedlines : Number of offscreen text lines,
2311
* sw->lines - win->height
2313
* maxrow + 1 : Number of onscreen text lines,
2315
* min(sw->lines + 1, win->height+1)
2317
* sw->topline : -Number of lines above the last max_row+1 lines
2319
* thumbTop = screen->topline + screen->savedlines;
2320
* thumbHeight = screen->max_row + 1;
2321
* totalHeight = thumbHeight + screen->savedlines;
2323
* XawScrollbarSetThumb(scrollWidget,
2324
* ((float)thumbTop) / totalHeight,
2325
* ((float)thumbHeight) / totalHeight);
2328
savedlines = sw->lines - win->height;
2331
maxrow = sw->lines < win->height ? sw->lines : win->height;
2332
winheight = win->height * W_Textheight + MENU_PAD * 2;
2334
thumbTop = sw->topline + savedlines;
2335
thumbHeight = maxrow + 1;
2336
totalHeight = thumbHeight + savedlines;
2338
x = win->width * W_Textwidth + WIN_EDGE * 2;
2339
y = winheight * thumbTop / totalHeight;
2340
h = winheight * thumbHeight / totalHeight;
2342
XClearArea(W_Display, win->window, x, 0, scroll_thumb_width, winheight,
2344
XFillRectangle(W_Display, win->window, scroll_thumb_gc,
2346
scroll_thumb_width, h);
2347
XDrawLine(W_Display, win->window, colortable[W_Red].contexts[0],
2348
x, 0, x, winheight);
2352
redrawScrolling(win)
2356
struct scrollingWindow *sw;
2357
register struct stringList *item;
2364
sw = (struct scrollingWindow *) win->data;
2369
y = (win->height - 1) * W_Textheight + fonts[1].baseline;
2370
for (item = sw->index; item && y > 0; item = item->next, y -= W_Textheight)
2372
XDrawImageString(W_Display, win->window,
2373
colortable[item->color].contexts[fontNum(item->font)],
2374
WIN_EDGE, MENU_PAD + y, item->string,
2381
#ifdef SHORT_PACKETS
2382
void W_SetSensitive(W_Window w, int v)
2384
struct window *win = W_Void2Window(w);
2386
win->insensitive = !v;
2388
if (win->type == WIN_SCROLL)
2389
redrawScrolling(win);
2394
W_MakeMenu(char *name, int x, int y, int width, int height, W_Window parent, int border)
2396
struct window *newwin;
2397
struct menuItem *items;
2400
XSetWindowAttributes attrs;
2403
printf("New window...\n");
2406
checkGeometry(name, &x, &y, &width, &height);
2407
checkParent(name, &parent);
2408
wparent = W_Void2Window(parent)->window;
2409
attrs.border_pixel = colortable[W_White].pixelValue;
2410
attrs.event_mask = KeyPressMask | ButtonPressMask | ExposureMask;
2413
attrs.event_mask |= KeyReleaseMask;
2414
#endif /* AUTOKEY */
2416
attrs.background_pixel = colortable[W_Black].pixelValue;
2417
attrs.do_not_propagate_mask = KeyPressMask | ButtonPressMask | ExposureMask;
2419
XCreateWindow(W_Display, wparent, x, y,
2420
width * W_Textwidth + WIN_EDGE * 2,
2421
height * (W_Textheight + MENU_PAD * 2) + (height - 1) * MENU_BAR, border,
2422
CopyFromParent, InputOutput, CopyFromParent,
2423
CWBackPixel | CWEventMask |
2427
class_hint.res_name = name;
2428
XSetClassHint(W_Display, newwin->window, &class_hint);
2429
XSetWMHints(W_Display, newwin->window, &wm_hint);
2430
if (wparent == W_Root && baseWin != NULL)
2431
XSetTransientForHint(W_Display, newwin->window, W_Void2Window(baseWin)->window);
2432
XStoreName(W_Display, newwin->window, name);
2433
newwin->name = strdup(name);
2434
items = (struct menuItem *) malloc(height * sizeof(struct menuItem));
2436
for (i = 0; i < height; i++)
2438
/* new: allocate once and reuse -tsh */
2439
items[i].column = 0;
2440
items[i].string = (char *) malloc(MAX_TEXT_WIDTH);
2441
items[i].color = W_White;
2443
newwin->data = (char *) items;
2444
newwin->width = width;
2445
newwin->height = height;
2446
if (wparent != W_Root)
2447
if (checkMapped(name))
2448
W_MapWindow(W_Window2Void(newwin));
2451
printf("New menu window %d, child of %d\n", newwin, parent);
2454
XSetWindowColormap(W_Display, newwin->window, W_Colormap);
2455
return W_Window2Void(newwin);
2458
void redrawMenu(struct window * win)
2462
for (count = 1; count < win->height; count++)
2464
XFillRectangle(W_Display, win->window,
2465
colortable[W_Grey].contexts[0],
2466
0, count * (W_Textheight + MENU_PAD * 2) + (count - 1) * MENU_BAR,
2467
win->width * W_Textwidth + WIN_EDGE * 2, MENU_BAR);
2469
for (count = 0; count < win->height; count++)
2471
redrawMenuItem(win, count);
2475
void redrawMenuItem(struct window *win, int n)
2477
struct menuItem *items;
2479
items = (struct menuItem *) win->data;
2480
XFillRectangle(W_Display, win->window,
2481
colortable[W_Black].contexts[0],
2482
WIN_EDGE, n * (W_Textheight + MENU_PAD * 2 + MENU_BAR) + MENU_PAD,
2483
win->width * W_Textwidth, W_Textheight);
2484
if (items[n].string)
2486
XDrawImageString(W_Display, win->window,
2487
colortable[items[n].color].contexts[1],
2488
WIN_EDGE + W_Textwidth * items[n].column,
2489
n * (W_Textheight + MENU_PAD * 2 + MENU_BAR) + MENU_PAD + fonts[1].baseline,
2490
items[n].string, strlen(items[n].string));
2494
static void changeMenuItem(struct window *win, int col, int n, char *str, W_Color color)
2496
struct menuItem *items;
2498
items = (struct menuItem *) win->data;
2500
STRNCPY(items[n].string, str, MAX_TEXT_WIDTH - 1);
2501
items[n].string[MAX_TEXT_WIDTH - 1] = 0;
2502
items[n].color = color;
2503
items[n].column = col;
2504
redrawMenuItem(win, n);
2508
W_DefineMapcursor(W_Window window)
2511
Pixmap mapcursmaskbit;
2513
struct window *win = W_Void2Window(window);
2520
f.pixel = colortable[W_White].pixelValue;
2521
b.pixel = colortable[W_Black].pixelValue;
2523
XQueryColor(W_Display, W_Colormap, &f);
2524
XQueryColor(W_Display, W_Colormap, &b);
2526
mapcursbit = XCreateBitmapFromData(W_Display, win->window, mapcursor_bits,
2527
mapcursor_width, mapcursor_height);
2529
if ((path = getdefault("mapCursorDef")))
2532
if (W_LoadBitmap(window, path, &mapcursmaskbit, &w, &h, &xh, &yh) != 1)
2534
mapcursmaskbit = XCreateBitmapFromData(W_Display, win->window,
2535
mapmask_bits, mapmask_width, mapmask_height);
2540
mapcursbit = XCreatePixmap(W_Display, win->window, w, h, 1);
2541
XFillRectangle(W_Display, mapcursbit,
2542
colortable[W_White].contexts[0], 0, 0, w, h);
2547
mapcursmaskbit = XCreateBitmapFromData(W_Display, win->window,
2548
mapmask_bits, mapmask_width, mapmask_height);
2551
XFreeCursor(W_Display, win->cursor);
2553
new = XCreatePixmapCursor(W_Display, mapcursbit, mapcursmaskbit,
2555
XRecolorCursor(W_Display, new, &b, &f);
2556
XDefineCursor(W_Display, win->window, new);
2561
W_DefineLocalcursor(W_Window window)
2564
Pixmap localcursmaskbit;
2565
Pixmap localcursbit;
2566
struct window *win = W_Void2Window(window);
2573
f.pixel = colortable[W_White].pixelValue;
2574
b.pixel = colortable[W_Black].pixelValue;
2576
XQueryColor(W_Display, W_Colormap, &f);
2577
XQueryColor(W_Display, W_Colormap, &b);
2579
localcursbit = XCreateBitmapFromData(W_Display, win->window,
2580
localcursor_bits, localcursor_width, localcursor_height);
2582
if ((path = getdefault("localCursorDef")))
2584
if (W_LoadBitmap(window, path, &localcursmaskbit, &w, &h, &xh, &yh) != 1)
2586
localcursmaskbit = XCreateBitmapFromData(W_Display, win->window,
2587
localmask_bits, localmask_width, localmask_height);
2592
localcursbit = XCreatePixmap(W_Display, win->window, w, h, 1);
2593
XFillRectangle(W_Display, localcursbit,
2594
colortable[W_White].contexts[0], 0, 0, w, h);
2598
localcursmaskbit = XCreateBitmapFromData(W_Display, win->window,
2599
localmask_bits, localmask_width, localmask_height);
2602
XFreeCursor(W_Display, win->cursor);
2604
new = XCreatePixmapCursor(W_Display, localcursbit, localcursmaskbit,
2606
XRecolorCursor(W_Display, new, &b, &f);
2607
XDefineCursor(W_Display, win->window, new);
2612
W_DefineFedCursor(W_Window window)
2615
Pixmap fedcursmaskbit;
2617
struct window *win = W_Void2Window(window);
2622
f.pixel = colortable[W_White].pixelValue;
2623
b.pixel = colortable[W_Black].pixelValue;
2625
XQueryColor(W_Display, W_Colormap, &f);
2626
XQueryColor(W_Display, W_Colormap, &b);
2628
fedcursbit = XCreateBitmapFromData(W_Display, win->window, fed_cruiser_bits,
2629
fed_cruiser_width, fed_cruiser_height);
2630
fedcursmaskbit = XCreateBitmapFromData(W_Display, win->window,
2631
fed_mask_bits, fed_mask_width, fed_mask_height);
2633
XFreeCursor(W_Display, win->cursor);
2635
new = XCreatePixmapCursor(W_Display, fedcursmaskbit, fedcursbit,
2637
XRecolorCursor(W_Display, new, &b, &f);
2638
XDefineCursor(W_Display, win->window, new);
2643
W_DefineRomCursor(W_Window window)
2646
Pixmap romcursmaskbit;
2648
struct window *win = W_Void2Window(window);
2653
f.pixel = colortable[W_White].pixelValue;
2654
b.pixel = colortable[W_Black].pixelValue;
2656
XQueryColor(W_Display, W_Colormap, &f);
2657
XQueryColor(W_Display, W_Colormap, &b);
2659
romcursbit = XCreateBitmapFromData(W_Display, win->window, rom_cruiser_bits,
2660
rom_cruiser_width, rom_cruiser_height);
2661
romcursmaskbit = XCreateBitmapFromData(W_Display, win->window,
2662
rom_mask_bits, rom_cruiser_width, rom_cruiser_height);
2664
XFreeCursor(W_Display, win->cursor);
2666
new = XCreatePixmapCursor(W_Display, romcursmaskbit, romcursbit,
2668
XRecolorCursor(W_Display, new, &b, &f);
2669
XDefineCursor(W_Display, win->window, new);
2674
W_DefineKliCursor(W_Window window)
2677
Pixmap klicursmaskbit;
2679
struct window *win = W_Void2Window(window);
2684
f.pixel = colortable[W_White].pixelValue;
2685
b.pixel = colortable[W_Black].pixelValue;
2687
XQueryColor(W_Display, W_Colormap, &f);
2688
XQueryColor(W_Display, W_Colormap, &b);
2690
klicursbit = XCreateBitmapFromData(W_Display, win->window, kli_cruiser_bits,
2691
kli_cruiser_width, kli_cruiser_height);
2692
klicursmaskbit = XCreateBitmapFromData(W_Display, win->window,
2693
fed_mask_bits, kli_cruiser_width, kli_cruiser_height);
2695
XFreeCursor(W_Display, win->cursor);
2697
new = XCreatePixmapCursor(W_Display, klicursmaskbit, klicursbit,
2699
XRecolorCursor(W_Display, new, &b, &f);
2700
XDefineCursor(W_Display, win->window, new);
2705
W_DefineOriCursor(W_Window window)
2708
Pixmap oricursmaskbit;
2710
struct window *win = W_Void2Window(window);
2715
f.pixel = colortable[W_White].pixelValue;
2716
b.pixel = colortable[W_Black].pixelValue;
2718
XQueryColor(W_Display, W_Colormap, &f);
2719
XQueryColor(W_Display, W_Colormap, &b);
2721
oricursbit = XCreateBitmapFromData(W_Display, win->window, ori_cruiser_bits,
2722
ori_cruiser_width, ori_cruiser_height);
2723
oricursmaskbit = XCreateBitmapFromData(W_Display, win->window,
2724
fed_mask_bits, ori_cruiser_width, ori_cruiser_height);
2726
XFreeCursor(W_Display, win->cursor);
2728
new = XCreatePixmapCursor(W_Display, oricursmaskbit, oricursbit,
2730
XRecolorCursor(W_Display, new, &b, &f);
2731
XDefineCursor(W_Display, win->window, new);
2736
W_DefineTrekCursor(W_Window window)
2739
struct window *win = W_Void2Window(window);
2742
int w, h, xh, yh, mw, mh, mxh, myh;
2744
f.pixel = colortable[W_Yellow].pixelValue;
2745
b.pixel = colortable[W_Black].pixelValue;
2747
XQueryColor(W_Display, W_Colormap, &f);
2748
XQueryColor(W_Display, W_Colormap, &b);
2751
XFreeCursor(W_Display, win->cursor);
2753
if ((path = getdefault("infoCursorDef")))
2757
if (W_LoadBitmap(window, path, &pm, &w, &h, &xh, &yh) != 1)
2758
new = XCreateFontCursor(W_Display, XC_trek);
2761
char mask_path[512];
2763
strcpy(mask_path, path);
2764
strcat(mask_path, ".mask");
2766
if (W_LoadBitmap(window, mask_path, &mpm, &mw, &mh, &mxh, &myh) != 1)
2770
mpm = XCreatePixmap(W_Display, win->window, w, h, 1);
2771
XFillRectangle(W_Display, mpm,
2772
colortable[W_White].contexts[0], 0, 0, w, h);
2775
if ((w != mw) || (h != mh))
2777
printf("Cursor and mask are not the same size. %s\n", path);
2778
new = XCreateFontCursor(W_Display, XC_trek);
2781
new = XCreatePixmapCursor(W_Display, pm, mpm,
2786
new = XCreateFontCursor(W_Display, XC_trek);
2788
XRecolorCursor(W_Display, new, &f, &b);
2789
XDefineCursor(W_Display, win->window, new);
2794
W_DefineWarningCursor(W_Window window)
2797
struct window *win = W_Void2Window(window);
2800
f.pixel = colortable[W_Red].pixelValue;
2801
b.pixel = colortable[W_Black].pixelValue;
2803
XQueryColor(W_Display, W_Colormap, &f);
2804
XQueryColor(W_Display, W_Colormap, &b);
2807
XFreeCursor(W_Display, win->cursor);
2809
new = XCreateFontCursor(W_Display, XC_pirate);
2810
XRecolorCursor(W_Display, new, &f, &b);
2811
XDefineCursor(W_Display, win->window, new);
2816
W_DefineArrowCursor(W_Window window)
2819
struct window *win = W_Void2Window(window);
2822
int w, h, xh, yh, mw, mh, mxh, myh;
2824
f.pixel = colortable[W_Black].pixelValue;
2825
b.pixel = colortable[W_White].pixelValue;
2827
XQueryColor(W_Display, W_Colormap, &f);
2828
XQueryColor(W_Display, W_Colormap, &b);
2831
XFreeCursor(W_Display, win->cursor);
2833
if ((path = getdefault("arrowCursorDef")))
2837
if (W_LoadBitmap(window, path, &pm, &w, &h, &xh, &yh) != 1)
2838
new = XCreateFontCursor(W_Display, XC_left_ptr);
2841
char mask_path[512];
2843
strcpy(mask_path, path);
2844
strcat(mask_path, ".mask");
2846
if (W_LoadBitmap(window, mask_path, &mpm, &mw, &mh, &mxh, &myh) != 1)
2850
mpm = XCreatePixmap(W_Display, win->window, w, h, 1);
2851
XFillRectangle(W_Display, mpm,
2852
colortable[W_White].contexts[0], 0, 0, w, h);
2855
if ((w != mw) || (h != mh))
2857
printf("Cursor and mask are not the same size. %s\n", path);
2858
new = XCreateFontCursor(W_Display, XC_left_ptr);
2861
new = XCreatePixmapCursor(W_Display, pm, mpm,
2866
new = XCreateFontCursor(W_Display, XC_left_ptr);
2868
XRecolorCursor(W_Display, new, &f, &b);
2869
XDefineCursor(W_Display, win->window, new);
2874
W_DefineTextCursor(W_Window window)
2877
struct window *win = W_Void2Window(window);
2880
int w, h, xh, yh, mw, mh, mxh, myh;
2882
f.pixel = colortable[W_Yellow].pixelValue;
2883
b.pixel = colortable[W_Black].pixelValue;
2885
XQueryColor(W_Display, W_Colormap, &f);
2886
XQueryColor(W_Display, W_Colormap, &b);
2889
XFreeCursor(W_Display, win->cursor);
2891
if ((path = getdefault("textCursorDef")))
2895
if (W_LoadBitmap(window, path, &pm, &w, &h, &xh, &yh) != 1)
2896
new = XCreateFontCursor(W_Display, XC_xterm);
2899
char mask_path[512];
2901
strcpy(mask_path, path);
2902
strcat(mask_path, ".mask");
2904
if (W_LoadBitmap(window, mask_path, &mpm, &mw, &mh, &mxh, &myh) != 1)
2908
mpm = XCreatePixmap(W_Display, win->window, w, h, 1);
2909
XFillRectangle(W_Display, mpm,
2910
colortable[W_White].contexts[0], 0, 0, w, h);
2913
if ((w != mw) || (h != mh))
2915
printf("Cursor and mask are not the same size. %s\n", path);
2916
new = XCreateFontCursor(W_Display, XC_xterm);
2919
new = XCreatePixmapCursor(W_Display, pm, mpm,
2924
new = XCreateFontCursor(W_Display, XC_xterm);
2926
XRecolorCursor(W_Display, new, &f, &b);
2927
XDefineCursor(W_Display, win->window, new);
2932
W_DefineCursor(W_Window window, int width, int height, char *bits, char *mask, int xhot, int yhot)
2934
static char *oldbits = NULL;
2939
XColor whiteCol, blackCol;
2942
printf("Defining cursor for %d\n", window);
2945
win = W_Void2Window(window);
2946
whiteCol.pixel = colortable[W_White].pixelValue;
2947
XQueryColor(W_Display, W_Colormap, &whiteCol);
2948
blackCol.pixel = colortable[W_Black].pixelValue;
2949
XQueryColor(W_Display, W_Colormap, &blackCol);
2950
if (!oldbits || oldbits != bits)
2952
cursbits = XCreateBitmapFromData(W_Display, win->window,
2953
bits, width, height);
2954
cursmask = XCreateBitmapFromData(W_Display, win->window,
2955
mask, width, height);
2957
curs = XCreatePixmapCursor(W_Display, cursbits, cursmask,
2958
&whiteCol, &blackCol, xhot, yhot);
2959
XFreePixmap(W_Display, cursbits);
2960
XFreePixmap(W_Display, cursmask);
2962
XDefineCursor(W_Display, win->window, curs);
2966
W_LoadBitmap(W_Window window, char *path, Pixmap * pixmap, int *width, int *height, int *x_hot, int *y_hot)
2971
win = W_Void2Window(window);
2973
status = XReadBitmapFile(W_Display, win->window, path, (unsigned int *) width,
2974
(unsigned int *) height, pixmap, x_hot, y_hot);
2976
if (status == BitmapSuccess)
2980
*x_hot = *width / 2;
2981
*y_hot = *height / 2;
2993
XBell(W_Display, 0);
2997
W_WindowWidth(W_Window window)
2999
return W_Void2Window(window)->width;
3003
W_WindowHeight(W_Window window)
3005
return W_Void2Window(window)->height;
3011
return ConnectionNumber(W_Display);
3015
W_DestroyWindow(W_Window window)
3020
printf("Destroying %d\n", window);
3023
win = W_Void2Window(window);
3025
XDestroyWindow(W_Display, win->window);
3031
W_SetTransientForHint(W_Window w, W_Window pw)
3033
XSetTransientForHint(W_Display, W_Void2Window(w)->window,
3034
W_Void2Window(pw)->window);
3038
void deleteWindow(struct window *window)
3040
struct windowlist **rm;
3041
struct windowlist *temp;
3043
rm = &hashtable[hash(window->window)];
3044
while (*rm != NULL && (*rm)->window != window)
3046
rm = &((*rm)->next);
3050
printf("Attempt to delete non-existent window!\n");
3055
free((char *) temp);
3059
W_SetIconWindow(W_Window main, W_Window icon)
3063
XSetIconName(W_Display, W_Void2Window(icon)->window, W_Void2Window(main)->name);
3065
hints.flags = IconWindowHint;
3066
hints.icon_window = W_Void2Window(icon)->window;
3068
hints.window_group = W_Void2Window(main)->window;
3069
hints.flags |= WindowGroupHint;
3071
XSetCommand(W_Display, W_Void2Window(main)->window, wm_argv, wm_argc);
3074
XSetWMHints(W_Display, W_Void2Window(main)->window, &hints);
3083
struct scrollingWindow *sw = (struct scrollingWindow *) win->data;
3084
int savedlines = sw->lines - win->height;
3089
if (sw->topline + savedlines > 0)
3093
fprintf(stderr, "scroll error, NULL index (scrollUp).\n");
3096
sw->index = sw->index->next;
3098
redrawScrolling(win);
3108
struct scrollingWindow *sw = (struct scrollingWindow *) win->data;
3110
if (sw->topline < 0)
3114
fprintf(stderr, "scroll error, NULL index (scrollDown).\n");
3117
sw->index = sw->index->prev;
3119
redrawScrolling(win);
3125
scrollPosition(win, y)
3130
struct scrollingWindow *sw = (struct scrollingWindow *) win->data;
3131
int savedlines, maxrow, winheight, newtop;
3133
savedlines = sw->lines - win->height;
3136
maxrow = sw->lines < win->height ? sw->lines : win->height;
3137
winheight = win->height * W_Textheight + MENU_PAD * 2;
3139
newtop = (y * (savedlines + maxrow + 1)) / winheight - savedlines;
3140
if (newtop < -savedlines)
3141
newtop = -savedlines;
3142
else if (newtop > 0)
3144
scrollTo(win, sw, newtop);
3148
scrollTo(win, sw, topline)
3151
struct scrollingWindow *sw;
3154
while (topline < sw->topline)
3158
fprintf(stderr, "scroll error, NULL index (1).\n");
3161
sw->index = sw->index->next;
3164
while (topline > sw->topline)
3168
fprintf(stderr, "scroll error, NULL index (2).\n");
3171
sw->index = sw->index->prev;
3174
redrawScrolling(win);
3178
scrollScrolling(wevent)
3182
switch (wevent->key)
3186
scrollUp(W_Void2Window(wevent->Window), wevent->y);
3190
scrollDown(W_Void2Window(wevent->Window), wevent->y);
3193
scrollPosition(W_Void2Window(wevent->Window), wevent->y);
3201
configureScrolling(win, x, y, width, height)
3204
int x, y; /* TODO */
3208
int new_text_width, new_text_height;
3209
int new_real_width, new_real_height;
3210
XWindowAttributes wa;
3211
int sw = scrollbar ? scroll_thumb_width : 0;
3214
/* XXX: can't shrink window */
3216
if (width <= win->width * W_Textwidth + WIN_EDGE * 2 &&
3217
height <= win->height * W_Textheight + MENU_PAD * 2)
3221
XGetWindowAttributes(W_Display, win->window, &wa);
3223
new_text_width = (wa.width - WIN_EDGE * 2 - sw) / W_Textwidth;
3224
new_text_height = (wa.height - MENU_PAD * 2) / W_Textheight;
3226
if (new_text_width <= 0)
3228
if (new_text_height <= 0)
3229
new_text_height = 1;
3230
if (new_text_width >= MAX_TEXT_WIDTH)
3231
new_text_width = MAX_TEXT_WIDTH - 1;
3233
new_real_width = new_text_width * W_Textwidth + WIN_EDGE * 2 + sw;
3234
new_real_height = new_text_height * W_Textheight + MENU_PAD * 2;
3236
if (new_real_height != wa.height || new_real_width != wa.width)
3238
XResizeWindow(W_Display, win->window, new_real_width, new_real_height);
3241
win->width = new_text_width;
3242
win->height = new_text_height;
3244
/* an expose event will follow a resize request, triggering *
3245
* redrawScrolling */
3248
/*****************************************************************************/
3249
/* Looks up any default geometry specified in the defaults file and */
3250
/* returns the values found there. Geometry should be of the form */
3251
/* [=][<width>x<height>][{+-}<xoffset>{+-}<yoffset>] */
3253
/* The result returned indicates which values were set. */
3254
/* XValue, YValue, WidthValue, HeightValue */
3256
/*****************************************************************************/
3259
checkGeometry(char *name, int *x, int *y, int *width, int *height)
3261
char buf[80], *geom_default;
3263
sprintf(buf, "%s.geometry", name);
3264
geom_default = getdefault(buf);
3266
return 0; /* nothing set */
3268
return XParseGeometry(geom_default, x, y, (unsigned int *) width, (unsigned int *) height);
3271
void checkParent(char *name, W_Window * parent)
3276
struct windowlist *windows;
3278
sprintf(buf, "%s.parent", name);
3279
adefault = getdefault(buf);
3280
if (adefault == NULL)
3282
/* parent must be name of other window or "root" */
3283
if (strcmpi(adefault, "root") == 0)
3285
*parent = W_Window2Void(&myroot);
3288
for (i = 0; i < HASHSIZE; i++)
3290
windows = hashtable[i];
3291
while (windows != NULL)
3293
if (strcmpi(adefault, windows->window->name) == 0)
3295
*parent = W_Window2Void(windows->window);
3298
windows = windows->next;
3303
int checkMapped(char *name)
3307
sprintf(buf, "%s.mapped", name);
3308
return booleanDefault(buf, 0);
3311
int checkMappedPref(char *name, int preferred)
3315
sprintf(buf, "%s.mapped", name);
3316
return booleanDefault(buf, preferred);
3320
W_WarpPointer(W_Window window, int x, int y)
3322
static int warped_from_x = 0, warped_from_y = 0;
3328
XWarpPointer(W_Display, None, W_Root, 0, 0, 0, 0, warped_from_x, warped_from_y);
3334
findMouse(&warped_from_x, &warped_from_y);
3335
XWarpPointer(W_Display, None, W_Void2Window(window)->window, 0, 0, 0, 0, 0, 0);
3340
void findMouse(int *x, int *y)
3342
Window theRoot, theChild;
3343
int wX, wY, rootX, rootY, status;
3344
unsigned int wButtons;
3346
status = XQueryPointer(W_Display, W_Root, &theRoot, &theChild, &rootX, &rootY, &wX, &wY, &wButtons);
3360
findMouseInWin(int *x, int *y, W_Window w)
3362
Window theRoot, theChild;
3363
int wX, wY, rootX, rootY, status;
3364
unsigned int wButtons;
3365
struct window *win = W_Void2Window(w);
3366
Window thisWin = win->window;
3368
status = XQueryPointer(W_Display, thisWin, &theRoot, &theChild,
3369
&rootX, &rootY, &wX, &wY, &wButtons);
3372
/* if it's in the window we specified then the values returned should *
3374
* * be within the with and height of the window */
3375
if (wX <= win->width && wY <= win->height)
3392
#define MAKE_WINDOW_GETTER(name, part) \
3393
W_Callback name(W_Window w) \
3395
return W_Void2Window(w)->part; \
3398
#define MAKE_WINDOW_SETTER(name, part) \
3399
void name(W_Window w, W_Callback c) \
3401
W_Void2Window(w)->part = c; \
3404
MAKE_WINDOW_GETTER(W_GetWindowKeyDownHandler, handle_keydown)
3405
MAKE_WINDOW_SETTER(W_SetWindowKeyDownHandler, handle_keydown)
3407
MAKE_WINDOW_GETTER(W_GetWindowKeyUpHandler, handle_keyup)
3408
MAKE_WINDOW_SETTER(W_SetWindowKeyUpHandler, handle_keyup)
3410
MAKE_WINDOW_GETTER(W_GetWindowButtonHandler, handle_button)
3411
MAKE_WINDOW_SETTER(W_SetWindowButtonHandler, handle_button)
3413
MAKE_WINDOW_GETTER(W_GetWindowExposeHandler, handle_expose)
3414
MAKE_WINDOW_SETTER(W_SetWindowExposeHandler, handle_expose)
3417
W_ResizeWindow(W_Window window, int neww, int newh) /* TSH 2/93 */
3422
Window win = W_Void2Window(window)->window;
3423
XSizeHints *sz_hints;
3425
sz_hints = XAllocSizeHints();
3426
sz_hints->min_width = (unsigned int) neww;
3427
sz_hints->max_width = (unsigned int) neww;
3428
sz_hints->min_height = (unsigned int) newh;
3429
sz_hints->max_height = (unsigned int) newh;
3430
sz_hints->flags = PMinSize | PMaxSize;
3431
XSetWMNormalHints(W_Display, win, sz_hints);
3432
XResizeWindow(W_Display, win, (unsigned int) neww, (unsigned int) newh);
3436
W_ReinitMenu(W_Window window, int neww, int newh)
3438
struct window *win = W_Void2Window(window);
3439
struct menuItem *items;
3442
items = (struct menuItem *) win->data;
3443
for(i=0; i< win->height; i++){
3444
free((char *) items[i].string);
3446
free ((char *)items);
3447
items = (struct menuItem *) malloc(newh * sizeof(struct menuItem));
3448
for(i=0; i< newh; i++){
3449
items[i].column = 0;
3450
items[i].string = (char *) malloc(MAX_TEXT_WIDTH);
3451
items[i].color = W_White;
3453
win->data = (char *) items;
3456
/* this procedure should only be used if the menu is initially defined
3457
by W_MakeMenu as large as it will get. If menu may grow, call
3458
W_ReinitMenu first */
3461
W_ResizeMenu(W_Window window, int neww, int newh) /* TSH 2/93 */
3463
struct window *w = W_Void2Window(window);
3468
W_ResizeWindow(window, neww*W_Textwidth+WIN_EDGE*2,
3469
newh*(W_Textheight+MENU_PAD*2)+(newh-1)*MENU_BAR);
3473
W_ResizeTextWindow(W_Window window, int neww, int newh) /* TSH
3483
W_ResizeWindow(window, neww * W_Textwidth + WIN_EDGE * 2,
3484
newh * W_Textheight + WIN_EDGE * 2);
3490
return (DisplayCells(W_Display, W_Screen) <= 2) || forceMono;
3494
W_EventsQueued(void)
3496
return XEventsQueued(W_Display, QueuedAlready);
3500
W_EventsQueuedCk(void)
3502
return XEventsQueued(W_Display, QueuedAfterReading);
3505
int W_ReadEvents(void)
3508
struct timeval timeout = {0, 0};
3512
FD_SET(ConnectionNumber(W_Display), &readfds);
3513
if (SELECT(max_fd, &readfds, 0, 0, &timeout) == 1)
3515
XPeekEvent(W_Display, &event);
3521
void W_OverlayBitmap(int x, int y, W_Icon bit, W_Color color)
3523
struct icon *icon = W_Void2Icon(bit);
3526
printf("Overlaying bitmap to %d\n", icon->window);
3529
XCopyPlane(W_Display, icon->bitmap, icon->window,
3530
colortable[color].contexts[0], 0, 0, icon->width, icon->height,
3534
void W_SetWindowName(W_Window w, char *name)
3536
struct window *win = W_Void2Window(w);
3538
XStoreName(W_Display, win->window, name);
3545
static XFontStruct *_tts_fontinfo;
3546
static int _tts_th, _tts_tw;
3549
W_TTSTextHeight(void)
3555
W_TTSTextWidth(char *s, int l)
3557
return XTextWidth(_tts_fontinfo, s, l);
3569
fontname = getdefault("tts_font");
3571
fontname = TTS_FONT;
3573
#ifdef SHOW_DEFAULTS
3574
show_defaults("TTS", "tts_font", fontname, "TTS font.");
3578
if (forceMono || DisplayCells(W_Display, W_Screen) <= 2)
3580
/* this is not going to work at all for b/w */
3582
F_beeplite_flags &= ~LITE_TTS;
3587
_tts_fontinfo = XLoadQueryFont(W_Display, fontname);
3590
fprintf(stderr, "netrek: Can't find font \"%s\".\n", fontname);
3591
_tts_fontinfo = XLoadQueryFont(W_Display, "fixed");
3595
fprintf(stderr, "netrek: Can't find any fonts.\n");
3598
_tts_th = _tts_fontinfo->max_bounds.descent +
3599
_tts_fontinfo->max_bounds.ascent;
3600
_tts_tw = _tts_fontinfo->max_bounds.width;
3602
values.font = _tts_fontinfo->fid;
3604
if (forceMono || DisplayCells(W_Display, W_Screen) <= 2)
3606
values.foreground = colortable[W_White].pixelValue;
3607
values.function = GXor;
3613
color = getdefault("tts_color");
3617
#ifdef SHOW_DEFAULTS
3618
show_defaults("TTS", "tts_color", color, "TTS msg color.");
3621
if (!XParseColor(W_Display, W_Colormap, color, &xc))
3623
fprintf(stderr, "netrek: Unknown tts_color \"%s\", using #777\n", color);
3624
(void) XParseColor(W_Display, W_Colormap, "#777", &xc);
3626
/* using the 8th color allocated in GetColors() */
3627
xc.pixel = colortable[W_Black].pixelValue | planes[0] | planes[2];
3628
if ((takeNearest) || (W_Visual->class != PseudoColor))
3629
XAllocColor(W_Display, W_Colormap, &xc);
3631
XStoreColor(W_Display, W_Colormap, &xc);
3632
values.foreground = xc.pixel;
3633
values.function = GXor;
3636
_tts_gc = XCreateGC(W_Display, W_Root, GCFont | GCForeground | GCFunction,
3639
XSetGraphicsExposures(W_Display, _tts_gc, False);
3643
W_EraseTTSText(W_Window window, int max_width, int y, int width)
3645
// struct window *win = W_Void2Window(window);
3646
int x = (max_width - width) / 2;
3650
y -= W_TTSTextHeight();
3652
W_ClearArea(window, x, y, width, W_TTSTextHeight());
3656
W_WriteTTSText(W_Window window, int max_width, int y, int width, char *str, int len)
3659
/* max_width of window */
3663
/* length of string */
3665
struct window *win = W_Void2Window(window);
3666
int x = (max_width - width) / 2;
3671
y -= _tts_fontinfo->max_bounds.descent;
3673
/* y -= W_TTSTextHeight(); y += _tts_fontinfo->max_bounds.ascent; */
3675
XDrawString(W_Display, win->window, _tts_gc, x, y, str, len);
3680
void W_Halo(int x, int y, W_Color color)
3682
struct window *win = W_Void2Window(mapw);
3684
if ((color != W_Ind) && (color != W_Grey))
3686
XSetForeground(W_Display, colortable[color].contexts[0],
3687
colortable[color].pixelValue);
3688
XDrawArc(W_Display, win->window, colortable[color].contexts[0],
3689
x - (mplanet_width / 2), y - (mplanet_width / 2),
3690
mplanet_width, mplanet_height, 0, 23040);
3693
#endif /* HAVE_XPM */
3695
void W_CameraSnap(W_Window window)
3698
struct window *win = W_Void2Window(window);
3699
camera_snap(W_Display, win->window);
3701
fprintf(stderr, "W_CameraSnap: function not implemented in this build.");
3707
/* XFree86 VidMode X extension handling */
3709
#include <X11/extensions/xf86vmode.h>
3711
XF86VidModeModeInfo **video_mode_list;
3712
XF86VidModeModeInfo *video_mode_current, *video_mode_original;
3713
int video_mode_dotclock, video_mode_list_size;
3715
/* restore video mode to known previous mode */
3716
static void video_mode_off()
3718
if (video_mode_current != video_mode_original) {
3720
x = XF86VidModeSwitchToMode(W_Display, W_Screen, video_mode_original);
3722
fprintf(stderr, "video_mode_off: XF86VidModeSwitchToMode: %d\n", x);
3724
video_mode_current = video_mode_original;
3728
/* check if X server has support for changing modes */
3729
static int video_mode_initialise() {
3731
if (!XF86VidModeQueryVersion(W_Display, &major, &minor)) {
3732
fprintf(stderr, "video_mode_initialise: XFree86-VidMode X extension absent\n");
3736
static int done = 0;
3741
XF86VidModeModeLine current;
3743
/* obtain the current mode line and list of known mode lines */
3744
XF86VidModeGetModeLine(W_Display, W_Screen, &video_mode_dotclock, ¤t);
3745
XF86VidModeGetAllModeLines(W_Display, W_Screen,
3746
&video_mode_list_size, &video_mode_list);
3748
/* find the current mode within the list of known mode lines */
3749
video_mode_current = NULL;
3750
for (line=0; line < video_mode_list_size; line++) {
3751
XF86VidModeModeInfo *mode = video_mode_list[line];
3752
if (mode->hdisplay == current.hdisplay &&
3753
mode->vdisplay == current.vdisplay &&
3754
mode->dotclock == video_mode_dotclock &&
3755
mode->htotal == current.htotal &&
3756
mode->vtotal == current.vtotal &&
3757
mode->flags == current.flags) {
3758
video_mode_original = video_mode_current = mode;
3762
/* do not change if the current mode was not found */
3763
if (video_mode_current == NULL) {
3764
fprintf(stderr, "video_mode_begin: this mode not found, "
3765
"cannot switch back, so not switching\n");
3772
static void video_mode_on()
3776
/* if there is a mode line for 1024x768 then use it */
3777
for (line=0; line < video_mode_list_size; line++) {
3778
XF86VidModeModeInfo *mode = video_mode_list[line];
3779
if (mode->hdisplay == 1024 && mode->vdisplay == 768) {
3781
x = XF86VidModeSwitchToMode(W_Display, W_Screen, mode);
3783
fprintf(stderr, "video_mode_on: XF86VidModeSwitchToMode: %d\n", x);
3785
/*! @bug: if this is done on a non-local display, the X error
3786
XF86VidModeClientNotLocal occurs. */
3787
video_mode_current = mode;
3793
static void view_port_warp(W_Window window)
3795
struct window *win = W_Void2Window(window);
3797
/* force the video view port to cover the window */
3800
XTranslateCoordinates(W_Display, win->window, W_Root, 0, 0, &tx, &ty, &child);
3801
XF86VidModeSetViewPort(W_Display, W_Screen, tx, ty);
3802
XMoveResizeWindow(W_Display, win->window, 0, 0, 1024, 768);
3803
XMapRaised(W_Display, win->window);
3804
XRaiseWindow(W_Display, win->window);
3807
/* force the cursor to stay within the window */
3808
static void pointer_grab_on(W_Window window)
3810
struct window *win = W_Void2Window(window);
3812
XGrabPointer(W_Display, win->window, True, ButtonPressMask |
3813
ButtonReleaseMask | EnterWindowMask | LeaveWindowMask |
3814
PointerMotionMask | PointerMotionHintMask |
3815
Button1MotionMask | Button2MotionMask |
3816
Button3MotionMask | Button4MotionMask |
3817
Button5MotionMask | ButtonMotionMask |
3818
KeymapStateMask, GrabModeAsync, GrabModeAsync,
3819
win->window, None, CurrentTime);
3820
XGrabKeyboard(W_Display, win->window, True, GrabModeAsync,
3821
GrabModeAsync, CurrentTime);
3824
static void pointer_grab_off(W_Window window)
3826
XUngrabPointer(W_Display, CurrentTime);
3827
XUngrabKeyboard(W_Display, CurrentTime);
3830
static void kde_fullscreen_on(W_Window window) {
3831
struct window *win = W_Void2Window(window);
3833
WM_HINTS = XInternAtom(W_Display, "_NET_WM_STATE", True);
3834
if (WM_HINTS != None) {
3836
p[0] = XInternAtom(W_Display, "_NET_WM_STATE_FULLSCREEN", True);
3837
XChangeProperty(W_Display, win->window, WM_HINTS, XA_ATOM, 32,
3838
PropModeReplace, (unsigned char *)p, 1);
3842
static void kde_fullscreen_off(W_Window window) {
3843
struct window *win = W_Void2Window(window);
3845
WM_HINTS = XInternAtom(W_Display, "_NET_WM_STATE", True);
3846
if (WM_HINTS != None) {
3847
XDeleteProperty(W_Display, win->window, WM_HINTS);
3851
#endif /* FULLSCREEN */
3853
void W_FullScreenOn(W_Window window)
3857
fprintf(stderr, "W_FullScreenOn\n");
3860
view_port_warp(window);
3861
pointer_grab_on(window);
3862
kde_fullscreen_on(window);
3866
void W_FullScreenOff(W_Window window)
3870
fprintf(stderr, "W_FullScreenOff\n");
3872
pointer_grab_off(window);
3873
kde_fullscreen_off(window);
3878
void W_FullScreenInitialise() {
3881
fprintf(stderr, "W_FullScreenInitialise\n");
3883
full_screen_enabled = 0;
3884
full_screen_default = 0;
3885
if (booleanDefault("FullScreen", 0)) {
3886
// FIXME: when this is on in .xtrekrc normal resolution may not be restored
3887
full_screen_default++;
3888
if (video_mode_initialise())
3889
full_screen_enabled++;
3894
int W_FullScreenToggle(W_Window window) {
3897
fprintf(stderr, "W_FullScreenToggle\n");
3899
if (full_screen_enabled) {
3900
full_screen_enabled = 0;
3901
W_FullScreenOff(window);
3903
if (!full_screen_default) {
3904
if (!video_mode_initialise()) {
3905
return FULLSCREEN_FAILED;
3908
full_screen_enabled++;
3909
W_FullScreenOn(window);
3911
return FULLSCREEN_OK;
3913
return FULLSCREEN_NOT_COMPILED;
3917
void W_FullScreenBegin(W_Window window) {
3920
fprintf(stderr, "W_FullScreenBegin\n");
3922
if (full_screen_enabled) {
3923
W_FullScreenOn(window);
3928
/* regularly enforce */
3929
void W_FullScreen(W_Window window) {
3931
if (full_screen_enabled) {
3932
view_port_warp(window);
3933
pointer_grab_on(window);