bound-check-menu

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

bound-check-menu

Victor Martinez
bound-check-menu does not consider monitor height/width.

For instance if you try in package stumpwm-user

    (select-from-menu
     (current-screen)
     (loop repeat 100 for i = 0 then (1+ i) collect (format nil "~a" i)))

depending on the monitor size parts of the menu are not shown.

The following replacement for bound-check-menu in menu-definitions.lisp works
for me although it doesn't consider monitor width, modline higth, boders, ...:

in menu-definitions.lisp:

; new function
(defun menu-height (menu)
  (let ((len (length (menu-table menu))))
    (min (or *menu-maximum-height* len) len)))

; new function
(defun frame-lines-height (&optional
                          (frame (current-head))
                             (screen (current-screen)))
  "Return how many text lines fit in the current monitor (?) considering the font in use."
   (floor (frame-height frame)
          (xlib:font-property (stumpwm::screen-font screen) :pixel_size)))

; new function
(defun max-menu-height (&optional
                          (frame (current-head))
                          (screen (current-screen)))
  "Todo: consider modline height, border height, ..."
  (max 0 (- (frame-lines-height frame screen) 3))) ; 3 because of 1 or 2 lines "..." and one line for menu label

(defun menu-start-end (i m l)
  "Return the start index and end index of the partition of l which corresponds
  to index i where l is greedily partitioned in pieces of max size m."
  (values
   (* m (floor i m))
   (min l (+ m (* m (floor i m))))))

(defun bound-check-menu (menu)
  "Adjust the menu view and selected item based
on current view and new selection."
  (let ((len (length (menu-table menu))))
    ;; Wrap around
    (setf (menu-selected menu)
          (if (zerop len) 0 (mod (menu-selected menu) len)))
    (setf (values (menu-view-start menu)
                  (menu-view-end menu))
          (menu-start-end
           (menu-selected menu)
           (max-menu-height)
           len))))

signature.asc (673 bytes) Download Attachment