Skip to content

Commit

Permalink
* user.lisp (command): new defstruct
Browse files Browse the repository at this point in the history
(*command-hash*): new defvar
(define-stumpwm-command): new macro
(set-key-binding): change 3rd arg to cmd
("next"): new stumpwm command
("prev"): likewise
("delete"): likewise
("kill"): likewise
("banish"): likewise
("windows"): likewise
("select"): likewise
(shell-command): remove function
("other"): new stumpwm command
(run-shell-command): new function
("exec"): new stumpwm command
("hsplit"): likewise
("vsplit"): likewise
(remove-split): use format for debugging output
("remove"): new stumpwm command
("sibling"): likewise
(choose-frame-by-number): new function
("fselect"): new stumpwm command
(eval-line): take the expression to eval as the second arg
("eval"): new stumpwm command
(split-by-one-space): new function
(parse-and-run-command): likewise
(interactive-command): new function
("colon"): new stumpwm command
("pull"): likewise
("meta"): likewise
(renumber): take the new number as arg #2
("number"): new stumpwm command
("reload"): likewise
(set-default-bindings): bind keys to stumpwm commands

* stumpwm.lisp (load-rc-file): change ~/.stumpwmrc path to be more portable.
(error-handler): use format for debugging output

* primitives.lisp (*key-bindings*): change to defvar.
(find-free-number): use format for debugging output

* input.lisp (setup-input-window): use format for debugging output
(shutdown-input-window): likewise

* core.lisp (process-existing-windows): use format for debugging output
(no-focus): likewise
(delete-window): likewise
(kill-window): likewise
(focus-frame): likewise
(sync-frame-windows): likewise
(draw-frame-numbers): likewise
(:configure-request): likewise
(handle-command-key): likewise
(:key-press): likewise
(handle-event): likewise
(echo-string-list): force output
  • Loading branch information
sabetts committed Dec 1, 2004
1 parent 428ee1b commit 669b455
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 129 deletions.
59 changes: 59 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
2004-11-30 Shawn Betts <katia_dilkina@verizon.net>

* user.lisp (command): new defstruct
(*command-hash*): new defvar
(define-stumpwm-command): new macro
(set-key-binding): change 3rd arg to cmd
("next"): new stumpwm command
("prev"): likewise
("delete"): likewise
("kill"): likewise
("banish"): likewise
("windows"): likewise
("select"): likewise
(shell-command): remove function
("other"): new stumpwm command
(run-shell-command): new function
("exec"): new stumpwm command
("hsplit"): likewise
("vsplit"): likewise
(remove-split): use format for debugging output
("remove"): new stumpwm command
("sibling"): likewise
(choose-frame-by-number): new function
("fselect"): new stumpwm command
(eval-line): take the expression to eval as the second arg
("eval"): new stumpwm command
(split-by-one-space): new function
(parse-and-run-command): likewise
(interactive-command): new function
("colon"): new stumpwm command
("pull"): likewise
("meta"): likewise
(renumber): take the new number as arg #2
("number"): new stumpwm command
("reload"): likewise
(set-default-bindings): bind keys to stumpwm commands

* stumpwm.lisp (load-rc-file): change ~/.stumpwmrc path to be more portable.
(error-handler): use format for debugging output

* primitives.lisp (*key-bindings*): change to defvar.
(find-free-number): use format for debugging output

* input.lisp (setup-input-window): use format for debugging output
(shutdown-input-window): likewise

* core.lisp (process-existing-windows): use format for debugging output
(no-focus): likewise
(delete-window): likewise
(kill-window): likewise
(focus-frame): likewise
(sync-frame-windows): likewise
(draw-frame-numbers): likewise
(:configure-request): likewise
(handle-command-key): likewise
(:key-press): likewise
(handle-event): likewise
(echo-string-list): force output

2004-11-12 Shawn Betts <katia_dilkina@verizon.net>

* primitives.lisp (screen): remove frame-hash. all dependant code
Expand Down
52 changes: 26 additions & 26 deletions core.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
:data data))

