1 ;;; w32-win.el --- parse switches controlling interface with W32 window system -*- lexical-binding: t -*-
3 ;; Copyright (C) 1993-1994, 2001-2013 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 3 of the License, or
13 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
25 ;; w32-win.el: this file is loaded from ../lisp/startup.el when it recognizes
26 ;; that W32 windows are to be used. Command line switches are parsed and those
27 ;; pertaining to W32 are processed and removed from the command line. The
28 ;; W32 display is opened and hooks are set for popping up the initial window.
30 ;; startup.el will then examine startup files, and eventually call the hooks
31 ;; which create the first window (s).
36 ;; These are the standard X switches from the Xt Initialize.c file of
39 ;; Command line Resource Manager string
42 ;; +synchronous *synchronous
43 ;; -background *background
46 ;; -bordercolor *borderColor
47 ;; -borderwidth .borderWidth
53 ;; -foreground *foreground
54 ;; -geometry .geometry
59 ;; -reverse *reverseVideo
61 ;; -selectionTimeout .selectionTimeout
62 ;; -synchronous *synchronous
65 ;; An alist of X options and the function which handles them. See
68 ;; (if (not (eq window-system 'w32))
69 ;; (error "%s: Loading w32-win.el but not compiled for w32" (invocation-name)))
71 (eval-when-compile (require 'cl-lib
))
81 ;; Keep an obsolete alias for w32-focus-frame and w32-select-font in case
82 ;; they are used by code outside Emacs.
83 (define-obsolete-function-alias 'w32-focus-frame
'x-focus-frame
"23.1")
84 (declare-function x-select-font
"w32font.c"
85 (&optional frame exclude-proportional
))
86 (define-obsolete-function-alias 'w32-select-font
'x-select-font
"23.1")
88 (defvar w32-color-map
) ;; defined in w32fns.c
89 (make-obsolete 'w32-default-color-map nil
"24.1")
91 (declare-function w32-send-sys-command
"w32fns.c")
92 (declare-function set-message-beep
"w32fns.c")
94 (declare-function cygwin-convert-file-name-from-windows
"cygw32.c"
95 (path &optional absolute_p
))
97 ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
98 (if (fboundp 'new-fontset
)
101 ;; The following definition is used for debugging scroll bar events.
102 ;(defun w32-handle-scroll-bar-event (event) (interactive "e") (princ event))
104 ;; (defun w32-drag-n-drop-debug (event)
105 ;; "Print the drag-n-drop EVENT in a readable form."
109 (defun w32-handle-dropped-file (window file-name
)
110 (let ((f (if (eq system-type
'cygwin
)
111 (cygwin-convert-file-name-from-windows file-name t
)
112 (subst-char-in-string ?
\\ ?
/ file-name
)))
113 (coding (or file-name-coding-system
114 default-file-name-coding-system
)))
117 (mapconcat 'url-hexify-string
118 (split-string (encode-coding-string f coding
)
121 (dnd-handle-one-url window
'private
123 (if (eq system-type
'cygwin
)
128 (defun w32-drag-n-drop (event &optional new-frame
)
129 "Edit the files listed in the drag-n-drop EVENT.
130 Switch to a buffer editing the last file dropped."
133 ;; Make sure the drop target has positive co-ords
134 ;; before setting the selected frame - otherwise it
135 ;; won't work. <skx@tardis.ed.ac.uk>
136 (let* ((window (posn-window (event-start event
)))
137 (coords (posn-x-y (event-start event
)))
140 (if (and (> x
0) (> y
0))
141 (set-frame-selected-window nil window
))
144 (select-frame (make-frame)))
146 (setq window
(selected-window))
148 (mapc (apply-partially #'w32-handle-dropped-file window
)
149 (car (cdr (cdr event
)))))))
151 (defun w32-drag-n-drop-other-frame (event)
152 "Edit the files listed in the drag-n-drop EVENT, in other frames.
153 May create new frames, or reuse existing ones. The frame editing
154 the last file dropped is selected."
156 (w32-drag-n-drop event t
))
158 ;; Bind the drag-n-drop event.
159 (global-set-key [drag-n-drop
] 'w32-drag-n-drop
)
160 (global-set-key [C-drag-n-drop
] 'w32-drag-n-drop-other-frame
)
162 ;; Keyboard layout/language change events
163 ;; For now ignore language-change events; in the future
164 ;; we should switch the Emacs Input Method to match the
165 ;; new layout/language selected by the user.
166 (global-set-key [language-change
] 'ignore
)
168 (defvar x-resource-name
)
173 ;;; make f10 activate the real menubar rather than the mini-buffer menu
174 ;;; navigation feature.
175 (defun w32-menu-bar-open (&optional frame
)
176 "Start key navigation of the menu bar in FRAME.
178 This initially activates the first menu-bar item, and you can then navigate
179 with the arrow keys, select a menu entry with the Return key or cancel with
180 the Escape key. If FRAME has no menu bar, this function does nothing.
182 If FRAME is nil or not given, use the selected frame.
183 If FRAME does not have the menu bar enabled, display a text menu using
187 (w32-send-sys-command ?
\xf100 frame
)
188 (with-selected-frame (or frame
(selected-frame))
192 ;; W32 systems have different fonts than commonly found on X, so
193 ;; we define our own standard fontset here.
194 (defvar w32-standard-fontset-spec
195 "-*-Courier New-normal-r-*-*-13-*-*-*-c-*-fontset-standard"
196 "String of fontset spec of the standard fontset.
197 This defines a fontset consisting of the Courier New variations for
198 European languages which are distributed with Windows as
199 \"Multilanguage Support\".
201 See the documentation of `create-fontset-from-fontset-spec' for the format.")
203 (defun x-win-suspend-error ()
204 "Report an error when a suspend is attempted."
205 (error "Suspending an Emacs running under W32 makes no sense"))
207 (defvar dynamic-library-alist
)
208 (defvar libpng-version
) ; image.c #ifdef HAVE_NTGUI
210 ;;; Set default known names for external libraries
211 (setq dynamic-library-alist
213 '(xpm "libxpm.dll" "xpm4.dll" "libXpm-nox4.dll")
214 ;; Versions of libpng 1.4.x and later are incompatible with
215 ;; earlier versions. Set up the list of libraries according to
216 ;; the version we were compiled against. (If we were compiled
217 ;; without PNG support, libpng-version's value is -1.)
218 (if (>= libpng-version
10400)
219 ;; libpng14-14.dll is libpng 1.4.3 from GTK+
220 '(png "libpng14-14.dll" "libpng14.dll")
221 '(png "libpng12d.dll" "libpng12.dll" "libpng3.dll" "libpng.dll"
222 ;; these are libpng 1.2.8 from GTK+
223 "libpng13d.dll" "libpng13.dll"))
224 '(jpeg "jpeg62.dll" "libjpeg.dll" "jpeg-62.dll" "jpeg.dll")
225 '(tiff "libtiff3.dll" "libtiff.dll")
226 ;; Versions of giflib 5.0.0 and later changed signatures of
227 ;; several functions used by Emacs, which makes those versions
228 ;; incompatible with previous ones. We select the correct
229 ;; libraries according to the version of giflib we were
230 ;; compiled against. (If we were compiled without GIF support,
231 ;; libgif-version's value is -1.)
232 (if (>= libgif-version
50000)
233 ;; Yes, giflib 5.x uses 6 as the major version of the API,
234 ;; thus "libgif-6.dll" below (giflib 4.x used 5 as the
235 ;; major API version).
236 ;; giflib5.dll is from the lua-files project.
237 '(gif "libgif-6.dll" "giflib5.dll")
238 '(gif "libgif-5.dll" "giflib4.dll" "libungif4.dll" "libungif.dll"))
239 '(svg "librsvg-2-2.dll")
240 '(gdk-pixbuf "libgdk_pixbuf-2.0-0.dll")
241 '(glib "libglib-2.0-0.dll")
242 '(gobject "libgobject-2.0-0.dll")
243 '(gnutls "libgnutls-28.dll" "libgnutls-26.dll")
244 '(libxml2 "libxml2-2.dll" "libxml2.dll")
245 '(zlib "zlib1.dll" "libz-1.dll")))
247 ;;; multi-tty support
248 (defvar w32-initialized nil
249 "Non-nil if the w32 window system has been initialized.")
251 (declare-function x-open-connection
"w32fns.c"
252 (display &optional xrm-string must-succeed
))
253 (declare-function create-default-fontset
"fontset" ())
254 (declare-function create-fontset-from-fontset-spec
"fontset"
255 (fontset-spec &optional style-variant noerror
))
256 (declare-function create-fontset-from-x-resource
"fontset" ())
257 (declare-function x-get-resource
"frame.c"
258 (attribute class
&optional component subclass
))
259 (declare-function x-handle-args
"common-win" (args))
260 (declare-function x-parse-geometry
"frame.c" (string))
261 (defvar x-command-line-resources
)
263 (defun w32-initialize-window-system (&optional _display
)
264 "Initialize Emacs for W32 GUI frames."
265 (cl-assert (not w32-initialized
))
267 ;; Do the actual Windows setup here; the above code just defines
268 ;; functions and variables that we use now.
270 (setq command-line-args
(x-handle-args command-line-args
))
272 ;; Make sure we have a valid resource name.
273 (or (stringp x-resource-name
)
274 (setq x-resource-name
275 ;; Change any . or * characters in x-resource-name to hyphens,
276 ;; so as not to choke when we use it in X resource queries.
277 (replace-regexp-in-string "[.*]" "-" (invocation-name))))
279 (x-open-connection "w32" x-command-line-resources
280 ;; Exit with a fatal error if this fails and we
281 ;; are the initial display
282 (eq initial-window-system
'w32
))
284 ;; Create the default fontset.
285 (create-default-fontset)
286 ;; Create the standard fontset.
288 (create-fontset-from-fontset-spec w32-standard-fontset-spec t
)
289 (error (display-warning
291 (format "Creation of the standard fontset failed: %s" err
)
293 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1,...).
294 (create-fontset-from-x-resource)
296 ;; Apply a geometry resource to the initial frame. Put it at the end
297 ;; of the alist, so that anything specified on the command line takes
299 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
303 (setq parsed
(x-parse-geometry res-geometry
))
304 ;; If the resource specifies a position,
305 ;; call the position and size "user-specified".
306 (if (or (assq 'top parsed
) (assq 'left parsed
))
307 (setq parsed
(cons '(user-position . t
)
308 (cons '(user-size . t
) parsed
))))
309 ;; All geometry parms apply to the initial frame.
310 (setq initial-frame-alist
(append initial-frame-alist parsed
))
311 ;; The size parms apply to all frames.
312 (if (and (assq 'height parsed
)
313 (not (assq 'height default-frame-alist
)))
314 (setq default-frame-alist
315 (cons (cons 'height
(cdr (assq 'height parsed
)))
316 default-frame-alist
))
317 (if (and (assq 'width parsed
)
318 (not (assq 'width default-frame-alist
)))
319 (setq default-frame-alist
320 (cons (cons 'width
(cdr (assq 'width parsed
)))
321 default-frame-alist
)))))))
323 ;; Check the reverseVideo resource.
324 (let ((case-fold-search t
))
325 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
326 (if (and rv
(string-match "^\\(true\\|yes\\|on\\)$" rv
))
327 (setq default-frame-alist
328 (cons '(reverse . t
) default-frame-alist
)))))
330 ;; Don't let Emacs suspend under Windows.
331 (add-hook 'suspend-hook
'x-win-suspend-error
)
333 ;; Turn off window-splitting optimization; w32 is usually fast enough
334 ;; that this is only annoying.
335 (setq split-window-keep-point t
)
337 ;; W32 expects the menu bar cut and paste commands to use the clipboard.
338 (menu-bar-enable-clipboard)
340 ;; Don't show the frame name; that's redundant.
341 (setq-default mode-line-frame-identification
" ")
343 ;; Set to a system sound if you want a fancy bell.
344 (set-message-beep 'ok
)
345 (x-apply-session-resources)
346 (setq w32-initialized t
))
348 (add-to-list 'display-format-alist
'("\\`w32\\'" . w32
))
349 (add-to-list 'handle-args-function-alist
'(w32 . x-handle-args
))
350 (add-to-list 'frame-creation-function-alist
'(w32 . x-create-frame-with-faces
))
351 (add-to-list 'window-system-initialization-alist
'(w32 . w32-initialize-window-system
))
355 ;;; w32-win.el ends here