summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-12-03 23:02:52 +0300
committerAndrei Karas <akaras@inbox.ru>2012-12-03 23:02:52 +0300
commit861505d90c9f3d526f41b645873584f520eff7b1 (patch)
treea91b0be670349339ebfc19b22bf28fc475aed1db
parent494ac0ccdf545e8055c83c22b8b2fbf9e045b32a (diff)
downloadmanaplus-861505d90c9f3d526f41b645873584f520eff7b1.tar.gz
manaplus-861505d90c9f3d526f41b645873584f520eff7b1.tar.bz2
manaplus-861505d90c9f3d526f41b645873584f520eff7b1.tar.xz
manaplus-861505d90c9f3d526f41b645873584f520eff7b1.zip
Add option to protect chat focus.
Enabled by default.
-rw-r--r--src/defaults.cpp1
-rw-r--r--src/gui/chatwindow.cpp29
-rw-r--r--src/gui/setup_chat.cpp3
3 files changed, 29 insertions, 4 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp
index dead34aaf..0e2f89579 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -279,6 +279,7 @@ DefaultsData* getConfigDefaults()
AddDEF("ministatussaved", 0);
AddDEF("allowscreensaver", false);
AddDEF("debugOpenGL", 0);
+ AddDEF("protectChatFocus", true);
return configData;
}
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp
index 7919fff24..11f399537 100644
--- a/src/gui/chatwindow.cpp
+++ b/src/gui/chatwindow.cpp
@@ -79,7 +79,8 @@ class ChatInput final : public TextField, public gcn::FocusListener
TextField(window, "", false),
gcn::FocusListener(),
mWindow(window),
- mChatTabs(tabs)
+ mChatTabs(tabs),
+ mFocusGaining(false)
{
setVisible(false);
addFocusListener(this);
@@ -93,9 +94,17 @@ class ChatInput final : public TextField, public gcn::FocusListener
*/
void focusLost(const gcn::Event &event A_UNUSED)
{
- processVisible(false);
- if (chatWindow)
- chatWindow->updateVisibility();
+ if (mFocusGaining || !config.getBoolValue("protectChatFocus"))
+ {
+ processVisible(false);
+ if (chatWindow)
+ chatWindow->updateVisibility();
+ mFocusGaining = false;
+ return;
+ }
+ mFocusGaining = true;
+ requestFocus();
+ mFocusGaining = false;
}
void processVisible(const bool n)
@@ -103,14 +112,25 @@ class ChatInput final : public TextField, public gcn::FocusListener
if (!mWindow || isVisible() == n)
return;
+ if (!n)
+ mFocusGaining = true;
setVisible(n);
if (config.getBoolValue("hideChatInput"))
mWindow->adjustTabSize();
}
+ void unprotectFocus()
+ { mFocusGaining = true; }
+
+ void setVisible(bool visible)
+ {
+ TextField::setVisible(visible);
+ }
+
private:
ChatWindow *mWindow;
TabbedArea *mChatTabs;
+ bool mFocusGaining;
};
const char *COLOR_NAME[14] =
@@ -503,6 +523,7 @@ void ChatWindow::action(const gcn::ActionEvent &event)
if (message.empty() || !mReturnToggles)
{
// Remove focus and hide input
+ mChatInput->unprotectFocus();
if (mFocusHandler)
mFocusHandler->focusNone();
diff --git a/src/gui/setup_chat.cpp b/src/gui/setup_chat.cpp
index b03211872..7b4cdeb2a 100644
--- a/src/gui/setup_chat.cpp
+++ b/src/gui/setup_chat.cpp
@@ -56,6 +56,9 @@ Setup_Chat::Setup_Chat(const Widget2 *const widget) :
new SetupItemCheckBox(_("Auto hide chat window."), "",
"autohideChat", this, "autohideChatEvent");
+ new SetupItemCheckBox(_("Protect chat focus."), "",
+ "protectChatFocus", this, "protectChatFocusEvent");
+
new SetupItemLabel(_("Colors"), "", this);