scx/c/xlib/event.c

88 lines
2.3 KiB
C

/* Copyright 2001-2003 by Norbert Freudemann, David Frese */
#include "xlib.h"
#define scx_extract_queued_mode(x) S48_EXTRACT_ENUM(x, "scx-queued-mode")
s48_value scx_Events_Queued(s48_value display, s48_value mode) {
int r = XEventsQueued(scx_extract_display(display),
scx_extract_queued_mode(mode));
return s48_enter_integer(r);
}
s48_value scx_Events_Pending(s48_value display) {
return s48_enter_integer(XPending(scx_extract_display(display)));
}
s48_value scx_Next_Event(s48_value display) {
XEvent e;
XNextEvent(scx_extract_display(display), &e);
return scx_enter_event(&e);
}
s48_value scx_Peek_Event(s48_value display) {
XEvent e;
XPeekEvent(scx_extract_display(display), &e);
return scx_enter_event(&e);
}
s48_value scx_Get_Motion_Events(s48_value display, s48_value window,
s48_value from, s48_value to) {
int n,i;
XTimeCoord *p = XGetMotionEvents(scx_extract_display(display),
scx_extract_window(window),
scx_extract_time(from),
scx_extract_time(to),
&n);
s48_value l = S48_NULL, t = S48_FALSE;
S48_DECLARE_GC_PROTECT(2);
S48_GC_PROTECT_2(l, t);
for (i = n-1; i >= 0; i--) {
t = s48_cons(s48_enter_fixnum(p[i].x), s48_enter_fixnum(p[i].y));
t = s48_cons(scx_enter_time(p[i].time), t);
l = s48_cons(t, l);
}
XFree((char*)p);
S48_GC_UNPROTECT();
return l;
}
s48_value scx_Send_Event(s48_value display, s48_value window,
s48_value propagate,
s48_value event_mask, s48_value event) {
XEvent e;
Status r;
scx_extract_event(event, &e);
r = XSendEvent(scx_extract_display(display),
scx_extract_window(window),
S48_EXTRACT_BOOLEAN(propagate),
scx_extract_event_mask(event_mask),
&e);
return r ? S48_TRUE : S48_FALSE;
}
s48_value scx_add_pending_channel(channel) {
int socket_fd;
S48_CHECK_CHANNEL(channel);
socket_fd = S48_UNSAFE_EXTRACT_FIXNUM(S48_UNSAFE_CHANNEL_OS_INDEX(channel));
if (! s48_add_pending_fd(socket_fd, 1)) /* 1 for: yes, is input */
s48_raise_out_of_memory_error();
return S48_UNSPECIFIC;
}
void scx_init_event(void) {
S48_EXPORT_FUNCTION(scx_Events_Queued);
S48_EXPORT_FUNCTION(scx_Events_Pending);
S48_EXPORT_FUNCTION(scx_Next_Event);
S48_EXPORT_FUNCTION(scx_Peek_Event);
S48_EXPORT_FUNCTION(scx_Get_Motion_Events);
S48_EXPORT_FUNCTION(scx_Send_Event);
S48_EXPORT_FUNCTION(scx_add_pending_channel);
}