]>
Dogcows Code - chaz/openbox/blob - openbox/actions/moveresizeto.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"
6 #include <stdlib.h> /* for atoi */
25 static gpointer
setup_func(xmlNodePtr node
);
26 static void free_func(gpointer o
);
27 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
28 /* 3.4-compatibility */
29 static gpointer
setup_center_func(xmlNodePtr node
);
31 void action_moveresizeto_startup(void)
33 actions_register("MoveResizeTo", setup_func
, free_func
, run_func
);
34 /* 3.4-compatibility */
35 actions_register("MoveToCenter", setup_center_func
, free_func
, run_func
);
38 static gpointer
setup_func(xmlNodePtr node
)
43 o
= g_slice_new0(Options
);
48 o
->monitor
= CURRENT_MONITOR
;
50 if ((n
= obt_xml_find_node(node
, "x")))
51 config_parse_gravity_coord(n
, &o
->x
);
53 if ((n
= obt_xml_find_node(node
, "y")))
54 config_parse_gravity_coord(n
, &o
->y
);
56 if ((n
= obt_xml_find_node(node
, "width"))) {
57 gchar
*s
= obt_xml_node_string(n
);
58 if (g_ascii_strcasecmp(s
, "current") != 0)
59 config_parse_relative_number(s
, &o
->w
, &o
->w_denom
);
62 if ((n
= obt_xml_find_node(node
, "height"))) {
63 gchar
*s
= obt_xml_node_string(n
);
64 if (g_ascii_strcasecmp(s
, "current") != 0)
65 config_parse_relative_number(s
, &o
->h
, &o
->h_denom
);
69 if ((n
= obt_xml_find_node(node
, "monitor"))) {
70 gchar
*s
= obt_xml_node_string(n
);
71 if (g_ascii_strcasecmp(s
, "current") != 0) {
72 if (!g_ascii_strcasecmp(s
, "all"))
73 o
->monitor
= ALL_MONITORS
;
74 else if(!g_ascii_strcasecmp(s
, "next"))
75 o
->monitor
= NEXT_MONITOR
;
76 else if(!g_ascii_strcasecmp(s
, "prev"))
77 o
->monitor
= PREV_MONITOR
;
79 o
->monitor
= obt_xml_node_int(n
) - 1;
87 static void free_func(gpointer o
)
89 g_slice_free(Options
, o
);
92 /* Always return FALSE because its not interactive */
93 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
101 gint x
, y
, lw
, lh
, w
, h
;
105 cmon
= client_monitor(c
);
107 case CURRENT_MONITOR
:
110 mon
= SCREEN_AREA_ALL_MONITORS
; break;
112 mon
= (cmon
+ 1 > screen_num_monitors
- 1) ? 0 : (cmon
+ 1); break;
114 mon
= (cmon
== 0) ? (screen_num_monitors
- 1) : (cmon
- 1); break;
116 g_assert_not_reached();
119 area
= screen_area(c
->desktop
, mon
, NULL
);
120 carea
= screen_area(c
->desktop
, cmon
, NULL
);
123 if (w
== G_MININT
) w
= c
->area
.width
;
124 else if (o
->w_denom
) w
= (w
* area
->width
) / o
->w_denom
;
127 if (h
== G_MININT
) h
= c
->area
.height
;
128 else if (o
->h_denom
) h
= (h
* area
->height
) / o
->h_denom
;
130 /* it might not be able to resize how they requested, so find out what
131 it will actually be resized to */
134 client_try_configure(c
, &x
, &y
, &w
, &h
, &lw
, &lh
, TRUE
);
136 /* get the frame's size */
137 w
+= c
->frame
->size
.left
+ c
->frame
->size
.right
;
138 h
+= c
->frame
->size
.top
+ c
->frame
->size
.bottom
;
142 x
= (x
* area
->width
) / o
->x
.denom
;
143 if (o
->x
.center
) x
= (area
->width
- w
) / 2;
144 else if (x
== G_MININT
) x
= c
->frame
->area
.x
- carea
->x
;
145 else if (o
->x
.opposite
) x
= area
->width
- w
- x
;
150 y
= (y
* area
->height
) / o
->y
.denom
;
151 if (o
->y
.center
) y
= (area
->height
- h
) / 2;
152 else if (y
== G_MININT
) y
= c
->frame
->area
.y
- carea
->y
;
153 else if (o
->y
.opposite
) y
= area
->height
- h
- y
;
156 /* get the client's size back */
157 w
-= c
->frame
->size
.left
+ c
->frame
->size
.right
;
158 h
-= c
->frame
->size
.top
+ c
->frame
->size
.bottom
;
160 frame_frame_gravity(c
->frame
, &x
, &y
); /* get the client coords */
161 client_try_configure(c
, &x
, &y
, &w
, &h
, &lw
, &lh
, TRUE
);
162 /* force it on screen if its moving to another monitor */
163 client_find_onscreen(c
, &x
, &y
, w
, h
, mon
!= cmon
);
165 actions_client_move(data
, TRUE
);
166 client_configure(c
, x
, y
, w
, h
, TRUE
, TRUE
, FALSE
);
167 actions_client_move(data
, FALSE
);
169 g_slice_free(Rect
, area
);
170 g_slice_free(Rect
, carea
);
176 /* 3.4-compatibility */
177 static gpointer
setup_center_func(xmlNodePtr node
)
181 o
= g_slice_new0(Options
);
This page took 0.042893 seconds and 5 git commands to generate.