Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1189)

Unified Diff: ui/base/x/x11_util.cc

Issue 6359008: Do not show notifications when in fullscreen or screensaver mode.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ui/base/x/x11_util.h ('K') | « ui/base/x/x11_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ExistsProperty(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;
}
« ui/base/x/x11_util.h ('K') | « ui/base/x/x11_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698