summaryrefslogtreecommitdiffstats
path: root/ui/base/x
diff options
context:
space:
mode:
authorderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-18 22:26:40 +0000
committerderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-18 22:26:40 +0000
commita3102766e725636ad23ad99faa1e8a481a1129e7 (patch)
treecea797379b158ff00fb8d4b2e86c67046b548946 /ui/base/x
parent8431abd52eb3f7cc0eb9812933fe3eb5e83def45 (diff)
downloadchromium_src-a3102766e725636ad23ad99faa1e8a481a1129e7.zip
chromium_src-a3102766e725636ad23ad99faa1e8a481a1129e7.tar.gz
chromium_src-a3102766e725636ad23ad99faa1e8a481a1129e7.tar.bz2
aura/chromeos: Avoid suspending while video is playing.
This adds an ash::VideoDetector class that watches for layer updates and attempts to detect the playback of video. A Chrome OS-specific observer updates a _CHROME_VIDEO_TIME property on the X root window, which is used by the power manager to defer screen dimming or other power management features. This matches the implementation currently in use on Chrome OS, with Chrome taking the X window manager's role for detecting video and setting the property. BUG=110114 TEST=added; also manually checked that the property is updated Review URL: http://codereview.chromium.org/9249004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118171 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/x')
-rw-r--r--ui/base/x/x11_util.cc36
-rw-r--r--ui/base/x/x11_util.h9
2 files changed, 45 insertions, 0 deletions
diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc
index 9605fde..302ffd6 100644
--- a/ui/base/x/x11_util.cc
+++ b/ui/base/x/x11_util.cc
@@ -18,6 +18,7 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/message_loop.h"
#include "base/string_number_conversions.h"
@@ -514,11 +515,46 @@ bool GetStringProperty(
return true;
}
+bool SetIntProperty(XID window,
+ const std::string& name,
+ const std::string& type,
+ int value) {
+ std::vector<int> values(1, value);
+ return SetIntArrayProperty(window, name, type, values);
+}
+
+bool SetIntArrayProperty(XID window,
+ const std::string& name,
+ const std::string& type,
+ const std::vector<int>& value) {
+ DCHECK(!value.empty());
+ Atom name_atom = GetAtom(name.c_str());
+ Atom type_atom = GetAtom(type.c_str());
+
+ // XChangeProperty() expects values of type 32 to be longs.
+ scoped_array<long> data(new long[value.size()]);
+ for (size_t i = 0; i < value.size(); ++i)
+ data[i] = value[i];
+
+ gdk_error_trap_push();
+ XChangeProperty(ui::GetXDisplay(),
+ window,
+ name_atom,
+ type_atom,
+ 32, // size in bits of items in 'value'
+ PropModeReplace,
+ reinterpret_cast<const unsigned char*>(data.get()),
+ value.size()); // num items
+ XSync(ui::GetXDisplay(), False);
+ return gdk_error_trap_pop() == 0;
+}
+
Atom GetAtom(const char* name) {
#if defined(TOOLKIT_USES_GTK)
return gdk_x11_get_xatom_by_name_for_display(
gdk_display_get_default(), name);
#else
+ // TODO(derat): Cache atoms to avoid round-trips to the server.
return XInternAtom(GetXDisplay(), name, false);
#endif
}
diff --git a/ui/base/x/x11_util.h b/ui/base/x/x11_util.h
index 757b149..411c941 100644
--- a/ui/base/x/x11_util.h
+++ b/ui/base/x/x11_util.h
@@ -124,6 +124,15 @@ UI_EXPORT bool GetAtomArrayProperty(XID window,
UI_EXPORT bool GetStringProperty(
XID window, const std::string& property_name, std::string* value);
+UI_EXPORT bool SetIntProperty(XID window,
+ const std::string& name,
+ const std::string& type,
+ int value);
+UI_EXPORT bool SetIntArrayProperty(XID window,
+ const std::string& name,
+ const std::string& type,
+ const std::vector<int>& value);
+
// Gets the X atom for default display corresponding to atom_name.
Atom GetAtom(const char* atom_name);