|
|
452870 |
#ifndef KEYBOARD_H
|
|
|
452870 |
#define KEYBOARD_H
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
#include "graph.h"
|
|
|
452870 |
#include "input.h"
|
|
|
452870 |
|
|
|
452870 |
|
|
|
843e7a |
// key flags
|
|
|
843e7a |
enum {
|
|
|
843e7a |
KF_DOUBLE = 1 << 0, // show two lables, insensitive for capslock
|
|
|
843e7a |
KF_HOLD = 1 << 1, // key to switch layout
|
|
|
843e7a |
KF_SHIFT = 1 << 2, // key to switch layout
|
|
|
843e7a |
KF_CAPS = 1 << 3, // key to switch layout
|
|
|
843e7a |
KF_LAYOUT = 1 << 4, // key to switch layout
|
|
|
843e7a |
KF_MOVE = 1 << 5, // handle to move the window
|
|
|
843e7a |
KF_SIZE = 1 << 6, // key to resize the window
|
|
|
843e7a |
KF_CLOSE = 1 << 7 }; // key to close the window
|
|
|
843e7a |
|
|
|
843e7a |
// special layout indices
|
|
|
843e7a |
enum {
|
|
|
843e7a |
LI_PREV = -1, // switch to previous layout in the list
|
|
|
843e7a |
LI_NEXT = -2, // switch to next layout in the list
|
|
|
843e7a |
LI_REVERT = -3 }; // switch to previously used layout
|
|
|
843e7a |
|
|
|
843e7a |
|
|
|
843e7a |
|
|
|
843e7a |
struct Key;
|
|
|
843e7a |
struct Layout;
|
|
|
452870 |
struct Keyboard;
|
|
|
843e7a |
typedef struct Key Key;
|
|
|
843e7a |
typedef struct Layout Layout;
|
|
|
452870 |
typedef struct Keyboard Keyboard;
|
|
|
452870 |
|
|
|
452870 |
|
|
|
843e7a |
struct Key {
|
|
|
452870 |
// keep these filds at the begining for easyest static initialization
|
|
|
452870 |
int x, y, w, h;
|
|
|
452870 |
unsigned int keySym;
|
|
|
843e7a |
unsigned int keySym2;
|
|
|
452870 |
const char *label;
|
|
|
452870 |
const char *label2;
|
|
|
843e7a |
unsigned int flags;
|
|
|
843e7a |
int layoutIndex;
|
|
|
452870 |
|
|
|
452870 |
// these fields will be set while initialization
|
|
|
843e7a |
Layout *l;
|
|
|
452870 |
TextLayout tl;
|
|
|
452870 |
TextLayout tl2;
|
|
|
452870 |
|
|
|
452870 |
// dynamic fields
|
|
|
452870 |
int down;
|
|
|
843e7a |
int downKeycode;
|
|
|
843e7a |
int mx, my; // mouse down position, relative to key origin
|
|
|
843e7a |
Key *nextHeld, *prevHeld;
|
|
|
843e7a |
};
|
|
|
452870 |
|
|
|
452870 |
|
|
|
843e7a |
struct Layout {
|
|
|
452870 |
// keep these filds at the begining for easyest static initialization
|
|
|
452870 |
Key *keys;
|
|
|
452870 |
int keysCount;
|
|
|
452870 |
int w, h;
|
|
|
452870 |
|
|
|
452870 |
// these fields will be set while initialization
|
|
|
843e7a |
Keyboard *kbd;
|
|
|
843e7a |
|
|
|
843e7a |
// dynamic fields
|
|
|
843e7a |
Layout *prev; // previously used layout
|
|
|
843e7a |
Key *downKey; // key that received the last mouse down event
|
|
|
843e7a |
};
|
|
|
843e7a |
|
|
|
843e7a |
|
|
|
843e7a |
struct Keyboard {
|
|
|
843e7a |
// keep these filds at the begining for easyest static initialization
|
|
|
843e7a |
Layout *layouts;
|
|
|
843e7a |
int layoutsCount;
|
|
|
843e7a |
int w, h;
|
|
|
843e7a |
|
|
|
843e7a |
// these fields will be set while initialization
|
|
|
452870 |
App *app;
|
|
|
452870 |
|
|
|
452870 |
// dynamic fields
|
|
|
843e7a |
Layout *current;
|
|
|
843e7a |
Key *firstHeld;
|
|
|
843e7a |
int shiftsDown;
|
|
|
843e7a |
int capslock;
|
|
|
452870 |
};
|
|
|
452870 |
|
|
|
452870 |
|
|
|
843e7a |
int keyInit(Key *k, Layout *l);
|
|
|
452870 |
void keyDeinit(Key *k);
|
|
|
452870 |
void keyDraw(Key *k, int cx, int cy, int cw, int ch);
|
|
|
843e7a |
void keyDown(Key *k, int x, int y);
|
|
|
843e7a |
void keyMotion(Key *k, int x, int y);
|
|
|
843e7a |
void keyUp(Key *k, int force);
|
|
|
843e7a |
|
|
|
843e7a |
int layoutInit(Layout *l, Keyboard *kbd);
|
|
|
843e7a |
void layoutDeinit(Layout *l);
|
|
|
843e7a |
void layoutDraw(Layout *l, int cx, int cy, int cw, int ch);
|
|
|
843e7a |
void layoutMouseDown(Layout *l, int x, int y);
|
|
|
843e7a |
void layoutMouseMotion(Layout *l, int x, int y);
|
|
|
843e7a |
void layoutMouseUp(Layout *l);
|
|
|
452870 |
|
|
|
452870 |
int keyboardInit(Keyboard *kbd, App *app);
|
|
|
452870 |
void keyboardDeinit(Keyboard *kbd);
|
|
|
843e7a |
void keyboardResize(Keyboard *kbd);
|
|
|
452870 |
void keyboardDraw(Keyboard *kbd, int cx, int cy, int cw, int ch);
|
|
|
452870 |
void keyboardMouseDown(Keyboard *kbd, int x, int y);
|
|
|
843e7a |
void keyboardMouseMotion(Keyboard *kbd, int x, int y);
|
|
|
452870 |
void keyboardMouseUp(Keyboard *kbd);
|
|
|
843e7a |
void keyboardSwitchLayout(Keyboard *kbd, int index);
|
|
|
843e7a |
void keyboardRelaseHeld(Keyboard *kbd);
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
#endif
|