SmCommun.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  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 libraries 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. /* $TOG: SmCommun.c /main/14 1999/09/20 13:47:25 mgreess $ */
  24. /*
  25. * (c) Copyright 1997, The Open Group
  26. */
  27. /*************************************<+>*************************************
  28. *****************************************************************************
  29. **
  30. ** File: SmCommun.c
  31. **
  32. ** Project: HP DT Session Manager (dtsession)
  33. **
  34. ** Description:
  35. ** -----------
  36. ** This file contains functionality needed to communicate with the
  37. ** other DT components. This includes initialization and callback code.
  38. **
  39. *****************************************************************************
  40. *************************************<+>*************************************/
  41. /*
  42. * (c) Copyright 1996 Digital Equipment Corporation.
  43. * (c) Copyright 1990, 1993, 1994, 1996 Hewlett-Packard Company
  44. * (c) Copyright 1993, 1994, 1996 International Business Machines Corp.
  45. * (c) Copyright 1993, 1994, 1996 Sun Microsystems, Inc.
  46. * (c) Copyright 1993, 1994, 1996 Novell, Inc.
  47. * (c) Copyright 1996 FUJITSU LIMITED.
  48. * (c) Copyright 1996 Hitachi.
  49. */
  50. #include <stdio.h>
  51. #ifdef _SUN_OS /* for the strtok calls */
  52. #include <string.h>
  53. #endif
  54. #include <X11/Intrinsic.h>
  55. #include <X11/StringDefs.h>
  56. #if defined (USE_X11SSEXT)
  57. #include <X11/extensions/scrnsaver.h>
  58. #endif /* USE_X11SSEXT */
  59. #include <Xm/Xm.h>
  60. #include <Dt/Dt.h>
  61. #include <Dt/DtP.h>
  62. #include <Dt/Action.h>
  63. #include <Dt/SessionM.h>
  64. #include <Dt/UserMsg.h>
  65. #include <Dt/Indicator.h>
  66. #include <Dt/MsgLog.h>
  67. #include <Tt/tttk.h>
  68. #include "Sm.h"
  69. #include "SmError.h"
  70. #include "SmLock.h"
  71. #include "SmCommun.h"
  72. #include "SmRestore.h"
  73. #include "SmSave.h"
  74. #include "SmUI.h"
  75. #include "SmProtocol.h"
  76. #include "SmGlobals.h"
  77. #include "SmXSMP.h"
  78. /*
  79. * Pulic var declarations
  80. */
  81. extern int clientRunning; /* from SmConMgmt.c */
  82. extern char **smExecArray;
  83. /*
  84. * Defines for this file only
  85. */
  86. #define SS_ON 0
  87. #define SS_OFF 1
  88. #define SS_DRAW 2
  89. /*
  90. * Constants for the Save_Session ToolTalk message
  91. */
  92. static const char *SAVE_TYPE = "save_type";
  93. static const char *SHUTDOWN = "shutdown";
  94. static const char *INTERACT_STYLE = "interact_style";
  95. static const char *FAST = "fast";
  96. static const char *GLOBAL = "global";
  97. static const char *NUM_BACKUPS = "num_sessions_backedup";
  98. static const char *SAVE_LOCAL = "Local";
  99. static const char *SAVE_GLOBAL = "Global";
  100. static const char *SAVE_BOTH = "Both";
  101. static const char *INTERACT_NONE = "None";
  102. static const char *INTERACT_ERRORS = "Errors";
  103. static const char *TRUE_STR = "True";
  104. static const char *FALSE_STR = "False";
  105. /*
  106. * Local function definitions
  107. */
  108. static void DtwmStarted(void);
  109. static void
  110. ProcessSaveSessionMessage (
  111. Tt_message saveMsg )
  112. {
  113. int i;
  114. int saveType = -1;
  115. Boolean shutdown = DEFAULT_SHUTDOWN;
  116. int interactStyle = DEFAULT_INTERACT_STYLE;
  117. Boolean fast = DEFAULT_FAST;
  118. Boolean global = DEFAULT_GLOBAL;
  119. int numSessionsBackedup;
  120. char * type;
  121. char * value;
  122. int num_args = tt_message_args_count (saveMsg);
  123. Tt_message tmpMsg;
  124. Tt_status status;
  125. for (i = 0; i < num_args; i++) {
  126. type = tt_message_arg_type (saveMsg, i);
  127. status = tt_ptr_error (type);
  128. if (status != TT_OK || type == NULL)
  129. continue;
  130. value = tt_message_arg_val (saveMsg, i);
  131. status = tt_ptr_error (value);
  132. if (status != TT_OK || value == NULL)
  133. continue;
  134. if (!strcmp (type, SAVE_TYPE)) {
  135. if (!strcmp (value, SAVE_LOCAL))
  136. saveType = SmSaveLocal;
  137. else if (!strcmp (value, SAVE_GLOBAL))
  138. saveType = SmSaveGlobal;
  139. else if (!strcmp (value, SAVE_BOTH))
  140. saveType = SmSaveBoth;
  141. else {
  142. tt_free (type);
  143. tt_free (value);
  144. break;
  145. }
  146. }
  147. else if (!strcmp (type, SHUTDOWN)) {
  148. if (!strcmp (value, TRUE_STR))
  149. shutdown = True;
  150. else if (!strcmp (value, FALSE_STR))
  151. shutdown = False;
  152. }
  153. else if (!strcmp (type, INTERACT_STYLE)){
  154. if (!strcmp (value, INTERACT_NONE))
  155. interactStyle = SmInteractStyleNone;
  156. else if (!strcmp (value, INTERACT_ERRORS))
  157. interactStyle = SmInteractStyleErrors;
  158. }
  159. else if (!strcmp (type, FAST)) {
  160. if (!strcmp (value, TRUE_STR))
  161. fast = True;
  162. else if (!strcmp (value, FALSE_STR))
  163. fast = False;
  164. }
  165. else if (!strcmp (type, GLOBAL)) {
  166. if (!strcmp (value, TRUE_STR))
  167. global = True;
  168. else if (!strcmp (value, FALSE_STR))
  169. global = False;
  170. }
  171. else if (!strcmp (type, NUM_BACKUPS)) {
  172. numSessionsBackedup = atoi (value);
  173. if (numSessionsBackedup > 0)
  174. smRes.numSessionsBackedup = numSessionsBackedup;
  175. }
  176. else {
  177. char *pch1;
  178. char *pch2;
  179. pch1 = strdup ((char *) GETMESSAGE (40, 16,
  180. "The Save_Session message contains the unrecognized argument '%s'."));
  181. if (pch1) {
  182. pch2 = XtMalloc (strlen (pch1)+strlen (type)+3);
  183. if (pch2) {
  184. (void) sprintf (pch2, pch1, type);
  185. DtMsgLogMessage (smGD.programName,
  186. DtMsgLogWarning, pch2);
  187. free (pch1); free (pch2);
  188. }
  189. else {
  190. free (pch1);
  191. }
  192. }
  193. }
  194. tt_free (type);
  195. tt_free (value);
  196. }
  197. if (saveType == -1) {
  198. PostSaveSessionErrorDialog ();
  199. return;
  200. }
  201. smGD.smState = IN_PROCESS;
  202. tmpMsg = tttk_message_create (0, TT_NOTICE, TT_SESSION, 0,
  203. "DtActivity_Beginning", 0);
  204. tt_message_send (tmpMsg);
  205. tt_message_destroy (tmpMsg);
  206. SaveState ((smGD.sessionType == HOME_SESSION),
  207. smSettings.startState, saveType, shutdown,
  208. interactStyle, fast, global);
  209. tmpMsg = tttk_message_create (0, TT_NOTICE, TT_SESSION, 0,
  210. "DtActivity_Began", 0);
  211. tt_message_send (tmpMsg);
  212. tt_message_destroy (tmpMsg);
  213. SetSystemReady ();
  214. }
  215. /*************************************<->*************************************
  216. *
  217. * handleSessionMgrRequest ()
  218. *
  219. *
  220. * Description:
  221. * -----------
  222. * Handle ToolTalk requests for which the session manager is responsible.
  223. *
  224. *
  225. * Inputs:
  226. * ------
  227. * Incoming request, and the pattern it matched.
  228. *
  229. *
  230. * Outputs:
  231. * -------
  232. * Whether the message has been consumed.
  233. *
  234. *
  235. * Comments:
  236. * --------
  237. *
  238. *************************************<->***********************************/
  239. Tt_callback_action
  240. handleSessionMgrRequest(
  241. Tt_message msg,
  242. Tt_pattern pat
  243. )
  244. {
  245. char *op;
  246. Tt_status status;
  247. Tt_callback_action rc;
  248. Boolean destroyMsg;
  249. if (tt_message_state( msg ) != TT_SENT)
  250. {
  251. /* msg is a reply to ourself */
  252. return TT_CALLBACK_CONTINUE;
  253. }
  254. op = tt_message_op( msg );
  255. status = tt_ptr_error( op );
  256. if ((status != TT_OK) || (op == 0))
  257. {
  258. /* Let tttk_Xt_input_handler() Do The Right Thing */
  259. return TT_CALLBACK_CONTINUE;
  260. }
  261. destroyMsg = True;
  262. if (strcmp( op, SM_DISPLAY_LOCK ) == 0)
  263. {
  264. if(smGD.smState == READY)
  265. {
  266. smGD.smState = IN_PROCESS;
  267. LockDisplay(True);
  268. }
  269. rc = TT_CALLBACK_PROCESSED;
  270. }
  271. else if (strcmp( op, SM_XSESSION_EXIT ) == 0)
  272. {
  273. if(smGD.smState == READY)
  274. {
  275. smGD.smState = IN_PROCESS;
  276. ExitSession( msg );
  277. /*
  278. * The session may have been canceled so set the smState
  279. * back to ready.
  280. */
  281. smGD.smState = READY;
  282. destroyMsg = False; /* done in SmUI.c */
  283. }
  284. rc = TT_CALLBACK_PROCESSED;
  285. }
  286. else if (strcmp( op, SM_RESOURCES_RELOAD ) == 0)
  287. {
  288. if(smGD.smState == READY)
  289. {
  290. smGD.smState = IN_PROCESS;
  291. ReloadResources();
  292. }
  293. rc = TT_CALLBACK_PROCESSED;
  294. }
  295. else if (strcmp( op, SM_SAVE_SESSION ) == 0)
  296. {
  297. if(smGD.smState == READY)
  298. {
  299. smGD.smState = IN_PROCESS;
  300. ProcessSaveSessionMessage (msg);
  301. }
  302. rc = TT_CALLBACK_PROCESSED;
  303. }
  304. else
  305. {
  306. rc = TT_CALLBACK_CONTINUE;
  307. destroyMsg = False;
  308. }
  309. if (destroyMsg == True)
  310. {
  311. tt_message_reply( msg );
  312. tt_message_destroy( msg );
  313. }
  314. tt_free( op );
  315. return (rc);
  316. }
  317. /*************************************<->*************************************
  318. *
  319. * StartMsgServer ()
  320. *
  321. *
  322. * Description:
  323. * -----------
  324. * Initialize the BMS and register the session manager with it. Then
  325. * register all requests and notifications that the session manager is
  326. * interested in.
  327. *
  328. *
  329. * Inputs:
  330. * ------
  331. * app = Application context for dtsession
  332. *
  333. *
  334. * Outputs:
  335. * -------
  336. *
  337. *
  338. * Comments:
  339. * --------
  340. *
  341. *************************************<->***********************************/
  342. void
  343. StartMsgServer(void)
  344. {
  345. Boolean makeConnect;
  346. String tmpString;
  347. char * sessId;
  348. char * procId;
  349. int fd;
  350. Tt_status status;
  351. /*
  352. * Before we start anything - initialize the customize data structure
  353. */
  354. smCust.screenSavChange = False;
  355. smCust.audioChange = False;
  356. smCust.keyboardChange = False;
  357. smCust.fontChange = False;
  358. smCust.pointerChange = False;
  359. smCust.dClickChange = False;
  360. smCust.preeditChange = False;
  361. makeConnect = DtAppInitialize(smGD.appCon, smGD.display, smGD.topLevelWid,
  362. SM_RESOURCE_NAME,
  363. DtSM_TOOL_CLASS);
  364. smDD.okString = XmStringCreateLocalized(((char *)GETMESSAGE(18, 39, "OK")));
  365. smDD.okLogoutString = XmStringCreateLocalized(((char *)GETMESSAGE(18, 39, "OK")));
  366. smDD.cancelLogoutString = XmStringCreateLocalized(((char *)GETMESSAGE(18,40, "Cancel")));
  367. smDD.helpString = XmStringCreateLocalized(((char *)GETMESSAGE(18, 41, "Help")));
  368. if(makeConnect == False)
  369. {
  370. smGD.bmsDead = True;
  371. }
  372. else
  373. {
  374. smGD.bmsDead = False;
  375. }
  376. procId = tt_open();
  377. status = tt_ptr_error( procId );
  378. if (status == TT_OK) {
  379. fd = tt_fd();
  380. status = tt_int_error( fd );
  381. if (status == TT_OK) {
  382. XtAppAddInput( smGD.appCon, fd, (XtPointer)XtInputReadMask,
  383. tttk_Xt_input_handler, procId );
  384. }
  385. }
  386. if (status != TT_OK) {
  387. smGD.bmsDead = True;
  388. }
  389. smGD.requests2Handle = 0;
  390. if (status == TT_OK) {
  391. smGD.requests2Handle = tt_pattern_create();
  392. tt_pattern_category_set( smGD.requests2Handle, TT_HANDLE );
  393. tt_pattern_class_add( smGD.requests2Handle, TT_REQUEST );
  394. tt_pattern_scope_add( smGD.requests2Handle, TT_SESSION );
  395. sessId = tt_default_session();
  396. tt_pattern_session_add( smGD.requests2Handle, sessId );
  397. tt_free( sessId );
  398. tt_pattern_op_add( smGD.requests2Handle, SM_DISPLAY_LOCK );
  399. tt_pattern_op_add( smGD.requests2Handle, SM_XSESSION_EXIT );
  400. tt_pattern_op_add( smGD.requests2Handle, SM_RESOURCES_RELOAD );
  401. tt_pattern_op_add( smGD.requests2Handle, SM_SAVE_SESSION );
  402. tt_pattern_callback_add( smGD.requests2Handle,
  403. handleSessionMgrRequest );
  404. status = tt_pattern_register( smGD.requests2Handle );
  405. if (status != TT_OK) {
  406. smGD.bmsDead = True;
  407. }
  408. }
  409. if (smGD.bmsDead) {
  410. char *errfmt, *errmsg, *statmsg;
  411. errfmt = SmNewString((char *) GETMESSAGE (6, 1,
  412. "Could not connect to ToolTalk message server:\n%sExiting ...\n"));
  413. statmsg = tt_status_message(status);
  414. errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
  415. sprintf(errmsg, errfmt, statmsg);
  416. PrintError(DtError, errmsg);
  417. SM_FREE(errfmt);
  418. XtFree(errmsg);
  419. WarnNoStartup();
  420. }
  421. } /* END OF FUNCTION StartMsgServer */
  422. /*************************************<->*************************************
  423. *
  424. * DtwmStarted (fields, client_data, num_words)
  425. *
  426. *
  427. * Description:
  428. * -----------
  429. *
  430. * Inputs:
  431. * ------
  432. *
  433. *
  434. * Outputs:
  435. * -------
  436. *
  437. *
  438. * Comments:
  439. * --------
  440. *
  441. *************************************<->***********************************/
  442. static void
  443. DtwmStarted(void)
  444. {
  445. smGD.dtwmRunning = True;
  446. } /* END OF FUNCTION DtwmStarted */
  447. /*************************************<->*************************************
  448. *
  449. * RestoreDefaults ()
  450. *
  451. *
  452. * Description:
  453. * -----------
  454. * A request has come in (usually from the customizer) to restore one of
  455. * the settings to their default states
  456. *
  457. * Inputs:
  458. * ------
  459. *
  460. *
  461. * Outputs:
  462. * -------
  463. * smToSet = (global) turns off flag of setting no longer set
  464. *
  465. *
  466. * Comments:
  467. * --------
  468. *
  469. *************************************<->***********************************/
  470. void
  471. RestoreDefaults(
  472. Atom toRestore)
  473. {
  474. if(toRestore == XaDtSmScreenInfo)
  475. {
  476. smToSet.screenSavChange = False;
  477. }
  478. else if(toRestore == XaDtSmAudioInfo)
  479. {
  480. smToSet.audioChange = False;
  481. }
  482. else if(toRestore == XaDtSmKeyboardInfo)
  483. {
  484. smToSet.keyboardChange = False;
  485. }
  486. else if(toRestore == XaDtSmPointerInfo)
  487. {
  488. smToSet.pointerChange = False;
  489. smToSet.pointerMapChange = False;
  490. }
  491. } /* END OF FUNCTION RestoreDefaults */
  492. /*************************************<->*************************************
  493. *
  494. * ProcessPropertyNotify ()
  495. *
  496. *
  497. * Description:
  498. * -----------
  499. * The customizer has changed one of the properties on the sm top level
  500. * window. This fact is remembered, so that at shutdown the information
  501. * can be saved
  502. *
  503. * Inputs:
  504. * ------
  505. *
  506. *
  507. * Outputs:
  508. * -------
  509. * smToSet = (global) turns on flag of setting being set
  510. *
  511. *
  512. * Comments:
  513. * --------
  514. *
  515. *************************************<->***********************************/
  516. void
  517. ProcessPropertyNotify(
  518. XEvent *next)
  519. {
  520. XPropertyEvent *pEvent = (XPropertyEvent *) next;
  521. if (pEvent->state != PropertyNewValue)
  522. {
  523. return;
  524. }
  525. if(pEvent->atom == XaDtSmScreenInfo)
  526. {
  527. smToSet.screenSavChange = True;
  528. smCust.screenSavChange = True;
  529. }
  530. else if(pEvent->atom == XaDtSmAudioInfo)
  531. {
  532. smToSet.audioChange = True;
  533. smCust.audioChange = True;
  534. }
  535. else if(pEvent->atom == XaDtSmKeyboardInfo)
  536. {
  537. smToSet.keyboardChange = True;
  538. smCust.keyboardChange = True;
  539. }
  540. else if(pEvent->atom == XaDtSmFontInfo)
  541. {
  542. smCust.fontChange = True;
  543. }
  544. else if(pEvent->atom == XaDtSmPreeditInfo)
  545. {
  546. smCust.preeditChange = True;
  547. }
  548. else if(pEvent->atom == XaDtSmPointerInfo)
  549. {
  550. smToSet.pointerChange = True;
  551. smCust.pointerChange = True;
  552. smToSet.pointerMapChange = True;
  553. smCust.dClickChange = True;
  554. }
  555. } /* END OF FUNCTION RecordChanges */
  556. /*************************************<->*************************************
  557. *
  558. * ProcessClientMessage(next)
  559. *
  560. *
  561. * Description:
  562. * -----------
  563. * A client message has come from somewhere. Process it if we know how.
  564. *
  565. * Inputs:
  566. * ------
  567. * next - the client message event
  568. *
  569. *
  570. * Outputs:
  571. * -------
  572. *
  573. *
  574. * Comments:
  575. * --------
  576. *
  577. *************************************<->***********************************/
  578. void
  579. ProcessClientMessage(
  580. XEvent *next)
  581. {
  582. XClientMessageEvent *cEvent = (XClientMessageEvent *) next;
  583. /*
  584. * If this event came from the style manager - process it
  585. */
  586. if(cEvent->message_type == XaDtSmStmProtocol)
  587. {
  588. if(cEvent->data.l[0] == XaDtSmSaveToHome)
  589. {
  590. /*
  591. * The style manager is asking for a save home session
  592. */
  593. if(smGD.smState == READY)
  594. {
  595. int startStateOrig;
  596. int confirmModeOrig;
  597. Tt_message msg;
  598. smGD.smState = IN_PROCESS;
  599. msg = tttk_message_create( 0, TT_NOTICE, TT_SESSION, 0,
  600. "DtActivity_Beginning", 0 );
  601. tt_message_send( msg );
  602. tt_message_destroy( msg );
  603. startStateOrig = smSettings.startState;
  604. confirmModeOrig = smSettings.confirmMode;
  605. smSettings.startState = cEvent->data.l[1];
  606. smSettings.confirmMode = cEvent->data.l[2];;
  607. smGD.homeSave = True;
  608. SaveState(True, smSettings.startState, SmSaveLocal,
  609. DEFAULT_SHUTDOWN, SmInteractStyleNone,
  610. DEFAULT_FAST, DEFAULT_GLOBAL);
  611. smGD.homeSave = False;
  612. smSettings.startState = startStateOrig;
  613. smSettings.confirmMode = confirmModeOrig;
  614. msg = tttk_message_create( 0, TT_NOTICE, TT_SESSION, 0,
  615. "DtActivity_Began", 0 );
  616. tt_message_send( msg );
  617. tt_message_destroy( msg );
  618. SetSystemReady();
  619. }
  620. }
  621. else if (cEvent->data.l[0] == XaDtSmRestoreDefault)
  622. {
  623. RestoreDefaults((Atom) cEvent->data.l[1]);
  624. }
  625. }
  626. else if(cEvent->message_type == XaSmWmProtocol)
  627. {
  628. /*
  629. * If this event came from the ws manager - process it
  630. */
  631. if(cEvent->data.l[0] == XaWmExitSession)
  632. {
  633. /*
  634. * The ws manager is sending an exit session message
  635. */
  636. if(smGD.smState == READY)
  637. {
  638. smGD.smState = IN_PROCESS;
  639. ExitSession(0);
  640. }
  641. }
  642. else if(cEvent->data.l[0] == XaWmLockDisplay)
  643. {
  644. /*
  645. * The ws manager is sending an lock display message
  646. */
  647. if(smGD.smState == READY)
  648. {
  649. smGD.smState = IN_PROCESS;
  650. LockDisplay(True);
  651. }
  652. }
  653. else if(cEvent->data.l[0] == XaWmWindowAck)
  654. {
  655. /*
  656. * The ws manager is sending a "client has been managed"
  657. */
  658. clientRunning = True;
  659. }
  660. else if(cEvent->data.l[0] == XaWmReady)
  661. {
  662. /*
  663. * The ws manager is sending a "ready for clients"
  664. */
  665. smGD.dtwmRunning = True;
  666. }
  667. }
  668. else if (cEvent->message_type == XaDtSmStateInfo)
  669. {
  670. SmStateInfo state;
  671. int flags = (int)cEvent->data.l[0];
  672. /*
  673. * Session state has been changed. Get new values.
  674. */
  675. if(_DtGetSmState(smGD.display, smGD.topLevelWindow, &state) == Success)
  676. {
  677. char *newRes = malloc(BUFSIZ);
  678. /*
  679. * Copy selected changes to data areas.
  680. */
  681. if (flags & SM_STATE_START)
  682. {
  683. smSettings.startState = state.smStartState;
  684. }
  685. if (flags & SM_STATE_CONFIRM)
  686. {
  687. smSettings.confirmMode = state.smConfirmMode;
  688. }
  689. newRes[0] = '\0';
  690. if (flags & SM_STATE_CYCLETIMEOUT)
  691. {
  692. smSaverRes.cycleTimeout = state.smCycleTimeout;
  693. sprintf(newRes+strlen(newRes), "dtsession*%scycleTimeout: %d\n",
  694. smGD.extensionSpec,
  695. smSaverRes.cycleTimeout/60);
  696. }
  697. if (flags & SM_STATE_LOCKTIMEOUT)
  698. {
  699. smSaverRes.lockTimeout = state.smLockTimeout;
  700. sprintf(newRes+strlen(newRes), "dtsession*%slockTimeout: %d\n",
  701. smGD.extensionSpec,
  702. smSaverRes.lockTimeout/60);
  703. }
  704. if (flags & SM_STATE_SAVERTIMEOUT)
  705. {
  706. smSaverRes.saverTimeout = state.smSaverTimeout;
  707. sprintf(newRes+strlen(newRes), "dtsession*%ssaverTimeout: %d\n",
  708. smGD.extensionSpec,
  709. smSaverRes.saverTimeout/60);
  710. }
  711. if (flags & SM_STATE_RANDOM)
  712. {
  713. smSaverRes.random = state.smRandom;
  714. sprintf(newRes+strlen(newRes), "dtsession*%srandom: %s\n",
  715. smGD.extensionSpec,
  716. smSaverRes.random ? "True\n" : "False\n");
  717. }
  718. if (newRes[0] != '\0')
  719. {
  720. _DtAddToResource(smGD.display, newRes);
  721. }
  722. free(newRes);
  723. }
  724. }
  725. else if (cEvent->message_type == XaDtSmSaverInfo)
  726. {
  727. SmSaverInfo saver;
  728. /*
  729. * Session screen saver list has been changed. Get new values.
  730. */
  731. if(_DtGetSmSaver(smGD.display, smGD.topLevelWindow, &saver) == Success)
  732. {
  733. char *pRes;
  734. SM_FREE(smGD.saverList);
  735. smGD.saverList = SmNewString(saver.saverList);
  736. SM_FREE(saver.saverList);
  737. pRes = malloc(strlen("dtsession*saverList: ") +
  738. strlen(smGD.saverList) +
  739. strlen(smGD.extensionSpec) +
  740. 2); /* for the '/n' and '/0' */
  741. if (pRes)
  742. {
  743. sprintf(pRes, "dtsession*%ssaverList: %s\n",
  744. smGD.extensionSpec,
  745. smGD.saverList);
  746. _DtAddToResource(smGD.display, pRes);
  747. free(pRes);
  748. }
  749. if (smGD.saverListParse)
  750. {
  751. SM_FREE(smGD.saverListParse);
  752. smGD.saverListParse = NULL;
  753. }
  754. }
  755. }
  756. #if defined (USE_HPSSEXT)
  757. else if(cEvent->message_type == XaSmScreenSaveRet)
  758. {
  759. if(cEvent->data.l[0] == SS_ON)
  760. {
  761. if (smSaverRes.saverTimeout + smSaverRes.lockTimeout > 0 &&
  762. smGD.smState == READY)
  763. {
  764. smGD.smState = IN_PROCESS;
  765. LockDisplay(False);
  766. }
  767. }
  768. }
  769. #endif /* USE_HPSSEXT */
  770. return;
  771. } /* END OF FUNCTION ProcessClientMessage */
  772. /*************************************<->*************************************
  773. *
  774. * ProcessScreenSaverMessage(next)
  775. *
  776. *
  777. * Description:
  778. * -----------
  779. * A screen saver message has come from the server. Process it if we know how.
  780. *
  781. * Inputs:
  782. * ------
  783. * next - the client message event
  784. *
  785. *
  786. * Outputs:
  787. * -------
  788. *
  789. *
  790. * Comments:
  791. * --------
  792. *
  793. *************************************<->***********************************/
  794. #if defined (USE_X11SSEXT)
  795. void
  796. ProcessScreenSaverMessage(
  797. XEvent *next)
  798. {
  799. XScreenSaverNotifyEvent *ssEvent = (XScreenSaverNotifyEvent *) next;
  800. static int ssCount = 0;
  801. if (ssEvent->state == ScreenSaverOn)
  802. {
  803. /*
  804. * Screen saver activated.
  805. */
  806. if (smSaverRes.saverTimeout + smSaverRes.lockTimeout > 0 &&
  807. smGD.smState == READY)
  808. {
  809. /*
  810. * Resource says to lock the display and SM is ready, so lock it.
  811. */
  812. smGD.smState = IN_PROCESS;
  813. LockDisplay(False);
  814. }
  815. }
  816. }
  817. #endif /* USE_X11SSEXT */
  818. /*************************************<->*************************************
  819. *
  820. * ProcessReloadActionsDatabase(void)
  821. *
  822. *
  823. * Description:
  824. * -----------
  825. * Register for notification of action database changes and load the action
  826. * database into our address space. This function can be called directly
  827. * by session mgr code, or called as a callback by the actions database.
  828. *
  829. * Inputs:
  830. * ------
  831. *
  832. * Outputs:
  833. * -------
  834. *
  835. * Comments:
  836. * --------
  837. * The first time in, this call registers itself as a callback routine with
  838. * the actions database. The first and subsequent times in, this call will
  839. * load the actions database into the session mgr address space.
  840. *
  841. *************************************<->***********************************/
  842. void
  843. ProcessReloadActionsDatabase(void)
  844. {
  845. static int needtoregister = 1;
  846. if (needtoregister)
  847. {
  848. /*
  849. * Have not yet registered with the actions database to call this
  850. * callback when the database changes. Do so.
  851. */
  852. DtDbReloadNotify((DtDbReloadCallbackProc) ProcessReloadActionsDatabase,
  853. (XtPointer) NULL);
  854. needtoregister = 0;
  855. }
  856. /*
  857. * Our copy of the actions database must be out of date. Reload.
  858. */
  859. DtDbLoad();
  860. }
  861. void
  862. ProcessEvent(Widget w, XtPointer client_data, XEvent *event,
  863. Boolean *continue_to_dispatch)
  864. {
  865. switch(event->type)
  866. {
  867. case ClientMessage:
  868. ProcessClientMessage(event);
  869. break;
  870. case PropertyNotify:
  871. ProcessPropertyNotify(event);
  872. break;
  873. default:
  874. #if defined (USE_X11SSEXT)
  875. if (event->type == smGD.ssEventType)
  876. ProcessScreenSaverMessage(event);
  877. #endif
  878. break;
  879. }
  880. }