1 /*
2 // window.c
3 */
4 
5 #include "xbook.h"
6 
7 char AppName[ BUFSIZE + 1 ];
8 
CreateWindow(display,parent,x,y,width,height,border,fore,back,events)9 Window CreateWindow( display, parent, x, y, width, height, border, fore, back,
10 events )
11 Display	*display;
12 Window	parent;
13 int	x, y, width, height, border;
14 unsigned int	fore, back;
15 long	events;
16 {
17 	Window	window;
18 	XSetWindowAttributes	attributes;
19 	unsigned long		attribute_mask;
20 	Visual			*visual = CopyFromParent;
21 
22 	attributes.background_pixel	= back;
23 	attributes.border_pixel		= fore;
24 	attributes.event_mask		= events;
25 	attribute_mask			= CWBackPixel | CWBorderPixel |
26 						CWEventMask;
27 
28 	window = XCreateWindow( display,
29 				parent,
30 				x, y, width, height,
31 				border,
32 				CopyFromParent,
33 				InputOutput,
34 				visual,
35 				attribute_mask,
36 				&attributes );
37 
38 	if( window == (Window) None )
39 	{
40 		QuitX( display, "",
41 			"Error: Could not open window." );
42 	}
43 	return( window );
44 }
45 
CheckGeometry(argc,argv,screen_width,screen_height,x,y,width,height)46 CheckGeometry( argc, argv, screen_width, screen_height, x, y, width, height )
47 int argc;
48 char *argv[];
49 int screen_width, screen_height;
50 int *x, *y, *width, *height;
51 {
52 	int status;
53 	int x1, y1, width1, height1;
54 	int counter;
55 
56 	counter = 1;
57 	while( counter < argc )
58 	{
59 		if( strncmp( argv[ counter ], "-geom", 5 ) == 0)
60 		{
61 			counter++;
62 			if( counter < argc )
63 			{
64 				status = XParseGeometry( argv[ counter ],
65 					&x1, &y1, &width1, &height1 );
66 				if( status & XValue )
67 					*x = x1;
68 				if( status & YValue )
69 					*y = y1;
70 				if( status & WidthValue )
71 					*width = width1;
72 				if( status & HeightValue )
73 					*height = height1;
74 				if( status & XNegative )
75 					*x = screen_width - *width + *x;
76 				if( status & YNegative )
77 					*y = screen_height - *height + *y;
78 			}
79 		}
80 		counter++;
81 	}
82 }
83 
MapWindow(display,window)84 MapWindow( display, window )
85 Display *display;
86 Window window;
87 {
88 	XMapRaised( display, window );
89 	XMapSubwindows( display, window );
90 	XFlush( display );
91 }
92 
NameWindow(display,window,name,class_name,class_type)93 NameWindow( display, window, name, class_name, class_type )
94 Display *display;
95 Window window;
96 char *name;
97 char *class_name;
98 char *class_type;
99 {
100 	XClassHint	*classhints;
101 #ifdef X11R4
102 	classhints = XAllocClassHint();
103 #else
104 	classhints = (XClassHint *) malloc( sizeof( XClassHint ) );
105 #endif
106 	if( classhints != (XClassHint *) NULL )
107 	{
108 		classhints->res_name = class_name;
109 		classhints->res_class = class_type;
110 		XSetClassHint( display, window, classhints );
111 #ifdef X11R4
112 	XFree( classhints );
113 #else
114 	free( classhints );
115 #endif
116 	}
117 	XStoreName( display, window, name );
118 	XSetIconName( display, window, name );
119 	(void) strcpy( AppName, name );
120 }
121 
SetWMHints(display,window,icon)122 SetWMHints( display, window, icon )
123 Display *display;
124 Window window;
125 Pixmap icon;
126 {
127 	XWMHints	*wmhints;
128 #ifdef X11R4
129 	wmhints	=	XAllocWMHints();
130 #else
131 	wmhints =	(XWMHints *) malloc( sizeof( XWMHints ) );
132 #endif
133 	if( wmhints != (XWMHints *) NULL )
134 	{
135 		wmhints->initial_state 	= NormalState;
136 		wmhints->input		= True;
137 		if( icon != (Pixmap) None )
138 		{
139 			wmhints->icon_pixmap	= icon;
140 			wmhints->icon_mask	= icon;
141 			wmhints->flags		= StateHint	|
142 						  InputHint	|
143 						  IconPixmapHint |
144 						  IconMaskHint;
145 		}
146 		else
147 		{
148 			wmhints->flags	= StateHint | InputHint;
149 		}
150 		XSetWMHints( display, window, wmhints );
151 #ifdef X11R6
152 		XFree( wmhints );
153 #else
154 		free( wmhints );
155 #endif
156 	}
157 }
158 
SetNormalHints(display,window,x,y,width,height)159 SetNormalHints( display, window, x, y, width, height )
160 Display		*display;
161 Window		window;
162 int		x, y, width, height;
163 {
164 	XSizeHints	*sizehints;
165 #ifdef X11R4
166 	sizehints = XAllocSizeHints();
167 #else
168 	sizehints = (XSizeHints *) malloc( sizeof( XSizeHints ) );
169 #endif
170 	if( sizehints != (XSizeHints *) NULL )
171 	{
172 		sizehints->x		=x;
173 		sizehints->y		=y;
174 		sizehints->width	=width;
175 		sizehints->height	=height;
176 		sizehints->min_width	=100;
177 		sizehints->min_height	=50;
178 		sizehints->flags	=USPosition | USSize | PMinSize;
179 #ifdef X11R4
180 		sizehints->base_width	=width;
181 		sizehints->base_height	=height;
182 		sizehints->flags	|= PBaseSize;
183 		XSetWMNormalHints( display, window, sizehints );
184 		XFree( sizehints );
185 #else
186 		XSetNormalHints( display, window, sizehints );
187 		free( sizehints );
188 #endif
189 	}
190 }
191 
GetAppName(name)192 GetAppName( name )
193 char *name;
194 {
195 	(void) strcpy(name , AppName );
196 }
197