디시인사이드 갤러리

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

갤러리 본문 영역

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

나르시갤로그로 이동합니다. 2025.09.27 19:18:36
조회 40 추천 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 - -
2892772 ❤+ [3] ♥냥덩이♥갤로그로 이동합니다. 09.28 102 0
2892769 오늘은 뭐할까 고민되네 ㅠㅠ 나르시갤로그로 이동합니다. 09.28 41 0
2892766 병신찐따 영포티 ㅋㅅㅋ ♥냥덩이♥갤로그로 이동합니다. 09.28 80 0
2892764 어흥! 호피무늬 모모링❤ [4] ♥냥덩이♥갤로그로 이동합니다. 09.28 119 0
2892761 인텔 ddr6 램64 10코어 이상 15w 미만 소비전력 아니면 안사줌 ♥냥덩이♥갤로그로 이동합니다. 09.28 43 0
2892754 주기적으로 컴퓨터, 노트북, 폰 포맷하는데 이상하나 ㅇㅇ(106.241) 09.28 41 0
2892753 웹개발 관련 여기서 물어봄? [2] Noitamina갤로그로 이동합니다. 09.28 81 0
2892747 ❤✨☀⭐⚡☘⛩나님 시작합니당⛩☘⚡⭐☀✨❤ ♥냥덩이♥갤로그로 이동합니다. 09.28 29 0
2892746 AI 시대 최고 수혜 주식은? [4] 나르시갤로그로 이동합니다. 09.28 79 0
2892739 자바로 뭐 할수있음? [8] ㅇㅇ갤로그로 이동합니다. 09.28 101 0
2892737 ㅆㅇㅆ 모기 새끼 프갤러(210.217) 09.28 69 5
2892735 아 조만간 연휴구나 [2] 루도그담당(58.239) 09.28 60 0
2892732 모기떄문에 짜증난다. 프갤러(210.217) 09.28 53 4
2892729 게임쪽은 계속하고 싶은데 돈이 없다. ㅆㅇㅆ(124.216) 09.28 55 0
2892726 게임쪽 창업<<이거 씨발 사기만 안먹었어도 계속했는데 [4] ㅆㅇㅆ(124.216) 09.28 102 0
2892725 if문에서 3일 걸리는 애들도 있네 [6] 루도그담당(58.239) 09.28 123 0
2892720 매일 4~5시간 자니까 건강이 엉망되었네 ㅎㅎ 나르시갤로그로 이동합니다. 09.28 34 0
2892719 ㅆㅇㅆ 이사람 요즘 뭐함? [2] ㅇㅇ갤로그로 이동합니다. 09.28 79 3
2892718 SM이 기술력이 낮다? 규모도 기술력이란걸 간과하지마 프갤러(219.115) 09.28 39 0
2892708 나님두 부천Bj 하구 싶당 야차 뜨실 분 구함 ♥냥덩이♥갤로그로 이동합니다. 09.28 56 0
2892697 하... 할 일들은 많고 시간은 없고 마음만 조급하고 후달린다... ㅇㅇ(223.38) 09.28 71 0
2892691 게임 같은거 만들 때, 컴하하스러운 내용 넣으면 어떤거 같음? [1] ㅇㅇ(106.241) 09.28 38 0
2892688 [애니뉴스] 소설 연재 사이트 제작 현황 프갤러(121.172) 09.28 30 0
2892677 러스트는 어려운 언어가 아니라 귀찮은 언어입니다. 프갤러(110.8) 09.28 54 0
2892676 방정리중 [1] 넥도리아(220.74) 09.28 63 0
2892673 크래시 에러 찾기 겁나 쉬워요 나르시갤로그로 이동합니다. 09.28 54 0
2892672 ■개발자 평균 정년은 40대 중반.jpg ㅇㅇ갤로그로 이동합니다. 09.28 102 1
2892670 리액트 이런거 쓰는거 진짜 위험하네 [3] ㅇㅇ(118.34) 09.28 177 0
2892669 러스트 아무도 안 써요 [9] 나르시갤로그로 이동합니다. 09.28 82 0
2892667 비전공자 특 ㅇㅇ(211.234) 09.28 61 2
2892666 바이브코딩으로는 넘을 수 없는 장벽은 존재함. 컴파일러라거나 ㅆㅇㅆ(124.216) 09.28 82 0
2892665 그래도 도저히 프로그래밍 못 놓겠다하면 바이브코딩부터 시작해라 ㅆㅇㅆ(124.216) 09.28 65 0
2892664 그냥 중딩이면 바이브 코딩으로 시작해라 파이썬, 자바 배우는건 그때가서 ㅆㅇㅆ(124.216) 09.28 74 0
2892662 중고등학생이면 그냥 대학 성적 잘받아라. 이거밖에 없다 [4] ㅆㅇㅆ(124.216) 09.28 108 0
2892661 중학교 2학년 프로그래밍 시작하려면 [2] 프갤러(221.154) 09.28 94 0
2892656 지피티 코드만 수정하면되요 이러는 애들 뺨때리고 싶은데 정상이냐 ㅆㅇㅆ(124.216) 09.28 57 0
2892650 근데 카톡 서비스 절대 못되돌릴거 같은데 저거 광고비 받았을거 아냐 ㅆㅇㅆ(124.216) 09.28 64 1
2892649 임마들 맨날 유튜브에 낚이는 이유도 알거 같노 ㅇㅇ갤로그로 이동합니다. 09.28 49 0
2892648 냥덩 versus 야옹 ㅇㅇ(223.38) 09.28 51 0
2892647 런타임 디버깅 개지랄해야하는 것들 러스트는 컴파일 타임에 거의 잡습니다. 프갤러(223.63) 09.28 47 0
2892646 러스트 홍보는 영업이 아닙니다. 프갤러(223.63) 09.28 46 0
2892645 나님은 마허라임 ㅇㅅㅇ ♥냥덩이♥갤로그로 이동합니다. 09.28 49 0
2892641 나님 강의 ♥냥덩이♥갤로그로 이동합니다. 09.28 49 0
2892639 [대한민국] 시사매거진-전쟁 발발 가능성 언급 프갤러(121.172) 09.28 50 0
2892636 프갤럼들 맨날 하는게 영업 아니었나?? [2] ㅇㅇ갤로그로 이동합니다. 09.28 63 0
2892635 ■AI 때문에 웹개발 자체를 포기해야하나 고민중이다 [2] ㅇㅇ갤로그로 이동합니다. 09.28 139 0
2892634 친중무능극좌 리짜이밍 부정평가 48% 과반 붕괴 ♥냥덩이♥갤로그로 이동합니다. 09.28 67 1
2892630 사람이 정말 열심히 살아야 하는것 같아... 항상 제대로 똑바로 살아야해 [1] ㅇㅇ(223.38) 09.28 50 0
2892627 월요일날 우체국에서 틀딱들 정모 하겟네 야옹아저씨갤로그로 이동합니다. 09.28 47 0
2892626 냥덩이 ♥냥덩이♥갤로그로 이동합니다. 09.28 58 0
뉴스 강원래, 휠체어에서 두 발로 벌떡…김송 “천국에서 다시 만나길” 디시트렌드 10.02
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2