디시인사이드 갤러리

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

갤러리 본문 영역

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

나르시갤로그로 이동합니다. 2025.09.27 19:18:36
조회 51 추천 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 - -
공지 프로그래밍 갤러리 이용 안내 [96] 운영자 20.09.28 47705 65
2894694 고졸 신입인데 뭐부터 공부할지 추천좀 해주라 ㄴㄴㅇ(118.176) 14:33 8 0
2894693 비와서 꿉꿉한데 에어컨도 안틀어주고 괜히 나왔습니다. 프갤러(221.149) 14:33 3 0
2894692 윈도우 이거 프로그래밍 좀 하려니까 설치할게 많네요 프갤러(221.149) 14:30 6 0
2894691 나님 탈갤합니당.. ♥덩냥이♥갤로그로 이동합니다. 14:17 12 0
2894690 망했습니다. 하는 것보다 고장네네요. [1] 넥도리아2025(119.195) 12:15 19 0
2894689 뉴스 보면 연휴 기간에도 납치 소식이누 ㄷ ㄷ 쇼부(211.234) 12:14 21 0
2894688 유행이 패션 음악 영화 책 미술 중 빨리 오는 순서 발명도둑잡기(118.216) 12:05 11 0
2894686 K-아이언맨 발명도둑잡기(118.216) 11:50 18 0
2894685 대왕고래 앞에 드러누운 민주당의 데자뷰 ㅇㅇ(121.168) 11:36 22 0
2894684 [대한민국] 세계대전에 대한 생각 프갤러(121.172) 11:32 15 0
2894683 트럼프 “내년 80세 생일에 백악관서 UFC 개최” 공식화 발명도둑잡기(118.216) 11:29 13 0
2894682 5시간 반 잤더니 졸리다 발명도둑잡기(118.216) 11:16 25 0
2894681 연령별로 가장 많이 들은 노래는…20대 ‘레블 하트’, 30대 ‘투 배드 발명도둑잡기(118.216) 10:51 15 0
2894680 AI`는 결국 전력, 에너지 싸움이다. 나르시갤로그로 이동합니다. 10:46 18 0
2894679 어쩔 수가 없다 발명도둑잡기(118.216) 10:40 36 0
2894678 2026 년 드라마 편성 발명도둑잡기(118.216) 10:36 24 0
2894677 [애니뉴스 + 대한민국] 사이트 개발상황 및 흑묘백묘란? 프갤러(121.172) 10:36 15 0
2894676 범죄율은 미국이 압도적 세계 최고고 발명도둑잡기(118.216) 10:28 16 0
2894675 10, 29, 50 억원 발명도둑잡기(118.216) 10:19 23 0
2894674 FreeBSD용 gprbuild 패키지 작성 스크립트 나르시갤로그로 이동합니다. 10:15 12 0
2894673 일본 여행와서도 딸딸이는 쳐야겠지? 류류(122.196) 10:01 24 0
2894672 아 배부르다 현지에서 아침 먹고옴 [1] 류류(122.196) 09:45 30 0
2894671 소박하면서 운치가 있음 [1] 류류(122.196) 08:04 34 0
2894670 일단 오늘은 도톤보리랑 신세카이만 가야겠다 류류(122.196) 08:03 15 0
2894669 친중극좌 97(영포티)~86 [2] ♥덩냥이♥갤로그로 이동합니다. 07:59 49 1
2894668 역시 일본 이라 그런지 자전거가 일상화 되어있네 [2] 류류(110.70) 07:47 36 0
2894667 위키세계어 아직도 있냐? 프갤러(59.12) 07:32 22 0
2894666 헬조센은 10시간을 쳐자도 개운하지 않던데 [1] 류류(122.196) 07:22 31 0
2894665 4시간 밖에 못잤는데 되게 개운하네 류류(122.196) 07:22 26 0
2894664 일본 교수 노벨 생리의학상 수상 ㅇㅇ(121.168) 07:14 55 0
2894663 수원성과 UFO ㅇㅅㅇ [3] 헤르 미온느갤로그로 이동합니다. 07:12 36 1
2894662 친중국가는 관광도 가지 말아야함 [3] ♥덩냥이♥갤로그로 이동합니다. 06:59 47 1
2894661 태연 ㅇㅅㅇ 헤르 미온느갤로그로 이동합니다. 06:31 17 0
2894660 하루 한 번 헤르미온느 찬양 헤르 미온느갤로그로 이동합니다. 06:29 36 0
2894652 모기가 두 마리였다 [1] 발명도둑잡기(118.216) 04:31 32 0
2894646 총애를 받으면 놀란 듯이 하라 발명도둑잡기(118.216) 04:03 21 0
2894638 도둑한테 휴일이 어딨냐 발명도둑잡기(118.216) 02:53 57 0
2894637 다카이치는 결국 카미카제의 반복으로 귀결될 뿐이다 [1] 발명도둑잡기(118.216) 02:36 25 0
2894636 음기 충전 발명도둑잡기(118.216) 02:29 22 0
2894621 절대 공개하지 않는 AS센터의 전설의 기술 100% 다 공개합니다 발명도둑잡기(118.216) 01:22 29 0
2894619 다른곳은 모르겠는데 오사카 여기는 모기가 없네 류류(122.196) 01:18 25 0
2894613 이건 진짜 혁명이다… 구글 나노바나나 20가지 활용법 직접 보여드립니다! 발명도둑잡기(118.216) 01:05 35 0
2894610 I Turned This Broken Phone Into A Home S 발명도둑잡기(118.216) 00:59 20 0
2894609 This hacked Chromebox is INSANELY impres 발명도둑잡기(118.216) 00:58 18 0
2894607 운영 체제 없이 어셈블리로 프로그래밍하기 발명도둑잡기(118.216) 00:55 34 0
2894604 숙소 도착 ㅠㅠ 류류(122.196) 00:48 41 0
2894602 introducing copyparty, the FOSS file ser 발명도둑잡기(118.216) 00:42 19 0
2894600 기존 아날로그 SLR 카메라 안에 CCD를 넣어 디지털로 바꾸는 장치 발명도둑잡기(118.216) 00:37 18 0
2894598 22살에 창업해 AI로 연매출 100억 원~!창업 6년차 발명도둑잡기(118.216) 00:34 34 0
뉴스 ‘둘째 임신’ 이시영 안타까운 근황…분만 위험 커지는 ‘이 병’ 진단 디시트렌드 10.05
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2