X11: Fix coding style

This commit is contained in:
Takuro Ashie 2022-04-25 16:34:02 +09:00 committed by Daijiro Fukuda
parent 3ad6cd187d
commit a5a3cbe5c0

View File

@ -536,6 +536,7 @@ static void enableCursor(_GLFWwindow* window)
} }
// Clear its handle when the input context has been destroyed // Clear its handle when the input context has been destroyed
//
static void inputContextDestroyCallback(XIC ic, XPointer clientData, XPointer callData) static void inputContextDestroyCallback(XIC ic, XPointer clientData, XPointer callData)
{ {
_GLFWwindow* window = (_GLFWwindow*) clientData; _GLFWwindow* window = (_GLFWwindow*) clientData;
@ -543,6 +544,7 @@ static void inputContextDestroyCallback(XIC ic, XPointer clientData, XPointer ca
} }
// Update cursor position to decide candidate window // Update cursor position to decide candidate window
//
static void _ximChangeCursorPosition(XIC xic, _GLFWwindow* window) static void _ximChangeCursorPosition(XIC xic, _GLFWwindow* window)
{ {
XVaNestedList preedit_attr; XVaNestedList preedit_attr;
@ -556,16 +558,19 @@ static void _ximChangeCursorPosition(XIC xic, _GLFWwindow* window)
} }
// IME Start callback (do nothing) // IME Start callback (do nothing)
//
static void _ximPreeditStartCallback(XIC xic, XPointer clientData, XPointer callData) static void _ximPreeditStartCallback(XIC xic, XPointer clientData, XPointer callData)
{ {
} }
// IME Done callback (do nothing) // IME Done callback (do nothing)
//
static void _ximPreeditDoneCallback(XIC xic, XPointer clientData, XPointer callData) static void _ximPreeditDoneCallback(XIC xic, XPointer clientData, XPointer callData)
{ {
} }
// IME Draw callback // IME Draw callback
//
static void _ximPreeditDrawCallback(XIC xic, XPointer clientData, XIMPreeditDrawCallbackStruct *callData) static void _ximPreeditDrawCallback(XIC xic, XPointer clientData, XIMPreeditDrawCallbackStruct *callData)
{ {
int i, j, length, ctext, rstart, rend; int i, j, length, ctext, rstart, rend;
@ -581,26 +586,33 @@ static void _ximPreeditDrawCallback(XIC xic, XPointer clientData, XIMPreeditDraw
int cursorY = window->preeditCursorPosY; int cursorY = window->preeditCursorPosY;
int cursorHeight = window->preeditCursorHeight; int cursorHeight = window->preeditCursorHeight;
if (!callData->text) { if (!callData->text)
{
// preedit text is empty // preedit text is empty
window->ntext = 0; window->ntext = 0;
window->nblocks = 0; window->nblocks = 0;
_glfwInputPreedit(window, 0); _glfwInputPreedit(window, 0);
return; return;
} else { }
else
{
text = callData->text; text = callData->text;
length = callData->chg_length; length = callData->chg_length;
if (text->encoding_is_wchar) { if (text->encoding_is_wchar)
{
// wchar is not supported // wchar is not supported
return; return;
} }
ctext = window->ctext; ctext = window->ctext;
while (ctext < length+1) { while (ctext < length + 1)
{
ctext = (ctext == 0) ? 1 : ctext * 2; ctext = (ctext == 0) ? 1 : ctext * 2;
} }
if (ctext != window->ctext) { if (ctext != window->ctext)
{
preeditText = _glfw_realloc(window->preeditText, sizeof(unsigned int) * ctext); preeditText = _glfw_realloc(window->preeditText, sizeof(unsigned int) * ctext);
if (preeditText == NULL) { if (preeditText == NULL)
{
return; return;
} }
window->preeditText = preeditText; window->preeditText = preeditText;
@ -608,52 +620,67 @@ static void _ximPreeditDrawCallback(XIC xic, XPointer clientData, XIMPreeditDraw
} }
window->ntext = length; window->ntext = length;
window->preeditText[length] = 0; window->preeditText[length] = 0;
if (window->cblocks == 0) { if (window->cblocks == 0)
{
window->preeditAttributeBlocks = _glfw_calloc(4, sizeof(int)); window->preeditAttributeBlocks = _glfw_calloc(4, sizeof(int));
window->cblocks = 4; window->cblocks = 4;
} }
src = text->string.multi_byte; src = text->string.multi_byte;
rend = 0; rend = 0;
rstart = length; rstart = length;
for (i = 0, j = 0; i < text->length; i++) { for (i = 0, j = 0; i < text->length; i++)
{
codePoint = decodeUTF8(&src); codePoint = decodeUTF8(&src);
if (i < callData->chg_first || callData->chg_first+length < i) { if (i < callData->chg_first || callData->chg_first + length < i)
{
continue; continue;
} }
window->preeditText[j++] = codePoint; window->preeditText[j++] = codePoint;
f = text->feedback[i]; f = text->feedback[i];
if ((f & XIMReverse) || (f & XIMHighlight)) { if ((f & XIMReverse) || (f & XIMHighlight))
{
rend = i; rend = i;
if (i < rstart) { if (i < rstart)
{
rstart = i; rstart = i;
} }
} }
} }
if (rstart == length) { if (rstart == length)
{
window->nblocks = 1; window->nblocks = 1;
window->preeditAttributeBlocks[0] = length; window->preeditAttributeBlocks[0] = length;
window->preeditAttributeBlocks[1] = 0; window->preeditAttributeBlocks[1] = 0;
_glfwInputPreedit(window, 0); _glfwInputPreedit(window, 0);
} else if (rstart == 0) { }
if (rend == length -1) { else if (rstart == 0)
{
if (rend == length -1)
{
window->nblocks = 1; window->nblocks = 1;
window->preeditAttributeBlocks[0] = length; window->preeditAttributeBlocks[0] = length;
window->preeditAttributeBlocks[1] = 0; window->preeditAttributeBlocks[1] = 0;
_glfwInputPreedit(window, 0); _glfwInputPreedit(window, 0);
} else { }
else
{
window->nblocks = 2; window->nblocks = 2;
window->preeditAttributeBlocks[0] = rend + 1; window->preeditAttributeBlocks[0] = rend + 1;
window->preeditAttributeBlocks[1] = length - rend - 1; window->preeditAttributeBlocks[1] = length - rend - 1;
window->preeditAttributeBlocks[2] = 0; window->preeditAttributeBlocks[2] = 0;
_glfwInputPreedit(window, 0); _glfwInputPreedit(window, 0);
} }
} else if (rend == length -1) { }
else if (rend == length - 1)
{
window->nblocks = 2; window->nblocks = 2;
window->preeditAttributeBlocks[0] = rstart; window->preeditAttributeBlocks[0] = rstart;
window->preeditAttributeBlocks[1] = length - rstart; window->preeditAttributeBlocks[1] = length - rstart;
window->preeditAttributeBlocks[2] = 0; window->preeditAttributeBlocks[2] = 0;
_glfwInputPreedit(window, 1); _glfwInputPreedit(window, 1);
} else { }
else
{
window->nblocks = 3; window->nblocks = 3;
window->preeditAttributeBlocks[0] = rstart; window->preeditAttributeBlocks[0] = rstart;
window->preeditAttributeBlocks[1] = rend - rstart + 1; window->preeditAttributeBlocks[1] = rend - rstart + 1;
@ -661,15 +688,17 @@ static void _ximPreeditDrawCallback(XIC xic, XPointer clientData, XIMPreeditDraw
window->preeditAttributeBlocks[3] = 0; window->preeditAttributeBlocks[3] = 0;
_glfwInputPreedit(window, 1); _glfwInputPreedit(window, 1);
} }
if ((cursorX != window->preeditCursorPosX) if ((cursorX != window->preeditCursorPosX) ||
|| (cursorY != window->preeditCursorPosY) (cursorY != window->preeditCursorPosY) ||
|| (cursorHeight != window->preeditCursorHeight)) { (cursorHeight != window->preeditCursorHeight))
{
_ximChangeCursorPosition(xic, window); _ximChangeCursorPosition(xic, window);
} }
} }
} }
// IME Caret callback (do nothing) // IME Caret callback (do nothing)
//
static void _ximPreeditCaretCallback(XIC xic, XPointer clientData, XPointer callData) static void _ximPreeditCaretCallback(XIC xic, XPointer clientData, XPointer callData)
{ {
} }
@ -693,6 +722,7 @@ static void _ximStatusDrawCallback(XIC xic, XPointer clientData, XIMStatusDrawCa
} }
// Create XIM Preedit callback // Create XIM Preedit callback
//
static XVaNestedList _createXIMPreeditCallbacks(_GLFWwindow* window) static XVaNestedList _createXIMPreeditCallbacks(_GLFWwindow* window)
{ {
window->x11.preeditStartCallback.client_data = (XPointer) window; window->x11.preeditStartCallback.client_data = (XPointer) window;
@ -704,14 +734,19 @@ static XVaNestedList _createXIMPreeditCallbacks(_GLFWwindow* window)
window->x11.preeditCaretCallback.client_data = (XPointer) window; window->x11.preeditCaretCallback.client_data = (XPointer) window;
window->x11.preeditCaretCallback.callback = (XIMProc) _ximPreeditCaretCallback; window->x11.preeditCaretCallback.callback = (XIMProc) _ximPreeditCaretCallback;
return XVaCreateNestedList(0, return XVaCreateNestedList(0,
XNPreeditStartCallback, &window->x11.preeditStartCallback.client_data, XNPreeditStartCallback,
XNPreeditDoneCallback, &window->x11.preeditDoneCallback.client_data, &window->x11.preeditStartCallback.client_data,
XNPreeditDrawCallback, &window->x11.preeditDrawCallback.client_data, XNPreeditDoneCallback,
XNPreeditCaretCallback, &window->x11.preeditCaretCallback.client_data, &window->x11.preeditDoneCallback.client_data,
XNPreeditDrawCallback,
&window->x11.preeditDrawCallback.client_data,
XNPreeditCaretCallback,
&window->x11.preeditCaretCallback.client_data,
NULL); NULL);
} }
// Create XIM status callback // Create XIM status callback
//
static XVaNestedList _createXIMStatusCallbacks(_GLFWwindow* window) static XVaNestedList _createXIMStatusCallbacks(_GLFWwindow* window)
{ {
window->x11.statusStartCallback.client_data = (XPointer) window; window->x11.statusStartCallback.client_data = (XPointer) window;
@ -721,9 +756,12 @@ static XVaNestedList _createXIMStatusCallbacks(_GLFWwindow* window)
window->x11.statusDrawCallback.client_data = (XPointer) window; window->x11.statusDrawCallback.client_data = (XPointer) window;
window->x11.statusDrawCallback.callback = (XIMProc) _ximStatusDrawCallback; window->x11.statusDrawCallback.callback = (XIMProc) _ximStatusDrawCallback;
return XVaCreateNestedList(0, return XVaCreateNestedList(0,
XNStatusStartCallback, &window->x11.statusStartCallback.client_data, XNStatusStartCallback,
XNStatusDoneCallback, &window->x11.statusDoneCallback.client_data, &window->x11.statusStartCallback.client_data,
XNStatusDrawCallback, &window->x11.statusDrawCallback.client_data, XNStatusDoneCallback,
&window->x11.statusDoneCallback.client_data,
XNStatusDrawCallback,
&window->x11.statusDrawCallback.client_data,
NULL); NULL);
} }
@ -3388,7 +3426,8 @@ VkResult _glfwCreateWindowSurfaceX11(VkInstance instance,
} }
} }
void _glfwPlatformResetPreeditText(_GLFWwindow* window) { void _glfwPlatformResetPreeditText(_GLFWwindow* window)
{
XIC ic = window->x11.ic; XIC ic = window->x11.ic;
/* restore conversion state after resetting ic later */ /* restore conversion state after resetting ic later */
@ -3416,16 +3455,17 @@ void _glfwPlatformResetPreeditText(_GLFWwindow* window) {
XFree (result); XFree (result);
} }
void _glfwPlatformSetIMEStatus(_GLFWwindow* window, int active) { void _glfwPlatformSetIMEStatus(_GLFWwindow* window, int active)
{
XIC ic = window->x11.ic; XIC ic = window->x11.ic;
if (active) { if (active)
XSetICFocus(ic); XSetICFocus(ic);
} else { else
XUnsetICFocus(ic); XUnsetICFocus(ic);
} }
}
int _glfwPlatformGetIMEStatus(_GLFWwindow* window) { int _glfwPlatformGetIMEStatus(_GLFWwindow* window)
{
return window->x11.imeFocus; return window->x11.imeFocus;
} }