]>
Dogcows Code - chaz/openbox/blob - openbox/actions/moveresizeto.c
3ee3498a4cc3122c1c6dd054ff9ba918717ff6d9
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 */
26 static gpointer
setup_func(xmlNodePtr node
);
27 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
29 void action_moveresizeto_startup(void)
31 actions_register("MoveResizeTo", setup_func
, g_free
, run_func
, NULL
, NULL
);
34 static void parse_coord(xmlNodePtr n
, gint
*pos
,
35 gboolean
*opposite
, gboolean
*center
)
37 gchar
*s
= obt_parse_node_string(n
);
38 if (g_ascii_strcasecmp(s
, "current") != 0) {
39 if (!g_ascii_strcasecmp(s
, "center"))
44 if (s
[0] == '-' || s
[0] == '+')
53 static gpointer
setup_func(xmlNodePtr node
)
58 o
= g_new0(Options
, 1);
63 o
->monitor
= CURRENT_MONITOR
;
65 if ((n
= obt_parse_find_node(node
, "x")))
66 parse_coord(n
, &o
->x
, &o
->xopposite
, &o
->xcenter
);
68 if ((n
= obt_parse_find_node(node
, "y")))
69 parse_coord(n
, &o
->y
, &o
->yopposite
, &o
->ycenter
);
71 if ((n
= obt_parse_find_node(node
, "width"))) {
72 gchar
*s
= obt_parse_node_string(n
);
73 if (g_ascii_strcasecmp(s
, "current") != 0)
74 o
->w
= obt_parse_node_int(n
);
77 if ((n
= obt_parse_find_node(node
, "height"))) {
78 gchar
*s
= obt_parse_node_string(n
);
79 if (g_ascii_strcasecmp(s
, "current") != 0)
80 o
->h
= obt_parse_node_int(n
);
84 if ((n
= obt_parse_find_node(node
, "monitor"))) {
85 gchar
*s
= obt_parse_node_string(n
);
86 if (g_ascii_strcasecmp(s
, "current") != 0) {
87 if (!g_ascii_strcasecmp(s
, "all"))
88 o
->monitor
= ALL_MONITORS
;
89 else if(!g_ascii_strcasecmp(s
, "next"))
90 o
->monitor
= NEXT_MONITOR
;
91 else if(!g_ascii_strcasecmp(s
, "prev"))
92 o
->monitor
= PREV_MONITOR
;
94 o
->monitor
= obt_parse_node_int(n
) - 1;
102 /* Always return FALSE because its not interactive */
103 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
105 Options
*o
= options
;
111 gint x
, y
, lw
, lh
, w
, h
;
115 cmon
= client_monitor(c
);
116 if (mon
== CURRENT_MONITOR
) mon
= cmon
;
117 else if (mon
== ALL_MONITORS
) mon
= SCREEN_AREA_ALL_MONITORS
;
118 else if (mon
== NEXT_MONITOR
) mon
= (cmon
+ 1 > screen_num_monitors
- 1) ? 0 : (cmon
+ 1);
119 else if (mon
== PREV_MONITOR
) mon
= (cmon
== 0) ? (screen_num_monitors
- 1) : (cmon
- 1);
121 area
= screen_area(c
->desktop
, mon
, NULL
);
122 carea
= screen_area(c
->desktop
, cmon
, NULL
);
125 if (w
== G_MININT
) w
= c
->area
.width
;
128 if (h
== G_MININT
) h
= c
->area
.height
;
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
;
141 if (o
->xcenter
) x
= (area
->width
- w
) / 2;
142 else if (x
== G_MININT
) x
= c
->frame
->area
.x
- carea
->x
;
143 else if (o
->xopposite
) x
= area
->width
- w
- x
;
147 if (o
->ycenter
) y
= (area
->height
- h
) / 2;
148 else if (y
== G_MININT
) y
= c
->frame
->area
.y
- carea
->y
;
149 else if (o
->yopposite
) y
= area
->height
- h
- y
;
152 /* get the client's size back */
153 w
-= c
->frame
->size
.left
+ c
->frame
->size
.right
;
154 h
-= c
->frame
->size
.top
+ c
->frame
->size
.bottom
;
156 frame_frame_gravity(c
->frame
, &x
, &y
); /* get the client coords */
157 client_try_configure(c
, &x
, &y
, &w
, &h
, &lw
, &lh
, TRUE
);
158 /* force it on screen if its moving to another monitor */
159 client_find_onscreen(c
, &x
, &y
, w
, h
, mon
!= cmon
);
161 actions_client_move(data
, TRUE
);
162 client_configure(c
, x
, y
, w
, h
, TRUE
, TRUE
, FALSE
);
163 actions_client_move(data
, FALSE
);
This page took 0.038976 seconds and 3 git commands to generate.