디시인사이드 갤러리

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

갤러리 본문 영역

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

나르시갤로그로 이동합니다. 2025.09.27 19:18:36
조회 61 추천 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
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 공개연애가 득보다 실인 것 같은 스타는? 운영자 25/10/06 - -
AD 프로게이머가 될테야!! 운영자 25/10/01 - -
2893546 기 모으는 모습 발명도둑잡기(118.235) 10.02 32 0
2893545 토쿄 가면 볼 수 있는 바이브 코더 [1] 발명도둑잡기(118.235) 10.02 57 0
2893544 입 안 헐어서 발명도둑잡기(39.7) 10.02 43 0
2893543 촘스키좌 논문 읽어보고 느낀거 [1] 3기견치코갤로그로 이동합니다. 10.02 67 1
2893542 bcachefs 발명도둑잡기(39.7) 10.02 38 0
2893540 힘들다... 진짜... 프갤러(27.179) 10.02 43 1
2893538 2023년 취업할땐 대충 게시판 포폴 베껴서 내도 취업되던데 [4] ㅇㅇ(223.38) 10.02 116 0
2893537 석사과정에서 코드퀄리티 구리다는 말 듣고 [2] ㅇㅇ(211.234) 10.02 104 4
2893536 현시대는 토발즈도 1찍 짱깨편인 무서운 시대이다ㅋㅋ번식 더 해줘라 이기 타이밍뒷.통수한방(1.213) 10.02 40 0
2893535 트럼프 관세 K팝 가수 겨냥 가능성 발명도둑잡기(118.216) 10.02 34 0
2893534 카카오 코테 요청 왔는데 원래 다 오는거임? [2] ㅇㅇ(58.140) 10.02 369 0
2893533 3d 프린터로 타자기 발명도둑잡기(118.216) 10.02 30 0
2893531 아줌마들 개새끼랑 대화하는 능력 줫되느 타이밍뒷.통수한방(1.213) 10.02 48 0
2893530 블랙핑크는 ㅇㅇ(121.168) 10.02 47 0
2893529 개 무서운 로보트 발명도둑잡기(118.216) 10.02 54 0
2893528 한글 자모 도장 [1] 발명도둑잡기(118.216) 10.02 66 0
2893527 오늘의 발명 실마리: 기념용 점토판 발명도둑잡기(118.216) 10.02 54 0
2893526 금융권 가지마라 ㅇㅇ(121.168) 10.02 454 0
2893525 지하 유물 자동 탐색 로보트 발명도둑잡기(118.216) 10.02 33 0
2893524 축하합니다. 프갤러(49.165) 10.02 42 0
2893523 친구간에도 서열을 나누려한다 ㅇㅇ(121.168) 10.02 55 0
2893520 여러분은 연휴때 무엇을 하고 지내실 예정인가요? [6] 루도그담당(58.239) 10.02 71 0
2893519 짱깨 한국서 난동 치안 불안 급증 ♥냥덩이♥갤로그로 이동합니다. 10.02 42 0
2893518 감사의 기적 발명도둑잡기(118.216) 10.02 55 0
2893517 이 개씨발일좆도못하는새끼야 [7] 개멍청한유라갤로그로 이동합니다. 10.02 106 0
2893515 야 원래 중국인 무비자였다가 싸드 배치해서 잠정중단했고 발명도둑잡기(118.216) 10.02 44 0
2893514 중복 ♥냥덩이♥갤로그로 이동합니다. 10.02 49 0
2893513 ❤✨☀⭐⚡☘⛩나님 시작합니당⛩☘⚡⭐☀✨❤ ♥덩냥이♥갤로그로 이동합니다. 10.02 53 0
2893512 hp 엔터프라이즈 하드디스크 6TB 18개 구입 발명도둑잡기(118.216) 10.02 50 0
2893510 러스트는 어렵고 비생산적이라는 편견으로 살아가는 사람들 [3] 프갤러(218.154) 10.02 66 0
2893509 꿈 꿨고 9시간 반 잤다 발명도둑잡기(118.216) 10.02 41 0
2893508 ❤✨☀⭐⚡☘⛩나님 시작합니당⛩☘⚡⭐☀✨❤ ♥냥덩이♥갤로그로 이동합니다. 10.02 59 0
2893507 아직 편견과 생각으로만 살아가는 사람들이 너무 많은듯 [6] 공기역학갤로그로 이동합니다. 10.02 88 0
2893506 [애니뉴스 + 대한민국] 기회의 평등과 결혼 프갤러(121.172) 10.02 32 0
2893505 컴공새끼들이 AI/빅데이터한다고 석사 석사 외치는게 가관임 [7] ㅇㅇ(211.170) 10.02 162 0
2893504 하루 월차 내면 열흘 연휴네 발명도둑잡기(118.216) 10.02 47 0
2893503 국민의힘이 말하는 상납견 배급견 문재인 김정숙 대장동 고기사먹어 [1] 넥도리아(223.38) 10.02 86 0
2893502 근데 상법개정이랑 배임죄 폐지는 상충하는거 아님? [4] ㅇㅇ(121.168) 10.02 89 0
2893501 뭔지랄을 했길래 하필 남쪽에서 태어났을까 ㅅㅂ [10] 타이밍뒷.통수한방(1.213) 10.02 99 0
2893500 질투 인민 공화국에 태어나신걸 환영합니다. [3] ㅇㅇ(121.168) 10.02 69 0
2893499 ❤✨☀⭐⚡☘⛩나님 시작합니당⛩☘⚡⭐☀✨❤ [2] ♥덩냥이♥갤로그로 이동합니다. 10.02 87 0
2893498 ai 재앙은 저능아 바이브코더에 의해 올겁니다. [1] 프갤러(218.154) 10.02 94 0
2893497 ai가 개똥코드 싸질러서 rewrite하는데 그걸 또 ai로 한다고? [4] 프갤러(218.154) 10.02 124 0
2893496 찢은 보수진보 대통합을 이루고 국가붕괴시킴 ㅋㅋㅋㅋㅋㅋ 타이밍뒷.통수한방(1.213) 10.02 35 0
2893495 rewrite it 정도는 ㅇㅇ갤로그로 이동합니다. 10.02 48 0
2893494 카카오톡 드디어 레전드 평점 돌파 [3] 헬마스터갤로그로 이동합니다. 10.02 107 0
2893493 한국을 예견한 미국 드라마 ㅇㅇ(121.168) 10.02 61 0
2893492 ❤✨☀⭐⚡☘⛩나님 시작합니당⛩☘⚡⭐☀✨❤ [3] ♥덩냥이♥갤로그로 이동합니다. 10.02 81 1
2893491 드디어 3 모니터 구축했다. 2년만에... 넥도리아(220.74) 10.02 46 0
2893489 [kt cloud x goorm] IT 직군 개발 / 비개발 8개 과정 프갤러(14.32) 10.02 789 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2