Debian Codegraph @

clients/mwm/WmWsmLib/disp.c

raw
1 /* $TOG: disp.c /main/6 1997/06/18 17:34:28 samborn $ */
2 /*
3 * Motif
4 *
5 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
6 *
7 * These libraries and programs are free software; you can
8 * redistribute them and/or modify them under the terms of the GNU
9 * Lesser General Public License as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * These libraries and programs are distributed in the hope that
14 * they will be useful, but WITHOUT ANY WARRANTY; without even the
15 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU Lesser General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with these librararies and programs; if not, write
21 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
22 * Floor, Boston, MA 02110-1301 USA
23 *
24 */
25 /*
26 * HISTORY
27 */
28
29 #include "wsm_proto.h"
30
31 WSMDispInfo * GDispInfo = NULL;
32
33 /* Function Name: _WSMGetDispInfo
34 * Description: Gets the display information structure associated with
35 * the display passed into this function.
36 * Arguments: dpy - The Display to get the info for.
37 * Returns: a WSMDispInfo structure for the display passed.
38 */
39
40 WSMDispInfo *
41 _WSMGetDispInfo(Display *dpy)
42 {
43 enum { XA_WSM_NAME_CONNECT, XA_WSM_NAME_EXTENSIONS, XA_WSM_NAME_CONFIG_FMT,
44 XA_WSM_NAME_GET_STATE, XA_WSM_NAME_SET_STATE, XA_WSM_NAME_REG_WINDOW,
45 XA_WSM_NAME_WM_GET_BACKGROUND_WINDOW,
46 XA_WSM_NAME_WM_SET_BACKGROUND_WINDOW, XA_WSM_NAME_WM_WINDOWS,
47 XA_WSM_NAME_WM_FOCUS, XA_WSM_NAME_WM_POINTER, XA_TARGETS,
48 XA_MULTIPLE, XA_TIMESTAMP, NUM_ATOMS };
49 static char *atom_names[] = {
50 WSM_NAME_CONNECT, WSM_NAME_EXTENSIONS, WSM_NAME_CONFIG_FMT,
51 WSM_NAME_GET_STATE, WSM_NAME_SET_STATE, WSM_NAME_REG_WINDOW,
52 WSM_NAME_WM_GET_BACKGROUND_WINDOW,
53 WSM_NAME_WM_SET_BACKGROUND_WINDOW, WSM_NAME_WM_WINDOWS,
54 WSM_NAME_WM_FOCUS, WSM_NAME_WM_POINTER, "TARGETS",
55 "MULTIPLE", "TIMESTAMP" };
56
57 WSMDispInfo * disp_info;
58 Atom atoms[XtNumber(atom_names)];
59
60 if (GDispInfo == NULL) {
61 disp_info = GDispInfo = (WSMDispInfo *) XtMalloc(sizeof(WSMDispInfo));
62 }
63 else {
64 disp_info = GDispInfo;
65
66 while (True) {
67 if (disp_info->disp == dpy)
68 return(disp_info);
69
70 if (disp_info->next == NULL)
71 break;
72
73 disp_info = disp_info->next;
74 }
75
76 /*
77 * This display is not on the global list, add it.
78 */
79
80 disp_info->next = (WSMDispInfo *) XtMalloc(sizeof(WSMDispInfo));
81 disp_info = disp_info->next;
82 }
83
84 disp_info->disp = dpy;
85
86 /*
87 * These are our names.
88 *
89 * ||| Should use XtConvertAndStore().
90 */
91
92 XInternAtoms(dpy, atom_names, XtNumber(atom_names), False, atoms);
93
94 disp_info->connect = atoms[XA_WSM_NAME_CONNECT];
95 disp_info->extensions = atoms[XA_WSM_NAME_EXTENSIONS];
96 disp_info->config_fmt = atoms[XA_WSM_NAME_CONFIG_FMT];
97 disp_info->get_state = atoms[XA_WSM_NAME_GET_STATE];
98 disp_info->set_state = atoms[XA_WSM_NAME_SET_STATE];
99 disp_info->reg_window = atoms[XA_WSM_NAME_REG_WINDOW];
100
101 disp_info->get_background = atoms[XA_WSM_NAME_WM_GET_BACKGROUND_WINDOW];
102 disp_info->set_background = atoms[XA_WSM_NAME_WM_SET_BACKGROUND_WINDOW];
103
104 disp_info->wm_windows = atoms[XA_WSM_NAME_WM_WINDOWS];
105 disp_info->wm_focus = atoms[XA_WSM_NAME_WM_FOCUS];
106 disp_info->wm_pointer = atoms[XA_WSM_NAME_WM_POINTER];
107
108 /*
109 * These global resources are unlikely to change.
110 */
111
112 disp_info->targets = atoms[XA_TARGETS];
113 disp_info->multiple = atoms[XA_MULTIPLE];
114 disp_info->timestamp = atoms[XA_TIMESTAMP];
115
116 disp_info->screen_info = NULL;
117 disp_info->next = NULL;
118
119 return(disp_info);
120 }
121
122 /* Function Name: _WSMGetScreenInfo
123 * Description: Gets the screen information structure associated with
124 * the display and screen passed into this function.
125 * Arguments: dpy - The Display to get the info for.
126 * screen_number - The screen number.
127 * Returns: a WSMScreenInfo structure for the display passed.
128 */
129
130 WSMScreenInfo *
131 _WSMGetScreenInfo(Display *dpy, int screen_number)
132 {
133 WSMDispInfo * disp_info = _WSMGetDispInfo(dpy);
134 WSMScreenInfo *screen_info;
135 char temp[BUFSIZ];
136
137 if (disp_info->screen_info == NULL) {
138 /*
139 * Didn't find any screen info on this display, allocate it
140 * and then drop down to the code below that fills in the data.
141 */
142
143 screen_info = (WSMScreenInfo *) XtMalloc(sizeof(WSMScreenInfo));
144 disp_info->screen_info = screen_info;
145 }
146 else {
147 screen_info = disp_info->screen_info;
148
149 /*
150 * Hunt through the screen info structs on this display until we
151 * find one that matches the screen num passed. If we don't find
152 * one then allocate a new one, put it on the end of the list and
153 * drop into the code below that fills in the data.
154 */
155
156 while (True) {
157 if (screen_info->screen_num == screen_number)
158 return(screen_info);
159
160 if (screen_info->next == NULL)
161 break;
162
163 screen_info = screen_info->next;
164 }
165
166 /*
167 * This screen is not on the display's screen list, add it.
168 */
169
170 screen_info->next = (WSMScreenInfo *) XtMalloc(sizeof(WSMScreenInfo));
171 screen_info = screen_info->next;
172 }
173
174 screen_info->screen_num = screen_number;
175
176 sprintf(temp, WM_SELECTION_FORMAT, screen_number);
177 screen_info->wm_selection = XInternAtom(dpy, temp, False);
178
179 sprintf(temp, WSM_SELECTION_FORMAT, screen_number);
180 screen_info->wsm_selection = XInternAtom(dpy, temp, False);
181
182 screen_info->next = NULL;
183 screen_info->global.num_attrs = 0;
184 screen_info->window.num_attrs = 0;
185 screen_info->icon.num_attrs = 0;
186 screen_info->request_callback = NULL;
187 screen_info->request_data = NULL;
188
189 return(screen_info);
190 }
191
192
193
194
195
196 /* Function Name: _WSMClearConfigScreenInfo
197 * Description: Resets the screen information structure associated with
198 * the display and screen passed into this function.
199 * Arguments: dpy - The Display to get the info for.
200 * screen_number - The screen number.
201 * Returns:
202 */
203
204 void
205 _WSMClearConfigScreenInfo(Display *dpy, int screen_number)
206 {
207 WSMDispInfo * disp_info = _WSMGetDispInfo(dpy);
208 WSMScreenInfo *screen_info;
209
210 if (disp_info->screen_info != NULL)
211 {
212 screen_info = disp_info->screen_info;
213
214 /*
215 * Hunt through the screen info structs on this display until we
216 * find one that matches the screen num passed.
217 */
218
219 while (True) {
220 if (screen_info->screen_num == screen_number)
221 break;
222
223 if (screen_info->next == NULL)
224 return;
225
226 screen_info = screen_info->next;
227 }
228
229 if (screen_info->global.num_attrs != 0){
230 XtFree((XtPointer)screen_info->global.attr_list);
231 screen_info->global.num_attrs = 0;
232 }
233
234 if (screen_info->window.num_attrs != 0){
235 XtFree((XtPointer)screen_info->window.attr_list);
236 screen_info->window.num_attrs = 0;
237 }
238
239 if (screen_info->icon.num_attrs != 0){
240 XtFree((XtPointer)screen_info->icon.attr_list);
241 screen_info->icon.num_attrs = 0;
242 }
243 }
244
245 }
246
247
248
249 /* Function Name: _WSMGetConfigFormat
250 * Description: Gets the Configuration format for the dpy, scr and
251 * type specified.
252 * Arguments: dpy - The display.
253 * screen_number - The screen number.
254 * type - The type of format required.
255 * Returns: A pointer to the config format, or NULL if none was
256 * found.
257 */
258
259 WSMConfigFormatData *
260 _WSMGetConfigFormat(Display *dpy, int screen_number, WSMConfigFormatType type)
261 {
262 WSMScreenInfo *screen_info = _WSMGetScreenInfo(dpy, screen_number);
263
264 if (screen_info == NULL)
265 return(NULL);
266
267 switch(type) {
268 case WSM_GLOBAL_FMT:
269 return(&(screen_info->global));
270 case WSM_WINDOW_FMT:
271 return(&(screen_info->window));
272 case WSM_ICON_FMT:
273 return(&(screen_info->icon));
274 default:
275 break;
276 }
277
278 return(NULL);
279 }
280
281 /* Function Name: _WSMGetSelectionAtom
282 * Description: Gets the Selection atom for the manager that we want to
283 * send to.
284 * Arguments: dpy - The display.
285 * screen_number - The screen number.
286 * send_to - Whether to send this to the WM or WSM.
287 * Returns: A pointer to the config format, or NULL if none was
288 * found.
289 */
290
291 Atom
292 _WSMGetSelectionAtom(Display *dpy, int screen_num, WSMClientType send_to)
293 {
294 WSMScreenInfo *screen_info = _WSMGetScreenInfo(dpy, screen_num);
295
296 if (screen_info == NULL)
297 return(None);
298
299 switch(send_to) {
300 case WSM_WORKSPACE_MANAGER:
301 return(screen_info->wsm_selection);
302 case WSM_WINDOW_MANAGER:
303 return(screen_info->wm_selection);
304 default:
305 break;
306 }
307
308 return(None);
309 }