summaryrefslogtreecommitdiff
path: root/unity-shared
diff options
authorAndrea Azzarone <azzaronea@gmail.com>2014-07-31 18:39:26 +0000
committerCI bot <ps-jenkins@lists.canonical.com>2014-07-31 18:39:26 +0000
commitca9ca5dfe0abae718e45d8b30cb891e723365b74 (patch)
tree3e31eebd455f7bce05408478634a3c1933022e1f /unity-shared
parent8d619731e143d87de273edccce194c940da73b5b (diff)
parent75772939c29273076cb05eb7009acb8ae8f54a85 (diff)
== Problem ==
Lockscreen capslock detection doesn't work well with remapped capslocks == Fix == Use gdk keymap to get the state of the caps lock. Fixes: 1347735 Approved by: PS Jenkins bot, Marco Trevisan (TreviƱo) (bzr r3849)
Diffstat (limited to 'unity-shared')
-rw-r--r--unity-shared/TextInput.cpp30
-rw-r--r--unity-shared/TextInput.h1
2 files changed, 6 insertions, 25 deletions
diff --git a/unity-shared/TextInput.cpp b/unity-shared/TextInput.cpp
index 23a4e3196..d8144990e 100644
--- a/unity-shared/TextInput.cpp
+++ b/unity-shared/TextInput.cpp
@@ -23,8 +23,6 @@
#include "unity-shared/RawPixel.h"
#include "unity-shared/PreviewStyle.h"
-#include <X11/XKBlib.h>
-
namespace unity
{
@@ -42,9 +40,6 @@ const RawPixel TOOLTIP_Y_OFFSET = 3_em;
const RawPixel TOOLTIP_OFFSET = 10_em;
const RawPixel DEFAULT_ICON_SIZE = 22_em;
-// Caps is on 0x1, couldn't find any #define in /usr/include/X11
-const int CAPS_STATE_ON = 0x1;
-
std::string WARNING_ICON = "dialog-warning-symbolic";
// Fonts
const std::string HINT_LABEL_DEFAULT_FONT_NAME = "Ubuntu";
@@ -114,7 +109,6 @@ TextInput::TextInput(NUX_FILE_LINE_DECL)
pango_entry_->SetFontSize(PANGO_ENTRY_FONT_SIZE);
pango_entry_->cursor_moved.connect([this](int i) { QueueDraw(); });
pango_entry_->mouse_down.connect(sigc::mem_fun(this, &TextInput::OnMouseButtonDown));
- pango_entry_->key_up.connect(sigc::mem_fun(this, &TextInput::OnKeyUp));
pango_entry_->end_key_focus.connect(sigc::mem_fun(this, &TextInput::OnEndKeyFocus));
pango_entry_->text_changed.connect([this](nux::TextEntry*) {
hint_->SetVisible(input_string().empty());
@@ -155,6 +149,10 @@ TextInput::TextInput(NUX_FILE_LINE_DECL)
"notify::gtk-font-name", sigc::mem_fun(this, &TextInput::OnFontChanged));
OnFontChanged(gtk_settings_get_default());
+ sig_manager_.Add<void, GdkKeymap*>(gdk_keymap_get_default(), "state-changed", [this](GdkKeymap*) {
+ CheckIfCapsLockOn();
+ });
+
input_string.SetGetterFunction(sigc::mem_fun(this, &TextInput::get_input_string));
input_string.SetSetterFunction(sigc::mem_fun(this, &TextInput::set_input_string));
im_active.SetGetterFunction(sigc::mem_fun(this, &TextInput::get_im_active));
@@ -174,14 +172,8 @@ TextInput::TextInput(NUX_FILE_LINE_DECL)
void TextInput::CheckIfCapsLockOn()
{
- Display *dpy = nux::GetGraphicsDisplay()->GetX11Display();
- unsigned int state = 0;
- XkbGetIndicatorState(dpy, XkbUseCoreKbd, &state);
-
- if ((state & CAPS_STATE_ON) == 1)
- caps_lock_on = true;
- else
- caps_lock_on = false;
+ GdkKeymap* keymap = gdk_keymap_get_default();
+ caps_lock_on = gdk_keymap_get_caps_lock_state(keymap) == FALSE ? false : true;
}
void TextInput::SetSpinnerVisible(bool visible)
@@ -418,16 +410,6 @@ void TextInput::UpdateBackground(bool force)
texture2D->UnReference();
}
-void TextInput::OnKeyUp(unsigned keysym,
- unsigned long keycode,
- unsigned long state)
-{
- if (!caps_lock_on && keysym == NUX_VK_CAPITAL)
- caps_lock_on = true;
- else if (caps_lock_on && keysym == NUX_VK_CAPITAL)
- caps_lock_on = false;
-}
-
void TextInput::OnMouseButtonDown(int x, int y, unsigned long button, unsigned long key)
{
hint_->SetVisible(false);
diff --git a/unity-shared/TextInput.h b/unity-shared/TextInput.h
index 1e708511e..a494997b9 100644
--- a/unity-shared/TextInput.h
+++ b/unity-shared/TextInput.h
@@ -99,7 +99,6 @@ private:
protected:
void OnInputHintChanged();
void OnMouseButtonDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
- void OnKeyUp(unsigned keysym, unsigned long keycode, unsigned long state);
void OnEndKeyFocus();
// getters & setters