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