mirror of
https://github.com/ch11ng/exwm.git
synced 2024-11-27 13:07:59 +01:00
Improve move/resize
The type of move/resize is consistent during one complete operation. So there is no need to judge it on every mouse motion.
This commit is contained in:
parent
10a7fe8d65
commit
7892ed36f1
1 changed files with 83 additions and 100 deletions
183
exwm-floating.el
183
exwm-floating.el
|
@ -211,9 +211,8 @@
|
||||||
(exwm-floating--unset-floating exwm--id)
|
(exwm-floating--unset-floating exwm--id)
|
||||||
(exwm-floating--set-floating exwm--id))))
|
(exwm-floating--set-floating exwm--id))))
|
||||||
|
|
||||||
(defvar exwm-floating--moveresize-id nil)
|
(defvar exwm-floating--moveresize-calculate nil
|
||||||
(defvar exwm-floating--moveresize-type nil)
|
"Calculate move/resize parameters [frame-id event-mask x y width height].")
|
||||||
(defvar exwm-floating--moveresize-delta nil)
|
|
||||||
|
|
||||||
(defun exwm-floating--start-moveresize (id &optional type)
|
(defun exwm-floating--start-moveresize (id &optional type)
|
||||||
"Start move/resize."
|
"Start move/resize."
|
||||||
|
@ -261,40 +260,85 @@
|
||||||
((< x 1) xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_LEFT))))
|
((< x 1) xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_LEFT))))
|
||||||
(when type
|
(when type
|
||||||
(cond ((= type xcb:ewmh:_NET_WM_MOVERESIZE_MOVE)
|
(cond ((= type xcb:ewmh:_NET_WM_MOVERESIZE_MOVE)
|
||||||
(setq exwm-floating--moveresize-delta (list win-x win-y 0 0)
|
(setq cursor exwm-floating--cursor-move
|
||||||
cursor exwm-floating--cursor-move))
|
exwm-floating--moveresize-calculate
|
||||||
|
`(lambda (x y)
|
||||||
|
(vector ,frame-id
|
||||||
|
,(logior xcb:ConfigWindow:X
|
||||||
|
xcb:ConfigWindow:Y)
|
||||||
|
(- x ,win-x) (- y ,win-y) 0 0))))
|
||||||
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_TOPLEFT)
|
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_TOPLEFT)
|
||||||
(setq exwm-floating--moveresize-delta
|
(setq cursor exwm-floating--cursor-top-left
|
||||||
(list win-x win-y (+ root-x width) (+ root-y height))
|
exwm-floating--moveresize-calculate
|
||||||
cursor exwm-floating--cursor-top-left))
|
`(lambda (x y)
|
||||||
|
(vector ,frame-id
|
||||||
|
,(logior xcb:ConfigWindow:X
|
||||||
|
xcb:ConfigWindow:Y
|
||||||
|
xcb:ConfigWindow:Width
|
||||||
|
xcb:ConfigWindow:Height)
|
||||||
|
(- x ,win-x) (- y ,win-y)
|
||||||
|
(- ,(+ root-x width) x)
|
||||||
|
(- ,(+ root-y height) y)))))
|
||||||
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_TOP)
|
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_TOP)
|
||||||
(setq exwm-floating--moveresize-delta
|
(setq cursor exwm-floating--cursor-top
|
||||||
(list 0 win-y 0 (+ root-y height))
|
exwm-floating--moveresize-calculate
|
||||||
cursor exwm-floating--cursor-top))
|
`(lambda (x y)
|
||||||
|
(vector ,frame-id
|
||||||
|
,(logior xcb:ConfigWindow:Y
|
||||||
|
xcb:ConfigWindow:Height)
|
||||||
|
0 (- y ,win-y) 0 (- ,(+ root-y height) y)))))
|
||||||
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_TOPRIGHT)
|
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_TOPRIGHT)
|
||||||
(setq exwm-floating--moveresize-delta
|
(setq cursor exwm-floating--cursor-top-right
|
||||||
(list 0 win-y (- root-x width) (+ root-y height))
|
exwm-floating--moveresize-calculate
|
||||||
cursor exwm-floating--cursor-top-right))
|
`(lambda (x y)
|
||||||
|
(vector ,frame-id
|
||||||
|
,(logior xcb:ConfigWindow:Y
|
||||||
|
xcb:ConfigWindow:Width
|
||||||
|
xcb:ConfigWindow:Height)
|
||||||
|
0 (- y ,win-y) (- x ,(- root-x width))
|
||||||
|
(- ,(+ root-y height) y)))))
|
||||||
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_RIGHT)
|
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_RIGHT)
|
||||||
(setq exwm-floating--moveresize-delta
|
(setq cursor exwm-floating--cursor-right
|
||||||
(list 0 0 (- root-x width) 0)
|
exwm-floating--moveresize-calculate
|
||||||
cursor exwm-floating--cursor-right))
|
`(lambda (x y)
|
||||||
|
(vector ,frame-id ,xcb:ConfigWindow:Width
|
||||||
|
0 0 (- x ,(- root-x width)) 0))))
|
||||||
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT)
|
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT)
|
||||||
(setq exwm-floating--moveresize-delta
|
(setq cursor exwm-floating--cursor-bottom-right
|
||||||
(list 0 0 (- root-x width) (- root-y height))
|
exwm-floating--moveresize-calculate
|
||||||
cursor exwm-floating--cursor-bottom-right))
|
`(lambda (x y)
|
||||||
|
(vector ,frame-id
|
||||||
|
,(logior xcb:ConfigWindow:Width
|
||||||
|
xcb:ConfigWindow:Height)
|
||||||
|
0 0 (- x ,(- root-x width))
|
||||||
|
(- y ,(- root-y height))))))
|
||||||
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_BOTTOM)
|
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_BOTTOM)
|
||||||
(setq exwm-floating--moveresize-delta
|
(setq cursor exwm-floating--cursor-bottom
|
||||||
(list 0 0 0 (- root-y height))
|
exwm-floating--moveresize-calculate
|
||||||
cursor exwm-floating--cursor-bottom))
|
`(lambda (x y)
|
||||||
|
(vector ,frame-id
|
||||||
|
,xcb:ConfigWindow:Height
|
||||||
|
0 0 0 (- y ,(- root-y height))))))
|
||||||
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT)
|
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT)
|
||||||
(setq exwm-floating--moveresize-delta
|
(setq cursor exwm-floating--cursor-bottom-left
|
||||||
(list win-x 0 (+ root-x width) (- root-y height))
|
exwm-floating--moveresize-calculate
|
||||||
cursor exwm-floating--cursor-bottom-left))
|
`(lambda (x y)
|
||||||
|
(vector ,frame-id
|
||||||
|
,(logior xcb:ConfigWindow:X
|
||||||
|
xcb:ConfigWindow:Width
|
||||||
|
xcb:ConfigWindow:Height)
|
||||||
|
(- x ,win-x)
|
||||||
|
0
|
||||||
|
(- ,(+ root-x width) x)
|
||||||
|
(- y ,(- root-y height))))))
|
||||||
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_LEFT)
|
((= type xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_LEFT)
|
||||||
(setq exwm-floating--moveresize-delta
|
(setq cursor exwm-floating--cursor-left
|
||||||
(list win-x 0 (+ root-x width) 0)
|
exwm-floating--moveresize-calculate
|
||||||
cursor exwm-floating--cursor-left)))
|
`(lambda (x y)
|
||||||
|
(vector ,frame-id
|
||||||
|
,(logior xcb:ConfigWindow:X
|
||||||
|
xcb:ConfigWindow:Width)
|
||||||
|
(- x ,win-x) 0 (- ,(+ root-x width) x) 0)))))
|
||||||
;; Select events and change cursor (should always succeed)
|
;; Select events and change cursor (should always succeed)
|
||||||
(xcb:+request-unchecked+reply exwm--connection
|
(xcb:+request-unchecked+reply exwm--connection
|
||||||
(make-instance 'xcb:GrabPointer
|
(make-instance 'xcb:GrabPointer
|
||||||
|
@ -305,89 +349,28 @@
|
||||||
:keyboard-mode xcb:GrabMode:Async
|
:keyboard-mode xcb:GrabMode:Async
|
||||||
:confine-to xcb:Window:None
|
:confine-to xcb:Window:None
|
||||||
:cursor cursor
|
:cursor cursor
|
||||||
:time xcb:Time:CurrentTime))
|
:time xcb:Time:CurrentTime)))))))
|
||||||
(setq exwm-floating--moveresize-id frame-id
|
|
||||||
exwm-floating--moveresize-type type))))))
|
|
||||||
|
|
||||||
(defun exwm-floating--stop-moveresize (&rest args)
|
(defun exwm-floating--stop-moveresize (&rest args)
|
||||||
"Stop move/resize."
|
"Stop move/resize."
|
||||||
(xcb:+request exwm--connection
|
(xcb:+request exwm--connection
|
||||||
(make-instance 'xcb:UngrabPointer :time xcb:Time:CurrentTime))
|
(make-instance 'xcb:UngrabPointer :time xcb:Time:CurrentTime))
|
||||||
(xcb:flush exwm--connection)
|
(xcb:flush exwm--connection)
|
||||||
(setq exwm-floating--moveresize-id nil
|
(setq exwm-floating--moveresize-calculate nil))
|
||||||
exwm-floating--moveresize-type nil
|
|
||||||
exwm-floating--moveresize-delta nil))
|
|
||||||
|
|
||||||
(defun exwm-floating--do-moveresize (data synthetic)
|
(defun exwm-floating--do-moveresize (data synthetic)
|
||||||
"Perform move/resize."
|
"Perform move/resize."
|
||||||
(let ((mask 0) (x 0) (y 0) (width 0) (height 0)
|
(when exwm-floating--moveresize-calculate
|
||||||
(delta exwm-floating--moveresize-delta)
|
(let ((obj (make-instance 'xcb:MotionNotify))
|
||||||
obj root-x root-y)
|
result)
|
||||||
(when (and exwm-floating--moveresize-id exwm-floating--moveresize-type)
|
|
||||||
(setq obj (make-instance 'xcb:MotionNotify))
|
|
||||||
(xcb:unmarshal obj data)
|
(xcb:unmarshal obj data)
|
||||||
(setq root-x (slot-value obj 'root-x)
|
(setq result (funcall exwm-floating--moveresize-calculate
|
||||||
root-y (slot-value obj 'root-y))
|
(slot-value obj 'root-x) (slot-value obj 'root-y)))
|
||||||
;; Perform move/resize according to the previously set type
|
|
||||||
(cond ((= exwm-floating--moveresize-type
|
|
||||||
xcb:ewmh:_NET_WM_MOVERESIZE_MOVE)
|
|
||||||
(setq mask (logior xcb:ConfigWindow:X xcb:ConfigWindow:Y)
|
|
||||||
x (- root-x (elt delta 0))
|
|
||||||
y (- root-y (elt delta 1))))
|
|
||||||
((= exwm-floating--moveresize-type
|
|
||||||
xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_TOPLEFT)
|
|
||||||
(setq mask
|
|
||||||
(logior xcb:ConfigWindow:X xcb:ConfigWindow:Y
|
|
||||||
xcb:ConfigWindow:Width xcb:ConfigWindow:Height)
|
|
||||||
x (- root-x (elt delta 0))
|
|
||||||
y (- root-y (elt delta 1))
|
|
||||||
width (- (elt delta 2) root-x)
|
|
||||||
height (- (elt delta 3) root-y)))
|
|
||||||
((= exwm-floating--moveresize-type
|
|
||||||
xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_TOP)
|
|
||||||
(setq mask (logior xcb:ConfigWindow:Y xcb:ConfigWindow:Height)
|
|
||||||
y (- root-y (elt delta 1))
|
|
||||||
height (- (elt delta 3) root-y)))
|
|
||||||
((= exwm-floating--moveresize-type
|
|
||||||
xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_TOPRIGHT)
|
|
||||||
(setq mask
|
|
||||||
(logior xcb:ConfigWindow:Y
|
|
||||||
xcb:ConfigWindow:Width xcb:ConfigWindow:Height)
|
|
||||||
y (- root-y (elt delta 1))
|
|
||||||
width (- root-x (elt delta 2))
|
|
||||||
height (- (elt delta 3) root-y)))
|
|
||||||
((= exwm-floating--moveresize-type
|
|
||||||
xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_RIGHT)
|
|
||||||
(setq mask (logior xcb:ConfigWindow:Width)
|
|
||||||
width (- root-x (elt delta 2))))
|
|
||||||
((= exwm-floating--moveresize-type
|
|
||||||
xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT)
|
|
||||||
(setq mask
|
|
||||||
(logior xcb:ConfigWindow:Width xcb:ConfigWindow:Height)
|
|
||||||
width (- root-x (elt delta 2))
|
|
||||||
height (- root-y (elt delta 3))))
|
|
||||||
((= exwm-floating--moveresize-type
|
|
||||||
xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_BOTTOM)
|
|
||||||
(setq mask (logior xcb:ConfigWindow:Height)
|
|
||||||
height (- root-y (elt delta 3))))
|
|
||||||
((= exwm-floating--moveresize-type
|
|
||||||
xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT)
|
|
||||||
(setq mask
|
|
||||||
(logior xcb:ConfigWindow:X
|
|
||||||
xcb:ConfigWindow:Width xcb:ConfigWindow:Height)
|
|
||||||
x (- root-x (elt delta 0))
|
|
||||||
width (- (elt delta 2) root-x)
|
|
||||||
height (- root-y (elt delta 3))))
|
|
||||||
((= exwm-floating--moveresize-type
|
|
||||||
xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_LEFT)
|
|
||||||
(setq mask
|
|
||||||
(logior xcb:ConfigWindow:X xcb:ConfigWindow:Width)
|
|
||||||
x (- root-x (elt delta 0))
|
|
||||||
width (- (elt delta 2) root-x))))
|
|
||||||
(xcb:+request exwm--connection
|
(xcb:+request exwm--connection
|
||||||
(make-instance 'xcb:ConfigureWindow
|
(make-instance 'xcb:ConfigureWindow
|
||||||
:window exwm-floating--moveresize-id :value-mask mask
|
:window (elt result 0) :value-mask (elt result 1)
|
||||||
:x x :y y :width width :height height))
|
:x (elt result 2) :y (elt result 3)
|
||||||
|
:width (elt result 4) :height (elt result 5)))
|
||||||
(xcb:flush exwm--connection))))
|
(xcb:flush exwm--connection))))
|
||||||
|
|
||||||
;; Cursors for moving/resizing a window
|
;; Cursors for moving/resizing a window
|
||||||
|
|
Loading…
Reference in a new issue