디시인사이드 갤러리

갤러리 이슈박스, 최근방문 갤러리

갤러리 본문 영역

XIM 통신 구현에서 공용체 union 사용 예시

나르시갤로그로 이동합니다. 2025.09.27 19:18:36
조회 41 추천 0 댓글 0

/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/*
 * nimf-xim.h
 * This file is part of Nimf.
 * Copyright (C) 2015-2024 Hodong Kim, All rights reserved.
 * Unauthorized copying of this software, via any medium is strictly prohibited.
 * Proprietary and confidential.
 * Written by Hodong Kim <hodong@nimfsoft.art>
 */

#ifndef __NIMF_XIM_H__
#define __NIMF_XIM_H__

#include "nimf-utils.h"
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include "nimf-xim-conn.h"
#include "nimf-service.h"
#include "nimf-server.h"
#include "c-mem.h"

C_BEGIN_DECLS

#define C_XIM_DATA_B_LEN  20

typedef struct _CXimHeader
{
  uint8_t  major_opcode;
  uint8_t  minor_opcode;
  uint16_t len;
} CXimHeader;

typedef struct
{
  uint8_t  byte_order;
  uint8_t  unused;
  uint16_t major_version; /* client-major-protocol-version */
  uint16_t minor_version; /* client-minor-protocol-version */
  uint16_t n_auth_names;  /* number of client-auth-protocol-names */
} CXimConnect;

/*
XIM_GET_IC_VALUES (IM library -> IM Server)

     2     CARD16           input-method-ID
     2     CARD16           input-context-ID
     2     n                byte length of ic-attribute-id
     n     LISTofCARD16     ic-attribute-id
     p                      unused, p=Pad(2+n)
*/
typedef struct
{
  uint16_t imid;
  uint16_t icid;
  uint16_t n_attr_ids;
} CXimGetICValues;

/*
XIM_FORWARD_EVENT (IM library <--> IM Server)
     2     CARD16         input-method-ID
     2     CARD16         input-context-ID
     2     BITMASK16      flag
           #0001          synchronous
           #0002          request filtering (*1)
           #0004          request lookupstring (*2)
     2     CARD16         serial number
           XEVENT         X event

(*1)  Indicate the receiver should filter events and possible preedit may be invoked.

(*2)  Indicate the receiver should only do lookup string. The IM Server is expected
to just do a conversion of the key event to the best candidate. This bit may
affect the state of the preedit state (e.g. compose of dead key sequences).
*/
typedef struct
{
  uint16_t imid;
  uint16_t icid;
  uint16_t flag;
  uint16_t serial;
} CXimForwardEvent;

typedef struct
{
  uint16_t   imid;
  uint16_t   icid;
  int16_t    x;
  int16_t    y;
} CXimExtMove;

typedef struct
{
  uint16_t imid;
  uint16_t unused;
} CXimPacketClose;

typedef struct
{
  uint16_t imid;
  uint16_t icid;
} CXimIC, CXimSync, CXimPacketDestroyIc, CXimSetIcFocus, CXimUnsetIcFocus,
  CXimResetIc;

typedef union _CXimBody
{
  CXimConnect         conn;
  CXimPacketClose     close;
  CXimPacketDestroyIc destroy;
  CXimSetIcFocus      set_ic_focus;
  CXimUnsetIcFocus    unset_ic_focus;
  CXimResetIc         reset_ic;
  CXimIC              ic;
  CXimGetICValues     icvs;
  CXimSync            sync;
  CXimExtMove         move;
} CXimBody;

typedef struct
{
  CXimHeader header;
  CXimBody   body;
} CXimPacket;

/** BEGIN of replies and callbacks */
/* from the server to the client */
typedef struct
{
  CXimHeader header;
  uint16_t   major_version;
  uint16_t   minor_version;
} CXimPacketConnectReply;

typedef struct
{
  CXimHeader header;
/*
XIM_CLOSE_REPLY (IM Server -> IM library)
     2     CARD16     input-method-ID
     2                unused
*/
  uint16_t imid;
  uint16_t unused;
} CXimCloseReply;

typedef struct
{
  CXimHeader header;
/* XIM_SET_EVENT_MASK
     2     CARD16        input-method-ID
     2     CARD16        input-context-ID
     4     EVENTMASK     forward-event-mask (*1)
     4     EVENTMASK     synchronous-event-mask (*2)
*/
  uint16_t imid;
  uint16_t icid;
  uint32_t forward_event_mask;
  uint32_t sync_event_mask;
} CXimSetEvevtMask;

