This source file includes following definitions.
- GetInstance
- AddObserver
- RemoveObserver
- GetPropertyAtom
- Notify
- WMSupportsActivation
- NotifyActiveWindowChanged
#include "ui/base/x/active_window_watcher_x.h"
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include "base/memory/singleton.h"
#include "ui/base/x/active_window_watcher_x_observer.h"
#include "ui/base/x/root_window_property_watcher_x.h"
#include "ui/base/x/x11_util.h"
#include "ui/gfx/gdk_compat.h"
#include "ui/gfx/gtk_compat.h"
namespace ui {
static const char* const kNetActiveWindow = "_NET_ACTIVE_WINDOW";
ActiveWindowWatcherX* ActiveWindowWatcherX::GetInstance() {
return Singleton<ActiveWindowWatcherX>::get();
}
void ActiveWindowWatcherX::AddObserver(ActiveWindowWatcherXObserver* observer) {
internal::RootWindowPropertyWatcherX::GetInstance();
GetInstance()->observers_.AddObserver(observer);
}
void ActiveWindowWatcherX::RemoveObserver(
ActiveWindowWatcherXObserver* observer) {
GetInstance()->observers_.RemoveObserver(observer);
}
Atom ActiveWindowWatcherX::GetPropertyAtom() {
return GetAtom(kNetActiveWindow);
}
void ActiveWindowWatcherX::Notify() {
GetInstance()->NotifyActiveWindowChanged();
}
bool ActiveWindowWatcherX::WMSupportsActivation() {
return gdk_x11_screen_supports_net_wm_hint(
gdk_screen_get_default(),
gdk_atom_intern_static_string(kNetActiveWindow));
}
ActiveWindowWatcherX::ActiveWindowWatcherX() {
}
ActiveWindowWatcherX::~ActiveWindowWatcherX() {
}
void ActiveWindowWatcherX::NotifyActiveWindowChanged() {
Atom type = None;
int format = 0;
long unsigned int num_items = 0, remaining_bytes = 0;
unsigned char* property = NULL;
XGetWindowProperty(gdk_x11_get_default_xdisplay(),
GDK_WINDOW_XID(gdk_get_default_root_window()),
GetAtom(kNetActiveWindow),
0,
1,
False,
AnyPropertyType,
&type,
&format,
&num_items,
&remaining_bytes,
&property);
if (format == 32 && num_items == 1) {
int xid = *reinterpret_cast<int*>(property);
GdkDisplay* display = gdk_display_get_default();
GdkWindow* active_window = gdk_x11_window_lookup_for_display(display, xid);
FOR_EACH_OBSERVER(ActiveWindowWatcherXObserver, observers_,
ActiveWindowChanged(active_window));
}
if (property)
XFree(property);
}
}