diff options
author | Arnon Gilboa <agilboa@redhat.com> | 2009-12-30 12:19:54 +0200 |
---|---|---|
committer | Yaniv Kamay <ykamay@redhat.com> | 2009-12-30 22:09:25 +0200 |
commit | 02a07b2c067e629749cbe8a9f9cfbfb487a512d7 (patch) | |
tree | e73f6dc72a73b158369aa62e7220bd787eafcdc2 /client/application.cpp | |
parent | c57bcf6f4433446b858867712ece4abec4fb5c3d (diff) | |
download | spice-02a07b2c067e629749cbe8a9f9cfbfb487a512d7.tar.gz spice-02a07b2c067e629749cbe8a9f9cfbfb487a512d7.tar.xz spice-02a07b2c067e629749cbe8a9f9cfbfb487a512d7.zip |
spice: on_activate_screen generates on_key_down for any modifier pressed
-call SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc...) only once, in RedWindow::init()
-add Application::cleanup_globals() & RedWindow::cleanup()
-cleanup LowLevelKeyboardProc()
Diffstat (limited to 'client/application.cpp')
-rw-r--r-- | client/application.cpp | 57 |
1 files changed, 42 insertions, 15 deletions
diff --git a/client/application.cpp b/client/application.cpp index 2f24307d..ac5877c4 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -1062,6 +1062,32 @@ void Application::reset_sticky() _sticky_info.key = REDKEY_INVALID; } +struct ModifierKey { + int modifier; + RedKey key; +}; + +ModifierKey modifier_keys[] = { + {Platform::L_SHIFT_MODIFIER, REDKEY_L_SHIFT}, + {Platform::R_SHIFT_MODIFIER, REDKEY_R_SHIFT}, + {Platform::L_CTRL_MODIFIER, REDKEY_L_CTRL}, + {Platform::R_CTRL_MODIFIER, REDKEY_R_CTRL}, + {Platform::L_ALT_MODIFIER, REDKEY_L_ALT}, + {Platform::R_ALT_MODIFIER, REDKEY_R_ALT}, +}; + +void Application::sync_keyboard_modifiers() +{ + uint32_t modifiers = Platform::get_keyboard_modifiers(); + for (int i = 0; i < sizeof(modifier_keys) / sizeof(modifier_keys[0]); i++) { + if (modifiers & modifier_keys[i].modifier) { + on_key_down(modifier_keys[i].key); + } else { + on_key_up(modifier_keys[i].key); + } + } +} + void Application::on_key_down(RedKey key) { if (key <= 0 || key >= REDKEY_NUM_KEYS) { @@ -1179,6 +1205,7 @@ void Application::on_activate_screen(RedScreen* screen) { ASSERT(!_active_screen || (_active_screen == screen)); _active_screen = screen; + sync_keyboard_modifiers(); } void Application::on_start_screen_key_interception(RedScreen* screen) @@ -1380,6 +1407,7 @@ void Application::exit_full_screen() return; } LOG_INFO(""); + _changing_screens = true; release_capture(); for (int i = 0; i < (int)_screens.size(); i++) { if (_screens[i]) { @@ -1396,27 +1424,16 @@ void Application::exit_full_screen() restore_screens_size(); show(); _main_screen->activate(); + _changing_screens = false; } bool Application::toggle_full_screen() { - RedKey shift_pressed = REDKEY_INVALID; - - if (_keyboard_state[REDKEY_L_SHIFT]) { - shift_pressed = REDKEY_L_SHIFT; - } else if (_keyboard_state[REDKEY_R_SHIFT]) { - shift_pressed = REDKEY_R_SHIFT; - } if (_full_screen) { exit_full_screen(); } else { enter_full_screen(); } - uint32_t modifiers = Platform::get_keyboard_modifiers(); - if ((shift_pressed == REDKEY_L_SHIFT && (modifiers & Platform::L_SHIFT_MODIFIER)) || - (shift_pressed == REDKEY_R_SHIFT && (modifiers & Platform::R_SHIFT_MODIFIER))) { - on_key_down(shift_pressed); - } return _full_screen; } @@ -1978,15 +1995,25 @@ void Application::init_globals() RedWindow::init(); } +void Application::cleanup_globals() +{ + RedWindow::cleanup(); +} + int Application::main(int argc, char** argv, const char* version_str) { + int ret; + init_globals(); LOG_INFO("starting %s", version_str); std::auto_ptr<Application> app(new Application()); AutoAbort auto_abort(*app.get()); - if (!app->process_cmd_line(argc, argv)) { - return app->_exit_code; + if (app->process_cmd_line(argc, argv)) { + ret = app->run(); + } else { + ret = app->_exit_code; } - return app->run(); + cleanup_globals(); + return ret; } |