Pastey mouse.e
- Posted by jimcbrown
(admin)
Dec 01, 2014
-- (c) Copyright 2014 - See License.txt
--
-- Mouse Routines
-- Linux - you need GPM server to be running
-- WIN32 - not implemented yet for the text console
include misc.e
include std/dll.e
include std/machine.e
-- Mouse Events:
global integer MOVE, LEFT_DOWN, LEFT_UP, RIGHT_DOWN, RIGHT_UP,
MIDDLE_DOWN, MIDDLE_UP, ANY_UP
if platform() = LINUX then
MOVE = 0
LEFT_DOWN = 4
LEFT_UP = 4
RIGHT_DOWN = 1
RIGHT_UP = 1
MIDDLE_DOWN = 2
MIDDLE_UP = 2
ANY_UP = 35 -- LEFT, RIGHT or MIDDLE up (best you can do under xterm)
else
MOVE = 1
LEFT_DOWN = 2
LEFT_UP = 4
RIGHT_DOWN = 8
RIGHT_UP = 16
MIDDLE_DOWN = 32
MIDDLE_UP = 64
end if
constant
MLIB = dll:open_dll({ "mouse.so" }),
M_GET_MOUSE = dll:define_c_func(MLIB, "GetMouse", {dll:C_POINTER}, dll:C_INT)
global function get_mouse()
-- report mouse events,
-- returns -1 if no mouse event,
-- otherwise returns {event#, x-coord, y-coord}
object ret
atom array
sequence result
array = allocate(4*3)
ret = c_func(M_GET_MOUSE, {array})
if (ret != -1) then
result = {0,0,0}
result[1] = peek4s(array)
result[2] = peek4s(array+4)
result[3] = peek4s(array+8)
ret = result
end if
free(array)
return ret
end function
global procedure mouse_events(integer events)
-- select the mouse events to be reported by get_mouse()
-- e.g. mouse_events(LEFT_UP + LEFT_DOWN + RIGHT_DOWN)
events = events
end procedure
global procedure mouse_pointer(integer show_it)
-- show (1) or hide (0) the mouse pointer
show_it = show_it
end procedure