headers/bsd: Add sys/queue.h.
[haiku.git] / src / servers / app / InputManager.cpp
blobde87fa99c870c019ddc107842bda01aea5484693
1 /*
2 * Copyright 2005, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Axel Dörfler, axeld@pinc-software.de
7 */
9 // TODO: introduce means to define event stream features (like local vs. net)
10 // TODO: introduce the possibility to identify a stream by a unique name
13 #include "EventStream.h"
14 #include "InputManager.h"
16 #include <Autolock.h>
19 InputManager* gInputManager;
20 // the global input manager will be created by the AppServer
23 InputManager::InputManager()
24 : BLocker("input manager"),
25 fFreeStreams(2, true),
26 fUsedStreams(2, true)
31 InputManager::~InputManager()
36 bool
37 InputManager::AddStream(EventStream* stream)
39 BAutolock _(this);
40 return fFreeStreams.AddItem(stream);
44 void
45 InputManager::RemoveStream(EventStream* stream)
47 BAutolock _(this);
48 fFreeStreams.RemoveItem(stream);
52 EventStream*
53 InputManager::GetStream()
55 BAutolock _(this);
57 EventStream* stream = NULL;
58 do {
59 delete stream;
60 // this deletes the previous invalid stream
62 stream = fFreeStreams.RemoveItemAt(0);
63 } while (stream != NULL && !stream->IsValid());
65 if (stream == NULL)
66 return NULL;
68 fUsedStreams.AddItem(stream);
69 return stream;
73 void
74 InputManager::PutStream(EventStream* stream)
76 if (stream == NULL)
77 return;
79 BAutolock _(this);
81 fUsedStreams.RemoveItem(stream, false);
82 if (stream->IsValid())
83 fFreeStreams.AddItem(stream);
84 else
85 delete stream;
89 void
90 InputManager::UpdateScreenBounds(BRect bounds)
92 BAutolock _(this);
94 for (int32 i = fUsedStreams.CountItems(); i-- > 0;) {
95 fUsedStreams.ItemAt(i)->UpdateScreenBounds(bounds);
98 for (int32 i = fFreeStreams.CountItems(); i-- > 0;) {
99 fFreeStreams.ItemAt(i)->UpdateScreenBounds(bounds);