1 #include "openbox/actions.h"
2 #include "openbox/client.h"
3 #include "openbox/screen.h"
4 #include "openbox/frame.h"
5 #include "openbox/config.h"
18 static gpointer
setup_func(xmlNodePtr node
);
19 static void free_func(gpointer options
);
20 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
22 void action_resizerelative_startup(void)
24 actions_register("ResizeRelative", setup_func
, free_func
, run_func
);
27 static void xml_node_relative(xmlNodePtr n
, gint
*num
, gint
*denom
)
31 s
= obt_xml_node_string(n
);
32 config_parse_relative_number(s
, num
, denom
);
36 static gpointer
setup_func(xmlNodePtr node
)
41 o
= g_slice_new0(Options
);
43 if ((n
= obt_xml_find_node(node
, "left")))
44 xml_node_relative(n
, &o
->left
, &o
->left_denom
);
45 if ((n
= obt_xml_find_node(node
, "right")))
46 xml_node_relative(n
, &o
->right
, &o
->right_denom
);
47 if ((n
= obt_xml_find_node(node
, "top")) ||
48 (n
= obt_xml_find_node(node
, "up")))
49 xml_node_relative(n
, &o
->top
, &o
->top_denom
);
50 if ((n
= obt_xml_find_node(node
, "bottom")) ||
51 (n
= obt_xml_find_node(node
, "down")))
52 xml_node_relative(n
, &o
->bottom
, &o
->bottom_denom
);
57 static void free_func(gpointer o
)
59 g_slice_free(Options
, o
);
62 /* Always return FALSE because its not interactive */
63 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
68 ObClient
*c
= data
->client
;
69 gint x
, y
, ow
, xoff
, nw
, oh
, yoff
, nh
, lw
, lh
;
70 gint left
= o
->left
, right
= o
->right
, top
= o
->top
, bottom
= o
->bottom
;
73 left
= left
* c
->area
.width
/ o
->left_denom
;
75 right
= right
* c
->area
.width
/ o
->right_denom
;
77 top
= top
* c
->area
.height
/ o
->top_denom
;
79 bottom
= bottom
* c
->area
.height
/ o
->bottom_denom
;
81 // When resizing, if the resize has a non-zero value then make sure it
82 // is at least as big as the size increment so the window does actually
87 xoff
= -MAX(left
, (left
? c
->size_inc
.width
: 0));
88 nw
= ow
+ MAX(right
+ left
, (right
+ left
? c
->size_inc
.width
: 0));
90 yoff
= -MAX(top
, (top
? c
->size_inc
.height
: 0));
91 nh
= oh
+ MAX(bottom
+ top
, (bottom
+ top
? c
->size_inc
.height
: 0));
93 client_try_configure(c
, &x
, &y
, &nw
, &nh
, &lw
, &lh
, TRUE
);
94 xoff
= xoff
== 0 ? 0 :
95 (xoff
< 0 ? MAX(xoff
, ow
-nw
) : MIN(xoff
, ow
-nw
));
96 yoff
= yoff
== 0 ? 0 :
97 (yoff
< 0 ? MAX(yoff
, oh
-nh
) : MIN(yoff
, oh
-nh
));
99 actions_client_move(data
, TRUE
);
100 client_move_resize(c
, x
+ xoff
, y
+ yoff
, nw
, nh
);
101 actions_client_move(data
, FALSE
);