@@ -677,12 +677,15 @@ struct Window::PrivateData { | |||||
fSelf->onDisplayAfter(); | fSelf->onDisplayAfter(); | ||||
} | } | ||||
void onPuglKeyboard(const bool press, const uint key) | |||||
int onPuglKeyboard(const bool press, const uint key) | |||||
{ | { | ||||
DBGp("PUGL: onKeyboard : %i %i\n", press, key); | DBGp("PUGL: onKeyboard : %i %i\n", press, key); | ||||
if (fModal.childFocus != nullptr) | if (fModal.childFocus != nullptr) | ||||
return fModal.childFocus->focus(); | |||||
{ | |||||
fModal.childFocus->focus(); | |||||
return 0; | |||||
} | |||||
Widget::KeyboardEvent ev; | Widget::KeyboardEvent ev; | ||||
ev.press = press; | ev.press = press; | ||||
@@ -695,16 +698,21 @@ struct Window::PrivateData { | |||||
Widget* const widget(*rit); | Widget* const widget(*rit); | ||||
if (widget->isVisible() && widget->onKeyboard(ev)) | if (widget->isVisible() && widget->onKeyboard(ev)) | ||||
break; | |||||
return 0; | |||||
} | } | ||||
return 1; | |||||
} | } | ||||
void onPuglSpecial(const bool press, const Key key) | |||||
int onPuglSpecial(const bool press, const Key key) | |||||
{ | { | ||||
DBGp("PUGL: onSpecial : %i %i\n", press, key); | DBGp("PUGL: onSpecial : %i %i\n", press, key); | ||||
if (fModal.childFocus != nullptr) | if (fModal.childFocus != nullptr) | ||||
return fModal.childFocus->focus(); | |||||
{ | |||||
fModal.childFocus->focus(); | |||||
return 0; | |||||
} | |||||
Widget::SpecialEvent ev; | Widget::SpecialEvent ev; | ||||
ev.press = press; | ev.press = press; | ||||
@@ -717,8 +725,10 @@ struct Window::PrivateData { | |||||
Widget* const widget(*rit); | Widget* const widget(*rit); | ||||
if (widget->isVisible() && widget->onSpecial(ev)) | if (widget->isVisible() && widget->onSpecial(ev)) | ||||
break; | |||||
return 0; | |||||
} | } | ||||
return 1; | |||||
} | } | ||||
void onPuglMouse(const int button, const bool press, const int x, const int y) | void onPuglMouse(const int button, const bool press, const int x, const int y) | ||||
@@ -889,14 +899,14 @@ struct Window::PrivateData { | |||||
handlePtr->onPuglDisplay(); | handlePtr->onPuglDisplay(); | ||||
} | } | ||||
static void onKeyboardCallback(PuglView* view, bool press, uint32_t key) | |||||
static int onKeyboardCallback(PuglView* view, bool press, uint32_t key) | |||||
{ | { | ||||
handlePtr->onPuglKeyboard(press, key); | |||||
return handlePtr->onPuglKeyboard(press, key); | |||||
} | } | ||||
static void onSpecialCallback(PuglView* view, bool press, PuglKey key) | |||||
static int onSpecialCallback(PuglView* view, bool press, PuglKey key) | |||||
{ | { | ||||
handlePtr->onPuglSpecial(press, static_cast<Key>(key)); | |||||
return handlePtr->onPuglSpecial(press, static_cast<Key>(key)); | |||||
} | } | ||||
static void onMouseCallback(PuglView* view, int button, bool press, int x, int y) | static void onMouseCallback(PuglView* view, int button, bool press, int x, int y) | ||||
@@ -74,8 +74,9 @@ typedef void (*PuglDisplayFunc)(PuglView* view); | |||||
@param view The view the event occured in. | @param view The view the event occured in. | ||||
@param press True if the key was pressed, false if released. | @param press True if the key was pressed, false if released. | ||||
@param key Unicode point of the key pressed. | @param key Unicode point of the key pressed. | ||||
@return 0 if event was handled, otherwise send event to parent window. | |||||
*/ | */ | ||||
typedef void (*PuglKeyboardFunc)(PuglView* view, bool press, uint32_t key); | |||||
typedef int (*PuglKeyboardFunc)(PuglView* view, bool press, uint32_t key); | |||||
/** | /** | ||||
A function called when the pointer moves. | A function called when the pointer moves. | ||||
@@ -129,8 +130,9 @@ typedef void (*PuglScrollFunc)(PuglView* view, int x, int y, float dx, float dy) | |||||
@param view The view the event occured in. | @param view The view the event occured in. | ||||
@param press True if the key was pressed, false if released. | @param press True if the key was pressed, false if released. | ||||
@param key The key pressed. | @param key The key pressed. | ||||
@return 0 if event was handled, otherwise send event to parent window. | |||||
*/ | */ | ||||
typedef void (*PuglSpecialFunc)(PuglView* view, bool press, PuglKey key); | |||||
typedef int (*PuglSpecialFunc)(PuglView* view, bool press, PuglKey key); | |||||
/** | /** | ||||
A function called when a filename is selected via file-browser. | A function called when a filename is selected via file-browser. | ||||
@@ -430,6 +430,7 @@ dispatchKey(PuglView* view, XEvent* event, bool press) | |||||
{ | { | ||||
KeySym sym; | KeySym sym; | ||||
char str[5]; | char str[5]; | ||||
PuglKey special; | |||||
const int n = XLookupString(&event->xkey, str, 4, &sym, NULL); | const int n = XLookupString(&event->xkey, str, 4, &sym, NULL); | ||||
if (sym == XK_Escape && view->closeFunc && !press && !view->parent) { | if (sym == XK_Escape && view->closeFunc && !press && !view->parent) { | ||||
@@ -438,18 +439,30 @@ dispatchKey(PuglView* view, XEvent* event, bool press) | |||||
return; | return; | ||||
} | } | ||||
if (n == 0) { | if (n == 0) { | ||||
goto send_event; | |||||
return; | return; | ||||
} | } | ||||
if (n > 1) { | if (n > 1) { | ||||
fprintf(stderr, "warning: Unsupported multi-byte key %X\n", (int)sym); | fprintf(stderr, "warning: Unsupported multi-byte key %X\n", (int)sym); | ||||
goto send_event; | |||||
return; | return; | ||||
} | } | ||||
const PuglKey special = keySymToSpecial(sym); | |||||
special = keySymToSpecial(sym); | |||||
if (special && view->specialFunc) { | if (special && view->specialFunc) { | ||||
view->specialFunc(view, press, special); | |||||
if (view->specialFunc(view, press, special) == 0) { | |||||
return; | |||||
} | |||||
} else if (!special && view->keyboardFunc) { | } else if (!special && view->keyboardFunc) { | ||||
view->keyboardFunc(view, press, str[0]); | |||||
if (view->keyboardFunc(view, press, str[0]) == 0) { | |||||
return; | |||||
} | |||||
} | |||||
send_event: | |||||
if (view->parent) { | |||||
event->xany.window = view->parent; | |||||
XSendEvent(view->impl->display, view->parent, True, press ? KeyPressMask : KeyReleaseMask, event); | |||||
} | } | ||||
} | } | ||||