(defun default-window-format (screen w)
"The default function called to format a window for display in the window list."
"Return a formatted string"
(format nil "~D~C~A"
(window-number screen w)
(cond ((xlib:window-equal w (screen-current-window screen))
Expand Down Expand Up @@ -189,7 +189,7 @@ managed."
(if (or (eql map-state :viewable)
(eql wm-state +iconic-state+))
(progn
(pprint (list 'processing (window-name win) win))
(format t "Processing ~S ~S~%" (window-name win) win)
(process-new-window win)
;; Pretend it's been mapped
(absorb-mapped-window screen win))))))))
Expand Down Expand Up @@ -313,7 +313,7 @@ give the last accessed window focus."

(defun no-focus (screen)
"don't focus any window but still read keyboard events."
(pprint 'no-focus)
(format t "no-focus~%")
(xlib:set-input-focus *display* (screen-focus-window screen) :POINTER-ROOT))

(defun focus-window (window)
Expand Down Expand Up @@ -343,12 +343,12 @@ maximized, and given focus."

(defun delete-window (window)
"Send a delete event to the window."
(pprint '(delete window))
(format t "Delete window~%")
(send-client-message window :WM_PROTOCOLS 213))

(defun kill-window (window)
"Kill the client associated with window."
(pprint '(kill client))
(format t "Kill client~%")
(xlib:kill-client *display* (xlib:window-id window)))


Expand Down Expand Up @@ -409,7 +409,7 @@ maximized, and given focus."
(defun focus-frame (screen f)
(let ((w (frame-window f)))
(setf (screen-current-frame screen) f)
(pprint f)
(format t "~S~%" f)
(if w
(focus-window w)
(no-focus screen))))
Expand Down Expand Up @@ -610,7 +610,7 @@ one."
"synchronize windows attached to FRAME."
(mapc (lambda (w)
(when (eq (window-frame screen w) frame)
(pprint '(maximizing w))
(format t "maximizing ~S~%" w)
(maximize-window w)))
(screen-mapped-windows screen)))

Expand Down Expand Up @@ -645,7 +645,7 @@ windows used to draw the numbers in. The caller must destroy them."
(xlib:screen-black-pixel (screen-number screen))
(format nil "~A" (frame-number f)))
(xlib:display-force-output *display*)
(pprint (list 'mapped (frame-number f)))
(format t "mapped ~S~%" (frame-number f))
w))
(screen-frames screen)))

Expand Down Expand Up @@ -702,6 +702,7 @@ the nth entry to highlight."
0 (* i height)
(xlib:drawable-width message-win)
height)))
(xlib:display-force-output *display*)
;; Set a timer to hide the message after a number of seconds
(reset-timeout))

