]>
Dogcows Code - chaz/openbox/blob - moveresizeto.c
d355dafdc5c30ea0535c1b239a2a62275899e364
1 #include "openbox/actions.h"
2 #include "openbox/client.h"
3 #include "openbox/screen.h"
4 #include "openbox/frame.h"
5 #include <stdlib.h> /* for atoi */
24 static gpointer
setup_func(xmlNodePtr node
);
25 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
27 void action_moveresizeto_startup(void)
29 actions_register("MoveResizeTo", setup_func
, g_free
, run_func
, NULL
, NULL
);
32 static void parse_coord(xmlNodePtr n
, gint
*pos
,
33 gboolean
*opposite
, gboolean
*center
)
35 gchar
*s
= obt_parse_node_string(n
);
36 if (g_ascii_strcasecmp(s
, "current") != 0) {
37 if (!g_ascii_strcasecmp(s
, "center"))
42 if (s
[0] == '-' || s
[0] == '+')
51 static gpointer
setup_func(xmlNodePtr node
)
56 o
= g_new0(Options
, 1);
61 o
->monitor
= CURRENT_MONITOR
;
63 if ((n
= obt_parse_find_node(node
, "x")))
64 parse_coord(n
, &o
->x
, &o
->xopposite
, &o
->xcenter
);
66 if ((n
= obt_parse_find_node(node
, "y")))
67 parse_coord(n
, &o
->y
, &o
->yopposite
, &o
->ycenter
);
69 if ((n
= obt_parse_find_node(node
, "width"))) {
70 gchar
*s
= obt_parse_node_string(n
);
71 if (g_ascii_strcasecmp(s
, "current") != 0)
72 o
->w
= obt_parse_node_int(n
);
75 if ((n
= obt_parse_find_node(node
, "height"))) {
76 gchar
*s
= obt_parse_node_string(n
);
77 if (g_ascii_strcasecmp(s
, "current") != 0)
78 o
->h
= obt_parse_node_int(n
);
82 if ((n
= obt_parse_find_node(node
, "monitor"))) {
83 gchar
*s
= obt_parse_node_string(n
);
84 if (g_ascii_strcasecmp(s
, "current") != 0) {
85 if (!g_ascii_strcasecmp(s
, "all"))
86 o
->monitor
= ALL_MONITORS
;
88 o
->monitor
= obt_parse_node_int(n
) - 1;
96 /* Always return FALSE because its not interactive */
97 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
105 gint x
, y
, lw
, lh
, w
, h
;
109 cmon
= client_monitor(c
);
110 if (mon
== CURRENT_MONITOR
) mon
= cmon
;
111 else if (mon
== ALL_MONITORS
) mon
= SCREEN_AREA_ALL_MONITORS
;
112 area
= screen_area(c
->desktop
, mon
, NULL
);
113 carea
= screen_area(c
->desktop
, cmon
, NULL
);
116 if (w
== G_MININT
) w
= c
->area
.width
;
119 if (h
== G_MININT
) h
= c
->area
.height
;
121 /* it might not be able to resize how they requested, so find out what
122 it will actually be resized to */
125 client_try_configure(c
, &x
, &y
, &w
, &h
, &lw
, &lh
, TRUE
);
127 /* get the frame's size */
128 w
+= c
->frame
->size
.left
+ c
->frame
->size
.right
;
129 h
+= c
->frame
->size
.top
+ c
->frame
->size
.bottom
;
132 if (o
->xcenter
) x
= (area
->width
- w
) / 2;
133 else if (x
== G_MININT
) x
= c
->frame
->area
.x
- carea
->x
;
134 else if (o
->xopposite
) x
= area
->width
- w
;
138 if (o
->ycenter
) y
= (area
->height
- h
) / 2;
139 else if (y
== G_MININT
) y
= c
->frame
->area
.y
- carea
->y
;
140 else if (o
->yopposite
) y
= area
->height
- h
;
143 /* get the client's size back */
144 w
-= c
->frame
->size
.left
+ c
->frame
->size
.right
;
145 h
-= c
->frame
->size
.top
+ c
->frame
->size
.bottom
;
147 frame_frame_gravity(c
->frame
, &x
, &y
); /* get the client coords */
148 client_try_configure(c
, &x
, &y
, &w
, &h
, &lw
, &lh
, TRUE
);
149 /* force it on screen if its moving to another monitor */
150 client_find_onscreen(c
, &x
, &y
, w
, h
, mon
!= cmon
);
152 actions_client_move(data
, TRUE
);
153 client_configure(c
, x
, y
, w
, h
, TRUE
, TRUE
, FALSE
);
154 actions_client_move(data
, FALSE
);
This page took 0.042511 seconds and 3 git commands to generate.