Re: [Sawfish] Nudge, nudge

[ Thread Index | Date Index | More lists.tuxfamily.org/sawfish Archives ]


What you want can be done with a 'recursive-edit': To make it work you need
to bind a mouse button in the title- or tab-bar to some function, which
   - grabs the keyboard
   - installs a custom keymap
   - enters its own key-reading loop

Note that you can only bind mouse button events to any part of the window
frame. This is by design, buried somewhere in the C-code, and usually what
you want in 99% of all cases: Even with the mouse pointer located somewhere
within the frame part of some window, you want normal keystrokes to be send
to the window itself, and not to its frame.

The code below has worked for me. Note that the thing "nudge-window" is
somewhat overloaded, though: It is
  - a structure,  try (get-structure 'nudge-window)
  - a symbol with a command definition, try (symbol-plist 'nudge-window)
  - a closure, just nudge-window w/o quotes

;;-----------------------------------------------------------------------------

(define-structure nudge-window
  (export nudge-window)

  (open rep
        rep.system
        sawfish.wm.commands
        sawfish.wm.events
        sawfish.wm.misc
        sawfish.wm.windows.subrs)

  (define target-window (make-fluid))

  (define (move-target-window x y)
    (let ((w (fluid target-window)))
      (when w
        (let ((wpos (window-position w)))
          (move-window-to w
                          (+ (car wpos) x)
                          (+ (cdr wpos) y))))))

  (define nudge-keymap
    (let ((kmap (make-keymap)))
      (bind-keys kmap
                 "Left"  (lambda () (move-target-window -1  0))
                 "Right" (lambda () (move-target-window +1  0))
                 "Up"    (lambda () (move-target-window  0 -1))
                 "Down"  (lambda () (move-target-window  0 +1)) )
      kmap))

  (define (loop-keys)
    (let
        ( (override-keymap  nudge-keymap)
          (unbound-key-hook (list (lambda () (throw 'nudge-exit))))
          (interrupt-mode   'exit) )
        (catch 'nudge-exit
          (recursive-edit)) ))

  (define (nudge-window win)
    (display-message (format nil "Nudging window %s ..." (window-name win)))
    (unwind-protect
        (let-fluids ((target-window win))
          (call-with-keyboard-grabbed loop-keys))
      (display-message)))
  )

(require 'rep.structures)
(open-structures '(nudge-window))
(define-command 'nudge-window nudge-window #:spec "%W")

;; Which one depends on whether the theme supports tabs
(bind-keys title-keymap  "Button1-Off" 'nudge-window)
(bind-keys tabbar-keymap "Button1-Off" 'nudge-window)


On 16.02.22 19:54, Geoff Kuenning wrote:
I'd be fine with that solution.

My first attempt was to bind the nudge commands to the arrow keys in the title bar.  But AFAICT Sawfish doesn't capture title-bar keystrokes.  Rats.

Would having those bound to with a modifier on the window,
like SUPER+ARROW, be an alternative?

--
Sawfish ML




--
Sawfish ML


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/