Index: chrome/browser/ui/libgtk2ui/gconf_listener.cc |
diff --git a/chrome/browser/ui/libgtk2ui/gconf_titlebar_listener.cc b/chrome/browser/ui/libgtk2ui/gconf_listener.cc |
similarity index 50% |
rename from chrome/browser/ui/libgtk2ui/gconf_titlebar_listener.cc |
rename to chrome/browser/ui/libgtk2ui/gconf_listener.cc |
index 6ec2fea70398dfef3194f5da58c6bad89a43f599..68e538efd421e091fbd106c129b99907c9950733 100644 |
--- a/chrome/browser/ui/libgtk2ui/gconf_titlebar_listener.cc |
+++ b/chrome/browser/ui/libgtk2ui/gconf_listener.cc |
@@ -2,10 +2,12 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/ui/libgtk2ui/gconf_titlebar_listener.h" |
+#include "chrome/browser/ui/libgtk2ui/gconf_listener.h" |
#include <gtk/gtk.h> |
+#include "base/bind.h" |
+#include "base/callback.h" |
#include "base/environment.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/nix/xdg_util.h" |
@@ -19,11 +21,17 @@ namespace { |
// The GConf key we read for the button placement string. Even through the key |
// has "metacity" in it, it's shared between metacity and compiz. |
-const char* kButtonLayoutKey = "/apps/metacity/general/button_layout"; |
+const char kButtonLayoutKey[] = "/apps/metacity/general/button_layout"; |
+ |
+// The GConf key we read for what to do in case of middle clicks on non client |
+// area. Even through the key has "metacity" in it, it's shared between |
+// metacity and compiz. |
+const char kMiddleClickActionKey[] = |
+ "/apps/metacity/general/action_middle_click_titlebar"; |
// GConf requires us to subscribe to a parent directory before we can subscribe |
// to changes in an individual key in that directory. |
-const char* kMetacityGeneral = "/apps/metacity/general"; |
+const char kMetacityGeneral[] = "/apps/metacity/general"; |
const char kDefaultButtonString[] = ":minimize,maximize,close"; |
@@ -33,7 +41,7 @@ namespace libgtk2ui { |
// Public interface: |
-GConfTitlebarListener::GConfTitlebarListener(Gtk2UI* delegate) |
+GConfListener::GConfListener(Gtk2UI* delegate) |
: delegate_(delegate), |
client_(NULL) { |
scoped_ptr<base::Environment> env(base::Environment::Create()); |
@@ -46,49 +54,64 @@ GConfTitlebarListener::GConfTitlebarListener(Gtk2UI* delegate) |
// 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. |
+ GError* error = NULL; |
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; |
+ // Get the initial value of the keys we're interested in. |
+ GetAndRegister(kButtonLayoutKey, |
+ base::Bind(&GConfListener::ParseAndStoreButtonValue, |
+ base::Unretained(this))); |
+ GetAndRegister(kMiddleClickActionKey, |
+ base::Bind(&GConfListener::ParseAndStoreMiddleClickValue, |
+ base::Unretained(this))); |
} |
} |
} |
-GConfTitlebarListener::~GConfTitlebarListener() { |
+GConfListener::~GConfListener() { |
} |
// Private: |
-void GConfTitlebarListener::OnChangeNotification(GConfClient* client, |
- guint cnxn_id, |
- GConfEntry* entry) { |
+void GConfListener::GetAndRegister( |
+ const char* key_to_subscribe, |
+ const base::Callback<void(GConfValue*)>& initial_setter) { |
+ GError* error = NULL; |
+ GConfValue* gconf_value = gconf_client_get(client_, key_to_subscribe, |
+ &error); |
+ if (HandleGError(error, key_to_subscribe)) |
+ return; |
+ initial_setter.Run(gconf_value); |
+ if (gconf_value) |
+ gconf_value_free(gconf_value); |
+ |
+ // Register to get notifies about changes to this key. |
+ gconf_client_notify_add( |
+ client_, key_to_subscribe, |
+ reinterpret_cast<void (*)(GConfClient*, guint, GConfEntry*, void*)>( |
+ OnChangeNotificationThunk), |
+ this, NULL, &error); |
+ if (HandleGError(error, key_to_subscribe)) |
+ return; |
+} |
+ |
+void GConfListener::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); |
+ ParseAndStoreButtonValue(gconf_value); |
+ } else if (strcmp(gconf_entry_get_key(entry), kMiddleClickActionKey) == 0) { |
+ GConfValue* gconf_value = gconf_entry_get_value(entry); |
+ ParseAndStoreMiddleClickValue(gconf_value); |
} |
} |
-bool GConfTitlebarListener::HandleGError(GError* error, const char* key) { |
+bool GConfListener::HandleGError(GError* error, const char* key) { |
if (error != NULL) { |
LOG(ERROR) << "Error with gconf key '" << key << "': " << error->message; |
g_error_free(error); |
@@ -99,7 +122,7 @@ bool GConfTitlebarListener::HandleGError(GError* error, const char* key) { |
return false; |
} |
-void GConfTitlebarListener::ParseAndStoreValue(GConfValue* gconf_value) { |
+void GConfListener::ParseAndStoreButtonValue(GConfValue* gconf_value) { |
std::string button_string; |
if (gconf_value) { |
const char* value = gconf_value_get_string(gconf_value); |
@@ -136,4 +159,29 @@ void GConfTitlebarListener::ParseAndStoreValue(GConfValue* gconf_value) { |
delegate_->SetWindowButtonOrdering(leading_buttons, trailing_buttons); |
} |
+void GConfListener::ParseAndStoreMiddleClickValue(GConfValue* gconf_value) { |
+ Gtk2UI::NonClientMiddleClickAction action = |
+ views::LinuxUI::MIDDLE_CLICK_ACTION_LOWER; |
+ if (gconf_value) { |
+ const char* value = gconf_value_get_string(gconf_value); |
+ |
+ if (strcmp(value, "none") == 0) { |
+ action = views::LinuxUI::MIDDLE_CLICK_ACTION_NONE; |
+ } else if (strcmp(value, "lower") == 0) { |
+ action = views::LinuxUI::MIDDLE_CLICK_ACTION_LOWER; |
+ } else if (strcmp(value, "minimize") == 0) { |
+ action = views::LinuxUI::MIDDLE_CLICK_ACTION_MINIMIZE; |
+ } else if (strcmp(value, "toggle-maximize") == 0) { |
+ action = views::LinuxUI::MIDDLE_CLICK_ACTION_TOGGLE_MAXIMIZE; |
+ } else { |
+ // While we want to have the default state be lower if there isn't a |
+ // value, we want to default to no action if the user has explicitly |
+ // chose an action that we don't implement. |
+ action = views::LinuxUI::MIDDLE_CLICK_ACTION_NONE; |
+ } |
+ } |
+ |
+ delegate_->SetNonClientMiddleClickAction(action); |
+} |
+ |
} // namespace libgtk2ui |