]>
Dogcows Code - chaz/openbox/blob - openbox/actions/resizerelative.c
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 if (left
&& ABS(left
) < c
->size_inc
.width
)
82 left
= left
< 0 ? -c
->size_inc
.width
: c
->size_inc
.width
;
83 if (right
&& ABS(right
) < c
->size_inc
.width
)
84 right
= right
< 0 ? -c
->size_inc
.width
: c
->size_inc
.width
;
85 if (top
&& ABS(top
) < c
->size_inc
.height
)
86 top
= top
< 0 ? -c
->size_inc
.height
: c
->size_inc
.height
;
87 if (bottom
&& ABS(bottom
) < c
->size_inc
.height
)
88 bottom
= bottom
< 0 ? -c
->size_inc
.height
: c
->size_inc
.height
;
90 /* When resizing, if the resize has a non-zero value then make sure it
91 is at least as big as the size increment so the window does actually
97 nw
= ow
+ right
+ left
;
100 nh
= oh
+ bottom
+ top
;
102 client_try_configure(c
, &x
, &y
, &nw
, &nh
, &lw
, &lh
, TRUE
);
103 xoff
= xoff
== 0 ? 0 :
104 (xoff
< 0 ? MAX(xoff
, ow
-nw
) : MIN(xoff
, ow
-nw
));
105 yoff
= yoff
== 0 ? 0 :
106 (yoff
< 0 ? MAX(yoff
, oh
-nh
) : MIN(yoff
, oh
-nh
));
108 actions_client_move(data
, TRUE
);
109 client_move_resize(c
, x
+ xoff
, y
+ yoff
, nw
, nh
);
110 actions_client_move(data
, FALSE
);
This page took 0.038804 seconds and 4 git commands to generate.