Set up the infrastructure for keyboard events.
This commit is contained in:
parent
72dacc82dd
commit
68387a8bfb
|
@ -123,6 +123,27 @@ static void handlerDragBroken(uiAreaHandler *ah, uiArea *a)
|
||||||
printf("drag broken\n");
|
printf("drag broken\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e)
|
||||||
|
{
|
||||||
|
char k[4];
|
||||||
|
|
||||||
|
k[0] = '\'';
|
||||||
|
k[1] = e->Key;
|
||||||
|
k[2] = '\'';
|
||||||
|
k[3] = '\0';
|
||||||
|
if (e->Key == 0) {
|
||||||
|
k[0] = '0';
|
||||||
|
k[1] = '\0';
|
||||||
|
}
|
||||||
|
printf("key key:%s extkey:%d mod:%d mods:%d up:%d\n",
|
||||||
|
k,
|
||||||
|
(int) e->ExtKey,
|
||||||
|
(int) e->Modifier,
|
||||||
|
(int) e->Modifiers;
|
||||||
|
e->Up);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void recalcScroll(GtkSpinButton *sb, gpointer data)
|
static void recalcScroll(GtkSpinButton *sb, gpointer data)
|
||||||
{
|
{
|
||||||
areaUpdateScroll(area);
|
areaUpdateScroll(area);
|
||||||
|
@ -151,6 +172,7 @@ int main(void)
|
||||||
h.ah.RedrawOnResize = handlerRedrawOnResize;
|
h.ah.RedrawOnResize = handlerRedrawOnResize;
|
||||||
h.ah.MouseEvent = handlerMouseEvent;
|
h.ah.MouseEvent = handlerMouseEvent;
|
||||||
h.ah.DragBroken = handlerDragBroken;
|
h.ah.DragBroken = handlerDragBroken;
|
||||||
|
h.ah.KeyEvent = handlerKeyEvent;
|
||||||
|
|
||||||
gtk_init(NULL, NULL);
|
gtk_init(NULL, NULL);
|
||||||
|
|
||||||
|
|
56
gtkarea/ui.h
56
gtkarea/ui.h
|
@ -4,6 +4,7 @@ typedef struct uiArea uiArea;
|
||||||
typedef struct uiAreaHandler uiAreaHandler;
|
typedef struct uiAreaHandler uiAreaHandler;
|
||||||
typedef struct uiAreaDrawParams uiAreaDrawParams;
|
typedef struct uiAreaDrawParams uiAreaDrawParams;
|
||||||
typedef struct uiAreaMouseEvent uiAreaMouseEvent;
|
typedef struct uiAreaMouseEvent uiAreaMouseEvent;
|
||||||
|
typedef struct uiAreaKeyEvent uiAreaKeyEvent;
|
||||||
|
|
||||||
typedef struct uiDrawContext uiDrawContext;
|
typedef struct uiDrawContext uiDrawContext;
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ struct uiAreaHandler {
|
||||||
int (*RedrawOnResize)(uiAreaHandler *, uiArea *);
|
int (*RedrawOnResize)(uiAreaHandler *, uiArea *);
|
||||||
void (*MouseEvent)(uiAreaHandler *, uiArea *, uiAreaMouseEvent *);
|
void (*MouseEvent)(uiAreaHandler *, uiArea *, uiAreaMouseEvent *);
|
||||||
void (*DragBroken)(uiAreaHandler *, uiArea *);
|
void (*DragBroken)(uiAreaHandler *, uiArea *);
|
||||||
|
int (*KeyEvent)(uiAreaHandler *, uiArea *, uiAreaKeyEvent *);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct uiAreaDrawParams {
|
struct uiAreaDrawParams {
|
||||||
|
@ -145,3 +147,57 @@ struct uiAreaMouseEvent {
|
||||||
|
|
||||||
uint64_t Held1To64;
|
uint64_t Held1To64;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef enum uiExtKey uiExtKey;
|
||||||
|
|
||||||
|
enum uiExtKey {
|
||||||
|
uiExtKeyEscape = 1,
|
||||||
|
uiExtKeyInsert, // equivalent to "Help" on Apple keyboards
|
||||||
|
uiExtKeyDelete,
|
||||||
|
uiExtKeyHome,
|
||||||
|
uiExtKeyEnd,
|
||||||
|
uiExtKeyPageUp,
|
||||||
|
uiExtKeyPageDown,
|
||||||
|
uiExtKeyUp,
|
||||||
|
uiExtKeyDown,
|
||||||
|
uiExtKeyLeft,
|
||||||
|
uiExtKeyRight,
|
||||||
|
uiExtKeyF1, // F1..F12 are guaranteed to be consecutive
|
||||||
|
uiExtKeyF2,
|
||||||
|
uiExtKeyF3,
|
||||||
|
uiExtKeyF4,
|
||||||
|
uiExtKeyF5,
|
||||||
|
uiExtKeyF6,
|
||||||
|
uiExtKeyF7,
|
||||||
|
uiExtKeyF8,
|
||||||
|
uiExtKeyF9,
|
||||||
|
uiExtKeyF10,
|
||||||
|
uiExtKeyF11,
|
||||||
|
uiExtKeyF12,
|
||||||
|
uiExtKeyN0, // numpad keys; independent of Num Lock state
|
||||||
|
uiExtKeyN1, // N0..N9 are guaranteed to be consecutive
|
||||||
|
uiExtKeyN2,
|
||||||
|
uiExtKeyN3,
|
||||||
|
uiExtKeyN4,
|
||||||
|
uiExtKeyN5,
|
||||||
|
uiExtKeyN6,
|
||||||
|
uiExtKeyN7,
|
||||||
|
uiExtKeyN8,
|
||||||
|
uiExtKeyN9,
|
||||||
|
uiExtKeyNDot,
|
||||||
|
uiExtKeyNEnter,
|
||||||
|
uiExtKeyNAdd,
|
||||||
|
uiExtKeyNSubtract,
|
||||||
|
uiExtKeyNMultiply,
|
||||||
|
uiExtKeyNDivide,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct uiAreaKeyEvent {
|
||||||
|
char Key;
|
||||||
|
uiExtKey ExtKey;
|
||||||
|
uiModifiers Modifier;
|
||||||
|
|
||||||
|
uiModifiers Modifiers;
|
||||||
|
|
||||||
|
int Up;
|
||||||
|
};
|
||||||
|
|
|
@ -129,6 +129,27 @@ static void handlerDragBroken(uiAreaHandler *ah, uiArea *a)
|
||||||
printf("drag broken\n");
|
printf("drag broken\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e)
|
||||||
|
{
|
||||||
|
char k[4];
|
||||||
|
|
||||||
|
k[0] = '\'';
|
||||||
|
k[1] = e->Key;
|
||||||
|
k[2] = '\'';
|
||||||
|
k[3] = '\0';
|
||||||
|
if (e->Key == 0) {
|
||||||
|
k[0] = '0';
|
||||||
|
k[1] = '\0';
|
||||||
|
}
|
||||||
|
printf("key key:%s extkey:%d mod:%d mods:%d up:%d\n",
|
||||||
|
k,
|
||||||
|
(int) e->ExtKey,
|
||||||
|
(int) e->Modifier,
|
||||||
|
(int) e->Modifiers;
|
||||||
|
e->Up);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// areaUpdateScroll(area);
|
// areaUpdateScroll(area);
|
||||||
|
|
||||||
@interface appDelegate : NSObject<NSApplicationDelegate, NSTextFieldDelegate>
|
@interface appDelegate : NSObject<NSApplicationDelegate, NSTextFieldDelegate>
|
||||||
|
@ -189,6 +210,7 @@ int main(void)
|
||||||
h.ah.RedrawOnResize = handlerRedrawOnResize;
|
h.ah.RedrawOnResize = handlerRedrawOnResize;
|
||||||
h.ah.MouseEvent = handlerMouseEvent;
|
h.ah.MouseEvent = handlerMouseEvent;
|
||||||
h.ah.DragBroken = handlerDragBroken;
|
h.ah.DragBroken = handlerDragBroken;
|
||||||
|
h.ah.KeyEvent = handlerKeyEvent;
|
||||||
|
|
||||||
app = [NSApplication sharedApplication];
|
app = [NSApplication sharedApplication];
|
||||||
[app setActivationPolicy:NSApplicationActivationPolicyRegular];
|
[app setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||||
|
|
|
@ -4,6 +4,7 @@ typedef struct uiArea uiArea;
|
||||||
typedef struct uiAreaHandler uiAreaHandler;
|
typedef struct uiAreaHandler uiAreaHandler;
|
||||||
typedef struct uiAreaDrawParams uiAreaDrawParams;
|
typedef struct uiAreaDrawParams uiAreaDrawParams;
|
||||||
typedef struct uiAreaMouseEvent uiAreaMouseEvent;
|
typedef struct uiAreaMouseEvent uiAreaMouseEvent;
|
||||||
|
typedef struct uiAreaKeyEvent uiAreaKeyEvent;
|
||||||
|
|
||||||
typedef struct uiDrawContext uiDrawContext;
|
typedef struct uiDrawContext uiDrawContext;
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ struct uiAreaHandler {
|
||||||
int (*RedrawOnResize)(uiAreaHandler *, uiArea *);
|
int (*RedrawOnResize)(uiAreaHandler *, uiArea *);
|
||||||
void (*MouseEvent)(uiAreaHandler *, uiArea *, uiAreaMouseEvent *);
|
void (*MouseEvent)(uiAreaHandler *, uiArea *, uiAreaMouseEvent *);
|
||||||
void (*DragBroken)(uiAreaHandler *, uiArea *);
|
void (*DragBroken)(uiAreaHandler *, uiArea *);
|
||||||
|
int (*KeyEvent)(uiAreaHandler *, uiArea *, uiAreaKeyEvent *);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct uiAreaDrawParams {
|
struct uiAreaDrawParams {
|
||||||
|
@ -145,3 +147,57 @@ struct uiAreaMouseEvent {
|
||||||
|
|
||||||
uint64_t Held1To64;
|
uint64_t Held1To64;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef enum uiExtKey uiExtKey;
|
||||||
|
|
||||||
|
enum uiExtKey {
|
||||||
|
uiExtKeyEscape = 1,
|
||||||
|
uiExtKeyInsert, // equivalent to "Help" on Apple keyboards
|
||||||
|
uiExtKeyDelete,
|
||||||
|
uiExtKeyHome,
|
||||||
|
uiExtKeyEnd,
|
||||||
|
uiExtKeyPageUp,
|
||||||
|
uiExtKeyPageDown,
|
||||||
|
uiExtKeyUp,
|
||||||
|
uiExtKeyDown,
|
||||||
|
uiExtKeyLeft,
|
||||||
|
uiExtKeyRight,
|
||||||
|
uiExtKeyF1, // F1..F12 are guaranteed to be consecutive
|
||||||
|
uiExtKeyF2,
|
||||||
|
uiExtKeyF3,
|
||||||
|
uiExtKeyF4,
|
||||||
|
uiExtKeyF5,
|
||||||
|
uiExtKeyF6,
|
||||||
|
uiExtKeyF7,
|
||||||
|
uiExtKeyF8,
|
||||||
|
uiExtKeyF9,
|
||||||
|
uiExtKeyF10,
|
||||||
|
uiExtKeyF11,
|
||||||
|
uiExtKeyF12,
|
||||||
|
uiExtKeyN0, // numpad keys; independent of Num Lock state
|
||||||
|
uiExtKeyN1, // N0..N9 are guaranteed to be consecutive
|
||||||
|
uiExtKeyN2,
|
||||||
|
uiExtKeyN3,
|
||||||
|
uiExtKeyN4,
|
||||||
|
uiExtKeyN5,
|
||||||
|
uiExtKeyN6,
|
||||||
|
uiExtKeyN7,
|
||||||
|
uiExtKeyN8,
|
||||||
|
uiExtKeyN9,
|
||||||
|
uiExtKeyNDot,
|
||||||
|
uiExtKeyNEnter,
|
||||||
|
uiExtKeyNAdd,
|
||||||
|
uiExtKeyNSubtract,
|
||||||
|
uiExtKeyNMultiply,
|
||||||
|
uiExtKeyNDivide,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct uiAreaKeyEvent {
|
||||||
|
char Key;
|
||||||
|
uiExtKey ExtKey;
|
||||||
|
uiModifiers Modifier;
|
||||||
|
|
||||||
|
uiModifiers Modifiers;
|
||||||
|
|
||||||
|
int Up;
|
||||||
|
};
|
||||||
|
|
|
@ -129,6 +129,27 @@ static void handlerDragBroken(uiAreaHandler *ah, uiArea *a)
|
||||||
printf("drag broken\n");
|
printf("drag broken\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e)
|
||||||
|
{
|
||||||
|
char k[4];
|
||||||
|
|
||||||
|
k[0] = '\'';
|
||||||
|
k[1] = e->Key;
|
||||||
|
k[2] = '\'';
|
||||||
|
k[3] = '\0';
|
||||||
|
if (e->Key == 0) {
|
||||||
|
k[0] = '0';
|
||||||
|
k[1] = '\0';
|
||||||
|
}
|
||||||
|
printf("key key:%s extkey:%d mod:%d mods:%d up:%d\n",
|
||||||
|
k,
|
||||||
|
(int) e->ExtKey,
|
||||||
|
(int) e->Modifier,
|
||||||
|
(int) e->Modifiers;
|
||||||
|
e->Up);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void repos(HWND hwnd)
|
static void repos(HWND hwnd)
|
||||||
{
|
{
|
||||||
RECT r;
|
RECT r;
|
||||||
|
@ -182,6 +203,7 @@ int main(void)
|
||||||
h.ah.RedrawOnResize = handlerRedrawOnResize;
|
h.ah.RedrawOnResize = handlerRedrawOnResize;
|
||||||
h.ah.MouseEvent = handlerMouseEvent;
|
h.ah.MouseEvent = handlerMouseEvent;
|
||||||
h.ah.DragBroken = handlerDragBroken;
|
h.ah.DragBroken = handlerDragBroken;
|
||||||
|
h.ah.KeyEvent = handlerKeyEvent;
|
||||||
|
|
||||||
registerAreaClass();
|
registerAreaClass();
|
||||||
|
|
||||||
|
|
56
winarea/ui.h
56
winarea/ui.h
|
@ -4,6 +4,7 @@ typedef struct uiArea uiArea;
|
||||||
typedef struct uiAreaHandler uiAreaHandler;
|
typedef struct uiAreaHandler uiAreaHandler;
|
||||||
typedef struct uiAreaDrawParams uiAreaDrawParams;
|
typedef struct uiAreaDrawParams uiAreaDrawParams;
|
||||||
typedef struct uiAreaMouseEvent uiAreaMouseEvent;
|
typedef struct uiAreaMouseEvent uiAreaMouseEvent;
|
||||||
|
typedef struct uiAreaKeyEvent uiAreaKeyEvent;
|
||||||
|
|
||||||
typedef struct uiDrawContext uiDrawContext;
|
typedef struct uiDrawContext uiDrawContext;
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ struct uiAreaHandler {
|
||||||
int (*RedrawOnResize)(uiAreaHandler *, uiArea *);
|
int (*RedrawOnResize)(uiAreaHandler *, uiArea *);
|
||||||
void (*MouseEvent)(uiAreaHandler *, uiArea *, uiAreaMouseEvent *);
|
void (*MouseEvent)(uiAreaHandler *, uiArea *, uiAreaMouseEvent *);
|
||||||
void (*DragBroken)(uiAreaHandler *, uiArea *);
|
void (*DragBroken)(uiAreaHandler *, uiArea *);
|
||||||
|
int (*KeyEvent)(uiAreaHandler *, uiArea *, uiAreaKeyEvent *);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct uiAreaDrawParams {
|
struct uiAreaDrawParams {
|
||||||
|
@ -145,3 +147,57 @@ struct uiAreaMouseEvent {
|
||||||
|
|
||||||
uint64_t Held1To64;
|
uint64_t Held1To64;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef enum uiExtKey uiExtKey;
|
||||||
|
|
||||||
|
enum uiExtKey {
|
||||||
|
uiExtKeyEscape = 1,
|
||||||
|
uiExtKeyInsert, // equivalent to "Help" on Apple keyboards
|
||||||
|
uiExtKeyDelete,
|
||||||
|
uiExtKeyHome,
|
||||||
|
uiExtKeyEnd,
|
||||||
|
uiExtKeyPageUp,
|
||||||
|
uiExtKeyPageDown,
|
||||||
|
uiExtKeyUp,
|
||||||
|
uiExtKeyDown,
|
||||||
|
uiExtKeyLeft,
|
||||||
|
uiExtKeyRight,
|
||||||
|
uiExtKeyF1, // F1..F12 are guaranteed to be consecutive
|
||||||
|
uiExtKeyF2,
|
||||||
|
uiExtKeyF3,
|
||||||
|
uiExtKeyF4,
|
||||||
|
uiExtKeyF5,
|
||||||
|
uiExtKeyF6,
|
||||||
|
uiExtKeyF7,
|
||||||
|
uiExtKeyF8,
|
||||||
|
uiExtKeyF9,
|
||||||
|
uiExtKeyF10,
|
||||||
|
uiExtKeyF11,
|
||||||
|
uiExtKeyF12,
|
||||||
|
uiExtKeyN0, // numpad keys; independent of Num Lock state
|
||||||
|
uiExtKeyN1, // N0..N9 are guaranteed to be consecutive
|
||||||
|
uiExtKeyN2,
|
||||||
|
uiExtKeyN3,
|
||||||
|
uiExtKeyN4,
|
||||||
|
uiExtKeyN5,
|
||||||
|
uiExtKeyN6,
|
||||||
|
uiExtKeyN7,
|
||||||
|
uiExtKeyN8,
|
||||||
|
uiExtKeyN9,
|
||||||
|
uiExtKeyNDot,
|
||||||
|
uiExtKeyNEnter,
|
||||||
|
uiExtKeyNAdd,
|
||||||
|
uiExtKeyNSubtract,
|
||||||
|
uiExtKeyNMultiply,
|
||||||
|
uiExtKeyNDivide,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct uiAreaKeyEvent {
|
||||||
|
char Key;
|
||||||
|
uiExtKey ExtKey;
|
||||||
|
uiModifiers Modifier;
|
||||||
|
|
||||||
|
uiModifiers Modifiers;
|
||||||
|
|
||||||
|
int Up;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue