]>
Dogcows Code - chaz/openbox/blob - placement.c
18c9c39b615895cb9e4b3d0971dd83012269478a
1 #include "kernel/dispatch.h"
2 #include "kernel/client.h"
3 #include "kernel/group.h"
4 #include "kernel/frame.h"
5 #include "kernel/screen.h"
6 #include "kernel/openbox.h"
7 #include "parser/parse.h"
11 static gboolean history
;
13 static void parse_xml(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
, void *d
)
17 node
= node
->xmlChildrenNode
;
18 if ((n
= parse_find_node("remember", node
)))
19 history
= parse_bool(doc
, n
);
22 void plugin_setup_config(ObParseInst
*i
)
26 parse_register(i
, "placement", parse_xml
, NULL
);
29 static Rect
* pick_head(ObClient
*c
)
31 /* try direct parent first */
32 if (c
->transient_for
&& c
->transient_for
!= OB_TRAN_GROUP
) {
33 return screen_area_monitor(c
->desktop
,
34 client_monitor(c
->transient_for
));
37 /* more than one guy in his group (more than just him) */
38 if (c
->group
&& c
->group
->members
->next
) {
41 /* try on the client's desktop */
42 for (it
= c
->group
->members
; it
; it
= g_slist_next(it
)) {
43 ObClient
*itc
= it
->data
;
45 (itc
->desktop
== c
->desktop
||
46 itc
->desktop
== DESKTOP_ALL
|| c
->desktop
== DESKTOP_ALL
))
47 return screen_area_monitor(c
->desktop
,
48 client_monitor(it
->data
));
51 /* try on all desktops */
52 for (it
= c
->group
->members
; it
; it
= g_slist_next(it
)) {
53 ObClient
*itc
= it
->data
;
55 return screen_area_monitor(c
->desktop
,
56 client_monitor(it
->data
));
63 static void place_random(ObClient
*c
)
69 if (ob_state() == OB_STATE_STARTING
) return;
73 area
= screen_area_monitor(c
->desktop
,
74 g_random_int_range(0, screen_num_monitors
));
78 r
= area
->x
+ area
->width
- c
->frame
->area
.width
;
79 b
= area
->y
+ area
->height
- c
->frame
->area
.height
;
81 if (r
> l
) x
= g_random_int_range(l
, r
+ 1);
83 if (b
> t
) y
= g_random_int_range(t
, b
+ 1);
86 frame_frame_gravity(c
->frame
, &x
, &y
); /* get where the client should be */
87 client_configure(c
, OB_CORNER_TOPLEFT
, x
, y
, c
->area
.width
, c
->area
.height
,
91 static void event(ObEvent
*e
, void *foo
)
93 g_assert(e
->type
== Event_Client_New
);
95 /* requested a position */
96 if (e
->data
.c
.client
->positioned
) return;
98 if (e
->data
.c
.client
->transient_for
) {
99 if (e
->data
.c
.client
->transient_for
!= OB_TRAN_GROUP
) {
100 ObClient
*c
= e
->data
.c
.client
;
101 ObClient
*p
= e
->data
.c
.client
->transient_for
;
102 int x
= (p
->frame
->area
.width
- c
->frame
->area
.width
) / 2 +
104 int y
= (p
->frame
->area
.height
- c
->frame
->area
.height
) / 2 +
106 client_configure(c
, OB_CORNER_TOPLEFT
, x
, y
,
107 c
->area
.width
, c
->area
.height
,
112 ObClient
*c
= e
->data
.c
.client
;
113 gboolean first
= TRUE
;
115 for (it
= c
->group
->members
; it
; it
= it
->next
) {
116 ObClient
*m
= it
->data
;
117 if (!(m
== c
|| m
->transient_for
)) {
119 l
= m
->frame
->area
.x
;
120 t
= m
->frame
->area
.y
;
121 r
= m
->frame
->area
.x
+ m
->frame
->area
.width
- 1;
122 b
= m
->frame
->area
.y
+ m
->frame
->area
.height
- 1;
125 l
= MIN(l
, m
->frame
->area
.x
);
126 t
= MIN(t
, m
->frame
->area
.y
);
127 r
= MAX(r
, m
->frame
->area
.x
+m
->frame
->area
.width
- 1);
128 b
= MAX(b
, m
->frame
->area
.y
+m
->frame
->area
.height
-1);
133 int x
= ((r
+ 1 - l
) - c
->frame
->area
.width
) / 2 + l
;
134 int y
= ((b
+ 1 - t
) - c
->frame
->area
.height
) / 2 + t
;
135 client_configure(c
, OB_CORNER_TOPLEFT
, x
, y
,
136 c
->area
.width
, c
->area
.height
,
143 /* center parentless dialogs on the screen */
144 if (e
->data
.c
.client
->type
== OB_CLIENT_TYPE_DIALOG
) {
146 ObClient
*c
= e
->data
.c
.client
;
151 area
= screen_area_monitor(c
->desktop
, 0);
153 x
= (area
->width
- c
->frame
->area
.width
) / 2 + area
->x
;
154 y
= (area
->height
- c
->frame
->area
.height
) / 2 + area
->y
;
155 client_configure(c
, OB_CORNER_TOPLEFT
, x
, y
,
156 c
->area
.width
, c
->area
.height
,
161 if (!history
|| !place_history(e
->data
.c
.client
))
162 place_random(e
->data
.c
.client
);
165 void plugin_startup()
167 dispatch_register(Event_Client_New
, (EventHandler
)event
, NULL
);
172 void plugin_shutdown()
174 dispatch_register(0, (EventHandler
)event
, NULL
);
This page took 0.039961 seconds and 3 git commands to generate.