diff options
Diffstat (limited to 'platform/x11/os_x11.cpp')
-rw-r--r-- | platform/x11/os_x11.cpp | 72 |
1 files changed, 34 insertions, 38 deletions
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 1fd91ec3c1..ddb5237d1b 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -659,8 +659,6 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a #endif _ensure_user_data_dir(); - power_manager = memnew(PowerX11); - if (p_desired.layered) { set_window_per_pixel_transparency_enabled(true); } @@ -870,8 +868,6 @@ void OS_X11::finalize() { visual_server->finish(); memdelete(visual_server); - memdelete(power_manager); - #if defined(OPENGL_ENABLED) if (video_driver_index == VIDEO_DRIVER_GLES2) { @@ -1892,6 +1888,8 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { if (status == XLookupChars) { bool keypress = xkeyevent->type == KeyPress; unsigned int keycode = KeyMappingX11::get_keycode(keysym_keycode); + unsigned int physical_keycode = KeyMappingX11::get_scancode(xkeyevent->keycode); + if (keycode >= 'a' && keycode <= 'z') keycode -= 'a' - 'A'; @@ -1900,23 +1898,29 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { for (int i = 0; i < tmp.length(); i++) { Ref<InputEventKey> k; k.instance(); - if (keycode == 0 && tmp[i] == 0) { + if (physical_keycode == 0 && keycode == 0 && tmp[i] == 0) { continue; } + if (keycode == 0) + keycode = physical_keycode; + get_key_modifier_state(xkeyevent->state, k); k->set_unicode(tmp[i]); k->set_pressed(keypress); - k->set_scancode(keycode); + k->set_keycode(keycode); + + k->set_physical_keycode(physical_keycode); k->set_echo(false); - if (k->get_scancode() == KEY_BACKTAB) { + if (k->get_keycode() == KEY_BACKTAB) { //make it consistent across platforms. - k->set_scancode(KEY_TAB); + k->set_keycode(KEY_TAB); + k->set_physical_keycode(KEY_TAB); k->set_shift(true); } @@ -1946,6 +1950,7 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { // keysym, so it works in all platforms the same. unsigned int keycode = KeyMappingX11::get_keycode(keysym_keycode); + unsigned int physical_keycode = KeyMappingX11::get_scancode(xkeyevent->keycode); /* Phase 3, obtain a unicode character from the keysym */ @@ -1965,9 +1970,12 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { bool keypress = xkeyevent->type == KeyPress; - if (keycode == 0 && unicode == 0) + if (physical_keycode == 0 && keycode == 0 && unicode == 0) return; + if (keycode == 0) + keycode = physical_keycode; + /* Phase 5, determine modifier mask */ // No problems here, except I had no way to @@ -2004,8 +2012,10 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { // is correct, but the xorg developers are // not very helpful today. - ::Time tresh = ABSDIFF(peek_event.xkey.time, xkeyevent->time); - if (peek_event.type == KeyPress && tresh < 5) { +#define ABSDIFF(x, y) (((x) < (y)) ? ((y) - (x)) : ((x) - (y))) + ::Time threshold = ABSDIFF(peek_event.xkey.time, xkeyevent->time); +#undef ABSDIFF + if (peek_event.type == KeyPress && threshold < 5) { KeySym rk; XLookupString((XKeyEvent *)&peek_event, str, 256, &rk, NULL); if (rk == keysym_keycode) { @@ -2029,37 +2039,39 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { if (keycode >= 'a' && keycode <= 'z') keycode -= 'a' - 'A'; - k->set_scancode(keycode); + k->set_keycode(keycode); + k->set_physical_keycode(physical_keycode); k->set_unicode(unicode); k->set_echo(p_echo); - if (k->get_scancode() == KEY_BACKTAB) { + if (k->get_keycode() == KEY_BACKTAB) { //make it consistent across platforms. - k->set_scancode(KEY_TAB); + k->set_keycode(KEY_TAB); + k->set_physical_keycode(KEY_TAB); k->set_shift(true); } //don't set mod state if modifier keys are released by themselves //else event.is_action() will not work correctly here if (!k->is_pressed()) { - if (k->get_scancode() == KEY_SHIFT) + if (k->get_keycode() == KEY_SHIFT) k->set_shift(false); - else if (k->get_scancode() == KEY_CONTROL) + else if (k->get_keycode() == KEY_CONTROL) k->set_control(false); - else if (k->get_scancode() == KEY_ALT) + else if (k->get_keycode() == KEY_ALT) k->set_alt(false); - else if (k->get_scancode() == KEY_META) + else if (k->get_keycode() == KEY_META) k->set_metakey(false); } - bool last_is_pressed = Input::get_singleton()->is_key_pressed(k->get_scancode()); + bool last_is_pressed = Input::get_singleton()->is_key_pressed(k->get_keycode()); if (k->is_pressed()) { if (last_is_pressed) { k->set_echo(true); } } - //printf("key: %x\n",k->get_scancode()); + //printf("key: %x\n",k->get_keycode()); input->accumulate_input_event(k); } @@ -3080,8 +3092,6 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c // allocate memory to contain the whole file cursor_image->pixels = (XcursorPixel *)memalloc(size); - image->lock(); - for (XcursorPixel index = 0; index < image_size; index++) { int row_index = floor(index / texture_size.width) + atlas_rect.position.y; int column_index = (index % int(texture_size.width)) + atlas_rect.position.x; @@ -3094,8 +3104,6 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c *(cursor_image->pixels + index) = image->get_pixel(column_index, row_index).to_argb32(); } - image->unlock(); - ERR_FAIL_COND(cursor_image->pixels == NULL); // Save it for a further usage @@ -3273,10 +3281,10 @@ void OS_X11::set_icon(const Ref<Image> &p_icon) { pd.write[0] = w; pd.write[1] = h; - PoolVector<uint8_t>::Read r = img->get_data().read(); + const uint8_t *r = img->get_data().ptr(); long *wr = &pd.write[2]; - uint8_t const *pr = r.ptr(); + uint8_t const *pr = r; for (int i = 0; i < w * h; i++) { long v = 0; @@ -3389,18 +3397,6 @@ void OS_X11::set_context(int p_context) { } } -OS::PowerState OS_X11::get_power_state() { - return power_manager->get_power_state(); -} - -int OS_X11::get_power_seconds_left() { - return power_manager->get_power_seconds_left(); -} - -int OS_X11::get_power_percent_left() { - return power_manager->get_power_percent_left(); -} - void OS_X11::disable_crash_handler() { crash_handler.disable(); } |