indent onscreen_keyboard.c onscreen_keyboard.h

This commit is contained in:
Bill Kendrick 2017-10-15 10:59:50 -07:00
parent e283cdb473
commit e9447f8c3b
2 changed files with 1095 additions and 1094 deletions

View file

@ -13,6 +13,7 @@ static void load_keymap(osk_layout *layout, char * keymap_name);
static void load_composemap(osk_layout * layout, char *composemap_name);
static int is_blank_or_comment(char *line);
/* static int isw_blank_or_comment(wchar_t *line); */
@ -59,10 +60,15 @@ static void mtw(wchar_t * wtok, char * tok)
free(ui16);
iconv_close(trans);
}
#define mbstowcs(wtok, tok, size) mtw(wtok, tok)
#endif
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surface *button_up, SDL_Surface *button_down, SDL_Surface *button_off, SDL_Surface *button_nav, SDL_Surface *button_hold, SDL_Surface *oskdel, SDL_Surface *osktab, SDL_Surface *oskenter, SDL_Surface *oskcapslock, SDL_Surface *oskshift, int disable_change)
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas, SDL_Surface * button_up,
SDL_Surface * button_down, SDL_Surface * button_off, SDL_Surface * button_nav,
SDL_Surface * button_hold, SDL_Surface * oskdel, SDL_Surface * osktab,
SDL_Surface * oskenter, SDL_Surface * oskcapslock, SDL_Surface * oskshift,
int disable_change)
{
SDL_Surface *surface;
osk_layout *layout;
@ -94,9 +100,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surf
layout->width * button_up->w,
layout->height * button_up->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, 0);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, 0);
if (!surface)
{
printf("Error creating the onscreen keyboard surface\n");
@ -136,7 +140,9 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surf
keyboard->kmdf.dead3 = NULL;
keyboard->kmdf.dead4 = NULL;
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, keyboard->layout->bgcolor.r, keyboard->layout->bgcolor.g, keyboard->layout->bgcolor.b));
SDL_FillRect(surface, NULL,
SDL_MapRGB(surface->format, keyboard->layout->bgcolor.r, keyboard->layout->bgcolor.g,
keyboard->layout->bgcolor.b));
keybd_prepare(keyboard);
@ -412,15 +418,10 @@ void load_hlayout(osk_layout *layout, char * hlayout_name)
"%s %i %i.%i %s %s %s %s %i",
key,
&keycode,
&key_width,
&key_width_decimal,
plain_label,
top_label,
altgr_label,
shift_altgr_label,
&shiftcaps);
&key_width, &key_width_decimal, plain_label, top_label, altgr_label, shift_altgr_label, &shiftcaps);
layout->keys[line_number][key_number].keycode = keycode;
layout->keys[line_number][key_number].width = (float)0.1 *key_width_decimal + key_width;
layout->keys[line_number][key_number].plain_label = plain_label;
layout->keys[line_number][key_number].top_label = top_label;
layout->keys[line_number][key_number].altgr_label = altgr_label;
@ -520,8 +521,7 @@ void load_keymap(osk_layout *layout, char * keymap_name)
/* FIXME: Why is the us-intl keymap duplicating the two first entries of every keycode? */
/* And why is the arabic keymap using the 5th and 6th entries as plain/shifted keys? */
readed = sscanf(line, "keycode %i = %s %s %s %s", &keycode,
ksname1, ksname2, ksname3, ksname4);
readed = sscanf(line, "keycode %i = %s %s %s %s", &keycode, ksname1, ksname2, ksname3, ksname4);
if (readed == 5 && keycode > 8 && keycode < 256)
{
@ -803,9 +803,7 @@ static void load_keysymdefs(osk_layout *layout, char * keysymdefs_name)
layout->keysymdefs[i].unicode = 0;
layout->keysymdefs[i].mnemo = malloc(sizeof(char) * 128);
sscanf(line, "#define XK_%s %x /* U+%x",
layout->keysymdefs[i].mnemo,
&layout->keysymdefs[i].keysym,
&layout->keysymdefs[i].unicode);
layout->keysymdefs[i].mnemo, &layout->keysymdefs[i].keysym, &layout->keysymdefs[i].unicode);
i++;
}
@ -862,8 +860,7 @@ static int keysym2unicode(int keysym, on_screen_keyboard * keyboard)
* This software is in the public domain. Share and enjoy!
*/
/* first check for Latin-1 characters (1:1 mapping) */
if ((keysym >= 0x0020 && keysym <= 0x007e) ||
(keysym >= 0x00a0 && keysym <= 0x00ff))
if ((keysym >= 0x0020 && keysym <= 0x007e) || (keysym >= 0x00a0 && keysym <= 0x00ff))
return keysym;
/* also check for directly encoded 24-bit UCS characters */
@ -992,7 +989,8 @@ static void keybd_prepare(on_screen_keyboard *keyboard)
char *fontname;
fontname = malloc(sizeof(char) * 255);
if (keyboard->osk_fonty == NULL) {
if (keyboard->osk_fonty == NULL)
{
if (keyboard->layout->fontpath)
{
/* First try if it is an absolute path */
@ -1028,8 +1026,7 @@ static void keybd_prepare(on_screen_keyboard *keyboard)
if (keyboard->osk_fonty == NULL)
{
fprintf(stderr, "\nError: Can't open the font!\n"
"The Simple DirectMedia Layer error that occurred was:\n"
"%s\n\n", SDL_GetError());
"The Simple DirectMedia Layer error that occurred was:\n" "%s\n\n", SDL_GetError());
free(fontname);
exit(1);
}
@ -1091,9 +1088,7 @@ static SDL_Surface * stretch_surface(SDL_Surface * orig, int width)
width,
orig->h,
orig->format->BitsPerPixel,
orig->format->Rmask,
orig->format->Gmask,
orig->format->Bmask, 0);
orig->format->Rmask, orig->format->Gmask, orig->format->Bmask, 0);
SDL_BlitSurface(orig, NULL, dest, NULL);
rect.y = 0;
@ -1139,6 +1134,7 @@ static void draw_keyboard(on_screen_keyboard *keyboard)
int i, j;
int key_height, accumulated_width, accumulated_height;
float key_width;
key_width = keyboard->button_up->w;
key_height = keyboard->button_up->h;
@ -1156,7 +1152,8 @@ static void draw_keyboard(on_screen_keyboard *keyboard)
keyboard->layout->keys[j][i].x = accumulated_width;
keyboard->layout->keys[j][i].y = accumulated_height;
draw_key(keyboard->layout->keys[j][i], keyboard, 0); }
draw_key(keyboard->layout->keys[j][i], keyboard, 0);
}
accumulated_width += (keyboard->layout->keys[j][i].width * key_width);
}
accumulated_height += key_height;
@ -1324,8 +1321,7 @@ static osk_key * find_key(on_screen_keyboard * keyboard, int x, int y)
key = NULL;
for (j = 0; j < keyboard->layout->height; j++)
{
if (keyboard->layout->keys[j][0].y < y &&
keyboard->layout->keys[j][0].y + keyboard->button_up->h > y)
if (keyboard->layout->keys[j][0].y < y && keyboard->layout->keys[j][0].y + keyboard->button_up->h > y)
for (i = 0; i < keyboard->layout->width; i++)
if (keyboard->layout->keys[j][i].x < x &&
keyboard->layout->keys[j][i].x + keyboard->layout->keys[j][i].width * keyboard->button_up->w > x)
@ -1493,8 +1489,7 @@ static int handle_keymods(char * keysym, osk_key * key, on_screen_keyboard *keyb
/* Seems ISO_Level3_Shift and ISO_Next_Group are used too for right Alt */
else if (strncmp("ISO_Level3_Shift", keysym, 16) == 0 ||
strncmp("ISO_Next_Group", keysym, 14) == 0||
strncmp("ALT_R", keysym, 5) == 0)
strncmp("ISO_Next_Group", keysym, 14) == 0 || strncmp("ALT_R", keysym, 5) == 0)
{
if (mod & KMOD_RALT)
{
@ -1667,7 +1662,10 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
}
new_keyboard = osk_create(name, keyboard->surface, keyboard->button_up, keyboard->button_down, keyboard->button_off, keyboard->button_nav, keyboard->button_hold, keyboard->oskdel, keyboard->osktab, keyboard->oskenter, keyboard->oskcapslock, keyboard->oskshift, keyboard->disable_change);
new_keyboard =
osk_create(name, keyboard->surface, keyboard->button_up, keyboard->button_down, keyboard->button_off,
keyboard->button_nav, keyboard->button_hold, keyboard->oskdel, keyboard->osktab,
keyboard->oskenter, keyboard->oskcapslock, keyboard->oskshift, keyboard->disable_change);
free(aux_list_ptr);
@ -1702,9 +1700,7 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
wkeysym = malloc(sizeof(wchar_t) * (strlen(keysym) + 1));
mbsrtowcs(wkeysym, (const char **) &keysym,
strlen(keysym)+1,
NULL);
mbsrtowcs(wkeysym, (const char **)&keysym, strlen(keysym) + 1, NULL);
#ifdef DEBUG
printf("wkeysym %ls %i\n\n", wkeysym, (int)wcslen(wkeysym));
@ -1731,8 +1727,7 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
event.key.keysym.sym = SDLK_RETURN;
event.key.keysym.unicode = '\r';
}
else if (wcsncmp(L"Tab", ks, 3) == 0 ||
wcsncmp(L"ISO_Left_Tab", ks, 12) == 0)
else if (wcsncmp(L"Tab", ks, 3) == 0 || wcsncmp(L"ISO_Left_Tab", ks, 12) == 0)
{
event.key.keysym.sym = SDLK_TAB;
event.key.keysym.unicode = '\t';
@ -1745,8 +1740,7 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
else if (wcsncmp(L"NoSymbol", ks, 8) == 0)
return (keyboard);
else
if (keyboard->composed_type == 1)
else if (keyboard->composed_type == 1)
event.key.keysym.unicode = *keyboard->composed;
else
event.key.keysym.unicode = keysym2unicode(mnemo2keysym(mnemo, keyboard), keyboard);
@ -1786,6 +1780,7 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
void osk_released(on_screen_keyboard * keyboard)
{
osk_key *key;
key = keyboard->last_key_pressed;
if (key)
{
@ -1800,6 +1795,7 @@ void osk_released(on_screen_keyboard *keyboard)
static void free_keymap(osk_keymap * keymap)
{
int i;
for (i = 0; i < 256; i++)
{
if (keymap[i].plain)
@ -1817,6 +1813,7 @@ static void free_keymap(osk_keymap *keymap)
static void free_composemap(osk_composenode * composenode)
{
int i;
for (i = 0; i < composenode->size; i++)
{
free_composemap(composenode->childs[i]);
@ -2062,4 +2059,3 @@ void osk_free(on_screen_keyboard *keyboard)
/* } */
/* } */
/* } */

View file

@ -133,11 +133,16 @@ typedef struct osk_keyboard
osk_key *last_key_pressed; /* The last key pressed */
} on_screen_keyboard;
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surface *button_up, SDL_Surface *button_down, SDL_Surface *button_off, SDL_Surface *button_nav, SDL_Surface *button_hold, SDL_Surface *oskdel, SDL_Surface *osktab, SDL_Surface *oskenter, SDL_Surface *oskcapslock, SDL_Surface *oskshift, int disable_change);
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas, SDL_Surface * button_up,
SDL_Surface * button_down, SDL_Surface * button_off, SDL_Surface * button_nav,
SDL_Surface * button_hold, SDL_Surface * oskdel, SDL_Surface * osktab,
SDL_Surface * oskenter, SDL_Surface * oskcapslock, SDL_Surface * oskshift,
int disable_change);
struct osk_layout *osk_load_layout(char *layout_name);
void osk_get_layout_data(char *layout_name, int *layout_w, int *layout_h, char * layout_buttons, char *layout_labels, char *layout_keycodes);
void osk_get_layout_data(char *layout_name, int *layout_w, int *layout_h, char *layout_buttons, char *layout_labels,
char *layout_keycodes);
void osk_reset(on_screen_keyboard * osk);
struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y);
void osk_released(on_screen_keyboard * osk);