Wayland: fix Fl::event_key(int)
This commit is contained in:
parent
7d167b3cf1
commit
13ce93330a
@ -26,6 +26,7 @@
|
||||
#include <FL/platform.H>
|
||||
#include <FL/fl_ask.H>
|
||||
#include <FL/filename.H>
|
||||
#include <FL/Fl_Int_Vector.H>
|
||||
#include "../../print_button.h"
|
||||
#include <dlfcn.h>
|
||||
#include <linux/input.h>
|
||||
@ -131,6 +132,8 @@ struct pointer_output {
|
||||
- Fl_Wayland_Window_Driver::update_scale() sets the scale info of the records for a given window
|
||||
*/
|
||||
|
||||
static Fl_Int_Vector key_vector; // used by Fl_Wayland_Screen_Driver::event_key()
|
||||
|
||||
Fl_Wayland_Screen_Driver::compositor_name Fl_Wayland_Screen_Driver::compositor = Fl_Wayland_Screen_Driver::unspecified;
|
||||
|
||||
|
||||
@ -647,6 +650,23 @@ static dead_key_struct dead_keys[] = {
|
||||
|
||||
const int dead_key_count = sizeof(dead_keys)/sizeof(struct dead_key_struct);
|
||||
|
||||
|
||||
static int search_int_vector(Fl_Int_Vector& v, int val) {
|
||||
for (int pos = 0; pos < v.size(); pos++) {
|
||||
if (v[pos] == val) return pos;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static void remove_int_vector(Fl_Int_Vector& v, int val) {
|
||||
int pos = search_int_vector(v, val);
|
||||
if (pos < 0) return;
|
||||
int last = v.pop_back();
|
||||
if (last != val) v[pos] = last;
|
||||
}
|
||||
|
||||
|
||||
static void wl_keyboard_key(void *data, struct wl_keyboard *wl_keyboard,
|
||||
uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
|
||||
{
|
||||
@ -662,9 +682,21 @@ fprintf(stderr, "key %s: sym: %-12s(%d) code:%u fl_win=%p, ", action, buf, sym,
|
||||
xkb_state_key_get_utf8(seat->xkb_state, keycode, buf, sizeof(buf));
|
||||
//fprintf(stderr, "utf8: '%s' e_length=%d [%d]\n", buf, (int)strlen(buf), *buf);
|
||||
Fl::e_keysym = sym;
|
||||
int for_key_vector = sym; // for support of Fl::event_key(int)
|
||||
// special processing for number keys == keycodes 10-19 :
|
||||
if (keycode >= 10 && keycode <= 18) Fl::e_keysym = keycode + 39;
|
||||
else if (keycode == 19) Fl::e_keysym = 48;
|
||||
if (keycode >= 10 && keycode <= 18) {
|
||||
Fl::e_keysym = keycode + 39;
|
||||
for_key_vector = '1' + (keycode - 10);
|
||||
} else if (keycode == 19) {
|
||||
Fl::e_keysym = '0';
|
||||
for_key_vector = '0';
|
||||
}
|
||||
if (for_key_vector >= 'a' && for_key_vector <= 'z') for_key_vector -= 32;
|
||||
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
||||
if (search_int_vector(key_vector, for_key_vector) < 0) key_vector.push_back(for_key_vector);
|
||||
} else {
|
||||
remove_int_vector(key_vector, for_key_vector);
|
||||
}
|
||||
Fl::e_text = buf;
|
||||
Fl::e_length = strlen(buf);
|
||||
// Process dead keys and compose sequences :
|
||||
@ -725,6 +757,7 @@ static void wl_keyboard_leave(void *data, struct wl_keyboard *wl_keyboard,
|
||||
seat->keyboard_surface = NULL;
|
||||
Fl_Window *win = Fl_Wayland_Screen_Driver::surface_to_window(surface);
|
||||
if (win) Fl::handle(FL_UNFOCUS, win);
|
||||
key_vector.size(0);
|
||||
}
|
||||
|
||||
static void wl_keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard,
|
||||
@ -1539,12 +1572,7 @@ void *Fl_Wayland_Screen_Driver::control_maximize_button(void *data) {
|
||||
|
||||
|
||||
int Fl_Wayland_Screen_Driver::event_key(int k) {
|
||||
if (k > FL_Button && k <= FL_Button+8)
|
||||
return Fl::event_state(8<<(k-FL_Button));
|
||||
int sym = Fl::event_key();
|
||||
if (sym >= 'a' && sym <= 'z' ) sym -= 32;
|
||||
if (k >= 'a' && k <= 'z' ) k -= 32;
|
||||
return (Fl::event() == FL_KEYDOWN || Fl::event() == FL_SHORTCUT) && sym == k;
|
||||
return (search_int_vector(key_vector, k) >= 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user