1 #include "openbox/actions.h"
2 #include "openbox/moveresize.h"
3 #include "openbox/client.h"
4 #include "openbox/frame.h"
8 gboolean corner_specified
;
12 static gpointer
setup_func(xmlNodePtr node
);
13 static void free_func(gpointer o
);
14 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
16 static guint32
pick_corner(gint x
, gint y
, gint cx
, gint cy
, gint cw
, gint ch
,
19 void action_resize_startup(void)
21 actions_register("Resize", setup_func
, free_func
, run_func
);
24 static gpointer
setup_func(xmlNodePtr node
)
29 o
= g_slice_new0(Options
);
31 if ((n
= obt_xml_find_node(node
, "edge"))) {
32 gchar
*s
= obt_xml_node_string(n
);
34 o
->corner_specified
= TRUE
;
35 if (!g_ascii_strcasecmp(s
, "top"))
36 o
->corner
= OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP
);
37 else if (!g_ascii_strcasecmp(s
, "bottom"))
38 o
->corner
= OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM
);
39 else if (!g_ascii_strcasecmp(s
, "left"))
40 o
->corner
= OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT
);
41 else if (!g_ascii_strcasecmp(s
, "right"))
42 o
->corner
= OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT
);
43 else if (!g_ascii_strcasecmp(s
, "topleft"))
44 o
->corner
= OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT
);
45 else if (!g_ascii_strcasecmp(s
, "topright"))
46 o
->corner
= OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT
);
47 else if (!g_ascii_strcasecmp(s
, "bottomleft"))
48 o
->corner
= OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
);
49 else if (!g_ascii_strcasecmp(s
, "bottomright"))
50 o
->corner
= OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
);
52 o
->corner_specified
= FALSE
;
59 static void free_func(gpointer o
)
61 g_slice_free(Options
, o
);
64 /* Always return FALSE because its not interactive */
65 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
70 ObClient
*c
= data
->client
;
74 corner
= OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD
);
75 else if (o
->corner_specified
)
76 corner
= o
->corner
; /* it was specified in the binding */
78 corner
= pick_corner(data
->x
, data
->y
,
79 c
->frame
->area
.x
, c
->frame
->area
.y
,
80 /* use the client size because the frame
81 can be differently sized (shaded
82 windows) and we want this based on the
84 c
->area
.width
+ c
->frame
->size
.left
+
86 c
->area
.height
+ c
->frame
->size
.top
+
87 c
->frame
->size
.bottom
, c
->shaded
);
89 moveresize_start(c
, data
->x
, data
->y
, data
->button
, corner
);
95 static guint32
pick_corner(gint x
, gint y
, gint cx
, gint cy
, gint cw
, gint ch
,
98 /* let's make x and y client relative instead of screen relative */
100 y
= ch
- (y
- cy
); /* y is inverted, 0 is at the bottom of the window */
103 #define A -4*X + 7*ch/3
104 #define B 4*X -15*ch/9
105 #define C -X/4 + 2*ch/3
106 #define D X/4 + 5*ch/12
108 #define F -X/4 + 7*ch/12
109 #define G 4*X - 4*ch/3
110 #define H -4*X + 8*ch/3
111 #define a (y > 5*ch/9)
112 #define b (x < 4*cw/9)
113 #define c (x > 5*cw/9)
114 #define d (y < 4*ch/9)
117 Each of these defines (except X which is just there for fun), represents
118 the equation of a line. The lines they represent are shown in the diagram
119 below. Checking y against these lines, we are able to choose a region
120 of the window as shown.
122 +---------------------A-------|-------|-------B---------------------+
129 | northwest | A north B | northeast |
132 C---------------------+----A--+-------+--B----+---------------------D
133 |CCCCCCC | A B | DDDDDDD|
134 | CCCCCCCC | A | | B | DDDDDDDD |
135 | CCCCCCC A B DDDDDDD |
136 - - - - - - - - - - - +CCCCCCC+aaaaaaa+DDDDDDD+ - - - - - - - - - - - -
138 | west | b move c | east | ad
140 - - - - - - - - - - - +EEEEEEE+ddddddd+FFFFFFF+- - - - - - - - - - - -
141 | EEEEEEE G H FFFFFFF |
142 | EEEEEEEE | G | | H | FFFFFFFF |
143 |EEEEEEE | G H | FFFFFFF|
144 E---------------------+----G--+-------+--H----+---------------------F
147 | southwest | G south H | southeast |
154 +---------------------G-------|-------|-------H---------------------+
158 /* for shaded windows, you can only resize west/east and move */
160 return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT
);
162 return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT
);
163 return OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE
);
167 return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT
);
168 else if (y
>= A
&& y
>= B
&& a
)
169 return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP
);
170 else if (y
< B
&& y
>= D
)
171 return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT
);
172 else if (y
< C
&& y
>= E
&& b
)
173 return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT
);
174 else if (y
< D
&& y
>= F
&& c
)
175 return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT
);
176 else if (y
< E
&& y
>= G
)
177 return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
);
178 else if (y
< G
&& y
< H
&& d
)
179 return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM
);
180 else if (y
>= H
&& y
< F
)
181 return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
);
183 return OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE
);