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: SmHftRing.c /main/5 1996/11/01 10:17:15 drk $ */
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 the AIX 3.2.x specific code required to enable and
40 ** disable the HFT ring. This is used for session locking.
42 *****************************************************************************
43 *************************************<+>*************************************/
50 #include <X11/Xosdefs.h>
60 static int open_hft_file(char *);
61 static void close_hft_file(int);
62 static int get_hft_ring(void);
63 static int process_hft(int, unsigned int);
64 static int scan_hft_ring(int);
65 static int my_strpos(char *, char);
66 static int is_local_display(void);
68 #define HFTRFILE "/dev/hft/0"
69 #define HFQSTAT hftqstat
70 #define HFSMGRCMD hftsmgrcmd
71 #define HFQEIO HFQERROR
72 #define HFCSMGR HFTCSMGR
73 #define HFQSMGR HFTQSMGR
74 #define HFVTSTATUS (HFVTACTIVE | HFVTNOHOTKEY)
75 #define HF_VTIODN hf_vtid
81 struct HFQSTAT hft_ring;
84 open_hft_file(char *hft_file_name)
86 return(open(hft_file_name, O_RDONLY));
90 close_hft_file(int hft_file)
99 struct hfbuf hft_buffer;
101 hft_buffer.hf_bufp = (char *)&hft_ring;
102 hft_buffer.hf_buflen = sizeof(hft_ring);
106 * Open the hft queue manager.
108 if ((hft_file = open_hft_file(HFTRFILE)) >= 0)
110 rc = ioctl(hft_file, HFQSMGR, &hft_buffer);
111 close_hft_file(hft_file);
118 process_hft(int hft_action, unsigned int hft_vtid)
120 struct HFSMGRCMD hft_manager;
121 char hft_file_name[20];
124 hft_manager.hf_cmd = hft_action;
125 hft_manager.hf_vtid = hft_vtid;
127 sprintf(hft_file_name, "/dev/hft/%u", hft_vtid);
128 if ((hft_file = open_hft_file(hft_file_name)) >= 0)
130 rc = ioctl(hft_file, HFCSMGR, &hft_manager);
131 close_hft_file(hft_file);
138 scan_hft_ring(int hft_action)
143 if (get_hft_ring() != 0)
148 for (hft = 0; hft < hft_ring.hf_numvts; hft++)
150 if (!(hft_ring.hf_vtinfo[hft].hf_vtstate & HFVTSTATUS))
152 if (process_hft(hft_action, hft_ring.hf_vtinfo[hft].HF_VTIODN) != 0)
162 my_strpos(char *s, char c)
166 return((t=strchr(s,c)) == NULL ? -1 : t - s);
170 is_local_display(void)
172 static int is_local = -1; /* display status */
173 char *dpyname; /* display name */
174 int n; /* position of colon char */
175 char hostname[MAXHOSTNAMELEN]; /* host name */
180 (((dpyname = getenv("DISPLAY")) != NULL) && /* name not null */
181 ((n = my_strpos(dpyname, ':')) != -1) && /* name has a colon */
182 ((n == 0) || /* name is :n */
183 (strncmp(dpyname, "unix", n) == 0) || /* name is unix:n */
184 (strncmp(dpyname, "localhost", n) == 0) || /* name is localhost:n */
185 ((gethostname(hostname, MAXHOSTNAMELEN) == 0) && /* hostname ok */
186 (strncmp(dpyname, hostname, n) == 0)))); /* name == hostname */
193 AixEnableHftRing(int enable)
195 if (is_local_display())
197 scan_hft_ring(enable ? SMUNHIDE : SMHIDE);