디시인사이드 갤러리

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

갤러리 본문 영역

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

나르시갤로그로 이동합니다. 2025.09.27 19:18:36
조회 48 추천 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 - -
2892533 aws 공부를 한다는게 뭔 말임? [1] 프갤러(220.93) 09.27 91 0
2892532 리액트를 하려다가도 안하게 되는게 프갤러(220.93) 09.27 52 0
2892528 터미네이터3가 시리즈 중 최고임 ♥냥덩이♥갤로그로 이동합니다. 09.27 96 0
2892527 핵전쟁 ♥냥덩이♥갤로그로 이동합니다. 09.27 46 0
2892525 아이폰폴드 펜지원 안하면 절대 안 사줌 ㅅㄱ ♥냥덩이♥갤로그로 이동합니다. 09.27 115 0
2892524 저장용 ♥냥덩이♥갤로그로 이동합니다. 09.27 49 0
2892522 야 아래 포폴 사이트 찾는놈아 내가 찾음 ㅇㅇ ㅆㅇㅆ(124.216) 09.27 82 0
2892520 제 N장: C 언어 인터페이스 연동 나르시갤로그로 이동합니다. 09.27 64 0
2892519 Ada 저술, Cim을 Ada로 코딩, Nimf를 Ada로 코딩... 흠 나르시갤로그로 이동합니다. 09.27 51 0
2892518 누구땜에 또 갤... 난장판 됐네 그려 ㅠㅠ 나르시갤로그로 이동합니다. 09.27 72 0
2892517 코딩천재는 신체부터가 다르당 ♥냥덩이♥갤로그로 이동합니다. 09.27 70 0
2892516 포폴 웹사이트 만들려 하는데 이 템플릿 뭔지 아는사람??? [6] 프갤러(61.75) 09.27 97 0
2892515 ㅆㅇㅆ 도대체 뭘 알려준다는거냐? 프갤러(210.217) 09.27 107 6
2892513 한국인이 체취 없는 이유 ♥냥덩이♥갤로그로 이동합니다. 09.27 92 0
2892511 병렬처리 디버깅 비법 알려준다. [1] ㅆㅇㅆ(124.216) 09.27 96 0
2892509 병렬처리에서 멈추는건 원인이 99퍼 락 경합임? [3] 프갤러(58.29) 09.27 89 0
2892508 구해조 나 좀 구해조 ♥냥덩이♥갤로그로 이동합니다. 09.27 46 0
2892507 나님 살짝쿵야 끙야 기운.. ♥냥덩이♥갤로그로 이동합니다. 09.27 59 0
2892504 파워 정상이 컬러가 자체적으로 안돌고 메인보드에서 돌림. 넥도리아(220.74) 09.27 43 0
2892503 파워 테스텨 하얀색은 1개만 연결하라던데... 넥도리아(220.74) 09.27 43 0
2892502 마키마씨의 발냄새 똥팬티냄새.. ♥냥덩이♥갤로그로 이동합니다. 09.27 94 0
2892501 요즘은 코딩보다 비트코인투자 영어공부중 [4] 초코냥갤로그로 이동합니다. 09.27 100 0
2892497 인간이 문명을 이룬건 두 손의 정밀한 조작과 언어소통이 가능한 구강구조 ♥냥덩이♥갤로그로 이동합니다. 09.27 43 0
2892496 이게 항상 그래, 내가 평소에 뭘 쓴다 이런건 기억도 안돼 ㅆㅇㅆ(124.216) 09.27 60 0
2892495 근데 저 짝 갤 사건 사고 많아가지고 [1] 루도그담당(58.239) 09.27 88 0
2892494 이게 참 좋은 일을 했어도 나쁘게 기억 된다니까? 미짜 술맥여서 성폭행 ㅆㅇㅆ(124.216) 09.27 71 0
2892490 울갤서 나 봤다하는 놈들이면 애초에 단톡으로 여자따먹던 새끼들밖에 [5] ㅆㅇㅆ(124.216) 09.27 109 0
2892489 뭐냐 울갤 언급하면 글삭됌? 루도그담당(58.239) 09.27 56 0
2892488 ㅆㅇㅆ야 한마디만 해주마 프갤러(210.217) 09.27 90 4
2892487 와따시 벌써 콧털에서 흰 수염 난다. [1] 프갤러(110.8) 09.27 60 0
2892484 여자 불러서 술맥여서 강간하던 새끼들이 정상적으로 학교다니고 [2] ㅆㅇㅆ(124.216) 09.27 84 0
2892483 리버싱할때 어셈 분석해보면 루도그담당(58.239) 09.27 78 0
2892482 유동아 아직도 미짜 불러서 술맥이고 따먹냐. 정신차리고 살아 새끼야 ㅆㅇㅆ(124.216) 09.27 52 0
2892481 성인들도 유딩처럼 불꽃놀이에 카메라 들이대고 [5] 헬마스터갤로그로 이동합니다. 09.27 78 0
2892480 나를 울갤에서 봤니마니하는데 내가 울갤서 싸운건 술마셔서 미짜 따먹던 ㅆㅇㅆ(124.216) 09.27 77 0
2892479 류도그<<임마 신기한게 임마 남 괴롭힐때마다 다중이 유동 ㅆㅇㅆ(124.216) 09.27 65 0
2892478 류도그가 병신인건 LLM을 써서 만들건 코딩을 타이핑하건 ㅆㅇㅆ(124.216) 09.27 58 0
2892476 오늘 하루종일 분석만 했다 [1] 루도그담당(58.239) 09.27 90 0
2892475 슬슬 류도그 또 나왔구만 ㅆㅇㅆ(124.216) 09.27 57 0
2892474 사기꾼은 ㅆㅇㅆ지 프갤러(210.217) 09.27 86 4
2892473 애초에 모든 학문의 근간은 암기서 시작함 ㅆㅇㅆ(124.216) 09.27 52 0
2892472 52Hz ♥냥덩이♥갤로그로 이동합니다. 09.27 53 0
2892471 애새끼좀 더 번식해라 이기이기 ㅋㅋㅋㅋ 타이밍뒷.통수한방(1.213) 09.27 46 0
2892470 개발 암기 잘할수록 유리함 애초에 대부분 프로그램 패턴이 정해져있어서 ㅆㅇㅆ(124.216) 09.27 70 0
2892469 파워 a.s q.n.a 넥도리아(220.74) 09.27 50 0
2892468 git 커밋 로그 영어로 써 줘 ㅋㅋ [1] 나르시갤로그로 이동합니다. 09.27 79 0
2892466 시발거 존나 뻥뻥거리네 프갤러(49.165) 09.27 70 0
2892465 코드에 문제가 있는지 확인해. [2] 나르시갤로그로 이동합니다. 09.27 85 0
2892464 지금 개발판 사기꾼 바닥임 [6] 프갤러(220.93) 09.27 130 0
2892460 아 씨발 개발자 포기할려니까 할만한게 딱히 없음 [9] ㅇㅇ갤로그로 이동합니다. 09.27 124 0
뉴스 ‘30만 팔로워’ 인플루언서 시신…범인은 “VIP” 실상은 달랐다 디시트렌드 10.04
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2