frame.el 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212
  1. ;;; frame.el --- multi-frame management independent of window systems -*- lexical-binding:t -*-
  2. ;; Copyright (C) 1993-1994, 1996-1997, 2000-2015 Free Software
  3. ;; Foundation, Inc.
  4. ;; Maintainer: emacs-devel@gnu.org
  5. ;; Keywords: internal
  6. ;; Package: emacs
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;;; Code:
  20. (eval-when-compile (require 'cl-lib))
  21. (cl-defgeneric frame-creation-function (params)
  22. "Method for window-system dependent functions to create a new frame.
  23. The window system startup file should add its frame creation
  24. function to this method, which should take an alist of parameters
  25. as its argument.")
  26. (cl-defmethod frame-creation-function (params
  27. &context (window-system (eql nil)))
  28. ;; It's tempting to get rid of tty-create-frame-with-faces and turn it into
  29. ;; this method (i.e. move this method to faces.el), but faces.el is loaded
  30. ;; much earlier from loadup.el (before cl-generic and even before
  31. ;; cl-preloaded), so we'd first have to reorder that part.
  32. (tty-create-frame-with-faces params))
  33. (defvar window-system-default-frame-alist nil
  34. "Window-system dependent default frame parameters.
  35. The value should be an alist of elements (WINDOW-SYSTEM . ALIST),
  36. where WINDOW-SYSTEM is a window system symbol (as returned by `framep')
  37. and ALIST is a frame parameter alist like `default-frame-alist'.
  38. Then, for frames on WINDOW-SYSTEM, any parameters specified in
  39. ALIST supersede the corresponding parameters specified in
  40. `default-frame-alist'.")
  41. (defvar display-format-alist nil
  42. "Alist of patterns to decode display names.
  43. The car of each entry is a regular expression matching a display
  44. name string. The cdr is a symbol giving the window-system that
  45. handles the corresponding kind of display.")
  46. ;; The initial value given here used to ask for a minibuffer.
  47. ;; But that's not necessary, because the default is to have one.
  48. ;; By not specifying it here, we let an X resource specify it.
  49. (defcustom initial-frame-alist nil
  50. "Alist of parameters for the initial X window frame.
  51. You can set this in your init file; for example,
  52. (setq initial-frame-alist
  53. '((top . 1) (left . 1) (width . 80) (height . 55)))
  54. Parameters specified here supersede the values given in
  55. `default-frame-alist'.
  56. If the value calls for a frame without a minibuffer, and you have
  57. not created a minibuffer frame on your own, a minibuffer frame is
  58. created according to `minibuffer-frame-alist'.
  59. You can specify geometry-related options for just the initial
  60. frame by setting this variable in your init file; however, they
  61. won't take effect until Emacs reads your init file, which happens
  62. after creating the initial frame. If you want the initial frame
  63. to have the proper geometry as soon as it appears, you need to
  64. use this three-step process:
  65. * Specify X resources to give the geometry you want.
  66. * Set `default-frame-alist' to override these options so that they
  67. don't affect subsequent frames.
  68. * Set `initial-frame-alist' in a way that matches the X resources,
  69. to override what you put in `default-frame-alist'."
  70. :type '(repeat (cons :format "%v"
  71. (symbol :tag "Parameter")
  72. (sexp :tag "Value")))
  73. :group 'frames)
  74. (defcustom minibuffer-frame-alist '((width . 80) (height . 2))
  75. "Alist of parameters for the initial minibuffer frame.
  76. This is the minibuffer frame created if `initial-frame-alist'
  77. calls for a frame without a minibuffer. The parameters specified
  78. here supersede those given in `default-frame-alist', for the
  79. initial minibuffer frame.
  80. You can set this in your init file; for example,
  81. (setq minibuffer-frame-alist
  82. '((top . 1) (left . 1) (width . 80) (height . 2)))
  83. It is not necessary to include (minibuffer . only); that is
  84. appended when the minibuffer frame is created."
  85. :type '(repeat (cons :format "%v"
  86. (symbol :tag "Parameter")
  87. (sexp :tag "Value")))
  88. :group 'frames)
  89. (defun handle-delete-frame (event)
  90. "Handle delete-frame events from the X server."
  91. (interactive "e")
  92. (let ((frame (posn-window (event-start event)))
  93. (i 0)
  94. (tail (frame-list)))
  95. (while tail
  96. (and (frame-visible-p (car tail))
  97. (not (eq (car tail) frame))
  98. (setq i (1+ i)))
  99. (setq tail (cdr tail)))
  100. (if (> i 0)
  101. (delete-frame frame t)
  102. ;; Gildea@x.org says it is ok to ask questions before terminating.
  103. (save-buffers-kill-emacs))))
  104. (defun handle-focus-in (_event)
  105. "Handle a focus-in event.
  106. Focus-in events are usually bound to this function.
  107. Focus-in events occur when a frame has focus, but a switch-frame event
  108. is not generated.
  109. This function runs the hook `focus-in-hook'."
  110. (interactive "e")
  111. (run-hooks 'focus-in-hook))
  112. (defun handle-focus-out (_event)
  113. "Handle a focus-out event.
  114. Focus-out events are usually bound to this function.
  115. Focus-out events occur when no frame has focus.
  116. This function runs the hook `focus-out-hook'."
  117. (interactive "e")
  118. (run-hooks 'focus-out-hook))
  119. ;;;; Arrangement of frames at startup
  120. ;; 1) Load the window system startup file from the lisp library and read the
  121. ;; high-priority arguments (-q and the like). The window system startup
  122. ;; file should create any frames specified in the window system defaults.
  123. ;;
  124. ;; 2) If no frames have been opened, we open an initial text frame.
  125. ;;
  126. ;; 3) Once the init file is done, we apply any newly set parameters
  127. ;; in initial-frame-alist to the frame.
  128. ;; If we create the initial frame, this is it.
  129. (defvar frame-initial-frame nil)
  130. ;; Record the parameters used in frame-initialize to make the initial frame.
  131. (defvar frame-initial-frame-alist)
  132. (defvar frame-initial-geometry-arguments nil)
  133. ;; startup.el calls this function before loading the user's init
  134. ;; file - if there is no frame with a minibuffer open now, create
  135. ;; one to display messages while loading the init file.
  136. (defun frame-initialize ()
  137. "Create an initial frame if necessary."
  138. ;; Are we actually running under a window system at all?
  139. (if (and initial-window-system
  140. (not noninteractive)
  141. (not (eq initial-window-system 'pc)))
  142. (progn
  143. ;; If there is no frame with a minibuffer besides the terminal
  144. ;; frame, then we need to create the opening frame. Make sure
  145. ;; it has a minibuffer, but let initial-frame-alist omit the
  146. ;; minibuffer spec.
  147. (or (delq terminal-frame (minibuffer-frame-list))
  148. (progn
  149. (setq frame-initial-frame-alist
  150. (append initial-frame-alist default-frame-alist nil))
  151. (setq frame-initial-frame-alist
  152. (cons (cons 'window-system initial-window-system)
  153. frame-initial-frame-alist))
  154. (setq default-minibuffer-frame
  155. (setq frame-initial-frame
  156. (make-frame frame-initial-frame-alist)))
  157. ;; Delete any specifications for window geometry parameters
  158. ;; so that we won't reapply them in frame-notice-user-settings.
  159. ;; It would be wrong to reapply them then,
  160. ;; because that would override explicit user resizing.
  161. (setq initial-frame-alist
  162. (frame-remove-geometry-params initial-frame-alist))))
  163. ;; Copy the environment of the Emacs process into the new frame.
  164. (set-frame-parameter frame-initial-frame 'environment
  165. (frame-parameter terminal-frame 'environment))
  166. ;; At this point, we know that we have a frame open, so we
  167. ;; can delete the terminal frame.
  168. (delete-frame terminal-frame)
  169. (setq terminal-frame nil))))
  170. (defvar frame-notice-user-settings t
  171. "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
  172. (declare-function tool-bar-mode "tool-bar" (&optional arg))
  173. (declare-function tool-bar-height "xdisp.c" (&optional frame pixelwise))
  174. (defalias 'tool-bar-lines-needed 'tool-bar-height)
  175. ;; startup.el calls this function after loading the user's init
  176. ;; file. Now default-frame-alist and initial-frame-alist contain
  177. ;; information to which we must react; do what needs to be done.
  178. (defun frame-notice-user-settings ()
  179. "Act on user's init file settings of frame parameters.
  180. React to settings of `initial-frame-alist',
  181. `window-system-default-frame-alist' and `default-frame-alist'
  182. there (in decreasing order of priority)."
  183. ;; Creating and deleting frames may shift the selected frame around,
  184. ;; and thus the current buffer. Protect against that. We don't
  185. ;; want to use save-excursion here, because that may also try to set
  186. ;; the buffer of the selected window, which fails when the selected
  187. ;; window is the minibuffer.
  188. (let ((old-buffer (current-buffer))
  189. (window-system-frame-alist
  190. (cdr (assq initial-window-system
  191. window-system-default-frame-alist))))
  192. (when (and frame-notice-user-settings
  193. (null frame-initial-frame))
  194. ;; This case happens when we don't have a window system, and
  195. ;; also for MS-DOS frames.
  196. (let ((parms (frame-parameters)))
  197. ;; Don't change the frame names.
  198. (setq parms (delq (assq 'name parms) parms))
  199. ;; Can't modify the minibuffer parameter, so don't try.
  200. (setq parms (delq (assq 'minibuffer parms) parms))
  201. (modify-frame-parameters
  202. nil
  203. (if initial-window-system
  204. parms
  205. ;; initial-frame-alist and default-frame-alist were already
  206. ;; applied in pc-win.el.
  207. (append initial-frame-alist window-system-frame-alist
  208. default-frame-alist parms nil)))
  209. (if (null initial-window-system) ;; MS-DOS does this differently in pc-win.el
  210. (let ((newparms (frame-parameters))
  211. (frame (selected-frame)))
  212. (tty-handle-reverse-video frame newparms)
  213. ;; tty-handle-reverse-video might change the frame's
  214. ;; color parameters, and we need to use the updated
  215. ;; value below.
  216. (setq newparms (frame-parameters))
  217. ;; If we changed the background color, we need to update
  218. ;; the background-mode parameter, and maybe some faces,
  219. ;; too.
  220. (when (assq 'background-color newparms)
  221. (unless (or (assq 'background-mode initial-frame-alist)
  222. (assq 'background-mode default-frame-alist))
  223. (frame-set-background-mode frame))
  224. (face-set-after-frame-default frame newparms))))))
  225. ;; If the initial frame is still around, apply initial-frame-alist
  226. ;; and default-frame-alist to it.
  227. (when (frame-live-p frame-initial-frame)
  228. ;; When tool-bar has been switched off, correct the frame size
  229. ;; by the lines added in x-create-frame for the tool-bar and
  230. ;; switch `tool-bar-mode' off.
  231. (when (display-graphic-p)
  232. (let* ((init-lines
  233. (assq 'tool-bar-lines initial-frame-alist))
  234. (other-lines
  235. (or (assq 'tool-bar-lines window-system-frame-alist)
  236. (assq 'tool-bar-lines default-frame-alist)))
  237. (lines (or init-lines other-lines))
  238. (height (tool-bar-height frame-initial-frame t)))
  239. ;; Adjust frame top if either zero (nil) tool bar lines have
  240. ;; been requested in the most relevant of the frame's alists
  241. ;; or tool bar mode has been explicitly turned off in the
  242. ;; user's init file.
  243. (when (and (> height 0)
  244. (or (and lines
  245. (or (null (cdr lines))
  246. (eq 0 (cdr lines))))
  247. (not tool-bar-mode)))
  248. (let* ((initial-top
  249. (cdr (assq 'top frame-initial-geometry-arguments)))
  250. (top (frame-parameter frame-initial-frame 'top)))
  251. (when (and (consp initial-top) (eq '- (car initial-top)))
  252. (let ((adjusted-top
  253. (cond
  254. ((and (consp top) (eq '+ (car top)))
  255. (list '+ (+ (cadr top) height)))
  256. ((and (consp top) (eq '- (car top)))
  257. (list '- (- (cadr top) height)))
  258. (t (+ top height)))))
  259. (modify-frame-parameters
  260. frame-initial-frame `((top . ,adjusted-top))))))
  261. ;; Reset `tool-bar-mode' when zero tool bar lines have been
  262. ;; requested for the window-system or default frame alists.
  263. (when (and tool-bar-mode
  264. (and other-lines
  265. (or (null (cdr other-lines))
  266. (eq 0 (cdr other-lines)))))
  267. (tool-bar-mode -1)))))
  268. ;; The initial frame we create above always has a minibuffer.
  269. ;; If the user wants to remove it, or make it a minibuffer-only
  270. ;; frame, then we'll have to delete the current frame and make a
  271. ;; new one; you can't remove or add a root window to/from an
  272. ;; existing frame.
  273. ;;
  274. ;; NOTE: default-frame-alist was nil when we created the
  275. ;; existing frame. We need to explicitly include
  276. ;; default-frame-alist in the parameters of the screen we
  277. ;; create here, so that its new value, gleaned from the user's
  278. ;; init file, will be applied to the existing screen.
  279. (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
  280. (assq 'minibuffer window-system-frame-alist)
  281. (assq 'minibuffer default-frame-alist)
  282. '(minibuffer . t)))
  283. t))
  284. ;; Create the new frame.
  285. (let (parms new)
  286. ;; MS-Windows needs this to avoid inflooping below.
  287. (if (eq system-type 'windows-nt)
  288. (sit-for 0 t))
  289. ;; If the frame isn't visible yet, wait till it is.
  290. ;; If the user has to position the window,
  291. ;; Emacs doesn't know its real position until
  292. ;; the frame is seen to be visible.
  293. (while (not (cdr (assq 'visibility
  294. (frame-parameters frame-initial-frame))))
  295. (sleep-for 1))
  296. (setq parms (frame-parameters frame-initial-frame))
  297. ;; Get rid of `name' unless it was specified explicitly before.
  298. (or (assq 'name frame-initial-frame-alist)
  299. (setq parms (delq (assq 'name parms) parms)))
  300. ;; An explicit parent-id is a request to XEmbed the frame.
  301. (or (assq 'parent-id frame-initial-frame-alist)
  302. (setq parms (delq (assq 'parent-id parms) parms)))
  303. (setq parms (append initial-frame-alist
  304. window-system-frame-alist
  305. default-frame-alist
  306. parms
  307. nil))
  308. ;; Get rid of `reverse', because that was handled
  309. ;; when we first made the frame.
  310. (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
  311. (if (assq 'height frame-initial-geometry-arguments)
  312. (setq parms (assq-delete-all 'height parms)))
  313. (if (assq 'width frame-initial-geometry-arguments)
  314. (setq parms (assq-delete-all 'width parms)))
  315. (if (assq 'left frame-initial-geometry-arguments)
  316. (setq parms (assq-delete-all 'left parms)))
  317. (if (assq 'top frame-initial-geometry-arguments)
  318. (setq parms (assq-delete-all 'top parms)))
  319. (setq new
  320. (make-frame
  321. ;; Use the geometry args that created the existing
  322. ;; frame, rather than the parms we get for it.
  323. (append frame-initial-geometry-arguments
  324. '((user-size . t) (user-position . t))
  325. parms)))
  326. ;; The initial frame, which we are about to delete, may be
  327. ;; the only frame with a minibuffer. If it is, create a
  328. ;; new one.
  329. (or (delq frame-initial-frame (minibuffer-frame-list))
  330. (make-initial-minibuffer-frame nil))
  331. ;; If the initial frame is serving as a surrogate
  332. ;; minibuffer frame for any frames, we need to wean them
  333. ;; onto a new frame. The default-minibuffer-frame
  334. ;; variable must be handled similarly.
  335. (let ((users-of-initial
  336. (filtered-frame-list
  337. (lambda (frame)
  338. (and (not (eq frame frame-initial-frame))
  339. (eq (window-frame
  340. (minibuffer-window frame))
  341. frame-initial-frame))))))
  342. (if (or users-of-initial
  343. (eq default-minibuffer-frame frame-initial-frame))
  344. ;; Choose an appropriate frame. Prefer frames which
  345. ;; are only minibuffers.
  346. (let* ((new-surrogate
  347. (car
  348. (or (filtered-frame-list
  349. (lambda (frame)
  350. (eq (cdr (assq 'minibuffer
  351. (frame-parameters frame)))
  352. 'only)))
  353. (minibuffer-frame-list))))
  354. (new-minibuffer (minibuffer-window new-surrogate)))
  355. (if (eq default-minibuffer-frame frame-initial-frame)
  356. (setq default-minibuffer-frame new-surrogate))
  357. ;; Wean the frames using frame-initial-frame as
  358. ;; their minibuffer frame.
  359. (dolist (frame users-of-initial)
  360. (modify-frame-parameters
  361. frame (list (cons 'minibuffer new-minibuffer)))))))
  362. ;; Redirect events enqueued at this frame to the new frame.
  363. ;; Is this a good idea?
  364. (redirect-frame-focus frame-initial-frame new)
  365. ;; Finally, get rid of the old frame.
  366. (delete-frame frame-initial-frame t))
  367. ;; Otherwise, we don't need all that rigmarole; just apply
  368. ;; the new parameters.
  369. (let (newparms allparms tail)
  370. (setq allparms (append initial-frame-alist
  371. window-system-frame-alist
  372. default-frame-alist nil))
  373. (if (assq 'height frame-initial-geometry-arguments)
  374. (setq allparms (assq-delete-all 'height allparms)))
  375. (if (assq 'width frame-initial-geometry-arguments)
  376. (setq allparms (assq-delete-all 'width allparms)))
  377. (if (assq 'left frame-initial-geometry-arguments)
  378. (setq allparms (assq-delete-all 'left allparms)))
  379. (if (assq 'top frame-initial-geometry-arguments)
  380. (setq allparms (assq-delete-all 'top allparms)))
  381. (setq tail allparms)
  382. ;; Find just the parms that have changed since we first
  383. ;; made this frame. Those are the ones actually set by
  384. ;; the init file. For those parms whose values we already knew
  385. ;; (such as those spec'd by command line options)
  386. ;; it is undesirable to specify the parm again
  387. ;; once the user has seen the frame and been able to alter it
  388. ;; manually.
  389. (let (newval oldval)
  390. (dolist (entry tail)
  391. (setq oldval (assq (car entry) frame-initial-frame-alist))
  392. (setq newval (cdr (assq (car entry) allparms)))
  393. (or (and oldval (eq (cdr oldval) newval))
  394. (setq newparms
  395. (cons (cons (car entry) newval) newparms)))))
  396. (setq newparms (nreverse newparms))
  397. (let ((new-bg (assq 'background-color newparms)))
  398. ;; If the `background-color' parameter is changed, apply
  399. ;; it first, then make sure that the `background-mode'
  400. ;; parameter and other faces are updated, before applying
  401. ;; the other parameters.
  402. (when new-bg
  403. (modify-frame-parameters frame-initial-frame
  404. (list new-bg))
  405. (unless (assq 'background-mode newparms)
  406. (frame-set-background-mode frame-initial-frame))
  407. (face-set-after-frame-default frame-initial-frame)
  408. (setq newparms (delq new-bg newparms)))
  409. (when (numberp (car frame-size-history))
  410. (setq frame-size-history
  411. (cons (1- (car frame-size-history))
  412. (cons
  413. (list frame-initial-frame
  414. "frame-notice-user-settings"
  415. nil newparms)
  416. (cdr frame-size-history)))))
  417. (modify-frame-parameters frame-initial-frame newparms)))))
  418. ;; Restore the original buffer.
  419. (set-buffer old-buffer)
  420. ;; Make sure the initial frame can be GC'd if it is ever deleted.
  421. ;; Make sure frame-notice-user-settings does nothing if called twice.
  422. (setq frame-notice-user-settings nil)
  423. (setq frame-initial-frame nil)))
  424. (defun make-initial-minibuffer-frame (display)
  425. (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
  426. (if display
  427. (make-frame-on-display display parms)
  428. (make-frame parms))))
  429. ;;;; Creation of additional frames, and other frame miscellanea
  430. (defun modify-all-frames-parameters (alist)
  431. "Modify all current and future frames' parameters according to ALIST.
  432. This changes `default-frame-alist' and possibly `initial-frame-alist'.
  433. Furthermore, this function removes all parameters in ALIST from
  434. `window-system-default-frame-alist'.
  435. See help of `modify-frame-parameters' for more information."
  436. (dolist (frame (frame-list))
  437. (modify-frame-parameters frame alist))
  438. (dolist (pair alist) ;; conses to add/replace
  439. ;; initial-frame-alist needs setting only when
  440. ;; frame-notice-user-settings is true.
  441. (and frame-notice-user-settings
  442. (setq initial-frame-alist
  443. (assq-delete-all (car pair) initial-frame-alist)))
  444. (setq default-frame-alist
  445. (assq-delete-all (car pair) default-frame-alist))
  446. ;; Remove any similar settings from the window-system specific
  447. ;; parameters---they would override default-frame-alist.
  448. (dolist (w window-system-default-frame-alist)
  449. (setcdr w (assq-delete-all (car pair) (cdr w)))))
  450. (and frame-notice-user-settings
  451. (setq initial-frame-alist (append initial-frame-alist alist)))
  452. (setq default-frame-alist (append default-frame-alist alist)))
  453. (defun get-other-frame ()
  454. "Return some frame other than the current frame.
  455. Create one if necessary. Note that the minibuffer frame, if separate,
  456. is not considered (see `next-frame')."
  457. (if (equal (next-frame) (selected-frame)) (make-frame) (next-frame)))
  458. (defun next-multiframe-window ()
  459. "Select the next window, regardless of which frame it is on."
  460. (interactive)
  461. (select-window (next-window (selected-window)
  462. (> (minibuffer-depth) 0)
  463. 0))
  464. (select-frame-set-input-focus (selected-frame)))
  465. (defun previous-multiframe-window ()
  466. "Select the previous window, regardless of which frame it is on."
  467. (interactive)
  468. (select-window (previous-window (selected-window)
  469. (> (minibuffer-depth) 0)
  470. 0))
  471. (select-frame-set-input-focus (selected-frame)))
  472. (defun window-system-for-display (display)
  473. "Return the window system for DISPLAY.
  474. Return nil if we don't know how to interpret DISPLAY."
  475. ;; MS-Windows doesn't know how to create a GUI frame in a -nw session.
  476. (if (and (eq system-type 'windows-nt)
  477. (null (window-system))
  478. (not (daemonp)))
  479. nil
  480. (cl-loop for descriptor in display-format-alist
  481. for pattern = (car descriptor)
  482. for system = (cdr descriptor)
  483. when (string-match-p pattern display) return system)))
  484. (defun make-frame-on-display (display &optional parameters)
  485. "Make a frame on display DISPLAY.
  486. The optional argument PARAMETERS specifies additional frame parameters."
  487. (interactive "sMake frame on display: ")
  488. (make-frame (cons (cons 'display display) parameters)))
  489. (declare-function x-close-connection "xfns.c" (terminal))
  490. (defun close-display-connection (display)
  491. "Close the connection to a display, deleting all its associated frames.
  492. For DISPLAY, specify either a frame or a display name (a string).
  493. If DISPLAY is nil, that stands for the selected frame's display."
  494. (interactive
  495. (list
  496. (let* ((default (frame-parameter nil 'display))
  497. (display (completing-read
  498. (format "Close display (default %s): " default)
  499. (delete-dups
  500. (mapcar (lambda (frame)
  501. (frame-parameter frame 'display))
  502. (frame-list)))
  503. nil t nil nil
  504. default)))
  505. (if (zerop (length display)) default display))))
  506. (let ((frames (delq nil
  507. (mapcar (lambda (frame)
  508. (if (equal display
  509. (frame-parameter frame 'display))
  510. frame))
  511. (frame-list)))))
  512. (if (and (consp frames)
  513. (not (y-or-n-p (if (cdr frames)
  514. (format "Delete %s frames? " (length frames))
  515. (format "Delete %s ? " (car frames))))))
  516. (error "Abort!")
  517. (mapc 'delete-frame frames)
  518. (x-close-connection display))))
  519. (defun make-frame-command ()
  520. "Make a new frame, on the same terminal as the selected frame.
  521. If the terminal is a text-only terminal, this also selects the
  522. new frame."
  523. (interactive)
  524. (if (display-graphic-p)
  525. (make-frame)
  526. (select-frame (make-frame))))
  527. (defvar before-make-frame-hook nil
  528. "Functions to run before a frame is created.")
  529. (defvar after-make-frame-functions nil
  530. "Functions to run after a frame is created.
  531. The functions are run with one arg, the newly created frame.")
  532. (defvar after-setting-font-hook nil
  533. "Functions to run after a frame's font has been changed.")
  534. ;; Alias, kept temporarily.
  535. (define-obsolete-function-alias 'new-frame 'make-frame "22.1")
  536. (defvar frame-inherited-parameters '()
  537. "Parameters `make-frame' copies from the `selected-frame' to the new frame.")
  538. (defvar x-display-name)
  539. (defun make-frame (&optional parameters)
  540. "Return a newly created frame displaying the current buffer.
  541. Optional argument PARAMETERS is an alist of frame parameters for
  542. the new frame. Each element of PARAMETERS should have the
  543. form (NAME . VALUE), for example:
  544. (name . STRING) The frame should be named STRING.
  545. (width . NUMBER) The frame should be NUMBER characters in width.
  546. (height . NUMBER) The frame should be NUMBER text lines high.
  547. You cannot specify either `width' or `height', you must specify
  548. neither or both.
  549. (minibuffer . t) The frame should have a minibuffer.
  550. (minibuffer . nil) The frame should have no minibuffer.
  551. (minibuffer . only) The frame should contain only a minibuffer.
  552. (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
  553. (window-system . nil) The frame should be displayed on a terminal device.
  554. (window-system . x) The frame should be displayed in an X window.
  555. (display . \":0\") The frame should appear on display :0.
  556. (terminal . TERMINAL) The frame should use the terminal object TERMINAL.
  557. In addition, any parameter specified in `default-frame-alist',
  558. but not present in PARAMETERS, is applied.
  559. Before creating the frame (via `frame-creation-function-alist'),
  560. this function runs the hook `before-make-frame-hook'. After
  561. creating the frame, it runs the hook `after-make-frame-functions'
  562. with one arg, the newly created frame.
  563. If a display parameter is supplied and a window-system is not,
  564. guess the window-system from the display.
  565. On graphical displays, this function does not itself make the new
  566. frame the selected frame. However, the window system may select
  567. the new frame according to its own rules."
  568. (interactive)
  569. (let* ((display (cdr (assq 'display parameters)))
  570. (w (cond
  571. ((assq 'terminal parameters)
  572. (let ((type (terminal-live-p
  573. (cdr (assq 'terminal parameters)))))
  574. (cond
  575. ((eq t type) nil)
  576. ((null type) (error "Terminal %s does not exist"
  577. (cdr (assq 'terminal parameters))))
  578. (t type))))
  579. ((assq 'window-system parameters)
  580. (cdr (assq 'window-system parameters)))
  581. (display
  582. (or (window-system-for-display display)
  583. (error "Don't know how to interpret display %S"
  584. display)))
  585. (t window-system)))
  586. (oldframe (selected-frame))
  587. (params parameters)
  588. frame)
  589. (unless (get w 'window-system-initialized)
  590. (let ((window-system w)) ;Hack attack!
  591. (window-system-initialization display))
  592. (setq x-display-name display)
  593. (put w 'window-system-initialized t))
  594. ;; Add parameters from `window-system-default-frame-alist'.
  595. (dolist (p (cdr (assq w window-system-default-frame-alist)))
  596. (unless (assq (car p) params)
  597. (push p params)))
  598. ;; Add parameters from `default-frame-alist'.
  599. (dolist (p default-frame-alist)
  600. (unless (assq (car p) params)
  601. (push p params)))
  602. ;; Now make the frame.
  603. (run-hooks 'before-make-frame-hook)
  604. ;; (setq frame-size-history '(1000))
  605. (setq frame (let ((window-system w)) ;Hack attack!
  606. (frame-creation-function params)))
  607. (normal-erase-is-backspace-setup-frame frame)
  608. ;; Inherit the original frame's parameters.
  609. (dolist (param frame-inherited-parameters)
  610. (unless (assq param parameters) ;Overridden by explicit parameters.
  611. (let ((val (frame-parameter oldframe param)))
  612. (when val (set-frame-parameter frame param val)))))
  613. (when (numberp (car frame-size-history))
  614. (setq frame-size-history
  615. (cons (1- (car frame-size-history))
  616. (cons (list frame "make-frame")
  617. (cdr frame-size-history)))))
  618. ;; We can run `window-configuration-change-hook' for this frame now.
  619. (frame-after-make-frame frame t)
  620. (run-hook-with-args 'after-make-frame-functions frame)
  621. frame))
  622. (defun filtered-frame-list (predicate)
  623. "Return a list of all live frames which satisfy PREDICATE."
  624. (let* ((frames (frame-list))
  625. (list frames))
  626. (while (consp frames)
  627. (unless (funcall predicate (car frames))
  628. (setcar frames nil))
  629. (setq frames (cdr frames)))
  630. (delq nil list)))
  631. (defun minibuffer-frame-list ()
  632. "Return a list of all frames with their own minibuffers."
  633. (filtered-frame-list
  634. (lambda (frame)
  635. (eq frame (window-frame (minibuffer-window frame))))))
  636. ;; Used to be called `terminal-id' in termdev.el.
  637. (defun get-device-terminal (device)
  638. "Return the terminal corresponding to DEVICE.
  639. DEVICE can be a terminal, a frame, nil (meaning the selected frame's terminal),
  640. the name of an X display device (HOST.SERVER.SCREEN) or a tty device file."
  641. (cond
  642. ((or (null device) (framep device))
  643. (frame-terminal device))
  644. ((stringp device)
  645. (let ((f (car (filtered-frame-list
  646. (lambda (frame)
  647. (or (equal (frame-parameter frame 'display) device)
  648. (equal (frame-parameter frame 'tty) device)))))))
  649. (or f (error "Display %s does not exist" device))
  650. (frame-terminal f)))
  651. ((terminal-live-p device) device)
  652. (t
  653. (error "Invalid argument %s in ‘get-device-terminal’" device))))
  654. (defun frames-on-display-list (&optional device)
  655. "Return a list of all frames on DEVICE.
  656. DEVICE should be a terminal, a frame,
  657. or a name of an X display or tty (a string of the form
  658. HOST:SERVER.SCREEN).
  659. If DEVICE is omitted or nil, it defaults to the selected
  660. frame's terminal device."
  661. (let* ((terminal (get-device-terminal device))
  662. (func #'(lambda (frame)
  663. (eq (frame-terminal frame) terminal))))
  664. (filtered-frame-list func)))
  665. (defun framep-on-display (&optional terminal)
  666. "Return the type of frames on TERMINAL.
  667. TERMINAL may be a terminal id, a display name or a frame. If it
  668. is a frame, its type is returned. If TERMINAL is omitted or nil,
  669. it defaults to the selected frame's terminal device. All frames
  670. on a given display are of the same type."
  671. (or (terminal-live-p terminal)
  672. (framep terminal)
  673. (framep (car (frames-on-display-list terminal)))))
  674. (defun frame-remove-geometry-params (param-list)
  675. "Return the parameter list PARAM-LIST, but with geometry specs removed.
  676. This deletes all bindings in PARAM-LIST for `top', `left', `width',
  677. `height', `user-size' and `user-position' parameters.
  678. Emacs uses this to avoid overriding explicit moves and resizings from
  679. the user during startup."
  680. (setq param-list (cons nil param-list))
  681. (let ((tail param-list))
  682. (while (consp (cdr tail))
  683. (if (and (consp (car (cdr tail)))
  684. (memq (car (car (cdr tail)))
  685. '(height width top left user-position user-size)))
  686. (progn
  687. (setq frame-initial-geometry-arguments
  688. (cons (car (cdr tail)) frame-initial-geometry-arguments))
  689. (setcdr tail (cdr (cdr tail))))
  690. (setq tail (cdr tail)))))
  691. (setq frame-initial-geometry-arguments
  692. (nreverse frame-initial-geometry-arguments))
  693. (cdr param-list))
  694. (declare-function x-focus-frame "frame.c" (frame))
  695. (defun select-frame-set-input-focus (frame &optional norecord)
  696. "Select FRAME, raise it, and set input focus, if possible.
  697. If `mouse-autoselect-window' is non-nil, also move mouse pointer
  698. to FRAME's selected window. Otherwise, if `focus-follows-mouse'
  699. is non-nil, move mouse cursor to FRAME.
  700. Optional argument NORECORD means to neither change the order of
  701. recently selected windows nor the buffer list."
  702. (select-frame frame norecord)
  703. (raise-frame frame)
  704. ;; Ensure, if possible, that FRAME gets input focus.
  705. (when (memq (window-system frame) '(x w32 ns))
  706. (x-focus-frame frame))
  707. ;; Move mouse cursor if necessary.
  708. (cond
  709. (mouse-autoselect-window
  710. (let ((edges (window-inside-edges (frame-selected-window frame))))
  711. ;; Move mouse cursor into FRAME's selected window to avoid that
  712. ;; Emacs mouse-autoselects another window.
  713. (set-mouse-position frame (nth 2 edges) (nth 1 edges))))
  714. (focus-follows-mouse
  715. ;; Move mouse cursor into FRAME to avoid that another frame gets
  716. ;; selected by the window manager.
  717. (set-mouse-position frame (1- (frame-width frame)) 0))))
  718. (defun other-frame (arg)
  719. "Select the ARGth different visible frame on current display, and raise it.
  720. All frames are arranged in a cyclic order.
  721. This command selects the frame ARG steps away in that order.
  722. A negative ARG moves in the opposite order.
  723. To make this command work properly, you must tell Emacs
  724. how the system (or the window manager) generally handles
  725. focus-switching between windows. If moving the mouse onto a window
  726. selects it (gives it focus), set `focus-follows-mouse' to t.
  727. Otherwise, that variable should be nil."
  728. (interactive "p")
  729. (let ((frame (selected-frame)))
  730. (while (> arg 0)
  731. (setq frame (next-frame frame))
  732. (while (not (eq (frame-visible-p frame) t))
  733. (setq frame (next-frame frame)))
  734. (setq arg (1- arg)))
  735. (while (< arg 0)
  736. (setq frame (previous-frame frame))
  737. (while (not (eq (frame-visible-p frame) t))
  738. (setq frame (previous-frame frame)))
  739. (setq arg (1+ arg)))
  740. (select-frame-set-input-focus frame)))
  741. (defun iconify-or-deiconify-frame ()
  742. "Iconify the selected frame, or deiconify if it's currently an icon."
  743. (interactive)
  744. (if (eq (cdr (assq 'visibility (frame-parameters))) t)
  745. (iconify-frame)
  746. (make-frame-visible)))
  747. (defun suspend-frame ()
  748. "Do whatever is right to suspend the current frame.
  749. Calls `suspend-emacs' if invoked from the controlling tty device,
  750. `suspend-tty' from a secondary tty device, and
  751. `iconify-or-deiconify-frame' from an X frame."
  752. (interactive)
  753. (let ((type (framep (selected-frame))))
  754. (cond
  755. ((memq type '(x ns w32)) (iconify-or-deiconify-frame))
  756. ((eq type t)
  757. (if (controlling-tty-p)
  758. (suspend-emacs)
  759. (suspend-tty)))
  760. (t (suspend-emacs)))))
  761. (defun make-frame-names-alist ()
  762. ;; Only consider the frames on the same display.
  763. (let* ((current-frame (selected-frame))
  764. (falist
  765. (cons
  766. (cons (frame-parameter current-frame 'name) current-frame) nil))
  767. (frame (next-frame nil 0)))
  768. (while (not (eq frame current-frame))
  769. (progn
  770. (push (cons (frame-parameter frame 'name) frame) falist)
  771. (setq frame (next-frame frame 0))))
  772. falist))
  773. (defvar frame-name-history nil)
  774. (defun select-frame-by-name (name)
  775. "Select the frame on the current terminal whose name is NAME and raise it.
  776. If there is no frame by that name, signal an error."
  777. (interactive
  778. (let* ((frame-names-alist (make-frame-names-alist))
  779. (default (car (car frame-names-alist)))
  780. (input (completing-read
  781. (format "Select Frame (default %s): " default)
  782. frame-names-alist nil t nil 'frame-name-history)))
  783. (if (= (length input) 0)
  784. (list default)
  785. (list input))))
  786. (let* ((frame-names-alist (make-frame-names-alist))
  787. (frame (cdr (assoc name frame-names-alist))))
  788. (if frame
  789. (select-frame-set-input-focus frame)
  790. (error "There is no frame named ‘%s’" name))))
  791. ;;;; Background mode.
  792. (defcustom frame-background-mode nil
  793. "The brightness of the background.
  794. Set this to the symbol `dark' if your background color is dark,
  795. `light' if your background is light, or nil (automatic by default)
  796. if you want Emacs to examine the brightness for you.
  797. If you change this without using customize, you should use
  798. `frame-set-background-mode' to update existing frames;
  799. e.g. (mapc 'frame-set-background-mode (frame-list))."
  800. :group 'faces
  801. :set #'(lambda (var value)
  802. (set-default var value)
  803. (mapc 'frame-set-background-mode (frame-list)))
  804. :initialize 'custom-initialize-changed
  805. :type '(choice (const dark)
  806. (const light)
  807. (const :tag "automatic" nil)))
  808. (declare-function x-get-resource "frame.c"
  809. (attribute class &optional component subclass))
  810. ;; Only used if window-system is not null.
  811. (declare-function x-display-grayscale-p "xfns.c" (&optional terminal))
  812. (defvar inhibit-frame-set-background-mode nil)
  813. (defun frame-set-background-mode (frame &optional keep-face-specs)
  814. "Set up display-dependent faces on FRAME.
  815. Display-dependent faces are those which have different definitions
  816. according to the `background-mode' and `display-type' frame parameters.
  817. If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate
  818. face specs for the new background mode."
  819. (unless inhibit-frame-set-background-mode
  820. (let* ((frame-default-bg-mode (frame-terminal-default-bg-mode frame))
  821. (bg-color (frame-parameter frame 'background-color))
  822. (tty-type (tty-type frame))
  823. (default-bg-mode
  824. (if (or (window-system frame)
  825. (and tty-type
  826. (string-match "^\\(xterm\\|\\rxvt\\|dtterm\\|eterm\\)"
  827. tty-type)))
  828. 'light
  829. 'dark))
  830. (non-default-bg-mode (if (eq default-bg-mode 'light) 'dark 'light))
  831. (bg-mode
  832. (cond (frame-default-bg-mode)
  833. ((equal bg-color "unspecified-fg") ; inverted colors
  834. non-default-bg-mode)
  835. ((not (color-values bg-color frame))
  836. default-bg-mode)
  837. ((>= (apply '+ (color-values bg-color frame))
  838. ;; Just looking at the screen, colors whose
  839. ;; values add up to .6 of the white total
  840. ;; still look dark to me.
  841. (* (apply '+ (color-values "white" frame)) .6))
  842. 'light)
  843. (t 'dark)))
  844. (display-type
  845. (cond ((null (window-system frame))
  846. (if (tty-display-color-p frame) 'color 'mono))
  847. ((display-color-p frame)
  848. 'color)
  849. ((x-display-grayscale-p frame)
  850. 'grayscale)
  851. (t 'mono)))
  852. (old-bg-mode
  853. (frame-parameter frame 'background-mode))
  854. (old-display-type
  855. (frame-parameter frame 'display-type)))
  856. (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
  857. (let ((locally-modified-faces nil)
  858. ;; Prevent face-spec-recalc from calling this function
  859. ;; again, resulting in a loop (bug#911).
  860. (inhibit-frame-set-background-mode t)
  861. (params (list (cons 'background-mode bg-mode)
  862. (cons 'display-type display-type))))
  863. (if keep-face-specs
  864. (modify-frame-parameters frame params)
  865. ;; If we are recomputing face specs, first collect a list
  866. ;; of faces that don't match their face-specs. These are
  867. ;; the faces modified on FRAME, and we avoid changing them
  868. ;; below. Use a negative list to avoid consing (we assume
  869. ;; most faces are unmodified).
  870. (dolist (face (face-list))
  871. (and (not (get face 'face-override-spec))
  872. (not (face-spec-match-p face
  873. (face-user-default-spec face)
  874. (selected-frame)))
  875. (push face locally-modified-faces)))
  876. ;; Now change to the new frame parameters
  877. (modify-frame-parameters frame params)
  878. ;; For all unmodified named faces, choose face specs
  879. ;; matching the new frame parameters.
  880. (dolist (face (face-list))
  881. (unless (memq face locally-modified-faces)
  882. (face-spec-recalc face frame)))))))))
  883. (defun frame-terminal-default-bg-mode (frame)
  884. "Return the default background mode of FRAME.
  885. This checks the `frame-background-mode' variable, the X resource
  886. named \"backgroundMode\" (if FRAME is an X frame), and finally
  887. the `background-mode' terminal parameter."
  888. (or frame-background-mode
  889. (let ((bg-resource
  890. (and (window-system frame)
  891. (x-get-resource "backgroundMode" "BackgroundMode"))))
  892. (if bg-resource
  893. (intern (downcase bg-resource))))
  894. (terminal-parameter frame 'background-mode)))
  895. ;;;; Frame configurations
  896. (defun current-frame-configuration ()
  897. "Return a list describing the positions and states of all frames.
  898. Its car is `frame-configuration'.
  899. Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
  900. where
  901. FRAME is a frame object,
  902. ALIST is an association list specifying some of FRAME's parameters, and
  903. WINDOW-CONFIG is a window configuration object for FRAME."
  904. (cons 'frame-configuration
  905. (mapcar (lambda (frame)
  906. (list frame
  907. (frame-parameters frame)
  908. (current-window-configuration frame)))
  909. (frame-list))))
  910. (defun set-frame-configuration (configuration &optional nodelete)
  911. "Restore the frames to the state described by CONFIGURATION.
  912. Each frame listed in CONFIGURATION has its position, size, window
  913. configuration, and other parameters set as specified in CONFIGURATION.
  914. However, this function does not restore deleted frames.
  915. Ordinarily, this function deletes all existing frames not
  916. listed in CONFIGURATION. But if optional second argument NODELETE
  917. is given and non-nil, the unwanted frames are iconified instead."
  918. (or (frame-configuration-p configuration)
  919. (signal 'wrong-type-argument
  920. (list 'frame-configuration-p configuration)))
  921. (let ((config-alist (cdr configuration))
  922. frames-to-delete)
  923. (dolist (frame (frame-list))
  924. (let ((parameters (assq frame config-alist)))
  925. (if parameters
  926. (progn
  927. (modify-frame-parameters
  928. frame
  929. ;; Since we can't set a frame's minibuffer status,
  930. ;; we might as well omit the parameter altogether.
  931. (let* ((parms (nth 1 parameters))
  932. (mini (assq 'minibuffer parms))
  933. (name (assq 'name parms))
  934. (explicit-name (cdr (assq 'explicit-name parms))))
  935. (when mini (setq parms (delq mini parms)))
  936. ;; Leave name in iff it was set explicitly.
  937. ;; This should fix the behavior reported in
  938. ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg01632.html
  939. (when (and name (not explicit-name))
  940. (setq parms (delq name parms)))
  941. parms))
  942. (set-window-configuration (nth 2 parameters)))
  943. (setq frames-to-delete (cons frame frames-to-delete)))))
  944. (mapc (if nodelete
  945. ;; Note: making frames invisible here was tried
  946. ;; but led to some strange behavior--each time the frame
  947. ;; was made visible again, the window manager asked afresh
  948. ;; for where to put it.
  949. 'iconify-frame
  950. 'delete-frame)
  951. frames-to-delete)))
  952. ;;;; Convenience functions for accessing and interactively changing
  953. ;;;; frame parameters.
  954. (defun frame-height (&optional frame)
  955. "Return number of lines available for display on FRAME.
  956. If FRAME is omitted, describe the currently selected frame.
  957. Exactly what is included in the return value depends on the
  958. window-system and toolkit in use - see `frame-pixel-height' for
  959. more details. The lines are in units of the default font height.
  960. The result is roughly related to the frame pixel height via
  961. height in pixels = height in lines * `frame-char-height'.
  962. However, this is only approximate, and is complicated e.g. by the
  963. fact that individual window lines and menu bar lines can have
  964. differing font heights."
  965. (cdr (assq 'height (frame-parameters frame))))
  966. (defun frame-width (&optional frame)
  967. "Return number of columns available for display on FRAME.
  968. If FRAME is omitted, describe the currently selected frame."
  969. (cdr (assq 'width (frame-parameters frame))))
  970. (declare-function x-list-fonts "xfaces.c"
  971. (pattern &optional face frame maximum width))
  972. (define-obsolete-function-alias 'set-default-font 'set-frame-font "23.1")
  973. (defun set-frame-font (font &optional keep-size frames)
  974. "Set the default font to FONT.
  975. When called interactively, prompt for the name of a font, and use
  976. that font on the selected frame. When called from Lisp, FONT
  977. should be a font name (a string), a font object, font entity, or
  978. font spec.
  979. If KEEP-SIZE is nil, keep the number of frame lines and columns
  980. fixed. If KEEP-SIZE is non-nil (or with a prefix argument), try
  981. to keep the current frame size fixed (in pixels) by adjusting the
  982. number of lines and columns.
  983. If FRAMES is nil, apply the font to the selected frame only.
  984. If FRAMES is non-nil, it should be a list of frames to act upon,
  985. or t meaning all existing graphical frames.
  986. Also, if FRAMES is non-nil, alter the user's Customization settings
  987. as though the font-related attributes of the `default' face had been
  988. \"set in this session\", so that the font is applied to future frames."
  989. (interactive
  990. (let* ((completion-ignore-case t)
  991. (font (completing-read "Font name: "
  992. ;; x-list-fonts will fail with an error
  993. ;; if this frame doesn't support fonts.
  994. (x-list-fonts "*" nil (selected-frame))
  995. nil nil nil nil
  996. (frame-parameter nil 'font))))
  997. (list font current-prefix-arg nil)))
  998. (when (or (stringp font) (fontp font))
  999. (let* ((this-frame (selected-frame))
  1000. ;; FRAMES nil means affect the selected frame.
  1001. (frame-list (cond ((null frames)
  1002. (list this-frame))
  1003. ((eq frames t)
  1004. (frame-list))
  1005. (t frames)))
  1006. height width)
  1007. (dolist (f frame-list)
  1008. (when (display-multi-font-p f)
  1009. (if keep-size
  1010. (setq height (* (frame-parameter f 'height)
  1011. (frame-char-height f))
  1012. width (* (frame-parameter f 'width)
  1013. (frame-char-width f))))
  1014. ;; When set-face-attribute is called for :font, Emacs
  1015. ;; guesses the best font according to other face attributes
  1016. ;; (:width, :weight, etc.) so reset them too (Bug#2476).
  1017. (set-face-attribute 'default f
  1018. :width 'normal :weight 'normal
  1019. :slant 'normal :font font)
  1020. (if keep-size
  1021. (modify-frame-parameters
  1022. f
  1023. (list (cons 'height (round height (frame-char-height f)))
  1024. (cons 'width (round width (frame-char-width f))))))))
  1025. (when frames
  1026. ;; Alter the user's Custom setting of the `default' face, but
  1027. ;; only for font-related attributes.
  1028. (let ((specs (cadr (assq 'user (get 'default 'theme-face))))
  1029. (attrs '(:family :foundry :slant :weight :height :width))
  1030. (new-specs nil))
  1031. (if (null specs) (setq specs '((t nil))))
  1032. (dolist (spec specs)
  1033. ;; Each SPEC has the form (DISPLAY ATTRIBUTE-PLIST)
  1034. (let ((display (nth 0 spec))
  1035. (plist (copy-tree (nth 1 spec))))
  1036. ;; Alter only DISPLAY conditions matching this frame.
  1037. (when (or (memq display '(t default))
  1038. (face-spec-set-match-display display this-frame))
  1039. (dolist (attr attrs)
  1040. (setq plist (plist-put plist attr
  1041. (face-attribute 'default attr)))))
  1042. (push (list display plist) new-specs)))
  1043. (setq new-specs (nreverse new-specs))
  1044. (put 'default 'customized-face new-specs)
  1045. (custom-push-theme 'theme-face 'default 'user 'set new-specs)
  1046. (put 'default 'face-modified nil))))
  1047. (run-hooks 'after-setting-font-hook 'after-setting-font-hooks)))
  1048. (defun set-frame-parameter (frame parameter value)
  1049. "Set frame parameter PARAMETER to VALUE on FRAME.
  1050. If FRAME is nil, it defaults to the selected frame.
  1051. See `modify-frame-parameters'."
  1052. (modify-frame-parameters frame (list (cons parameter value))))
  1053. (defun set-background-color (color-name)
  1054. "Set the background color of the selected frame to COLOR-NAME.
  1055. When called interactively, prompt for the name of the color to use.
  1056. To get the frame's current background color, use `frame-parameters'."
  1057. (interactive (list (read-color "Background color: ")))
  1058. (modify-frame-parameters (selected-frame)
  1059. (list (cons 'background-color color-name)))
  1060. (or window-system
  1061. (face-set-after-frame-default (selected-frame)
  1062. (list
  1063. (cons 'background-color color-name)
  1064. ;; Pass the foreground-color as
  1065. ;; well, if defined, to avoid
  1066. ;; losing it when faces are reset
  1067. ;; to their defaults.
  1068. (assq 'foreground-color
  1069. (frame-parameters))))))
  1070. (defun set-foreground-color (color-name)
  1071. "Set the foreground color of the selected frame to COLOR-NAME.
  1072. When called interactively, prompt for the name of the color to use.
  1073. To get the frame's current foreground color, use `frame-parameters'."
  1074. (interactive (list (read-color "Foreground color: ")))
  1075. (modify-frame-parameters (selected-frame)
  1076. (list (cons 'foreground-color color-name)))
  1077. (or window-system
  1078. (face-set-after-frame-default (selected-frame)
  1079. (list
  1080. (cons 'foreground-color color-name)
  1081. ;; Pass the background-color as
  1082. ;; well, if defined, to avoid
  1083. ;; losing it when faces are reset
  1084. ;; to their defaults.
  1085. (assq 'background-color
  1086. (frame-parameters))))))
  1087. (defun set-cursor-color (color-name)
  1088. "Set the text cursor color of the selected frame to COLOR-NAME.
  1089. When called interactively, prompt for the name of the color to use.
  1090. This works by setting the `cursor-color' frame parameter on the
  1091. selected frame.
  1092. You can also set the text cursor color, for all frames, by
  1093. customizing the `cursor' face."
  1094. (interactive (list (read-color "Cursor color: ")))
  1095. (modify-frame-parameters (selected-frame)
  1096. (list (cons 'cursor-color color-name))))
  1097. (defun set-mouse-color (color-name)
  1098. "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
  1099. When called interactively, prompt for the name of the color to use.
  1100. To get the frame's current mouse color, use `frame-parameters'."
  1101. (interactive (list (read-color "Mouse color: ")))
  1102. (modify-frame-parameters (selected-frame)
  1103. (list (cons 'mouse-color
  1104. (or color-name
  1105. (cdr (assq 'mouse-color
  1106. (frame-parameters))))))))
  1107. (defun set-border-color (color-name)
  1108. "Set the color of the border of the selected frame to COLOR-NAME.
  1109. When called interactively, prompt for the name of the color to use.
  1110. To get the frame's current border color, use `frame-parameters'."
  1111. (interactive (list (read-color "Border color: ")))
  1112. (modify-frame-parameters (selected-frame)
  1113. (list (cons 'border-color color-name))))
  1114. (define-minor-mode auto-raise-mode
  1115. "Toggle whether or not selected frames should auto-raise.
  1116. With a prefix argument ARG, enable Auto Raise mode if ARG is
  1117. positive, and disable it otherwise. If called from Lisp, enable
  1118. the mode if ARG is omitted or nil.
  1119. Auto Raise mode does nothing under most window managers, which
  1120. switch focus on mouse clicks. It only has an effect if your
  1121. window manager switches focus on mouse movement (in which case
  1122. you should also change `focus-follows-mouse' to t). Then,
  1123. enabling Auto Raise mode causes any graphical Emacs frame which
  1124. acquires focus to be automatically raised.
  1125. Note that this minor mode controls Emacs's own auto-raise
  1126. feature. Window managers that switch focus on mouse movement
  1127. often have their own auto-raise feature."
  1128. :variable (frame-parameter nil 'auto-raise)
  1129. (if (frame-parameter nil 'auto-raise)
  1130. (raise-frame)))
  1131. (define-minor-mode auto-lower-mode
  1132. "Toggle whether or not the selected frame should auto-lower.
  1133. With a prefix argument ARG, enable Auto Lower mode if ARG is
  1134. positive, and disable it otherwise. If called from Lisp, enable
  1135. the mode if ARG is omitted or nil.
  1136. Auto Lower mode does nothing under most window managers, which
  1137. switch focus on mouse clicks. It only has an effect if your
  1138. window manager switches focus on mouse movement (in which case
  1139. you should also change `focus-follows-mouse' to t). Then,
  1140. enabling Auto Lower Mode causes any graphical Emacs frame which
  1141. loses focus to be automatically lowered.
  1142. Note that this minor mode controls Emacs's own auto-lower
  1143. feature. Window managers that switch focus on mouse movement
  1144. often have their own features for raising or lowering frames."
  1145. :variable (frame-parameter nil 'auto-lower))
  1146. (defun set-frame-name (name)
  1147. "Set the name of the selected frame to NAME.
  1148. When called interactively, prompt for the name of the frame.
  1149. On text terminals, the frame name is displayed on the mode line.
  1150. On graphical displays, it is displayed on the frame's title bar."
  1151. (interactive "sFrame name: ")
  1152. (modify-frame-parameters (selected-frame)
  1153. (list (cons 'name name))))
  1154. (defun frame-current-scroll-bars (&optional frame)
  1155. "Return the current scroll-bar types for frame FRAME.
  1156. Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies
  1157. the current location of the vertical scroll-bars (`left', `right'
  1158. or nil), and HORIZONTAL specifies the current location of the
  1159. horizontal scroll bars (`bottom' or nil). FRAME must specify a
  1160. live frame and defaults to the selected one."
  1161. (let* ((frame (window-normalize-frame frame))
  1162. (vertical (frame-parameter frame 'vertical-scroll-bars))
  1163. (horizontal (frame-parameter frame 'horizontal-scroll-bars)))
  1164. (unless (memq vertical '(left right nil))
  1165. (setq vertical default-frame-scroll-bars))
  1166. (cons vertical (and horizontal 'bottom))))
  1167. (declare-function x-frame-geometry "xfns.c" (&optional frame))
  1168. (declare-function w32-frame-geometry "w32fns.c" (&optional frame))
  1169. (declare-function ns-frame-geometry "nsfns.m" (&optional frame))
  1170. (defun frame-geometry (&optional frame)
  1171. "Return geometric attributes of FRAME.
  1172. FRAME must be a live frame and defaults to the selected one. The return
  1173. value is an association list of the attributes listed below. All height
  1174. and width values are in pixels.
  1175. `outer-position' is a cons of the outer left and top edges of FRAME
  1176. relative to the origin - the position (0, 0) - of FRAME's display.
  1177. `outer-size' is a cons of the outer width and height of FRAME. The
  1178. outer size includes the title bar and the external borders as well as
  1179. any menu and/or tool bar of frame.
  1180. `external-border-size' is a cons of the horizontal and vertical width of
  1181. FRAME's external borders as supplied by the window manager.
  1182. `title-bar-size' is a cons of the width and height of the title bar of
  1183. FRAME as supplied by the window manager. If both of them are zero,
  1184. FRAME has no title bar. If only the width is zero, Emacs was not
  1185. able to retrieve the width information.
  1186. `menu-bar-external', if non-nil, means the menu bar is external (never
  1187. included in the inner edges of FRAME).
  1188. `menu-bar-size' is a cons of the width and height of the menu bar of
  1189. FRAME.
  1190. `tool-bar-external', if non-nil, means the tool bar is external (never
  1191. included in the inner edges of FRAME).
  1192. `tool-bar-position' tells on which side the tool bar on FRAME is and can
  1193. be one of `left', `top', `right' or `bottom'. If this is nil, FRAME
  1194. has no tool bar.
  1195. `tool-bar-size' is a cons of the width and height of the tool bar of
  1196. FRAME.
  1197. `internal-border-width' is the width of the internal border of
  1198. FRAME."
  1199. (let* ((frame (window-normalize-frame frame))
  1200. (frame-type (framep-on-display frame)))
  1201. (cond
  1202. ((eq frame-type 'x)
  1203. (x-frame-geometry frame))
  1204. ((eq frame-type 'w32)
  1205. (w32-frame-geometry frame))
  1206. ((eq frame-type 'ns)
  1207. (ns-frame-geometry frame))
  1208. (t
  1209. (list
  1210. '(outer-position 0 . 0)
  1211. (cons 'outer-size (cons (frame-width frame) (frame-height frame)))
  1212. '(external-border-size 0 . 0)
  1213. '(title-bar-size 0 . 0)
  1214. '(menu-bar-external . nil)
  1215. (let ((menu-bar-lines (frame-parameter frame 'menu-bar-lines)))
  1216. (cons 'menu-bar-size
  1217. (if menu-bar-lines
  1218. (cons (frame-width frame) 1)
  1219. 1 0)))
  1220. '(tool-bar-external . nil)
  1221. '(tool-bar-position . nil)
  1222. '(tool-bar-size 0 . 0)
  1223. (cons 'internal-border-width
  1224. (frame-parameter frame 'internal-border-width)))))))
  1225. (declare-function x-frame-edges "xfns.c" (&optional frame type))
  1226. (declare-function w32-frame-edges "w32fns.c" (&optional frame type))
  1227. (declare-function ns-frame-edges "nsfns.m" (&optional frame type))
  1228. (defun frame-edges (&optional frame type)
  1229. "Return coordinates of FRAME's edges.
  1230. FRAME must be a live frame and defaults to the selected one. The
  1231. list returned has the form (LEFT TOP RIGHT BOTTOM) where all
  1232. values are in pixels relative to the origin - the position (0, 0)
  1233. - of FRAME's display. For terminal frames all values are
  1234. relative to LEFT and TOP which are both zero.
  1235. Optional argument TYPE specifies the type of the edges. TYPE
  1236. `outer-edges' means to return the outer edges of FRAME. TYPE
  1237. `native-edges' (or nil) means to return the native edges of
  1238. FRAME. TYPE `inner-edges' means to return the inner edges of
  1239. FRAME."
  1240. (let* ((frame (window-normalize-frame frame))
  1241. (frame-type (framep-on-display frame)))
  1242. (cond
  1243. ((eq frame-type 'x)
  1244. (x-frame-edges frame type))
  1245. ((eq frame-type 'w32)
  1246. (w32-frame-edges frame type))
  1247. ((eq frame-type 'ns)
  1248. (ns-frame-edges frame type))
  1249. (t
  1250. (list 0 0 (frame-width frame) (frame-height frame))))))
  1251. (declare-function w32-mouse-absolute-pixel-position "w32fns.c")
  1252. (declare-function x-mouse-absolute-pixel-position "xfns.c")
  1253. (defun mouse-absolute-pixel-position ()
  1254. "Return absolute position of mouse cursor in pixels.
  1255. The position is returned as a cons cell (X . Y) of the
  1256. coordinates of the mouse cursor position in pixels relative to a
  1257. position (0, 0) of the selected frame's terminal."
  1258. (let ((frame-type (framep-on-display)))
  1259. (cond
  1260. ((eq frame-type 'x)
  1261. (x-mouse-absolute-pixel-position))
  1262. ((eq frame-type 'w32)
  1263. (w32-mouse-absolute-pixel-position))
  1264. (t
  1265. (cons 0 0)))))
  1266. (declare-function w32-set-mouse-absolute-pixel-position "w32fns.c" (x y))
  1267. (declare-function x-set-mouse-absolute-pixel-position "xfns.c" (x y))
  1268. (defun set-mouse-absolute-pixel-position (x y)
  1269. "Move mouse pointer to absolute pixel position (X, Y).
  1270. The coordinates X and Y are interpreted in pixels relative to a
  1271. position (0, 0) of the selected frame's terminal."
  1272. (let ((frame-type (framep-on-display)))
  1273. (cond
  1274. ((eq frame-type 'x)
  1275. (x-set-mouse-absolute-pixel-position x y))
  1276. ((eq frame-type 'w32)
  1277. (w32-set-mouse-absolute-pixel-position x y)))))
  1278. (defun frame-monitor-attributes (&optional frame)
  1279. "Return the attributes of the physical monitor dominating FRAME.
  1280. If FRAME is omitted or nil, describe the currently selected frame.
  1281. A frame is dominated by a physical monitor when either the
  1282. largest area of the frame resides in the monitor, or the monitor
  1283. is the closest to the frame if the frame does not intersect any
  1284. physical monitors.
  1285. See `display-monitor-attributes-list' for the list of attribute
  1286. keys and their meanings."
  1287. (or frame (setq frame (selected-frame)))
  1288. (cl-loop for attributes in (display-monitor-attributes-list frame)
  1289. for frames = (cdr (assq 'frames attributes))
  1290. if (memq frame frames) return attributes))
  1291. ;;;; Frame/display capabilities.
  1292. (declare-function msdos-mouse-p "dosfns.c")
  1293. (defun display-mouse-p (&optional display)
  1294. "Return non-nil if DISPLAY has a mouse available.
  1295. DISPLAY can be a display name, a frame, or nil (meaning the selected
  1296. frame's display)."
  1297. (let ((frame-type (framep-on-display display)))
  1298. (cond
  1299. ((eq frame-type 'pc)
  1300. (msdos-mouse-p))
  1301. ((eq frame-type 'w32)
  1302. (with-no-warnings
  1303. (> w32-num-mouse-buttons 0)))
  1304. ((memq frame-type '(x ns))
  1305. t) ;; We assume X and NeXTstep *always* have a pointing device
  1306. (t
  1307. (or (and (featurep 'xt-mouse)
  1308. xterm-mouse-mode)
  1309. ;; t-mouse is distributed with the GPM package. It doesn't have
  1310. ;; a toggle.
  1311. (featurep 't-mouse)
  1312. ;; No way to check whether a w32 console has a mouse, assume
  1313. ;; it always does.
  1314. (boundp 'w32-use-full-screen-buffer))))))
  1315. (defun display-popup-menus-p (&optional display)
  1316. "Return non-nil if popup menus are supported on DISPLAY.
  1317. DISPLAY can be a display name, a frame, or nil (meaning the selected
  1318. frame's display).
  1319. Support for popup menus requires that the mouse be available."
  1320. (display-mouse-p display))
  1321. (defun display-graphic-p (&optional display)
  1322. "Return non-nil if DISPLAY is a graphic display.
  1323. Graphical displays are those which are capable of displaying several
  1324. frames and several different fonts at once. This is true for displays
  1325. that use a window system such as X, and false for text-only terminals.
  1326. DISPLAY can be a display name, a frame, or nil (meaning the selected
  1327. frame's display)."
  1328. (not (null (memq (framep-on-display display) '(x w32 ns)))))
  1329. (defun display-images-p (&optional display)
  1330. "Return non-nil if DISPLAY can display images.
  1331. DISPLAY can be a display name, a frame, or nil (meaning the selected
  1332. frame's display)."
  1333. (and (display-graphic-p display)
  1334. (fboundp 'image-mask-p)
  1335. (fboundp 'image-size)))
  1336. (defalias 'display-multi-frame-p 'display-graphic-p)
  1337. (defalias 'display-multi-font-p 'display-graphic-p)
  1338. (defun display-selections-p (&optional display)
  1339. "Return non-nil if DISPLAY supports selections.
  1340. A selection is a way to transfer text or other data between programs
  1341. via special system buffers called `selection' or `clipboard'.
  1342. DISPLAY can be a display name, a frame, or nil (meaning the selected
  1343. frame's display)."
  1344. (let ((frame-type (framep-on-display display)))
  1345. (cond
  1346. ((eq frame-type 'pc)
  1347. ;; MS-DOS frames support selections when Emacs runs inside
  1348. ;; a Windows DOS Box.
  1349. (with-no-warnings
  1350. (not (null dos-windows-version))))
  1351. ((memq frame-type '(x w32 ns))
  1352. t)
  1353. (t
  1354. nil))))
  1355. (declare-function x-display-screens "xfns.c" (&optional terminal))
  1356. (defun display-screens (&optional display)
  1357. "Return the number of screens associated with DISPLAY.
  1358. DISPLAY should be either a frame or a display name (a string).
  1359. If DISPLAY is omitted or nil, it defaults to the selected frame's display."
  1360. (let ((frame-type (framep-on-display display)))
  1361. (cond
  1362. ((memq frame-type '(x w32 ns))
  1363. (x-display-screens display))
  1364. (t
  1365. 1))))
  1366. (declare-function x-display-pixel-height "xfns.c" (&optional terminal))
  1367. (defun display-pixel-height (&optional display)
  1368. "Return the height of DISPLAY's screen in pixels.
  1369. DISPLAY can be a display name or a frame.
  1370. If DISPLAY is omitted or nil, it defaults to the selected frame's display.
  1371. For character terminals, each character counts as a single pixel.
  1372. For graphical terminals, note that on \"multi-monitor\" setups this
  1373. refers to the pixel height for all physical monitors associated
  1374. with DISPLAY. To get information for each physical monitor, use
  1375. `display-monitor-attributes-list'."
  1376. (let ((frame-type (framep-on-display display)))
  1377. (cond
  1378. ((memq frame-type '(x w32 ns))
  1379. (x-display-pixel-height display))
  1380. (t
  1381. (frame-height (if (framep display) display (selected-frame)))))))
  1382. (declare-function x-display-pixel-width "xfns.c" (&optional terminal))
  1383. (defun display-pixel-width (&optional display)
  1384. "Return the width of DISPLAY's screen in pixels.
  1385. DISPLAY can be a display name or a frame.
  1386. If DISPLAY is omitted or nil, it defaults to the selected frame's display.
  1387. For character terminals, each character counts as a single pixel.
  1388. For graphical terminals, note that on \"multi-monitor\" setups this
  1389. refers to the pixel width for all physical monitors associated
  1390. with DISPLAY. To get information for each physical monitor, use
  1391. `display-monitor-attributes-list'."
  1392. (let ((frame-type (framep-on-display display)))
  1393. (cond
  1394. ((memq frame-type '(x w32 ns))
  1395. (x-display-pixel-width display))
  1396. (t
  1397. (frame-width (if (framep display) display (selected-frame)))))))
  1398. (defcustom display-mm-dimensions-alist nil
  1399. "Alist for specifying screen dimensions in millimeters.
  1400. The functions `display-mm-height' and `display-mm-width' consult
  1401. this list before asking the system.
  1402. Each element has the form (DISPLAY . (WIDTH . HEIGHT)), e.g.
  1403. \(\":0.0\" . (287 . 215)).
  1404. If `display' is t, it specifies dimensions for all graphical displays
  1405. not explicitly specified."
  1406. :version "22.1"
  1407. :type '(alist :key-type (choice (string :tag "Display name")
  1408. (const :tag "Default" t))
  1409. :value-type (cons :tag "Dimensions"
  1410. (integer :tag "Width")
  1411. (integer :tag "Height")))
  1412. :group 'frames)
  1413. (declare-function x-display-mm-height "xfns.c" (&optional terminal))
  1414. (defun display-mm-height (&optional display)
  1415. "Return the height of DISPLAY's screen in millimeters.
  1416. If the information is unavailable, this function returns nil.
  1417. DISPLAY can be a display name or a frame.
  1418. If DISPLAY is omitted or nil, it defaults to the selected frame's display.
  1419. You can override what the system thinks the result should be by
  1420. adding an entry to `display-mm-dimensions-alist'.
  1421. For graphical terminals, note that on \"multi-monitor\" setups this
  1422. refers to the height in millimeters for all physical monitors
  1423. associated with DISPLAY. To get information for each physical
  1424. monitor, use `display-monitor-attributes-list'."
  1425. (and (memq (framep-on-display display) '(x w32 ns))
  1426. (or (cddr (assoc (or display (frame-parameter nil 'display))
  1427. display-mm-dimensions-alist))
  1428. (cddr (assoc t display-mm-dimensions-alist))
  1429. (x-display-mm-height display))))
  1430. (declare-function x-display-mm-width "xfns.c" (&optional terminal))
  1431. (defun display-mm-width (&optional display)
  1432. "Return the width of DISPLAY's screen in millimeters.
  1433. If the information is unavailable, this function returns nil.
  1434. DISPLAY can be a display name or a frame.
  1435. If DISPLAY is omitted or nil, it defaults to the selected frame's display.
  1436. You can override what the system thinks the result should be by
  1437. adding an entry to `display-mm-dimensions-alist'.
  1438. For graphical terminals, note that on \"multi-monitor\" setups this
  1439. refers to the width in millimeters for all physical monitors
  1440. associated with DISPLAY. To get information for each physical
  1441. monitor, use `display-monitor-attributes-list'."
  1442. (and (memq (framep-on-display display) '(x w32 ns))
  1443. (or (cadr (assoc (or display (frame-parameter nil 'display))
  1444. display-mm-dimensions-alist))
  1445. (cadr (assoc t display-mm-dimensions-alist))
  1446. (x-display-mm-width display))))
  1447. (declare-function x-display-backing-store "xfns.c" (&optional terminal))
  1448. ;; In NS port, the return value may be `buffered', `retained', or
  1449. ;; `non-retained'. See src/nsfns.m.
  1450. (defun display-backing-store (&optional display)
  1451. "Return the backing store capability of DISPLAY's screen.
  1452. The value may be `always', `when-mapped', `not-useful', or nil if
  1453. the question is inapplicable to a certain kind of display.
  1454. DISPLAY can be a display name or a frame.
  1455. If DISPLAY is omitted or nil, it defaults to the selected frame's display."
  1456. (let ((frame-type (framep-on-display display)))
  1457. (cond
  1458. ((memq frame-type '(x w32 ns))
  1459. (x-display-backing-store display))
  1460. (t
  1461. 'not-useful))))
  1462. (declare-function x-display-save-under "xfns.c" (&optional terminal))
  1463. (defun display-save-under (&optional display)
  1464. "Return non-nil if DISPLAY's screen supports the SaveUnder feature.
  1465. DISPLAY can be a display name or a frame.
  1466. If DISPLAY is omitted or nil, it defaults to the selected frame's display."
  1467. (let ((frame-type (framep-on-display display)))
  1468. (cond
  1469. ((memq frame-type '(x w32 ns))
  1470. (x-display-save-under display))
  1471. (t
  1472. 'not-useful))))
  1473. (declare-function x-display-planes "xfns.c" (&optional terminal))
  1474. (defun display-planes (&optional display)
  1475. "Return the number of planes supported by DISPLAY.
  1476. DISPLAY can be a display name or a frame.
  1477. If DISPLAY is omitted or nil, it defaults to the selected frame's display."
  1478. (let ((frame-type (framep-on-display display)))
  1479. (cond
  1480. ((memq frame-type '(x w32 ns))
  1481. (x-display-planes display))
  1482. ((eq frame-type 'pc)
  1483. 4)
  1484. (t
  1485. (truncate (log (length (tty-color-alist)) 2))))))
  1486. (declare-function x-display-color-cells "xfns.c" (&optional terminal))
  1487. (defun display-color-cells (&optional display)
  1488. "Return the number of color cells supported by DISPLAY.
  1489. DISPLAY can be a display name or a frame.
  1490. If DISPLAY is omitted or nil, it defaults to the selected frame's display."
  1491. (let ((frame-type (framep-on-display display)))
  1492. (cond
  1493. ((memq frame-type '(x w32 ns))
  1494. (x-display-color-cells display))
  1495. ((eq frame-type 'pc)
  1496. 16)
  1497. (t
  1498. (tty-display-color-cells display)))))
  1499. (declare-function x-display-visual-class "xfns.c" (&optional terminal))
  1500. (defun display-visual-class (&optional display)
  1501. "Return the visual class of DISPLAY.
  1502. The value is one of the symbols `static-gray', `gray-scale',
  1503. `static-color', `pseudo-color', `true-color', or `direct-color'.
  1504. DISPLAY can be a display name or a frame.
  1505. If DISPLAY is omitted or nil, it defaults to the selected frame's display."
  1506. (let ((frame-type (framep-on-display display)))
  1507. (cond
  1508. ((memq frame-type '(x w32 ns))
  1509. (x-display-visual-class display))
  1510. ((and (memq frame-type '(pc t))
  1511. (tty-display-color-p display))
  1512. 'static-color)
  1513. (t
  1514. 'static-gray))))
  1515. (declare-function x-display-monitor-attributes-list "xfns.c"
  1516. (&optional terminal))
  1517. (declare-function w32-display-monitor-attributes-list "w32fns.c"
  1518. (&optional display))
  1519. (declare-function ns-display-monitor-attributes-list "nsfns.m"
  1520. (&optional terminal))
  1521. (defun display-monitor-attributes-list (&optional display)
  1522. "Return a list of physical monitor attributes on DISPLAY.
  1523. DISPLAY can be a display name, a terminal name, or a frame.
  1524. If DISPLAY is omitted or nil, it defaults to the selected frame's display.
  1525. Each element of the list represents the attributes of a physical
  1526. monitor. The first element corresponds to the primary monitor.
  1527. The attributes for a physical monitor are represented as an alist
  1528. of attribute keys and values as follows:
  1529. geometry -- Position and size in pixels in the form of (X Y WIDTH HEIGHT)
  1530. workarea -- Position and size of the work area in pixels in the
  1531. form of (X Y WIDTH HEIGHT)
  1532. mm-size -- Width and height in millimeters in the form of
  1533. (WIDTH HEIGHT)
  1534. frames -- List of frames dominated by the physical monitor
  1535. name (*) -- Name of the physical monitor as a string
  1536. source (*) -- Source of multi-monitor information as a string
  1537. where X, Y, WIDTH, and HEIGHT are integers. X and Y are coordinates
  1538. of the top-left corner, and might be negative for monitors other than
  1539. the primary one. Keys labeled with (*) are optional.
  1540. The \"work area\" is a measure of the \"usable\" display space.
  1541. It may be less than the total screen size, owing to space taken up
  1542. by window manager features (docks, taskbars, etc.). The precise
  1543. details depend on the platform and environment.
  1544. The `source' attribute describes the source from which the information
  1545. was obtained. On X, this may be one of: \"Gdk\", \"XRandr\", \"Xinerama\",
  1546. or \"fallback\".
  1547. A frame is dominated by a physical monitor when either the
  1548. largest area of the frame resides in the monitor, or the monitor
  1549. is the closest to the frame if the frame does not intersect any
  1550. physical monitors. Every (non-tooltip) frame (including invisible ones)
  1551. in a graphical display is dominated by exactly one physical
  1552. monitor at a time, though it can span multiple (or no) physical
  1553. monitors."
  1554. (let ((frame-type (framep-on-display display)))
  1555. (cond
  1556. ((eq frame-type 'x)
  1557. (x-display-monitor-attributes-list display))
  1558. ((eq frame-type 'w32)
  1559. (w32-display-monitor-attributes-list display))
  1560. ((eq frame-type 'ns)
  1561. (ns-display-monitor-attributes-list display))
  1562. (t
  1563. (let ((geometry (list 0 0 (display-pixel-width display)
  1564. (display-pixel-height display))))
  1565. `(((geometry . ,geometry)
  1566. (workarea . ,geometry)
  1567. (mm-size . (,(display-mm-width display)
  1568. ,(display-mm-height display)))
  1569. (frames . ,(frames-on-display-list display)))))))))
  1570. ;;;; Frame geometry values
  1571. (defun frame-geom-value-cons (type value &optional frame)
  1572. "Return equivalent geometry value for FRAME as a cons with car `+'.
  1573. A geometry value equivalent to VALUE for FRAME is returned,
  1574. where the value is a cons with car `+', not numeric.
  1575. TYPE is the car of the original geometry spec (TYPE . VALUE).
  1576. It is `top' or `left', depending on which edge VALUE is related to.
  1577. VALUE is the cdr of a frame geometry spec: (left/top . VALUE).
  1578. If VALUE is a number, then it is converted to a cons value, perhaps
  1579. relative to the opposite frame edge from that in the original spec.
  1580. FRAME defaults to the selected frame.
  1581. Examples (measures in pixels) -
  1582. Assuming display height/width=1024, frame height/width=600:
  1583. 300 inside display edge: 300 => (+ 300)
  1584. (+ 300) => (+ 300)
  1585. 300 inside opposite display edge: (- 300) => (+ 124)
  1586. -300 => (+ 124)
  1587. 300 beyond display edge
  1588. (= 724 inside opposite display edge): (+ -300) => (+ -300)
  1589. 300 beyond display edge
  1590. (= 724 inside opposite display edge): (- -300) => (+ 724)
  1591. In the 3rd, 4th, and 6th examples, the returned value is relative to
  1592. the opposite frame edge from the edge indicated in the input spec."
  1593. (cond ((and (consp value) (eq '+ (car value))) ; e.g. (+ 300), (+ -300)
  1594. value)
  1595. ((natnump value) (list '+ value)) ; e.g. 300 => (+ 300)
  1596. (t ; e.g. -300, (- 300), (- -300)
  1597. (list '+ (- (if (eq 'left type) ; => (+ 124), (+ 124), (+ 724)
  1598. (x-display-pixel-width)
  1599. (x-display-pixel-height))
  1600. (if (integerp value) (- value) (cadr value))
  1601. (if (eq 'left type)
  1602. (frame-pixel-width frame)
  1603. (frame-pixel-height frame)))))))
  1604. (defun frame-geom-spec-cons (spec &optional frame)
  1605. "Return equivalent geometry spec for FRAME as a cons with car `+'.
  1606. A geometry specification equivalent to SPEC for FRAME is returned,
  1607. where the value is a cons with car `+', not numeric.
  1608. SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE).
  1609. If VALUE is a number, then it is converted to a cons value, perhaps
  1610. relative to the opposite frame edge from that in the original spec.
  1611. FRAME defaults to the selected frame.
  1612. Examples (measures in pixels) -
  1613. Assuming display height=1024, frame height=600:
  1614. top 300 below display top: (top . 300) => (top + 300)
  1615. (top + 300) => (top + 300)
  1616. bottom 300 above display bottom: (top - 300) => (top + 124)
  1617. (top . -300) => (top + 124)
  1618. top 300 above display top
  1619. (= bottom 724 above display bottom): (top + -300) => (top + -300)
  1620. bottom 300 below display bottom
  1621. (= top 724 below display top): (top - -300) => (top + 724)
  1622. In the 3rd, 4th, and 6th examples, the returned value is relative to
  1623. the opposite frame edge from the edge indicated in the input spec."
  1624. (cons (car spec) (frame-geom-value-cons (car spec) (cdr spec) frame)))
  1625. (defun delete-other-frames (&optional frame)
  1626. "Delete all frames on the current terminal, except FRAME.
  1627. If FRAME uses another frame's minibuffer, the minibuffer frame is
  1628. left untouched. FRAME nil or omitted means use the selected frame."
  1629. (interactive)
  1630. (unless frame
  1631. (setq frame (selected-frame)))
  1632. (let* ((mini-frame (window-frame (minibuffer-window frame)))
  1633. (frames (delq mini-frame (delq frame (frame-list)))))
  1634. ;; Only consider frames on the same terminal.
  1635. (dolist (frame (prog1 frames (setq frames nil)))
  1636. (if (eq (frame-terminal) (frame-terminal frame))
  1637. (push frame frames)))
  1638. ;; Delete mon-minibuffer-only frames first, because `delete-frame'
  1639. ;; signals an error when trying to delete a mini-frame that's
  1640. ;; still in use by another frame.
  1641. (dolist (frame frames)
  1642. (unless (eq (frame-parameter frame 'minibuffer) 'only)
  1643. (delete-frame frame)))
  1644. ;; Delete minibuffer-only frames.
  1645. (dolist (frame frames)
  1646. (when (eq (frame-parameter frame 'minibuffer) 'only)
  1647. (delete-frame frame)))))
  1648. ;; miscellaneous obsolescence declarations
  1649. (define-obsolete-variable-alias 'delete-frame-hook
  1650. 'delete-frame-functions "22.1")
  1651. ;;; Window dividers.
  1652. (defgroup window-divider nil
  1653. "Window dividers."
  1654. :version "25.1"
  1655. :group 'frames
  1656. :group 'windows)
  1657. (defcustom window-divider-default-places 'right-only
  1658. "Default positions of window dividers.
  1659. Possible values are `bottom-only' (dividers on the bottom of each
  1660. window only), `right-only' (dividers on the right of each window
  1661. only), and t (dividers on the bottom and on the right of each
  1662. window). The default is `right-only'.
  1663. The value takes effect if and only if dividers are enabled by
  1664. `window-divider-mode'.
  1665. To position dividers on frames individually, use the frame
  1666. parameters `bottom-divider-width' and `right-divider-width'."
  1667. :type '(choice (const :tag "Bottom only" bottom-only)
  1668. (const :tag "Right only" right-only)
  1669. (const :tag "Bottom and right" t))
  1670. :initialize 'custom-initialize-default
  1671. :set (lambda (symbol value)
  1672. (set-default symbol value)
  1673. (when window-divider-mode
  1674. (window-divider-mode-apply t)))
  1675. :version "25.1")
  1676. (defun window-divider-width-valid-p (value)
  1677. "Return non-nil if VALUE is a positive number."
  1678. (and (numberp value) (> value 0)))
  1679. (defcustom window-divider-default-bottom-width 6
  1680. "Default width of dividers on bottom of windows.
  1681. The value must be a positive integer and takes effect when bottom
  1682. dividers are displayed by `window-divider-mode'.
  1683. To adjust bottom dividers for frames individually, use the frame
  1684. parameter `bottom-divider-width'."
  1685. :type '(restricted-sexp
  1686. :tag "Default width of bottom dividers"
  1687. :match-alternatives (frame-window-divider-width-valid-p))
  1688. :initialize 'custom-initialize-default
  1689. :set (lambda (symbol value)
  1690. (set-default symbol value)
  1691. (when window-divider-mode
  1692. (window-divider-mode-apply t)))
  1693. :version "25.1")
  1694. (defcustom window-divider-default-right-width 6
  1695. "Default width of dividers on the right of windows.
  1696. The value must be a positive integer and takes effect when right
  1697. dividers are displayed by `window-divider-mode'.
  1698. To adjust right dividers for frames individually, use the frame
  1699. parameter `right-divider-width'."
  1700. :type '(restricted-sexp
  1701. :tag "Default width of right dividers"
  1702. :match-alternatives (frame-window-divider-width-valid-p))
  1703. :initialize 'custom-initialize-default
  1704. :set (lambda (symbol value)
  1705. (set-default symbol value)
  1706. (when window-divider-mode
  1707. (window-divider-mode-apply t)))
  1708. :version "25.1")
  1709. (defun window-divider-mode-apply (enable)
  1710. "Apply window divider places and widths to all frames.
  1711. If ENABLE is nil, apply default places and widths. Else reset
  1712. all divider widths to zero."
  1713. (let ((bottom (if (and enable
  1714. (memq window-divider-default-places
  1715. '(bottom-only t)))
  1716. window-divider-default-bottom-width
  1717. 0))
  1718. (right (if (and enable
  1719. (memq window-divider-default-places
  1720. '(right-only t)))
  1721. window-divider-default-right-width
  1722. 0)))
  1723. (modify-all-frames-parameters
  1724. (list (cons 'bottom-divider-width bottom)
  1725. (cons 'right-divider-width right)))
  1726. (setq default-frame-alist
  1727. (assq-delete-all
  1728. 'bottom-divider-width default-frame-alist))
  1729. (setq default-frame-alist
  1730. (assq-delete-all
  1731. 'right-divider-width default-frame-alist))
  1732. (when (> bottom 0)
  1733. (setq default-frame-alist
  1734. (cons
  1735. (cons 'bottom-divider-width bottom)
  1736. default-frame-alist)))
  1737. (when (> right 0)
  1738. (setq default-frame-alist
  1739. (cons
  1740. (cons 'right-divider-width right)
  1741. default-frame-alist)))))
  1742. (define-minor-mode window-divider-mode
  1743. "Display dividers between windows (Window Divider mode).
  1744. With a prefix argument ARG, enable Window Divider mode if ARG is
  1745. positive, and disable it otherwise. If called from Lisp, enable
  1746. the mode if ARG is omitted or nil.
  1747. The option `window-divider-default-places' specifies on which
  1748. side of a window dividers are displayed. The options
  1749. `window-divider-default-bottom-width' and
  1750. `window-divider-default-right-width' specify their respective
  1751. widths."
  1752. :group 'window-divider
  1753. :global t
  1754. (window-divider-mode-apply window-divider-mode))
  1755. ;; Blinking cursor
  1756. (defgroup cursor nil
  1757. "Displaying text cursors."
  1758. :version "21.1"
  1759. :group 'frames)
  1760. (defcustom blink-cursor-delay 0.5
  1761. "Seconds of idle time after which cursor starts to blink."
  1762. :type 'number
  1763. :group 'cursor)
  1764. (defcustom blink-cursor-interval 0.5
  1765. "Length of cursor blink interval in seconds."
  1766. :type 'number
  1767. :group 'cursor)
  1768. (defcustom blink-cursor-blinks 10
  1769. "How many times to blink before using a solid cursor on NS, X, and MS-Windows.
  1770. Use 0 or negative value to blink forever."
  1771. :version "24.4"
  1772. :type 'integer
  1773. :group 'cursor)
  1774. (defvar blink-cursor-blinks-done 1
  1775. "Number of blinks done since we started blinking on NS, X, and MS-Windows.")
  1776. (defvar blink-cursor-idle-timer nil
  1777. "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
  1778. The function `blink-cursor-start' is called when the timer fires.")
  1779. (defvar blink-cursor-timer nil
  1780. "Timer started from `blink-cursor-start'.
  1781. This timer calls `blink-cursor-timer-function' every
  1782. `blink-cursor-interval' seconds.")
  1783. (defun blink-cursor-start ()
  1784. "Timer function called from the timer `blink-cursor-idle-timer'.
  1785. This starts the timer `blink-cursor-timer', which makes the cursor blink
  1786. if appropriate. It also arranges to cancel that timer when the next
  1787. command starts, by installing a pre-command hook."
  1788. (when (null blink-cursor-timer)
  1789. ;; Set up the timer first, so that if this signals an error,
  1790. ;; blink-cursor-end is not added to pre-command-hook.
  1791. (setq blink-cursor-blinks-done 1)
  1792. (setq blink-cursor-timer
  1793. (run-with-timer blink-cursor-interval blink-cursor-interval
  1794. 'blink-cursor-timer-function))
  1795. (add-hook 'pre-command-hook 'blink-cursor-end)
  1796. (internal-show-cursor nil nil)))
  1797. (defun blink-cursor-timer-function ()
  1798. "Timer function of timer `blink-cursor-timer'."
  1799. (internal-show-cursor nil (not (internal-show-cursor-p)))
  1800. ;; Suspend counting blinks when the w32 menu-bar menu is displayed,
  1801. ;; since otherwise menu tooltips will behave erratically.
  1802. (or (and (fboundp 'w32--menu-bar-in-use)
  1803. (w32--menu-bar-in-use))
  1804. (setq blink-cursor-blinks-done (1+ blink-cursor-blinks-done)))
  1805. ;; Each blink is two calls to this function.
  1806. (when (and (> blink-cursor-blinks 0)
  1807. (<= (* 2 blink-cursor-blinks) blink-cursor-blinks-done))
  1808. (blink-cursor-suspend)
  1809. (add-hook 'post-command-hook 'blink-cursor-check)))
  1810. (defun blink-cursor-end ()
  1811. "Stop cursor blinking.
  1812. This is installed as a pre-command hook by `blink-cursor-start'.
  1813. When run, it cancels the timer `blink-cursor-timer' and removes
  1814. itself as a pre-command hook."
  1815. (remove-hook 'pre-command-hook 'blink-cursor-end)
  1816. (internal-show-cursor nil t)
  1817. (when blink-cursor-timer
  1818. (cancel-timer blink-cursor-timer)
  1819. (setq blink-cursor-timer nil)))
  1820. (defun blink-cursor-suspend ()
  1821. "Suspend cursor blinking.
  1822. This is called when no frame has focus and timers can be suspended.
  1823. Timers are restarted by `blink-cursor-check', which is called when a
  1824. frame receives focus."
  1825. (blink-cursor-end)
  1826. (when blink-cursor-idle-timer
  1827. (cancel-timer blink-cursor-idle-timer)
  1828. (setq blink-cursor-idle-timer nil)))
  1829. (defun blink-cursor-check ()
  1830. "Check if cursor blinking shall be restarted.
  1831. This is done when a frame gets focus. Blink timers may be stopped by
  1832. `blink-cursor-suspend'."
  1833. (when (and blink-cursor-mode
  1834. (not blink-cursor-idle-timer))
  1835. (remove-hook 'post-command-hook 'blink-cursor-check)
  1836. (setq blink-cursor-idle-timer
  1837. (run-with-idle-timer blink-cursor-delay
  1838. blink-cursor-delay
  1839. 'blink-cursor-start))))
  1840. (define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1")
  1841. (define-minor-mode blink-cursor-mode
  1842. "Toggle cursor blinking (Blink Cursor mode).
  1843. With a prefix argument ARG, enable Blink Cursor mode if ARG is
  1844. positive, and disable it otherwise. If called from Lisp, enable
  1845. the mode if ARG is omitted or nil.
  1846. If the value of `blink-cursor-blinks' is positive (10 by default),
  1847. the cursor stops blinking after that number of blinks, if Emacs
  1848. gets no input during that time.
  1849. See also `blink-cursor-interval' and `blink-cursor-delay'.
  1850. This command is effective only on graphical frames. On text-only
  1851. terminals, cursor blinking is controlled by the terminal."
  1852. :init-value (not (or noninteractive
  1853. no-blinking-cursor
  1854. (eq system-type 'ms-dos)
  1855. (not (memq window-system '(x w32 ns)))))
  1856. :initialize 'custom-initialize-delay
  1857. :group 'cursor
  1858. :global t
  1859. (blink-cursor-suspend)
  1860. (remove-hook 'focus-in-hook #'blink-cursor-check)
  1861. (remove-hook 'focus-out-hook #'blink-cursor-suspend)
  1862. (when blink-cursor-mode
  1863. (add-hook 'focus-in-hook #'blink-cursor-check)
  1864. (add-hook 'focus-out-hook #'blink-cursor-suspend)
  1865. (setq blink-cursor-idle-timer
  1866. (run-with-idle-timer blink-cursor-delay
  1867. blink-cursor-delay
  1868. #'blink-cursor-start))))
  1869. ;; Frame maximization/fullscreen
  1870. (defun toggle-frame-maximized ()
  1871. "Toggle maximization state of selected frame.
  1872. Maximize selected frame or un-maximize if it is already maximized.
  1873. If the frame is in fullscreen state, don't change its state, but
  1874. set the frame's `fullscreen-restore' parameter to `maximized', so
  1875. the frame will be maximized after disabling fullscreen state.
  1876. Note that with some window managers you may have to set
  1877. `frame-resize-pixelwise' to non-nil in order to make a frame
  1878. appear truly maximized. In addition, you may have to set
  1879. `x-frame-normalize-before-maximize' in order to enable
  1880. transitions from one fullscreen state to another.
  1881. See also `toggle-frame-fullscreen'."
  1882. (interactive)
  1883. (let ((fullscreen (frame-parameter nil 'fullscreen)))
  1884. (cond
  1885. ((memq fullscreen '(fullscreen fullboth))
  1886. (set-frame-parameter nil 'fullscreen-restore 'maximized))
  1887. ((eq fullscreen 'maximized)
  1888. (set-frame-parameter nil 'fullscreen nil))
  1889. (t
  1890. (set-frame-parameter nil 'fullscreen 'maximized)))))
  1891. (defun toggle-frame-fullscreen ()
  1892. "Toggle fullscreen state of selected frame.
  1893. Make selected frame fullscreen or restore its previous size if it
  1894. is already fullscreen.
  1895. Before making the frame fullscreen remember the current value of
  1896. the frame's `fullscreen' parameter in the `fullscreen-restore'
  1897. parameter of the frame. That value is used to restore the
  1898. frame's fullscreen state when toggling fullscreen the next time.
  1899. Note that with some window managers you may have to set
  1900. `frame-resize-pixelwise' to non-nil in order to make a frame
  1901. appear truly fullscreen. In addition, you may have to set
  1902. `x-frame-normalize-before-maximize' in order to enable
  1903. transitions from one fullscreen state to another.
  1904. See also `toggle-frame-maximized'."
  1905. (interactive)
  1906. (let ((fullscreen (frame-parameter nil 'fullscreen)))
  1907. (if (memq fullscreen '(fullscreen fullboth))
  1908. (let ((fullscreen-restore (frame-parameter nil 'fullscreen-restore)))
  1909. (if (memq fullscreen-restore '(maximized fullheight fullwidth))
  1910. (set-frame-parameter nil 'fullscreen fullscreen-restore)
  1911. (set-frame-parameter nil 'fullscreen nil)))
  1912. (modify-frame-parameters
  1913. nil `((fullscreen . fullboth) (fullscreen-restore . ,fullscreen))))))
  1914. ;;;; Key bindings
  1915. (define-key ctl-x-5-map "2" 'make-frame-command)
  1916. (define-key ctl-x-5-map "1" 'delete-other-frames)
  1917. (define-key ctl-x-5-map "0" 'delete-frame)
  1918. (define-key ctl-x-5-map "o" 'other-frame)
  1919. (define-key global-map [f11] 'toggle-frame-fullscreen)
  1920. (define-key global-map [(meta f10)] 'toggle-frame-maximized)
  1921. (define-key esc-map [f10] 'toggle-frame-maximized)
  1922. ;; Misc.
  1923. ;; Only marked as obsolete in 24.3.
  1924. (define-obsolete-variable-alias 'automatic-hscrolling
  1925. 'auto-hscroll-mode "22.1")
  1926. (make-variable-buffer-local 'show-trailing-whitespace)
  1927. ;; Defined in dispnew.c.
  1928. (make-obsolete-variable
  1929. 'window-system-version "it does not give useful information." "24.3")
  1930. (provide 'frame)
  1931. ;;; frame.el ends here