1
;; contrib/wmresize.jl -- wm-like resize/move boxes
5
;; Copyright (C) 2002 Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
7
;; http://merlin.org/sawfish/
9
;; This is free software; you can redistribute it and/or modify it
10
;; under the terms of the GNU General Public License as published by
11
;; the Free Software Foundation; either version 2, or (at your option)
14
;; This is distributed in the hope that it will be useful, but
15
;; WITHOUT ANY WARRANTY; without even the implied warranty of
16
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
;; GNU General Public License for more details.
19
;; You should have received a copy of the GNU General Public License
20
;; along with sawfish; see the file COPYING. If not, write to
21
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27
;; Create a directory ~/.sawfish/lisp/contrib and then put this file there:
28
;; mkdir -p ~/.sawfish/lisp/contrib
29
;; mv wmresize.jl ~/.sawfish/lisp/contrib
31
;; Then add to your .sawfishrc:
32
;; (require 'contrib.wmresize)
34
;; Then restart sawfish and go to Customize->Move/Resize and select
35
;; the dimension animation mode.
37
;; The appearance of the animation mode can be customized under
38
;; Customize->Move/Resize->Ugliness.
40
(define-structure contrib.wmresize
50
sawfish.wm.util.window-outline)
52
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
53
;; move-resize basic ugliness settings
54
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
56
(defgroup move-ugliness "Ugliness" :group move)
58
(defcustom ugly-move-resize-dim-font default-font
59
"Font for move/resize dimension marks."
61
:group (move move-ugliness))
63
(defcustom ugly-dim-text-shift 0
64
"Y-axis position correction for dimension text."
67
:group (move move-ugliness))
69
(defcustom ugly-dim-offset 3
73
:group (move move-ugliness))
75
(defcustom ugly-dim-width 16
79
:group (move move-ugliness))
81
(defcustom ugly-dim-arrow-size (cons 4 8)
82
"Dimension arrow size."
83
:type (pair (labelled "Width:" (number 0 100)) (labelled "Length:" (number 0 100)))
84
:group (move move-ugliness))
86
(if (not (memq 'dimension (custom-get-options 'move-outline-mode)))
87
(custom-add-option 'move-outline-mode 'dimension))
88
(if (not (memq 'dimension (custom-get-options 'resize-outline-mode)))
89
(custom-add-option 'resize-outline-mode 'dimension))
91
(define (draw-dim-outline x y width height)
92
(require 'sawfish.wm.util.x)
93
(require 'sawfish.wm.fonts)
94
(let ((gc (x-create-root-xor-gc))
95
(wtext (format nil "%d" width))
96
(htext (format nil "%d" height))
97
(htwidth) (wtwidth) (dim) (halfdim)
99
(halfdimoff) (w-orig-y) (h-orig-x)
100
(arrw (car ugly-dim-arrow-size)) (arrl (cdr ugly-dim-arrow-size))
101
(fheight (font-height ugly-move-resize-dim-font))
104
(x-draw-rectangle 'root gc (cons x y) (cons width height))
106
(setq wtwidth (text-width wtext ugly-move-resize-dim-font))
107
(setq htwidth (text-width htext ugly-move-resize-dim-font))
108
(setq dim ugly-dim-width)
109
(setq halfdim (round (/ dim 2)))
110
(setq halfdimoff (+ halfdim off))
112
;; check where to draw (top/bottom, left/right)
113
(if (> (+ dim off) y) (setq w-orig-y (+ y height dim (* off 2))) (setq w-orig-y y) )
114
(if (> (+ dim off) x) (setq h-orig-x (+ x width dim (* off 2))) (setq h-orig-x x) )
116
;; horizontal dimension
117
(if (or (> (+ wtwidth 2 (* arrl 2)) width) (> w-orig-y (screen-height))) (setq wtwidth 0)
118
(x-draw-line 'root gc (cons x (- w-orig-y off)) (cons x (- w-orig-y off dim)) )
119
(x-draw-line 'root gc (cons (+ x width -1) (- w-orig-y off)) (cons (+ x width -1) (- w-orig-y off dim)) )
121
(x-draw-string 'root gc (cons
122
(round (+ x (- (/ width 2) (/ wtwidth 2))))
123
(round (+ (- w-orig-y halfdimoff) (/ fheight 2) ugly-dim-text-shift))) wtext ugly-move-resize-dim-font)
125
(x-draw-line 'root gc
126
(cons x (- w-orig-y halfdimoff))
127
(cons (round (+ x (- (/ width 2) (/ wtwidth 2) 2) ) ) (- w-orig-y halfdimoff) )
130
(x-draw-line 'root gc
131
(cons (round (+ x (+ (/ width 2) (/ wtwidth 2) 2 ) ) ) (- w-orig-y halfdimoff) )
132
(cons (+ x width) (- w-orig-y halfdimoff))
135
(x-draw-line 'root gc (cons (+ x arrl) (- w-orig-y (+ halfdimoff arrw)))
136
(cons x (- w-orig-y halfdimoff)))
137
(x-draw-line 'root gc (cons (+ x arrl) (- w-orig-y (- halfdimoff arrw)))
138
(cons x (- w-orig-y halfdimoff)))
139
(x-draw-line 'root gc (cons (- (+ x width) arrl) (- w-orig-y (+ halfdimoff arrw)))
140
(cons (+ x width) (- w-orig-y (+ halfdim off))))
141
(x-draw-line 'root gc (cons (- (+ x width) arrl) (- w-orig-y (- halfdimoff arrw)))
142
(cons (+ x width) (- w-orig-y halfdimoff)))
146
;; vertical dimension
147
(if (or (> (+ fheight 2 (* arrl 2)) height) (> h-orig-x (screen-width))) (setq fheight 0)
148
(x-draw-line 'root gc (cons (- h-orig-x off dim) y) (cons (- h-orig-x off) y) )
149
(x-draw-line 'root gc (cons (- h-orig-x off dim) (+ y height)) (cons (- h-orig-x off) (+ y height)) )
151
(x-draw-string 'root gc (cons
152
(round (- h-orig-x (/ htwidth 2) halfdimoff))
153
(round (+ y (/ height 2) (/ fheight 2) ugly-dim-text-shift))) htext ugly-move-resize-dim-font)
155
(x-draw-line 'root gc
156
(cons (- h-orig-x halfdimoff) y)
157
(cons (- h-orig-x halfdimoff) (round (+ y (- (/ height 2) (/ fheight 2) 2 ) ) ) )
160
(x-draw-line 'root gc
161
(cons (- h-orig-x halfdimoff) (round (+ y (+ (/ height 2) (/ fheight 2) 2 ) ) ) )
162
(cons (- h-orig-x halfdimoff) (+ y height))
165
(x-draw-line 'root gc (cons (- h-orig-x (+ halfdimoff arrw)) (+ y arrl)) (cons (- h-orig-x halfdimoff) y))
166
(x-draw-line 'root gc (cons (- h-orig-x (- halfdimoff arrw)) (+ y arrl)) (cons (- h-orig-x halfdimoff) y))
167
(x-draw-line 'root gc (cons (- h-orig-x (+ halfdimoff arrw)) (- (+ y height) arrl))
168
(cons (- h-orig-x halfdimoff) (+ y height)))
169
(x-draw-line 'root gc (cons (- h-orig-x (- halfdimoff arrw)) (- (+ y height) arrl))
170
(cons (- h-orig-x halfdimoff) (+ y height)))
175
(define-window-outliner 'dimension draw-dim-outline))