1 /*
2  * Copyright (C) 2000-2004 the xine project
3  *
4  * This file is part of xine, a unix video player.
5  *
6  * xine is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * xine is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
19  *
20  * $Id$
21  *
22  */
23 
24 #ifndef _HAVE_DND_H
25 #define _HAVE_DND_H
26 
27 #include <X11/Xlib.h>
28 
29 #define _XA_XdndAware Atoms[0]
30 #define _XA_XdndEnter Atoms[1]
31 #define _XA_XdndLeave Atoms[2]
32 #define _XA_XdndDrop Atoms[3]
33 #define _XA_XdndPosition Atoms[4]
34 #define _XA_XdndStatus Atoms[5]
35 #define _XA_XdndSelection Atoms[6]
36 #define _XA_XdndFinished Atoms[7]
37 #define _XA_XdndTypeList Atoms[8]
38 #define _XA_INCR Atoms[9]
39 #define _XA_WM_DELETE_WINDOW Atoms[10]
40 #define TIMIDITY_PROTOCOL_ATOM Atoms[11]
41 #define _XA_ATOMS_COUNT 12
42 
43 #define MAX_SUPPORTED_TYPE 2
44 
45 typedef void (*dnd_callback_t) (const char *);
46 
47 typedef struct {
48   Display             *display;
49   Window               win;
50 
51   dnd_callback_t  callback;
52 
53   int                  x;
54   int                  y;
55   Window               dropper_toplevel;
56   Window               dropper_window;
57   Window               dragger_window;
58   Atom                *dragger_typelist;
59   Atom                 desired;
60   Time                 time;
61 
62   Atom                 Atoms[_XA_ATOMS_COUNT];
63   Atom                 supported[MAX_SUPPORTED_TYPE];
64   Atom                 version;
65   Bool                 in_progress;
66 } DndClass;
67 
68 /* header was ripped from xdnd's example on its page */
69 
70 #define XDND_THREE 3
71 #define XDND_ENTER_SOURCE_WIN(e)	((e)->xclient.data.l[0])
72 #define XDND_ENTER_THREE_TYPES(e)	(((e)->xclient.data.l[1] & 0x1UL) == 0)
73 #define XDND_ENTER_THREE_TYPES_SET(e,b)	(e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x1UL) | (((b) == 0) ? 0 : 0x1UL)
74 #define XDND_ENTER_VERSION(e)		((e)->xclient.data.l[1] >> 24)
75 #define XDND_ENTER_VERSION_SET(e,v)	(e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~(0xFF << 24)) | ((v) << 24)
76 #define XDND_ENTER_TYPE(e,i)		((e)->xclient.data.l[2 + i])	/* i => (0, 1, 2) */
77 
78 /* XdndPosition */
79 #define XDND_POSITION_SOURCE_WIN(e)	((e)->xclient.data.l[0])
80 #define XDND_POSITION_ROOT_X(e)		((e)->xclient.data.l[2] >> 16)
81 #define XDND_POSITION_ROOT_Y(e)		((e)->xclient.data.l[2] & 0xFFFFUL)
82 #define XDND_POSITION_ROOT_SET(e,x,y)	(e)->xclient.data.l[2]  = ((x) << 16) | ((y) & 0xFFFFUL)
83 #define XDND_POSITION_TIME(e)		((e)->xclient.data.l[3])
84 #define XDND_POSITION_ACTION(e)		((e)->xclient.data.l[4])
85 
86 /* XdndStatus */
87 #define XDND_STATUS_TARGET_WIN(e)	((e)->xclient.data.l[0])
88 #define XDND_STATUS_WILL_ACCEPT(e)	((e)->xclient.data.l[1] & 0x1L)
89 #define XDND_STATUS_WILL_ACCEPT_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x1UL) | (((b) == 0) ? 0 : 0x1UL)
90 #define XDND_STATUS_WANT_POSITION(e)	((e)->xclient.data.l[1] & 0x2UL)
91 #define XDND_STATUS_WANT_POSITION_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x2UL) | (((b) == 0) ? 0 : 0x2UL)
92 #define XDND_STATUS_RECT_X(e)		((e)->xclient.data.l[2] >> 16)
93 #define XDND_STATUS_RECT_Y(e)		((e)->xclient.data.l[2] & 0xFFFFL)
94 #define XDND_STATUS_RECT_WIDTH(e)	((e)->xclient.data.l[3] >> 16)
95 #define XDND_STATUS_RECT_HEIGHT(e)	((e)->xclient.data.l[3] & 0xFFFFL)
96 #define XDND_STATUS_RECT_SET(e,x,y,w,h)	{(e)->xclient.data.l[2] = ((x) << 16) | ((y) & 0xFFFFUL); (e)->xclient.data.l[3] = ((w) << 16) | ((h) & 0xFFFFUL); }
97 #define XDND_STATUS_ACTION(e)		((e)->xclient.data.l[4])
98 
99 /* XdndLeave */
100 #define XDND_LEAVE_SOURCE_WIN(e)	((e)->xclient.data.l[0])
101 
102 /* XdndDrop */
103 #define XDND_DROP_SOURCE_WIN(e)		((e)->xclient.data.l[0])
104 #define XDND_DROP_TIME(e)		((e)->xclient.data.l[2])
105 
106 /* XdndFinished */
107 #define XDND_FINISHED_TARGET_WIN(e)	((e)->xclient.data.l[0])
108 
109 /*
110  * *** DND
111  */
112 void init_dnd(Display *, DndClass *);
113 
114 int make_window_dnd_aware(DndClass *, Window, dnd_callback_t);
115 
116 int process_client_dnd_message(DndClass *, XEvent *);
117 
118 #endif
119