typedef struct
{
  CXimHeader header;
/*
XIM_ENCODING_NEGOTIATION_REPLY (IM Server -> IM library)
     2     CARD16     input-method-ID
     2     CARD16     category of the encoding determined.
           #0         name
           #1         detailed data
     2     INT16      index of the encoding determinated.
     2                unused
*/
  uint16_t imid;
  uint16_t category;
  int16_t  index;
  uint16_t unused;
} CXimEncodingNegotiationReply;

typedef struct
{
  CXimHeader header;
/*
XIM_SET_IM_VALUES_REPLY (IM Server -> IM library)
     2     CARD16     input-method-ID
     2                unused
*/
  uint16_t imid;
  uint16_t unused;
} CXimSetImValuesReply;

typedef struct
{
  CXimHeader header;
  uint16_t   imid;
  uint16_t   icid;
} CXimCreateIcReply, CXimDestroyIcReply, CXimSetIcValuesReply, CXimSyncReq,
  CXimSyncReply, CXimStatusStart, CXimStatusDone, CXimPreeditStart,
  CXimPreeditDone;

typedef struct
{
  CXimHeader header;
  uint16_t   imid;
  uint16_t   icid;
  int32_t    retval;
} CXimPreeditStartReply;

/***** End of replies and callbacks *****/

/* See: CXimAttr xim_attrs[] in nimf-xim.c
   Caution: CXimAttr xim_attrs order mappings */
typedef enum {
  XN_QUERY_INPUT_STYLE,
  XN_RESOURCE_NAME,
  XN_RESOURCE_CLASS,
  N_IM_ATTRS
} NimfXimImAttrType;

/* See: CXimAttr xic_attrs[] in nimf-xim.c
   Caution: CXimAttr xic_attrs order mappings */
typedef enum {
  XN_INPUT_STYLE,
  XN_CLIENT_WINDOW,
  XN_FOCUS_WINDOW,
  XN_FILTER_EVENTS,
  XN_PREEDIT_ATTRIBUTES,
  XN_STATUS_ATTRIBUTES,
  XN_FONT_SET,
  XN_AREA,
  XN_AREA_NEEDED,
  XN_COLORMAP,
  XN_STD_COLORMAP,
  XN_FOREGROUND,
  XN_BACKGROUND,
  XN_BACKGROUND_PIXMAP,
  XN_SPOT_LOCATION,
  XN_LINE_SPACE,
  XN_PREEDIT_STATE,
  XN_SEPARATOROF_NESTED_LIST,
  N_IC_ATTRS
} NimfXimIcAttrType;

typedef struct _NimfXimConn  NimfXimConn;

/*
XIMATTR
     2     CARD16         attribute ID (*1)
     2     CARD16         type of the value (*2)
     2     n              length of im-attribute
     n     STRING8        im-attribute
     p                    unused, p = Pad(2+n)

The im-attribute argument specifies XIM values such as XNQueryInputStyle.

XICATTR
     2     CARD16         attribute ID (*1)
     2     CARD16         type of the value (*2)
     2     n              length of ic-attribute
     n     STRING8        ic-attribute
     p                    unused, p = Pad(2+n)

(*1) XIMATTR and XICATTR are used during the setup stage and XIMATTRIBUTE and
     XICATTRIBUTE are used after each attribute ID has been recognized by
     the IM Server and the IM library.
*/
typedef struct
{
  uint16_t  id;
  uint16_t  type;
  uint16_t  name_len;
  char     *name;
} CXimAttr;

/*
 * https://www.x.org/releases/X11R7.7/doc/libX11/XIM/xim.html' target="_blank">https://www.x.org/releases/X11R7.7/doc/libX11/XIM/xim.html#Data_Types
 * value types of XIMATTR and XICATTR
 */
#define C_XIM_VALUE_TYPE_SEPARATOR                 0
#define C_XIM_VALUE_TYPE_CARD8                     1
#define C_XIM_VALUE_TYPE_CARD16                    2
#define C_XIM_VALUE_TYPE_CARD32                    3
#define C_XIM_VALUE_TYPE_STRING8                   4
#define C_XIM_VALUE_TYPE_WINDOW                    5

#define C_XIM_VALUE_TYPE_XIM_STYLES               10
#define C_XIM_VALUE_TYPE_X_RECTANGLE              11
#define C_XIM_VALUE_TYPE_X_POINT                  12
#define C_XIM_VALUE_TYPE_X_FONT_SET               13

#define C_XIM_VALUE_TYPE_XIM_HOT_KEY_TRIGGERS     15

#define C_XIM_VALUE_TYPE_XIM_STRING_CONVERSION    17
#define C_XIM_VALUE_TYPE_XIM_PREEDIT_STATE        18
#define C_XIM_VALUE_TYPE_XIM_RESET_STATE          19

