From: Chong Yidong Date: Sun, 27 Jun 2010 00:30:52 +0000 (-0400) Subject: Change default-frame-alist and menu/tool-bar-mode interaction (Bug#2249). X-Git-Tag: emacs-pretest-24.0.90~104^2~275^2~438^2~51^2~109 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6431f2e619d1ce4cff097a3837f6b9e931f1f61a;p=emacs.git Change default-frame-alist and menu/tool-bar-mode interaction (Bug#2249). Don't add entries for `menu-bar-lines' and `tool-bar-lines' to `default-frame-alist' and `initial-frame-alist' at startup. Instead, use X resources to update the `menu-bar-mode' and `tool-bar-mode' variables at startup, and use them as defaults during frame creation. * lisp/frame.el (frame-notice-user-settings): Don't change default-frame-alist based on menu-bar-mode and tool-bar-mode, or vice versa. * lisp/menu-bar.el (menu-bar-mode): * lisp/tool-bar.el (tool-bar-mode): Don't change default-frame-alist. Set init-value to t. * lisp/startup.el (command-line): Use X resources to set the value of menu-bar-mode and tool-bar-mode, before calling frame-initialize. * src/frame.c (Vmenu_bar_mode, Vtool_bar_mode): New vars. * src/w32fns.c (Fx_create_frame): * src/nsfns.m (Fx_create_frame): Likewise. * src/xfns.c (Fx_create_frame): Don't consult X resouces when setting menu-bar-lines and tool-bar-lines. Use menu-bar-mode and tool-bar-mode, which are now set using these X resources at startup, to determine the defaults. --- diff --git a/etc/NEWS b/etc/NEWS index 122bd27d805..ef791281671 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -275,6 +275,15 @@ programmer-visible consequences. ** Passing a nil argument to a minor mode function now turns the mode ON unconditionally. + +** During startup, Emacs no longer adds entries for `menu-bar-lines' +and `tool-bar-lines' to `default-frame-alist' and +`initial-frame-alist'. With these alist entries omitted, `make-frame' +checks the value of the variable `menu-bar-mode'/`tool-bar-mode' to +determine whether to create a menu-bar or tool-bar, respectively. +If the alist entries are added, they override the value of +`menu-bar-mode'/`tool-bar-mode'. + * Lisp changes in Emacs 24.1 diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0b1fa599c62..d4862e17a73 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,16 @@ +2010-06-27 Chong Yidong + + * startup.el (command-line): Use X resources to set the value of + menu-bar-mode and tool-bar-mode, before calling frame-initialize. + + * menu-bar.el (menu-bar-mode): + * tool-bar.el (tool-bar-mode): Don't change default-frame-alist. + Set init-value to t. + + * frame.el (frame-notice-user-settings): Don't change + default-frame-alist based on menu-bar-mode and tool-bar-mode, or + vice versa (Bug#2249). + 2010-06-26 Eli Zaretskii * w32-fns.el (w32-convert-standard-filename): Doc fix. diff --git a/lisp/frame.el b/lisp/frame.el index 7456db4021c..de33715aed4 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -39,13 +39,6 @@ as its argument.") (defvar window-system-default-frame-alist nil "Alist of window-system dependent default frame parameters. -You can set this in your init file; for example, - - ;; Disable menubar and toolbar on the console, but enable them under X. - (setq window-system-default-frame-alist - '((x (menu-bar-lines . 1) (tool-bar-lines . 1)) - (nil (menu-bar-lines . 0) (tool-bar-lines . 0)))) - Parameters specified here supersede the values given in `default-frame-alist'.") @@ -287,36 +280,6 @@ and (cdr ARGS) as second." React to settings of `initial-frame-alist', `window-system-default-frame-alist' and `default-frame-alist' there (in decreasing order of priority)." - ;; Make menu-bar-mode and default-frame-alist consistent. - (when (boundp 'menu-bar-mode) - (let ((default (assq 'menu-bar-lines default-frame-alist))) - (if default - (setq menu-bar-mode (not (eq (cdr default) 0))) - (setq default-frame-alist - (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0)) - default-frame-alist))))) - - ;; Make tool-bar-mode and default-frame-alist consistent. Don't do - ;; it in batch mode since that would leave a tool-bar-lines - ;; parameter in default-frame-alist in a dumped Emacs, which is not - ;; what we want. - (when (and (boundp 'tool-bar-mode) - (not noninteractive)) - (let ((default (assq 'tool-bar-lines default-frame-alist))) - (if default - (setq tool-bar-mode (not (eq (cdr default) 0))) - ;; If Emacs was started on a tty, changing default-frame-alist - ;; would disable the toolbar on X frames created later. We - ;; want to keep the default of showing a toolbar under X even - ;; in this case. - ;; - ;; If the user explicitly called `tool-bar-mode' in .emacs, - ;; then default-frame-alist is already changed anyway. - (when initial-window-system - (setq default-frame-alist - (cons (cons 'tool-bar-lines (if tool-bar-mode 1 0)) - default-frame-alist)))))) - ;; Creating and deleting frames may shift the selected frame around, ;; and thus the current buffer. Protect against that. We don't ;; want to use save-excursion here, because that may also try to set diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 903bea36044..20ad50c9048 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -1924,28 +1924,20 @@ Buffers menu is regenerated." `(menu-item ,(purecopy "Previous History Item") previous-history-element :help ,(purecopy "Put previous minibuffer history element in the minibuffer")))) -;;;###autoload -;; This comment is taken from tool-bar.el near -;; (put 'tool-bar-mode ...) -;; We want to pretend the menu bar by standard is on, as this will make -;; customize consider disabling the menu bar a customization, and save -;; that. We could do this for real by setting :init-value below, but -;; that would overwrite disabling the tool bar from X resources. -(put 'menu-bar-mode 'standard-value '(t)) - (define-minor-mode menu-bar-mode "Toggle display of a menu bar on each frame. This command applies to all frames that exist and frames to be created in the future. With a numeric argument, if the argument is positive, turn on menu bars; otherwise, turn off menu bars." - :init-value nil + :init-value t :global t :group 'frames - ;; Make menu-bar-mode and default-frame-alist consistent. - (modify-all-frames-parameters (list (cons 'menu-bar-lines - (if menu-bar-mode 1 0)))) + ;; Turn the menu-bars on all frames on or off. + (let ((val (if menu-bar-mode 1 0))) + (dolist (frame (frame-list)) + (set-frame-parameter frame 'menu-bar-lines val))) ;; Make the message appear when Emacs is idle. We can not call message ;; directly. The minor-mode message "Menu-bar mode disabled" comes diff --git a/lisp/startup.el b/lisp/startup.el index 71857076d4f..67ebf47c5dd 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -878,10 +878,32 @@ opening the first frame (e.g. open a connection to an X server).") (run-hooks 'before-init-hook) - ;; Under X Window, this creates the X frame and deletes the terminal frame. + ;; Under X, this creates the X frame and deletes the terminal frame. (unless (daemonp) + ;; Enable or disable the tool-bar and menu-bar. + ;; While we're at it, set `no-blinking-cursor' too. + (cond + ((or noninteractive emacs-basic-display) + (setq menu-bar-mode nil + tool-bar-mode nil + no-blinking-cursor t)) + ;; Check X resources if available. + ((memq initial-window-system '(x w32 ns)) + (let ((no-vals '("no" "off" "false"))) + (if (member (x-get-resource "menuBar" "MenuBar") no-vals) + (setq menu-bar-mode nil)) + (if (member (x-get-resource "toolBar" "ToolBar") no-vals) + (setq tool-bar-mode nil)) + (if (member (x-get-resource "cursorBlink" "CursorBlink") + no-vals) + (setq no-blinking-cursor t))))) (frame-initialize)) + ;; Set up the tool-bar (even in tty frames, since Emacs might open a + ;; graphical frame later). + (unless noninteractive + (tool-bar-setup)) + ;; Turn off blinking cursor if so specified in X resources. This is here ;; only because all other settings of no-blinking-cursor are here. (unless (or noninteractive @@ -891,25 +913,6 @@ opening the first frame (e.g. open a connection to an X server).") '("off" "false"))))) (setq no-blinking-cursor t)) - ;; If frame was created with a menu bar, set menu-bar-mode on. - (unless (or noninteractive - emacs-basic-display - (and (memq initial-window-system '(x w32)) - (<= (frame-parameter nil 'menu-bar-lines) 0))) - (menu-bar-mode 1)) - - (unless (or noninteractive (not (fboundp 'tool-bar-mode))) - ;; Set up the tool-bar. Do this even in tty frames, so that there - ;; is a tool-bar if Emacs later opens a graphical frame. - (if (or emacs-basic-display - (and (numberp (frame-parameter nil 'tool-bar-lines)) - (<= (frame-parameter nil 'tool-bar-lines) 0))) - ;; On a graphical display with the toolbar disabled via X - ;; resources, set up the toolbar without enabling it. - (tool-bar-setup) - ;; Otherwise, enable tool-bar-mode. - (tool-bar-mode 1))) - ;; Re-evaluate predefined variables whose initial value depends on ;; the runtime context. (mapc 'custom-reevaluate-setting diff --git a/lisp/tool-bar.el b/lisp/tool-bar.el index a05d05daeb9..eaa8551b019 100644 --- a/lisp/tool-bar.el +++ b/lisp/tool-bar.el @@ -48,21 +48,17 @@ With numeric ARG, display the tool bar if and only if ARG is positive. See `tool-bar-add-item' and `tool-bar-add-item-from-menu' for conveniently adding tool bar items." - :init-value nil + :init-value t :global t :group 'mouse :group 'frames - (if tool-bar-mode - (progn - ;; Make one tool-bar-line for any - including non-graphical - - ;; terminal, see Bug#1754. If this causes problems, we should - ;; handle the problem in `modify-frame-parameters' or do not - ;; call `modify-all-frames-parameters' when toggling the tool - ;; bar off either. - (modify-all-frames-parameters (list (cons 'tool-bar-lines 1))) - (if (= 1 (length (default-value 'tool-bar-map))) ; not yet setup - (tool-bar-setup))) - (modify-all-frames-parameters (list (cons 'tool-bar-lines 0))))) + ;; Make tool-bar even if terminal is non-graphical (Bug#1754). + (let ((val (if tool-bar-mode 1 0))) + (dolist (frame (frame-list)) + (set-frame-parameter frame 'tool-bar-lines val))) + (when tool-bar-mode + (if (= 1 (length (default-value 'tool-bar-map))) ; not yet setup + (tool-bar-setup)))) ;;;###autoload ;; Used in the Show/Hide menu, to have the toggle reflect the current frame. @@ -74,17 +70,6 @@ See `tool-bar-mode' for more information." (tool-bar-mode (if (> (frame-parameter nil 'tool-bar-lines) 0) 0 1)) (tool-bar-mode arg))) -;;;###autoload -;; We want to pretend the toolbar by standard is on, as this will make -;; customize consider disabling the toolbar a customization, and save -;; that. We could do this for real by setting :init-value above, but -;; that would turn on the toolbar in MS Windows where it is currently -;; useless, and it would overwrite disabling the tool bar from X -;; resources. If anyone want to implement this in a cleaner way, -;; please do so. -;; -- Per Abrahamsen 2002-02-21. -(put 'tool-bar-mode 'standard-value '(t)) - (defvar tool-bar-map (make-sparse-keymap) "Keymap for the tool bar. Define this locally to override the global tool bar.") diff --git a/src/ChangeLog b/src/ChangeLog index 9777ab2202b..a7de72e3f95 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2010-06-27 Chong Yidong + + * xfns.c (Fx_create_frame): Don't consult X resouces when setting + menu-bar-lines and tool-bar-lines. Use menu-bar-mode and + tool-bar-mode, which are now set using these X resources at + startup, to determine the defaults (Bug#2249). + + * w32fns.c (Fx_create_frame): + * nsfns.m (Fx_create_frame): Likewise. + + * frame.c (Vmenu_bar_mode, Vtool_bar_mode): New vars. + 2010-06-24 Juanma Barranquero * gtkutil.c (xg_update_scrollbar_pos): diff --git a/src/frame.c b/src/frame.c index 3e1b2daf556..f542595e5f5 100644 --- a/src/frame.c +++ b/src/frame.c @@ -119,6 +119,7 @@ Lisp_Object Qtitle, Qname; Lisp_Object Qexplicit_name; Lisp_Object Qunsplittable; Lisp_Object Qmenu_bar_lines, Qtool_bar_lines; +Lisp_Object Vmenu_bar_mode, Vtool_bar_mode; Lisp_Object Qleft_fringe, Qright_fringe; Lisp_Object Qbuffer_predicate, Qbuffer_list, Qburied_buffer_list; Lisp_Object Qtty_color_mode; @@ -4648,6 +4649,14 @@ recursively). */); Qdelete_frame_functions = intern_c_string ("delete-frame-functions"); staticpro (&Qdelete_frame_functions); + DEFVAR_LISP ("menu-bar-mode", &Vmenu_bar_mode, + doc: /* Non-nil if Menu-Bar mode is enabled. */); + Vmenu_bar_mode = Qt; + + DEFVAR_LISP ("tool-bar-mode", &Vtool_bar_mode, + doc: /* Non-nil if Tool-Bar mode is enabled. */); + Vtool_bar_mode = Qt; + DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame, doc: /* Minibufferless frames use this frame's minibuffer. diff --git a/src/nsfns.m b/src/nsfns.m index 53264a5f595..d05fcf451e7 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -1234,10 +1234,18 @@ be shared by the new frame. */) init_frame_faces (f); - x_default_parameter (f, parms, Qmenu_bar_lines, make_number (0), "menuBar", - "menuBar", RES_TYPE_NUMBER); - x_default_parameter (f, parms, Qtool_bar_lines, make_number (0), "toolBar", - "toolBar", RES_TYPE_NUMBER); + /* The X resources controlling the menu-bar and tool-bar are + processed specially at startup, and reflected in the mode + variables; ignore them here. */ + x_default_parameter (f, parms, Qmenu_bar_lines, + NILP (Vmenu_bar_mode) + ? make_number (0) : make_number (1), + NULL, NULL, RES_TYPE_NUMBER); + x_default_parameter (f, parms, Qtool_bar_lines, + NILP (Vtool_bar_mode) + ? make_number (0) : make_number (1), + NULL, NULL, RES_TYPE_NUMBER); + x_default_parameter (f, parms, Qbuffer_predicate, Qnil, "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL); x_default_parameter (f, parms, Qtitle, Qnil, "title", "Title", diff --git a/src/w32fns.c b/src/w32fns.c index bc310da0d2f..f498539a568 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -290,6 +290,7 @@ static unsigned menu_free_timer = 0; /* The below are defined in frame.c. */ +extern Lisp_Object Vmenu_bar_mode, Vtool_bar_mode; extern Lisp_Object Vwindow_system_version; #ifdef GLYPH_DEBUG @@ -4462,10 +4463,17 @@ This function is an internal primitive--use `make-frame' instead. */) happen. */ init_frame_faces (f); - x_default_parameter (f, parameters, Qmenu_bar_lines, make_number (1), - "menuBar", "MenuBar", RES_TYPE_NUMBER); - x_default_parameter (f, parameters, Qtool_bar_lines, make_number (1), - "toolBar", "ToolBar", RES_TYPE_NUMBER); + /* The X resources controlling the menu-bar and tool-bar are + processed specially at startup, and reflected in the mode + variables; ignore them here. */ + x_default_parameter (f, parameters, Qmenu_bar_lines, + NILP (Vmenu_bar_mode) + ? make_number (0) : make_number (1), + NULL, NULL, RES_TYPE_NUMBER); + x_default_parameter (f, parameters, Qtool_bar_lines, + NILP (Vtool_bar_mode) + ? make_number (0) : make_number (1), + NULL, NULL, RES_TYPE_NUMBER); x_default_parameter (f, parameters, Qbuffer_predicate, Qnil, "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL); diff --git a/src/xfns.c b/src/xfns.c index 4f9afeef6cc..516aaaffc93 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -204,6 +204,8 @@ extern Lisp_Object Vsystem_name; /* The below are defined in frame.c. */ +extern Lisp_Object Vmenu_bar_mode, Vtool_bar_mode; + #if GLYPH_DEBUG int image_cache_refcount, dpyinfo_refcount; #endif @@ -3450,10 +3452,18 @@ This function is an internal primitive--use `make-frame' instead. */) happen. */ init_frame_faces (f); - x_default_parameter (f, parms, Qmenu_bar_lines, make_number (1), - "menuBar", "MenuBar", RES_TYPE_BOOLEAN_NUMBER); - x_default_parameter (f, parms, Qtool_bar_lines, make_number (1), - "toolBar", "ToolBar", RES_TYPE_NUMBER); + /* The X resources controlling the menu-bar and tool-bar are + processed specially at startup, and reflected in the mode + variables; ignore them here. */ + x_default_parameter (f, parms, Qmenu_bar_lines, + NILP (Vmenu_bar_mode) + ? make_number (0) : make_number (1), + NULL, NULL, RES_TYPE_NUMBER); + x_default_parameter (f, parms, Qtool_bar_lines, + NILP (Vtool_bar_mode) + ? make_number (0) : make_number (1), + NULL, NULL, RES_TYPE_NUMBER); + x_default_parameter (f, parms, Qbuffer_predicate, Qnil, "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL);