takaxp / moom

A Moom port to Emacs - Make your dominant hand FREE from your mouse
GNU General Public License v3.0
77 stars 3 forks source link

Emacs has built-in code that would eliminate need to set margins #18

Closed notuntoward closed 3 years ago

notuntoward commented 3 years ago

I just tried out v1.4.12 on a couple different computers and monitors. As I guessed, it would be necessary to adjust the margins differently for different monitor resolutions (#17 ).

However, I discovered that emacs internal functions make it possible to avoid the need to set margins at all. Below are two hacked versions of toggle-frame-fullscreen for toggling frame height and width. They're not perfect -- they get mildly confused when mixing fullscreen, height and width toggling -- but they do always position and size the frame correctly, regardless of monitor.

(defun sdo/toggle-frame-fullheight (&optional frame)
  "Toggle height part of fullscreen state of FRAME.
Make selected frame full height or restore its previous size
if it is already fullscreen.

This is a hacked version of built-in toggle-frame-fullscreen

See also `toggle-frame-maximized'."
  (interactive)
  (let ((fullscreen (frame-parameter frame 'fullscreen)))
    (if (memq fullscreen '(fullscreen fullheight))
    (let ((fullscreen-restore (frame-parameter frame 'fullscreen-restore)))
      (if (memq fullscreen-restore '(maximized fullheight fullwidth))
          (set-frame-parameter frame 'fullscreen fullscreen-restore)
        (set-frame-parameter frame 'fullscreen nil)))
      (modify-frame-parameters
       frame `((fullscreen . fullheight) (fullscreen-restore . ,fullscreen))))
    ;; Manipulating a frame without waiting for the fullscreen
    ;; animation to complete can cause a crash, or other unexpected
    ;; behavior, on macOS (bug#28496).
    (when (featurep 'cocoa) (sleep-for 0.5))))

And...

(defun sdo/toggle-frame-fullwidth (&optional frame)
  "Toggle width part of fullscreen state of FRAME.
Make selected frame full width or restore its previous size
if it is already fullscreen.

This is a hacked version of built-in toggle-frame-fullscreen

See also `toggle-frame-maximized'."
  (interactive)
  (let ((fullscreen (frame-parameter frame 'fullscreen)))
    (if (memq fullscreen '(fullscreen fullwidth))
    (let ((fullscreen-restore (frame-parameter frame 'fullscreen-restore)))
      (if (memq fullscreen-restore '(maximized fullwidth fullwidth))
          (set-frame-parameter frame 'fullscreen fullscreen-restore)
        (set-frame-parameter frame 'fullscreen nil)))
      (modify-frame-parameters
       frame `((fullscreen . fullwidth) (fullscreen-restore . ,fullscreen))))
    ;; Manipulating a frame without waiting for the fullscreen
    ;; animation to complete can cause a crash, or other unexpected
    ;; behavior, on macOS (bug#28496).
    (when (featurep 'cocoa) (sleep-for 0.5))))
takaxp commented 3 years ago

Thank you for providing nice information but previously I've discovered such approach rely on frame-parameter and modify-frame-parameters and it was not good to control frame position and size. I'll revisit the approach and adopt if it will not break existing APIs.

takaxp commented 3 years ago

Bad news. The proposed command is not valid in my environment. As I commented in #17, the issue highly depends on user environment...

unnamed

takaxp commented 3 years ago

I'll close this issue because I still see some spaces between frame and screen even if the proposed commands are used for filling width or height, and both in my environments. Additionally, the fullscreen parameter on modify-frame-parameters with fillwidth or fillheight shall be changed to nil before calling existing APIs in moom otherwise parameter fullscreen will not be changed. So relying on modify-frame-parameters is not good choice for moom. I'm not sure how many patterns of moom-user-margin are observed in your side, but I hope the number is quite a little.

takaxp commented 3 years ago

I have added some modifications which include an update on calculation of active region in a monitor. I'm not sure the change can resolve your issue but it is worth to try the latest version 1.4.20 in you side.