OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file defines utility functions for X11 (Linux only). This code has been | 5 // This file defines utility functions for X11 (Linux only). This code has been |
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support | 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support |
7 // remains woefully incomplete. | 7 // remains woefully incomplete. |
8 | 8 |
9 #include "app/x11_util.h" | 9 #include "app/x11_util.h" |
10 | 10 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 if (format != 32 || num_items != 1) { | 222 if (format != 32 || num_items != 1) { |
223 XFree(property); | 223 XFree(property); |
224 return false; | 224 return false; |
225 } | 225 } |
226 | 226 |
227 *value = *(reinterpret_cast<int*>(property)); | 227 *value = *(reinterpret_cast<int*>(property)); |
228 XFree(property); | 228 XFree(property); |
229 return true; | 229 return true; |
230 } | 230 } |
231 | 231 |
| 232 bool GetIntArrayProperty(XID window, |
| 233 const std::string& property_name, |
| 234 std::vector<int>* value) { |
| 235 Atom property_atom = gdk_x11_get_xatom_by_name_for_display( |
| 236 gdk_display_get_default(), property_name.c_str()); |
| 237 |
| 238 Atom type = None; |
| 239 int format = 0; // size in bits of each item in 'property' |
| 240 long unsigned int num_items = 0, remaining_bytes = 0; |
| 241 unsigned char* properties = NULL; |
| 242 |
| 243 int result = XGetWindowProperty(GetXDisplay(), |
| 244 window, |
| 245 property_atom, |
| 246 0, // offset into property data to read |
| 247 (~0L), // max length to get (all of them) |
| 248 False, // deleted |
| 249 AnyPropertyType, |
| 250 &type, |
| 251 &format, |
| 252 &num_items, |
| 253 &remaining_bytes, |
| 254 &properties); |
| 255 if (result != Success) |
| 256 return false; |
| 257 |
| 258 if (format != 32) { |
| 259 XFree(properties); |
| 260 return false; |
| 261 } |
| 262 |
| 263 int* int_properties = reinterpret_cast<int*>(properties); |
| 264 value->clear(); |
| 265 value->insert(value->begin(), int_properties, int_properties + num_items); |
| 266 XFree(properties); |
| 267 return true; |
| 268 } |
| 269 |
232 bool GetStringProperty( | 270 bool GetStringProperty( |
233 XID window, const std::string& property_name, std::string* value) { | 271 XID window, const std::string& property_name, std::string* value) { |
234 Atom property_atom = gdk_x11_get_xatom_by_name_for_display( | 272 Atom property_atom = gdk_x11_get_xatom_by_name_for_display( |
235 gdk_display_get_default(), property_name.c_str()); | 273 gdk_display_get_default(), property_name.c_str()); |
236 | 274 |
237 Atom type = None; | 275 Atom type = None; |
238 int format = 0; // size in bits of each item in 'property' | 276 int format = 0; // size in bits of each item in 'property' |
239 long unsigned int num_items = 0, remaining_bytes = 0; | 277 long unsigned int num_items = 0, remaining_bytes = 0; |
240 unsigned char* property = NULL; | 278 unsigned char* property = NULL; |
241 | 279 |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 event.xclient.format = 32; | 780 event.xclient.format = 32; |
743 event.xclient.data.l[0] = desktop; | 781 event.xclient.data.l[0] = desktop; |
744 event.xclient.data.l[1] = 1; // source indication | 782 event.xclient.data.l[1] = 1; // source indication |
745 | 783 |
746 int result = XSendEvent(GetXDisplay(), GetX11RootWindow(), False, | 784 int result = XSendEvent(GetXDisplay(), GetX11RootWindow(), False, |
747 SubstructureNotifyMask, &event); | 785 SubstructureNotifyMask, &event); |
748 return result == Success; | 786 return result == Success; |
749 } | 787 } |
750 | 788 |
751 } // namespace x11_util | 789 } // namespace x11_util |
OLD | NEW |