#define C_XIM_VALUE_TYPE_NESTED_LIST          0x7fff

/*
  https://www.x.org/releases/X11R7.7/doc/libX11/XIM/xim.html' target="_blank">https://www.x.org/releases/X11R7.7/doc/libX11/XIM/xim.html#common_extensions
 */
#define XIM_EXTENSION           128
#define XIM_EXT_SET_EVENT_MASK 0x30
#define XIM_EXT_MOVE           0x33

typedef struct
{
  uint16_t  major_opcode;
  uint16_t  minor_opcode;
  uint16_t  len;
  char     *name;
} CXimExt;

typedef struct _NimfXim  NimfXim;
struct _NimfXim
{
  NimfService base;
  NimfServer* server;
  CSource*  xsource;
  CRef     *received;
  CHashMap *conns;
  /* client_windows: client window -- ims_window mapping
   * This is to prevent memory leaks.
   * xterm does not send XIM_DISCONNECT. This leads to memory leaks.
   * When the server receives a DestroyNotify, the server finds the ims_window
   * corresponding to the client window and removes it.
   */
  CHashMap *client_windows;

  Display*  display;
  CHashMap* xim_attr_map;
  CHashMap* xic_attr_map;
  CXimAttr* xim_attrs;
  CXimAttr* xic_attrs;
  CHashMap* ext_map;
  CHashMap* imids; /* hashmap for creating a unique id from a connection. */
  Window    im_window;
  XIMStyles im_styles;
  uint32_t  im_event_mask;
  Atom      atom_xconnect;
  Atom      atom_protocol;
  Atom      atom_locales;
  Atom      atom_transport;
  Atom      atom_xim_servers;
  Atom      atom_server;
  int     error_code;
  bool    active;
  bool    is_dispatched;
  bool    full_sync;
  uint8_t byte_order;
#ifdef DEBUG
  int     depth;
#endif
};

bool nimf_xim_wait (NimfXim *xim, uint16_t icid, uint16_t major_opcode);

C_END_DECLS

#endif /* __NIMF_XIM_H__ */

추천 비추천

0

고정닉 0

0

댓글 영역

