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

Unified Diff: chrome/browser/ui/gtk/gconf_titlebar_listener.cc

Issue 11338028: Add support for XFWM titlebar buttons. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/gtk/gconf_titlebar_listener.cc
===================================================================
--- chrome/browser/ui/gtk/gconf_titlebar_listener.cc (revision 164859)
+++ chrome/browser/ui/gtk/gconf_titlebar_listener.cc (working copy)
@@ -6,12 +6,7 @@
#include <gtk/gtk.h>
-#include "base/environment.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/singleton.h"
-#include "base/nix/xdg_util.h"
#include "chrome/browser/ui/gtk/browser_titlebar.h"
-#include "ui/base/x/x11_util.h"
namespace {
@@ -25,84 +20,61 @@
} // namespace
-// Public interface:
-
-// static
-GConfTitlebarListener* GConfTitlebarListener::GetInstance() {
- return Singleton<GConfTitlebarListener>::get();
+GConfTitlebarListener::GConfTitlebarListener() : client_(NULL) {
}
-void GConfTitlebarListener::SetTitlebarButtons(BrowserTitlebar* titlebar) {
- if (client_) {
- titlebar->BuildButtons(current_value_);
- titlebars_.insert(titlebar);
- } else {
- titlebar->BuildButtons(BrowserTitlebar::kDefaultButtonString);
- }
+GConfTitlebarListener::~GConfTitlebarListener() {
}
-void GConfTitlebarListener::RemoveObserver(BrowserTitlebar* titlebar) {
- titlebars_.erase(titlebar);
-}
+bool GConfTitlebarListener::Init() {
+ client_ = gconf_client_get_default();
+ if (!client_)
+ return false;
-// Protected:
+ // Get the initial value of the key.
+ GError* error = NULL;
+ GConfValue* gconf_value = gconf_client_get(client_, kButtonLayoutKey, &error);
+ if (HandleGError(error, kButtonLayoutKey))
+ return false;
+ ParseAndStoreValue(gconf_value);
+ if (gconf_value)
+ gconf_value_free(gconf_value);
-GConfTitlebarListener::~GConfTitlebarListener() {}
+ // Register that we're interested in the values of this directory.
+ gconf_client_add_dir(client_, kMetacityGeneral, GCONF_CLIENT_PRELOAD_ONELEVEL,
+ &error);
+ if (HandleGError(error, kMetacityGeneral))
+ return false;
-// Private:
+ // Register to get notifies about changes to this key.
+ gconf_client_notify_add(
+ client_,
+ kButtonLayoutKey,
+ reinterpret_cast<void (*)(GConfClient*, guint, GConfEntry*, void*)>(
+ OnChangeNotificationThunk),
+ this,
+ NULL,
+ &error);
+ if (HandleGError(error, kButtonLayoutKey))
+ return false;
+ return true;
+}
-GConfTitlebarListener::GConfTitlebarListener() : client_(NULL) {
- scoped_ptr<base::Environment> env(base::Environment::Create());
- base::nix::DesktopEnvironment de =
- base::nix::GetDesktopEnvironment(env.get());
- if (de == base::nix::DESKTOP_ENVIRONMENT_GNOME ||
- de == base::nix::DESKTOP_ENVIRONMENT_UNITY ||
- ui::GuessWindowManager() == ui::WM_METACITY) {
- client_ = gconf_client_get_default();
- // If we fail to get a context, that's OK, since we'll just fallback on
- // not receiving gconf keys.
- if (client_) {
- // Get the initial value of the key.
- GError* error = NULL;
- GConfValue* gconf_value = gconf_client_get(client_, kButtonLayoutKey,
- &error);
- if (HandleGError(error, kButtonLayoutKey))
- return;
- ParseAndStoreValue(gconf_value);
- if (gconf_value)
- gconf_value_free(gconf_value);
-
- // Register that we're interested in the values of this directory.
- gconf_client_add_dir(client_, kMetacityGeneral,
- GCONF_CLIENT_PRELOAD_ONELEVEL, &error);
- if (HandleGError(error, kMetacityGeneral))
- return;
-
- // Register to get notifies about changes to this key.
- gconf_client_notify_add(
- client_, kButtonLayoutKey,
- reinterpret_cast<void (*)(GConfClient*, guint, GConfEntry*, void*)>(
- OnChangeNotificationThunk),
- this, NULL, &error);
- if (HandleGError(error, kButtonLayoutKey))
- return;
- }
- }
+std::string GConfTitlebarListener::GetCurrentValue() {
+ return current_value_;
}
void GConfTitlebarListener::OnChangeNotification(GConfClient* client,
guint cnxn_id,
GConfEntry* entry) {
- if (strcmp(gconf_entry_get_key(entry), kButtonLayoutKey) == 0) {
- GConfValue* gconf_value = gconf_entry_get_value(entry);
- ParseAndStoreValue(gconf_value);
+ if (strcmp(gconf_entry_get_key(entry), kButtonLayoutKey) != 0)
+ return;
- // Broadcast the new configuration to all windows:
- for (std::set<BrowserTitlebar*>::const_iterator it = titlebars_.begin();
- it != titlebars_.end(); ++it) {
- (*it)->BuildButtons(current_value_);
- }
- }
+ GConfValue* gconf_value = gconf_entry_get_value(entry);
+ ParseAndStoreValue(gconf_value);
+
+ // Broadcast the new configuration to all windows:
+ TitlebarListener::GetInstance()->SetTitleBars(current_value_);
}
bool GConfTitlebarListener::HandleGError(GError* error, const char* key) {

Powered by Google App Engine
This is Rietveld 408576698