Workaround for KDE's FONTLIST bug (and for the various
[nedit.git] / source / server_common.c
blobbcfe5a7e749cc85ef1fc3aec3732ab200d6f4d06
1 /*******************************************************************************
2 * *
3 * server_common.c -- Nirvana Editor common server stuff *
4 * *
5 * Copyright (C) 1999 Mark Edel *
6 * *
7 * This is free software; you can redistribute it and/or modify it under the *
8 * terms of the GNU General Public License as published by the Free Software *
9 * Foundation; either version 2 of the License, or (at your option) any later *
10 * version. *
11 * *
12 * This software is distributed in the hope that it will be useful, but WITHOUT *
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
15 * for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License along with *
18 * software; if not, write to the Free Software Foundation, Inc., 59 Temple *
19 * Place, Suite 330, Boston, MA 02111-1307 USA *
20 * *
21 * Nirvana Text Editor *
22 * November, 1995 *
23 * *
24 * Written by Mark Edel *
25 * *
26 *******************************************************************************/
27 #include <stdio.h>
28 #include <Xm/Xm.h>
29 #include <sys/types.h>
30 #ifdef VMS
31 #include "../util/VMSparam.h"
32 #else
33 #ifndef __MVS__
34 #include <sys/param.h>
35 #endif
36 #endif /*VMS*/
37 #include "textBuf.h"
38 #include "nedit.h"
39 #include "server_common.h"
40 #include "../util/utils.h"
43 * Create the server property atoms for the server with serverName.
44 * Atom names are generated as follows:
46 * NEDIT_SERVER_EXISTS_<host_name>_<user>_<server_name>
47 * NEDIT_SERVER_REQUEST_<host_name>_<user>_<server_name>
49 * <server_name> is the name that can be set by the user to allow
50 * for multiple servers to run on the same display. <server_name>
51 * defaults to "" if not supplied by the user.
53 * <user> is the user name of the current user.
55 void CreateServerPropertyAtoms(const char *serverName,
56 Atom *serverExistsAtomReturn,
57 Atom *serverRequestAtomReturn)
59 char propName[20+1+MAXNODENAMELEN+1+MAXUSERNAMELEN+1+MAXSERVERNAMELEN];
60 const char *userName = GetUserName();
61 const char *hostName = GetNameOfHost();
63 sprintf(propName, "NEDIT_SERVER_EXISTS_%s_%s_%s", hostName, userName, serverName);
64 *serverExistsAtomReturn = XInternAtom(TheDisplay, propName, False);
65 sprintf(propName, "NEDIT_SERVER_REQUEST_%s_%s_%s", hostName, userName, serverName);
66 *serverRequestAtomReturn = XInternAtom(TheDisplay, propName, False);
70 * Create the individual property atoms for each file being
71 * opened by the server with serverName. This atom is used
72 * by nc to monitor if the file has been closed.
74 * Atom names are generated as follows:
76 * NEDIT_FILE_<host_name>_<user>_<server_name>_<path>
78 * <server_name> is the name that can be set by the user to allow
79 * for multiple servers to run on the same display. <server_name>
80 * defaults to "" if not supplied by the user.
82 * <user> is the user name of the current user.
84 * <path> is the path of the file being edited.
86 Atom CreateServerFileOpenAtom(const char *serverName,
87 const char *path)
89 char propName[10+1+MAXNODENAMELEN+1+MAXUSERNAMELEN+1+MAXSERVERNAMELEN+1+MAXPATHLEN+1+7];
90 const char *userName = GetUserName();
91 const char *hostName = GetNameOfHost();
92 Atom atom;
94 sprintf(propName, "NEDIT_FILE_%s_%s_%s_%s_WF_OPEN", hostName, userName, serverName, path);
95 atom = XInternAtom(TheDisplay, propName, False);
96 return(atom);
99 Atom CreateServerFileClosedAtom(const char *serverName,
100 const char *path,
101 Bool only_if_exist)
103 char propName[10+1+MAXNODENAMELEN+1+MAXUSERNAMELEN+1+MAXSERVERNAMELEN+1+MAXPATHLEN+1+9];
104 const char *userName = GetUserName();
105 const char *hostName = GetNameOfHost();
106 Atom atom;
108 sprintf(propName, "NEDIT_FILE_%s_%s_%s_%s_WF_CLOSED", hostName, userName, serverName, path);
109 atom = XInternAtom(TheDisplay, propName, only_if_exist);
110 return(atom);
114 * Delete all File atoms that belong to this server (as specified by
115 * <host_name>_<user>_<server_name>).
117 void DeleteServerFileAtoms(const char* serverName, Window rootWindow)
119 char propNamePrefix[10+1+MAXNODENAMELEN+1+MAXUSERNAMELEN+1+MAXSERVERNAMELEN+1];
120 const char *userName = GetUserName();
121 const char *hostName = GetNameOfHost();
122 int length = sprintf(propNamePrefix, "NEDIT_FILE_%s_%s_%s_", hostName, userName, serverName);
124 int nProperties;
125 Atom* atoms = XListProperties(TheDisplay, rootWindow, &nProperties);
126 if (atoms != NULL) {
127 int i;
128 for (i = 0; i < nProperties; i++) {
129 /* XGetAtomNames() is more efficient, but doesn't exist in X11R5. */
130 char *name = XGetAtomName(TheDisplay, atoms[i]);
131 if (name != NULL && strncmp(propNamePrefix, name, length) == 0) {
132 XDeleteProperty(TheDisplay, rootWindow, atoms[i]);
135 XtFree((char*)atoms);