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 libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: SmScreen.c /main/4 1995/10/30 09:38:03 rswiston $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
26 * (c) Copyright 1993, 1994 International Business Machines Corp. *
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
28 * (c) Copyright 1993, 1994 Novell, Inc. *
30 /*************************************<+>*************************************
31 *****************************************************************************
35 ** Project: DT Session Manager (dtsession)
39 ** This file contains all routines needed to manage external
42 *****************************************************************************
43 *************************************<+>*************************************/
47 #include <X11/Intrinsic.h>
48 #include <X11/Xutil.h>
49 #include <X11/Xatom.h>
51 #include <Dt/UserMsg.h>
52 #include <Dt/SaverP.h>
55 #include "SmUI.h" /* smDD.* */
58 #include "SmProtocol.h"
59 #include "SmGlobals.h"
63 * Structures visible to this module only.
68 /* variable length saver[] array */
69 /* saver command strings */
73 * Variables global to this module only
75 static int savernum; /* current screen saver number */
76 static void *saverstate = NULL; /* current running screen saver state */
77 static int firsttime = 1; /* first call to StartScreenSaver */
80 * Local Function declarations
82 static void ParseSaverList(char *, int *, int *, SmSaverParseStruct *);
86 /*************************************<->*************************************
93 * Start an external screen saver.
105 *************************************<->***********************************/
108 StartScreenSaver( void )
111 SmSaverParseStruct *parse;
113 if (!smGD.saverListParse)
116 * Parse the screen saver list.
118 smGD.saverListParse = SmSaverParseSaverList(smGD.saverList);
120 if (!smGD.saverListParse)
127 parse = (SmSaverParseStruct *)smGD.saverListParse;
129 if (parse->count == 0)
135 * Decide which saver number to use.
137 savernum = (savernum + 1) % parse->count;
142 * Load actions database.
144 ProcessReloadActionsDatabase();
149 * Start screen saver. _DtSaverStop() must be called to terminate the
152 saverstate = _DtSaverStart(smGD.display, smDD.coverDrawing,
153 smGD.numSavedScreens, parse->saver[savernum],
159 /*************************************<->*************************************
166 * Stop an external screen saver.
178 *************************************<->***********************************/
180 StopScreenSaver( void )
185 * Terminate screen saver.
187 _DtSaverStop(smGD.display, saverstate);
192 /*************************************<->*************************************
194 * SmSaverParseSaverList()
199 * Parse screen saver list into allocated buffer.
201 * SaverLine = {SaverSpec|WhiteSpace}
202 * SaverSpec = WhiteSpace Command WhiteSpace
203 * Command = <valid action name>
204 * WhiteSpace = {<space>|<horizontal tab>|<line feed>}
206 * For example, a saverList resource might be specified as:
208 * StartDtscreenSwarm \n\
209 * StartDtscreenQix \n\
212 * And be represented in memory as:
213 * "StartDtscreenSwarm \n StartDtscreenQix\n StartDtscreenLife"
218 * saverList - pointer to screen saver list. This memory is not changed.
226 * pointer to allocated memory containing parsed saver list
231 *************************************<->***********************************/
234 SmSaverParseSaverList(
237 char tokenSep[] = " \n\t";
241 int len = strlen(saverList);
242 int bytes = sizeof(long);
244 SmSaverParseStruct *pstruct;
246 tmpStr = (char *)XtMalloc(len + 1);
247 memcpy(tmpStr, saverList, len+1);
248 token = strtok(tmpStr, tokenSep);
252 bytes += sizeof(char *) + strlen(token) + 1;
253 token = strtok(NULL, tokenSep);
256 pstruct = (SmSaverParseStruct *)XtMalloc(bytes);
260 memcpy(tmpStr, saverList, len+1);
261 token = strtok(tmpStr, tokenSep);
263 p = (char *)(pstruct->saver + i);
267 pstruct->saver[pstruct->count] = p;
268 strcpy(pstruct->saver[pstruct->count], token);
269 p += strlen(token) + 1;
270 token = strtok(NULL, tokenSep);
274 XtFree ((char *) tmpStr);
275 return((void *)pstruct);