From f290f3e46ee27cf48b9b6dbc0f35c0d8af6d0c00 Mon Sep 17 00:00:00 2001 From: "tc@google.com" Date: Fri, 7 Aug 2009 18:03:10 +0000 Subject: Fix a bug where we don't maximize on titlebar double click in KWin. GTK+ sends the following events on double click: GDK_BUTTON_PRESS GDK_BUTTON_RELEASE GDK_BUTTON_PRESS GDK_2BUTTON_PRESS GDK_BUTTON_RELEASE If we start a gtk_window_begin_move_drag on the second GDK_BUTTON_PRESS, the call to gtk_window_maximize fails. To work around this, we keep track of the last click and if it's going to be a double click, we don't call gtk_window_begin_move_drag. BUG=18401 Review URL: http://codereview.chromium.org/165102 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22736 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/gtk/browser_window_gtk.cc | 38 ++++++++++++++++++++++++++++---- chrome/browser/gtk/browser_window_gtk.h | 5 +++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 1bbf1b3..5d23c1f 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -389,7 +389,8 @@ BrowserWindowGtk::BrowserWindowGtk(Browser* browser) panel_controller_(NULL), #endif frame_cursor_(NULL), - is_active_(true) { + is_active_(true), + last_click_time_(0) { use_custom_frame_.Init(prefs::kUseCustomChromeFrame, browser_->profile()->GetPrefs(), this); @@ -1567,10 +1568,39 @@ gboolean BrowserWindowGtk::OnButtonPressEvent(GtkWidget* widget, && !has_hit_edge; if (event->button == 1) { if (GDK_BUTTON_PRESS == event->type) { + guint32 last_click_time = browser->last_click_time_; + gfx::Point last_click_position = browser->last_click_position_; + browser->last_click_time_ = event->time; + browser->last_click_position_ = gfx::Point(event->x, event->y); + if (has_hit_titlebar) { - gtk_window_begin_move_drag(browser->window_, event->button, - event->x_root, event->y_root, event->time); - return TRUE; + // We want to start a move when the user single clicks, but not start a + // move when the user double clicks. However, a double click sends the + // following GDK events: GDK_BUTTON_PRESS, GDK_BUTTON_RELEASE, + // GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS, GDK_BUTTON_RELEASE. If we + // start a gtk_window_begin_move_drag on the second GDK_BUTTON_PRESS, + // the call to gtk_window_maximize fails. To work around this, we + // keep track of the last click and if it's going to be a double click, + // we don't call gtk_window_begin_move_drag. + static GtkSettings* settings = gtk_settings_get_default(); + gint double_click_time = 250; + gint double_click_distance = 5; + g_object_get(G_OBJECT(settings), + "gtk-double-click-time", &double_click_time, + "gtk-double-click-distance", &double_click_distance, + NULL); + + guint32 click_time = event->time - last_click_time; + int click_move_x = event->x - last_click_position.x(); + int click_move_y = event->y - last_click_position.y(); + + if (click_time > static_cast(double_click_time) || + click_move_x > double_click_distance || + click_move_y > double_click_distance) { + gtk_window_begin_move_drag(browser->window_, event->button, + event->x_root, event->y_root, event->time); + return TRUE; + } } else if (has_hit_edge) { gtk_window_begin_resize_drag(browser->window_, edge, event->button, event->x_root, event->y_root, event->time); diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index acb1d66..c5e0ed3 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -352,6 +352,11 @@ class BrowserWindowGtk : public BrowserWindow, // this will always be true. bool is_active_; + // Keep track of the last click time and the last click position so we can + // filter out extra GDK_BUTTON_PRESS events when a double click happens. + guint32 last_click_time_; + gfx::Point last_click_position_; + DISALLOW_COPY_AND_ASSIGN(BrowserWindowGtk); }; -- cgit v1.1