2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /*$TOG: Protocol.c /main/6 1997/06/18 17:30:30 samborn $*/
24 /************************************<+>*************************************
25 ****************************************************************************
31 ** Description: inter-client communication for Dtstyle
34 ****************************************************************************
35 ************************************<+>*************************************/
37 * (c) Copyright 1996 Digital Equipment Corporation.
38 * (c) Copyright 1990, 1993, 1996 Hewlett-Packard Company.
39 * (c) Copyright 1996 International Business Machines Corp.
40 * (c) Copyright 1996 Sun Microsystems, Inc.
41 * (c) Copyright 1996 Novell, Inc.
42 * (c) Copyright 1996 FUJITSU LIMITED.
43 * (c) Copyright 1996 Hitachi.
46 /*+++++++++++++++++++++++++++++++++++++++*/
48 /*+++++++++++++++++++++++++++++++++++++++*/
52 #include <X11/Intrinsic.h>
53 #include <X11/Xatom.h>
55 #include <Xm/Protocols.h>
58 #include <Dt/Connect.h>
59 #include <Dt/SessionM.h>
60 #include <Dt/SessionP.h>
65 #include "SaveRestore.h"
68 #include <Dt/Message.h>
69 #include <Dt/UserMsg.h>
71 /*+++++++++++++++++++++++++++++++++++++++*/
72 /* include extern functions */
73 /*+++++++++++++++++++++++++++++++++++++++*/
76 #ifndef CDE_INSTALLATION_TOP
77 #define CDE_INSTALLATION_TOP "/opt/dt"
80 #define WS_STARTUP_RETRY_COUNT 12
81 #define WS_STARTUP_TIME 5000
82 #define ERR1 ((char *)GETMESSAGE(2, 4, "Cannot communicate with the session\nmanager... Exiting."))
83 #define ERR2 ((char *)GETMESSAGE(2, 9, "Could not obtain screen saver information\nfrom the session manager. Start up settings\nmay be incorrect."))
86 * Global variable definitions
90 static Atom xaWmSaveYourself;
91 static Atom xaWmDeleteWindow;
93 /* Atoms for client messages */
94 static Atom xaSmStmProtocol;
95 static Atom xaSmStateChange;
96 static Atom xaSmRestoreDefault;
97 static Atom xaSmLockChange;
98 static Atom xaSmSaveToHome;
100 /* Atoms for window properties */
101 static Atom xaDtSaveMode;
102 static Atom xaDtSmAudioInfo;
103 static Atom xaDtSmKeyboardInfo;
104 static Atom xaDtSmPointerInfo;
105 static Atom xaDtSmScreenInfo;
106 static Atom xaDtSmFontInfo;
107 static Atom xaDtSmPreeditInfo;
109 /* local function definitions */
110 static void SmRestoreDefault(Atom);
113 /*************************************<->*************************************
120 * Handles interning of atoms for inter-client communication.
125 *************************************<->***********************************/
127 InitDtstyleProtocol( void )
130 enum { XA_DT_SAVE_MODE, XA_WM_SAVE_YOURSELF, XA_WM_DELETE_WINDOW,
131 XA_DT_SM_STM_PROTOCOL, XA_DT_SM_SAVE_TO_HOME,
132 XA_DT_SM_STATE_CHANGE, XA_DT_SM_RESTORE_DEFAULT,
133 XA_DT_SM_LOCK_CHANGE, XA_DT_SM_AUDIO_INFO,
134 XA_DT_SM_SCREEN_INFO, XA_DT_SM_KEYBOARD_INFO,
135 XA_DT_SM_POINTER_INFO, XA_DT_SM_FONT_INFO,
136 XA_DT_SM_PREEDIT_INFO, NUM_ATOMS };
137 static char *atom_names[] = {
138 _XA_DT_SAVE_MODE, "WM_SAVE_YOURSELF", "WM_DELETE_WINDOW",
139 _XA_DT_SM_STM_PROTOCOL, _XA_DT_SM_SAVE_TO_HOME,
140 _XA_DT_SM_STATE_CHANGE, _XA_DT_SM_RESTORE_DEFAULT,
141 _XA_DT_SM_LOCK_CHANGE, _XA_DT_SM_AUDIO_INFO,
142 _XA_DT_SM_SCREEN_INFO, _XA_DT_SM_KEYBOARD_INFO,
143 _XA_DT_SM_POINTER_INFO, _XA_DT_SM_FONT_INFO,
144 _XA_DT_SM_PREEDIT_INFO };
145 Atom atoms[XtNumber(atom_names)];
147 /* Get Session Manager Window ID for communication */
149 if (_DtGetSmWindow (style.display,
150 XRootWindow(style.display,0),
151 &smWindow) == Success)
153 if (_DtGetSmState (style.display, smWindow, &style.smState) != Success)
155 _DtSimpleError (progName, DtWarning, NULL, ERR1, NULL);
158 if (_DtGetSmSaver (style.display, smWindow, &style.smSaver) != Success)
159 _DtSimpleError (progName, DtWarning, NULL, ERR2, NULL);
164 XInternAtoms(style.display, atom_names, XtNumber(atom_names), False, atoms);
166 xaDtSaveMode = atoms[XA_DT_SAVE_MODE];
167 xaWmSaveYourself = atoms[XA_WM_SAVE_YOURSELF];
168 xaWmDeleteWindow = atoms[XA_WM_DELETE_WINDOW];
169 xaSmStmProtocol = atoms[XA_DT_SM_STM_PROTOCOL];
170 xaSmSaveToHome = atoms[XA_DT_SM_SAVE_TO_HOME];
171 xaSmStateChange = atoms[XA_DT_SM_STATE_CHANGE];
172 xaSmRestoreDefault = atoms[XA_DT_SM_RESTORE_DEFAULT];
173 xaSmLockChange = atoms[XA_DT_SM_LOCK_CHANGE];
174 xaDtSmAudioInfo = atoms[XA_DT_SM_AUDIO_INFO];
175 xaDtSmScreenInfo = atoms[XA_DT_SM_SCREEN_INFO];
176 xaDtSmKeyboardInfo = atoms[XA_DT_SM_KEYBOARD_INFO];
177 xaDtSmPointerInfo = atoms[XA_DT_SM_POINTER_INFO];
178 xaDtSmFontInfo = atoms[XA_DT_SM_FONT_INFO];
179 xaDtSmPreeditInfo = atoms[XA_DT_SM_PREEDIT_INFO];
183 /*************************************<->*************************************
185 * SetWindowProperites ()
190 * Add the WM_DELETE_WINDOW and WM_SAVE_YOURSELF properties to the
191 * dtstyle main window
193 *************************************<->***********************************/
195 SetWindowProperties( void )
198 /* Add WM_SAVE_YOURSELF property to the main window */
199 XmAddWMProtocolCallback(style.shell, xaWmSaveYourself, saveSessionCB, NULL);
201 /* Add WM_DELETE_WINDOW property to the main window */
202 XmAddWMProtocolCallback(style.shell, xaWmDeleteWindow, activateCB_exitBtn, NULL);
207 /*************************************<->*************************************
209 * HandleWorkspaceChange
214 * Do processing required when workspace changes. A DtWsmWsChangeProc.
216 *************************************<->***********************************/
218 HandleWorkspaceChange (
223 CheckWorkspace (); /* Backdrop may need to update colors */
226 /*************************************<->*************************************
228 * ListenForWorkspaceChange ()
235 *************************************<->***********************************/
237 ListenForWorkspaceChange( void )
240 DtWsmAddCurrentWorkspaceCallback (style.shell,
241 (DtWsmWsChangeProc) HandleWorkspaceChange, NULL);
245 /************************************************************************
246 * WorkspaceStartupTimer()
248 * Check to see if the workspace manager is ready
249 ************************************************************************/
251 WorkspaceStartupTimer(
252 XtPointer client_data,
256 intptr_t count = (intptr_t) client_data;
258 if (DtWsmGetCurrentWorkspace (style.display, style.root, &aWS)
262 * OK, the workspace manager is ready. Get the
263 * colors and redraw the bitmap.
267 else if (--count > 0)
269 /* wait a little longer for the workspace manager */
270 client_data = (XtPointer) count;
271 (void) XtAppAddTimeOut (XtWidgetToApplicationContext(style.shell),
272 WS_STARTUP_TIME, WorkspaceStartupTimer, client_data);
276 /*************************************<->*************************************
283 * Dtstyle has been reparented.
284 * The parenting happens twice when the window manager has been restarted.
285 * First Dtstyle gets reparented to the root window, then reparented to
286 * the window manager.
288 *************************************<->***********************************/
292 XtPointer client_data,
295 if ((event->type == ReparentNotify) &&
296 (event->xreparent.parent != style.root))
298 if (style.backdropDialog && XtIsManaged(style.backdropDialog))
300 client_data = (XtPointer) WS_STARTUP_RETRY_COUNT;
301 (void) XtAppAddTimeOut (XtWidgetToApplicationContext(style.shell),
302 WS_STARTUP_TIME, WorkspaceStartupTimer, client_data);
307 /*************************************<->*************************************
309 * GetSessionSaveMode ()
314 * Get the session save mode from the Session Manager
316 *************************************<->***********************************/
319 unsigned char **mode )
324 unsigned long nitems;
325 unsigned long leftover;
327 XGetWindowProperty(style.display, RootWindow(style.display, 0),
329 (long)BUFSIZ,False,AnyPropertyType,&actualType,
330 &actualFormat,&nitems,&leftover,
336 /*************************************<->*************************************
338 * SmSaveHomeSession ()
342 * Tell Session Manager to save the home session
344 *************************************<->***********************************/
350 XClientMessageEvent stmToSmMessage;
355 * Tell session manager save home state using current smStartState
356 * and smConfirmMode. Note that the session state will retain the
357 * original smStartState and smConfirmMode values.
359 stmToSmMessage.type = ClientMessage;
360 stmToSmMessage.window = smWindow;
361 stmToSmMessage.message_type = xaSmStmProtocol;
362 stmToSmMessage.format = 32;
363 stmToSmMessage.data.l[0] = xaSmSaveToHome;
364 stmToSmMessage.data.l[1] = style.smState.smStartState;
365 stmToSmMessage.data.l[2] = style.smState.smConfirmMode;
366 stmToSmMessage.data.l[3] = CurrentTime;
367 XSendEvent(style.display, smWindow, False, NoEventMask,
368 (XEvent *) &stmToSmMessage);
372 /*************************************<->*************************************
374 * SmNewStartupSettings ()
378 * Tell Session Manager about new Startup settings
380 *************************************<->***********************************/
382 SmNewStartupSettings( void )
388 state.flags = SM_STATE_START | SM_STATE_CONFIRM;
389 state.smStartState = style.smState.smStartState;
390 state.smConfirmMode = style.smState.smConfirmMode;
391 _DtSetSmState(style.display, smWindow, &state);
395 /*************************************<->*************************************
397 * SmRestoreDefault ()
401 * Tell Session Manager to restore the default value to one of the settings
403 *************************************<->***********************************/
405 SmRestoreDefault(Atom toRestore)
407 XClientMessageEvent stmToSmMessage;
411 stmToSmMessage.type = ClientMessage;
412 stmToSmMessage.window = smWindow;
413 stmToSmMessage.message_type = xaSmStmProtocol;
414 stmToSmMessage.format = 32;
415 stmToSmMessage.data.l[0] = xaSmRestoreDefault;
416 stmToSmMessage.data.l[1] = toRestore;
417 stmToSmMessage.data.l[2] = CurrentTime;
418 XSendEvent(style.display, smWindow, False, NoEventMask,
419 (XEvent *) &stmToSmMessage);
424 /*************************************<->*************************************
426 * SmDefaultAudioSettings ()
430 * Tell Session Manager to set default Xserver audio settings
432 *************************************<->***********************************/
434 SmDefaultAudioSettings( void )
438 /* Delete the property to indicate default settings to SM */
439 SmRestoreDefault(xaDtSmAudioInfo);
443 /*************************************<->*************************************
445 * SmNewAudioSettings ()
449 * Tell Session Manager about new Xserver audio settings
451 *************************************<->***********************************/
459 PropDtSmAudioInfo audioProp;
464 * Set the property on the Session Manager window
465 * indicating the new screen saver settings
469 audioProp.smBellPercent = (CARD32) volume;
470 audioProp.smBellPitch = (CARD32) tone;
471 audioProp.smBellDuration = (CARD32) duration;
472 XChangeProperty (style.display, smWindow,
476 (unsigned char *)&audioProp,
477 PROP_DT_SM_AUDIO_INFO_ELEMENTS);
481 /*************************************<->*************************************
483 * SmDefaultScreenSettings ()
487 * Tell Session Manager to set default Xserver screen settings
489 *************************************<->***********************************/
491 SmDefaultScreenSettings( void )
495 /* Delete the property to indicate default settings to SM */
496 SmRestoreDefault(xaDtSmScreenInfo);
501 /*************************************<->*************************************
503 * SmNewScreenSettings ()
507 * Tell Session Manager about new Xserver screen settings
509 *************************************<->***********************************/
519 PropDtSmScreenInfo screenProp;
524 * Set the property on the Session Manager window
525 * indicating the new screen saver settings
528 screenProp.flags = 0;
529 screenProp.smTimeout = (CARD32) timeout; /* 0-7200 */
530 screenProp.smInterval = (CARD32) interval; /* -1 */
531 screenProp.smPreferBlank = (CARD32) blanking; /* 0,1 */
532 screenProp.smAllowExp = (CARD32) exposures;
533 XChangeProperty (style.display, smWindow,
537 (unsigned char *)&screenProp,
538 PROP_DT_SM_SCREEN_INFO_ELEMENTS);
542 /*************************************<->*************************************
544 * SmNewSaverSettings ()
548 * Tell Session Manager about new saver settings:
549 * saver timeout, lock timeout, cycle timeout, selected saver list
551 *************************************<->***********************************/
559 SmStateInfo state; /* structure that will contain new state info */
560 SmSaverInfo saver; /* structure that will contain selected saver list */
562 int saverTime_change; /* saver timeout */
563 int lockTime_change; /* lock timeout */
564 int cycleTime_change; /* saver timeout */
568 lockTime_change = (style.smState.smLockTimeout != lockTime);
569 saverTime_change = (style.smState.smSaverTimeout != saverTime);
570 cycleTime_change = (style.smState.smCycleTimeout != cycleTime);
571 state.flags = (saverTime_change ? SM_STATE_SAVERTIMEOUT : 0) |
572 (lockTime_change ? SM_STATE_LOCKTIMEOUT : 0) |
573 (cycleTime_change ? SM_STATE_CYCLETIMEOUT : 0);
577 state.smSaverTimeout = saverTime;
578 state.smLockTimeout = lockTime;
579 state.smCycleTimeout = cycleTime;
581 _DtSetSmState(style.display, smWindow, &state);
583 saver.saverList = selsaversList;
584 _DtSetSmSaver(style.display, smWindow, &saver);
590 /*************************************<->*************************************
596 * Tell Session Manager about new saver timeout
597 * used for telling the session manager if it should run savers or not when
598 * the user enables/disables saver toggle (or the savers toggle in no saver
599 * extension mode) without having to press OK. A zero is sent to the session
600 * manager when no savers should be run.
601 *************************************<->***********************************/
603 SmNewSaverTime(int saverTime)
605 SmStateInfo state; /* structure that will contain new state info */
609 state.flags = SM_STATE_SAVERTIMEOUT;
610 state.smSaverTimeout = saverTime;
611 _DtSetSmState(style.display, smWindow, &state);
617 /*************************************<->*************************************
619 * SmDefaultKeyboardSettings ()
623 * Tell Session Manager to set default Xserver Keyboard settings
625 *************************************<->***********************************/
627 SmDefaultKeyboardSettings( void )
631 /* Delete the property to indicate default settings to SM */
632 SmRestoreDefault(xaDtSmKeyboardInfo);
636 /*************************************<->*************************************
638 * SmNewKeyboardSettings ()
642 * Tell Session Manager about new Xserver Keyboard settings
644 *************************************<->***********************************/
646 SmNewKeyboardSettings(
651 PropDtSmKeyboardInfo KeyboardProp;
656 * Set the property on the Session Manager window
657 * indicating the new screen saver settings
660 KeyboardProp.flags = 0;
661 KeyboardProp.smKeyClickPercent = (CARD32) keyClickPercent;
662 KeyboardProp.smGlobalAutoRepeat = (CARD32) autoRepeat;
663 XChangeProperty (style.display, smWindow,
667 (unsigned char *)&KeyboardProp,
668 PROP_DT_SM_KEYBOARD_INFO_ELEMENTS);
672 /*************************************<->*************************************
674 * SmDefaultPointerSettings ()
678 * Tell Session Manager to set default Xserver Pointer settings
680 *************************************<->***********************************/
682 SmDefaultPointerSettings( void )
686 /* Delete the property to indicate default settings to SM */
687 SmRestoreDefault(xaDtSmPointerInfo);
691 /*************************************<->*************************************
693 * SmNewPointerSettings ()
697 * Tell Session Manager about new Xserver Pointer settings
699 *************************************<->***********************************/
701 SmNewPointerSettings(
708 * Set the property on the Session Manager window
709 * indicating the new screen saver settings
712 XChangeProperty (style.display, smWindow,
716 (unsigned char *)pointerString,
717 strlen(pointerString));
721 /*************************************<->*************************************
723 * SmNewPreeditSettings ()
727 * Tell Session Manager about new preeditType resources
729 *************************************<->***********************************/
731 SmNewPreeditSettings(
732 char *preeditResourceString)
739 * Set the property on the Session Manager window
740 * indicating the new font resource string
743 XChangeProperty (style.display, smWindow,
747 (unsigned char *)preeditResourceString,
748 strlen(preeditResourceString));
751 /*************************************<->*************************************
753 * SmNewFontSettings ()
757 * Tell Session Manager about new font resources
759 *************************************<->***********************************/
762 char *fontResourceString)
769 * Set the property on the Session Manager window
770 * indicating the new font resource string
773 XChangeProperty (style.display, smWindow,
777 (unsigned char *)fontResourceString,
778 strlen(fontResourceString));