OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [libgui/] [src/] [tkWarpPointer.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
 
2
/* -----------------------------------------------------------------------------
3
* NAME:
4
*               WarpPointer
5
*
6
* SYNOPSIS:     int WarpPointer (clientData, interp, objc, objv)
7
*               Implements tcl function:
8
*               warp_pointer win x y
9
*
10
* DESC:
11
*               Forces the pointer to a specific location.  There is probably
12
*               no good reason to use this except in the testsuite!
13
*
14
* ARGS:
15
*               win (objv[1]) - tk window name that coordinates are relative to.
16
*                               Use "." for absolute coordinates
17
*
18
*               x (obvj[2])   - X coordinate
19
*               y (objv[3])   - Y coordinate
20
* RETURNS:
21
*
22
*
23
* NOTES:
24
*
25
*
26
* ---------------------------------------------------------------------------*/
27
#include "tk.h"
28
#ifdef _WIN32
29
#include <windows.h>
30
#include <winuser.h>
31
#endif
32
 
33
int
34
WarpPointer (clientData, interp, objc, objv)
35
    ClientData clientData;
36
    Tcl_Interp *interp;
37
    int objc;
38
    Tcl_Obj *CONST objv[];
39
{
40
    Tk_Window tkwin;
41
    int x, y;
42
    char *str;
43
 
44
    if (objc != 4) {
45
      Tcl_WrongNumArgs(interp, 1, objv, "widgetId x y");
46
      return TCL_ERROR;
47
    }
48
 
49
    if ((Tcl_GetIntFromObj (interp, objv[2], &x) == TCL_ERROR) ||
50
        (Tcl_GetIntFromObj (interp, objv[3], &y) == TCL_ERROR))
51
      return TCL_ERROR;
52
 
53
    tkwin = Tk_NameToWindow(interp, Tcl_GetStringFromObj(objv[1], NULL), \
54
                         Tk_MainWindow (interp));
55
    if (tkwin == NULL)
56
      return TCL_ERROR;
57
 
58
    {
59
#ifdef _WIN32
60
      int wx, wy;
61
      Tk_GetRootCoords (tkwin, &wx, &wy);
62
      SetCursorPos (wx + x, wy + y);
63
#else
64
      Window win = Tk_WindowId(tkwin);
65
      XWarpPointer(Tk_Display(tkwin), None, win, 0, 0, 0, 0, x, y);
66
#endif
67
    }
68
 
69
    return TCL_OK;
70
}
71
 
72
int
73
cyg_create_warp_pointer_command (Tcl_Interp *interp)
74
{
75
  if (!Tcl_CreateObjCommand (interp, "warp_pointer", WarpPointer, NULL, NULL))
76
    return TCL_ERROR;
77
  return TCL_OK;
78
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.