1 ;;; w32-win.el --- parse switches controlling interface with W32 window system
3 ;; Copyright (C) 1993, 1994, 2003, 2005 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., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, 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 (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 (push (cons (nth 3 aelt
) (or (nth 4 aelt
) (pop x-invocation-args
)))
143 default-frame-alist
))))
145 (defun x-handle-numeric-switch (switch)
146 "Handle SWITCH of the form \"-switch n\"."
147 (let ((aelt (assoc switch command-line-x-option-alist
)))
149 (push (cons (nth 3 aelt
) (string-to-number (pop x-invocation-args
)))
150 default-frame-alist
))))
152 ;; Handle options that apply to initial frame only
153 (defun x-handle-initial-switch (switch)
154 (let ((aelt (assoc switch command-line-x-option-alist
)))
156 (push (cons (nth 3 aelt
) (or (nth 4 aelt
) (pop x-invocation-args
)))
157 initial-frame-alist
))))
159 (defun x-handle-iconic (switch)
160 "Make \"-iconic\" SWITCH apply only to the initial frame."
161 (push '(visibility . icon
) initial-frame-alist
))
163 (defun x-handle-xrm-switch (switch)
164 "Handle the \"-xrm\" SWITCH."
165 (or (consp x-invocation-args
)
166 (error "%s: missing argument to `%s' option" (invocation-name) switch
))
167 (setq x-command-line-resources
168 (if (null x-command-line-resources
)
169 (car x-invocation-args
)
170 (concat x-command-line-resources
"\n" (car x-invocation-args
))))
171 (setq x-invocation-args
(cdr x-invocation-args
)))
173 (defun x-handle-geometry (switch)
174 "Handle the \"-geometry\" SWITCH."
175 (let* ((geo (x-parse-geometry (car x-invocation-args
)))
176 (left (assq 'left geo
))
177 (top (assq 'top geo
))
178 (height (assq 'height geo
))
179 (width (assq 'width geo
)))
180 (if (or height width
)
181 (setq default-frame-alist
182 (append default-frame-alist
184 (if height
(list height
))
185 (if width
(list width
)))
187 (append initial-frame-alist
189 (if height
(list height
))
190 (if width
(list width
)))))
192 (setq initial-frame-alist
193 (append initial-frame-alist
194 '((user-position . t
))
195 (if left
(list left
))
196 (if top
(list top
)))))
197 (setq x-invocation-args
(cdr x-invocation-args
))))
199 (defun x-handle-name-switch (switch)
200 "Handle a \"-name\" SWITCH."
201 ;; Handle the -name option. Set the variable x-resource-name
202 ;; to the option's operand; set the name of the initial frame, too.
203 (or (consp x-invocation-args
)
204 (error "%s: missing argument to `%s' option" (invocation-name) switch
))
205 (setq x-resource-name
(pop x-invocation-args
))
206 (push (cons 'name x-resource-name
) initial-frame-alist
))
208 (defvar x-display-name nil
209 "The display name specifying server and frame.")
211 (defun x-handle-display (switch)
212 "Handle the \"-display\" SWITCH."
213 (setq x-display-name
(pop x-invocation-args
)))
215 (defun x-handle-args (args)
216 "Process the X-related command line options in ARGS.
217 This is done before the user's startup file is loaded. They are copied to
218 `x-invocation args' from which the X-related things are extracted, first
219 the switch (e.g., \"-fg\") in the following code, and possible values
220 \(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
221 This returns ARGS with the arguments that have been processed removed."
222 ;; We use ARGS to accumulate the args that we don't handle here, to return.
223 (setq x-invocation-args args
225 (while (and x-invocation-args
226 (not (equal (car x-invocation-args
) "--")))
227 (let* ((this-switch (car x-invocation-args
))
228 (orig-this-switch this-switch
)
229 completion argval aelt handler
)
230 (setq x-invocation-args
(cdr x-invocation-args
))
231 ;; Check for long options with attached arguments
232 ;; and separate out the attached option argument into argval.
233 (if (string-match "^--[^=]*=" this-switch
)
234 (setq argval
(substring this-switch
(match-end 0))
235 this-switch
(substring this-switch
0 (1- (match-end 0)))))
236 ;; Complete names of long options.
237 (if (string-match "^--" this-switch
)
239 (setq completion
(try-completion this-switch command-line-x-option-alist
))
240 (if (eq completion t
)
241 ;; Exact match for long option.
243 (if (stringp completion
)
244 (let ((elt (assoc completion command-line-x-option-alist
)))
245 ;; Check for abbreviated long option.
247 (error "Option `%s' is ambiguous" this-switch
))
248 (setq this-switch completion
))))))
249 (setq aelt
(assoc this-switch command-line-x-option-alist
))
250 (if aelt
(setq handler
(nth 2 aelt
)))
253 (let ((x-invocation-args
254 (cons argval x-invocation-args
)))
255 (funcall handler this-switch
))
256 (funcall handler this-switch
))
257 (push orig-this-switch args
))))
258 (nconc (nreverse args
) x-invocation-args
))
264 (defvar x-colors
'("LightGreen"
863 "LightGoldenrodYellow"
864 "light goldenrod yellow"
881 "medium spring green"
1016 "The list of X colors from the `rgb.txt' file.
1017 XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
1019 (defun xw-defined-colors (&optional frame
)
1020 "Internal function called by `defined-colors', which see."
1021 (or frame
(setq frame
(selected-frame)))
1022 (let ((defined-colors nil
))
1023 (dolist (this-color (or (mapcar 'car w32-color-map
) x-colors
))
1024 (and (color-supported-p this-color frame t
)
1025 (push this-color defined-colors
)))
1031 ;;; make f10 activate the real menubar rather than the mini-buffer menu
1032 ;;; navigation feature.
1033 (global-set-key [f10] (lambda ()
1034 (interactive) (w32-send-sys-command ?\xf100)))
1036 (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
1040 ;;; Do the actual Windows setup here; the above code just defines
1041 ;;; functions and variables that we use now.
1043 (setq command-line-args (x-handle-args command-line-args))
1045 ;;; Make sure we have a valid resource name.
1046 (or (stringp x-resource-name)
1047 (setq x-resource-name
1048 ;; Change any . or * characters in x-resource-name to hyphens,
1049 ;; so as not to choke when we use it in X resource queries.
1050 (replace-regexp-in-string "[.*]" "-" (invocation-name))))
1052 ;; For the benefit of older Emacses (19.27 and earlier) that are sharing
1053 ;; the same lisp directory, don't pass the third argument unless we seem
1054 ;; to have the multi-display support.
1055 (if (fboundp 'x-close-connection)
1056 (x-open-connection ""
1057 x-command-line-resources
1058 ;; Exit Emacs with fatal error if this fails.
1060 (x-open-connection ""
1061 x-command-line-resources))
1063 (setq frame-creation-function 'x-create-frame-with-faces)
1065 (setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
1068 ;; W32 expects the menu bar cut and paste commands to use the clipboard.
1069 ;; This has ,? to match both on Sunos and on Solaris.
1070 (menu-bar-enable-clipboard)
1072 ;; W32 systems have different fonts than commonly found on X, so
1073 ;; we define our own standard fontset here.
1074 (defvar w32-standard-fontset-spec
1075 "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-fontset-standard"
1076 "String of fontset spec of the standard fontset.
1077 This defines a fontset consisting of the Courier New variations for
1078 European languages which are distributed with Windows as
1079 \"Multilanguage Support\".
1081 See the documentation of `create-fontset-from-fontset-spec for the format.")
1083 ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
1084 (if (fboundp 'new-fontset)
1086 ;; Setup the default fontset.
1087 (setup-default-fontset)
1088 ;; Create the standard fontset.
1089 (create-fontset-from-fontset-spec w32-standard-fontset-spec t)
1090 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1,...).
1091 (create-fontset-from-x-resource)
1092 ;; Try to create a fontset from a font specification which comes
1093 ;; from initial-frame-alist, default-frame-alist, or X resource.
1094 ;; A font specification in command line argument (i.e. -fn XXXX)
1095 ;; should be already in default-frame-alist as a `font'
1096 ;; parameter. However, any font specifications in site-start
1097 ;; library, user's init file (.emacs), and default.el are not
1098 ;; yet handled here.
1100 (let ((font (or (cdr (assq 'font initial-frame-alist))
1101 (cdr (assq 'font default-frame-alist))
1102 (x-get-resource "font" "Font")))
1103 xlfd-fields resolved-name)
1105 (not (query-fontset font))
1106 (setq resolved-name (x-resolve-font-name font))
1107 (setq xlfd-fields (x-decompose-font-name font)))
1108 (if (string= "fontset"
1109 (aref xlfd-fields xlfd-regexp-registry-subnum))
1111 (x-complement-fontset-spec xlfd-fields nil))
1112 ;; Create a fontset from FONT. The fontset name is
1113 ;; generated from FONT.
1114 (create-fontset-from-ascii-font font
1115 resolved-name "startup"))))))
1117 ;; Apply a geometry resource to the initial frame. Put it at the end
1118 ;; of the alist, so that anything specified on the command line takes
1120 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
1124 (setq parsed (x-parse-geometry res-geometry))
1125 ;; If the resource specifies a position,
1126 ;; call the position and size "user-specified".
1127 (if (or (assq 'top parsed) (assq 'left parsed))
1128 (setq parsed (cons '(user-position . t)
1129 (cons '(user-size . t) parsed))))
1130 ;; All geometry parms apply to the initial frame.
1131 (setq initial-frame-alist (append initial-frame-alist parsed))
1132 ;; The size parms apply to all frames.
1133 (if (assq 'height parsed)
1134 (push (cons 'height (cdr (assq 'height parsed)))
1135 default-frame-alist))
1136 (if (assq 'width parsed)
1137 (push (cons 'width (cdr (assq 'width parsed)))
1138 default-frame-alist)))))
1140 ;; Check the reverseVideo resource.
1141 (let ((case-fold-search t))
1142 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
1143 (if (and rv (string-match "^\\(true\\|yes\\|on\\)$" rv))
1144 (push '(reverse . t) default-frame-alist))))
1146 (defun x-win-suspend-error ()
1147 "Report an error when a suspend is attempted."
1148 (error "Suspending an Emacs running under W32 makes no sense"))
1149 (add-hook 'suspend-hook 'x-win-suspend-error)
1151 ;;; Turn off window-splitting optimization; w32 is usually fast enough
1152 ;;; that this is only annoying.
1153 (setq split-window-keep-point t)
1155 ;; Don't show the frame name; that's redundant.
1156 (setq-default mode-line-frame-identification " ")
1158 ;;; Set to a system sound if you want a fancy bell.
1159 (set-message-beep 'ok)
1161 ;; Remap some functions to call w32 common dialogs
1163 (defun internal-face-interactive (what &optional bool)
1164 (let* ((fn (intern (concat "face-" what)))
1165 (prompt (concat "Set " what " of face "))
1166 (face (read-face-name prompt))
1167 (default (if (fboundp fn)
1168 (or (funcall fn face (selected-frame))
1169 (funcall fn 'default (selected-frame)))))
1170 (fn-win (intern (concat (symbol-name window-system) "-select-" what)))
1173 (cond ((fboundp fn-win)
1176 (completing-read (concat prompt " " (symbol-name face) " to: ")
1177 (mapcar (function (lambda (color)
1178 (cons color color)))
1180 nil nil nil nil default))
1182 (y-or-n-p (concat "Should face " (symbol-name face)
1185 (read-string (concat prompt " " (symbol-name face) " to: ")
1187 (list face (if (equal value "") nil value))))
1189 ;;; Enable Japanese fonts on Windows to be used by default.
1190 (set-fontset-font nil (make-char 'katakana-jisx0201) '("*" . "JISX0208-SJIS"))
1191 (set-fontset-font nil (make-char 'latin-jisx0201) '("*" . "JISX0208-SJIS"))
1192 (set-fontset-font nil (make-char 'japanese-jisx0208) '("*" . "JISX0208-SJIS"))
1193 (set-fontset-font nil (make-char 'japanese-jisx0208-1978) '("*" . "JISX0208-SJIS"))
1195 (defun mouse-set-font (&rest fonts)
1197 If `w32-use-w32-font-dialog' is non-nil (the default), use the Windows
1198 font dialog to get the matching FONTS. Otherwise use a pop-up menu
1199 \(like Emacs on other platforms) initialized with the fonts in
1200 `w32-fixed-font-alist'."
1202 (if w32-use-w32-font-dialog
1203 (let ((chosen-font (w32-select-font (selected-frame)
1204 w32-list-proportional-fonts)))
1205 (and chosen-font (list chosen-font)))
1208 ;; Append list of fontsets currently defined.
1209 ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
1210 (if (fboundp 'new-fontset)
1211 (append w32-fixed-font-alist (list (generate-fontset-menu)))))))
1217 (setq font (car fonts))
1218 (set-default-font font)
1220 (error (setq fonts (cdr fonts)))))
1222 (error "Font not found")))))
1224 ;;; Set default known names for image libraries
1225 (setq image-library-alist
1226 '((xpm "xpm4.dll" "libXpm-nox4.dll" "libxpm.dll")
1227 (png "libpng13d.dll" "libpng13.dll" "libpng12d.dll" "libpng12.dll" "libpng.dll")
1228 (jpeg "jpeg62.dll" "libjpeg.dll" "jpeg-62.dll" "jpeg.dll")
1229 (tiff "libtiff3.dll" "libtiff.dll")
1230 (gif "libungif.dll")))
1232 ;; arch-tag: 69fb1701-28c2-4890-b351-3d1fe4b4f166
1233 ;;; w32-win.el ends here