From a9136213020efb69672996e2306ae8c26b14e629 Mon Sep 17 00:00:00 2001 From: Chris Feng Date: Wed, 24 Aug 2016 19:21:17 +0800 Subject: [PATCH] Add toggle commands * exwm-input.el (exwm-input-toggle-keyboard): New command for toggling keyboard mode. * exwm-layout.el (exwm-layout-toggle-fullscreen): New command for toggling fullscreen mode. * exwm-core.el (exwm-mode-menu, exwm-mode-map): Use them. --- exwm-core.el | 10 ++-------- exwm-input.el | 10 ++++++++++ exwm-layout.el | 10 ++++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/exwm-core.el b/exwm-core.el index 0c92d90..e65ad51 100644 --- a/exwm-core.el +++ b/exwm-core.el @@ -150,10 +150,7 @@ "*General*" "---" ["Toggle floating" exwm-floating-toggle-floating] - ["Enter fullscreen" exwm-layout-set-fullscreen - (null (memq xcb:Atom:_NET_WM_STATE_FULLSCREEN exwm--ewmh-state))] - ["Leave fullscreen" exwm-reset - (memq xcb:Atom:_NET_WM_STATE_FULLSCREEN exwm--ewmh-state)] + ["Toggle fullscreen mode" exwm-layout-toggle-fullscreen] ["Hide window" exwm-floating-hide exwm--floating-frame] "---" @@ -168,10 +165,7 @@ "---" "*Keyboard*" "---" - ["Capture keyboard" exwm-input-release-keyboard exwm--keyboard-grabbed] - ;; It's recommended to use `exwm-reset' rather than - ;; `exwm-input-grab-keyboard' to release keyboard (enter line-mode). - ["Release keyboard" exwm-reset (not exwm--keyboard-grabbed)] + ["Toggle keyboard mode" exwm-input-toggle-keyboard] ["Send key" exwm-input-send-next-key exwm--keyboard-grabbed] ;; This is merely a reference. ("Send simulation key" :filter diff --git a/exwm-input.el b/exwm-input.el index e582812..61858e9 100644 --- a/exwm-input.el +++ b/exwm-input.el @@ -567,6 +567,16 @@ This value should always be overwritten.") (exwm-input--update-mode-line id) (force-mode-line-update)))) +;;;###autoload +(defun exwm-input-toggle-keyboard (&optional id) + "Toggle between 'line-mode' and 'char-mode'." + (interactive (list (exwm--buffer->id (window-buffer)))) + (when id + (with-current-buffer (exwm--id->buffer id) + (if exwm--keyboard-grabbed + (exwm-input-release-keyboard id) + (exwm-reset))))) + (defun exwm-input--fake-key (event) "Fake a key event equivalent to Emacs event EVENT." (let* ((keysym (xcb:keysyms:event->keysym exwm--connection event)) diff --git a/exwm-layout.el b/exwm-layout.el index e8fd8e5..355b834 100644 --- a/exwm-layout.el +++ b/exwm-layout.el @@ -260,6 +260,16 @@ (delq xcb:Atom:_NET_WM_STATE_FULLSCREEN exwm--ewmh-state)) (call-interactively #'exwm-input-grab-keyboard))) +;;;###autoload +(defun exwm-layout-toggle-fullscreen (&optional id) + "Toggle fullscreen mode." + (interactive (list (exwm--buffer->id (window-buffer)))) + (when id + (with-current-buffer (exwm--id->buffer id) + (if (memq xcb:Atom:_NET_WM_STATE_FULLSCREEN exwm--ewmh-state) + (exwm-reset) + (exwm-layout-set-fullscreen id))))) + (defvar exwm-layout--other-buffer-exclude-exwm-mode-buffers nil "When non-nil, prevent EXWM buffers from being selected by `other-buffer'.")