This source file includes following definitions.
- Initialize
- Shutdown
- GetInstance
- xkb_event_base_
- Stop
- WillProcessEvent
- DidProcessEvent
- ProcessedXEvent
#include "chrome/browser/chromeos/events/system_key_event_listener.h"
#define XK_MISCELLANY 1
#include <X11/keysymdef.h>
#include <X11/XF86keysym.h>
#include <X11/XKBlib.h>
#undef Status
#include "base/message_loop/message_loop.h"
#include "chromeos/ime/input_method_manager.h"
#include "chromeos/ime/xkeyboard.h"
#include "ui/base/x/x11_util.h"
namespace chromeos {
namespace {
static SystemKeyEventListener* g_system_key_event_listener = NULL;
}
void SystemKeyEventListener::Initialize() {
CHECK(!g_system_key_event_listener);
g_system_key_event_listener = new SystemKeyEventListener();
}
void SystemKeyEventListener::Shutdown() {
if (g_system_key_event_listener) {
delete g_system_key_event_listener;
g_system_key_event_listener = NULL;
}
}
SystemKeyEventListener* SystemKeyEventListener::GetInstance() {
return g_system_key_event_listener;
}
SystemKeyEventListener::SystemKeyEventListener()
: stopped_(false),
xkb_event_base_(0) {
XDisplay* display = gfx::GetXDisplay();
int xkb_major_version = XkbMajorVersion;
int xkb_minor_version = XkbMinorVersion;
if (!XkbQueryExtension(display,
NULL,
&xkb_event_base_,
NULL,
&xkb_major_version,
&xkb_minor_version)) {
LOG(WARNING) << "Could not query Xkb extension";
}
if (!XkbSelectEvents(display, XkbUseCoreKbd,
XkbStateNotifyMask,
XkbStateNotifyMask)) {
LOG(WARNING) << "Could not install Xkb Indicator observer";
}
base::MessageLoopForUI::current()->AddObserver(this);
}
SystemKeyEventListener::~SystemKeyEventListener() {
Stop();
}
void SystemKeyEventListener::Stop() {
if (stopped_)
return;
base::MessageLoopForUI::current()->RemoveObserver(this);
stopped_ = true;
}
base::EventStatus SystemKeyEventListener::WillProcessEvent(
const base::NativeEvent& event) {
return ProcessedXEvent(event) ? base::EVENT_HANDLED : base::EVENT_CONTINUE;
}
void SystemKeyEventListener::DidProcessEvent(const base::NativeEvent& event) {
}
bool SystemKeyEventListener::ProcessedXEvent(XEvent* xevent) {
input_method::InputMethodManager* input_method_manager =
input_method::InputMethodManager::Get();
if (xevent->type == xkb_event_base_) {
XkbEvent* xkey_event = reinterpret_cast<XkbEvent*>(xevent);
if (xkey_event->any.xkb_type == XkbStateNotify) {
if (xkey_event->state.mods) {
input_method_manager->GetXKeyboard()->DisableNumLock();
}
return true;
}
}
return false;
}
}