1 /* Console functions for X windows.
2 Copyright (C) 1996 Ben Wing.
4 This file is part of XEmacs.
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Synched up with: Not in FSF. */
23 /* This file Mule-ized by Ben Wing, 7-10-00. */
27 Ben Wing: January 1996, for 19.14.
33 #include "console-x.h"
35 #include "process.h" /* canonicalize_host_name */
36 #include "redisplay.h" /* for display_arg */
38 DEFINE_CONSOLE_TYPE (x);
41 x_initially_selected_for_input (struct console *con)
47 split_up_display_spec (Lisp_Object display, int *hostname_length,
48 int *display_length, int *screen_length)
52 dotptr = strrchr ((char *) XSTRING_DATA (display), ':');
55 *hostname_length = XSTRING_LENGTH (display);
60 *hostname_length = dotptr - XSTRING_DATA (display);
62 dotptr = strchr ((char *) dotptr, '.');
64 *display_length = (dotptr - XSTRING_DATA (display) - *hostname_length);
66 *display_length = XSTRING_LENGTH (display) - *hostname_length;
69 *screen_length = (XSTRING_LENGTH (display) - *display_length
73 /* Remember, in all of the following functions, we have to verify
74 the integrity of our input, because the generic functions don't. */
77 x_device_to_console_connection (Lisp_Object connection, Error_behavior errb)
79 /* Strip the trailing .# off of the connection, if it's there. */
81 if (NILP (connection))
85 int hostname_length, display_length, screen_length;
87 if (!ERRB_EQ (errb, ERROR_ME))
89 if (!STRINGP (connection))
93 CHECK_STRING (connection);
95 split_up_display_spec (connection, &hostname_length, &display_length,
97 connection = make_string (XSTRING_DATA (connection),
98 hostname_length + display_length);
105 get_display_arg_connection (void)
107 const Extbyte *disp_name;
109 /* If the user didn't explicitly specify a display to use when
110 they called make-x-device, then we first check to see if a
111 display was specified on the command line with -display. If
112 so, we set disp_name to it. Otherwise we use XDisplayName to
113 see what DISPLAY is set to. XtOpenDisplay knows how to do
114 both of these things, but we need to know the name to use. */
122 make_argc_argv (Vx_initial_argv_list, &argc, &argv);
125 for (elt = 0; elt < argc; elt++)
127 if (!strcmp (argv[elt], "-d") || !strcmp (argv[elt], "-display"))
131 suppress_early_error_handler_backtrace = 1;
132 type_error (Qinvalid_argument,
133 "-display specified with no arg");
137 disp_name = argv[elt + 1];
143 /* assert: display_arg is only set if we found the display
144 arg earlier so we can't fail to find it now. */
145 assert (disp_name != NULL);
146 conn = build_ext_string (disp_name, Qcommand_argument_encoding);
147 free_argc_argv (argv);
151 return build_ext_string (XDisplayName (0), Qx_display_name_encoding);
154 /* "semi-canonicalize" means convert to a nicer form for printing, but
155 don't completely canonicalize (into some likely ugly form) */
158 x_semi_canonicalize_console_connection (Lisp_Object connection,
165 if (NILP (connection))
166 connection = get_display_arg_connection ();
169 if (!ERRB_EQ (errb, ERROR_ME))
171 if (!STRINGP (connection))
172 RETURN_UNGCPRO (Qunbound);
175 CHECK_STRING (connection);
179 /* Be lenient, allow people to specify a device connection instead of
180 a console connection -- e.g. "foo:0.0" instead of "foo:0". This
181 only happens in `find-console' and `get-console'. */
182 connection = x_device_to_console_connection (connection, errb);
184 /* Check for a couple of standard special cases */
185 if (string_byte (XSTRING (connection), 0) == ':')
186 connection = concat2 (build_string ("localhost"), connection);
187 else if (!strncmp (XSTRING_DATA (connection), "unix:", 5))
188 connection = concat2 (build_string ("localhost:"),
189 Fsubstring (connection, make_int (5), Qnil));
191 RETURN_UNGCPRO (connection);
195 x_canonicalize_console_connection (Lisp_Object connection, Error_behavior errb)
197 Lisp_Object hostname = Qnil;
198 struct gcpro gcpro1, gcpro2;
200 GCPRO2 (connection, hostname);
202 connection = x_semi_canonicalize_console_connection (connection, errb);
203 if (UNBOUNDP (connection))
204 RETURN_UNGCPRO (Qunbound);
207 int hostname_length, display_length, screen_length;
209 split_up_display_spec (connection, &hostname_length, &display_length,
211 hostname = Fsubstring (connection, Qzero, make_int (hostname_length));
212 hostname = canonicalize_host_name (hostname);
213 connection = concat2 (hostname,
214 make_string (XSTRING_DATA (connection)
215 + hostname_length, display_length));
218 RETURN_UNGCPRO (connection);
222 x_semi_canonicalize_device_connection (Lisp_Object connection,
225 int hostname_length, display_length, screen_length;
229 if (NILP (connection))
230 connection = get_display_arg_connection ();
233 if (!ERRB_EQ (errb, ERROR_ME))
235 if (!STRINGP (connection))
236 RETURN_UNGCPRO (Qunbound);
239 CHECK_STRING (connection);
242 split_up_display_spec (connection, &hostname_length, &display_length,
246 connection = concat2 (connection, build_string (".0"));
247 RETURN_UNGCPRO (connection);
251 x_canonicalize_device_connection (Lisp_Object connection, Error_behavior errb)
253 int hostname_length, display_length, screen_length;
254 Lisp_Object screen_str = Qnil;
255 struct gcpro gcpro1, gcpro2;
257 GCPRO2 (screen_str, connection);
258 connection = x_semi_canonicalize_device_connection (connection, errb);
259 if (UNBOUNDP (connection))
260 RETURN_UNGCPRO (Qunbound);
262 split_up_display_spec (connection, &hostname_length, &display_length,
265 screen_str = build_string (XSTRING_DATA (connection)
266 + hostname_length + display_length);
267 connection = x_canonicalize_console_connection (connection, errb);
269 RETURN_UNGCPRO (concat2 (connection, screen_str));
273 console_type_create_x (void)
275 INITIALIZE_CONSOLE_TYPE (x, "x", "console-x-p");
277 CONSOLE_HAS_METHOD (x, semi_canonicalize_console_connection);
278 CONSOLE_HAS_METHOD (x, canonicalize_console_connection);
279 CONSOLE_HAS_METHOD (x, semi_canonicalize_device_connection);
280 CONSOLE_HAS_METHOD (x, canonicalize_device_connection);
281 CONSOLE_HAS_METHOD (x, device_to_console_connection);
282 CONSOLE_HAS_METHOD (x, initially_selected_for_input);
287 reinit_console_type_create_x (void)
289 REINITIALIZE_CONSOLE_TYPE (x);