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 /* $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>
54 #include "SmUI.h" /* smDD.* */
57 #include "SmProtocol.h"
58 #include "SmGlobals.h"
62 * Structures visible to this module only.
67 /* variable length saver[] array */
68 /* saver command strings */
72 * Variables global to this module only
74 static int savernum; /* current screen saver number */
75 static void *saverstate = NULL; /* current running screen saver state */
76 static int firsttime = 1; /* first call to StartScreenSaver */
79 * Local Function declarations
81 static void ParseSaverList(char *, int *, int *, SmSaverParseStruct *);
85 /*************************************<->*************************************
92 * Start an external screen saver.
104 *************************************<->***********************************/
107 StartScreenSaver( void )
110 SmSaverParseStruct *parse;
112 if (!smGD.saverListParse)
115 * Parse the screen saver list.
117 smGD.saverListParse = SmSaverParseSaverList(smGD.saverList);
119 if (!smGD.saverListParse)
126 parse = (SmSaverParseStruct *)smGD.saverListParse;
128 if (parse->count == 0)
134 * Decide which saver number to use.
136 savernum = (savernum + 1) % parse->count;
141 * Load actions database.
143 ProcessReloadActionsDatabase();
148 * Start screen saver. _DtSaverStop() must be called to terminate the
151 saverstate = _DtSaverStart(smGD.display, smDD.coverDrawing,
152 smGD.numSavedScreens, parse->saver[savernum],
158 /*************************************<->*************************************
165 * Stop an external screen saver.
177 *************************************<->***********************************/
179 StopScreenSaver( void )
184 * Terminate screen saver.
186 _DtSaverStop(smGD.display, saverstate);
191 /*************************************<->*************************************
193 * SmSaverParseSaverList()
198 * Parse screen saver list into allocated buffer.
200 * SaverLine = {SaverSpec|WhiteSpace}
201 * SaverSpec = WhiteSpace Command WhiteSpace
202 * Command = <valid action name>
203 * WhiteSpace = {<space>|<horizontal tab>|<line feed>}
205 * For example, a saverList resource might be specified as:
207 * StartDtscreenSwarm \n\
208 * StartDtscreenQix \n\
211 * And be represented in memory as:
212 * "StartDtscreenSwarm \n StartDtscreenQix\n StartDtscreenLife"
217 * saverList - pointer to screen saver list. This memory is not changed.
225 * pointer to allocated memory containing parsed saver list
230 *************************************<->***********************************/
233 SmSaverParseSaverList(
236 char tokenSep[] = " \n\t";
240 int len = strlen(saverList);
241 int bytes = sizeof(int);
243 SmSaverParseStruct *pstruct;
245 tmpStr = (char *)XtMalloc(len + 1);
246 memcpy(tmpStr, saverList, len+1);
247 token = strtok(tmpStr, tokenSep);
251 bytes += sizeof(char *) + strlen(token) + 1;
252 token = strtok(NULL, tokenSep);
255 pstruct = (SmSaverParseStruct *)XtMalloc(bytes);
259 memcpy(tmpStr, saverList, len+1);
260 token = strtok(tmpStr, tokenSep);
262 p = (char *)(pstruct->saver + i);
266 pstruct->saver[pstruct->count] = p;
267 strcpy(pstruct->saver[pstruct->count], token);
268 p += strlen(token) + 1;
269 token = strtok(NULL, tokenSep);
273 XtFree ((char *) tmpStr);
274 return((void *)pstruct);