2012-06-21 23:52:19 +04:00
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2012 Openismus GmbH
|
2012-09-10 01:08:32 +04:00
|
|
|
|
* Copyright © 2012 Intel Corporation
|
2012-06-21 23:52:19 +04:00
|
|
|
|
*
|
2015-06-11 08:48:59 +03:00
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2012-06-21 23:52:19 +04:00
|
|
|
|
*
|
2015-06-11 08:48:59 +03:00
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2012-06-21 23:52:19 +04:00
|
|
|
|
*/
|
|
|
|
|
|
2014-04-07 15:40:35 +04:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2016-06-23 12:59:34 +03:00
|
|
|
|
#include <stdbool.h>
|
2016-07-19 14:16:27 +03:00
|
|
|
|
#include <stdint.h>
|
2012-06-21 23:52:19 +04:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2019-04-27 00:57:31 +03:00
|
|
|
|
#include <errno.h>
|
2012-06-21 23:52:19 +04:00
|
|
|
|
|
|
|
|
|
#include <linux/input.h>
|
|
|
|
|
#include <cairo.h>
|
|
|
|
|
|
|
|
|
|
#include "window.h"
|
2015-11-17 11:00:30 +03:00
|
|
|
|
#include "input-method-unstable-v1-client-protocol.h"
|
2015-11-17 11:00:29 +03:00
|
|
|
|
#include "text-input-unstable-v1-client-protocol.h"
|
2016-03-17 00:15:18 +03:00
|
|
|
|
#include "shared/xalloc.h"
|
2013-01-17 00:26:44 +04:00
|
|
|
|
|
2013-04-18 18:47:17 +04:00
|
|
|
|
struct keyboard;
|
|
|
|
|
|
2012-06-21 23:52:19 +04:00
|
|
|
|
struct virtual_keyboard {
|
2015-11-17 11:00:30 +03:00
|
|
|
|
struct zwp_input_panel_v1 *input_panel;
|
|
|
|
|
struct zwp_input_method_v1 *input_method;
|
|
|
|
|
struct zwp_input_method_context_v1 *context;
|
2012-06-21 23:52:19 +04:00
|
|
|
|
struct display *display;
|
2013-04-18 18:47:29 +04:00
|
|
|
|
struct output *output;
|
2012-09-10 01:08:43 +04:00
|
|
|
|
char *preedit_string;
|
2013-01-17 00:26:41 +04:00
|
|
|
|
uint32_t preedit_style;
|
2012-11-18 22:06:44 +04:00
|
|
|
|
struct {
|
|
|
|
|
xkb_mod_mask_t shift_mask;
|
|
|
|
|
} keysym;
|
2013-01-17 00:26:39 +04:00
|
|
|
|
uint32_t serial;
|
2013-01-17 00:26:44 +04:00
|
|
|
|
uint32_t content_hint;
|
|
|
|
|
uint32_t content_purpose;
|
2013-04-18 18:47:16 +04:00
|
|
|
|
char *preferred_language;
|
2013-01-31 18:52:20 +04:00
|
|
|
|
char *surrounding_text;
|
2013-04-18 18:47:41 +04:00
|
|
|
|
uint32_t surrounding_cursor;
|
2013-04-18 18:47:17 +04:00
|
|
|
|
struct keyboard *keyboard;
|
2016-06-23 12:59:34 +03:00
|
|
|
|
bool toplevel;
|
2021-09-15 07:54:29 +03:00
|
|
|
|
bool overlay;
|
2021-05-25 14:27:37 +03:00
|
|
|
|
struct zwp_input_panel_surface_v1 *ips;
|
2012-06-21 23:52:19 +04:00
|
|
|
|
};
|
|
|
|
|
|
2012-09-10 01:08:42 +04:00
|
|
|
|
enum key_type {
|
|
|
|
|
keytype_default,
|
|
|
|
|
keytype_backspace,
|
|
|
|
|
keytype_enter,
|
|
|
|
|
keytype_space,
|
|
|
|
|
keytype_switch,
|
|
|
|
|
keytype_symbols,
|
2012-09-17 17:28:07 +04:00
|
|
|
|
keytype_tab,
|
|
|
|
|
keytype_arrow_up,
|
|
|
|
|
keytype_arrow_left,
|
|
|
|
|
keytype_arrow_right,
|
2013-01-17 00:26:41 +04:00
|
|
|
|
keytype_arrow_down,
|
|
|
|
|
keytype_style
|
2012-09-10 01:08:42 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct key {
|
|
|
|
|
enum key_type key_type;
|
|
|
|
|
|
|
|
|
|
char *label;
|
2014-04-15 14:38:31 +04:00
|
|
|
|
char *uppercase;
|
|
|
|
|
char *symbol;
|
2012-09-10 01:08:42 +04:00
|
|
|
|
|
|
|
|
|
unsigned int width;
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-17 00:26:44 +04:00
|
|
|
|
struct layout {
|
|
|
|
|
const struct key *keys;
|
|
|
|
|
uint32_t count;
|
|
|
|
|
|
|
|
|
|
uint32_t columns;
|
|
|
|
|
uint32_t rows;
|
2013-04-18 18:47:16 +04:00
|
|
|
|
|
|
|
|
|
const char *language;
|
|
|
|
|
uint32_t text_direction;
|
2013-01-17 00:26:44 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct key normal_keys[] = {
|
2014-04-15 14:38:31 +04:00
|
|
|
|
{ keytype_default, "q", "Q", "1", 1},
|
|
|
|
|
{ keytype_default, "w", "W", "2", 1},
|
|
|
|
|
{ keytype_default, "e", "E", "3", 1},
|
|
|
|
|
{ keytype_default, "r", "R", "4", 1},
|
|
|
|
|
{ keytype_default, "t", "T", "5", 1},
|
|
|
|
|
{ keytype_default, "y", "Y", "6", 1},
|
|
|
|
|
{ keytype_default, "u", "U", "7", 1},
|
|
|
|
|
{ keytype_default, "i", "I", "8", 1},
|
|
|
|
|
{ keytype_default, "o", "O", "9", 1},
|
|
|
|
|
{ keytype_default, "p", "P", "0", 1},
|
|
|
|
|
{ keytype_backspace, "<--", "<--", "<--", 2},
|
|
|
|
|
|
|
|
|
|
{ keytype_tab, "->|", "->|", "->|", 1},
|
|
|
|
|
{ keytype_default, "a", "A", "-", 1},
|
|
|
|
|
{ keytype_default, "s", "S", "@", 1},
|
|
|
|
|
{ keytype_default, "d", "D", "*", 1},
|
|
|
|
|
{ keytype_default, "f", "F", "^", 1},
|
|
|
|
|
{ keytype_default, "g", "G", ":", 1},
|
|
|
|
|
{ keytype_default, "h", "H", ";", 1},
|
|
|
|
|
{ keytype_default, "j", "J", "(", 1},
|
|
|
|
|
{ keytype_default, "k", "K", ")", 1},
|
|
|
|
|
{ keytype_default, "l", "L", "~", 1},
|
|
|
|
|
{ keytype_enter, "Enter", "Enter", "Enter", 2},
|
|
|
|
|
|
|
|
|
|
{ keytype_switch, "ABC", "abc", "ABC", 2},
|
|
|
|
|
{ keytype_default, "z", "Z", "/", 1},
|
|
|
|
|
{ keytype_default, "x", "X", "\'", 1},
|
|
|
|
|
{ keytype_default, "c", "C", "\"", 1},
|
|
|
|
|
{ keytype_default, "v", "V", "+", 1},
|
|
|
|
|
{ keytype_default, "b", "B", "=", 1},
|
|
|
|
|
{ keytype_default, "n", "N", "?", 1},
|
|
|
|
|
{ keytype_default, "m", "M", "!", 1},
|
|
|
|
|
{ keytype_default, ",", ",", "\\", 1},
|
|
|
|
|
{ keytype_default, ".", ".", "|", 1},
|
|
|
|
|
{ keytype_switch, "ABC", "abc", "ABC", 1},
|
|
|
|
|
|
|
|
|
|
{ keytype_symbols, "?123", "?123", "abc", 1},
|
|
|
|
|
{ keytype_space, "", "", "", 5},
|
|
|
|
|
{ keytype_arrow_up, "/\\", "/\\", "/\\", 1},
|
|
|
|
|
{ keytype_arrow_left, "<", "<", "<", 1},
|
|
|
|
|
{ keytype_arrow_right, ">", ">", ">", 1},
|
|
|
|
|
{ keytype_arrow_down, "\\/", "\\/", "\\/", 1},
|
|
|
|
|
{ keytype_style, "", "", "", 2}
|
2013-01-17 00:26:41 +04:00
|
|
|
|
};
|
|
|
|
|
|
2013-01-17 00:26:44 +04:00
|
|
|
|
static const struct key numeric_keys[] = {
|
2014-04-15 14:38:31 +04:00
|
|
|
|
{ keytype_default, "1", "1", "1", 1},
|
|
|
|
|
{ keytype_default, "2", "2", "2", 1},
|
|
|
|
|
{ keytype_default, "3", "3", "3", 1},
|
|
|
|
|
{ keytype_default, "4", "4", "4", 1},
|
|
|
|
|
{ keytype_default, "5", "5", "5", 1},
|
|
|
|
|
{ keytype_default, "6", "6", "6", 1},
|
|
|
|
|
{ keytype_default, "7", "7", "7", 1},
|
|
|
|
|
{ keytype_default, "8", "8", "8", 1},
|
|
|
|
|
{ keytype_default, "9", "9", "9", 1},
|
|
|
|
|
{ keytype_default, "0", "0", "0", 1},
|
|
|
|
|
{ keytype_backspace, "<--", "<--", "<--", 2},
|
|
|
|
|
|
|
|
|
|
{ keytype_space, "", "", "", 4},
|
|
|
|
|
{ keytype_enter, "Enter", "Enter", "Enter", 2},
|
|
|
|
|
{ keytype_arrow_up, "/\\", "/\\", "/\\", 1},
|
|
|
|
|
{ keytype_arrow_left, "<", "<", "<", 1},
|
|
|
|
|
{ keytype_arrow_right, ">", ">", ">", 1},
|
|
|
|
|
{ keytype_arrow_down, "\\/", "\\/", "\\/", 1},
|
|
|
|
|
{ keytype_style, "", "", "", 2}
|
2013-01-17 00:26:44 +04:00
|
|
|
|
};
|
|
|
|
|
|
2013-04-18 18:47:16 +04:00
|
|
|
|
static const struct key arabic_keys[] = {
|
2014-04-15 14:38:31 +04:00
|
|
|
|
{ keytype_default, "ض", "ﹶ", "۱", 1},
|
|
|
|
|
{ keytype_default, "ص", "ﹰ", "۲", 1},
|
|
|
|
|
{ keytype_default, "ث", "ﹸ", "۳", 1},
|
|
|
|
|
{ keytype_default, "ق", "ﹲ", "۴", 1},
|
|
|
|
|
{ keytype_default, "ف", "ﻹ", "۵", 1},
|
|
|
|
|
{ keytype_default, "غ", "ﺇ", "۶", 1},
|
|
|
|
|
{ keytype_default, "ع", "`", "۷", 1},
|
|
|
|
|
{ keytype_default, "ه", "٪", "۸", 1},
|
|
|
|
|
{ keytype_default, "خ", ">", "۹", 1},
|
|
|
|
|
{ keytype_default, "ح", "<", "۰", 1},
|
|
|
|
|
{ keytype_backspace, "-->", "-->", "-->", 2},
|
|
|
|
|
|
|
|
|
|
{ keytype_tab, "->|", "->|", "->|", 1},
|
|
|
|
|
{ keytype_default, "ش", "ﹺ", "ﹼ", 1},
|
|
|
|
|
{ keytype_default, "س", "ﹴ", "!", 1},
|
|
|
|
|
{ keytype_default, "ي", "[", "@", 1},
|
|
|
|
|
{ keytype_default, "ب", "]", "#", 1},
|
|
|
|
|
{ keytype_default, "ل", "ﻷ", "$", 1},
|
|
|
|
|
{ keytype_default, "ا", "أ", "%", 1},
|
|
|
|
|
{ keytype_default, "ت", "-", "^", 1},
|
|
|
|
|
{ keytype_default, "ن", "x", "&", 1},
|
|
|
|
|
{ keytype_default, "م", "/", "*", 1},
|
|
|
|
|
{ keytype_default, "ك", ":", "_", 1},
|
|
|
|
|
{ keytype_default, "د", "\"", "+", 1},
|
|
|
|
|
{ keytype_enter, "Enter", "Enter", "Enter", 2},
|
|
|
|
|
|
|
|
|
|
{ keytype_switch, "Shift", "Base", "Shift", 2},
|
|
|
|
|
{ keytype_default, "ئ", "~", ")", 1},
|
|
|
|
|
{ keytype_default, "ء", "°", "(", 1},
|
|
|
|
|
{ keytype_default, "ؤ", "{", "\"", 1},
|
|
|
|
|
{ keytype_default, "ر", "}", "\'", 1},
|
|
|
|
|
{ keytype_default, "ى", "ﺁ", "؟", 1},
|
|
|
|
|
{ keytype_default, "ة", "'", "!", 1},
|
|
|
|
|
{ keytype_default, "و", ",", ";", 1},
|
|
|
|
|
{ keytype_default, "ﺯ", ".", "\\", 1},
|
|
|
|
|
{ keytype_default, "ظ", "؟", "=", 1},
|
|
|
|
|
{ keytype_switch, "Shift", "Base", "Shift", 2},
|
|
|
|
|
|
|
|
|
|
{ keytype_symbols, "؟٣٢١", "؟٣٢١", "Base", 1},
|
|
|
|
|
{ keytype_default, "ﻻ", "ﻵ", "|", 1},
|
|
|
|
|
{ keytype_default, ",", "،", "،", 1},
|
|
|
|
|
{ keytype_space, "", "", "", 6},
|
|
|
|
|
{ keytype_default, ".", "ذ", "]", 1},
|
|
|
|
|
{ keytype_default, "ط", "ﺝ", "[", 1},
|
|
|
|
|
{ keytype_style, "", "", "", 2}
|
2013-04-18 18:47:16 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2013-01-17 00:26:44 +04:00
|
|
|
|
static const struct layout normal_layout = {
|
|
|
|
|
normal_keys,
|
|
|
|
|
sizeof(normal_keys) / sizeof(*normal_keys),
|
|
|
|
|
12,
|
2013-04-18 18:47:16 +04:00
|
|
|
|
4,
|
|
|
|
|
"en",
|
2015-11-17 11:00:29 +03:00
|
|
|
|
ZWP_TEXT_INPUT_V1_TEXT_DIRECTION_LTR
|
2013-01-17 00:26:44 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct layout numeric_layout = {
|
|
|
|
|
numeric_keys,
|
|
|
|
|
sizeof(numeric_keys) / sizeof(*numeric_keys),
|
|
|
|
|
12,
|
2013-04-18 18:47:16 +04:00
|
|
|
|
2,
|
|
|
|
|
"en",
|
2015-11-17 11:00:29 +03:00
|
|
|
|
ZWP_TEXT_INPUT_V1_TEXT_DIRECTION_LTR
|
2013-04-18 18:47:16 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct layout arabic_layout = {
|
|
|
|
|
arabic_keys,
|
|
|
|
|
sizeof(arabic_keys) / sizeof(*arabic_keys),
|
|
|
|
|
13,
|
|
|
|
|
4,
|
|
|
|
|
"ar",
|
2015-11-17 11:00:29 +03:00
|
|
|
|
ZWP_TEXT_INPUT_V1_TEXT_DIRECTION_RTL
|
2013-01-17 00:26:44 +04:00
|
|
|
|
};
|
|
|
|
|
|
2013-01-17 00:26:41 +04:00
|
|
|
|
static const char *style_labels[] = {
|
|
|
|
|
"default",
|
2013-04-18 18:47:25 +04:00
|
|
|
|
"none",
|
2013-01-17 00:26:41 +04:00
|
|
|
|
"active",
|
|
|
|
|
"inactive",
|
|
|
|
|
"highlight",
|
|
|
|
|
"underline",
|
|
|
|
|
"selection",
|
|
|
|
|
"incorrect"
|
2012-09-10 01:08:42 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const double key_width = 60;
|
|
|
|
|
static const double key_height = 50;
|
|
|
|
|
|
|
|
|
|
enum keyboard_state {
|
2014-04-15 14:38:31 +04:00
|
|
|
|
KEYBOARD_STATE_DEFAULT,
|
|
|
|
|
KEYBOARD_STATE_UPPERCASE,
|
|
|
|
|
KEYBOARD_STATE_SYMBOLS
|
2012-09-10 01:08:42 +04:00
|
|
|
|
};
|
|
|
|
|
|
2012-06-21 23:52:19 +04:00
|
|
|
|
struct keyboard {
|
|
|
|
|
struct virtual_keyboard *keyboard;
|
|
|
|
|
struct window *window;
|
|
|
|
|
struct widget *widget;
|
2012-09-10 01:08:42 +04:00
|
|
|
|
|
|
|
|
|
enum keyboard_state state;
|
2012-06-21 23:52:19 +04:00
|
|
|
|
};
|
|
|
|
|
|
2014-01-10 11:55:30 +04:00
|
|
|
|
static void __attribute__ ((format (printf, 1, 2)))
|
|
|
|
|
dbg(const char *fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
va_list argp;
|
|
|
|
|
|
|
|
|
|
va_start(argp, fmt);
|
2018-11-23 15:10:16 +03:00
|
|
|
|
vfprintf(stderr, fmt, argp);
|
2014-01-10 11:55:30 +04:00
|
|
|
|
va_end(argp);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-17 00:26:41 +04:00
|
|
|
|
static const char *
|
|
|
|
|
label_from_key(struct keyboard *keyboard,
|
|
|
|
|
const struct key *key)
|
|
|
|
|
{
|
|
|
|
|
if (key->key_type == keytype_style)
|
|
|
|
|
return style_labels[keyboard->keyboard->preedit_style];
|
|
|
|
|
|
2014-04-15 14:38:31 +04:00
|
|
|
|
switch(keyboard->state) {
|
|
|
|
|
case KEYBOARD_STATE_DEFAULT:
|
2013-01-17 00:26:41 +04:00
|
|
|
|
return key->label;
|
2014-04-15 14:38:31 +04:00
|
|
|
|
case KEYBOARD_STATE_UPPERCASE:
|
|
|
|
|
return key->uppercase;
|
|
|
|
|
case KEYBOARD_STATE_SYMBOLS:
|
|
|
|
|
return key->symbol;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "";
|
2013-01-17 00:26:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 01:08:42 +04:00
|
|
|
|
static void
|
2013-01-17 00:26:41 +04:00
|
|
|
|
draw_key(struct keyboard *keyboard,
|
|
|
|
|
const struct key *key,
|
2012-09-10 01:08:42 +04:00
|
|
|
|
cairo_t *cr,
|
|
|
|
|
unsigned int row,
|
|
|
|
|
unsigned int col)
|
|
|
|
|
{
|
|
|
|
|
const char *label;
|
|
|
|
|
cairo_text_extents_t extents;
|
|
|
|
|
|
|
|
|
|
cairo_save(cr);
|
|
|
|
|
cairo_rectangle(cr,
|
|
|
|
|
col * key_width, row * key_height,
|
|
|
|
|
key->width * key_width, key_height);
|
|
|
|
|
cairo_clip(cr);
|
|
|
|
|
|
|
|
|
|
/* Paint frame */
|
|
|
|
|
cairo_rectangle(cr,
|
|
|
|
|
col * key_width, row * key_height,
|
|
|
|
|
key->width * key_width, key_height);
|
|
|
|
|
cairo_set_line_width(cr, 3);
|
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
|
|
|
|
|
/* Paint text */
|
2013-01-17 00:26:41 +04:00
|
|
|
|
label = label_from_key(keyboard, key);
|
2012-09-10 01:08:42 +04:00
|
|
|
|
cairo_text_extents(cr, label, &extents);
|
|
|
|
|
|
|
|
|
|
cairo_translate(cr,
|
|
|
|
|
col * key_width,
|
|
|
|
|
row * key_height);
|
|
|
|
|
cairo_translate(cr,
|
|
|
|
|
(key->width * key_width - extents.width) / 2,
|
|
|
|
|
(key_height - extents.y_bearing) / 2);
|
|
|
|
|
cairo_show_text(cr, label);
|
|
|
|
|
|
|
|
|
|
cairo_restore(cr);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-17 00:26:44 +04:00
|
|
|
|
static const struct layout *
|
|
|
|
|
get_current_layout(struct virtual_keyboard *keyboard)
|
|
|
|
|
{
|
|
|
|
|
switch (keyboard->content_purpose) {
|
2015-11-17 11:00:29 +03:00
|
|
|
|
case ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_DIGITS:
|
|
|
|
|
case ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_NUMBER:
|
2013-01-17 00:26:44 +04:00
|
|
|
|
return &numeric_layout;
|
|
|
|
|
default:
|
2013-04-18 18:47:16 +04:00
|
|
|
|
if (keyboard->preferred_language &&
|
|
|
|
|
strcmp(keyboard->preferred_language, "ar") == 0)
|
|
|
|
|
return &arabic_layout;
|
|
|
|
|
else
|
|
|
|
|
return &normal_layout;
|
2013-01-17 00:26:44 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-21 23:52:19 +04:00
|
|
|
|
static void
|
|
|
|
|
redraw_handler(struct widget *widget, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct keyboard *keyboard = data;
|
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
struct rectangle allocation;
|
|
|
|
|
cairo_t *cr;
|
2012-09-10 01:08:42 +04:00
|
|
|
|
unsigned int i;
|
|
|
|
|
unsigned int row = 0, col = 0;
|
2013-01-17 00:26:44 +04:00
|
|
|
|
const struct layout *layout;
|
|
|
|
|
|
|
|
|
|
layout = get_current_layout(keyboard->keyboard);
|
2012-06-21 23:52:19 +04:00
|
|
|
|
|
|
|
|
|
surface = window_get_surface(keyboard->window);
|
|
|
|
|
widget_get_allocation(keyboard->widget, &allocation);
|
|
|
|
|
|
|
|
|
|
cr = cairo_create(surface);
|
|
|
|
|
cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height);
|
|
|
|
|
cairo_clip(cr);
|
|
|
|
|
|
2021-11-17 20:25:17 +03:00
|
|
|
|
cairo_select_font_face(cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
|
2012-09-10 01:08:42 +04:00
|
|
|
|
cairo_set_font_size(cr, 16);
|
2012-06-21 23:52:19 +04:00
|
|
|
|
|
2012-09-10 01:08:42 +04:00
|
|
|
|
cairo_translate(cr, allocation.x, allocation.y);
|
2012-06-21 23:52:19 +04:00
|
|
|
|
|
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
2012-09-10 01:08:42 +04:00
|
|
|
|
cairo_set_source_rgba(cr, 1, 1, 1, 0.75);
|
2013-01-17 00:26:44 +04:00
|
|
|
|
cairo_rectangle(cr, 0, 0, layout->columns * key_width, layout->rows * key_height);
|
2012-06-21 23:52:19 +04:00
|
|
|
|
cairo_paint(cr);
|
|
|
|
|
|
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
|
|
|
|
|
2013-01-17 00:26:44 +04:00
|
|
|
|
for (i = 0; i < layout->count; ++i) {
|
2012-06-21 23:52:19 +04:00
|
|
|
|
cairo_set_source_rgb(cr, 0, 0, 0);
|
2013-01-17 00:26:44 +04:00
|
|
|
|
draw_key(keyboard, &layout->keys[i], cr, row, col);
|
|
|
|
|
col += layout->keys[i].width;
|
|
|
|
|
if (col >= layout->columns) {
|
2012-09-10 01:08:42 +04:00
|
|
|
|
row += 1;
|
|
|
|
|
col = 0;
|
|
|
|
|
}
|
2012-06-21 23:52:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cairo_destroy(cr);
|
|
|
|
|
cairo_surface_destroy(surface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
resize_handler(struct widget *widget,
|
|
|
|
|
int32_t width, int32_t height, void *data)
|
|
|
|
|
{
|
|
|
|
|
/* struct keyboard *keyboard = data; */
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 18:47:41 +04:00
|
|
|
|
static char *
|
|
|
|
|
insert_text(const char *text, uint32_t offset, const char *insert)
|
|
|
|
|
{
|
2014-01-10 11:39:20 +04:00
|
|
|
|
int tlen = strlen(text), ilen = strlen(insert);
|
|
|
|
|
char *new_text = xmalloc(tlen + ilen + 1);
|
2013-04-18 18:47:41 +04:00
|
|
|
|
|
2014-01-10 11:39:20 +04:00
|
|
|
|
memcpy(new_text, text, offset);
|
|
|
|
|
memcpy(new_text + offset, insert, ilen);
|
|
|
|
|
memcpy(new_text + offset + ilen, text + offset, tlen - offset);
|
|
|
|
|
new_text[tlen + ilen] = '\0';
|
2013-04-18 18:47:41 +04:00
|
|
|
|
|
|
|
|
|
return new_text;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-05 06:26:42 +04:00
|
|
|
|
static void
|
|
|
|
|
virtual_keyboard_commit_preedit(struct virtual_keyboard *keyboard)
|
|
|
|
|
{
|
2013-04-18 18:47:41 +04:00
|
|
|
|
char *surrounding_text;
|
|
|
|
|
|
2012-11-05 06:26:42 +04:00
|
|
|
|
if (!keyboard->preedit_string ||
|
|
|
|
|
strlen(keyboard->preedit_string) == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_cursor_position(keyboard->context,
|
|
|
|
|
0, 0);
|
|
|
|
|
zwp_input_method_context_v1_commit_string(keyboard->context,
|
|
|
|
|
keyboard->serial,
|
|
|
|
|
keyboard->preedit_string);
|
2013-04-18 18:47:41 +04:00
|
|
|
|
|
|
|
|
|
if (keyboard->surrounding_text) {
|
|
|
|
|
surrounding_text = insert_text(keyboard->surrounding_text,
|
|
|
|
|
keyboard->surrounding_cursor,
|
|
|
|
|
keyboard->preedit_string);
|
|
|
|
|
free(keyboard->surrounding_text);
|
|
|
|
|
keyboard->surrounding_text = surrounding_text;
|
|
|
|
|
keyboard->surrounding_cursor += strlen(keyboard->preedit_string);
|
|
|
|
|
} else {
|
|
|
|
|
keyboard->surrounding_text = strdup(keyboard->preedit_string);
|
|
|
|
|
keyboard->surrounding_cursor = strlen(keyboard->preedit_string);
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-05 06:26:42 +04:00
|
|
|
|
free(keyboard->preedit_string);
|
|
|
|
|
keyboard->preedit_string = strdup("");
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-17 00:26:41 +04:00
|
|
|
|
static void
|
2013-01-17 00:26:48 +04:00
|
|
|
|
virtual_keyboard_send_preedit(struct virtual_keyboard *keyboard,
|
|
|
|
|
int32_t cursor)
|
2013-01-17 00:26:41 +04:00
|
|
|
|
{
|
2013-01-17 00:26:48 +04:00
|
|
|
|
uint32_t index = strlen(keyboard->preedit_string);
|
|
|
|
|
|
2013-01-17 00:26:41 +04:00
|
|
|
|
if (keyboard->preedit_style)
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_preedit_styling(keyboard->context,
|
|
|
|
|
0,
|
|
|
|
|
strlen(keyboard->preedit_string),
|
|
|
|
|
keyboard->preedit_style);
|
2013-01-17 00:26:48 +04:00
|
|
|
|
if (cursor > 0)
|
|
|
|
|
index = cursor;
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_preedit_cursor(keyboard->context,
|
|
|
|
|
index);
|
|
|
|
|
zwp_input_method_context_v1_preedit_string(keyboard->context,
|
|
|
|
|
keyboard->serial,
|
|
|
|
|
keyboard->preedit_string,
|
|
|
|
|
keyboard->preedit_string);
|
2013-01-17 00:26:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 18:47:41 +04:00
|
|
|
|
static const char *
|
|
|
|
|
prev_utf8_char(const char *s, const char *p)
|
|
|
|
|
{
|
|
|
|
|
for (--p; p >= s; --p) {
|
|
|
|
|
if ((*p & 0xc0) != 0x80)
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
delete_before_cursor(struct virtual_keyboard *keyboard)
|
|
|
|
|
{
|
|
|
|
|
const char *start, *end;
|
|
|
|
|
|
|
|
|
|
if (!keyboard->surrounding_text) {
|
2014-01-10 11:55:30 +04:00
|
|
|
|
dbg("delete_before_cursor: No surrounding text available\n");
|
2013-04-18 18:47:41 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
start = prev_utf8_char(keyboard->surrounding_text,
|
|
|
|
|
keyboard->surrounding_text + keyboard->surrounding_cursor);
|
|
|
|
|
if (!start) {
|
2014-01-10 11:55:30 +04:00
|
|
|
|
dbg("delete_before_cursor: No previous character to delete\n");
|
2013-04-18 18:47:41 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-15 22:37:09 +04:00
|
|
|
|
end = keyboard->surrounding_text + keyboard->surrounding_cursor;
|
2013-04-18 18:47:41 +04:00
|
|
|
|
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_delete_surrounding_text(keyboard->context,
|
2023-04-24 13:46:25 +03:00
|
|
|
|
start - keyboard->surrounding_text,
|
2015-11-17 11:00:30 +03:00
|
|
|
|
end - start);
|
|
|
|
|
zwp_input_method_context_v1_commit_string(keyboard->context,
|
|
|
|
|
keyboard->serial,
|
|
|
|
|
"");
|
2013-04-18 18:47:41 +04:00
|
|
|
|
|
|
|
|
|
/* Update surrounding text */
|
|
|
|
|
keyboard->surrounding_cursor = start - keyboard->surrounding_text;
|
|
|
|
|
keyboard->surrounding_text[keyboard->surrounding_cursor] = '\0';
|
|
|
|
|
if (*end)
|
|
|
|
|
memmove(keyboard->surrounding_text + keyboard->surrounding_cursor, end, strlen(end));
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-10 11:45:18 +04:00
|
|
|
|
static char *
|
|
|
|
|
append(char *s1, const char *s2)
|
|
|
|
|
{
|
|
|
|
|
int len1, len2;
|
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
|
|
len1 = strlen(s1);
|
|
|
|
|
len2 = strlen(s2);
|
|
|
|
|
s = xrealloc(s1, len1 + len2 + 1);
|
|
|
|
|
memcpy(s + len1, s2, len2);
|
|
|
|
|
s[len1 + len2] = '\0';
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 01:08:42 +04:00
|
|
|
|
static void
|
2012-11-18 22:06:44 +04:00
|
|
|
|
keyboard_handle_key(struct keyboard *keyboard, uint32_t time, const struct key *key, struct input *input, enum wl_pointer_button_state state)
|
2012-09-10 01:08:42 +04:00
|
|
|
|
{
|
2014-05-07 05:11:07 +04:00
|
|
|
|
const char *label = NULL;
|
2014-04-15 14:38:31 +04:00
|
|
|
|
|
|
|
|
|
switch(keyboard->state) {
|
|
|
|
|
case KEYBOARD_STATE_DEFAULT :
|
|
|
|
|
label = key->label;
|
|
|
|
|
break;
|
|
|
|
|
case KEYBOARD_STATE_UPPERCASE :
|
|
|
|
|
label = key->uppercase;
|
|
|
|
|
break;
|
|
|
|
|
case KEYBOARD_STATE_SYMBOLS :
|
|
|
|
|
label = key->symbol;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xkb_mod_mask_t mod_mask = keyboard->state == KEYBOARD_STATE_DEFAULT ? 0 : keyboard->keyboard->keysym.shift_mask;
|
2012-11-18 22:06:44 +04:00
|
|
|
|
uint32_t key_state = (state == WL_POINTER_BUTTON_STATE_PRESSED) ? WL_KEYBOARD_KEY_STATE_PRESSED : WL_KEYBOARD_KEY_STATE_RELEASED;
|
2012-09-10 01:08:42 +04:00
|
|
|
|
|
|
|
|
|
switch (key->key_type) {
|
|
|
|
|
case keytype_default:
|
2012-11-18 22:06:44 +04:00
|
|
|
|
if (state != WL_POINTER_BUTTON_STATE_PRESSED)
|
|
|
|
|
break;
|
|
|
|
|
|
2014-01-10 11:45:18 +04:00
|
|
|
|
keyboard->keyboard->preedit_string =
|
|
|
|
|
append(keyboard->keyboard->preedit_string,
|
|
|
|
|
label);
|
2013-01-17 00:26:48 +04:00
|
|
|
|
virtual_keyboard_send_preedit(keyboard->keyboard, -1);
|
2012-09-10 01:08:42 +04:00
|
|
|
|
break;
|
|
|
|
|
case keytype_backspace:
|
2012-11-18 22:06:44 +04:00
|
|
|
|
if (state != WL_POINTER_BUTTON_STATE_PRESSED)
|
|
|
|
|
break;
|
|
|
|
|
|
2012-09-10 01:08:44 +04:00
|
|
|
|
if (strlen(keyboard->keyboard->preedit_string) == 0) {
|
2013-04-18 18:47:41 +04:00
|
|
|
|
delete_before_cursor(keyboard->keyboard);
|
2012-09-17 17:28:08 +04:00
|
|
|
|
} else {
|
|
|
|
|
keyboard->keyboard->preedit_string[strlen(keyboard->keyboard->preedit_string) - 1] = '\0';
|
2013-01-17 00:26:48 +04:00
|
|
|
|
virtual_keyboard_send_preedit(keyboard->keyboard, -1);
|
2012-09-10 01:08:44 +04:00
|
|
|
|
}
|
2012-09-10 01:08:42 +04:00
|
|
|
|
break;
|
|
|
|
|
case keytype_enter:
|
2012-11-05 06:26:42 +04:00
|
|
|
|
virtual_keyboard_commit_preedit(keyboard->keyboard);
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_keysym(keyboard->keyboard->context,
|
|
|
|
|
display_get_serial(keyboard->keyboard->display),
|
|
|
|
|
time,
|
|
|
|
|
XKB_KEY_Return, key_state, mod_mask);
|
2012-09-10 01:08:42 +04:00
|
|
|
|
break;
|
|
|
|
|
case keytype_space:
|
2012-11-18 22:06:44 +04:00
|
|
|
|
if (state != WL_POINTER_BUTTON_STATE_PRESSED)
|
|
|
|
|
break;
|
2014-01-10 11:45:18 +04:00
|
|
|
|
keyboard->keyboard->preedit_string =
|
|
|
|
|
append(keyboard->keyboard->preedit_string, " ");
|
2012-11-05 06:26:42 +04:00
|
|
|
|
virtual_keyboard_commit_preedit(keyboard->keyboard);
|
2012-09-10 01:08:42 +04:00
|
|
|
|
break;
|
|
|
|
|
case keytype_switch:
|
2012-11-18 22:06:44 +04:00
|
|
|
|
if (state != WL_POINTER_BUTTON_STATE_PRESSED)
|
|
|
|
|
break;
|
2014-04-15 14:38:31 +04:00
|
|
|
|
switch(keyboard->state) {
|
|
|
|
|
case KEYBOARD_STATE_DEFAULT:
|
|
|
|
|
keyboard->state = KEYBOARD_STATE_UPPERCASE;
|
|
|
|
|
break;
|
|
|
|
|
case KEYBOARD_STATE_UPPERCASE:
|
|
|
|
|
keyboard->state = KEYBOARD_STATE_DEFAULT;
|
|
|
|
|
break;
|
|
|
|
|
case KEYBOARD_STATE_SYMBOLS:
|
|
|
|
|
keyboard->state = KEYBOARD_STATE_UPPERCASE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-09-10 01:08:42 +04:00
|
|
|
|
break;
|
|
|
|
|
case keytype_symbols:
|
2012-11-18 22:06:44 +04:00
|
|
|
|
if (state != WL_POINTER_BUTTON_STATE_PRESSED)
|
|
|
|
|
break;
|
2014-04-15 14:38:31 +04:00
|
|
|
|
switch(keyboard->state) {
|
|
|
|
|
case KEYBOARD_STATE_DEFAULT:
|
|
|
|
|
keyboard->state = KEYBOARD_STATE_SYMBOLS;
|
|
|
|
|
break;
|
|
|
|
|
case KEYBOARD_STATE_UPPERCASE:
|
|
|
|
|
keyboard->state = KEYBOARD_STATE_SYMBOLS;
|
|
|
|
|
break;
|
|
|
|
|
case KEYBOARD_STATE_SYMBOLS:
|
|
|
|
|
keyboard->state = KEYBOARD_STATE_DEFAULT;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-09-10 01:08:42 +04:00
|
|
|
|
break;
|
|
|
|
|
case keytype_tab:
|
2012-11-05 06:26:42 +04:00
|
|
|
|
virtual_keyboard_commit_preedit(keyboard->keyboard);
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_keysym(keyboard->keyboard->context,
|
|
|
|
|
display_get_serial(keyboard->keyboard->display),
|
|
|
|
|
time,
|
|
|
|
|
XKB_KEY_Tab, key_state, mod_mask);
|
2012-09-10 01:08:42 +04:00
|
|
|
|
break;
|
2012-09-17 17:28:07 +04:00
|
|
|
|
case keytype_arrow_up:
|
2012-11-05 06:26:42 +04:00
|
|
|
|
virtual_keyboard_commit_preedit(keyboard->keyboard);
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_keysym(keyboard->keyboard->context,
|
|
|
|
|
display_get_serial(keyboard->keyboard->display),
|
|
|
|
|
time,
|
|
|
|
|
XKB_KEY_Up, key_state, mod_mask);
|
2012-09-17 17:28:07 +04:00
|
|
|
|
break;
|
|
|
|
|
case keytype_arrow_left:
|
2012-11-05 06:26:42 +04:00
|
|
|
|
virtual_keyboard_commit_preedit(keyboard->keyboard);
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_keysym(keyboard->keyboard->context,
|
|
|
|
|
display_get_serial(keyboard->keyboard->display),
|
|
|
|
|
time,
|
|
|
|
|
XKB_KEY_Left, key_state, mod_mask);
|
2012-09-17 17:28:07 +04:00
|
|
|
|
break;
|
|
|
|
|
case keytype_arrow_right:
|
2012-11-05 06:26:42 +04:00
|
|
|
|
virtual_keyboard_commit_preedit(keyboard->keyboard);
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_keysym(keyboard->keyboard->context,
|
|
|
|
|
display_get_serial(keyboard->keyboard->display),
|
|
|
|
|
time,
|
|
|
|
|
XKB_KEY_Right, key_state, mod_mask);
|
2012-09-17 17:28:07 +04:00
|
|
|
|
break;
|
|
|
|
|
case keytype_arrow_down:
|
2012-11-05 06:26:42 +04:00
|
|
|
|
virtual_keyboard_commit_preedit(keyboard->keyboard);
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_keysym(keyboard->keyboard->context,
|
|
|
|
|
display_get_serial(keyboard->keyboard->display),
|
|
|
|
|
time,
|
|
|
|
|
XKB_KEY_Down, key_state, mod_mask);
|
2012-09-17 17:28:07 +04:00
|
|
|
|
break;
|
2013-01-17 00:26:41 +04:00
|
|
|
|
case keytype_style:
|
|
|
|
|
if (state != WL_POINTER_BUTTON_STATE_PRESSED)
|
|
|
|
|
break;
|
|
|
|
|
keyboard->keyboard->preedit_style = (keyboard->keyboard->preedit_style + 1) % 8; /* TODO */
|
2013-01-17 00:26:48 +04:00
|
|
|
|
virtual_keyboard_send_preedit(keyboard->keyboard, -1);
|
2013-01-17 00:26:41 +04:00
|
|
|
|
break;
|
2012-09-10 01:08:42 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-21 23:52:19 +04:00
|
|
|
|
static void
|
|
|
|
|
button_handler(struct widget *widget,
|
|
|
|
|
struct input *input, uint32_t time,
|
|
|
|
|
uint32_t button,
|
|
|
|
|
enum wl_pointer_button_state state, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct keyboard *keyboard = data;
|
|
|
|
|
struct rectangle allocation;
|
2012-09-10 01:08:42 +04:00
|
|
|
|
int32_t x, y;
|
|
|
|
|
int row, col;
|
|
|
|
|
unsigned int i;
|
2013-01-17 00:26:44 +04:00
|
|
|
|
const struct layout *layout;
|
|
|
|
|
|
|
|
|
|
layout = get_current_layout(keyboard->keyboard);
|
2012-06-21 23:52:19 +04:00
|
|
|
|
|
2012-11-18 22:06:44 +04:00
|
|
|
|
if (button != BTN_LEFT) {
|
2012-06-21 23:52:19 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
input_get_position(input, &x, &y);
|
|
|
|
|
|
|
|
|
|
widget_get_allocation(keyboard->widget, &allocation);
|
|
|
|
|
x -= allocation.x;
|
|
|
|
|
y -= allocation.y;
|
|
|
|
|
|
2012-09-10 01:08:42 +04:00
|
|
|
|
row = y / key_height;
|
2013-01-17 00:26:44 +04:00
|
|
|
|
col = x / key_width + row * layout->columns;
|
|
|
|
|
for (i = 0; i < layout->count; ++i) {
|
|
|
|
|
col -= layout->keys[i].width;
|
2012-10-09 21:44:34 +04:00
|
|
|
|
if (col < 0) {
|
2013-01-17 00:26:44 +04:00
|
|
|
|
keyboard_handle_key(keyboard, time, &layout->keys[i], input, state);
|
2012-09-10 01:08:42 +04:00
|
|
|
|
break;
|
2012-10-09 21:44:34 +04:00
|
|
|
|
}
|
2012-09-10 01:08:42 +04:00
|
|
|
|
}
|
2012-06-21 23:52:19 +04:00
|
|
|
|
|
|
|
|
|
widget_schedule_redraw(widget);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-27 21:49:42 +04:00
|
|
|
|
static void
|
2014-01-08 00:57:59 +04:00
|
|
|
|
touch_handler(struct input *input, uint32_t time,
|
|
|
|
|
float x, float y, uint32_t state, void *data)
|
2013-08-27 21:49:42 +04:00
|
|
|
|
{
|
|
|
|
|
struct keyboard *keyboard = data;
|
|
|
|
|
struct rectangle allocation;
|
|
|
|
|
int row, col;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
const struct layout *layout;
|
|
|
|
|
|
|
|
|
|
layout = get_current_layout(keyboard->keyboard);
|
|
|
|
|
|
|
|
|
|
widget_get_allocation(keyboard->widget, &allocation);
|
|
|
|
|
|
|
|
|
|
x -= allocation.x;
|
|
|
|
|
y -= allocation.y;
|
|
|
|
|
|
|
|
|
|
row = (int)y / key_height;
|
|
|
|
|
col = (int)x / key_width + row * layout->columns;
|
|
|
|
|
for (i = 0; i < layout->count; ++i) {
|
|
|
|
|
col -= layout->keys[i].width;
|
|
|
|
|
if (col < 0) {
|
2014-01-08 00:57:59 +04:00
|
|
|
|
keyboard_handle_key(keyboard, time,
|
|
|
|
|
&layout->keys[i], input, state);
|
2013-08-27 21:49:42 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-08 00:57:59 +04:00
|
|
|
|
widget_schedule_redraw(keyboard->widget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
touch_down_handler(struct widget *widget, struct input *input,
|
|
|
|
|
uint32_t serial, uint32_t time, int32_t id,
|
|
|
|
|
float x, float y, void *data)
|
|
|
|
|
{
|
2015-05-15 18:17:47 +03:00
|
|
|
|
touch_handler(input, time, x, y,
|
2014-01-08 00:57:59 +04:00
|
|
|
|
WL_POINTER_BUTTON_STATE_PRESSED, data);
|
2013-08-27 21:49:42 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
touch_up_handler(struct widget *widget, struct input *input,
|
2014-01-08 00:57:59 +04:00
|
|
|
|
uint32_t serial, uint32_t time, int32_t id,
|
|
|
|
|
void *data)
|
2013-08-27 21:49:42 +04:00
|
|
|
|
{
|
2014-01-08 00:57:59 +04:00
|
|
|
|
float x, y;
|
|
|
|
|
|
|
|
|
|
input_get_touch(input, id, &x, &y);
|
2013-08-27 21:49:42 +04:00
|
|
|
|
|
2014-01-08 00:57:59 +04:00
|
|
|
|
touch_handler(input, time, x, y,
|
|
|
|
|
WL_POINTER_BUTTON_STATE_RELEASED, data);
|
2013-08-27 21:49:42 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 01:08:40 +04:00
|
|
|
|
static void
|
2013-04-18 18:47:15 +04:00
|
|
|
|
handle_surrounding_text(void *data,
|
2015-11-17 11:00:30 +03:00
|
|
|
|
struct zwp_input_method_context_v1 *context,
|
2013-04-18 18:47:15 +04:00
|
|
|
|
const char *text,
|
|
|
|
|
uint32_t cursor,
|
|
|
|
|
uint32_t anchor)
|
2012-09-10 01:08:40 +04:00
|
|
|
|
{
|
2013-01-17 00:26:44 +04:00
|
|
|
|
struct virtual_keyboard *keyboard = data;
|
|
|
|
|
|
2013-01-31 18:52:20 +04:00
|
|
|
|
free(keyboard->surrounding_text);
|
|
|
|
|
keyboard->surrounding_text = strdup(text);
|
2013-04-18 18:47:41 +04:00
|
|
|
|
|
|
|
|
|
keyboard->surrounding_cursor = cursor;
|
2012-09-10 01:08:40 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 01:08:46 +04:00
|
|
|
|
static void
|
2013-04-18 18:47:15 +04:00
|
|
|
|
handle_reset(void *data,
|
2015-11-17 11:00:30 +03:00
|
|
|
|
struct zwp_input_method_context_v1 *context)
|
2012-09-10 01:08:46 +04:00
|
|
|
|
{
|
|
|
|
|
struct virtual_keyboard *keyboard = data;
|
|
|
|
|
|
2014-01-10 11:55:30 +04:00
|
|
|
|
dbg("Reset pre-edit buffer\n");
|
2012-09-10 01:08:46 +04:00
|
|
|
|
|
|
|
|
|
if (strlen(keyboard->preedit_string)) {
|
|
|
|
|
free(keyboard->preedit_string);
|
|
|
|
|
keyboard->preedit_string = strdup("");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-17 00:26:44 +04:00
|
|
|
|
static void
|
2013-04-18 18:47:15 +04:00
|
|
|
|
handle_content_type(void *data,
|
2015-11-17 11:00:30 +03:00
|
|
|
|
struct zwp_input_method_context_v1 *context,
|
2013-04-18 18:47:15 +04:00
|
|
|
|
uint32_t hint,
|
|
|
|
|
uint32_t purpose)
|
2013-01-17 00:26:44 +04:00
|
|
|
|
{
|
|
|
|
|
struct virtual_keyboard *keyboard = data;
|
|
|
|
|
|
|
|
|
|
keyboard->content_hint = hint;
|
|
|
|
|
keyboard->content_purpose = purpose;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-17 00:26:48 +04:00
|
|
|
|
static void
|
2013-04-18 18:47:15 +04:00
|
|
|
|
handle_invoke_action(void *data,
|
2015-11-17 11:00:30 +03:00
|
|
|
|
struct zwp_input_method_context_v1 *context,
|
2013-04-18 18:47:15 +04:00
|
|
|
|
uint32_t button,
|
|
|
|
|
uint32_t index)
|
2013-01-17 00:26:48 +04:00
|
|
|
|
{
|
|
|
|
|
struct virtual_keyboard *keyboard = data;
|
|
|
|
|
|
|
|
|
|
if (button != BTN_LEFT)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
virtual_keyboard_send_preedit(keyboard, index);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-31 18:52:20 +04:00
|
|
|
|
static void
|
2013-04-18 18:47:33 +04:00
|
|
|
|
handle_commit_state(void *data,
|
2015-11-17 11:00:30 +03:00
|
|
|
|
struct zwp_input_method_context_v1 *context,
|
2013-04-18 18:47:33 +04:00
|
|
|
|
uint32_t serial)
|
2013-01-31 18:52:20 +04:00
|
|
|
|
{
|
|
|
|
|
struct virtual_keyboard *keyboard = data;
|
|
|
|
|
const struct layout *layout;
|
|
|
|
|
|
2013-04-18 18:47:33 +04:00
|
|
|
|
keyboard->serial = serial;
|
|
|
|
|
|
2013-01-31 18:52:20 +04:00
|
|
|
|
layout = get_current_layout(keyboard);
|
|
|
|
|
|
|
|
|
|
if (keyboard->surrounding_text)
|
2014-01-10 11:55:30 +04:00
|
|
|
|
dbg("Surrounding text updated: %s\n", keyboard->surrounding_text);
|
2013-01-31 18:52:20 +04:00
|
|
|
|
|
2013-04-18 18:47:17 +04:00
|
|
|
|
window_schedule_resize(keyboard->keyboard->window,
|
2013-01-31 18:52:20 +04:00
|
|
|
|
layout->columns * key_width,
|
|
|
|
|
layout->rows * key_height);
|
|
|
|
|
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_language(context,
|
|
|
|
|
keyboard->serial,
|
|
|
|
|
layout->language);
|
|
|
|
|
zwp_input_method_context_v1_text_direction(context,
|
|
|
|
|
keyboard->serial,
|
|
|
|
|
layout->text_direction);
|
2013-04-18 18:47:16 +04:00
|
|
|
|
|
2013-04-18 18:47:17 +04:00
|
|
|
|
widget_schedule_redraw(keyboard->keyboard->widget);
|
2013-01-31 18:52:20 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 18:47:15 +04:00
|
|
|
|
static void
|
|
|
|
|
handle_preferred_language(void *data,
|
2015-11-17 11:00:30 +03:00
|
|
|
|
struct zwp_input_method_context_v1 *context,
|
2013-04-18 18:47:15 +04:00
|
|
|
|
const char *language)
|
|
|
|
|
{
|
2013-04-18 18:47:16 +04:00
|
|
|
|
struct virtual_keyboard *keyboard = data;
|
|
|
|
|
|
|
|
|
|
if (keyboard->preferred_language)
|
|
|
|
|
free(keyboard->preferred_language);
|
|
|
|
|
|
|
|
|
|
keyboard->preferred_language = NULL;
|
|
|
|
|
|
|
|
|
|
if (language)
|
|
|
|
|
keyboard->preferred_language = strdup(language);
|
2013-04-18 18:47:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-17 11:00:30 +03:00
|
|
|
|
static const struct zwp_input_method_context_v1_listener input_method_context_listener = {
|
2013-04-18 18:47:15 +04:00
|
|
|
|
handle_surrounding_text,
|
|
|
|
|
handle_reset,
|
|
|
|
|
handle_content_type,
|
|
|
|
|
handle_invoke_action,
|
2013-04-18 18:47:33 +04:00
|
|
|
|
handle_commit_state,
|
2013-04-18 18:47:15 +04:00
|
|
|
|
handle_preferred_language
|
2012-09-10 01:08:40 +04:00
|
|
|
|
};
|
|
|
|
|
|
2012-09-10 01:08:32 +04:00
|
|
|
|
static void
|
|
|
|
|
input_method_activate(void *data,
|
2015-11-17 11:00:30 +03:00
|
|
|
|
struct zwp_input_method_v1 *input_method,
|
|
|
|
|
struct zwp_input_method_context_v1 *context)
|
2012-09-10 01:08:32 +04:00
|
|
|
|
{
|
|
|
|
|
struct virtual_keyboard *keyboard = data;
|
2012-11-18 22:06:44 +04:00
|
|
|
|
struct wl_array modifiers_map;
|
2013-04-18 18:47:17 +04:00
|
|
|
|
const struct layout *layout;
|
|
|
|
|
|
2014-04-15 14:38:31 +04:00
|
|
|
|
keyboard->keyboard->state = KEYBOARD_STATE_DEFAULT;
|
2012-09-10 01:08:32 +04:00
|
|
|
|
|
|
|
|
|
if (keyboard->context)
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_destroy(keyboard->context);
|
2012-09-10 01:08:32 +04:00
|
|
|
|
|
2012-09-10 01:08:43 +04:00
|
|
|
|
if (keyboard->preedit_string)
|
|
|
|
|
free(keyboard->preedit_string);
|
|
|
|
|
|
|
|
|
|
keyboard->preedit_string = strdup("");
|
2013-04-18 18:47:17 +04:00
|
|
|
|
keyboard->content_hint = 0;
|
|
|
|
|
keyboard->content_purpose = 0;
|
|
|
|
|
free(keyboard->preferred_language);
|
|
|
|
|
keyboard->preferred_language = NULL;
|
|
|
|
|
free(keyboard->surrounding_text);
|
|
|
|
|
keyboard->surrounding_text = NULL;
|
|
|
|
|
|
2013-04-18 18:47:33 +04:00
|
|
|
|
keyboard->serial = 0;
|
2012-09-10 01:08:43 +04:00
|
|
|
|
|
2012-09-10 01:08:32 +04:00
|
|
|
|
keyboard->context = context;
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_add_listener(context,
|
|
|
|
|
&input_method_context_listener,
|
|
|
|
|
keyboard);
|
2012-11-18 22:06:44 +04:00
|
|
|
|
|
|
|
|
|
wl_array_init(&modifiers_map);
|
|
|
|
|
keysym_modifiers_add(&modifiers_map, "Shift");
|
|
|
|
|
keysym_modifiers_add(&modifiers_map, "Control");
|
|
|
|
|
keysym_modifiers_add(&modifiers_map, "Mod1");
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_modifiers_map(context, &modifiers_map);
|
2012-11-18 22:06:44 +04:00
|
|
|
|
keyboard->keysym.shift_mask = keysym_modifiers_get_mask(&modifiers_map, "Shift");
|
|
|
|
|
wl_array_release(&modifiers_map);
|
2013-04-18 18:47:17 +04:00
|
|
|
|
|
|
|
|
|
layout = get_current_layout(keyboard);
|
|
|
|
|
|
|
|
|
|
window_schedule_resize(keyboard->keyboard->window,
|
|
|
|
|
layout->columns * key_width,
|
|
|
|
|
layout->rows * key_height);
|
|
|
|
|
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_language(context,
|
|
|
|
|
keyboard->serial,
|
|
|
|
|
layout->language);
|
|
|
|
|
zwp_input_method_context_v1_text_direction(context,
|
|
|
|
|
keyboard->serial,
|
|
|
|
|
layout->text_direction);
|
2013-04-18 18:47:17 +04:00
|
|
|
|
|
|
|
|
|
widget_schedule_redraw(keyboard->keyboard->widget);
|
2012-09-10 01:08:32 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
input_method_deactivate(void *data,
|
2015-11-17 11:00:30 +03:00
|
|
|
|
struct zwp_input_method_v1 *input_method,
|
|
|
|
|
struct zwp_input_method_context_v1 *context)
|
2012-09-10 01:08:32 +04:00
|
|
|
|
{
|
|
|
|
|
struct virtual_keyboard *keyboard = data;
|
|
|
|
|
|
|
|
|
|
if (!keyboard->context)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-11-17 11:00:30 +03:00
|
|
|
|
zwp_input_method_context_v1_destroy(keyboard->context);
|
2012-09-10 01:08:32 +04:00
|
|
|
|
keyboard->context = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-17 11:00:30 +03:00
|
|
|
|
static const struct zwp_input_method_v1_listener input_method_listener = {
|
2012-09-10 01:08:32 +04:00
|
|
|
|
input_method_activate,
|
|
|
|
|
input_method_deactivate
|
|
|
|
|
};
|
|
|
|
|
|
2012-06-21 23:52:19 +04:00
|
|
|
|
static void
|
2012-10-11 05:34:26 +04:00
|
|
|
|
global_handler(struct display *display, uint32_t name,
|
2012-06-21 23:52:19 +04:00
|
|
|
|
const char *interface, uint32_t version, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct virtual_keyboard *keyboard = data;
|
|
|
|
|
|
2015-11-17 11:00:30 +03:00
|
|
|
|
if (!strcmp(interface, "zwp_input_panel_v1")) {
|
2012-10-11 05:34:26 +04:00
|
|
|
|
keyboard->input_panel =
|
2015-11-17 11:00:30 +03:00
|
|
|
|
display_bind(display, name, &zwp_input_panel_v1_interface, 1);
|
|
|
|
|
} else if (!strcmp(interface, "zwp_input_method_v1")) {
|
2012-10-11 05:34:26 +04:00
|
|
|
|
keyboard->input_method =
|
|
|
|
|
display_bind(display, name,
|
2015-11-17 11:00:30 +03:00
|
|
|
|
&zwp_input_method_v1_interface, 1);
|
|
|
|
|
zwp_input_method_v1_add_listener(keyboard->input_method,
|
|
|
|
|
&input_method_listener,
|
|
|
|
|
keyboard);
|
2012-06-21 23:52:19 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-06-23 12:59:34 +03:00
|
|
|
|
set_toplevel(struct output *output, struct virtual_keyboard *virtual_keyboard)
|
|
|
|
|
{
|
2023-11-21 16:26:59 +03:00
|
|
|
|
zwp_input_panel_surface_v1_set_toplevel(virtual_keyboard->ips,
|
2016-06-23 12:59:34 +03:00
|
|
|
|
output_get_wl_output(output),
|
|
|
|
|
ZWP_INPUT_PANEL_SURFACE_V1_POSITION_CENTER_BOTTOM);
|
|
|
|
|
virtual_keyboard->toplevel = true;
|
2021-09-15 07:54:29 +03:00
|
|
|
|
virtual_keyboard->overlay = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_overlay(struct output *output, struct virtual_keyboard *virtual_keyboard)
|
|
|
|
|
{
|
2023-11-21 16:26:59 +03:00
|
|
|
|
zwp_input_panel_surface_v1_set_overlay_panel(virtual_keyboard->ips);
|
2021-09-15 07:54:29 +03:00
|
|
|
|
virtual_keyboard->toplevel = false;
|
|
|
|
|
virtual_keyboard->overlay = true;
|
2016-06-23 12:59:34 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
display_output_handler(struct output *output, void *data) {
|
|
|
|
|
struct virtual_keyboard *keyboard = data;
|
2021-09-15 07:54:29 +03:00
|
|
|
|
const char *type = getenv("WESTON_KEYBOARD_SURFACE_TYPE");
|
2016-06-23 12:59:34 +03:00
|
|
|
|
|
2021-09-15 07:54:29 +03:00
|
|
|
|
if (type && strcasecmp("overlay", type) == 0) {
|
|
|
|
|
if (!keyboard->overlay)
|
|
|
|
|
set_overlay(output, keyboard);
|
|
|
|
|
} else {
|
|
|
|
|
if (!keyboard->toplevel)
|
|
|
|
|
set_toplevel(output, keyboard);
|
|
|
|
|
}
|
2016-06-23 12:59:34 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
keyboard_create(struct virtual_keyboard *virtual_keyboard)
|
2012-06-21 23:52:19 +04:00
|
|
|
|
{
|
|
|
|
|
struct keyboard *keyboard;
|
2013-01-17 00:26:44 +04:00
|
|
|
|
const struct layout *layout;
|
2013-04-18 18:47:39 +04:00
|
|
|
|
|
2013-01-17 00:26:44 +04:00
|
|
|
|
layout = get_current_layout(virtual_keyboard);
|
2012-06-21 23:52:19 +04:00
|
|
|
|
|
2013-08-08 05:57:05 +04:00
|
|
|
|
keyboard = xzalloc(sizeof *keyboard);
|
2012-06-21 23:52:19 +04:00
|
|
|
|
keyboard->keyboard = virtual_keyboard;
|
2012-06-27 18:22:15 +04:00
|
|
|
|
keyboard->window = window_create_custom(virtual_keyboard->display);
|
2012-06-21 23:52:19 +04:00
|
|
|
|
keyboard->widget = window_add_widget(keyboard->window, keyboard);
|
2013-04-18 18:47:17 +04:00
|
|
|
|
|
2023-11-21 16:26:59 +03:00
|
|
|
|
virtual_keyboard->ips =
|
|
|
|
|
zwp_input_panel_v1_get_input_panel_surface(virtual_keyboard->input_panel,
|
|
|
|
|
window_get_wl_surface(keyboard->window));
|
2013-04-18 18:47:17 +04:00
|
|
|
|
virtual_keyboard->keyboard = keyboard;
|
2012-06-21 23:52:19 +04:00
|
|
|
|
|
|
|
|
|
window_set_title(keyboard->window, "Virtual keyboard");
|
clients/window: Add functions to set/retrieve app_id
Adds appid for all clients using the toolkit, flower, fullscreen, image,
resizor, scaler, smoke, stacking, subsurfaces, terminal,
touch-calibrator, transformed, etc.
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-09-09 13:52:18 +03:00
|
|
|
|
window_set_appid(keyboard->window,
|
|
|
|
|
"org.freedesktop.weston.virtual-keyboard");
|
2012-06-21 23:52:19 +04:00
|
|
|
|
window_set_user_data(keyboard->window, keyboard);
|
|
|
|
|
|
|
|
|
|
widget_set_redraw_handler(keyboard->widget, redraw_handler);
|
|
|
|
|
widget_set_resize_handler(keyboard->widget, resize_handler);
|
|
|
|
|
widget_set_button_handler(keyboard->widget, button_handler);
|
2013-08-27 21:49:42 +04:00
|
|
|
|
widget_set_touch_down_handler(keyboard->widget, touch_down_handler);
|
|
|
|
|
widget_set_touch_up_handler(keyboard->widget, touch_up_handler);
|
|
|
|
|
|
2012-09-10 01:08:42 +04:00
|
|
|
|
window_schedule_resize(keyboard->window,
|
2013-01-17 00:26:44 +04:00
|
|
|
|
layout->columns * key_width,
|
|
|
|
|
layout->rows * key_height);
|
2012-06-21 23:52:19 +04:00
|
|
|
|
|
2016-06-23 12:59:34 +03:00
|
|
|
|
display_set_output_configure_handler(virtual_keyboard->display,
|
|
|
|
|
display_output_handler);
|
2012-06-21 23:52:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-21 17:26:31 +03:00
|
|
|
|
static void
|
|
|
|
|
keyboard_destroy(struct virtual_keyboard *virtual_keyboard)
|
|
|
|
|
{
|
2021-05-25 14:27:37 +03:00
|
|
|
|
if (virtual_keyboard->ips)
|
|
|
|
|
zwp_input_panel_surface_v1_destroy(virtual_keyboard->ips);
|
|
|
|
|
|
2021-05-21 17:26:31 +03:00
|
|
|
|
if (virtual_keyboard->input_panel)
|
|
|
|
|
zwp_input_panel_v1_destroy(virtual_keyboard->input_panel);
|
|
|
|
|
|
|
|
|
|
if (virtual_keyboard->input_method)
|
|
|
|
|
zwp_input_method_v1_destroy(virtual_keyboard->input_method);
|
|
|
|
|
|
|
|
|
|
widget_destroy(virtual_keyboard->keyboard->widget);
|
|
|
|
|
window_destroy(virtual_keyboard->keyboard->window);
|
|
|
|
|
free(virtual_keyboard->keyboard);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-21 23:52:19 +04:00
|
|
|
|
int
|
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
struct virtual_keyboard virtual_keyboard;
|
|
|
|
|
|
2013-01-17 00:26:41 +04:00
|
|
|
|
memset(&virtual_keyboard, 0, sizeof virtual_keyboard);
|
|
|
|
|
|
2013-02-21 00:27:49 +04:00
|
|
|
|
virtual_keyboard.display = display_create(&argc, argv);
|
2012-06-21 23:52:19 +04:00
|
|
|
|
if (virtual_keyboard.display == NULL) {
|
2019-04-27 00:57:31 +03:00
|
|
|
|
fprintf(stderr, "failed to create display: %s\n",
|
|
|
|
|
strerror(errno));
|
2012-06-21 23:52:19 +04:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
display_set_user_data(virtual_keyboard.display, &virtual_keyboard);
|
2012-10-11 05:34:26 +04:00
|
|
|
|
display_set_global_handler(virtual_keyboard.display, global_handler);
|
2013-04-18 18:47:29 +04:00
|
|
|
|
|
2014-09-16 21:13:16 +04:00
|
|
|
|
if (virtual_keyboard.input_panel == NULL) {
|
|
|
|
|
fprintf(stderr, "No input panel global\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-23 12:59:34 +03:00
|
|
|
|
keyboard_create(&virtual_keyboard);
|
2012-06-21 23:52:19 +04:00
|
|
|
|
|
|
|
|
|
display_run(virtual_keyboard.display);
|
|
|
|
|
|
2021-05-21 17:26:31 +03:00
|
|
|
|
keyboard_destroy(&virtual_keyboard);
|
|
|
|
|
display_destroy(virtual_keyboard.display);
|
|
|
|
|
|
2012-06-21 23:52:19 +04:00
|
|
|
|
return 0;
|
|
|
|
|
}
|