Expand Down Expand Up @@ -842,7 +843,7 @@ list of modifier symbols."
(declare (ignorable above-sibling))
(declare (ignorable parent))
(declare (ignorable stack-mode))
(pprint value-mask)
(format t "~S~%" value-mask)
(handler-case
(labels ((has-x (mask) (= 1 (logand mask 1)))
(has-y (mask) (= 2 (logand mask 2)))
Expand All @@ -852,21 +853,21 @@ list of modifier symbols."
(has-stackmode (mask) (= 64 (logand mask 64))))
(let ((screen (window-screen window)))
(xlib:with-state (window)
(pprint value-mask)
(format t "~S~%" value-mask)
(when (has-x value-mask)
(pprint 'x)
(format t "x~%")
(setf (xlib:drawable-x window) x))
(when (has-y value-mask)
(pprint 'y)
(format t "x~%")
(setf (xlib:drawable-y window) y))
(when (has-h value-mask)
(pprint 'h)
(format t "h~%")
(setf (xlib:drawable-height window) height))
(when (has-w value-mask)
(pprint 'w)
(format t "w~%")
(setf (xlib:drawable-width window) width))
(when (has-bw value-mask)
(pprint 'bw)
(format t "bw~%")
(setf (xlib:drawable-border-width window) border-width)))
;; TODO: are we ICCCM compliant?
;; Make sure that goes to the client
Expand Down Expand Up @@ -938,15 +939,14 @@ list of modifier symbols."
(defun handle-command-key (screen code state)
"Find the command mapped to the (code state) and executed it."
(let* ((key (keycode->character code (xlib:make-state-keys state)))
(fn (gethash (list key (remove :shift (xlib:make-state-keys state))) *key-bindings*)))
(pprint (list key state))
;(pprint (cook-keycode code state))
(pprint fn)
(if (null fn)
(pprint '(no match))
(cmd (gethash (list key (remove :shift (xlib:make-state-keys state))) *key-bindings*)))
(format t "key-press: ~S ~S~%" key state)
(format t "~S~%" cmd)
(if (null cmd)
(format t "no match.~%")
(progn
(pprint '(found it))
(funcall fn screen)))))
(format t "found it.~%")
(interactive-command cmd screen)))))

(define-stump-event-handler :key-press (code state window root)
(declare (ignorable window))
Expand All @@ -959,11 +959,11 @@ list of modifier symbols."
;; grab the keyboard
(grab-pointer screen)
(grab-keyboard screen)
(pprint '(awaiting command key))
(format t "Awaiting command key~%")
;; Listen for key
(let ((key (do ((k (read-key) (read-key)))
((not (is-modifier (xlib:keycode->keysym *display* (car k) 0))) k))))
(pprint '(handling command))
(format t "Handling Command~%")
;; We've read our key, so we can release the keyboard.
(ungrab-pointer)
(ungrab-keyboard)
Expand All @@ -972,7 +972,7 @@ list of modifier symbols."

(defun handle-event (&rest event-slots &key display event-key &allow-other-keys)
(declare (ignorable display))
(pprint (list 'handling 'event event-key))
(format t "Handling event ~S~%" event-key)
(let ((eventfn (gethash event-key *event-fn-table*)))
(when eventfn
(apply eventfn event-slots))
Expand Down
4 changes: 2 additions & 2 deletions input.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
(let* ((height (+ (xlib:font-descent (screen-font screen))
(xlib:font-ascent (screen-font screen))))
(win (screen-input-window screen)))
(pprint '(setup input window))
(format t "Setup input window~%")
;; Window dimensions
(xlib:map-window win)
(setf (xlib:window-priority win) :above)
Expand All @@ -50,7 +50,7 @@
:sync-keyboard-p nil :sync-pointer-p nil)))

(defun shutdown-input-window (screen)
(pprint '(shutdown input window))
(format t "Shutdown input window~%")
(xlib:ungrab-keyboard *display*)
(xlib:unmap-window (screen-input-window screen)))

Expand Down
4 changes: 2 additions & 2 deletions primitives.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ screen and window. It should return a string.")
(mods nil :type list)
(fn nil :type function))

(defparameter *key-bindings* (make-hash-table :test 'equal)
(defvar *key-bindings* (make-hash-table :test 'equal)
"An alist of keysym function pairs.")

;; FIXME: This variable is set only once but it needs to be set after
Expand Down Expand Up @@ -215,7 +215,7 @@ calls fn on the value for the key hash-key, not the pair."
for i in nums
when (/= n i)
do (return n))))
(pprint nums)
(format t "Free number: ~S~%" nums)
(if new-num
new-num
;; there was no space between the numbers, so use the last + 1
Expand Down
37 changes: 23 additions & 14 deletions sample-stumpwmrc.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,34 @@

(in-package :stumpwm)

;; prompt the user for an interactive command. The first arg is an
;; optional initial contents.
(define-stumpwm-command "colon1" (screen (initial :rest nil))
(let ((cmd (read-one-line screen ": " initial)))
(when cmd
(interactive-command cmd))))

;; Read some doc
(set-key-binding #\d '() (lambda (s) (run-command-string "gv")))
(set-key-binding #\d '() "exec gv")
;; Browse somewhere
(set-key-binding #\b '() (partial-command "" "firefox http://www."))
(set-key-binding #\b '() "colon1 exec firefox http://www.")
;; Ssh somewhere
(set-key-binding #\s '(:control) (partial-command "" "xterm -e ssh "))
(set-key-binding #\s '(:control) "colon1 exec xterm -e ssh ")
;; Lock screen
(set-key-binding #\l '(:control) (lambda (s) (run-command-string "xlock")))
(set-key-binding #\l '(:control) "exec xlock")

;; Web jump (works for Google and Imdb)
(defmacro make-web-jump (name prefix)
`(define-stumpwm-command ,name (screen (search :rest ,(concatenate name " search: ")))
(run-shell-command
(concatenate 'string ,prefix
(substitute #\+ #\Space search)))))

(make-web-jump "google" "firefox http://www.google.fr/search?q=")
(make-web-jump "imdb" "firefox http://www.imdb.com/find?q=")

;; Web search (works for Google and Imdb)
(defun make-web-search (prompt prefix)
#'(lambda (s)
(let ((search (read-one-line s prompt)))
(unless (null search)
(run-command-string
(concatenate 'string prefix
(substitute #\+ #\Space search)))))))
(set-key-binding #\g '() (make-web-search "Google search: " "firefox http://www.google.fr/search?q="))
(set-key-binding #\i '() (make-web-search "IMDB search: " "firefox http://www.imdb.com/find?q="))
(set-key-binding #\g '() "google")
(set-key-binding #\i '() "imdb")

;; Message window font
(setf *font-name* "-xos4-terminus-medium-r-normal--14-140-72-72-c-80-iso8859-15")
12 changes: 5 additions & 7 deletions stumpwm.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
doesn't exist. Returns a values list: whether the file loaded (t if no
rc files exist), the error if it didn't, and the rc file that was
loaded."
(let* ((user-rc (probe-file (format nil "~A/.stumpwmrc"
(or (port:getenv "HOME")
(error "$HOME not set!?")))))

(let* ((user-rc (probe-file "home:.stumpwmrc"))
(etc-rc (probe-file #p"/etc/stumpwmrc"))
(rc (or user-rc etc-rc)))
(if rc
Expand All @@ -62,7 +59,7 @@ loaded."
('xlib:access-error
(error "Another window manager is running."))
(t
(pprint (list 'error error-key key-vals)))))
(format t "Error ~S ~S~%" error-key key-vals))))

(defun stumpwm-internal-loop ()
"The internal loop that waits for events and handles them."
Expand Down Expand Up @@ -111,13 +108,14 @@ loaded."
(mapc #'process-existing-windows *screen-list*)
;; Give the first screen's frame focus
(focus-frame (first *screen-list*) (screen-current-frame (first *screen-list*)))
;; Setup our keys. FIXME: should this be in the hook?
;; Setup the default key bindings. FIXME: should this be in the hook?
(set-default-bindings)
(echo-string (first *screen-list*) "Welcome to The Stump Window Manager!")
;; Load rc file
(multiple-value-bind (success err rc) (load-rc-file)
(unless success
(echo-string (first *screen-list*)
(format "Error loading ~A: ~A" rc err))))
(format nil "Error loading ~A: ~A" rc err))))
(run-hook *start-hook*)
;; Let's manage.
(stumpwm-internal-loop))
Expand Down
Loading

0 comments on commit 669b455

Please sign in to comment.