From f07435e22b99ccc095c35861dfc76e617ab91d02 Mon Sep 17 00:00:00 2001 From: Matt Spear Date: Mon, 7 Mar 2011 22:40:24 -0800 Subject: [PATCH 1/5] add command hook --- bindings.lisp | 3 ++- primitives.lisp | 9 +++++++++ user.lisp | 6 +++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/bindings.lisp b/bindings.lisp index e8d11b6..66e43f8 100644 --- a/bindings.lisp +++ b/bindings.lisp @@ -232,7 +232,8 @@ from most specific groups to most general groups.") "Command mode allows you to type ratpoison commands without needing the @key{C-t} prefix. Keys not bound in StumpWM will still get sent to the current window. To exit command mode, type @key{C-g}." - (message "Press C-g to exit command-mode.") + (setf *in-command-mode* T) + (run-hook-with-args *command-mode-hook* T) (push-top-map *root-map*)) (defcommand set-prefix-key (key) ((:key "Key: ")) diff --git a/primitives.lisp b/primitives.lisp index 10ca8df..ef96629 100644 --- a/primitives.lisp +++ b/primitives.lisp @@ -146,8 +146,17 @@ be an integer.") (defvar *message-window-timer* nil "Keep track of the timer that hides the message window.") +(defvar *in-command-mode* nil + "If T then is in command mode, otherwise nil") + ;;; Hooks +(defvar *command-mode-hook* (list #'(lambda (start) + (when (eq start T) + (message "Press C-g to exit command-mode.")))) + "A hook called whenever command mode is started or exited + it is givet nil on exit, T on start") + (defvar *urgent-window-hook* '() "A hook called whenever a window sets the property indicating that it demands the user's attention") diff --git a/user.lisp b/user.lisp index e9ca71c..ec7bf86 100644 --- a/user.lisp +++ b/user.lisp @@ -213,7 +213,11 @@ such a case, kill the shell command to resume StumpWM." "" ;; This way you can exit from command mode (when (pop-top-map) - (message "Exited."))) + (if *in-command-mode* + (progn + (run-hook-with-args *command-mode-hook* nil) + (setf *in-command-mode* nil)) + (message "Exited.")))) (defcommand-alias abort keyboard-quit) -- 1.7.3.5 From 3b91f965c626a09c2f64da119ef2b61fb74cf18a Mon Sep 17 00:00:00 2001 From: Matt Spear Date: Mon, 7 Mar 2011 22:45:07 -0800 Subject: [PATCH 2/5] ordering --- core.lisp | 5 +++-- user.lisp | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core.lisp b/core.lisp index b32dc00..b7fc450 100644 --- a/core.lisp +++ b/core.lisp @@ -115,8 +115,9 @@ (defun ungrab-pointer () "Remove the grab on the cursor and restore the cursor shape." - (xlib:ungrab-pointer *display*) - (xlib:display-finish-output *display*)) + (unless *in-command-mode* + (xlib:ungrab-pointer *display*) + (xlib:display-finish-output *display*))) (defun grab-keyboard (xwin) (let ((ret (xlib:grab-keyboard xwin :owner-p nil diff --git a/user.lisp b/user.lisp index ec7bf86..50202e2 100644 --- a/user.lisp +++ b/user.lisp @@ -215,8 +215,8 @@ such a case, kill the shell command to resume StumpWM." (when (pop-top-map) (if *in-command-mode* (progn - (run-hook-with-args *command-mode-hook* nil) - (setf *in-command-mode* nil)) + (setf *in-command-mode* nil) + (run-hook-with-args *command-mode-hook* nil)) (message "Exited.")))) (defcommand-alias abort keyboard-quit) -- 1.7.3.5 From 398fbb043499819a57433f76a01421af10d4c397 Mon Sep 17 00:00:00 2001 From: Matt Spear Date: Wed, 9 Mar 2011 21:56:04 -0800 Subject: [PATCH 3/5] change command-mode interface --- bindings.lisp | 3 +-- core.lisp | 32 ++++++++++++++++++-------------- primitives.lisp | 14 +++++++------- user.lisp | 9 +++------ 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/bindings.lisp b/bindings.lisp index 66e43f8..c58d000 100644 --- a/bindings.lisp +++ b/bindings.lisp @@ -232,8 +232,7 @@ from most specific groups to most general groups.") "Command mode allows you to type ratpoison commands without needing the @key{C-t} prefix. Keys not bound in StumpWM will still get sent to the current window. To exit command mode, type @key{C-g}." - (setf *in-command-mode* T) - (run-hook-with-args *command-mode-hook* T) + (run-hook-with-args *command-mode-start-hook*) (push-top-map *root-map*)) (defcommand set-prefix-key (key) ((:key "Key: ")) diff --git a/core.lisp b/core.lisp index b7fc450..bbfd96f 100644 --- a/core.lisp +++ b/core.lisp @@ -101,23 +101,27 @@ (defun grab-pointer (screen) "Grab the pointer and set the pointer shape." - (let* ((white (xlib:make-color :red 1.0 :green 1.0 :blue 1.0)) - (black (xlib:make-color :red 0.0 :green 0.0 :blue 0.0)) - (cursor-font (xlib:open-font *display* "cursor")) - (cursor (xlib:create-glyph-cursor :source-font cursor-font - :source-char 64 - :mask-font cursor-font - :mask-char 65 - :foreground black - :background white))) - (xlib:grab-pointer (screen-root screen) nil :owner-p nil - :cursor cursor))) + (progn + (incf *grab-pointer-count*) + (let* ((white (xlib:make-color :red 1.0 :green 1.0 :blue 1.0)) + (black (xlib:make-color :red 0.0 :green 0.0 :blue 0.0)) + (cursor-font (xlib:open-font *display* "cursor")) + (cursor (xlib:create-glyph-cursor :source-font cursor-font + :source-char 64 + :mask-font cursor-font + :mask-char 65 + :foreground black + :background white))) + (xlib:grab-pointer (screen-root screen) nil :owner-p nil + :cursor cursor)))) (defun ungrab-pointer () "Remove the grab on the cursor and restore the cursor shape." - (unless *in-command-mode* - (xlib:ungrab-pointer *display*) - (xlib:display-finish-output *display*))) + (progn + (when (> *grab-pointer-count* 0) (decf *grab-pointer-count*)) + (when (eq *grab-pointer-count* 0) + (xlib:ungrab-pointer *display*) + (xlib:display-finish-output *display*)))) (defun grab-keyboard (xwin) (let ((ret (xlib:grab-keyboard xwin :owner-p nil diff --git a/primitives.lisp b/primitives.lisp index ef96629..d79bf78 100644 --- a/primitives.lisp +++ b/primitives.lisp @@ -146,16 +146,16 @@ be an integer.") (defvar *message-window-timer* nil "Keep track of the timer that hides the message window.") -(defvar *in-command-mode* nil - "If T then is in command mode, otherwise nil") +(defvar *grab-pointer-count* 0 + "The number of times the pointer has been grabbed") ;;; Hooks -(defvar *command-mode-hook* (list #'(lambda (start) - (when (eq start T) - (message "Press C-g to exit command-mode.")))) - "A hook called whenever command mode is started or exited - it is givet nil on exit, T on start") +(defvar *command-mode-start-hook* '() + "A hook called whenever command mode is started") + +(defvar *command-mode-end-hook* '() + "A hook called whenever command mode is ended") (defvar *urgent-window-hook* '() "A hook called whenever a window sets the property indicating that diff --git a/user.lisp b/user.lisp index 50202e2..d5824b7 100644 --- a/user.lisp +++ b/user.lisp @@ -212,12 +212,9 @@ such a case, kill the shell command to resume StumpWM." (defcommand keyboard-quit () () "" ;; This way you can exit from command mode - (when (pop-top-map) - (if *in-command-mode* - (progn - (setf *in-command-mode* nil) - (run-hook-with-args *command-mode-hook* nil)) - (message "Exited.")))) + (if (pop-top-map) + (run-hook-with-args *command-mode-end-hook*) + (message "Exited."))) (defcommand-alias abort keyboard-quit) -- 1.7.3.5 From 36ef730dc4fb6dde1baa09f5bad8df775cd617dd Mon Sep 17 00:00:00 2001 From: Matt Spear Date: Wed, 9 Mar 2011 22:01:23 -0800 Subject: [PATCH 4/5] forgot to add the let and if in user --- bindings.lisp | 4 ---- primitives.lisp | 4 ++++ user.lisp | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bindings.lisp b/bindings.lisp index c58d000..103cb0b 100644 --- a/bindings.lisp +++ b/bindings.lisp @@ -27,7 +27,6 @@ (export '(*groups-map* *help-map* - *root-map* set-prefix-key)) (defvar *escape-key* (kbd "C-t") @@ -38,9 +37,6 @@ C-t.") (defvar *escape-fake-key* (kbd "t") "The binding that sends the fake escape key to the current window.") -(defvar *root-map* nil - "This is the keymap by default bound to @kbd{C-t}. It is known as the @dfn{prefix map}.") - (defvar *groups-map* nil "The keymap that group related key bindings sit on. It is bound to @kbd{C-t g} by default.") diff --git a/primitives.lisp b/primitives.lisp index d79bf78..4cc8ba7 100644 --- a/primitives.lisp +++ b/primitives.lisp @@ -104,6 +104,7 @@ *banish-pointer-to* *xwin-to-window* *resize-map* + *root-map* *default-group-name* *window-border-style* *data-dir* @@ -1024,6 +1025,9 @@ input focus is transfered to the window you click on.") (defvar *xwin-to-window* (make-hash-table) "Hash table for looking up windows quickly.") +(defvar *root-map* nil + "This is the keymap by default bound to @kbd{C-t}. It is known as the @dfn{prefix map}.") + (defvar *resize-map* nil "The keymap used for resizing a window") diff --git a/user.lisp b/user.lisp index d5824b7..44349cc 100644 --- a/user.lisp +++ b/user.lisp @@ -212,9 +212,11 @@ such a case, kill the shell command to resume StumpWM." (defcommand keyboard-quit () () "" ;; This way you can exit from command mode - (if (pop-top-map) + (let ((in-top-map (eq *top-map* *root-map*))) + (when (pop-top-map) + (if in-top-map (run-hook-with-args *command-mode-end-hook*) - (message "Exited."))) + (message "Exited."))))) (defcommand-alias abort keyboard-quit) -- 1.7.3.5 From 9de87b54ca57bb2b02c169df3e2f38eaab5a402d Mon Sep 17 00:00:00 2001 From: Matt Spear Date: Thu, 10 Mar 2011 20:30:11 -0800 Subject: [PATCH 5/5] command-mode revisions --- core.lisp | 6 ++---- kmap.lisp | 4 ++++ primitives.lisp | 18 ++++++++++++------ user.lisp | 4 ++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/core.lisp b/core.lisp index bbfd96f..d75c851 100644 --- a/core.lisp +++ b/core.lisp @@ -101,7 +101,6 @@ (defun grab-pointer (screen) "Grab the pointer and set the pointer shape." - (progn (incf *grab-pointer-count*) (let* ((white (xlib:make-color :red 1.0 :green 1.0 :blue 1.0)) (black (xlib:make-color :red 0.0 :green 0.0 :blue 0.0)) @@ -113,15 +112,14 @@ :foreground black :background white))) (xlib:grab-pointer (screen-root screen) nil :owner-p nil - :cursor cursor)))) + :cursor cursor))) (defun ungrab-pointer () "Remove the grab on the cursor and restore the cursor shape." - (progn (when (> *grab-pointer-count* 0) (decf *grab-pointer-count*)) (when (eq *grab-pointer-count* 0) (xlib:ungrab-pointer *display*) - (xlib:display-finish-output *display*)))) + (xlib:display-finish-output *display*))) (defun grab-keyboard (xwin) (let ((ret (xlib:grab-keyboard xwin :owner-p nil diff --git a/kmap.lisp b/kmap.lisp index 936f15f..0ba5841 100644 --- a/kmap.lisp +++ b/kmap.lisp @@ -26,6 +26,7 @@ (in-package stumpwm) (export '(*top-map* + *root-map* define-key kbd lookup-command @@ -37,6 +38,9 @@ "The top level key map. This is where you'll find the binding for the @dfn{prefix map}.") +(defvar *root-map* nil + "This is the keymap by default bound to @kbd{C-t}. It is known as the @dfn{prefix map}.") + (defstruct key keysym shift control meta alt hyper super) diff --git a/primitives.lisp b/primitives.lisp index 4cc8ba7..ddbeb9e 100644 --- a/primitives.lisp +++ b/primitives.lisp @@ -33,6 +33,8 @@ *frame-indicator-text* *frame-indicator-timer* *message-window-timer* + *command-mode-start-hook* + *command-mode-end-hook* *urgent-window-hook* *new-window-hook* *destroy-window-hook* @@ -104,7 +106,6 @@ *banish-pointer-to* *xwin-to-window* *resize-map* - *root-map* *default-group-name* *window-border-style* *data-dir* @@ -118,6 +119,8 @@ remove-hook run-hook run-hook-with-args + command-mode-start-message + command-mode-end-message split-string with-restarts-menu with-data-file @@ -152,10 +155,10 @@ be an integer.") ;;; Hooks -(defvar *command-mode-start-hook* '() +(defvar *command-mode-start-hook* (list (lambda () (command-mode-start-message))) "A hook called whenever command mode is started") -(defvar *command-mode-end-hook* '() +(defvar *command-mode-end-hook* (list (lambda () (command-mode-end-message))) "A hook called whenever command mode is ended") (defvar *urgent-window-hook* '() @@ -1025,9 +1028,6 @@ input focus is transfered to the window you click on.") (defvar *xwin-to-window* (make-hash-table) "Hash table for looking up windows quickly.") -(defvar *root-map* nil - "This is the keymap by default bound to @kbd{C-t}. It is known as the @dfn{prefix map}.") - (defvar *resize-map* nil "The keymap used for resizing a window") @@ -1114,3 +1114,9 @@ of :error." (:preserve thing) (:invert (string-downcase thing))) package)) + +(defun command-mode-start-message () + (message "Press C-g to exit command-mode.")) + +(defun command-mode-end-message () + (message "Exited command-mode.")) diff --git a/user.lisp b/user.lisp index 44349cc..e1a3bd1 100644 --- a/user.lisp +++ b/user.lisp @@ -212,9 +212,9 @@ such a case, kill the shell command to resume StumpWM." (defcommand keyboard-quit () () "" ;; This way you can exit from command mode - (let ((in-top-map (eq *top-map* *root-map*))) + (let ((in-command-mode (eq *top-map* *root-map*))) (when (pop-top-map) - (if in-top-map + (if in-command-mode (run-hook-with-args *command-mode-end-hook*) (message "Exited."))))) -- 1.7.3.5