ch11ng / exwm

Emacs X Window Manager
2.85k stars 136 forks source link

exwm window eats my key #401

Closed QiangF closed 6 years ago

QiangF commented 6 years ago

The idea is to change terminal buffer (xterm, termite etc.) name according to usage, such as "remote session", "debug" etc. The renaming is done with a hook:

(defun my-exwm-rename ()
    (progn
        (exwm-workspace-rename-buffer (read-string "Buffer name (optional):" "default"))
        (setq buffer-read-only nil)))

(add-hook 'exwm-manage-finish-hook #'my-exwm-rename)

The terminal app is started with:

(defun my-term ()
    "Create new term buffer."
  (interactive)
  (start-process-shell-command "termite" nil "termite"))

The problem is after the user enter the name of the buffer, the next key is not sent to the application, (need to press enter twice to get to the app). This doesn't happend if the buffer is a normal emacs buffer (such as ansi-term buffer.

ch11ng commented 6 years ago

Do you really need to rename every buffer? I think it's better to make my-exwm-rename a command and use it on demand. exwm-manage-finish-hook is not a good place to do this.

QiangF commented 6 years ago

The code in the issue is just a siplified function to illustrate the issue that happens when using read-string to get the buffer name. The purpose of renaming xterm (termite) buffer is like add a purpose tag for the buffer (so I can easily switch to the buffer using shortcut keys) . I also add a hook to rename other exwm buffers for easy switching :

    (exwm-workspace-rename-buffer
     (concat exwm-class-name ":"
             (if (<= (length exwm-title) 50) exwm-title
               (concat (substring exwm-title 0 49) "...")))))
    (setq buffer-read-only nil)))

My full setup borrows some ideas from exwmx-appconfig :

(defun my-exwm-appconfig ()
  (let* ((appconfig (exwmx-appconfig--search
                     `((:class ,exwm-class-name)
                       (:instance ,exwm-instance-name))))
         (floating (plist-get appconfig :floating))
         (default-name (plist-get appconfig :default-name))
         (char-mode (plist-get appconfig :char-mode))
         (position (plist-get appconfig :position))
         (prefix-keys (plist-get appconfig :prefix-keys))
         (prefix-keys-added (plist-get appconfig :add-prefix-keys))
         (prefix-keys-removed (plist-get appconfig :remove-prefix-keys))
         (simulation-keys (plist-get appconfig :simulation-keys)))
    (if appconfig
        (progn
          (message "%s" "appconfig")
          (when char-mode (exwm-layout-set-fullscreen))
          (when floating
            (exwm-floating--set-floating exwm--id)
            (if (= (length position) 2)
                (apply #'exwmx-floating-set-positon position)))
          (if prefix-keys (setq-local exwm-input-prefix-keys)
            (progn
              (if prefix-keys-removed (dolist (key prefix-keys-removed)
                                        (setq-local exwm-input-prefix-keys (remove key exwm-input-prefix-keys))))
              (if prefix-keys-added
                  (setq-local exwm-input-prefix-keys (append prefix-keys-added exwm-input-prefix-keys)))
              ))
          (if (not (string-equal simulation-keys "default"))
              (my-eval-string (concat "(exwm-input-set-local-simulation-keys '(" simulation-keys "))"))))
      (message "no appconfig"))
    ;; rename window
    (if default-name
        (progn
          (exwm-workspace-rename-buffer (read-from-minibuffer "Buffer name (optional):" default-name))
          ;; (start-process-shell-command "xdo enter" nil "xdotool key --delay 40 Return")
          )
    (exwm-workspace-rename-buffer
     (concat exwm-class-name ":"
             (if (<= (length exwm-title) 50) exwm-title
               (concat (substring exwm-title 0 49) "...")))))
    (setq buffer-read-only nil)))
  (add-hook 'exwm-manage-finish-hook #'my-exwm-appconfig)
ch11ng commented 6 years ago

Please try if it's fixed now.

medranocalvo commented 6 years ago

@QiangF could you check latest version?

QiangF commented 6 years ago

It's solved. I have been waiting for a stable release for a long time. After updating from 0.16 to the master branch, no 100% cpu usage any more.