1 ;;; w32-win.el --- parse switches controlling interface with W32 window system
3 ;; Copyright (C) 1993, 1994, 2002, 2003, 2004,
4 ;; 2005, 2006 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 (defvar xlfd-regexp-registry-subnum
)
85 ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
86 (if (fboundp 'new-fontset
)
89 ;; The following definition is used for debugging scroll bar events.
90 ;(defun w32-handle-scroll-bar-event (event) (interactive "e") (princ event))
92 ;; Handle mouse-wheel events with mwheel.
95 (defun w32-drag-n-drop-debug (event)
96 "Print the drag-n-drop EVENT in a readable form."
100 (defun w32-drag-n-drop (event)
101 "Edit the files listed in the drag-n-drop EVENT.
102 Switch to a buffer editing the last file dropped."
105 ;; Make sure the drop target has positive co-ords
106 ;; before setting the selected frame - otherwise it
107 ;; won't work. <skx@tardis.ed.ac.uk>
108 (let* ((window (posn-window (event-start event
)))
109 (coords (posn-x-y (event-start event
)))
112 (if (and (> x
0) (> y
0))
113 (set-frame-selected-window nil window
))
114 (mapcar (lambda (file-name)
115 (let ((f (subst-char-in-string ?
\\ ?
/ file-name
))
116 (coding (or file-name-coding-system
117 default-file-name-coding-system
)))
119 (mapconcat 'url-hexify-string
120 (split-string (encode-coding-string f coding
)
123 (dnd-handle-one-url window
'private
124 (concat "file:" file-name
)))
125 (car (cdr (cdr event
)))))
128 (defun w32-drag-n-drop-other-frame (event)
129 "Edit the files listed in the drag-n-drop EVENT, in other frames.
130 May create new frames, or reuse existing ones. The frame editing
131 the last file dropped is selected."
133 (mapcar 'find-file-other-frame
(car (cdr (cdr event
)))))
135 ;; Bind the drag-n-drop event.
136 (global-set-key [drag-n-drop
] 'w32-drag-n-drop
)
137 (global-set-key [C-drag-n-drop
] 'w32-drag-n-drop-other-frame
)
139 ;; Keyboard layout/language change events
140 ;; For now ignore language-change events; in the future
141 ;; we should switch the Emacs Input Method to match the
142 ;; new layout/language selected by the user.
143 (global-set-key [language-change
] 'ignore
)
145 (defvar x-invocation-args
)
147 (defvar x-command-line-resources nil
)
149 (defun x-handle-switch (switch)
150 "Handle SWITCH of the form \"-switch value\" or \"-switch\"."
151 (let ((aelt (assoc switch command-line-x-option-alist
)))
153 (push (cons (nth 3 aelt
) (or (nth 4 aelt
) (pop x-invocation-args
)))
154 default-frame-alist
))))
156 (defun x-handle-numeric-switch (switch)
157 "Handle SWITCH of the form \"-switch n\"."
158 (let ((aelt (assoc switch command-line-x-option-alist
)))
160 (push (cons (nth 3 aelt
) (string-to-number (pop x-invocation-args
)))
161 default-frame-alist
))))
163 ;; Handle options that apply to initial frame only
164 (defun x-handle-initial-switch (switch)
165 (let ((aelt (assoc switch command-line-x-option-alist
)))
167 (push (cons (nth 3 aelt
) (or (nth 4 aelt
) (pop x-invocation-args
)))
168 initial-frame-alist
))))
170 (defun x-handle-iconic (switch)
171 "Make \"-iconic\" SWITCH apply only to the initial frame."
172 (push '(visibility . icon
) initial-frame-alist
))
174 (defun x-handle-xrm-switch (switch)
175 "Handle the \"-xrm\" SWITCH."
176 (or (consp x-invocation-args
)
177 (error "%s: missing argument to `%s' option" (invocation-name) switch
))
178 (setq x-command-line-resources
179 (if (null x-command-line-resources
)
180 (car x-invocation-args
)
181 (concat x-command-line-resources
"\n" (car x-invocation-args
))))
182 (setq x-invocation-args
(cdr x-invocation-args
)))
184 (defun x-handle-geometry (switch)
185 "Handle the \"-geometry\" SWITCH."
186 (let* ((geo (x-parse-geometry (car x-invocation-args
)))
187 (left (assq 'left geo
))
188 (top (assq 'top geo
))
189 (height (assq 'height geo
))
190 (width (assq 'width geo
)))
191 (if (or height width
)
192 (setq default-frame-alist
193 (append default-frame-alist
195 (if height
(list height
))
196 (if width
(list width
)))
198 (append initial-frame-alist
200 (if height
(list height
))
201 (if width
(list width
)))))
203 (setq initial-frame-alist
204 (append initial-frame-alist
205 '((user-position . t
))
206 (if left
(list left
))
207 (if top
(list top
)))))
208 (setq x-invocation-args
(cdr x-invocation-args
))))
210 (defun x-handle-name-switch (switch)
211 "Handle the \"-name\" SWITCH."
212 ;; Handle the -name option. Set the variable x-resource-name
213 ;; to the option's operand; set the name of the initial frame, too.
214 (or (consp x-invocation-args
)
215 (error "%s: missing argument to `%s' option" (invocation-name) switch
))
216 (setq x-resource-name
(pop x-invocation-args
))
217 (push (cons 'name x-resource-name
) initial-frame-alist
))
219 (defvar x-display-name nil
220 "The display name specifying server and frame.")
222 (defun x-handle-display (switch)
223 "Handle the \"-display\" SWITCH."
224 (setq x-display-name
(pop x-invocation-args
)))
226 (defun x-handle-args (args)
227 "Process the X-related command line options in ARGS.
228 This is done before the user's startup file is loaded. They are copied to
229 `x-invocation args' from which the X-related things are extracted, first
230 the switch (e.g., \"-fg\") in the following code, and possible values
231 \(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
232 This returns ARGS with the arguments that have been processed removed."
233 ;; We use ARGS to accumulate the args that we don't handle here, to return.
234 (setq x-invocation-args args
236 (while (and x-invocation-args
237 (not (equal (car x-invocation-args
) "--")))
238 (let* ((this-switch (car x-invocation-args
))
239 (orig-this-switch this-switch
)
240 completion argval aelt handler
)
241 (setq x-invocation-args
(cdr x-invocation-args
))
242 ;; Check for long options with attached arguments
243 ;; and separate out the attached option argument into argval.
244 (if (string-match "^--[^=]*=" this-switch
)
245 (setq argval
(substring this-switch
(match-end 0))
246 this-switch
(substring this-switch
0 (1- (match-end 0)))))
247 ;; Complete names of long options.
248 (if (string-match "^--" this-switch
)
250 (setq completion
(try-completion this-switch command-line-x-option-alist
))
251 (if (eq completion t
)
252 ;; Exact match for long option.
254 (if (stringp completion
)
255 (let ((elt (assoc completion command-line-x-option-alist
)))
256 ;; Check for abbreviated long option.
258 (error "Option `%s' is ambiguous" this-switch
))
259 (setq this-switch completion
))))))
260 (setq aelt
(assoc this-switch command-line-x-option-alist
))
261 (if aelt
(setq handler
(nth 2 aelt
)))
264 (let ((x-invocation-args
265 (cons argval x-invocation-args
)))
266 (funcall handler this-switch
))
267 (funcall handler this-switch
))
268 (push orig-this-switch args
))))
269 (nconc (nreverse args
) x-invocation-args
))
275 (defvar x-colors
'("LightGreen"
874 "LightGoldenrodYellow"
875 "light goldenrod yellow"
892 "medium spring green"
1027 "The list of X colors from the `rgb.txt' file.
1028 XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
1030 (defun xw-defined-colors (&optional frame
)
1031 "Internal function called by `defined-colors', which see."
1032 (or frame
(setq frame
(selected-frame)))
1033 (let ((defined-colors nil
))
1034 (dolist (this-color (or (mapcar 'car w32-color-map
) x-colors
))
1035 (and (color-supported-p this-color frame t
)
1036 (push this-color defined-colors
)))
1042 ;;; make f10 activate the real menubar rather than the mini-buffer menu
1043 ;;; navigation feature.
1044 (global-set-key [f10] (lambda ()
1045 (interactive) (w32-send-sys-command ?\xf100)))
1047 (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
1050 (define-key function-key-map [S-tab] [backtab])
1053 ;;; Do the actual Windows setup here; the above code just defines
1054 ;;; functions and variables that we use now.
1056 (setq command-line-args (x-handle-args command-line-args))
1058 ;;; Make sure we have a valid resource name.
1059 (or (stringp x-resource-name)
1060 (setq x-resource-name
1061 ;; Change any . or * characters in x-resource-name to hyphens,
1062 ;; so as not to choke when we use it in X resource queries.
1063 (replace-regexp-in-string "[.*]" "-" (invocation-name))))
1065 ;; For the benefit of older Emacses (19.27 and earlier) that are sharing
1066 ;; the same lisp directory, don't pass the third argument unless we seem
1067 ;; to have the multi-display support.
1068 (if (fboundp 'x-close-connection)
1069 (x-open-connection ""
1070 x-command-line-resources
1071 ;; Exit Emacs with fatal error if this fails.
1073 (x-open-connection ""
1074 x-command-line-resources))
1076 (setq frame-creation-function 'x-create-frame-with-faces)
1078 (setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
1081 ;; W32 expects the menu bar cut and paste commands to use the clipboard.
1082 ;; This has ,? to match both on Sunos and on Solaris.
1083 (menu-bar-enable-clipboard)
1085 ;; W32 systems have different fonts than commonly found on X, so
1086 ;; we define our own standard fontset here.
1087 (defvar w32-standard-fontset-spec
1088 "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-fontset-standard"
1089 "String of fontset spec of the standard fontset.
1090 This defines a fontset consisting of the Courier New variations for
1091 European languages which are distributed with Windows as
1092 \"Multilanguage Support\".
1094 See the documentation of `create-fontset-from-fontset-spec' for the format.")
1096 ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
1097 (if (fboundp 'new-fontset)
1099 ;; Setup the default fontset.
1100 (setup-default-fontset)
1101 ;; Create the standard fontset.
1102 (create-fontset-from-fontset-spec w32-standard-fontset-spec t)
1103 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1,...).
1104 (create-fontset-from-x-resource)
1105 ;; Try to create a fontset from a font specification which comes
1106 ;; from initial-frame-alist, default-frame-alist, or X resource.
1107 ;; A font specification in command line argument (i.e. -fn XXXX)
1108 ;; should be already in default-frame-alist as a `font'
1109 ;; parameter. However, any font specifications in site-start
1110 ;; library, user's init file (.emacs), and default.el are not
1111 ;; yet handled here.
1113 (let ((font (or (cdr (assq 'font initial-frame-alist))
1114 (cdr (assq 'font default-frame-alist))
1115 (x-get-resource "font" "Font")))
1116 xlfd-fields resolved-name)
1118 (not (query-fontset font))
1119 (setq resolved-name (x-resolve-font-name font))
1120 (setq xlfd-fields (x-decompose-font-name font)))
1121 (if (string= "fontset"
1122 (aref xlfd-fields xlfd-regexp-registry-subnum))
1124 (x-complement-fontset-spec xlfd-fields nil))
1125 ;; Create a fontset from FONT. The fontset name is
1126 ;; generated from FONT.
1127 (create-fontset-from-ascii-font font
1128 resolved-name "startup"))))))
1130 ;; Apply a geometry resource to the initial frame. Put it at the end
1131 ;; of the alist, so that anything specified on the command line takes
1133 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
1137 (setq parsed (x-parse-geometry res-geometry))
1138 ;; If the resource specifies a position,
1139 ;; call the position and size "user-specified".
1140 (if (or (assq 'top parsed) (assq 'left parsed))
1141 (setq parsed (cons '(user-position . t)
1142 (cons '(user-size . t) parsed))))
1143 ;; All geometry parms apply to the initial frame.
1144 (setq initial-frame-alist (append initial-frame-alist parsed))
1145 ;; The size parms apply to all frames.
1146 (if (assq 'height parsed)
1147 (push (cons 'height (cdr (assq 'height parsed)))
1148 default-frame-alist))
1149 (if (assq 'width parsed)
1150 (push (cons 'width (cdr (assq 'width parsed)))
1151 default-frame-alist)))))
1153 ;; Check the reverseVideo resource.
1154 (let ((case-fold-search t))
1155 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
1156 (if (and rv (string-match "^\\(true\\|yes\\|on\\)$" rv))
1157 (push '(reverse . t) default-frame-alist))))
1159 (defun x-win-suspend-error ()
1160 "Report an error when a suspend is attempted."
1161 (error "Suspending an Emacs running under W32 makes no sense"))
1162 (add-hook 'suspend-hook 'x-win-suspend-error)
1164 ;;; Turn off window-splitting optimization; w32 is usually fast enough
1165 ;;; that this is only annoying.
1166 (setq split-window-keep-point t)
1168 ;; Don't show the frame name; that's redundant.
1169 (setq-default mode-line-frame-identification " ")
1171 ;;; Set to a system sound if you want a fancy bell.
1172 (set-message-beep 'ok)
1174 ;; Remap some functions to call w32 common dialogs
1176 (defun internal-face-interactive (what &optional bool)
1177 (let* ((fn (intern (concat "face-" what)))
1178 (prompt (concat "Set " what " of face "))
1179 (face (read-face-name prompt))
1180 (default (if (fboundp fn)
1181 (or (funcall fn face (selected-frame))
1182 (funcall fn 'default (selected-frame)))))
1183 (fn-win (intern (concat (symbol-name window-system) "-select-" what)))
1186 (cond ((fboundp fn-win)
1189 (completing-read (concat prompt " " (symbol-name face) " to: ")
1190 (mapcar (function (lambda (color)
1191 (cons color color)))
1193 nil nil nil nil default))
1195 (y-or-n-p (concat "Should face " (symbol-name face)
1198 (read-string (concat prompt " " (symbol-name face) " to: ")
1200 (list face (if (equal value "") nil value))))
1202 ;;; Enable Japanese fonts on Windows to be used by default.
1203 (set-fontset-font nil (make-char 'katakana-jisx0201) '("*" . "JISX0208-SJIS"))
1204 (set-fontset-font nil (make-char 'latin-jisx0201) '("*" . "JISX0208-SJIS"))
1205 (set-fontset-font nil (make-char 'japanese-jisx0208) '("*" . "JISX0208-SJIS"))
1206 (set-fontset-font nil (make-char 'japanese-jisx0208-1978) '("*" . "JISX0208-SJIS"))
1208 (defun mouse-set-font (&rest fonts)
1209 "Select an Emacs font from a list of known good fonts and fontsets.
1211 If `w32-use-w32-font-dialog' is non-nil (the default), use the Windows
1212 font dialog to display the list of possible fonts. Otherwise use a
1213 pop-up menu (like Emacs does on other platforms) initialized with
1214 the fonts in `w32-fixed-font-alist'.
1215 If `w32-list-proportional-fonts' is non-nil, add proportional fonts
1216 to the list in the font selection dialog (the fonts listed by the
1217 pop-up menu are unaffected by `w32-list-proportional-fonts')."
1219 (if w32-use-w32-font-dialog
1220 (let ((chosen-font (w32-select-font (selected-frame)
1221 w32-list-proportional-fonts)))
1222 (and chosen-font (list chosen-font)))
1225 ;; Append list of fontsets currently defined.
1226 ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
1227 (if (fboundp 'new-fontset)
1228 (append w32-fixed-font-alist (list (generate-fontset-menu)))))))
1234 (setq font (car fonts))
1235 (set-default-font font)
1237 (error (setq fonts (cdr fonts)))))
1239 (error "Font not found")))))
1241 ;;; Set default known names for image libraries
1242 (setq image-library-alist
1243 '((xpm "xpm4.dll" "libXpm-nox4.dll" "libxpm.dll")
1244 (png "libpng13d.dll" "libpng13.dll" "libpng12d.dll" "libpng12.dll" "libpng.dll")
1245 (jpeg "jpeg62.dll" "libjpeg.dll" "jpeg-62.dll" "jpeg.dll")
1246 (tiff "libtiff3.dll" "libtiff.dll")
1247 (gif "giflib4.dll" "libungif4.dll" "libungif.dll")))
1249 ;; arch-tag: 69fb1701-28c2-4890-b351-3d1fe4b4f166
1250 ;;; w32-win.el ends here