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

Side by Side Diff: chrome/browser/gtk/browser_window_gtk.cc

Issue 203027: Linux: avoid browser windows moving around by the size of WM decorations over restart. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/gtk/browser_window_gtk.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/gtk/browser_window_gtk.h" 5 #include "chrome/browser/gtk/browser_window_gtk.h"
6 6
7 #include <gdk/gdkkeysyms.h> 7 #include <gdk/gdkkeysyms.h>
8 #include <X11/XF86keysym.h> 8 #include <X11/XF86keysym.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // actually a couple pixels more that should overlap the toolbar and web 118 // actually a couple pixels more that should overlap the toolbar and web
119 // content area, but we don't use those pixels. 119 // content area, but we don't use those pixels.
120 const int kContentShadowThickness = 2; 120 const int kContentShadowThickness = 2;
121 // The offset to the background when the custom frame is off. We want the 121 // The offset to the background when the custom frame is off. We want the
122 // window background to line up with the tab background regardless of whether 122 // window background to line up with the tab background regardless of whether
123 // we're in custom frame mode or not. Since themes are designed with the 123 // we're in custom frame mode or not. Since themes are designed with the
124 // custom frame in mind, we need to offset the background when the custom frame 124 // custom frame in mind, we need to offset the background when the custom frame
125 // is off. 125 // is off.
126 const int kCustomFrameBackgroundVerticalOffset = 15; 126 const int kCustomFrameBackgroundVerticalOffset = 15;
127 127
128 // When a window is moved or resized, GTK will call MainWindowConfigured below.
tony 2009/09/18 18:45:12 Nit: I expect this comment to either be in the hea
Mike Mammarella 2009/09/18 21:18:40 Done.
129 // The GdkEventConfigure* that we get doesn't have quite the right coordinates
130 // though (they're relative to the drawable window area, rather than any window
131 // manager decorations, if enabled), so we need to call gtk_window_get_position
132 // to get the right values. (Otherwise session restore, if enabled, will
133 // restore windows to incorrect positions.) That's a round trip to the X server
134 // though, so we set a debounce timer and only call it after we haven't seen a
135 // reconfigure event in a short while.
136 const int kDebounceTimeoutMilliseconds = 100;
137
128 base::LazyInstance<ActiveWindowWatcher> 138 base::LazyInstance<ActiveWindowWatcher>
129 g_active_window_watcher(base::LINKER_INITIALIZED); 139 g_active_window_watcher(base::LINKER_INITIALIZED);
130 140
131 gboolean MainWindowConfigured(GtkWindow* window, GdkEventConfigure* event, 141 gboolean MainWindowConfigured(GtkWindow* window, GdkEventConfigure* event,
132 BrowserWindowGtk* browser_win) { 142 BrowserWindowGtk* browser_win) {
133 gfx::Rect bounds = gfx::Rect(event->x, event->y, event->width, event->height); 143 gfx::Rect bounds = gfx::Rect(event->x, event->y, event->width, event->height);
134 browser_win->OnBoundsChanged(bounds); 144 browser_win->OnBoundsChanged(bounds);
135 return FALSE; 145 return FALSE;
136 } 146 }
137 147
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 1364
1355 void BrowserWindowGtk::OnBoundsChanged(const gfx::Rect& bounds) { 1365 void BrowserWindowGtk::OnBoundsChanged(const gfx::Rect& bounds) {
1356 GetLocationBar()->location_entry()->ClosePopup(); 1366 GetLocationBar()->location_entry()->ClosePopup();
1357 1367
1358 if (bounds_.size() != bounds.size()) 1368 if (bounds_.size() != bounds.size())
1359 OnSizeChanged(bounds.width(), bounds.height()); 1369 OnSizeChanged(bounds.width(), bounds.height());
1360 1370
1361 bounds_ = bounds; 1371 bounds_ = bounds;
1362 if (!IsFullscreen() && !IsMaximized()) 1372 if (!IsFullscreen() && !IsMaximized())
1363 restored_bounds_ = bounds; 1373 restored_bounds_ = bounds;
1374
1375 // We don't use Reset() because the timer may not yet be running.
1376 // (In that case Stop() is a no-op.)
1377 mainwin_configure_debounce_timer_.Stop();
1378 mainwin_configure_debounce_timer_.Start(base::TimeDelta::FromMilliseconds(
1379 kDebounceTimeoutMilliseconds), this,
1380 &BrowserWindowGtk::OnDebouncedBoundsChanged);
1381 }
1382
1383 void BrowserWindowGtk::OnDebouncedBoundsChanged() {
1384 gint x, y;
1385 gtk_window_get_position(window_, &x, &y);
1386 gfx::Point origin(x, y);
1387 bounds_.set_origin(origin);
tony 2009/09/18 18:45:12 Should we update restored_bounds_ too?
Mike Mammarella 2009/09/18 21:18:40 Done.
1364 SaveWindowPosition(); 1388 SaveWindowPosition();
1365 } 1389 }
1366 1390
1367 void BrowserWindowGtk::OnStateChanged(GdkWindowState state, 1391 void BrowserWindowGtk::OnStateChanged(GdkWindowState state,
1368 GdkWindowState changed_mask) { 1392 GdkWindowState changed_mask) {
1369 state_ = state; 1393 state_ = state;
1370 1394
1371 if (changed_mask & GDK_WINDOW_STATE_FULLSCREEN) { 1395 if (changed_mask & GDK_WINDOW_STATE_FULLSCREEN) {
1372 bool is_fullscreen = state & GDK_WINDOW_STATE_FULLSCREEN; 1396 bool is_fullscreen = state & GDK_WINDOW_STATE_FULLSCREEN;
1373 browser_->UpdateCommandsForFullscreenMode(is_fullscreen); 1397 browser_->UpdateCommandsForFullscreenMode(is_fullscreen);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 geometry.min_height = 1; 1501 geometry.min_height = 1;
1478 gtk_window_set_geometry_hints(window_, NULL, &geometry, GDK_HINT_MIN_SIZE); 1502 gtk_window_set_geometry_hints(window_, NULL, &geometry, GDK_HINT_MIN_SIZE);
1479 1503
1480 // If we call gtk_window_maximize followed by gtk_window_present, compiz gets 1504 // If we call gtk_window_maximize followed by gtk_window_present, compiz gets
1481 // confused and maximizes the window, but doesn't set the 1505 // confused and maximizes the window, but doesn't set the
1482 // GDK_WINDOW_STATE_MAXIMIZED bit. So instead, we keep track of whether to 1506 // GDK_WINDOW_STATE_MAXIMIZED bit. So instead, we keep track of whether to
1483 // maximize and call it after gtk_window_present. 1507 // maximize and call it after gtk_window_present.
1484 maximize_after_show_ = browser_->GetSavedMaximizedState(); 1508 maximize_after_show_ = browser_->GetSavedMaximizedState();
1485 1509
1486 gfx::Rect bounds = browser_->GetSavedWindowBounds(); 1510 gfx::Rect bounds = browser_->GetSavedWindowBounds();
1487 // We don't blindly call SetBounds here, that sets a forced position 1511 // We don't blindly call SetBounds here: that sets a forced position
1488 // on the window and we intentionally *don't* do that for normal 1512 // on the window and we intentionally *don't* do that for normal
1489 // windows. We tested many programs and none of them restored their 1513 // windows. Most programs do not restore their window position on
1490 // position on Linux. 1514 // Linux, instead letting the window manager choose a position.
1491 // 1515 //
1492 // However, in cases like dropping a tab where the bounds are 1516 // However, in cases like dropping a tab where the bounds are
1493 // specifically set, we do want to position explicitly. 1517 // specifically set, we do want to position explicitly. We also
1518 // force the position as part of session restore, as applications
1519 // that restore other, similar state (for instance GIMP, audacity,
1520 // pidgin, dia, and gkrellm) do tend to restore their positions.
1494 if (browser_->bounds_overridden()) { 1521 if (browser_->bounds_overridden()) {
1495 // For popups, bounds are set in terms of the client area rather than the 1522 // For popups, bounds are set in terms of the client area rather than the
1496 // entire window. 1523 // entire window.
1497 SetBoundsImpl(bounds, !(browser_->type() & Browser::TYPE_POPUP)); 1524 SetBoundsImpl(bounds, !(browser_->type() & Browser::TYPE_POPUP));
1498 } else { 1525 } else {
1499 // Ignore the position but obey the size. 1526 // Ignore the position but obey the size.
1500 SetWindowSize(window_, bounds.width(), bounds.height()); 1527 SetWindowSize(window_, bounds.width(), bounds.height());
1501 } 1528 }
1502 } 1529 }
1503 1530
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
2203 // special-case the ones where the custom frame should be used. These names 2230 // special-case the ones where the custom frame should be used. These names
2204 // are taken from the WMs' source code. 2231 // are taken from the WMs' source code.
2205 return (wm_name == "Blackbox" || 2232 return (wm_name == "Blackbox" ||
2206 wm_name == "compiz" || 2233 wm_name == "compiz" ||
2207 wm_name == "e16" || // Enlightenment DR16 2234 wm_name == "e16" || // Enlightenment DR16
2208 wm_name == "KWin" || 2235 wm_name == "KWin" ||
2209 wm_name == "Metacity" || 2236 wm_name == "Metacity" ||
2210 wm_name == "Openbox" || 2237 wm_name == "Openbox" ||
2211 wm_name == "Xfwm4"); 2238 wm_name == "Xfwm4");
2212 } 2239 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/browser_window_gtk.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698