summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-10 19:30:58 +0000
committerdcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-10 19:30:58 +0000
commitca595c8f7a5213fc146ef578f5e49f9316d0ee90 (patch)
tree12358febef35da74ba1f8428082e3463657fb62b
parent9cf12c316c486bccd4680a2366f00707917771d8 (diff)
downloadchromium_src-ca595c8f7a5213fc146ef578f5e49f9316d0ee90.zip
chromium_src-ca595c8f7a5213fc146ef578f5e49f9316d0ee90.tar.gz
chromium_src-ca595c8f7a5213fc146ef578f5e49f9316d0ee90.tar.bz2
Create utility functions for helping determine the X window manager.
Since a couple places check for the current window manager, consolidate the logic into utility functions so it's checked consistently. Also re-enables Panel on Mutter, GNOME 3's window manager. BUG=none TEST=none Review URL: http://codereview.chromium.org/8508023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109477 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/notifications/notification_browsertest.cc14
-rw-r--r--chrome/browser/ui/browser.cc14
-rw-r--r--chrome/browser/ui/gtk/browser_window_gtk.cc29
-rw-r--r--chrome/browser/ui/panels/base_panel_browser_test.cc5
-rw-r--r--ui/base/x/x11_util.cc31
-rw-r--r--ui/base/x/x11_util.h18
6 files changed, 67 insertions, 44 deletions
diff --git a/chrome/browser/chromeos/notifications/notification_browsertest.cc b/chrome/browser/chromeos/notifications/notification_browsertest.cc
index c0ad2a7..08124ee 100644
--- a/chrome/browser/chromeos/notifications/notification_browsertest.cc
+++ b/chrome/browser/chromeos/notifications/notification_browsertest.cc
@@ -24,13 +24,6 @@
#include "content/public/browser/notification_service.h"
#include "ui/base/x/x11_util.h"
-namespace {
-
-// The name of ChromeOS's window manager.
-const char* kChromeOsWindowManagerName = "chromeos-wm";
-
-} // namespace
-
namespace chromeos {
class NotificationTest : public InProcessBrowserTest,
@@ -50,13 +43,12 @@ class NotificationTest : public InProcessBrowserTest,
virtual void SetUp() {
// Detect if we're running under ChromeOS WindowManager. See
// the description for "under_chromeos_" below for why we need this.
- std::string wm_name;
- bool wm_name_valid = ui::GetWindowManagerName(&wm_name);
+ ui::WindowManagerName wm_type = ui::GuessWindowManager();
// NOTE: On Chrome OS the wm and Chrome are started in parallel. This
// means it's possible for us not to be able to get the name of the window
// manager. We assume that when this happens we're on Chrome OS.
- under_chromeos_ = (!wm_name_valid ||
- wm_name == kChromeOsWindowManagerName);
+ under_chromeos_ = (wm_type == ui::WM_CHROME_OS ||
+ wm_type == ui::WM_UNKNOWN);
InProcessBrowserTest::SetUp();
}
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index ffec67c..0bb65e5 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -446,14 +446,12 @@ Browser* Browser::CreateForApp(Type type,
#if defined(TOOLKIT_GTK)
// Panels are only supported on a white list of window managers for Linux.
if (type == TYPE_PANEL) {
- // Some window managers seem to include version (icewm for example), so
- // limiting the comparison to the name part of the string.
- std::string wm_name;
- if (!ui::GetWindowManagerName(&wm_name) ||
- (strncasecmp(wm_name.c_str(), "compiz", sizeof("compiz") - 1) &&
- strncasecmp(wm_name.c_str(), "metacity", sizeof("metacity") - 1) &&
- strncasecmp(wm_name.c_str(), "icewm", sizeof("icewm") - 1) &&
- strncasecmp(wm_name.c_str(), "kwin", sizeof("kwin") - 1))) {
+ ui::WindowManagerName wm_type = ui::GuessWindowManager();
+ if (wm_type != ui::WM_COMPIZ &&
+ wm_type != ui::WM_ICE_WM &&
+ wm_type != ui::WM_KWIN &&
+ wm_type != ui::WM_METACITY &&
+ wm_type != ui::WM_MUTTER) {
type = TYPE_POPUP;
}
}
diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc
index b4b2df2..48fd65c 100644
--- a/chrome/browser/ui/gtk/browser_window_gtk.cc
+++ b/chrome/browser/ui/gtk/browser_window_gtk.cc
@@ -348,8 +348,7 @@ void BrowserWindowGtk::Init() {
// 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
// compiz, suppress such raises, as they are not necessary in compiz anyway.
- std::string wm_name;
- if (ui::GetWindowManagerName(&wm_name) && wm_name == "compiz")
+ if (ui::GuessWindowManager() == ui::WM_COMPIZ)
suppress_window_raise_ = true;
window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
@@ -878,9 +877,8 @@ void BrowserWindowGtk::ExitFullscreen() {
// fullscreens us again. This is a little flickery and not necessary if
// there's a gnome-panel, but it's not easy to detect whether there's a
// panel or not.
- std::string wm_name;
bool unmaximize_before_unfullscreen = IsMaximized() &&
- ui::GetWindowManagerName(&wm_name) && wm_name == "Metacity";
+ ui::GuessWindowManager() == ui::WM_METACITY;
if (unmaximize_before_unfullscreen)
UnMaximize();
@@ -2388,10 +2386,6 @@ BrowserWindowGtk::TitleDecoration BrowserWindowGtk::GetWindowTitle(
// static
bool BrowserWindowGtk::GetCustomFramePrefDefault() {
- std::string wm_name;
- if (!ui::GetWindowManagerName(&wm_name))
- return false;
-
// Ideally, we'd use the custom frame by default and just fall back on using
// system decorations for the few (?) tiling window managers where the custom
// frame doesn't make sense (e.g. awesome, ion3, ratpoison, xmonad, etc.) or
@@ -2399,16 +2393,15 @@ bool BrowserWindowGtk::GetCustomFramePrefDefault() {
// _NET_SUPPORTING_WM property makes it easy to look up a name for the current
// WM, but at least some of the WMs in the latter group don't set it.
// Instead, we default to using system decorations for all WMs and
- // special-case the ones where the custom frame should be used. These names
- // are taken from the WMs' source code.
- return (wm_name == "Blackbox" ||
- wm_name == "compiz" ||
- wm_name == "Compiz" ||
- wm_name == "e16" || // Enlightenment DR16
- wm_name == "Metacity" ||
- wm_name == "Mutter" ||
- wm_name == "Openbox" ||
- wm_name == "Xfwm4");
+ // special-case the ones where the custom frame should be used.
+ ui::WindowManagerName wm_type = ui::GuessWindowManager();
+ return (wm_type == ui::WM_BLACKBOX ||
+ wm_type == ui::WM_COMPIZ ||
+ wm_type == ui::WM_ENLIGHTENMENT ||
+ wm_type == ui::WM_METACITY ||
+ wm_type == ui::WM_MUTTER ||
+ wm_type == ui::WM_OPENBOX ||
+ wm_type == ui::WM_XFWM4);
}
// static
diff --git a/chrome/browser/ui/panels/base_panel_browser_test.cc b/chrome/browser/ui/panels/base_panel_browser_test.cc
index 9f79674..bcfbee0 100644
--- a/chrome/browser/ui/panels/base_panel_browser_test.cc
+++ b/chrome/browser/ui/panels/base_panel_browser_test.cc
@@ -254,13 +254,10 @@ Panel* BasePanelBrowserTest::CreatePanelWithParams(
panel->Show();
} else {
#if defined(OS_LINUX)
- std::string wm_name;
- bool has_name = ui::GetWindowManagerName(&wm_name);
// On bots, we might have a simple window manager which always activates new
// windows, and can't always deactivate them. Activate previously active
// window back to ensure the new window is inactive.
- // IceWM has a name string like "IceWM 1.3.6 (Linux 2.6.24-23-server/x86)"
- if (has_name && wm_name.find("IceWM") != std::string::npos) {
+ if (ui::GuessWindowManager() == ui::WM_ICE_WM) {
Browser* last_active_browser = BrowserList::GetLastActive();
EXPECT_TRUE(last_active_browser);
EXPECT_NE(last_active_browser, panel->browser());
diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc
index d901a72..dada148 100644
--- a/ui/base/x/x11_util.cc
+++ b/ui/base/x/x11_util.cc
@@ -19,8 +19,9 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/message_loop.h"
-#include "base/stringprintf.h"
#include "base/string_number_conversions.h"
+#include "base/string_util.h"
+#include "base/stringprintf.h"
#include "base/threading/thread.h"
#include "ui/base/x/x11_util_internal.h"
#include "ui/gfx/rect.h"
@@ -711,6 +712,34 @@ bool GetWindowManagerName(std::string* wm_name) {
return !got_error && result;
}
+WindowManagerName GuessWindowManager() {
+ std::string name;
+ if (GetWindowManagerName(&name)) {
+ // These names are taken from the WMs' source code.
+ if (name == "Compiz" || name == "compiz")
+ return WM_COMPIZ;
+ if (name == "KWin")
+ return WM_KWIN;
+ if (name == "Metacity")
+ return WM_METACITY;
+ if (name == "Mutter")
+ return WM_MUTTER;
+ if (name == "Xfwm4")
+ return WM_XFWM4;
+ if (name == "chromeos-wm")
+ return WM_CHROME_OS;
+ if (name == "Blackbox")
+ return WM_BLACKBOX;
+ if (name == "e16")
+ return WM_ENLIGHTENMENT;
+ if (StartsWithASCII(name, "IceWM", true))
+ return WM_ICE_WM;
+ if (name == "Openbox")
+ return WM_OPENBOX;
+ }
+ return WM_UNKNOWN;
+}
+
bool ChangeWindowDesktop(XID window, XID destination) {
int desktop;
if (!GetWindowDesktop(destination, &desktop))
diff --git a/ui/base/x/x11_util.h b/ui/base/x/x11_util.h
index 519e235..f9e979c 100644
--- a/ui/base/x/x11_util.h
+++ b/ui/base/x/x11_util.h
@@ -178,8 +178,22 @@ UI_EXPORT void PutARGBImage(Display* display, void* visual, int depth,
void FreePicture(Display* display, XID picture);
void FreePixmap(Display* display, XID pixmap);
-// Get the window manager name.
-UI_EXPORT bool GetWindowManagerName(std::string* name);
+enum WindowManagerName {
+ WM_UNKNOWN,
+ WM_BLACKBOX,
+ WM_CHROME_OS,
+ WM_COMPIZ,
+ WM_ENLIGHTENMENT,
+ WM_ICE_WM,
+ WM_KWIN,
+ WM_METACITY,
+ WM_MUTTER,
+ WM_OPENBOX,
+ WM_XFWM4,
+};
+// Attempts to guess the window maager. Returns WM_UNKNOWN if we can't
+// determine it for one reason or another.
+UI_EXPORT WindowManagerName GuessWindowManager();
// Change desktop for |window| to the desktop of |destination| window.
UI_EXPORT bool ChangeWindowDesktop(XID window, XID destination);