mirror of
https://github.com/glfw/glfw.git
synced 2025-06-14 19:52:14 +00:00
X11: Fix coding style
This commit is contained in:
parent
3ad6cd187d
commit
a5a3cbe5c0
154
src/x11_window.c
154
src/x11_window.c
@ -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,10 +544,11 @@ 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;
|
||||||
XPoint spot;
|
XPoint spot;
|
||||||
|
|
||||||
spot.x = window->preeditCursorPosX;
|
spot.x = window->preeditCursorPosX;
|
||||||
spot.y = window->preeditCursorPosY + window->preeditCursorHeight;
|
spot.y = window->preeditCursorPosY + window->preeditCursorHeight;
|
||||||
@ -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;
|
||||||
@ -574,33 +579,40 @@ static void _ximPreeditDrawCallback(XIC xic, XPointer clientData, XIMPreeditDraw
|
|||||||
unsigned int codePoint;
|
unsigned int codePoint;
|
||||||
unsigned int* preeditText;
|
unsigned int* preeditText;
|
||||||
XIMFeedback f;
|
XIMFeedback f;
|
||||||
_GLFWwindow* window = (_GLFWwindow*)clientData;
|
_GLFWwindow* window = (_GLFWwindow*) clientData;
|
||||||
|
|
||||||
// keep cursor position to reduce API call
|
// keep cursor position to reduce API call
|
||||||
int cursorX = window->preeditCursorPosX;
|
int cursorX = window->preeditCursorPosX;
|
||||||
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);
|
{
|
||||||
if (preeditText == NULL) {
|
preeditText = _glfw_realloc(window->preeditText, sizeof(unsigned int) * ctext);
|
||||||
|
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,70 +688,81 @@ 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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _ximStatusStartCallback(XIC xic, XPointer clientData, XPointer callData)
|
static void _ximStatusStartCallback(XIC xic, XPointer clientData, XPointer callData)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*)clientData;
|
_GLFWwindow* window = (_GLFWwindow*) clientData;
|
||||||
window->x11.imeFocus = GLFW_TRUE;
|
window->x11.imeFocus = GLFW_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _ximStatusDoneCallback(XIC xic, XPointer clientData, XPointer callData)
|
static void _ximStatusDoneCallback(XIC xic, XPointer clientData, XPointer callData)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*)clientData;
|
_GLFWwindow* window = (_GLFWwindow*) clientData;
|
||||||
window->x11.imeFocus = GLFW_FALSE;
|
window->x11.imeFocus = GLFW_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _ximStatusDrawCallback(XIC xic, XPointer clientData, XIMStatusDrawCallbackStruct* callData)
|
static void _ximStatusDrawCallback(XIC xic, XPointer clientData, XIMStatusDrawCallbackStruct* callData)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*)clientData;
|
_GLFWwindow* window = (_GLFWwindow*) clientData;
|
||||||
_glfwInputIMEStatus(window);
|
_glfwInputIMEStatus(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
window->x11.preeditStartCallback.callback = (XIMProc)_ximPreeditStartCallback;
|
window->x11.preeditStartCallback.callback = (XIMProc) _ximPreeditStartCallback;
|
||||||
window->x11.preeditDoneCallback.client_data = (XPointer)window;
|
window->x11.preeditDoneCallback.client_data = (XPointer) window;
|
||||||
window->x11.preeditDoneCallback.callback = (XIMProc)_ximPreeditDoneCallback;
|
window->x11.preeditDoneCallback.callback = (XIMProc) _ximPreeditDoneCallback;
|
||||||
window->x11.preeditDrawCallback.client_data = (XPointer)window;
|
window->x11.preeditDrawCallback.client_data = (XPointer) window;
|
||||||
window->x11.preeditDrawCallback.callback = (XIMProc)_ximPreeditDrawCallback;
|
window->x11.preeditDrawCallback.callback = (XIMProc) _ximPreeditDrawCallback;
|
||||||
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,
|
||||||
NULL);
|
XNPreeditDrawCallback,
|
||||||
|
&window->x11.preeditDrawCallback.client_data,
|
||||||
|
XNPreeditCaretCallback,
|
||||||
|
&window->x11.preeditCaretCallback.client_data,
|
||||||
|
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;
|
||||||
window->x11.statusStartCallback.callback = (XIMProc)_ximStatusStartCallback;
|
window->x11.statusStartCallback.callback = (XIMProc) _ximStatusStartCallback;
|
||||||
window->x11.statusDoneCallback.client_data = (XPointer)window;
|
window->x11.statusDoneCallback.client_data = (XPointer) window;
|
||||||
window->x11.statusDoneCallback.callback = (XIMProc)_ximStatusDoneCallback;
|
window->x11.statusDoneCallback.callback = (XIMProc) _ximStatusDoneCallback;
|
||||||
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,
|
||||||
NULL);
|
&window->x11.statusDoneCallback.client_data,
|
||||||
|
XNStatusDrawCallback,
|
||||||
|
&window->x11.statusDrawCallback.client_data,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the X11 window (and its colormap)
|
// Create the X11 window (and its colormap)
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user