From 6415adea49a7ca96e6cfcf63c96cb0857de97f75 Mon Sep 17 00:00:00 2001 From: Richard Kim Date: Sun, 7 Aug 2022 07:19:17 -0700 Subject: [PATCH] Fixed #15583 and also bound SPC T g to toggle gui elements --- core/core-early-funcs.el | 23 ++++++++++--------- core/core-spacemacs.el | 2 +- early-init.el | 16 +++++++++---- .../spacemacs-defaults/keybindings.el | 7 ++++++ 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/core/core-early-funcs.el b/core/core-early-funcs.el index 8fa46c9242de..d8f209af4393 100644 --- a/core/core-early-funcs.el +++ b/core/core-early-funcs.el @@ -22,18 +22,19 @@ ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . -(defun spacemacs/removes-gui-elements () - "Remove the menu bar, tool bar and scroll bars." - ;; removes the GUI elements - (when (and (fboundp 'scroll-bar-mode) (not (eq scroll-bar-mode -1))) - (scroll-bar-mode -1)) - (when (and (fboundp 'tool-bar-mode) (not (eq tool-bar-mode -1))) - (tool-bar-mode -1)) +(defun spacemacs//toggle-gui-elements (&optional on-off) + "Toggle menu bar, tool bar, scroll bars, and tool tip modes. If +optional ON-OFF is not specified, then toggle on/off state. If +ON-OFF is 0 or 1, then turn gui elements OFF or ON respectively." + (when (fboundp 'scroll-bar-mode) + (scroll-bar-mode (or on-off (not scroll-bar-mode)))) + (when (fboundp 'tool-bar-mode) + (tool-bar-mode (or on-off (not tool-bar-mode)))) (unless (memq (window-system) '(mac ns)) - (when (and (fboundp 'menu-bar-mode) (not (eq menu-bar-mode -1))) - (menu-bar-mode -1))) + (when (fboundp 'menu-bar-mode) + (menu-bar-mode (or on-off (not menu-bar-mode))))) ;; tooltips in echo-aera - (when (and (fboundp 'tooltip-mode) (not (eq tooltip-mode -1))) - (tooltip-mode -1))) + (when (fboundp 'tooltip-mode) + (tooltip-mode (or on-off (not tooltip-mode))))) (provide 'core-early-funcs) diff --git a/core/core-spacemacs.el b/core/core-spacemacs.el index 3e231ff48274..8ba062a0ea75 100644 --- a/core/core-spacemacs.el +++ b/core/core-spacemacs.el @@ -74,7 +74,7 @@ the final step of executing code in `emacs-startup-hook'.") (setq ad-redefinition-action 'accept) ;; this is for a smoother UX at startup (i.e. less graphical glitches) (hidden-mode-line-mode) - (spacemacs/removes-gui-elements) + (spacemacs//toggle-gui-elements 0) (spacemacs//setup-ido-vertical-mode) ;; explicitly set the preferred coding systems to avoid annoying prompt ;; from emacs (especially on Microsoft Windows) diff --git a/early-init.el b/early-init.el index 139004245f2f..218328397b8d 100644 --- a/early-init.el +++ b/early-init.el @@ -39,8 +39,14 @@ "core/core-early-funcs") nil (not init-file-debug)) -;; Remove GUI elements soon after GUI being initialized to avoid some possible grapical glitches. -;; This has to be done use these hooks, -;; see https://www.gnu.org/software/emacs/manual/html_node/emacs/Early-Init-File.html -(add-hook 'window-setup-hook 'spacemacs/removes-gui-elements) -(add-hook 'tty-setup-hook 'spacemacs/removes-gui-elements) +;; Unfortunately the hooks below prevent users from customizing gui elements +;; within dotspacemacs/user-config function. Thus the hooks are commented out. +;; These should not be needed in any case since gui elements are turned off +;; within spacemacs/init function. Original comment follows next. +;; +;; Remove GUI elements soon after GUI being initialized to avoid some possible +;; grapical glitches. This has to be done use these hooks, see +;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Early-Init-File.html +;; +;; (add-hook 'window-setup-hook 'spacemacs/toggle-gui-elements-off) +;; (add-hook 'tty-setup-hook 'spacemacs/toggle-gui-elements-off) diff --git a/layers/+spacemacs/spacemacs-defaults/keybindings.el b/layers/+spacemacs/spacemacs-defaults/keybindings.el index 3f19164dae89..4978e58cd5ad 100644 --- a/layers/+spacemacs/spacemacs-defaults/keybindings.el +++ b/layers/+spacemacs/spacemacs-defaults/keybindings.el @@ -595,6 +595,13 @@ respond to this toggle." :mode menu-bar-mode :documentation "Display the menu bar." :evil-leader "Tm") +(spacemacs|add-toggle gui-elements + :if window-system + :status (or menu-bar-mode tool-bar-mode scroll-bar-mode tooltip-mode) + :on (spacemacs//toggle-gui-elements 1) + :off (spacemacs//toggle-gui-elements 0) + :documentation "Toggle menubar, toolbar, scrollbar, and tooltip modes." + :evil-leader "Tg") ;; quit ----------------------------------------------------------------------- (spacemacs/set-leader-keys "qs" 'spacemacs/save-buffers-kill-emacs