디시인사이드 갤러리

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

갤러리 본문 영역

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

나르시갤로그로 이동합니다. 2025.09.27 19:18:36
조회 43 추천 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 - -
2892480 나를 울갤에서 봤니마니하는데 내가 울갤서 싸운건 술마셔서 미짜 따먹던 [1] ㅆㅇㅆ(124.216) 09.27 70 0
2892479 류도그<<임마 신기한게 임마 남 괴롭힐때마다 다중이 유동 ㅆㅇㅆ(124.216) 09.27 61 0
2892478 류도그가 병신인건 LLM을 써서 만들건 코딩을 타이핑하건 ㅆㅇㅆ(124.216) 09.27 54 0
2892476 오늘 하루종일 분석만 했다 [1] 루도그담당(58.239) 09.27 83 0
2892475 슬슬 류도그 또 나왔구만 ㅆㅇㅆ(124.216) 09.27 52 0
2892474 사기꾼은 ㅆㅇㅆ지 프갤러(210.217) 09.27 77 3
2892473 애초에 모든 학문의 근간은 암기서 시작함 ㅆㅇㅆ(124.216) 09.27 48 0
2892472 52Hz ♥냥덩이♥갤로그로 이동합니다. 09.27 46 0
2892471 애새끼좀 더 번식해라 이기이기 ㅋㅋㅋㅋ 타이밍뒷.통수한방(1.213) 09.27 43 0
2892470 개발 암기 잘할수록 유리함 애초에 대부분 프로그램 패턴이 정해져있어서 ㅆㅇㅆ(124.216) 09.27 65 0
2892469 파워 a.s q.n.a 넥도리아(220.74) 09.27 46 0
2892468 git 커밋 로그 영어로 써 줘 ㅋㅋ [1] 나르시갤로그로 이동합니다. 09.27 72 0
2892466 시발거 존나 뻥뻥거리네 프갤러(49.165) 09.27 65 0
2892465 코드에 문제가 있는지 확인해. [2] 나르시갤로그로 이동합니다. 09.27 79 0
2892464 지금 개발판 사기꾼 바닥임 [6] 프갤러(220.93) 09.27 122 0
2892460 아 씨발 개발자 포기할려니까 할만한게 딱히 없음 [9] ㅇㅇ갤로그로 이동합니다. 09.27 112 0
2892459 민생쿠폰10만원받았는데 식비로도 10만원 넘게필요하지않음?? 타이밍뒷.통수한방(1.213) 09.27 40 0
XIM 통신 구현에서 공용체 union 사용 예시 나르시갤로그로 이동합니다. 09.27 43 0
2892456 저번 프붕이 통신 프로토콜 질문에 대한 실제 예시 코드 ㅋㅋ 나르시갤로그로 이동합니다. 09.27 46 0
2892455 공채 합격률이 상채 합격률보다 더 높은가? ㅇㅇ갤로그로 이동합니다. 09.27 40 0
2892453 프붕이들 깜놀랄 프로토콜 설계 ㅋㅋ [5] 나르시갤로그로 이동합니다. 09.27 76 0
2892452 고수분들은 코테 준비 어케 했음? 코테>>약간 후기도 있음 프갤러(114.205) 09.27 210 0
2892443 다음과 같은 에러가 났다. 어떻게 해결하는 것이 좋겠는가? [1] 나르시갤로그로 이동합니다. 09.27 68 0
2892442 다음 코드의 형변환에 문제 없지? 나르시갤로그로 이동합니다. 09.27 59 0
2892439 디자인 = 설계, 오늘 제미니 제안 사항 나르시갤로그로 이동합니다. 09.27 69 0
2892437 쓰레기통에 재활용하기에는 방의물건이 200-300 가치다 책포함. [2] 넥도리아(220.74) 09.27 42 0
2892434 내 자신의 디자인적 능력이 너무 덜떨어져있다 [4] ㅆㅇㅆ(124.216) 09.27 61 0
2892433 ■램16기가면 윈도우는 쓰지 말아야함? OS추천좀 [4] ㅇㅇ갤로그로 이동합니다. 09.27 88 0
2892431 주말이나 휴가때 즐기는 취미나 휴식활동 있음?? [3] ㅇㅇ(223.39) 09.27 59 0
2892430 알고리즘 강의 들을만한 사람 없음? 프갤러(114.205) 09.27 39 0
2892429 오늘도 코딩하다보면 정신나갈것같군. ㅆㅇㅆ(124.216) 09.27 60 0
2892424 책샀어요. 옆에는 기억이 안나는 SSD 넥도리아(220.74) 09.27 68 0
2892423 이미 메신저 앱 겁나 많아요. 위챗이 카톡의 최대 경쟁자입니다 [5] 나르시갤로그로 이동합니다. 09.27 73 0
2892422 몇%정도 점유율 뺏겨야 나머지 사람들도 움직이려나 프갤러(45.64) 09.27 42 0
2892419 지금 메신저앱 나오면 빈집털기 ㅆㄱㄴ인데 ㅇㅇ갤로그로 이동합니다. 09.27 46 0
2892418 카톡한데 서버 이중화 왜 안 했냐고 열라 까던 조센징 정부 [2] 나르시갤로그로 이동합니다. 09.27 120 0
2892417 분석계획실행피드백 [2] 공기역학갤로그로 이동합니다. 09.27 72 0
2892414 우체국은 서버 이중화도 안 한거냐?? 대박인걸 나르시갤로그로 이동합니다. 09.27 103 0
2892413 우체국 화재) 한국 IT가 이정도로 개판이다. [3] 나르시갤로그로 이동합니다. 09.27 137 0
2892412 카카오뱅크 욕했던 조센징들 보셈 나르시갤로그로 이동합니다. 09.27 65 0
2892410 뜌.. 뜌땨잇!! [2] ♥냥덩이♥갤로그로 이동합니다. 09.27 69 1
2892409 역시 착착 진행중이었구만 ㄷㄷ ㅇㅇ갤로그로 이동합니다. 09.27 66 0
2892407 인지과학조져라 손발이시립디다갤로그로 이동합니다. 09.27 46 0
2892406 노인들이 주장하는 노력과 운이라는 말 존나 좇같음 타이밍뒷.통수한방(1.213) 09.27 47 0
2892405 카톡 점유율 보아할 때 카톡은 착한 편 [1] 나르시갤로그로 이동합니다. 09.27 55 0
2892403 구글씨발 애미뒤진새끼들 광고존나덕지덕지줘패고싶다 [1] 밀우갤로그로 이동합니다. 09.27 45 0
2892401 나르시 뭐임? 간첩임? 카톡 욕하는 이유- [1] 프갤러(121.172) 09.27 51 0
2892400 라면이 이렇게 먹으면 은근 영양적으로 잘맞고 맛있기까지 하다니까;; [1] ㅇㅇ(223.39) 09.27 63 0
2892398 카톡 욕하는 놈들 구글 유튜브는 왜 욕 안 해? [1] 나르시갤로그로 이동합니다. 09.27 49 0
2892397 카톡 욕하는 놈들 지옥에나 떨어져라 나르시갤로그로 이동합니다. 09.27 47 0
뉴스 가수 마션&늑우∙Allroot∙LONA, 10월 1주 차 위클리 키트앨범 스포트라이트 선정! 디시트렌드 14:00
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2