1 ;;; w32-win.el --- parse switches controlling interface with W32 window system
3 ;; Copyright (C) 1993, 1994, 2003, 2004 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; w32-win.el: this file is loaded from ../lisp/startup.el when it recognizes
28 ;; that W32 windows are to be used. Command line switches are parsed and those
29 ;; pertaining to W32 are processed and removed from the command line. The
30 ;; W32 display is opened and hooks are set for popping up the initial window.
32 ;; startup.el will then examine startup files, and eventually call the hooks
33 ;; which create the first window (s).
38 ;; These are the standard X switches from the Xt Initialize.c file of
41 ;; Command line Resource Manager string
44 ;; +synchronous *synchronous
45 ;; -background *background
48 ;; -bordercolor *borderColor
49 ;; -borderwidth .borderWidth
55 ;; -foreground *foreground
56 ;; -geometry .geometry
61 ;; -reverse *reverseVideo
63 ;; -selectionTimeout .selectionTimeout
64 ;; -synchronous *synchronous
67 ;; An alist of X options and the function which handles them. See
70 (if (not (eq window-system 'w32))
71 (error "%s: Loading w32-win.el but not compiled for w32" (invocation-name)))
82 ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
83 (if (fboundp 'new-fontset)
86 ;; The following definition is used for debugging scroll bar events.
87 ;(defun w32-handle-scroll-bar-event (event) (interactive "e") (princ event))
89 ;; Handle mouse-wheel events with mwheel.
92 (defun w32-drag-n-drop-debug (event)
93 "Print the drag-n-drop EVENT in a readable form."
97 (defun w32-drag-n-drop (event)
98 "Edit the files listed in the drag-n-drop EVENT.
99 Switch to a buffer editing the last file dropped."
102 ;; Make sure the drop target has positive co-ords
103 ;; before setting the selected frame - otherwise it
104 ;; won't work. <skx@tardis.ed.ac.uk>
105 (let* ((window (posn-window (event-start event)))
106 (coords (posn-x-y (event-start event)))
109 (if (and (> x 0) (> y 0))
110 (set-frame-selected-window nil window))
111 (mapcar (lambda (file-name)
112 (x-dnd-handle-one-url window 'private
113 (concat "file:" file-name)))
114 (car (cdr (cdr event)))))
117 (defun w32-drag-n-drop-other-frame (event)
118 "Edit the files listed in the drag-n-drop EVENT, in other frames.
119 May create new frames, or reuse existing ones. The frame editing
120 the last file dropped is selected."
122 (mapcar 'find-file-other-frame (car (cdr (cdr event)))))
124 ;; Bind the drag-n-drop event.
125 (global-set-key [drag-n-drop] 'w32-drag-n-drop)
126 (global-set-key [C-drag-n-drop] 'w32-drag-n-drop-other-frame)
128 ;; Keyboard layout/language change events
129 ;; For now ignore language-change events; in the future
130 ;; we should switch the Emacs Input Method to match the
131 ;; new layout/language selected by the user.
132 (global-set-key [language-change] 'ignore)
134 (defvar x-invocation-args)
136 (defvar x-command-line-resources nil)
138 (defun x-handle-switch (switch)
139 "Handle SWITCH of the form \"-switch value\" or \"-switch\"."
140 (let ((aelt (assoc switch command-line-x-option-alist)))
142 (let ((param (nth 3 aelt))
143 (value (nth 4 aelt)))
145 (setq default-frame-alist
146 (cons (cons param value)
147 default-frame-alist))
148 (setq default-frame-alist
150 (car x-invocation-args))
152 x-invocation-args (cdr x-invocation-args)))))))
154 (defun x-handle-numeric-switch (switch)
155 "Handle SWITCH of the form \"-switch n\"."
156 (let ((aelt (assoc switch command-line-x-option-alist)))
158 (let ((param (nth 3 aelt)))
159 (setq default-frame-alist
161 (string-to-int (car x-invocation-args)))
164 (cdr x-invocation-args))))))
166 ;; Handle options that apply to initial frame only
167 (defun x-handle-initial-switch (switch)
168 (let ((aelt (assoc switch command-line-x-option-alist)))
170 (let ((param (nth 3 aelt))
171 (value (nth 4 aelt)))
173 (setq initial-frame-alist
174 (cons (cons param value)
175 initial-frame-alist))
176 (setq initial-frame-alist
178 (car x-invocation-args))
180 x-invocation-args (cdr x-invocation-args)))))))
182 (defun x-handle-iconic (switch)
183 "Make \"-iconic\" SWITCH apply only to the initial frame."
184 (setq initial-frame-alist
185 (cons '(visibility . icon) initial-frame-alist)))
187 (defun x-handle-xrm-switch (switch)
188 "Handle the \"-xrm\" SWITCH."
189 (or (consp x-invocation-args)
190 (error "%s: missing argument to `%s' option" (invocation-name) switch))
191 (setq x-command-line-resources
192 (if (null x-command-line-resources)
193 (car x-invocation-args)
194 (concat x-command-line-resources "\n" (car x-invocation-args))))
195 (setq x-invocation-args (cdr x-invocation-args)))
197 (defun x-handle-geometry (switch)
198 "Handle the \"-geometry\" SWITCH."
199 (let* ((geo (x-parse-geometry (car x-invocation-args)))
200 (left (assq 'left geo))
201 (top (assq 'top geo))
202 (height (assq 'height geo))
203 (width (assq 'width geo)))
204 (if (or height width)
205 (setq default-frame-alist
206 (append default-frame-alist
208 (if height (list height))
209 (if width (list width)))
211 (append initial-frame-alist
213 (if height (list height))
214 (if width (list width)))))
216 (setq initial-frame-alist
217 (append initial-frame-alist
218 '((user-position . t))
219 (if left (list left))
220 (if top (list top)))))
221 (setq x-invocation-args (cdr x-invocation-args))))
223 (defun x-handle-name-switch (switch)
224 "Handle a \"-name\" SWITCH."
225 ;; Handle the -name option. Set the variable x-resource-name
226 ;; to the option's operand; set the name of the initial frame, too.
227 (or (consp x-invocation-args)
228 (error "%s: missing argument to `%s' option" (invocation-name) switch))
229 (setq x-resource-name (car x-invocation-args)
230 x-invocation-args (cdr x-invocation-args))
231 (setq initial-frame-alist (cons (cons 'name x-resource-name)
232 initial-frame-alist)))
234 (defvar x-display-name nil
235 "The display name specifying server and frame.")
237 (defun x-handle-display (switch)
238 "Handle the \"-display\" SWITCH."
239 (setq x-display-name (car x-invocation-args)
240 x-invocation-args (cdr x-invocation-args)))
242 (defun x-handle-args (args)
243 "Process the X-related command line options in ARGS.
244 This is done before the user's startup file is loaded. They are copied to
245 `x-invocation args' from which the X-related things are extracted, first
246 the switch (e.g., \"-fg\") in the following code, and possible values
247 \(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
248 This returns ARGS with the arguments that have been processed removed."
249 ;; We use ARGS to accumulate the args that we don't handle here, to return.
250 (setq x-invocation-args args
252 (while (and x-invocation-args
253 (not (equal (car x-invocation-args) "--")))
254 (let* ((this-switch (car x-invocation-args))
255 (orig-this-switch this-switch)
256 completion argval aelt handler)
257 (setq x-invocation-args (cdr x-invocation-args))
258 ;; Check for long options with attached arguments
259 ;; and separate out the attached option argument into argval.
260 (if (string-match "^--[^=]*=" this-switch)
261 (setq argval (substring this-switch (match-end 0))
262 this-switch (substring this-switch 0 (1- (match-end 0)))))
263 ;; Complete names of long options.
264 (if (string-match "^--" this-switch)
266 (setq completion (try-completion this-switch command-line-x-option-alist))
267 (if (eq completion t)
268 ;; Exact match for long option.
270 (if (stringp completion)
271 (let ((elt (assoc completion command-line-x-option-alist)))
272 ;; Check for abbreviated long option.
274 (error "Option `%s' is ambiguous" this-switch))
275 (setq this-switch completion))))))
276 (setq aelt (assoc this-switch command-line-x-option-alist))
277 (if aelt (setq handler (nth 2 aelt)))
280 (let ((x-invocation-args
281 (cons argval x-invocation-args)))
282 (funcall handler this-switch))
283 (funcall handler this-switch))
284 (setq args (cons orig-this-switch args)))))
285 (nconc (nreverse args) x-invocation-args))
291 (defvar x-colors '("LightGreen"
890 "LightGoldenrodYellow"
891 "light goldenrod yellow"
908 "medium spring green"
1043 "The list of X colors from the `rgb.txt' file.
1044 XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
1046 (defun xw-defined-colors (&optional frame)
1047 "Internal function called by `defined-colors', which see."
1048 (or frame (setq frame (selected-frame)))
1049 (let* ((color-map-colors (mapcar (lambda (clr) (car clr)) w32-color-map))
1050 (all-colors (or color-map-colors x-colors))
1052 (defined-colors nil))
1053 (message "Defining colors...")
1055 (setq this-color (car all-colors)
1056 all-colors (cdr all-colors))
1057 (and (color-supported-p this-color frame t)
1058 (setq defined-colors (cons this-color defined-colors))))
1064 ;;; make f10 activate the real menubar rather than the mini-buffer menu
1065 ;;; navigation feature.
1066 (global-set-key [f10] (lambda ()
1067 (interactive) (w32-send-sys-command ?\xf100)))
1069 (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
1073 ;;; Do the actual Windows setup here; the above code just defines
1074 ;;; functions and variables that we use now.
1076 (setq command-line-args (x-handle-args command-line-args))
1078 ;;; Make sure we have a valid resource name.
1079 (or (stringp x-resource-name)
1081 (setq x-resource-name (invocation-name))
1083 ;; Change any . or * characters in x-resource-name to hyphens,
1084 ;; so as not to choke when we use it in X resource queries.
1085 (while (setq i (string-match "[.*]" x-resource-name))
1086 (aset x-resource-name i ?-))))
1088 ;; For the benefit of older Emacses (19.27 and earlier) that are sharing
1089 ;; the same lisp directory, don't pass the third argument unless we seem
1090 ;; to have the multi-display support.
1091 (if (fboundp 'x-close-connection)
1092 (x-open-connection ""
1093 x-command-line-resources
1094 ;; Exit Emacs with fatal error if this fails.
1096 (x-open-connection ""
1097 x-command-line-resources))
1099 (setq frame-creation-function 'x-create-frame-with-faces)
1101 (setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
1104 ;; W32 expects the menu bar cut and paste commands to use the clipboard.
1105 ;; This has ,? to match both on Sunos and on Solaris.
1106 (menu-bar-enable-clipboard)
1108 ;; W32 systems have different fonts than commonly found on X, so
1109 ;; we define our own standard fontset here.
1110 (defvar w32-standard-fontset-spec
1111 "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-fontset-standard"
1112 "String of fontset spec of the standard fontset.
1113 This defines a fontset consisting of the Courier New variations for
1114 European languages which are distributed with Windows as
1115 \"Multilanguage Support\".
1117 See the documentation of `create-fontset-from-fontset-spec for the format.")
1119 ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
1120 (if (fboundp 'new-fontset)
1122 ;; Setup the default fontset.
1123 (setup-default-fontset)
1124 ;; Create the standard fontset.
1125 (create-fontset-from-fontset-spec w32-standard-fontset-spec t)
1126 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1,...).
1127 (create-fontset-from-x-resource)
1128 ;; Try to create a fontset from a font specification which comes
1129 ;; from initial-frame-alist, default-frame-alist, or X resource.
1130 ;; A font specification in command line argument (i.e. -fn XXXX)
1131 ;; should be already in default-frame-alist as a `font'
1132 ;; parameter. However, any font specifications in site-start
1133 ;; library, user's init file (.emacs), and default.el are not
1134 ;; yet handled here.
1136 (let ((font (or (cdr (assq 'font initial-frame-alist))
1137 (cdr (assq 'font default-frame-alist))
1138 (x-get-resource "font" "Font")))
1139 xlfd-fields resolved-name)
1141 (not (query-fontset font))
1142 (setq resolved-name (x-resolve-font-name font))
1143 (setq xlfd-fields (x-decompose-font-name font)))
1144 (if (string= "fontset"
1145 (aref xlfd-fields xlfd-regexp-registry-subnum))
1147 (x-complement-fontset-spec xlfd-fields nil))
1148 ;; Create a fontset from FONT. The fontset name is
1149 ;; generated from FONT.
1150 (create-fontset-from-ascii-font font
1151 resolved-name "startup"))))))
1153 ;; Apply a geometry resource to the initial frame. Put it at the end
1154 ;; of the alist, so that anything specified on the command line takes
1156 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
1160 (setq parsed (x-parse-geometry res-geometry))
1161 ;; If the resource specifies a position,
1162 ;; call the position and size "user-specified".
1163 (if (or (assq 'top parsed) (assq 'left parsed))
1164 (setq parsed (cons '(user-position . t)
1165 (cons '(user-size . t) parsed))))
1166 ;; All geometry parms apply to the initial frame.
1167 (setq initial-frame-alist (append initial-frame-alist parsed))
1168 ;; The size parms apply to all frames.
1169 (if (assq 'height parsed)
1170 (setq default-frame-alist
1171 (cons (cons 'height (cdr (assq 'height parsed)))
1172 default-frame-alist)))
1173 (if (assq 'width parsed)
1174 (setq default-frame-alist
1175 (cons (cons 'width (cdr (assq 'width parsed)))
1176 default-frame-alist))))))
1178 ;; Check the reverseVideo resource.
1179 (let ((case-fold-search t))
1180 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
1182 (string-match "^\\(true\\|yes\\|on\\)$" rv))
1183 (setq default-frame-alist
1184 (cons '(reverse . t) default-frame-alist)))))
1186 (defun x-win-suspend-error ()
1187 "Report an error when a suspend is attempted."
1188 (error "Suspending an Emacs running under W32 makes no sense"))
1189 (add-hook 'suspend-hook 'x-win-suspend-error)
1191 ;;; Turn off window-splitting optimization; w32 is usually fast enough
1192 ;;; that this is only annoying.
1193 (setq split-window-keep-point t)
1195 ;; Don't show the frame name; that's redundant.
1196 (setq-default mode-line-frame-identification " ")
1198 ;;; Set to a system sound if you want a fancy bell.
1199 (set-message-beep 'ok)
1201 ;; Remap some functions to call w32 common dialogs
1203 (defun internal-face-interactive (what &optional bool)
1204 (let* ((fn (intern (concat "face-" what)))
1205 (prompt (concat "Set " what " of face "))
1206 (face (read-face-name prompt))
1207 (default (if (fboundp fn)
1208 (or (funcall fn face (selected-frame))
1209 (funcall fn 'default (selected-frame)))))
1210 (fn-win (intern (concat (symbol-name window-system) "-select-" what)))
1213 (cond ((fboundp fn-win)
1216 (completing-read (concat prompt " " (symbol-name face) " to: ")
1217 (mapcar (function (lambda (color)
1218 (cons color color)))
1220 nil nil nil nil default))
1222 (y-or-n-p (concat "Should face " (symbol-name face)
1225 (read-string (concat prompt " " (symbol-name face) " to: ")
1227 (list face (if (equal value "") nil value))))
1229 ;;; Enable Japanese fonts on Windows to be used by default.
1230 (set-fontset-font nil (make-char 'katakana-jisx0201) '("*" . "JISX0208-SJIS"))
1231 (set-fontset-font nil (make-char 'latin-jisx0201) '("*" . "JISX0208-SJIS"))
1232 (set-fontset-font nil (make-char 'japanese-jisx0208) '("*" . "JISX0208-SJIS"))
1233 (set-fontset-font nil (make-char 'japanese-jisx0208-1978) '("*" . "JISX0208-SJIS"))
1235 (defun mouse-set-font (&rest fonts)
1237 If `w32-use-w32-font-dialog' is non-nil (the default), use the Windows
1238 font dialog to get the matching FONTS. Otherwise use a pop-up menu
1239 \(like Emacs on other platforms) initialized with the fonts in
1240 `w32-fixed-font-alist'."
1242 (if w32-use-w32-font-dialog
1243 (let ((chosen-font (w32-select-font (selected-frame)
1244 w32-list-proportional-fonts)))
1245 (and chosen-font (list chosen-font)))
1248 ;; Append list of fontsets currently defined.
1249 ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
1250 (if (fboundp 'new-fontset)
1251 (append w32-fixed-font-alist (list (generate-fontset-menu)))))))
1257 (setq font (car fonts))
1258 (set-default-font font)
1260 (error (setq fonts (cdr fonts)))))
1262 (error "Font not found")))))
1264 ;;; Set default known names for image libraries
1265 (setq image-library-alist
1266 '((xpm "libXpm-nox4.dll" "libxpm.dll")
1267 (png "libpng13d.dll" "libpng13.dll" "libpng12d.dll" "libpng12.dll" "libpng.dll")
1268 (jpeg "jpeg62.dll" "libjpeg.dll" "jpeg-62.dll" "jpeg.dll")
1269 (tiff "libtiff3.dll" "libtiff.dll")
1270 (gif "libungif.dll")))
1272 ;;; arch-tag: 69fb1701-28c2-4890-b351-3d1fe4b4f166
1273 ;;; w32-win.el ends here