WmIPC.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  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. /*
  24. * (c) Copyright 1997, The Open Group
  25. */
  26. /*
  27. * (c) Copyright 1987, 1988, 1989, 1990, 1992, 1993 HEWLETT-PACKARD COMPANY
  28. * ALL RIGHTS RESERVED
  29. */
  30. /*
  31. * Included Files:
  32. */
  33. #include "WmGlobal.h"
  34. #include "WmProtocol.h"
  35. #include <Xm/XmAll.h>
  36. #include <Dt/Dt.h>
  37. #include <Dt/DtP.h>
  38. #include <Dt/Action.h>
  39. #include <Dt/WsmM.h>
  40. #include <Dt/IndicatorM.h>
  41. #include <Dt/UserMsg.h>
  42. #include <Dt/Icon.h>
  43. #include "WmBackdrop.h"
  44. #include "WmError.h"
  45. #include "WmFunction.h"
  46. #include "WmWrkspace.h"
  47. #include "WmIPC.h"
  48. #include "WmXSMP.h"
  49. #include "WmPanelP.h"
  50. #include "DataBaseLoad.h"
  51. /*
  52. * include extern functions and definitions
  53. */
  54. extern void UpdateFileTypeControlFields ( void );
  55. extern WmScreenData * GetScreenForWindow (Window);
  56. static void ToolTalkError(Widget, char*, Tt_status);
  57. /*
  58. * data for the "DT screen"
  59. */
  60. /*
  61. * globals
  62. */
  63. Const char *szWM_TOOL_CLASS = DtWM_TOOL_CLASS;
  64. /******************************<->*************************************
  65. *
  66. * dtInitialize (char * program_name, XtAppContext appContext)
  67. *
  68. * Description:
  69. * -----------
  70. * Initialize the messaging mechanism
  71. *
  72. * Inputs:
  73. * ------
  74. * program_name - argv[0]
  75. * appContext - used throughout the WM
  76. *
  77. * Outputs:
  78. * -------
  79. *
  80. * Comments:
  81. * --------
  82. *
  83. ******************************<->***********************************/
  84. void
  85. dtInitialize(
  86. char *program_name,
  87. XtAppContext appContext )
  88. {
  89. (void) DtAppInitialize(appContext, DISPLAY1, wmGD.topLevelW1,
  90. program_name, (char *)szWM_TOOL_CLASS);
  91. /*
  92. * Load action definitions from the action database.
  93. */
  94. #ifdef DT_PERFORMANCE
  95. _DtPerfChkpntMsgSend("Begin action database load");
  96. #endif
  97. DtDbLoad();
  98. #ifdef DT_PERFORMANCE
  99. _DtPerfChkpntMsgSend("End action database load");
  100. #endif
  101. } /* END OF FUNCTION dtInitialize */
  102. /******************************<->*************************************
  103. *
  104. * dtInitializeMessaging (Widget)
  105. *
  106. * Description:
  107. * -----------
  108. * Initialize the messaging mechanisms
  109. *
  110. * Inputs:
  111. * ------
  112. *
  113. * Outputs:
  114. * -------
  115. *
  116. * Comments:
  117. * --------
  118. *
  119. ******************************<->***********************************/
  120. void
  121. dtInitializeMessaging(Widget toplevel)
  122. {
  123. int i;
  124. WmScreenData * pSD;
  125. String sName;
  126. Tt_status status;
  127. Tt_pattern notice_pattern, request_pattern;
  128. char *default_session;
  129. int fd;
  130. char *procId;
  131. char *errfmt;
  132. Tt_callback_action NoticeMsgCB(
  133. Tt_message m,
  134. Tt_pattern p);
  135. Tt_callback_action RequestMsgCB(
  136. Tt_message m,
  137. Tt_pattern p);
  138. /*
  139. * Makef sure we have a ToolTalk connection
  140. */
  141. procId = tt_open();
  142. status = tt_ptr_error(procId);
  143. if (status != TT_OK) {
  144. errfmt =
  145. GETMESSAGE(2, 2, "Could not connect to ToolTalk:\n%s\n");
  146. ToolTalkError(toplevel, errfmt, status);
  147. return;
  148. }
  149. fd = tt_fd();
  150. status = tt_int_error(fd);
  151. if (status == TT_OK) {
  152. XtAppAddInput(XtWidgetToApplicationContext(wmGD.topLevelW), fd,
  153. (XtPointer)XtInputReadMask, tttk_Xt_input_handler, procId);
  154. } else {
  155. ToolTalkError(toplevel, "tt_fd()", status);
  156. }
  157. default_session = tt_default_session();
  158. status = tt_ptr_error(default_session);
  159. if (status != TT_OK) {
  160. errfmt = GETMESSAGE(2, 4, "Could not get default ToolTalk session:\n%s\n");
  161. ToolTalkError(toplevel, errfmt, status);
  162. return;
  163. }
  164. errfmt = GETMESSAGE(2, 5, "Error constructing ToolTalk pattern:\n%s\n");
  165. notice_pattern = tt_pattern_create();
  166. status = tt_ptr_error(notice_pattern);
  167. if (status != TT_OK) {
  168. ToolTalkError(toplevel, errfmt, status);
  169. return;
  170. }
  171. request_pattern = tt_pattern_create();
  172. status = tt_ptr_error(request_pattern);
  173. if (status != TT_OK) {
  174. ToolTalkError(toplevel, errfmt, status);
  175. return;
  176. }
  177. status = tt_pattern_category_set(notice_pattern, TT_OBSERVE);
  178. if (status != TT_OK) {
  179. ToolTalkError(toplevel, errfmt, status);
  180. return;
  181. }
  182. status = tt_pattern_category_set(request_pattern, TT_HANDLE);
  183. if (status != TT_OK) {
  184. ToolTalkError(toplevel, errfmt, status);
  185. return;
  186. }
  187. status = tt_pattern_scope_add(notice_pattern, TT_SESSION);
  188. if (status != TT_OK) {
  189. ToolTalkError(toplevel, errfmt, status);
  190. return;
  191. }
  192. status = tt_pattern_scope_add(request_pattern, TT_SESSION);
  193. if (status != TT_OK) {
  194. ToolTalkError(toplevel, errfmt, status);
  195. return;
  196. }
  197. status = tt_pattern_session_add(notice_pattern, default_session);
  198. if (status != TT_OK) {
  199. ToolTalkError(toplevel, errfmt, status);
  200. return;
  201. }
  202. status = tt_pattern_session_add(request_pattern, default_session);
  203. if (status != TT_OK) {
  204. ToolTalkError(toplevel, errfmt, status);
  205. return;
  206. }
  207. tt_free( default_session );
  208. status = tt_pattern_class_add(notice_pattern, TT_NOTICE);
  209. if (status != TT_OK) {
  210. ToolTalkError(toplevel, errfmt, status);
  211. return;
  212. }
  213. status = tt_pattern_state_add(notice_pattern, TT_SENT);
  214. if (status != TT_OK) {
  215. ToolTalkError(toplevel, errfmt, status);
  216. return;
  217. }
  218. status = tt_pattern_class_add(request_pattern, TT_REQUEST);
  219. if (status != TT_OK) {
  220. ToolTalkError(toplevel, errfmt, status);
  221. return;
  222. }
  223. status = tt_pattern_state_add(request_pattern, TT_SENT);
  224. if (status != TT_OK) {
  225. ToolTalkError(toplevel, errfmt, status);
  226. return;
  227. }
  228. /*
  229. * Ops handled by the notice_pattern
  230. */
  231. status = tt_pattern_op_add(notice_pattern, "DtActivity_Beginning");
  232. if (status != TT_OK) {
  233. ToolTalkError(toplevel, errfmt, status);
  234. return;
  235. }
  236. status = tt_pattern_op_add(notice_pattern, "DtActivity_Began");
  237. if (status != TT_OK) {
  238. ToolTalkError(toplevel, errfmt, status);
  239. return;
  240. }
  241. status = tt_pattern_op_add(notice_pattern, "DtTypes_Reloaded");
  242. if (status != TT_OK) {
  243. ToolTalkError(toplevel, errfmt, status);
  244. return;
  245. }
  246. /*
  247. * Ops handled by the request_pattern
  248. */
  249. status = tt_pattern_op_add(request_pattern, "DtPanel_Restore");
  250. if (status != TT_OK) {
  251. ToolTalkError(toplevel, errfmt, status);
  252. return;
  253. }
  254. status = tt_pattern_op_add(request_pattern, "DtWorkspace_SetCurrent");
  255. if (status != TT_OK) {
  256. ToolTalkError(toplevel, errfmt, status);
  257. return;
  258. }
  259. status = tt_pattern_op_add(request_pattern, "DtWorkspace_Title_Set");
  260. if (status != TT_OK) {
  261. ToolTalkError(toplevel, errfmt, status);
  262. return;
  263. }
  264. status = tt_pattern_op_add(request_pattern, "DtWorkspace_Add");
  265. if (status != TT_OK) {
  266. ToolTalkError(toplevel, errfmt, status);
  267. return;
  268. }
  269. status = tt_pattern_op_add(request_pattern, "DtWorkspace_Delete");
  270. if (status != TT_OK) {
  271. ToolTalkError(toplevel, errfmt, status);
  272. return;
  273. }
  274. status = tt_pattern_op_add(request_pattern, "GetWsmClients");
  275. if (status != TT_OK) {
  276. ToolTalkError(toplevel, errfmt, status);
  277. return;
  278. }
  279. /*
  280. * Register callback for the notice_pattern
  281. */
  282. status = tt_pattern_callback_add(notice_pattern, NoticeMsgCB);
  283. if (status != TT_OK) {
  284. ToolTalkError(toplevel, errfmt, status);
  285. return;
  286. }
  287. /*
  288. * Register callback for the request_pattern
  289. */
  290. status = tt_pattern_callback_add(request_pattern, RequestMsgCB);
  291. if (status != TT_OK) {
  292. ToolTalkError(toplevel, errfmt, status);
  293. return;
  294. }
  295. status = tt_pattern_register(notice_pattern);
  296. if (status != TT_OK) {
  297. ToolTalkError(toplevel, errfmt, status);
  298. return;
  299. }
  300. status = tt_pattern_register(request_pattern);
  301. if (status != TT_OK) {
  302. ToolTalkError(toplevel, errfmt, status);
  303. return;
  304. }
  305. } /* END OF FUNCTION dtInitializeMessaging */
  306. /******************************<->*************************************
  307. *
  308. * dtCloseIPC ()
  309. *
  310. * Description:
  311. * -----------
  312. * Shuts down the messaging mechanism
  313. *
  314. * Inputs:
  315. * ------
  316. *
  317. * Outputs:
  318. * -------
  319. *
  320. * Comments:
  321. * --------
  322. * Should be done before exiting
  323. *
  324. ******************************<->***********************************/
  325. void
  326. dtCloseIPC( void )
  327. {
  328. } /* END OF FUNCTION dtCloseIPC */
  329. /******************************<->*************************************
  330. *
  331. * void dtReadyNotification()
  332. *
  333. * Description:
  334. * -----------
  335. * Tells the world that we're up and ready.
  336. *
  337. * Inputs:
  338. * ------
  339. *
  340. * Outputs:
  341. * -------
  342. *
  343. * Comments:
  344. * --------
  345. * Invoked as the fitting culmination of dtwm initialization
  346. *
  347. ******************************<->***********************************/
  348. void
  349. dtReadyNotification( void )
  350. {
  351. SendClientMsg( wmGD.dtSmWindow,
  352. (long) wmGD.xa_DT_SM_WM_PROTOCOL,
  353. (long) wmGD.xa_DT_WM_READY,
  354. CurrentTime, NULL, 0);
  355. } /* END OF FUNCTION dtReadyNotification */
  356. /******************************<->*************************************
  357. *
  358. * WmStopWaiting ()
  359. *
  360. * Description:
  361. * -----------
  362. * This is called to turn off "system busy" activity
  363. *
  364. * Inputs:
  365. * ------
  366. *
  367. * Outputs:
  368. * -------
  369. * None
  370. *
  371. * Comments:
  372. * ---------
  373. * This routine relies on two globals, blinkerPCW and dtSD,
  374. * on the major assumptions that:
  375. * - there is just one DT Screen, with the front panel enabled
  376. * - there is just one dtwmbusy control in that front panel
  377. ******************************<->***********************************/
  378. void
  379. WmStopWaiting( void )
  380. {
  381. if (wmGD.dtSD)
  382. {
  383. WmFrontPanelSetBusy (False);
  384. }
  385. } /* END OF FUNCTION WmStopWaiting */
  386. /******************************<->*************************************
  387. *
  388. * dtSendWorkspaceModifyNotification ()
  389. *
  390. * Description:
  391. * -----------
  392. * This is called to announce that the workspace set has been
  393. * modified
  394. *
  395. * Inputs:
  396. * ------
  397. * pSD - pointer to screen data
  398. * aWs - id of workspace just modified
  399. * iType - type of modification
  400. *
  401. * Outputs:
  402. * -------
  403. * None
  404. *
  405. * Comments:
  406. * ---------
  407. * Sends the message:
  408. *
  409. * "MODIFY_WORKSPACE" "<atom_for_wsname>" "<modify_type>"
  410. *
  411. * <modify_type> is one of:
  412. * ADD
  413. * DELETE
  414. * BACKDROP
  415. * TITLE
  416. ******************************<->***********************************/
  417. void
  418. dtSendWorkspaceModifyNotification(
  419. WmScreenData *pSD,
  420. Atom aWs,
  421. int iType)
  422. {
  423. char sNum[40];
  424. char pch[40];
  425. char pchType[40];
  426. Tt_message msg;
  427. Tt_status status;
  428. msg = tt_pnotice_create(TT_SESSION, "DtWorkspace_Modified");
  429. status = tt_ptr_error(msg);
  430. if (status != TT_OK) {
  431. return;
  432. }
  433. sprintf(sNum, "%d", pSD->screen);
  434. status = tt_message_arg_add(msg, TT_IN, Tttk_string, sNum);
  435. if (status != TT_OK) {
  436. return;
  437. }
  438. sprintf (pch, "%ld", aWs);
  439. status = tt_message_arg_add(msg, TT_IN, Tttk_string, pch);
  440. if (status != TT_OK) {
  441. return;
  442. }
  443. sprintf (pchType, "%d", iType);
  444. status = tt_message_arg_add(msg, TT_IN, Tttk_string, pchType);
  445. if (status != TT_OK) {
  446. return;
  447. }
  448. status = tt_message_send(msg);
  449. if (status != TT_OK) {
  450. return;
  451. }
  452. tt_message_destroy(msg);
  453. }
  454. /******************************<->*************************************
  455. *
  456. * dtSendMarqueeSelectionNotification ()
  457. *
  458. * Description:
  459. * -----------
  460. * This is called to announce marquee selection state
  461. *
  462. * Inputs:
  463. * ------
  464. * pSD - pointer to screen data
  465. * type - id of workspace just modified
  466. * x - x position of UL corner of rectangle
  467. * y - y position of UL corner of rectangle
  468. * width - width of rectangle
  469. * height - height of rectangle
  470. *
  471. * Outputs:
  472. * -------
  473. * None
  474. *
  475. * Comments:
  476. * ---------
  477. * Sends the message:
  478. *
  479. * "MARQUEE_SELECTION" "<type>" "<x>" "<y>" "<width>" "<height>"
  480. *
  481. * <modify_type> is one of:
  482. * BEGIN
  483. * END
  484. * CONTINUE
  485. * CANCEL
  486. ******************************<->***********************************/
  487. void
  488. dtSendMarqueeSelectionNotification(
  489. WmScreenData *pSD,
  490. int type,
  491. Position x,
  492. Position y,
  493. Dimension width,
  494. Dimension height)
  495. {
  496. Tt_message msg;
  497. Tt_status status;
  498. char sNum[40];
  499. msg = tt_pnotice_create(TT_SESSION, "DtMarquee_Selection");
  500. status = tt_ptr_error(msg);
  501. if (status != TT_OK) {
  502. return;
  503. }
  504. sprintf(sNum, "%d", pSD->screen);
  505. status = tt_message_arg_add(msg, TT_IN, Tttk_string, sNum);
  506. if (status != TT_OK) {
  507. return;
  508. }
  509. if (tt_message_arg_add(msg, TT_IN, "integer", NULL) != TT_OK) {
  510. return;
  511. }
  512. if (tt_message_arg_ival_set(msg, 1, type) != TT_OK) {
  513. return;
  514. }
  515. if (tt_message_arg_add(msg, TT_IN, "integer", NULL) != TT_OK) {
  516. return;
  517. }
  518. if (tt_message_arg_ival_set(msg, 2, x) != TT_OK) {
  519. return;
  520. }
  521. if (tt_message_arg_add(msg, TT_IN, "integer", NULL) != TT_OK) {
  522. return;
  523. }
  524. if (tt_message_arg_ival_set(msg, 3, y) != TT_OK) {
  525. return;
  526. }
  527. if (tt_message_arg_add(msg, TT_IN, "integer", NULL) != TT_OK) {
  528. return;
  529. }
  530. if (tt_message_arg_ival_set(msg, 4, width) != TT_OK) {
  531. return;
  532. }
  533. if (tt_message_arg_add(msg, TT_IN, "integer", NULL) != TT_OK) {
  534. return;
  535. }
  536. if (tt_message_arg_ival_set(msg, 5, height) != TT_OK) {
  537. return;
  538. }
  539. status = tt_message_send(msg);
  540. if (status != TT_OK) {
  541. return;
  542. }
  543. tt_message_destroy(msg);
  544. }
  545. /******************************<->*************************************
  546. *
  547. * NoticeMsgCB ()
  548. *
  549. *
  550. * Description:
  551. * -----------
  552. * This is called to handle busy and stopbusy message
  553. *
  554. * Inputs:
  555. * ------
  556. * m = ToolTalk message
  557. * p = ToolTalk pattern
  558. *
  559. * Outputs:
  560. * -------
  561. * TT_CALLBACK_PROCESSED
  562. * TT_CALLBACK_CINTINUE
  563. *
  564. * Comments:
  565. * ---------
  566. ******************************<->***********************************/
  567. Tt_callback_action
  568. NoticeMsgCB(Tt_message m, Tt_pattern p)
  569. {
  570. char *op;
  571. Tt_status status;
  572. if (tt_message_state(m) != TT_SENT) {
  573. return TT_CALLBACK_CONTINUE;
  574. }
  575. op = tt_message_op(m);
  576. status = tt_ptr_error(op);
  577. if (status != TT_OK) {
  578. return TT_CALLBACK_CONTINUE;
  579. }
  580. if (!strcmp(op, "DtActivity_Began")) {
  581. WmStopWaiting();
  582. /* CDExc21081 */
  583. tt_message_destroy(m);
  584. }
  585. else if (!strcmp(op, "DtActivity_Beginning")) {
  586. if (wmGD.dtSD) {
  587. WmFrontPanelSetBusy (True);
  588. }
  589. /* CDExc21081 */
  590. tt_message_destroy(m);
  591. }
  592. else if (!strcmp(op, "DtTypes_Reloaded")) {
  593. /*
  594. * Blink busy light during reload.
  595. */
  596. WmFrontPanelSetBusy (True);
  597. /*
  598. * Load action definitions from the action database.
  599. */
  600. DtDbLoad();
  601. UpdateFileTypeControlFields();
  602. /*
  603. * Turn off busy light.
  604. */
  605. WmFrontPanelSetBusy (False);
  606. /* CDExc21081 */
  607. tt_message_destroy(m);
  608. }
  609. tt_free(op);
  610. return TT_CALLBACK_PROCESSED;
  611. } /* END OF FUNCTION NoticeMsgCB */
  612. /******************************<->*************************************
  613. *
  614. * RequestMsgCB ()
  615. *
  616. *
  617. * Description:
  618. * -----------
  619. * This is called to handle busy and stopbusy message
  620. *
  621. * Inputs:
  622. * ------
  623. * m = ToolTalk message
  624. * p = ToolTalk pattern
  625. *
  626. * Outputs:
  627. * -------
  628. * TT_CALLBACK_PROCESSED
  629. * TT_CALLBACK_CINTINUE
  630. *
  631. * Comments:
  632. * ---------
  633. ******************************<->***********************************/
  634. Tt_callback_action
  635. RequestMsgCB(Tt_message m, Tt_pattern p)
  636. {
  637. char *op;
  638. Tt_status status;
  639. int screen_num;
  640. WmScreenData *pSD;
  641. WmWorkspaceData *pWS = NULL;
  642. Atom aWs;
  643. char *pch;
  644. String sName;
  645. if (tt_message_state(m) != TT_SENT) {
  646. return TT_CALLBACK_CONTINUE;
  647. }
  648. op = tt_message_op(m);
  649. status = tt_ptr_error(op);
  650. if (status != TT_OK) {
  651. return TT_CALLBACK_CONTINUE;
  652. }
  653. if (!strcmp(op, "DtPanel_Restore")) {
  654. tt_message_reply(m);
  655. tt_message_destroy(m);
  656. SessionDeleteAll();
  657. F_Restart( DTWM_REQP_NO_CONFIRM, NULL, NULL );
  658. }
  659. else if (!strcmp(op, "DtWorkspace_SetCurrent")) {
  660. /*
  661. * 1st arg: integer, screen number
  662. * 2nd arg: string, atom of workspace name
  663. */
  664. /* get the first arg from the message */
  665. tt_message_arg_ival(m, 0, &screen_num);
  666. pSD = &wmGD.Screens[screen_num];
  667. /* get the second arg from the message */
  668. pch = tt_message_arg_val(m, 1);
  669. /* retrieve the selected workspace */
  670. aWs = strtoul (pch, (char **) NULL, 0);
  671. tt_free( pch );
  672. pWS = GetWorkspaceData (pSD, aWs);
  673. if (pWS) {
  674. ChangeToWorkspace (pWS);
  675. }
  676. tt_message_reply(m);
  677. tt_message_destroy(m);
  678. }
  679. else if (!strcmp(op, "DtWorkspace_Title_Set")) {
  680. /*
  681. * 1st arg: integer, screen number
  682. * 2nd arg: string, atom of workspace name
  683. * 3rd arg: string, new name for the workspace
  684. */
  685. /* get the first arg from the message */
  686. tt_message_arg_ival(m, 0, &screen_num);
  687. pSD = &wmGD.Screens[screen_num];
  688. /* get the second arg from the message */
  689. pch = tt_message_arg_val(m, 1);
  690. /* retrieve the selected workspace */
  691. aWs = strtoul (pch, (char **) NULL, 0);
  692. tt_free( pch );
  693. pWS = GetWorkspaceData (pSD, aWs);
  694. /* get the third arg from the message */
  695. pch = tt_message_arg_val(m, 2);
  696. if (pWS) {
  697. ChangeWorkspaceTitle (pWS, pch);
  698. }
  699. tt_free( pch );
  700. tt_message_reply(m);
  701. tt_message_destroy(m);
  702. }
  703. else if (!strcmp(op, "DtWorkspace_Add")) {
  704. /*
  705. * 1st arg: string, user-visible title of the workspace
  706. */
  707. pch = tt_message_arg_val(m, 0);
  708. F_CreateWorkspace( pch, NULL, NULL );
  709. tt_free( pch );
  710. tt_message_reply(m);
  711. tt_message_destroy(m);
  712. }
  713. else if (!strcmp(op, "DtWorkspace_Delete")) {
  714. /*
  715. * 1st arg: string, atom of workspace name
  716. */
  717. pch = tt_message_arg_val(m, 0);
  718. /* retrieve the selected workspace */
  719. aWs = strtoul (pch, (char **) NULL, 0);
  720. tt_free( pch );
  721. sName = (String) XmGetAtomName (DISPLAY1, aWs);
  722. F_DeleteWorkspace( sName, NULL, NULL );
  723. tt_message_reply(m);
  724. tt_message_destroy(m);
  725. XtFree(sName);
  726. }
  727. else if (!strcmp(op, "GetWsmClients")) {
  728. /* No TT_IN args. */
  729. ClientData **clients;
  730. int nClients;
  731. if (GetSmClientIdClientList(&clients, &nClients))
  732. {
  733. char *clientIds = (char *)NULL;
  734. int *clientWorkspaces = (int *)NULL;
  735. int clientIdLen = 0;
  736. SortClientListByWorkspace(clients, nClients);
  737. tt_message_arg_ival_set(m, 0, nClients);
  738. if (nClients > 0)
  739. {
  740. int i;
  741. char *ptr;
  742. ClientData *pCD;
  743. clientIdLen = 0;
  744. for (i = 0; i < nClients; i++)
  745. clientIdLen += strlen(clients[i]->smClientID) + 1;
  746. if (((clientIds =
  747. (char *)XtMalloc(clientIdLen * sizeof(char)))
  748. == (char *)NULL) ||
  749. ((clientWorkspaces =
  750. (int *)XtMalloc(nClients * sizeof(int)))
  751. == (int *)NULL))
  752. {
  753. if (clientIds != (char *)NULL)
  754. XtFree(clientIds);
  755. /* LATER - Right way to handle errors? */
  756. tt_message_fail(m);
  757. tt_message_destroy(m);
  758. tt_free(op);
  759. return TT_CALLBACK_PROCESSED;
  760. }
  761. else
  762. {
  763. for (i = 0, ptr = clientIds;
  764. i < nClients;
  765. ptr += strlen(pCD->smClientID) + 1, i++)
  766. {
  767. pCD = clients[i];
  768. strcpy(ptr, pCD->smClientID);
  769. clientWorkspaces[i] =
  770. pCD->pWsList[pCD->currentWsc].wsID;
  771. }
  772. }
  773. }
  774. tt_message_arg_bval_set(m, 1, (unsigned char *)clientIds,
  775. clientIdLen * sizeof(char));
  776. tt_message_arg_bval_set(m, 2, (unsigned char *)clientWorkspaces,
  777. nClients * sizeof(int));
  778. if (clientIds != (char *)NULL)
  779. XtFree(clientIds);
  780. if (clientWorkspaces != (int *)NULL)
  781. XtFree((char *)clientWorkspaces);
  782. XtFree((char *)clients);
  783. }
  784. tt_message_reply(m);
  785. tt_message_destroy(m);
  786. } else {
  787. tt_free( op );
  788. return TT_CALLBACK_CONTINUE;
  789. }
  790. tt_free(op);
  791. return TT_CALLBACK_PROCESSED;
  792. } /* END OF FUNCTION RequestMsgCB */
  793. /******************************<->*************************************
  794. *
  795. * ToolTalkError ()
  796. *
  797. *
  798. * Description:
  799. * -----------
  800. *
  801. * Inputs:
  802. * ------
  803. *
  804. * Outputs:
  805. * -------
  806. *
  807. * Comments:
  808. * ---------
  809. ******************************<->***********************************/
  810. #define GETXMSTRING(s, m, d) XmStringCreateLocalized(GETMESSAGE(s,m,d))
  811. static void
  812. OKCB (Widget dialog, XtPointer client_data, XtPointer call_data)
  813. {
  814. XtUnmanageChild((Widget) client_data);
  815. }
  816. static void
  817. ToolTalkError(Widget parent, char *errfmt, Tt_status status)
  818. {
  819. Arg args[10];
  820. Widget dialog, dialogShell;
  821. char *errmsg, *statmsg, *title;
  822. XmString xms_errmsg, xms_ok, xms_title;
  823. int n;
  824. if (! tt_is_err(status)) return;
  825. statmsg = tt_status_message(status);
  826. errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
  827. sprintf(errmsg, errfmt, statmsg);
  828. xms_ok = GETXMSTRING(2, 3, "OK");
  829. xms_errmsg = XmStringCreateLocalized(errmsg);
  830. xms_title = GETXMSTRING(2, 1, "Dtwm - Error");
  831. n = 0;
  832. XtSetArg(args[n], XmNautoUnmanage, False); n++;
  833. XtSetArg(args[n], XmNokLabelString, xms_ok); n++;
  834. XtSetArg(args[n], XmNdialogTitle, xms_title); n++;
  835. XtSetArg(args[n], XmNmessageString, xms_errmsg); n++;
  836. XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
  837. dialog = XmCreateErrorDialog(parent, "IconEditorError", args, n);
  838. XtAddCallback(dialog, XmNokCallback, OKCB, (XtPointer) dialog);
  839. XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
  840. XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
  841. /*
  842. * Disable the frame menu from dialog since we don't want the user
  843. * to be able to close dialogs with the frame menu
  844. */
  845. dialogShell = XtParent(dialog);
  846. n = 0;
  847. XtSetArg(args[n], XmNmwmDecorations, MWM_DECOR_BORDER | MWM_DECOR_TITLE); n++;
  848. XtSetValues(dialogShell, args, n);
  849. XtManageChild(dialog);
  850. XtRealizeWidget(dialogShell);
  851. _DtSimpleError("Dtwm", DtFatalError, NULL, errmsg);
  852. XtFree(errmsg);
  853. XmStringFree(xms_ok);
  854. XmStringFree(xms_errmsg);
  855. XmStringFree(xms_title);
  856. }
  857. /**************************** eof ***************************/