1860dfc9aSClemens Zeidler /*
2860dfc9aSClemens Zeidler * Copyright 2010, Haiku.
3860dfc9aSClemens Zeidler * Distributed under the terms of the MIT License.
4860dfc9aSClemens Zeidler *
5860dfc9aSClemens Zeidler * Authors:
6860dfc9aSClemens Zeidler * Clemens Zeidler <haiku@clemens-zeidler.de>
7860dfc9aSClemens Zeidler */
8860dfc9aSClemens Zeidler
9a92ef26cSClemens Zeidler
10860dfc9aSClemens Zeidler #include "DesktopListener.h"
11860dfc9aSClemens Zeidler
12860dfc9aSClemens Zeidler
~DesktopListener()13860dfc9aSClemens Zeidler DesktopListener::~DesktopListener()
14860dfc9aSClemens Zeidler {
15860dfc9aSClemens Zeidler
16860dfc9aSClemens Zeidler }
17860dfc9aSClemens Zeidler
18860dfc9aSClemens Zeidler
DesktopObservable()19860dfc9aSClemens Zeidler DesktopObservable::DesktopObservable()
20860dfc9aSClemens Zeidler :
21860dfc9aSClemens Zeidler fWeAreInvoking(false)
22860dfc9aSClemens Zeidler {
23860dfc9aSClemens Zeidler
24860dfc9aSClemens Zeidler }
25860dfc9aSClemens Zeidler
26860dfc9aSClemens Zeidler
27860dfc9aSClemens Zeidler void
RegisterListener(DesktopListener * listener,Desktop * desktop)28d6734c08SClemens Zeidler DesktopObservable::RegisterListener(DesktopListener* listener, Desktop* desktop)
29860dfc9aSClemens Zeidler {
30860dfc9aSClemens Zeidler fDesktopListenerList.Add(listener);
31d6734c08SClemens Zeidler listener->ListenerRegistered(desktop);
32860dfc9aSClemens Zeidler }
33860dfc9aSClemens Zeidler
34860dfc9aSClemens Zeidler
35860dfc9aSClemens Zeidler void
UnregisterListener(DesktopListener * listener)36860dfc9aSClemens Zeidler DesktopObservable::UnregisterListener(DesktopListener* listener)
37860dfc9aSClemens Zeidler {
38860dfc9aSClemens Zeidler fDesktopListenerList.Remove(listener);
39d6734c08SClemens Zeidler listener->ListenerUnregistered();
40860dfc9aSClemens Zeidler }
41860dfc9aSClemens Zeidler
42860dfc9aSClemens Zeidler
43b6ba2290SClemens Zeidler const DesktopListenerDLList&
GetDesktopListenerList()44b6ba2290SClemens Zeidler DesktopObservable::GetDesktopListenerList()
45b6ba2290SClemens Zeidler {
46b6ba2290SClemens Zeidler return fDesktopListenerList;
47b6ba2290SClemens Zeidler }
48b6ba2290SClemens Zeidler
49b6ba2290SClemens Zeidler
50c0494bc5SClemens Zeidler bool
MessageForListener(Window * sender,BPrivate::LinkReceiver & link,BPrivate::LinkSender & reply)51c0494bc5SClemens Zeidler DesktopObservable::MessageForListener(Window* sender,
529ff327deSClemens Zeidler BPrivate::LinkReceiver& link, BPrivate::LinkSender& reply)
53c0494bc5SClemens Zeidler {
54c0494bc5SClemens Zeidler int32 identifier;
55c0494bc5SClemens Zeidler link.Read<int32>(&identifier);
56c0494bc5SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
57c0494bc5SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener)) {
58c0494bc5SClemens Zeidler if (listener->Identifier() == identifier) {
599ff327deSClemens Zeidler if (!listener->HandleMessage(sender, link, reply))
60c0494bc5SClemens Zeidler break;
61c0494bc5SClemens Zeidler return true;
62c0494bc5SClemens Zeidler }
63c0494bc5SClemens Zeidler }
64c0494bc5SClemens Zeidler return false;
65c0494bc5SClemens Zeidler }
66860dfc9aSClemens Zeidler
67860dfc9aSClemens Zeidler
68860dfc9aSClemens Zeidler void
NotifyWindowAdded(Window * window)69bba6f48dSClemens Zeidler DesktopObservable::NotifyWindowAdded(Window* window)
70860dfc9aSClemens Zeidler {
71860dfc9aSClemens Zeidler if (fWeAreInvoking)
72860dfc9aSClemens Zeidler return;
73860dfc9aSClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
74860dfc9aSClemens Zeidler
75c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
76c84e1250SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
77c84e1250SClemens Zeidler listener->WindowAdded(window);
78860dfc9aSClemens Zeidler }
79860dfc9aSClemens Zeidler
80860dfc9aSClemens Zeidler
81860dfc9aSClemens Zeidler void
NotifyWindowRemoved(Window * window)82bba6f48dSClemens Zeidler DesktopObservable::NotifyWindowRemoved(Window* window)
83860dfc9aSClemens Zeidler {
84860dfc9aSClemens Zeidler if (fWeAreInvoking)
85860dfc9aSClemens Zeidler return;
86860dfc9aSClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
87860dfc9aSClemens Zeidler
88c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
89c84e1250SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
90c84e1250SClemens Zeidler listener->WindowRemoved(window);
91860dfc9aSClemens Zeidler }
92860dfc9aSClemens Zeidler
93860dfc9aSClemens Zeidler
9483cdf43fSClemens Zeidler bool
NotifyKeyPressed(uint32 what,int32 key,int32 modifiers)95bba6f48dSClemens Zeidler DesktopObservable::NotifyKeyPressed(uint32 what, int32 key, int32 modifiers)
96860dfc9aSClemens Zeidler {
97860dfc9aSClemens Zeidler if (fWeAreInvoking)
9883cdf43fSClemens Zeidler return false;
99860dfc9aSClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
100860dfc9aSClemens Zeidler
10183cdf43fSClemens Zeidler bool skipEvent = false;
102c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
10383cdf43fSClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener)) {
10483cdf43fSClemens Zeidler if (listener->KeyPressed(what, key, modifiers))
10583cdf43fSClemens Zeidler skipEvent = true;
10683cdf43fSClemens Zeidler }
10783cdf43fSClemens Zeidler return skipEvent;
108860dfc9aSClemens Zeidler }
109860dfc9aSClemens Zeidler
110860dfc9aSClemens Zeidler
111860dfc9aSClemens Zeidler void
NotifyMouseEvent(BMessage * message)112bba6f48dSClemens Zeidler DesktopObservable::NotifyMouseEvent(BMessage* message)
113860dfc9aSClemens Zeidler {
114860dfc9aSClemens Zeidler if (fWeAreInvoking)
115860dfc9aSClemens Zeidler return;
116860dfc9aSClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
117860dfc9aSClemens Zeidler
118c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
119c84e1250SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
120860dfc9aSClemens Zeidler listener->MouseEvent(message);
121860dfc9aSClemens Zeidler }
122860dfc9aSClemens Zeidler
123860dfc9aSClemens Zeidler
124860dfc9aSClemens Zeidler void
NotifyMouseDown(Window * window,BMessage * message,const BPoint & where)125bba6f48dSClemens Zeidler DesktopObservable::NotifyMouseDown(Window* window, BMessage* message,
126860dfc9aSClemens Zeidler const BPoint& where)
127860dfc9aSClemens Zeidler {
128860dfc9aSClemens Zeidler if (fWeAreInvoking)
129860dfc9aSClemens Zeidler return;
130860dfc9aSClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
131860dfc9aSClemens Zeidler
132c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
133c84e1250SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
134860dfc9aSClemens Zeidler listener->MouseDown(window, message, where);
135860dfc9aSClemens Zeidler }
136860dfc9aSClemens Zeidler
137860dfc9aSClemens Zeidler
138860dfc9aSClemens Zeidler void
NotifyMouseUp(Window * window,BMessage * message,const BPoint & where)139bba6f48dSClemens Zeidler DesktopObservable::NotifyMouseUp(Window* window, BMessage* message,
140860dfc9aSClemens Zeidler const BPoint& where)
141860dfc9aSClemens Zeidler {
142860dfc9aSClemens Zeidler if (fWeAreInvoking)
143860dfc9aSClemens Zeidler return;
144860dfc9aSClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
145860dfc9aSClemens Zeidler
146c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
147c84e1250SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
148860dfc9aSClemens Zeidler listener->MouseUp(window, message, where);
149860dfc9aSClemens Zeidler }
150860dfc9aSClemens Zeidler
151860dfc9aSClemens Zeidler
152860dfc9aSClemens Zeidler void
NotifyMouseMoved(Window * window,BMessage * message,const BPoint & where)153bba6f48dSClemens Zeidler DesktopObservable::NotifyMouseMoved(Window* window, BMessage* message,
154860dfc9aSClemens Zeidler const BPoint& where)
155860dfc9aSClemens Zeidler {
156860dfc9aSClemens Zeidler if (fWeAreInvoking)
157860dfc9aSClemens Zeidler return;
158860dfc9aSClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
159860dfc9aSClemens Zeidler
160c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
161c84e1250SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
162860dfc9aSClemens Zeidler listener->MouseMoved(window, message, where);
163860dfc9aSClemens Zeidler }
164860dfc9aSClemens Zeidler
165860dfc9aSClemens Zeidler
166860dfc9aSClemens Zeidler void
NotifyWindowMoved(Window * window)167bba6f48dSClemens Zeidler DesktopObservable::NotifyWindowMoved(Window* window)
168860dfc9aSClemens Zeidler {
169860dfc9aSClemens Zeidler if (fWeAreInvoking)
170860dfc9aSClemens Zeidler return;
171860dfc9aSClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
172860dfc9aSClemens Zeidler
173c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
174c84e1250SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
175c84e1250SClemens Zeidler listener->WindowMoved(window);
176860dfc9aSClemens Zeidler }
177860dfc9aSClemens Zeidler
178860dfc9aSClemens Zeidler
179860dfc9aSClemens Zeidler void
NotifyWindowResized(Window * window)180bba6f48dSClemens Zeidler DesktopObservable::NotifyWindowResized(Window* window)
181860dfc9aSClemens Zeidler {
182860dfc9aSClemens Zeidler if (fWeAreInvoking)
183860dfc9aSClemens Zeidler return;
184860dfc9aSClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
185860dfc9aSClemens Zeidler
186c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
187c84e1250SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
188c84e1250SClemens Zeidler listener->WindowResized(window);
189860dfc9aSClemens Zeidler }
190860dfc9aSClemens Zeidler
191860dfc9aSClemens Zeidler
192860dfc9aSClemens Zeidler void
NotifyWindowActivated(Window * window)1934772e0b2SPhilippe Houdoin DesktopObservable::NotifyWindowActivated(Window* window)
194860dfc9aSClemens Zeidler {
195860dfc9aSClemens Zeidler if (fWeAreInvoking)
196860dfc9aSClemens Zeidler return;
197860dfc9aSClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
198860dfc9aSClemens Zeidler
199c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
200c84e1250SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
201*27b76737SJohn Scipione listener->WindowActivated(window);
202860dfc9aSClemens Zeidler }
203860dfc9aSClemens Zeidler
204860dfc9aSClemens Zeidler
205860dfc9aSClemens Zeidler void
NotifyWindowSentBehind(Window * window,Window * behindOf)206bba6f48dSClemens Zeidler DesktopObservable::NotifyWindowSentBehind(Window* window, Window* behindOf)
207860dfc9aSClemens Zeidler {
208860dfc9aSClemens Zeidler if (fWeAreInvoking)
209860dfc9aSClemens Zeidler return;
210860dfc9aSClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
211860dfc9aSClemens Zeidler
212c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
213c84e1250SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
214c84e1250SClemens Zeidler listener->WindowSentBehind(window, behindOf);
215860dfc9aSClemens Zeidler }
216860dfc9aSClemens Zeidler
217860dfc9aSClemens Zeidler
218d25313d4SClemens Zeidler void
NotifyWindowWorkspacesChanged(Window * window,uint32 workspaces)219bba6f48dSClemens Zeidler DesktopObservable::NotifyWindowWorkspacesChanged(Window* window,
220bba6f48dSClemens Zeidler uint32 workspaces)
221d25313d4SClemens Zeidler {
222d25313d4SClemens Zeidler if (fWeAreInvoking)
223d25313d4SClemens Zeidler return;
224d25313d4SClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
225d25313d4SClemens Zeidler
226c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
227c84e1250SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
228c84e1250SClemens Zeidler listener->WindowWorkspacesChanged(window, workspaces);
229c84e1250SClemens Zeidler }
230c84e1250SClemens Zeidler
231c84e1250SClemens Zeidler
232c84e1250SClemens Zeidler void
NotifyWindowHidden(Window * window,bool fromMinimize)233cd67c205SClemens Zeidler DesktopObservable::NotifyWindowHidden(Window* window, bool fromMinimize)
23455fbf11fSClemens Zeidler {
23555fbf11fSClemens Zeidler if (fWeAreInvoking)
23655fbf11fSClemens Zeidler return;
23755fbf11fSClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
23855fbf11fSClemens Zeidler
23955fbf11fSClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
24055fbf11fSClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
241cd67c205SClemens Zeidler listener->WindowHidden(window, fromMinimize);
24255fbf11fSClemens Zeidler }
24355fbf11fSClemens Zeidler
24455fbf11fSClemens Zeidler
24555fbf11fSClemens Zeidler void
NotifyWindowMinimized(Window * window,bool minimize)246bba6f48dSClemens Zeidler DesktopObservable::NotifyWindowMinimized(Window* window, bool minimize)
247c84e1250SClemens Zeidler {
248c84e1250SClemens Zeidler if (fWeAreInvoking)
249c84e1250SClemens Zeidler return;
250c84e1250SClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
251c84e1250SClemens Zeidler
252c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
253c84e1250SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
254c84e1250SClemens Zeidler listener->WindowMinimized(window, minimize);
255c84e1250SClemens Zeidler }
256c84e1250SClemens Zeidler
257c84e1250SClemens Zeidler
258c84e1250SClemens Zeidler void
NotifyWindowTabLocationChanged(Window * window,float location,bool isShifting)259bba6f48dSClemens Zeidler DesktopObservable::NotifyWindowTabLocationChanged(Window* window,
260bb2e9b06SClemens Zeidler float location, bool isShifting)
261c84e1250SClemens Zeidler {
262c84e1250SClemens Zeidler if (fWeAreInvoking)
263c84e1250SClemens Zeidler return;
264c84e1250SClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
265c84e1250SClemens Zeidler
266c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
267c84e1250SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
268bb2e9b06SClemens Zeidler listener->WindowTabLocationChanged(window, location, isShifting);
269d25313d4SClemens Zeidler }
270d25313d4SClemens Zeidler
271d25313d4SClemens Zeidler
272dcbc4af5SClemens Zeidler void
NotifySizeLimitsChanged(Window * window,int32 minWidth,int32 maxWidth,int32 minHeight,int32 maxHeight)27308a79ab2SClemens Zeidler DesktopObservable::NotifySizeLimitsChanged(Window* window, int32 minWidth,
274dcbc4af5SClemens Zeidler int32 maxWidth, int32 minHeight, int32 maxHeight)
275dcbc4af5SClemens Zeidler {
276dcbc4af5SClemens Zeidler if (fWeAreInvoking)
277dcbc4af5SClemens Zeidler return;
278dcbc4af5SClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
279dcbc4af5SClemens Zeidler
280dcbc4af5SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
281dcbc4af5SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
28208a79ab2SClemens Zeidler listener->SizeLimitsChanged(window, minWidth, maxWidth, minHeight,
283dcbc4af5SClemens Zeidler maxHeight);
284dcbc4af5SClemens Zeidler }
285dcbc4af5SClemens Zeidler
286dcbc4af5SClemens Zeidler
2877306ba04SClemens Zeidler void
NotifyWindowLookChanged(Window * window,window_look look)2887306ba04SClemens Zeidler DesktopObservable::NotifyWindowLookChanged(Window* window, window_look look)
2897306ba04SClemens Zeidler {
2907306ba04SClemens Zeidler if (fWeAreInvoking)
2917306ba04SClemens Zeidler return;
2927306ba04SClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
2937306ba04SClemens Zeidler
2947306ba04SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
2957306ba04SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
2967306ba04SClemens Zeidler listener->WindowLookChanged(window, look);
2977306ba04SClemens Zeidler }
2987306ba04SClemens Zeidler
2997306ba04SClemens Zeidler
3007c5525e8SClemens Zeidler void
NotifyWindowFeelChanged(Window * window,window_feel feel)3017c5525e8SClemens Zeidler DesktopObservable::NotifyWindowFeelChanged(Window* window, window_feel feel)
3027c5525e8SClemens Zeidler {
3037c5525e8SClemens Zeidler if (fWeAreInvoking)
3047c5525e8SClemens Zeidler return;
3057c5525e8SClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
3067c5525e8SClemens Zeidler
3077c5525e8SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
3087c5525e8SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
3097c5525e8SClemens Zeidler listener->WindowFeelChanged(window, feel);
3107c5525e8SClemens Zeidler }
3117c5525e8SClemens Zeidler
3127c5525e8SClemens Zeidler
313860dfc9aSClemens Zeidler bool
SetDecoratorSettings(Window * window,const BMessage & settings)314c84e1250SClemens Zeidler DesktopObservable::SetDecoratorSettings(Window* window,
315860dfc9aSClemens Zeidler const BMessage& settings)
316860dfc9aSClemens Zeidler {
317860dfc9aSClemens Zeidler if (fWeAreInvoking)
318860dfc9aSClemens Zeidler return false;
319860dfc9aSClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
320860dfc9aSClemens Zeidler
321860dfc9aSClemens Zeidler bool changed = false;
322c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
323c84e1250SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
324860dfc9aSClemens Zeidler changed = changed | listener->SetDecoratorSettings(window, settings);
325860dfc9aSClemens Zeidler
326860dfc9aSClemens Zeidler return changed;
327860dfc9aSClemens Zeidler }
328860dfc9aSClemens Zeidler
329860dfc9aSClemens Zeidler
330860dfc9aSClemens Zeidler void
GetDecoratorSettings(Window * window,BMessage & settings)331c84e1250SClemens Zeidler DesktopObservable::GetDecoratorSettings(Window* window, BMessage& settings)
332860dfc9aSClemens Zeidler {
333860dfc9aSClemens Zeidler if (fWeAreInvoking)
334860dfc9aSClemens Zeidler return;
335860dfc9aSClemens Zeidler InvokeGuard invokeGuard(fWeAreInvoking);
336860dfc9aSClemens Zeidler
337c84e1250SClemens Zeidler for (DesktopListener* listener = fDesktopListenerList.First();
338c84e1250SClemens Zeidler listener != NULL; listener = fDesktopListenerList.GetNext(listener))
339860dfc9aSClemens Zeidler listener->GetDecoratorSettings(window, settings);
340860dfc9aSClemens Zeidler }
341860dfc9aSClemens Zeidler
342860dfc9aSClemens Zeidler
InvokeGuard(bool & invoking)343860dfc9aSClemens Zeidler DesktopObservable::InvokeGuard::InvokeGuard(bool& invoking)
344860dfc9aSClemens Zeidler :
345860dfc9aSClemens Zeidler fInvoking(invoking)
346860dfc9aSClemens Zeidler {
347860dfc9aSClemens Zeidler fInvoking = true;
348860dfc9aSClemens Zeidler }
349860dfc9aSClemens Zeidler
350860dfc9aSClemens Zeidler
~InvokeGuard()351860dfc9aSClemens Zeidler DesktopObservable::InvokeGuard::~InvokeGuard()
352860dfc9aSClemens Zeidler {
353860dfc9aSClemens Zeidler fInvoking = false;
354860dfc9aSClemens Zeidler }
355