| Index: ui/base/x/x11_util.cc
|
| ===================================================================
|
| --- ui/base/x/x11_util.cc (revision 72012)
|
| +++ ui/base/x/x11_util.cc (working copy)
|
| @@ -66,6 +66,28 @@
|
| _exit(1);
|
| }
|
|
|
| +// Note: The caller should free the resulting value data.
|
| +bool GetProperty(XID window, const std::string& property_name, long max_length,
|
| + Atom* type, int* format, unsigned long* num_items,
|
| + unsigned char** property) {
|
| + Atom property_atom = gdk_x11_get_xatom_by_name_for_display(
|
| + gdk_display_get_default(), property_name.c_str());
|
| +
|
| + unsigned long remaining_bytes = 0;
|
| + return XGetWindowProperty(GetXDisplay(),
|
| + window,
|
| + property_atom,
|
| + 0, // offset into property data to read
|
| + max_length, // max length to get
|
| + False, // deleted
|
| + AnyPropertyType,
|
| + type,
|
| + format,
|
| + num_items,
|
| + &remaining_bytes,
|
| + property);
|
| +}
|
| +
|
| } // namespace
|
|
|
| bool XDisplayExists() {
|
| @@ -221,27 +243,29 @@
|
| return true;
|
| }
|
|
|
| +bool PropertyExists(XID window, const std::string& property_name) {
|
| + Atom type = None;
|
| + int format = 0; // size in bits of each item in 'property'
|
| + long unsigned int num_items = 0;
|
| + unsigned char* property = NULL;
|
| +
|
| + int result = GetProperty(window, property_name, 1,
|
| + &type, &format, &num_items, &property);
|
| + if (result != Success)
|
| + return false;
|
| +
|
| + XFree(property);
|
| + return num_items > 0;
|
| +}
|
| +
|
| bool GetIntProperty(XID window, const std::string& property_name, int* value) {
|
| - Atom property_atom = gdk_x11_get_xatom_by_name_for_display(
|
| - gdk_display_get_default(), property_name.c_str());
|
| -
|
| Atom type = None;
|
| int format = 0; // size in bits of each item in 'property'
|
| - long unsigned int num_items = 0, remaining_bytes = 0;
|
| + long unsigned int num_items = 0;
|
| unsigned char* property = NULL;
|
|
|
| - int result = XGetWindowProperty(GetXDisplay(),
|
| - window,
|
| - property_atom,
|
| - 0, // offset into property data to read
|
| - 1, // max length to get
|
| - False, // deleted
|
| - AnyPropertyType,
|
| - &type,
|
| - &format,
|
| - &num_items,
|
| - &remaining_bytes,
|
| - &property);
|
| + int result = GetProperty(window, property_name, 1,
|
| + &type, &format, &num_items, &property);
|
| if (result != Success)
|
| return false;
|
|
|
| @@ -258,26 +282,14 @@
|
| bool GetIntArrayProperty(XID window,
|
| const std::string& property_name,
|
| std::vector<int>* value) {
|
| - Atom property_atom = gdk_x11_get_xatom_by_name_for_display(
|
| - gdk_display_get_default(), property_name.c_str());
|
| -
|
| Atom type = None;
|
| int format = 0; // size in bits of each item in 'property'
|
| - long unsigned int num_items = 0, remaining_bytes = 0;
|
| + long unsigned int num_items = 0;
|
| unsigned char* properties = NULL;
|
|
|
| - int result = XGetWindowProperty(GetXDisplay(),
|
| - window,
|
| - property_atom,
|
| - 0, // offset into property data to read
|
| - (~0L), // max length to get (all of them)
|
| - False, // deleted
|
| - AnyPropertyType,
|
| - &type,
|
| - &format,
|
| - &num_items,
|
| - &remaining_bytes,
|
| - &properties);
|
| + int result = GetProperty(window, property_name,
|
| + (~0L), // (all of them)
|
| + &type, &format, &num_items, &properties);
|
| if (result != Success)
|
| return false;
|
|
|
| @@ -293,28 +305,41 @@
|
| return true;
|
| }
|
|
|
| +bool GetAtomArrayProperty(XID window,
|
| + const std::string& property_name,
|
| + std::vector<Atom>* value) {
|
| + Atom type = None;
|
| + int format = 0; // size in bits of each item in 'property'
|
| + long unsigned int num_items = 0;
|
| + unsigned char* properties = NULL;
|
| +
|
| + int result = GetProperty(window, property_name,
|
| + (~0L), // (all of them)
|
| + &type, &format, &num_items, &properties);
|
| + if (result != Success)
|
| + return false;
|
| +
|
| + if (type != XA_ATOM) {
|
| + XFree(properties);
|
| + return false;
|
| + }
|
| +
|
| + Atom* atom_properties = reinterpret_cast<Atom*>(properties);
|
| + value->clear();
|
| + value->insert(value->begin(), atom_properties, atom_properties + num_items);
|
| + XFree(properties);
|
| + return true;
|
| +}
|
| +
|
| bool GetStringProperty(
|
| XID window, const std::string& property_name, std::string* value) {
|
| - Atom property_atom = gdk_x11_get_xatom_by_name_for_display(
|
| - gdk_display_get_default(), property_name.c_str());
|
| -
|
| Atom type = None;
|
| int format = 0; // size in bits of each item in 'property'
|
| - long unsigned int num_items = 0, remaining_bytes = 0;
|
| + long unsigned int num_items = 0;
|
| unsigned char* property = NULL;
|
|
|
| - int result = XGetWindowProperty(GetXDisplay(),
|
| - window,
|
| - property_atom,
|
| - 0, // offset into property data to read
|
| - 1024, // max length to get
|
| - False, // deleted
|
| - AnyPropertyType,
|
| - &type,
|
| - &format,
|
| - &num_items,
|
| - &remaining_bytes,
|
| - &property);
|
| + int result = GetProperty(window, property_name, 1024,
|
| + &type, &format, &num_items, &property);
|
| if (result != Success)
|
| return false;
|
|
|
| @@ -412,26 +437,17 @@
|
| bool GetXWindowStack(std::vector<XID>* windows) {
|
| windows->clear();
|
|
|
| - static Atom atom = XInternAtom(GetXDisplay(),
|
| - "_NET_CLIENT_LIST_STACKING", False);
|
| -
|
| Atom type;
|
| int format;
|
| unsigned long count;
|
| - unsigned long bytes_after;
|
| unsigned char *data = NULL;
|
| - if (XGetWindowProperty(GetXDisplay(),
|
| - GetX11RootWindow(),
|
| - atom,
|
| - 0, // offset
|
| - ~0L, // length
|
| - False, // delete
|
| - AnyPropertyType, // requested type
|
| - &type,
|
| - &format,
|
| - &count,
|
| - &bytes_after,
|
| - &data) != Success) {
|
| + if (!GetProperty(GetX11RootWindow(),
|
| + "_NET_CLIENT_LIST_STACKING",
|
| + ~0L,
|
| + &type,
|
| + &format,
|
| + &count,
|
| + &data)) {
|
| return false;
|
| }
|
|
|
| @@ -752,6 +768,34 @@
|
| SetX11ErrorHandlers(NULL, NULL);
|
| }
|
|
|
| +bool IsX11WindowFullScreen(XID window) {
|
| + // First check if _NET_WM_STATE property contains _NET_WM_STATE_FULLSCREEN.
|
| + static Atom atom = gdk_x11_get_xatom_by_name_for_display(
|
| + gdk_display_get_default(), "_NET_WM_STATE_FULLSCREEN");
|
| +
|
| + std::vector<Atom> atom_properties;
|
| + if (GetAtomArrayProperty(window,
|
| + "_NET_WM_STATE",
|
| + &atom_properties) &&
|
| + std::find(atom_properties.begin(), atom_properties.end(), atom)
|
| + != atom_properties.end())
|
| + return true;
|
| +
|
| + // As the last resort, check if the window size is as large as the main
|
| + // screen.
|
| + GdkRectangle monitor_rect;
|
| + gdk_screen_get_monitor_geometry(gdk_screen_get_default(), 0, &monitor_rect);
|
| +
|
| + gfx::Rect window_rect;
|
| + if (!ui::GetWindowRect(window, &window_rect))
|
| + return false;
|
| +
|
| + return monitor_rect.x == window_rect.x() &&
|
| + monitor_rect.y == window_rect.y() &&
|
| + monitor_rect.width == window_rect.width() &&
|
| + monitor_rect.height == window_rect.height();
|
| +}
|
| +
|
| // ----------------------------------------------------------------------------
|
| // These functions are declared in x11_util_internal.h because they require
|
| // XLib.h to be included, and it conflicts with many other headers.
|
|
|