1 ;;; w32-win.el --- parse switches controlling interface with W32 window system
3 ;; Copyright (C) 1993, 1994, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; w32-win.el: this file is loaded from ../lisp/startup.el when it recognizes
29 ;; that W32 windows are to be used. Command line switches are parsed and those
30 ;; pertaining to W32 are processed and removed from the command line. The
31 ;; W32 display is opened and hooks are set for popping up the initial window.
33 ;; startup.el will then examine startup files, and eventually call the hooks
34 ;; which create the first window (s).
39 ;; These are the standard X switches from the Xt Initialize.c file of
42 ;; Command line Resource Manager string
45 ;; +synchronous *synchronous
46 ;; -background *background
49 ;; -bordercolor *borderColor
50 ;; -borderwidth .borderWidth
56 ;; -foreground *foreground
57 ;; -geometry .geometry
62 ;; -reverse *reverseVideo
64 ;; -selectionTimeout .selectionTimeout
65 ;; -synchronous *synchronous
68 ;; An alist of X options and the function which handles them. See
71 (if (not (eq window-system 'w32))
72 (error "%s: Loading w32-win.el but not compiled for w32" (invocation-name)))
83 ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
84 (if (fboundp 'new-fontset)
87 ;; The following definition is used for debugging scroll bar events.
88 ;(defun w32-handle-scroll-bar-event (event) (interactive "e") (princ event))
90 ;; Handle mouse-wheel events with mwheel.
93 (defun w32-drag-n-drop-debug (event)
94 "Print the drag-n-drop EVENT in a readable form."
98 (defun w32-drag-n-drop (event)
99 "Edit the files listed in the drag-n-drop EVENT.
100 Switch to a buffer editing the last file dropped."
103 ;; Make sure the drop target has positive co-ords
104 ;; before setting the selected frame - otherwise it
105 ;; won't work. <skx@tardis.ed.ac.uk>
106 (let* ((window (posn-window (event-start event)))
107 (coords (posn-x-y (event-start event)))
110 (if (and (> x 0) (> y 0))
111 (set-frame-selected-window nil window))
112 (mapcar (lambda (file-name)
113 (dnd-handle-one-url window 'private
114 (concat "file:" file-name)))
115 (car (cdr (cdr event)))))
118 (defun w32-drag-n-drop-other-frame (event)
119 "Edit the files listed in the drag-n-drop EVENT, in other frames.
120 May create new frames, or reuse existing ones. The frame editing
121 the last file dropped is selected."
123 (mapcar 'find-file-other-frame (car (cdr (cdr event)))))
125 ;; Bind the drag-n-drop event.
126 (global-set-key [drag-n-drop] 'w32-drag-n-drop)
127 (global-set-key [C-drag-n-drop] 'w32-drag-n-drop-other-frame)
129 ;; Keyboard layout/language change events
130 ;; For now ignore language-change events; in the future
131 ;; we should switch the Emacs Input Method to match the
132 ;; new layout/language selected by the user.
133 (global-set-key [language-change] 'ignore)
135 (defvar x-invocation-args)
137 (defvar x-command-line-resources nil)
139 (defun x-handle-switch (switch)
140 "Handle SWITCH of the form \"-switch value\" or \"-switch\"."
141 (let ((aelt (assoc switch command-line-x-option-alist)))
143 (push (cons (nth 3 aelt) (or (nth 4 aelt) (pop x-invocation-args)))
144 default-frame-alist))))
146 (defun x-handle-numeric-switch (switch)
147 "Handle SWITCH of the form \"-switch n\"."
148 (let ((aelt (assoc switch command-line-x-option-alist)))
150 (push (cons (nth 3 aelt) (string-to-number (pop x-invocation-args)))
151 default-frame-alist))))
153 ;; Handle options that apply to initial frame only
154 (defun x-handle-initial-switch (switch)
155 (let ((aelt (assoc switch command-line-x-option-alist)))
157 (push (cons (nth 3 aelt) (or (nth 4 aelt) (pop x-invocation-args)))
158 initial-frame-alist))))
160 (defun x-handle-iconic (switch)
161 "Make \"-iconic\" SWITCH apply only to the initial frame."
162 (push '(visibility . icon) initial-frame-alist))
164 (defun x-handle-xrm-switch (switch)
165 "Handle the \"-xrm\" SWITCH."
166 (or (consp x-invocation-args)
167 (error "%s: missing argument to `%s' option" (invocation-name) switch))
168 (setq x-command-line-resources
169 (if (null x-command-line-resources)
170 (car x-invocation-args)
171 (concat x-command-line-resources "\n" (car x-invocation-args))))
172 (setq x-invocation-args (cdr x-invocation-args)))
174 (defun x-handle-geometry (switch)
175 "Handle the \"-geometry\" SWITCH."
176 (let* ((geo (x-parse-geometry (car x-invocation-args)))
177 (left (assq 'left geo))
178 (top (assq 'top geo))
179 (height (assq 'height geo))
180 (width (assq 'width geo)))
181 (if (or height width)
182 (setq default-frame-alist
183 (append default-frame-alist
185 (if height (list height))
186 (if width (list width)))
188 (append initial-frame-alist
190 (if height (list height))
191 (if width (list width)))))
193 (setq initial-frame-alist
194 (append initial-frame-alist
195 '((user-position . t))
196 (if left (list left))
197 (if top (list top)))))
198 (setq x-invocation-args (cdr x-invocation-args))))
200 (defun x-handle-name-switch (switch)
201 "Handle a \"-name\" SWITCH."
202 ;; Handle the -name option. Set the variable x-resource-name
203 ;; to the option's operand; set the name of the initial frame, too.
204 (or (consp x-invocation-args)
205 (error "%s: missing argument to `%s' option" (invocation-name) switch))
206 (setq x-resource-name (pop x-invocation-args))
207 (push (cons 'name x-resource-name) initial-frame-alist))
209 (defvar x-display-name nil
210 "The display name specifying server and frame.")
212 (defun x-handle-display (switch)
213 "Handle the \"-display\" SWITCH."
214 (setq x-display-name (pop x-invocation-args)))
216 (defun x-handle-args (args)
217 "Process the X-related command line options in ARGS.
218 This is done before the user's startup file is loaded. They are copied to
219 `x-invocation args' from which the X-related things are extracted, first
220 the switch (e.g., \"-fg\") in the following code, and possible values
221 \(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
222 This returns ARGS with the arguments that have been processed removed."
223 ;; We use ARGS to accumulate the args that we don't handle here, to return.
224 (setq x-invocation-args args
226 (while (and x-invocation-args
227 (not (equal (car x-invocation-args) "--")))
228 (let* ((this-switch (car x-invocation-args))
229 (orig-this-switch this-switch)
230 completion argval aelt handler)
231 (setq x-invocation-args (cdr x-invocation-args))
232 ;; Check for long options with attached arguments
233 ;; and separate out the attached option argument into argval.
234 (if (string-match "^--[^=]*=" this-switch)
235 (setq argval (substring this-switch (match-end 0))
236 this-switch (substring this-switch 0 (1- (match-end 0)))))
237 ;; Complete names of long options.
238 (if (string-match "^--" this-switch)
240 (setq completion (try-completion this-switch command-line-x-option-alist))
241 (if (eq completion t)
242 ;; Exact match for long option.
244 (if (stringp completion)
245 (let ((elt (assoc completion command-line-x-option-alist)))
246 ;; Check for abbreviated long option.
248 (error "Option `%s' is ambiguous" this-switch))
249 (setq this-switch completion))))))
250 (setq aelt (assoc this-switch command-line-x-option-alist))
251 (if aelt (setq handler (nth 2 aelt)))
254 (let ((x-invocation-args
255 (cons argval x-invocation-args)))
256 (funcall handler this-switch))
257 (funcall handler this-switch))
258 (push orig-this-switch args))))
259 (nconc (nreverse args) x-invocation-args))
265 (defvar x-colors '("LightGreen"
864 "LightGoldenrodYellow"
865 "light goldenrod yellow"
882 "medium spring green"
1017 "The list of X colors from the `rgb.txt' file.
1018 XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
1020 (defun xw-defined-colors (&optional frame)
1021 "Internal function called by `defined-colors', which see."
1022 (or frame (setq frame (selected-frame)))
1023 (let ((defined-colors nil))
1024 (dolist (this-color (or (mapcar 'car w32-color-map) x-colors))
1025 (and (color-supported-p this-color frame t)
1026 (push this-color defined-colors)))
1032 ;;; make f10 activate the real menubar rather than the mini-buffer menu
1033 ;;; navigation feature.
1034 (global-set-key [f10] (lambda ()
1035 (interactive) (w32-send-sys-command ?\xf100)))
1037 (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
1041 ;;; Do the actual Windows setup here; the above code just defines
1042 ;;; functions and variables that we use now.
1044 (setq command-line-args (x-handle-args command-line-args))
1046 ;;; Make sure we have a valid resource name.
1047 (or (stringp x-resource-name)
1048 (setq x-resource-name
1049 ;; Change any . or * characters in x-resource-name to hyphens,
1050 ;; so as not to choke when we use it in X resource queries.
1051 (replace-regexp-in-string "[.*]" "-" (invocation-name))))
1053 ;; For the benefit of older Emacses (19.27 and earlier) that are sharing
1054 ;; the same lisp directory, don't pass the third argument unless we seem
1055 ;; to have the multi-display support.
1056 (if (fboundp 'x-close-connection)
1057 (x-open-connection ""
1058 x-command-line-resources
1059 ;; Exit Emacs with fatal error if this fails.
1061 (x-open-connection ""
1062 x-command-line-resources))
1064 (setq frame-creation-function 'x-create-frame-with-faces)
1066 (setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
1069 ;; W32 expects the menu bar cut and paste commands to use the clipboard.
1070 ;; This has ,? to match both on Sunos and on Solaris.
1071 (menu-bar-enable-clipboard)
1073 ;; W32 systems have different fonts than commonly found on X, so
1074 ;; we define our own standard fontset here.
1075 (defvar w32-standard-fontset-spec
1076 "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-fontset-standard"
1077 "String of fontset spec of the standard fontset.
1078 This defines a fontset consisting of the Courier New variations for
1079 European languages which are distributed with Windows as
1080 \"Multilanguage Support\".
1082 See the documentation of `create-fontset-from-fontset-spec for the format.")
1084 ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
1085 (if (fboundp 'new-fontset)
1087 ;; Setup the default fontset.
1088 (setup-default-fontset)
1089 ;; Create the standard fontset.
1090 (create-fontset-from-fontset-spec w32-standard-fontset-spec t)
1091 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1,...).
1092 (create-fontset-from-x-resource)
1093 ;; Try to create a fontset from a font specification which comes
1094 ;; from initial-frame-alist, default-frame-alist, or X resource.
1095 ;; A font specification in command line argument (i.e. -fn XXXX)
1096 ;; should be already in default-frame-alist as a `font'
1097 ;; parameter. However, any font specifications in site-start
1098 ;; library, user's init file (.emacs), and default.el are not
1099 ;; yet handled here.
1101 (let ((font (or (cdr (assq 'font initial-frame-alist))
1102 (cdr (assq 'font default-frame-alist))
1103 (x-get-resource "font" "Font")))
1104 xlfd-fields resolved-name)
1106 (not (query-fontset font))
1107 (setq resolved-name (x-resolve-font-name font))
1108 (setq xlfd-fields (x-decompose-font-name font)))
1109 (if (string= "fontset"
1110 (aref xlfd-fields xlfd-regexp-registry-subnum))
1112 (x-complement-fontset-spec xlfd-fields nil))
1113 ;; Create a fontset from FONT. The fontset name is
1114 ;; generated from FONT.
1115 (create-fontset-from-ascii-font font
1116 resolved-name "startup"))))))
1118 ;; Apply a geometry resource to the initial frame. Put it at the end
1119 ;; of the alist, so that anything specified on the command line takes
1121 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
1125 (setq parsed (x-parse-geometry res-geometry))
1126 ;; If the resource specifies a position,
1127 ;; call the position and size "user-specified".
1128 (if (or (assq 'top parsed) (assq 'left parsed))
1129 (setq parsed (cons '(user-position . t)
1130 (cons '(user-size . t) parsed))))
1131 ;; All geometry parms apply to the initial frame.
1132 (setq initial-frame-alist (append initial-frame-alist parsed))
1133 ;; The size parms apply to all frames.
1134 (if (assq 'height parsed)
1135 (push (cons 'height (cdr (assq 'height parsed)))
1136 default-frame-alist))
1137 (if (assq 'width parsed)
1138 (push (cons 'width (cdr (assq 'width parsed)))
1139 default-frame-alist)))))
1141 ;; Check the reverseVideo resource.
1142 (let ((case-fold-search t))
1143 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
1144 (if (and rv (string-match "^\\(true\\|yes\\|on\\)$" rv))
1145 (push '(reverse . t) default-frame-alist))))
1147 (defun x-win-suspend-error ()
1148 "Report an error when a suspend is attempted."
1149 (error "Suspending an Emacs running under W32 makes no sense"))
1150 (add-hook 'suspend-hook 'x-win-suspend-error)
1152 ;;; Turn off window-splitting optimization; w32 is usually fast enough
1153 ;;; that this is only annoying.
1154 (setq split-window-keep-point t)
1156 ;; Don't show the frame name; that's redundant.
1157 (setq-default mode-line-frame-identification " ")
1159 ;;; Set to a system sound if you want a fancy bell.
1160 (set-message-beep 'ok)
1162 ;; Remap some functions to call w32 common dialogs
1164 (defun internal-face-interactive (what &optional bool)
1165 (let* ((fn (intern (concat "face-" what)))
1166 (prompt (concat "Set " what " of face "))
1167 (face (read-face-name prompt))
1168 (default (if (fboundp fn)
1169 (or (funcall fn face (selected-frame))
1170 (funcall fn 'default (selected-frame)))))
1171 (fn-win (intern (concat (symbol-name window-system) "-select-" what)))
1174 (cond ((fboundp fn-win)
1177 (completing-read (concat prompt " " (symbol-name face) " to: ")
1178 (mapcar (function (lambda (color)
1179 (cons color color)))
1181 nil nil nil nil default))
1183 (y-or-n-p (concat "Should face " (symbol-name face)
1186 (read-string (concat prompt " " (symbol-name face) " to: ")
1188 (list face (if (equal value "") nil value))))
1190 ;;; Enable Japanese fonts on Windows to be used by default.
1191 (set-fontset-font nil (make-char 'katakana-jisx0201) '("*" . "JISX0208-SJIS"))
1192 (set-fontset-font nil (make-char 'latin-jisx0201) '("*" . "JISX0208-SJIS"))
1193 (set-fontset-font nil (make-char 'japanese-jisx0208) '("*" . "JISX0208-SJIS"))
1194 (set-fontset-font nil (make-char 'japanese-jisx0208-1978) '("*" . "JISX0208-SJIS"))
1196 (defun mouse-set-font (&rest fonts)
1198 If `w32-use-w32-font-dialog' is non-nil (the default), use the Windows
1199 font dialog to get the matching FONTS. Otherwise use a pop-up menu
1200 \(like Emacs on other platforms) initialized with the fonts in
1201 `w32-fixed-font-alist'."
1203 (if w32-use-w32-font-dialog
1204 (let ((chosen-font (w32-select-font (selected-frame)
1205 w32-list-proportional-fonts)))
1206 (and chosen-font (list chosen-font)))
1209 ;; Append list of fontsets currently defined.
1210 ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
1211 (if (fboundp 'new-fontset)
1212 (append w32-fixed-font-alist (list (generate-fontset-menu)))))))
1218 (setq font (car fonts))
1219 (set-default-font font)
1221 (error (setq fonts (cdr fonts)))))
1223 (error "Font not found")))))
1225 ;;; Set default known names for image libraries
1226 (setq image-library-alist
1227 '((xpm "xpm4.dll" "libXpm-nox4.dll" "libxpm.dll")
1228 (png "libpng13d.dll" "libpng13.dll" "libpng12d.dll" "libpng12.dll" "libpng.dll")
1229 (jpeg "jpeg62.dll" "libjpeg.dll" "jpeg-62.dll" "jpeg.dll")
1230 (tiff "libtiff3.dll" "libtiff.dll")
1231 (gif "libungif.dll")))
1233 ;; arch-tag: 69fb1701-28c2-4890-b351-3d1fe4b4f166
1234 ;;; w32-win.el ends here