]>
Dogcows Code - chaz/openbox/blob - openbox/actions/moveresizeto.c
acad73b50a578c91acad4d297936594868eb6f98
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(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
);
27 static void free_func(gpointer options
);
28 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
30 void action_moveresizeto_startup(void)
32 actions_register("MoveResizeTo",
39 static void parse_coord(xmlDocPtr doc
, xmlNodePtr n
, gint
*pos
,
40 gboolean
*opposite
, gboolean
*center
)
42 gchar
*s
= parse_string(doc
, n
);
43 if (g_ascii_strcasecmp(s
, "current") != 0) {
44 if (!g_ascii_strcasecmp(s
, "center"))
49 if (s
[0] == '-' || s
[0] == '+')
58 static gpointer
setup_func(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
)
63 o
= g_new0(Options
, 1);
68 o
->monitor
= CURRENT_MONITOR
;
70 if ((n
= parse_find_node("x", node
)))
71 parse_coord(doc
, n
, &o
->x
, &o
->xopposite
, &o
->xcenter
);
73 if ((n
= parse_find_node("y", node
)))
74 parse_coord(doc
, n
, &o
->y
, &o
->yopposite
, &o
->ycenter
);
76 if ((n
= parse_find_node("width", node
))) {
77 gchar
*s
= parse_string(doc
, n
);
78 if (g_ascii_strcasecmp(s
, "current") != 0)
79 o
->w
= parse_int(doc
, n
);
82 if ((n
= parse_find_node("height", node
))) {
83 gchar
*s
= parse_string(doc
, n
);
84 if (g_ascii_strcasecmp(s
, "current") != 0)
85 o
->h
= parse_int(doc
, n
);
89 if ((n
= parse_find_node("monitor", node
))) {
90 gchar
*s
= parse_string(doc
, n
);
91 if (g_ascii_strcasecmp(s
, "current") != 0) {
92 if (!g_ascii_strcasecmp(s
, "all"))
93 o
->monitor
= ALL_MONITORS
;
94 else if(!g_ascii_strcasecmp(s
, "next"))
95 o
->monitor
= NEXT_MONITOR
;
96 else if(!g_ascii_strcasecmp(s
, "prev"))
97 o
->monitor
= PREV_MONITOR
;
99 o
->monitor
= parse_int(doc
, n
) - 1;
107 static void free_func(gpointer options
)
109 Options
*o
= options
;
114 /* Always return FALSE because its not interactive */
115 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
117 Options
*o
= options
;
123 gint x
, y
, lw
, lh
, w
, h
;
127 cmon
= client_monitor(c
);
128 if (mon
== CURRENT_MONITOR
) mon
= cmon
;
129 else if (mon
== ALL_MONITORS
) mon
= SCREEN_AREA_ALL_MONITORS
;
130 else if (mon
== NEXT_MONITOR
) mon
= (cmon
+ 1 > screen_num_monitors
- 1) ? 0 : (cmon
+ 1);
131 else if (mon
== PREV_MONITOR
) mon
= (cmon
== 0) ? (screen_num_monitors
- 1) : (cmon
- 1);
133 area
= screen_area(c
->desktop
, mon
, NULL
);
134 carea
= screen_area(c
->desktop
, cmon
, NULL
);
137 if (w
== G_MININT
) w
= c
->area
.width
;
140 if (h
== G_MININT
) h
= c
->area
.height
;
142 /* it might not be able to resize how they requested, so find out what
143 it will actually be resized to */
146 client_try_configure(c
, &x
, &y
, &w
, &h
, &lw
, &lh
, TRUE
);
148 /* get the frame's size */
149 w
+= c
->frame
->size
.left
+ c
->frame
->size
.right
;
150 h
+= c
->frame
->size
.top
+ c
->frame
->size
.bottom
;
153 if (o
->xcenter
) x
= (area
->width
- w
) / 2;
154 else if (x
== G_MININT
) x
= c
->frame
->area
.x
- carea
->x
;
155 else if (o
->xopposite
) x
= area
->width
- w
- x
;
159 if (o
->ycenter
) y
= (area
->height
- h
) / 2;
160 else if (y
== G_MININT
) y
= c
->frame
->area
.y
- carea
->y
;
161 else if (o
->yopposite
) y
= area
->height
- h
- y
;
164 /* get the client's size back */
165 w
-= c
->frame
->size
.left
+ c
->frame
->size
.right
;
166 h
-= c
->frame
->size
.top
+ c
->frame
->size
.bottom
;
168 frame_frame_gravity(c
->frame
, &x
, &y
); /* get the client coords */
169 client_try_configure(c
, &x
, &y
, &w
, &h
, &lw
, &lh
, TRUE
);
170 /* force it on screen if its moving to another monitor */
171 client_find_onscreen(c
, &x
, &y
, w
, h
, mon
!= cmon
);
173 actions_client_move(data
, TRUE
);
174 client_configure(c
, x
, y
, w
, h
, TRUE
, TRUE
, FALSE
);
175 actions_client_move(data
, FALSE
);
This page took 0.03961 seconds and 4 git commands to generate.