전체 댓글 0
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 우리나라를 대표해서 UN 연설자로 내보내고 싶은 스타는? 운영자 25/09/29 - -
AD 프로게이머가 될테야!! 운영자 25/10/01 - -
2892931 카카오톡 11에서 갑자기 25로 버전 바꿧네 헬마스터갤로그로 이동합니다. 09.29 50 0
2892930 ❤✨☀⭐⚡☘⛩나님 시작합니당⛩☘⚡⭐☀✨❤ ♥냥덩이♥갤로그로 이동합니다. 09.29 25 0
2892929 중국 형님들 걍 존나 잘침 루도그담당(118.235) 09.29 46 0
2892928 supabase<<이거 RLS 설정 존나 귀찮네 진짜 ㅆㅇㅆ(124.216) 09.29 48 0
2892927 ai 이거 로컬에서 쓴다는게 말이 안되는데 현시대에서?? 타이밍뒷.통수한방(1.213) 09.29 77 0
2892925 아직도 짱개가 기술적으로 한국보다 밑이라는 착각은 마시기 바랍니다. 프갤러(218.154) 09.29 55 0
2892924 여동생년 족치러 간다...하... ㅇㅇ(211.234) 09.29 63 0
2892923 해외여행 가시는 분? [1] 발명도둑잡기(39.7) 09.29 45 0
2892921 애새끼좀 더 번식해라 이기이기 ㅋㅋㅋㅋ 타이밍뒷.통수한방(1.213) 09.29 31 0
2892920 냥덩이 마누라 될 사람 발명도둑잡기(39.7) 09.29 49 1
2892919 성 착취자는 보상금을 챙겼고 성 피해자는 절규를 남겼다 발명도둑잡기(39.7) 09.29 35 0
2892918 점심 간식 발명도둑잡기(39.7) 09.29 31 0
2892917 근데 난 사실 질문글삭 [2] 루도그담당(118.235) 09.29 50 0
2892916 나처럼 질문글삭해도 남길 수 있게 댓글에 더해서 글로 해라 [2] ㅆㅇㅆ(124.216) 09.29 57 0
2892914 MCP 랭체인, RAG 해보면 다 재밌음. 왜냐하면 지금 LLM이 ㅆㅇㅆ(124.216) 09.29 68 0
2892913 요즘 ai 발전된거 개무섭노 [3] 프갤러(61.76) 09.29 124 0
2892912 이런 씨발 비주얼스튜디오 세팅다날라갔니 ㅇㅇ(223.38) 09.29 44 0
2892911 나님 통찰력 ㄱㅆㅅㅌㅊ !! ♥냥덩이♥갤로그로 이동합니다. 09.29 34 1
2892909 프로그래머 입장에서 짱개 입국을 막아야하는 이유 [1] 프갤러(218.154) 09.29 65 0
2892908 나님 조만간 퐁퐁영45티 글 하나 써봄 ♥냥덩이♥갤로그로 이동합니다. 09.29 42 0
2892907 대한민국 중국남자 무비자입국 절대적으로 막아야합니다 [2] ㅇㅇ갤로그로 이동합니다. 09.29 401 3
2892904 주가 떨어졌네 개떡 같은거 ㅎㅎ 나르시갤로그로 이동합니다. 09.29 42 0
2892903 블록체인으로 수익이 나는것자체가 세상이 모순덩어리인거지 [2] 타이밍뒷.통수한방(1.213) 09.29 62 0
2892897 MCP랑 랭체인은 재미없어보이네여 [4] PyTorch갤로그로 이동합니다. 09.29 78 0
2892896 애새끼좀 더 번식해라 이기이기 ㅋㅋㅋㅋ 타이밍뒷.통수한방(1.213) 09.29 32 0
2892895 [대한민국] 주한미군 사령관 중장 표기 프갤러(121.172) 09.29 42 0
2892894 카톡을 대체할 개쩌는 메신저 만들어봐라 ㅇㅇ갤로그로 이동합니다. 09.29 61 0
2892884 질문글삭뭐냐고 루도그담당(211.184) 09.29 51 0
2892880 개발자새끼들 뭐좀 더 안다고 깝치지좀 마라 ㅇㅇ; [6] 프갤러(118.33) 09.29 144 2
2892879 플러터 쓰는데 gradle 이거 세팅하기 존나 좆같다 프갤러(222.121) 09.29 57 0
2892878 자러간다~ ㅇㅅㅇ 헤르 미온느갤로그로 이동합니다. 09.29 31 0
2892872 피곤하다 [2] 루도그담당(211.184) 09.29 54 0
2892865 수제 햄버거집 몰카 ㅇㅅㅇ [2] 헤르 미온느갤로그로 이동합니다. 09.29 70 0
2892864 태연 ㅇㅅㅇ 헤르 미온느갤로그로 이동합니다. 09.29 36 0
2892863 하루 한 번 헤르미온느 찬양 헤르 미온느갤로그로 이동합니다. 09.29 59 0
2892861 3500억 $ -> imf -> 알짜기업 팔림 -> 망국 프갤러(175.197) 09.29 112 0
2892860 지드래곤 ♥냥덩이♥갤로그로 이동합니다. 09.29 62 0
2892859 귀염 ♥냥덩이♥갤로그로 이동합니다. 09.29 38 0
2892858 프랑스 사태 보면 나님 예지몽 ㄹㅇ 인듯 ♥냥덩이♥갤로그로 이동합니다. 09.29 56 1
2892857 프갤 켜니 화면주사율이 일정해짐. 다른거 하면 이상해지네.. DVI소프펌 넥도리아(220.74) 09.29 56 0
2892856 다카이치 사나에 - 닥터때바라 닮음 (둘다 빌런대장) ㅇㅇ(175.197) 09.29 41 0
2892855 앱히키 씨발년아 뒤져라 [1] ㅇㅇ(222.108) 09.29 62 0
2892854 인지과학조져라 손발이시립디다갤로그로 이동합니다. 09.29 63 0
2892853 자고 일어나서 빌드하면 드디어 타로 일일 운세까지는 완성하겠네 [2] ㅆㅇㅆ(124.216) 09.29 54 0
2892852 AMI를 vmdk로 추출 후 vmware에서 부팅해본사람 ㅇㅇ갤로그로 이동합니다. 09.29 38 0
2892849 스레드가 뭔지도 모르는 새끼가 왜 비동기로 개념싸움 거는거야 [2] ㅇㅇ(106.241) 09.29 80 1
2892843 밥버러지... 고기도 익고... 명절한상 1주 시작. 넥도리아(220.74) 09.29 77 0
2892842 파이썬 질문인데 sha256 체크섬이 일치하지 않는다고 뜨는데.. [1] 프갤러(125.249) 09.29 70 0
2892841 ㅅㅂ... 알콜중독인가 잠이안와서 갈비탕 한그릇에 맥주깠다 ㅇㅇ(223.38) 09.29 37 0
2892840 밥 언재끔 커피 뿌려주었는데... 넥도리아(220.74) 09.29 78 0
뉴스 ‘폭군의 셰프’ 男배우, 군 면제 받았다…“어머니 위해 간 70% 절제” 디시트렌드 10.02
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2