#include "content/public/common/renderer_preferences.h"
#include "ui/base/accelerators/platform_accelerator_gtk.h"
#include "ui/base/models/simple_menu_model.h"
+#include "ui/base/x/active_window_watcher_x.h"
#include "ui/base/x/x11_util.h"
#include "ui/gfx/gtk_util.h"
#include "ui/gfx/rect.h"
vbox_(gtk_vbox_new(FALSE, 0)),
state_(GDK_WINDOW_STATE_WITHDRAWN),
is_always_on_top_(false),
+ is_active_(false),
suppress_window_raise_(false),
frame_cursor_(NULL) {
gtk_container_add(GTK_CONTAINER(window_), vbox_);
if (!icon_.IsEmpty())
gtk_window_set_icon(window_, icon_.ToGdkPixbuf());
+ ui::ActiveWindowWatcherX::AddObserver(this);
+
// In some (older) versions of compiz, raising top-level windows when they
// are partially off-screen causes them to get snapped back on screen, not
// always even on the current virtual desktop. If we are running under
}
bool NativeWindowGtk::IsFocused() {
+ if (ui::ActiveWindowWatcherX::WMSupportsActivation())
+ return is_active_;
+
+ // This still works even though we don't get the activation notification.
return gtk_window_is_active(window_);
}
}
}
+void NativeWindowGtk::ActiveWindowChanged(GdkWindow* active_window) {
+ is_active_ = gtk_widget_get_window(GTK_WIDGET(window_)) == active_window;
+}
+
void NativeWindowGtk::RegisterAccelerators() {
DCHECK(menu_);
accelerator_table_.clear();
#include "third_party/skia/include/core/SkRegion.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/gtk/gtk_signal.h"
+#include "ui/base/x/active_window_watcher_x_observer.h"
#include "ui/gfx/size.h"
namespace atom {
class NativeWindowGtk : public NativeWindow,
- public MenuGtk::Delegate {
+ public MenuGtk::Delegate,
+ public ui::ActiveWindowWatcherXObserver {
public:
explicit NativeWindowGtk(content::WebContents* web_contents,
base::DictionaryValue* options);
virtual void UpdateDraggableRegions(
const std::vector<DraggableRegion>& regions) OVERRIDE;
+ // Overridden from ActiveWindowWatcherXObserver.
+ virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE;
+
private:
// Register accelerators supported by the menu model.
void RegisterAccelerators();
// clicked to maximize.
scoped_ptr<SkRegion> draggable_region_;
+ // True if the window manager thinks the window is active. It could happpen
+ // that the WM thinks a window is active but it's actually not, like when
+ // showing a context menu.
+ bool is_active_;
+
// If true, don't call gdk_window_raise() when we get a click in the title
// bar or window border. This is to work around a compiz bug.
bool suppress_window_raise_;