]>
Dogcows Code - chaz/openbox/blob - openbox/actions/growtoedge.c
1 #include "openbox/actions.h"
2 #include "openbox/misc.h"
3 #include "openbox/client.h"
4 #include "openbox/frame.h"
5 #include "openbox/screen.h"
13 static gpointer
setup_func(xmlNodePtr node
);
14 static gpointer
setup_shrink_func(xmlNodePtr node
);
15 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
16 /* 3.4-compatibility */
17 static gpointer
setup_north_func(xmlNodePtr node
);
18 static gpointer
setup_south_func(xmlNodePtr node
);
19 static gpointer
setup_east_func(xmlNodePtr node
);
20 static gpointer
setup_west_func(xmlNodePtr node
);
22 void action_growtoedge_startup(void)
24 actions_register("GrowToEdge", setup_func
,
26 actions_register("ShrinkToEdge", setup_shrink_func
,
28 /* 3.4-compatibility */
29 actions_register("GrowToEdgeNorth", setup_north_func
, g_free
, run_func
);
30 actions_register("GrowToEdgeSouth", setup_south_func
, g_free
, run_func
);
31 actions_register("GrowToEdgeEast", setup_east_func
, g_free
, run_func
);
32 actions_register("GrowToEdgeWest", setup_west_func
, g_free
, run_func
);
35 static gpointer
setup_func(xmlNodePtr node
)
40 o
= g_new0(Options
, 1);
41 o
->dir
= OB_DIRECTION_NORTH
;
44 if ((n
= obt_parse_find_node(node
, "direction"))) {
45 gchar
*s
= obt_parse_node_string(n
);
46 if (!g_ascii_strcasecmp(s
, "north") ||
47 !g_ascii_strcasecmp(s
, "up"))
48 o
->dir
= OB_DIRECTION_NORTH
;
49 else if (!g_ascii_strcasecmp(s
, "south") ||
50 !g_ascii_strcasecmp(s
, "down"))
51 o
->dir
= OB_DIRECTION_SOUTH
;
52 else if (!g_ascii_strcasecmp(s
, "west") ||
53 !g_ascii_strcasecmp(s
, "left"))
54 o
->dir
= OB_DIRECTION_WEST
;
55 else if (!g_ascii_strcasecmp(s
, "east") ||
56 !g_ascii_strcasecmp(s
, "right"))
57 o
->dir
= OB_DIRECTION_EAST
;
64 static gpointer
setup_shrink_func(xmlNodePtr node
)
74 static gboolean
do_grow(ObActionsData
*data
, gint x
, gint y
, gint w
, gint h
)
76 gint realw
, realh
, lw
, lh
;
80 client_try_configure(data
->client
, &x
, &y
, &realw
, &realh
,
82 /* if it's going to be resized smaller than it intended, don't
83 move the window over */
84 if (x
!= data
->client
->area
.x
) x
+= w
- realw
;
85 if (y
!= data
->client
->area
.y
) y
+= h
- realh
;
87 if (x
!= data
->client
->area
.x
|| y
!= data
->client
->area
.y
||
88 realw
!= data
->client
->area
.width
||
89 realh
!= data
->client
->area
.height
)
91 actions_client_move(data
, TRUE
);
92 client_move_resize(data
->client
, x
, y
, realw
, realh
);
93 actions_client_move(data
, FALSE
);
99 /* Always return FALSE because its not interactive */
100 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
102 Options
*o
= options
;
108 /* don't allow vertical resize if shaded */
109 ((o
->dir
== OB_DIRECTION_NORTH
|| o
->dir
== OB_DIRECTION_SOUTH
) &&
110 data
->client
->shaded
))
117 client_find_resize_directional(data
->client
, o
->dir
, TRUE
,
119 if (do_grow(data
, x
, y
, w
, h
))
123 /* we couldn't grow, so try shrink! */
124 opp
= (o
->dir
== OB_DIRECTION_NORTH
? OB_DIRECTION_SOUTH
:
125 (o
->dir
== OB_DIRECTION_SOUTH
? OB_DIRECTION_NORTH
:
126 (o
->dir
== OB_DIRECTION_EAST
? OB_DIRECTION_WEST
:
127 OB_DIRECTION_EAST
)));
128 client_find_resize_directional(data
->client
, opp
, FALSE
,
131 case OB_DIRECTION_NORTH
:
132 half
= data
->client
->area
.y
+ data
->client
->area
.height
/ 2;
138 case OB_DIRECTION_SOUTH
:
139 half
= data
->client
->area
.height
/ 2;
143 case OB_DIRECTION_WEST
:
144 half
= data
->client
->area
.x
+ data
->client
->area
.width
/ 2;
150 case OB_DIRECTION_EAST
:
151 half
= data
->client
->area
.width
/ 2;
155 default: g_assert_not_reached();
157 if (do_grow(data
, x
, y
, w
, h
))
163 /* 3.4-compatibility */
164 static gpointer
setup_north_func(xmlNodePtr node
)
166 Options
*o
= g_new0(Options
, 1);
168 o
->dir
= OB_DIRECTION_NORTH
;
172 static gpointer
setup_south_func(xmlNodePtr node
)
174 Options
*o
= g_new0(Options
, 1);
176 o
->dir
= OB_DIRECTION_SOUTH
;
180 static gpointer
setup_east_func(xmlNodePtr node
)
182 Options
*o
= g_new0(Options
, 1);
184 o
->dir
= OB_DIRECTION_EAST
;
188 static gpointer
setup_west_func(xmlNodePtr node
)
190 Options
*o
= g_new0(Options
, 1);
192 o
->dir
= OB_DIRECTION_WEST
;
This page took 0.042719 seconds and 4 git commands to generate.