1 /***********************************************************/ 2 /* Copyright 1996 Daniel Dardailler. 3 Permission to use, copy, modify, distribute, and sell this software 4 for any purpose is hereby granted without fee, provided that the above 5 copyright notice appear in all copies and that both that copyright 6 notice and this permission notice appear in supporting documentation, 7 and that the name of Daniel Dardailler not be used in advertising or 8 publicity pertaining to distribution of the software without specific, 9 written prior permission. Daniel Dardailler makes no representations 10 about the suitability of this software for any purpose. It is 11 provided "as is" without express or implied warranty. 12 ************************************************************/ 13 #ifndef _DnDP_h 14 #define _DnDP_h 15 16 /*** Dnd Protocol stream structures and other low-level stuff */ 17 18 #include "Dnd.h" 19 #include <X11/Xmd.h> 20 21 typedef struct _DndSrcProp { 22 BYTE byte_order ; 23 BYTE protocol_version ; 24 CARD16 target_index ; 25 CARD32 selection ; 26 } DndSrcProp ; 27 28 typedef struct _DndReceiverProp { 29 BYTE byte_order ; 30 BYTE protocol_version ; 31 BYTE protocol_style ; 32 BYTE pad1; 33 CARD32 proxy_window; 34 CARD16 num_drop_sites ; 35 CARD16 pad2; 36 CARD32 total_size; 37 } DndReceiverProp ; 38 39 /* need to use some union hack since window and property are in 40 different order depending on the message ... */ 41 typedef struct _DndTop { 42 CARD32 src_window; 43 CARD32 property; 44 } DndTop ; 45 46 typedef struct _DndPot { 47 INT16 x; 48 INT16 y; 49 CARD32 property; 50 CARD32 src_window; 51 } DndPot ; 52 53 typedef struct _DndMessage { 54 BYTE reason; 55 BYTE byte_order; 56 CARD16 flags; 57 CARD32 time; 58 union { 59 DndTop top ; 60 DndPot pot ; 61 } data ; 62 } DndMessage ; 63 64 typedef struct { 65 BYTE byte_order; 66 BYTE protocol_version; 67 CARD16 num_target_lists; 68 CARD32 data_size; 69 /* then come series of CARD16,CARD32,CARD32,CARD32... */ 70 } DndTargets; 71 72 73 /* protocol version */ 74 #define DND_PROTOCOL_VERSION 0 75 76 77 #define DND_EVENT_TYPE_MASK ((BYTE)0x80) 78 #define DND_EVENT_TYPE_SHIFT 7 79 #define DND_CLEAR_EVENT_TYPE ((BYTE)0x7F) 80 81 /* message_type is data[0] of the client_message 82 this return 1 (receiver bit up) or 0 (initiator) */ 83 #define DND_GET_EVENT_TYPE(message_type) \ 84 ((char) (((message_type) & DND_EVENT_TYPE_MASK) >> DND_EVENT_TYPE_SHIFT)) 85 86 /* event_type can be 0 (initiator) or 1 (receiver) */ 87 #define DND_SET_EVENT_TYPE(event_type) \ 88 (((BYTE)(event_type) << DND_EVENT_TYPE_SHIFT) & DND_EVENT_TYPE_MASK) 89 90 91 #define DND_OPERATION_MASK ((CARD16) 0x000F) 92 #define DND_OPERATION_SHIFT 0 93 #define DND_STATUS_MASK ((CARD16) 0x00F0) 94 #define DND_STATUS_SHIFT 4 95 #define DND_OPERATIONS_MASK ((CARD16) 0x0F00) 96 #define DND_OPERATIONS_SHIFT 8 97 #define DND_COMPLETION_MASK ((CARD16) 0xF000) 98 #define DND_COMPLETION_SHIFT 12 99 100 #define DND_GET_OPERATION(flags) \ 101 ((unsigned char) \ 102 (((flags) & DND_OPERATION_MASK) >> DND_OPERATION_SHIFT)) 103 104 #define DND_SET_OPERATION(operation) \ 105 (((CARD16)(operation) << DND_OPERATION_SHIFT)\ 106 & DND_OPERATION_MASK) 107 108 #define DND_GET_STATUS(flags) \ 109 ((unsigned char) \ 110 (((flags) & DND_STATUS_MASK) >> DND_STATUS_SHIFT)) 111 112 #define DND_SET_STATUS(status) \ 113 (((CARD16)(status) << DND_STATUS_SHIFT)\ 114 & DND_STATUS_MASK) 115 116 #define DND_GET_OPERATIONS(flags) \ 117 ((unsigned char) \ 118 (((flags) & DND_OPERATIONS_MASK) >> DND_OPERATIONS_SHIFT)) 119 120 #define DND_SET_OPERATIONS(operation) \ 121 (((CARD16)(operation) << DND_OPERATIONS_SHIFT)\ 122 & DND_OPERATIONS_MASK) 123 124 #define DND_GET_COMPLETION(flags) \ 125 ((unsigned char) \ 126 (((flags) & DND_COMPLETION_MASK) >> DND_COMPLETION_SHIFT)) 127 128 #define DND_SET_COMPLETION(completion) \ 129 (((CARD16)(completion) << DND_COMPLETION_SHIFT)\ 130 & DND_COMPLETION_MASK) 131 132 133 #define SWAP4BYTES(l) {\ 134 struct { unsigned t :32;} bit32;\ 135 char n, *tp = (char *) &bit32;\ 136 bit32.t = l;\ 137 n = tp[0]; tp[0] = tp[3]; tp[3] = n;\ 138 n = tp[1]; tp[1] = tp[2]; tp[2] = n;\ 139 l = bit32.t;\ 140 } 141 142 #define SWAP2BYTES(s) {\ 143 struct { unsigned t :16; } bit16;\ 144 char n, *tp = (char *) &bit16;\ 145 bit16.t = s;\ 146 n = tp[0]; tp[0] = tp[1]; tp[1] = n;\ 147 s = bit16.t;\ 148 } 149 150 151 /** Private extern functions */ 152 153 extern unsigned char _DndByteOrder (void); 154 155 156 /***** Targets/Index stuff */ 157 158 typedef struct { 159 int num_targets; 160 Atom *targets; 161 } DndTargetsTableEntryRec, * DndTargetsTableEntry; 162 163 typedef struct { 164 int num_entries; 165 DndTargetsTableEntry entries; 166 } DndTargetsTableRec, * DndTargetsTable; 167 168 extern int _DndTargetsToIndex(Display * display, Atom * targets, 169 int num_targets); 170 171 extern int _DndIndexToTargets(Display * display, 172 int index, 173 Atom ** targets); 174 175 #endif /* _DndP_h */ 176