From 8b36ed546068bd365c1345f937f3b26cd2b7d0d4 Mon Sep 17 00:00:00 2001 From: Arnon Gilboa Date: Tue, 17 Nov 2009 16:44:50 +0200 Subject: spice: on toggle_full_screen, generate on_key_down if shift is still pressed --- client/application.cpp | 12 ++++++++++++ client/inputs_channel.cpp | 4 ++-- client/platform.h | 20 +++++++++++++++++++- client/windows/platform.cpp | 21 +++++++++++++++++++-- client/x11/platform.cpp | 25 ++++++++++++++++++++++--- 5 files changed, 74 insertions(+), 8 deletions(-) (limited to 'client') diff --git a/client/application.cpp b/client/application.cpp index 42a65f6c..db930400 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -1231,11 +1231,23 @@ void Application::exit_full_screen() bool Application::toggle_full_screen() { + RedKey shift_pressed = REDKEY_INVALID; + + if (_key_table[REDKEY_L_SHIFT].press) { + shift_pressed = REDKEY_L_SHIFT; + } else if (_key_table[REDKEY_R_SHIFT].press) { + 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; } diff --git a/client/inputs_channel.cpp b/client/inputs_channel.cpp index d686be22..df434937 100644 --- a/client/inputs_channel.cpp +++ b/client/inputs_channel.cpp @@ -327,7 +327,7 @@ void InputsChannel::set_local_modifiers() modifiers |= Platform::CAPS_LOCK_MODIFIER; } - Platform::set_keyboard_modifiers(_modifiers); + Platform::set_keyboard_lock_modifiers(_modifiers); } void InputsChannel::on_focus_in() @@ -335,7 +335,7 @@ void InputsChannel::on_focus_in() #ifdef SYNC_REMOTH_MODIFIRES Message* message = new Message(REDC_INPUTS_KEY_MODIFAIERS, sizeof(RedcKeyDown)); RedcKeyModifiers* modifiers = (RedcKeyModifiers*)message->data(); - modifiers->modifiers = Platform::get_keyboard_modifiers(); + modifiers->modifiers = Platform::get_keyboard_lock_modifiers(); post_message(message); #else set_local_modifiers(); diff --git a/client/platform.h b/client/platform.h index 5dca7177..ece61c9d 100644 --- a/client/platform.h +++ b/client/platform.h @@ -77,8 +77,26 @@ public: CAPS_LOCK_MODIFIER = (1 << CAPS_LOCK_MODIFIER_SHIFT), }; + static uint32_t get_keyboard_lock_modifiers(); + static void set_keyboard_lock_modifiers(uint32_t modifiers); + + enum { + L_SHIFT_MODIFIER_SHIFT, + R_SHIFT_MODIFIER_SHIFT, + L_CTRL_MODIFIER_SHIFT, + R_CTRL_MODIFIER_SHIFT, + L_ALT_MODIFIER_SHIFT, + R_ALT_MODIFIER_SHIFT, + + L_SHIFT_MODIFIER = (1 << L_SHIFT_MODIFIER_SHIFT), + R_SHIFT_MODIFIER = (1 << R_SHIFT_MODIFIER_SHIFT), + L_CTRL_MODIFIER = (1 << L_CTRL_MODIFIER_SHIFT), + R_CTRL_MODIFIER = (1 << R_CTRL_MODIFIER_SHIFT), + L_ALT_MODIFIER = (1 << L_ALT_MODIFIER_SHIFT), + R_ALT_MODIFIER = (1 << R_ALT_MODIFIER_SHIFT), + }; + static uint32_t get_keyboard_modifiers(); - static void set_keyboard_modifiers(uint32_t modifiers); static LocalCursor* create_local_cursor(CursorData* cursor_data); static LocalCursor* create_inactive_cursor(); diff --git a/client/windows/platform.cpp b/client/windows/platform.cpp index 24c9ca93..6b218404 100644 --- a/client/windows/platform.cpp +++ b/client/windows/platform.cpp @@ -444,7 +444,7 @@ static void toggle_modifier(int key) SendInput(2, inputs, sizeof(INPUT)); } -uint32_t Platform::get_keyboard_modifiers() +uint32_t Platform::get_keyboard_lock_modifiers() { uint32_t modifiers = 0; if ((GetKeyState(VK_SCROLL) & 1)) { @@ -459,7 +459,7 @@ uint32_t Platform::get_keyboard_modifiers() return modifiers; } -void Platform::set_keyboard_modifiers(uint32_t modifiers) +void Platform::set_keyboard_lock_modifiers(uint32_t modifiers) { if (((modifiers >> SCROLL_LOCK_MODIFIER_SHIFT) & 1) != (GetKeyState(VK_SCROLL) & 1)) { toggle_modifier(VK_SCROLL); @@ -474,6 +474,23 @@ void Platform::set_keyboard_modifiers(uint32_t modifiers) } } +#define KEY_BIT(keymap, key, bit) (keymap[key] & 0x80 ? bit : 0) + +uint32_t Platform::get_keyboard_modifiers() +{ + BYTE keymap[256]; + + if (!GetKeyboardState(keymap)) { + return 0; + } + return KEY_BIT(keymap, VK_LSHIFT, L_SHIFT_MODIFIER) | + KEY_BIT(keymap, VK_RSHIFT, R_SHIFT_MODIFIER) | + KEY_BIT(keymap, VK_LCONTROL, L_CTRL_MODIFIER) | + KEY_BIT(keymap, VK_RCONTROL, R_CTRL_MODIFIER) | + KEY_BIT(keymap, VK_LMENU, L_ALT_MODIFIER) | + KEY_BIT(keymap, VK_RMENU, R_ALT_MODIFIER); +} + class WinBaseLocalCursor: public LocalCursor { public: WinBaseLocalCursor() : _handle (0) {} diff --git a/client/x11/platform.cpp b/client/x11/platform.cpp index 8288f555..10d621ba 100644 --- a/client/x11/platform.cpp +++ b/client/x11/platform.cpp @@ -2148,7 +2148,7 @@ void Platform::set_process_loop(ProcessLoop& main_process_loop) main_loop->add_file(*x_event_handler); } -uint32_t Platform::get_keyboard_modifiers() +uint32_t Platform::get_keyboard_lock_modifiers() { XKeyboardState keyboard_state; uint32_t modifiers = 0; @@ -2195,9 +2195,9 @@ static void set_keyboard_led(XLed led, int set) } } -void Platform::set_keyboard_modifiers(uint32_t modifiers) +void Platform::set_keyboard_lock_modifiers(uint32_t modifiers) { - uint32_t now = get_keyboard_modifiers(); + uint32_t now = get_keyboard_lock_modifiers(); if ((now & CAPS_LOCK_MODIFIER) != (modifiers & CAPS_LOCK_MODIFIER)) { set_keyboard_led(X11_CAPS_LOCK_LED, !!(modifiers & CAPS_LOCK_MODIFIER)); @@ -2210,6 +2210,25 @@ void Platform::set_keyboard_modifiers(uint32_t modifiers) } } +uint32_t key_bit(char* keymap, int key, uint32_t bit) +{ + KeyCode key_code = XKeysymToKeycode(x_display, key); + return (((keymap[key_code >> 3] >> (key_code & 7)) & 1) ? bit : 0); +} + +uint32_t Platform::get_keyboard_modifiers() +{ + char keymap[32]; + + XQueryKeymap(x_display, keymap); + return key_bit(keymap, XK_Shift_L, L_SHIFT_MODIFIER) | + key_bit(keymap, XK_Shift_R, R_SHIFT_MODIFIER) | + key_bit(keymap, XK_Control_L, L_CTRL_MODIFIER) | + key_bit(keymap, XK_Control_R, R_CTRL_MODIFIER) | + key_bit(keymap, XK_Alt_L, L_ALT_MODIFIER) | + key_bit(keymap, XK_Alt_R, R_ALT_MODIFIER); +} + WaveRecordAbstract* Platform::create_recorder(RecordClient& client, uint32_t sampels_per_sec, uint32_t bits_per_sample, -- cgit