Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtstyle / Keyboard.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /************************************<+>*************************************
24  ****************************************************************************
25  **
26  **   File:        Keyboard.c
27  **
28  **   Project:     DT 3.0
29  **
30  **   Description: Controls the DtStyle keyboard dialog
31  **
32  **
33  **  (c) Copyright Hewlett-Packard Company, 1990.  
34  **
35  **
36  **
37  ****************************************************************************
38  ************************************<+>*************************************/
39 /* $XConsortium: Keyboard.c /main/4 1995/10/30 13:10:18 rswiston $ */
40
41 /*+++++++++++++++++++++++++++++++++++++++*/
42 /* include files                         */
43 /*+++++++++++++++++++++++++++++++++++++++*/
44
45 #include <X11/Xlib.h>
46 #include <Xm/MwmUtil.h>
47
48 #include <Xm/Xm.h>
49 #include <Xm/XmP.h>
50 #include <Xm/Form.h>
51 #include <Xm/LabelG.h>
52 #include <Xm/PushBG.h>
53 #include <Xm/Scale.h>
54 #include <Xm/ToggleBG.h>
55 #include <Xm/VendorSEP.h>
56
57 #include <Dt/DialogBox.h>
58 #include <Dt/Icon.h>
59
60 #include <Dt/Message.h>
61 #include <Dt/HourGlass.h>
62
63 #include "Help.h"
64 #include "Main.h"
65 #include "SaveRestore.h"
66 #include "Protocol.h"
67
68 /*+++++++++++++++++++++++++++++++++++++++*/
69 /* include extern functions              */
70 /*+++++++++++++++++++++++++++++++++++++++*/
71 #include "Keyboard.h"
72
73 /*+++++++++++++++++++++++++++++++++++++++*/
74 /* Local #defines                        */
75 /*+++++++++++++++++++++++++++++++++++++++*/
76 #define VOLUME_MAX       100
77 #define SCALE_WIDTH      200
78
79 /*+++++++++++++++++++++++++++++++++++++++*/
80 /* Internal Functions                    */
81 /*+++++++++++++++++++++++++++++++++++++++*/
82
83
84 static Widget build_keyboardDlg( Widget shell) ;
85 static void layoutCB( 
86                         Widget w,
87                         XtPointer client_data,
88                         XtPointer call_data) ;
89 static void _DtmapCB_keyboardDlg( 
90                         Widget w,
91                         XtPointer client_data,
92                         XtPointer call_data) ;
93 static int getValue( Widget w) ;
94 static void valueChangedCB( 
95                         Widget w,
96                         XtPointer client_data,
97                         XtPointer call_data) ;
98 static void autoRepeatToggleCB( 
99                         Widget w,
100                         XtPointer client_data,
101                         XtPointer call_data) ;
102 static void systemDefaultCB( 
103                         Widget w,
104                         XtPointer client_data,
105                         XtPointer call_data) ;
106 static void ButtonCB( 
107                         Widget w,
108                         XtPointer client_data,
109                         XtPointer call_data) ;
110
111
112 /*+++++++++++++++++++++++++++++++++++++++*/
113 /* Internal Variables                    */
114 /*+++++++++++++++++++++++++++++++++++++++*/
115
116 typedef struct {
117     Widget          pictLabel;
118     Widget          systemDefault;
119     Widget          volumeLabGad;
120     Widget          volumeScale;
121     Widget          autoRepeatToggle;
122     XKeyboardState  values;
123     int             new_key_click_percent;
124     int             new_autoRepeat;
125     Boolean         systemDefaultFlag;
126 } Kbd, *KdbPtr;
127
128 static Kbd kbd;
129 static saveRestore save = {FALSE, 0, };
130
131 /*+++++++++++++++++++++++++++++++++++++++*/
132 /* popup_kbdDialog                       */
133 /*+++++++++++++++++++++++++++++++++++++++*/
134 void 
135 popup_keyboardBB(
136         Widget shell )
137 {
138     if (style.kbdDialog == NULL) 
139     {
140       _DtTurnOnHourGlass(shell);  
141       build_keyboardDlg(shell);
142       XtManageChild(style.kbdDialog);
143       _DtTurnOffHourGlass(shell);  
144     }
145     else 
146     {
147       XtManageChild(style.kbdDialog);
148       raiseWindow(XtWindow(XtParent(style.kbdDialog)));
149     }
150 }
151
152 /*+++++++++++++++++++++++++++++++++++++++*/
153 /* build__keyboardDlg                    */
154 /*+++++++++++++++++++++++++++++++++++++++*/
155 static Widget 
156 build_keyboardDlg(
157         Widget shell )
158 {
159     register int     i, n;
160     Arg              args[MAX_ARGS];
161     Widget           widget_list[12]; 
162     int              count = 0;
163     Widget           form;
164     Pixel            foreground, background;
165     Boolean          set;
166     XmString         button_string[NUM_LABELS]; 
167     XmString         string;
168
169     /* Set up DialogBoxDialog button labels */
170     button_string[0] = CMPSTR(_DtOkString);
171     button_string[1] = CMPSTR(_DtCancelString);
172     button_string[2] = CMPSTR(_DtHelpString);
173
174     /* Create toplevel DialogBox */
175
176     /* saveRestore
177      * Note that save.poscnt has been initialized elsewhere.  
178      * save.posArgs may contain information from restoreBeep().*/
179
180     XtSetArg(save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS);  
181     save.poscnt++;
182     XtSetArg(save.posArgs[save.poscnt], XmNbuttonLabelStrings, button_string);  
183     save.poscnt++;
184     XtSetArg (save.posArgs[save.poscnt], XmNdefaultPosition, False); 
185     save.poscnt++;
186     style.kbdDialog = __DtCreateDialogBoxDialog(shell, "KeyboardDialog", save.posArgs, save.poscnt);
187     XtAddCallback(style.kbdDialog, XmNcallback, ButtonCB, NULL);
188     XtAddCallback(style.kbdDialog, XmNhelpCallback,
189             (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_KEYBOARD_DIALOG);
190
191     XmStringFree(button_string[0]);
192     XmStringFree(button_string[1]);
193     XmStringFree(button_string[2]);
194
195     widget_list[0] = _DtDialogBoxGetButton(style.kbdDialog,2);
196     n=0;
197     XtSetArg(args[n], XmNautoUnmanage, False); n++;
198     XtSetArg(args[n], XmNcancelButton, widget_list[0]); n++;
199     XtSetValues (style.kbdDialog, args, n);
200
201     n=0;
202     XtSetArg(args[n], XmNtitle, ((char *)GETMESSAGE(13, 6, "Style Manager - Keyboard"))); n++;
203     XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
204     XtSetArg(args[n], XmNmwmFunctions,  DIALOG_MWM_FUNC ); n++;
205     XtSetValues (XtParent(style.kbdDialog), args, n);
206
207     n = 0;
208     XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
209     XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
210     XtSetArg(args[n], XmNallowOverlap, False); n++;
211     XtSetArg(args[n], XmNchildType, XmWORK_AREA);  n++;
212     form = XmCreateForm(style.kbdDialog, "keyboardForm", args, n);
213
214     /* create keyboard pixmap */
215
216     n = 0;
217     XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
218     XtSetArg(args[n], XmNbehavior, XmICON_LABEL); n++;
219     XtSetArg(args[n], XmNpixmapForeground, style.secBSCol); n++;
220     XtSetArg(args[n], XmNpixmapBackground, style.secTSCol); n++;
221     XtSetArg(args[n], XmNstring, NULL); n++;  
222     XtSetArg(args[n], XmNshadowThickness, 0); n++;  
223     XtSetArg(args[n], XmNimageName, KEYBOARD_ICON); n++;  
224     XtSetArg(args[n], XmNtraversalOn, False); n++;  
225     widget_list[count++] = 
226     kbd.pictLabel= _DtCreateIcon(form, "keyboardpictLabel", args, n);
227
228     n = 0;
229     XtSetArg(args[n], XmNmarginHeight, LB_MARGIN_HEIGHT);  n++;
230     XtSetArg(args[n], XmNmarginWidth, LB_MARGIN_WIDTH);  n++;
231     string = CMPSTR(((char *)GETMESSAGE(13, 2, "Default")));
232     XtSetArg(args[n], XmNlabelString, string); n++;
233     XtSetArg(args[n], XmNnavigationType, XmTAB_GROUP); n++;  
234     widget_list[count++] = 
235     kbd.systemDefault= XmCreatePushButtonGadget(form, "systemDefault", args, n);
236     XmStringFree(string);
237     
238     n = 0;
239     set = (kbd.values.global_auto_repeat == AutoRepeatModeOn) ? True : False;
240     XtSetArg(args[n], XmNset, set);  n++;
241     string = CMPSTR(((char *)GETMESSAGE(13, 3, "Auto Repeat")));
242     XtSetArg(args[n], XmNlabelString, string); n++;
243     XtSetArg(args[n], XmNnavigationType, XmTAB_GROUP); n++;  
244     widget_list[count++] = 
245     kbd.autoRepeatToggle= XmCreateToggleButtonGadget(form, "autoRepeatToggle", args, n);
246     XmStringFree(string);
247
248     n = 0;
249     XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
250     string = CMPSTR(((char *)GETMESSAGE(13, 4, "Click Volume")));
251     XtSetArg(args[n], XmNmarginHeight, 0); n++;
252     XtSetArg(args[n], XmNlabelString, string); n++;
253     widget_list[count++] = 
254     kbd.volumeLabGad= XmCreateLabelGadget(form,"volumeLabGad", args, n);
255     XmStringFree(string);
256
257     n = 0;
258     XtSetArg(args[n], XmNmaximum, VOLUME_MAX); n++; 
259     XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
260     XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_RIGHT); n++;
261     XtSetArg(args[n], XmNshowValue, True); n++;
262     XtSetArg(args[n], XmNhighlightThickness, SCALE_HIGHLIGHT_THICKNESS); n++; 
263     XtSetArg(args[n], XmNscaleWidth, SCALE_WIDTH); n++; 
264     widget_list[count++] = 
265     kbd.volumeScale= XmCreateScale(form,"volumeScale", args, n);
266
267     XtAddCallback(style.kbdDialog, XmNmapCallback, layoutCB, NULL);
268     XtAddCallback(style.kbdDialog, XmNmapCallback, _DtmapCB_keyboardDlg, shell);
269     XtAddCallback(kbd.systemDefault, XmNactivateCallback, systemDefaultCB, NULL);
270     XtAddCallback(kbd.volumeScale, XmNvalueChangedCallback, valueChangedCB, NULL);
271     XtAddCallback(kbd.autoRepeatToggle, XmNvalueChangedCallback, autoRepeatToggleCB, NULL);
272
273     XtManageChild(form);
274     XtManageChildren(widget_list,count); 
275
276     return(style.kbdDialog);
277 }
278
279 /*+++++++++++++++++++++++++++++++++++++++*/
280 /* layoutCB                              */
281 /*+++++++++++++++++++++++++++++++++++++++*/
282 static void 
283 layoutCB(
284         Widget w,
285         XtPointer client_data,
286         XtPointer call_data )
287 {
288     int              n;
289     Arg              args[MAX_ARGS];
290
291     /* Picture Label */
292     n=0;
293     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_FORM);       n++;
294     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing);    n++;
295     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);       n++;
296     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);       n++;
297     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
298     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_NONE);       n++;
299     XtSetValues (kbd.pictLabel, args, n);
300
301     /* system Default */
302     n=0;
303     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_FORM);       n++;
304     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing);    n++;
305     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);       n++;
306     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_NONE);       n++;
307     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM);       n++;
308     XtSetArg(args[n], XmNrightOffset,        style.horizontalSpacing);  n++;
309     XtSetValues (kbd.systemDefault, args, n);
310
311     /* auto repeat toggle */
312     n=0;
313     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_WIDGET);     n++;
314     XtSetArg(args[n], XmNtopWidget,          kbd.pictLabel);       n++;
315     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing); n++;
316     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);       n++;
317     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);       n++;
318     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
319     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_NONE);       n++;
320     XtSetValues (kbd.autoRepeatToggle, args, n);
321
322     /* Volume Label */
323     n=0;
324
325     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_NONE);     n++;
326     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_FORM);       n++;
327     XtSetArg(args[n], XmNbottomOffset,       style.verticalSpacing);    n++;
328     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);       n++;
329     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
330     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_NONE);       n++;
331     XtSetValues (kbd.volumeLabGad, args, n);
332
333
334     /* Volume Scale */
335     n=0;
336     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_WIDGET);     n++;
337     XtSetArg(args[n], XmNtopWidget,          kbd.autoRepeatToggle);n++;
338     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing);n++;
339     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_FORM); n++;
340     XtSetArg(args[n], XmNbottomOffset,       style.verticalSpacing);  n++;
341     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_WIDGET);     n++;
342     XtSetArg(args[n], XmNleftWidget,         kbd.volumeLabGad);    n++;
343     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
344     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM);       n++;
345     XtSetValues (kbd.volumeScale, args, n);
346
347     XtRemoveCallback(style.kbdDialog, XmNmapCallback, layoutCB, NULL);
348 }
349
350
351 /*+++++++++++++++++++++++++++++++++++++++*/
352 /* _DtmapCB_keyboardDlg                     */
353 /*+++++++++++++++++++++++++++++++++++++++*/
354 static void 
355 _DtmapCB_keyboardDlg(
356         Widget w,
357         XtPointer client_data,
358         XtPointer call_data )
359 {
360     static int  first_time = 1;
361     int         n;
362     Arg         args[MAX_ARGS];
363     Boolean     set;
364
365     if (first_time)
366     {
367         DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
368
369         if (!save.restoreFlag)
370             putDialog ((Widget)client_data, w);
371
372         first_time = 0;
373     }
374
375     /* get keyboard values for click volume */
376     XGetKeyboardControl(style.display, &kbd.values);
377     kbd.new_key_click_percent = kbd.values.key_click_percent;
378     kbd.new_autoRepeat = kbd.values.global_auto_repeat;
379
380     n=0;
381     XtSetArg(args[n], XmNvalue, kbd.values.key_click_percent); n++;
382     XtSetValues(kbd.volumeScale, args, n);
383
384     n=0;
385     set = (kbd.values.global_auto_repeat == AutoRepeatModeOn) ? True : False;
386     XtSetArg(args[n], XmNset, set);  n++;
387     XtSetValues(kbd.autoRepeatToggle, args, n);
388 }
389
390 static int 
391 getValue(
392         Widget w )
393 {
394     int n, value;
395     Arg args[1];
396
397     n=0;
398     XtSetArg(args[n], XmNvalue, &value); n++;
399     XtGetValues(w, args, n);
400     return(value);
401 }
402
403
404 /*+++++++++++++++++++++++++++++++++++++++*/
405 /* valueChangedCB                        */
406 /*+++++++++++++++++++++++++++++++++++++++*/
407 static void 
408 valueChangedCB(
409         Widget w,
410         XtPointer client_data,
411         XtPointer call_data )
412 {
413
414     XKeyboardControl    kbdControl;
415     int                 kbdControlMask;
416
417     /* set keyboard click volume to scale value */
418
419     kbdControlMask = KBKeyClickPercent;
420     kbdControl.key_click_percent = kbd.new_key_click_percent =
421                   getValue(kbd.volumeScale);
422     XChangeKeyboardControl(style.display, kbdControlMask, &kbdControl);
423     kbd.systemDefaultFlag = False;
424 }
425
426 /*+++++++++++++++++++++++++++++++++++++++*/
427 /* autoRepeatToggleCB                    */
428 /*+++++++++++++++++++++++++++++++++++++++*/
429 static void 
430 autoRepeatToggleCB(
431         Widget w,
432         XtPointer client_data,
433         XtPointer call_data )
434 {
435
436     /* set auto repeat to new value */
437
438     if (((XmToggleButtonCallbackStruct *)call_data)->set)
439     {
440         XAutoRepeatOn(style.display);
441         kbd.new_autoRepeat = AutoRepeatModeOn;
442     }
443     else
444     {
445         XAutoRepeatOff(style.display);
446         kbd.new_autoRepeat = AutoRepeatModeOff;
447     }
448     kbd.systemDefaultFlag = False;
449 }
450
451 /*+++++++++++++++++++++++++++++++++++++++*/
452 /* systemDefaultCB                       */
453 /*+++++++++++++++++++++++++++++++++++++++*/
454 static void 
455 systemDefaultCB(
456         Widget w,
457         XtPointer client_data,
458         XtPointer call_data )
459 {
460     int                 n;
461     Arg                 args[MAX_ARGS];
462     XKeyboardControl    kbdControl;
463     int                 kbdControlMask;
464     XKeyboardState      kbdState;
465     Boolean             set;
466
467     /* set keyboard click volume to system default value */
468
469     kbdControlMask = KBKeyClickPercent | KBAutoRepeatMode;
470     kbdControl.key_click_percent = -1;
471     kbdControl.auto_repeat_mode = AutoRepeatModeDefault;
472     XChangeKeyboardControl(style.display, kbdControlMask, &kbdControl);
473
474     XGetKeyboardControl(style.display, &kbdState);
475
476     n=0;
477     XtSetArg(args[n], XmNvalue, kbdState.key_click_percent); n++;
478     XtSetValues(kbd.volumeScale, args, n);
479
480     n=0;
481     set = (kbdState.global_auto_repeat == AutoRepeatModeOn) ? True : False;
482     XtSetArg(args[n], XmNset, set);  n++;
483     XtSetValues(kbd.autoRepeatToggle, args, n);
484
485     kbd.systemDefaultFlag = True;
486 }
487
488 /*+++++++++++++++++++++++++++++++++++++++*/
489 /* ButtonCB                              */
490 /* callback for PushButtons in DialogBox */
491 /*+++++++++++++++++++++++++++++++++++++++*/
492 static void 
493 ButtonCB(
494         Widget w,
495         XtPointer client_data,
496         XtPointer call_data )
497 {
498     int                 n;
499     Arg                 args[MAX_ARGS];
500     XKeyboardControl    kbdControl;
501     int                 kbdControlMask;
502     DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
503
504
505     switch (cb->button_position)
506     {
507       case OK_BUTTON:
508           XtUnmanageChild (w);
509
510           /* if sendSettings is true send message to Session Manager */
511
512           if(style.smState.smSendSettings)
513           {
514              if(kbd.systemDefaultFlag)
515              {
516                 SmDefaultKeyboardSettings();
517              }
518              else
519              {
520                 SmNewKeyboardSettings( kbd.new_key_click_percent, /* 0-100 */
521                                        kbd.new_autoRepeat);       /* 0,1   */
522              }
523           }
524           break;
525
526       case CANCEL_BUTTON:
527           /* reset to incoming keyboard values */ 
528
529           n=0;
530           XtSetArg(args[n], XmNvalue, kbd.values.key_click_percent); n++;
531           XtSetValues(kbd.volumeScale, args, n);
532
533           n=0;
534           XtSetArg(args[n], XmNset, kbd.values.global_auto_repeat); n++;
535           XtSetValues(kbd.autoRepeatToggle, args, n);
536
537           kbdControlMask = KBKeyClickPercent | KBAutoRepeatMode;
538           kbdControl.key_click_percent = kbd.values.key_click_percent;
539           kbdControl.auto_repeat_mode = kbd.values.global_auto_repeat;
540           XChangeKeyboardControl(style.display, kbdControlMask, &kbdControl);
541
542           XtUnmanageChild(w);
543           break;
544
545       case HELP_BUTTON:
546           XtCallCallbacks(style.kbdDialog, XmNhelpCallback, (XtPointer)NULL);
547           break;
548
549       default:
550           break;
551     }
552 }
553
554
555 /************************************************************************
556  * restoreKeybd()
557  *
558  * restore any state information saved with saveKeybd.
559  * This is called from restoreSession with the application
560  * shell and the special xrm database retrieved for restore.
561  ************************************************************************/
562 void 
563 restoreKeybd(
564         Widget shell,
565         XrmDatabase db )
566 {
567     XrmName xrm_name[5];
568     XrmRepresentation rep_type;
569     XrmValue value;
570
571     xrm_name [0] = XrmStringToQuark ("keyboardDlg");
572     xrm_name [2] = NULL;
573
574     /* get x position */
575     xrm_name [1] = XrmStringToQuark ("x");
576     if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
577       XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr)); save.poscnt++;
578       save.restoreFlag = True;
579     }
580
581     /* get y position */
582     xrm_name [1] = XrmStringToQuark ("y");
583     if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
584       XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr)); save.poscnt++;
585     }
586
587     xrm_name [1] = XrmStringToQuark ("ismapped");
588     XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
589     /* Are we supposed to be mapped? */
590     if (strcmp(value.addr, "True") == 0)
591       popup_keyboardBB(shell);
592 }
593
594 /************************************************************************
595  * saveKeybd()
596  *
597  * This routine will write out to the passed file descriptor any state
598  * information this dialog needs.  It is called from saveSessionCB with the
599  * file already opened.
600  * All information is saved in xrm format.  There is no restriction
601  * on what can be saved.  It doesn't have to be defined or be part of any
602  * widget or Xt definition.  Just name and save it here and recover it in
603  * restoreBackdrop.  The suggested minimum is whether you are mapped, and your
604  * location.
605  ************************************************************************/
606 void 
607 saveKeybd(
608         int fd )
609 {
610     Position x,y;
611     char *bufr = style.tmpBigStr;     /* size=[1024], make bigger if needed */
612     XmVendorShellExtObject  vendorExt;
613     XmWidgetExtData         extData;
614
615     if (style.kbdDialog != NULL) 
616     {
617         if (XtIsManaged(style.kbdDialog))
618             sprintf(bufr, "*keyboardDlg.ismapped: True\n");
619         else
620             sprintf(bufr, "*keyboardDlg.ismapped: False\n");
621
622         /* Get and write out the geometry info for our Window */
623         x = XtX(XtParent(style.kbdDialog));
624         y = XtY(XtParent(style.kbdDialog));
625
626         /* Modify x & y to take into account window mgr frames
627          * This is pretty bogus, but I don't know a better way to do it.
628          */
629         extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
630         vendorExt = (XmVendorShellExtObject)extData->widget;
631         x -= vendorExt->vendor.xOffset;
632         y -= vendorExt->vendor.yOffset;
633
634         sprintf(bufr, "%s*keyboardDlg.x: %d\n", bufr, x);
635         sprintf(bufr, "%s*keyboardDlg.y: %d\n", bufr, y);
636
637         write (fd, bufr, strlen(bufr));
638     }
639 }
640