1 /* grTCairo4.c -
2  *
3  * Copyright 2017 Open Circuit Design
4  *
5  * This file contains functions to manage the graphics tablet associated
6  * with the X display.
7  *
8  * Written by Chuan Chen
9  */
10 
11 #include <signal.h>
12 #include <stdio.h>
13 #include <X11/Xlib.h>
14 #include <cairo/cairo-xlib.h>
15 
16 #include "tcltk/tclmagic.h"
17 #include "utils/magic.h"
18 #include "utils/magsgtty.h"
19 #include "textio/textio.h"
20 #include "utils/geometry.h"
21 #include "windows/windows.h"
22 #include "graphics/graphics.h"
23 #include "graphics/graphicsInt.h"
24 #include "graphics/grTkCommon.h"
25 #include "textio/txcommands.h"
26 #include "grTCairoInt.h"
27 
28 extern Display *grXdpy;
29 
30 
31 /*---------------------------------------------------------
32  * GrTCairoDisableTablet:
33  *	Turns off the cursor.
34  *
35  * Results:	None.
36  *
37  * Side Effects:    None.
38  *---------------------------------------------------------
39  */
40 
41 void
GrTCairoDisableTablet()42 GrTCairoDisableTablet ()
43 {
44     /* (Unimplemented) */
45 }
46 
47 
48 /*---------------------------------------------------------
49  * GrTCairoEnableTablet:
50  *	This routine enables the graphics tablet.
51  *
52  * Results:
53  *   	None.
54  *
55  * Side Effects:
56  *	Simply turn on the crosshair.
57  *---------------------------------------------------------
58  */
59 
60 void
GrTCairoEnableTablet()61 GrTCairoEnableTablet ()
62 {
63     /* (Unimplemented) */
64 }
65 
66 
67 /*
68  * ----------------------------------------------------------------------------
69  * grtcairoGetCursorPos:
70  * 	Read the cursor position in magic coordinates.
71  *
72  * Results:
73  *	TRUE is returned if the coordinates were succesfully read, FALSE
74  *	otherwise.
75  *
76  * Side effects:
77  *	The parameter is filled in with the cursor position, in the form of
78  *	a point in screen coordinates.
79  * ----------------------------------------------------------------------------
80  */
81 
82 bool
grtcairoGetCursorPos(mw,p)83 grtcairoGetCursorPos (mw, p)
84     MagWindow *mw;	/* window for which result is given */
85     Point *p;		/* point to be filled in with screen coordinates */
86 {
87     int x, y, x1, y1;
88     unsigned int buttons;
89     Window win1, win2;
90 
91     if (mw == (MagWindow *)NULL) mw = tcairoCurrent.mw;
92 
93     XQueryPointer(grXdpy, Tk_WindowId((Tk_Window)(mw->w_grdata)),
94 		  &win1, &win2, &x1, &y1,
95 		  &x, &y, &buttons);
96 
97     p->p_x = x;
98     p->p_y = grXtransY(mw, y);
99 
100     return TRUE;
101 }
102 
103 /*
104  * ----------------------------------------------------------------------------
105  * grtcairoGetCursorRootPos:
106  * 	Read the cursor position in sreen root coordinates.
107  *
108  * Results:
109  *	TRUE is returned if the coordinates were succesfully read, FALSE
110  *	otherwise.
111  *
112  * Side effects:
113  *	The parameter is filled in with the cursor position, in the form of
114  *	a point in screen coordinates.
115  * ----------------------------------------------------------------------------
116  */
117 
118 bool
grtcairoGetCursorRootPos(mw,p)119 grtcairoGetCursorRootPos (mw, p)
120     MagWindow *mw;	/* window for which result is given */
121     Point *p;		/* point to be filled in with screen coordinates */
122 {
123     int x, y, x1, y1;
124     unsigned int buttons;
125     Window win1, win2;
126 
127     if (mw == (MagWindow *)NULL) mw = tcairoCurrent.mw;
128 
129     XQueryPointer(grXdpy, Tk_WindowId((Tk_Window)(mw->w_grdata)),
130 		  &win1, &win2, &x1, &y1,
131 		  &x, &y, &buttons);
132 
133     p->p_x = x1;
134     p->p_y = y1;
135 
136     return TRUE;
137 }
138