1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/base/x/x11_foreign_window_manager.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/singleton.h"
15 XForeignWindowManager
* XForeignWindowManager::GetInstance() {
16 return base::Singleton
<XForeignWindowManager
>::get();
19 int XForeignWindowManager::RequestEvents(XID xid
, long event_mask
) {
20 request_map_
[xid
].push_back(Request(next_request_id_
, event_mask
));
21 UpdateSelectedEvents(xid
);
22 return next_request_id_
++;
25 void XForeignWindowManager::CancelRequest(int request_id
) {
26 for (std::map
<XID
, RequestVector
>::iterator map_it
= request_map_
.begin();
27 map_it
!= request_map_
.end(); ++map_it
) {
28 RequestVector
* vector
= &map_it
->second
;
29 for (RequestVector::iterator vector_it
= vector
->begin();
30 vector_it
!= vector
->end(); ++vector_it
) {
31 if (vector_it
->request_id
== request_id
) {
32 vector
->erase(vector_it
);
33 UpdateSelectedEvents(map_it
->first
);
35 request_map_
.erase(map_it
);
42 void XForeignWindowManager::OnWindowDestroyed(XID xid
) {
43 request_map_
.erase(xid
);
46 XForeignWindowManager::XForeignWindowManager() : next_request_id_(0) {
49 XForeignWindowManager::~XForeignWindowManager() {
52 void XForeignWindowManager::UpdateSelectedEvents(XID xid
) {
53 std::map
<XID
, RequestVector
>::iterator it
= request_map_
.find(xid
);
54 if (it
== request_map_
.end())
57 long event_mask
= NoEventMask
;
58 const RequestVector
& list
= it
->second
;
59 for (size_t i
= 0; i
< list
.size(); ++i
)
60 event_mask
|= list
[i
].event_mask
;
62 XSelectInput(gfx::GetXDisplay(), xid
, event_mask
);
65 XForeignWindowManager::Request::Request(int request_id
, long event_mask
)
66 : request_id(request_id
),
67 event_mask(event_mask
) {
70 XForeignWindowManager::Request::~Request() {