Created
November 13, 2010 05:31
-
-
Save erik/675109 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* window.c | |
* | |
* by YOSHIDA Kazuhiro (moriq.kazuhiro@nifty.ne.jp) | |
*/ | |
#include "ruby.h" | |
#include "init.h" | |
#include <locale.h> | |
#include <X11/keysym.h> | |
#ifdef HAVE_X11_EXTENSIONS_SHAPE_H | |
#include <X11/extensions/shape.h> | |
#endif | |
#include "display.h" | |
#include "window.h" | |
#include "event.h" | |
#include "gc.h" | |
#include "point.h" | |
#include "rect.h" | |
#include "im.h" | |
#include "cursor.h" | |
#include "icon.h" | |
#include "image.h" | |
#include "time_coord.h" | |
#include "debug.h" | |
DefIntern(exposed) | |
void | |
xlib_no_window() | |
{ | |
rb_raise(rb_eRuntimeError, "already closed window"); | |
} | |
static void | |
xlib_free_window(winp) | |
t_window *winp; | |
{ | |
Debug("xlib free window begin"); | |
if (winp->ic) { | |
Debug("ic exist"); | |
xlib_free_ic(winp->ic); | |
winp->ic = 0; | |
} | |
if (winp->xwindow) { | |
if (winp->xparent) | |
XDestroyWindow(winp->xdisplay, winp->xwindow); | |
else | |
XFreePixmap(winp->xdisplay, winp->xwindow); | |
winp->xwindow = 0; | |
} | |
winp->next->prev = winp->prev; | |
winp->prev->next = winp->next; | |
free(winp); | |
Debug("xlib free window end"); | |
} | |
static VALUE | |
xlib_window_close(self) | |
VALUE self; | |
{ | |
t_window *winp; | |
Debug("xlib window close begin"); | |
GetWindow(self, winp); | |
if (winp->xparent) | |
XDestroyWindow(winp->xdisplay, winp->xwindow); | |
else | |
XFreePixmap(winp->xdisplay, winp->xwindow); | |
winp->xwindow = 0; | |
rb_ary_delete(rb_iv_get(rb_iv_get(self, "@display"), "@windows"), self); | |
Debug("xlib window close end"); | |
return Qnil; | |
} | |
static VALUE | |
xlib_window_create(argc, argv, self, parent) | |
int argc; | |
VALUE *argv, self, parent; | |
{ | |
t_display *disp; | |
t_window *parp = NULL; /* parent window */ | |
t_window *winp; | |
Display *xdisplay; | |
Window xwindow, xparent; | |
int screen; | |
Visual *xvisual; | |
XSetWindowAttributes attr; | |
unsigned long mask; | |
/* | |
unsigned long xbgpixel; | |
*/ | |
int x, y, width, height, depth; | |
VALUE obj, ary, display, resizable; | |
GetWindow(parent, parp); | |
xlib_scan_args_rect_size(argc, argv, x, y, width, height); | |
display = rb_iv_get(parent, "@display"); | |
GetDisplay(display, disp); | |
xdisplay = disp->xdisplay; | |
screen = DefaultScreen(xdisplay); | |
xparent = parp->xwindow; | |
/* | |
if (argc && RTEST(*argv)) { | |
xbgpixel = NUM2INT(*argv); | |
} else { | |
xbgpixel = BlackPixel(xdisplay, screen); | |
} | |
if (argc && --argc) ++argv; | |
*/ | |
attr.backing_store = WhenMapped; | |
attr.event_mask = events; | |
mask = CWBackingStore | CWEventMask; | |
if (argc && RTEST(*argv)) { | |
mask |= CWOverrideRedirect; | |
attr.override_redirect = True; | |
} | |
if (argc && --argc) ++argv; | |
if (argc) { | |
resizable = RTEST(*argv); | |
if (--argc) ++argv; | |
} else { | |
resizable = 0; | |
} | |
if (argc && RTEST(*argv)) { | |
t_visual *visp; | |
Data_Get_Struct(*argv, t_visual, visp); | |
depth = visp->depth; | |
xvisual = visp->visual; | |
} else { | |
depth = DefaultDepth(xdisplay, screen); | |
xvisual = CopyFromParent; | |
} | |
if (argc && --argc) ++argv; | |
xlib_raise_if_argc_rest(argc); | |
xwindow = XCreateWindow(xdisplay, xparent, | |
x, y, width, height, | |
1, depth, InputOutput, xvisual, | |
mask, &attr); | |
/* | |
XSetWindowBackground(xdisplay, xwindow, xbgpixel); | |
*/ | |
obj = Data_Make_Struct(self, t_window, 0, xlib_free_window, winp); | |
winp->prev = disp->window_list_head; | |
winp->next = disp->window_list_head->next; | |
disp->window_list_head->next->prev = winp; | |
disp->window_list_head->next = winp; | |
winp->xdisplay = xdisplay; | |
winp->xparent = xparent; | |
winp->xwindow = xwindow; | |
winp->ic = 0; | |
rb_iv_set(obj, "@display", display); | |
rb_iv_set(obj, "@parent", parent); | |
rb_iv_set(obj, "@shown", Qfalse); | |
rb_iv_set(obj, "@events", rb_hash_new()); | |
ary = rb_iv_get(display, "@windows"); | |
rb_ary_push(ary, obj); | |
if (!resizable) { | |
XSizeHints hint; | |
hint.flags = PPosition | PMinSize | PMaxSize; | |
hint.min_width = hint.max_width = width ; | |
hint.min_height = hint.max_height = height; | |
XSetWMNormalHints(xdisplay, xwindow, &hint); | |
} | |
XSetWMProtocols(xdisplay, xwindow, &(disp->proto), 1); | |
return obj; | |
} | |
static VALUE | |
xlib_window_new(argc, argv, self) | |
int argc; | |
VALUE *argv, self; | |
{ | |
VALUE parent; | |
int argc_orig; | |
VALUE *argv_orig; | |
VALUE obj; | |
argc_orig = argc; | |
argv_orig = argv; | |
xlib_raise_if_argc_none(argc, "need Window"); | |
parent = *argv; | |
if (--argc) ++argv; | |
obj = xlib_window_create(argc, argv, self, parent); | |
rb_funcall2(obj, id_init, 0, NULL); | |
return obj; | |
} | |
static VALUE | |
xlib_window_show(self) | |
VALUE self; | |
{ | |
t_window *winp; | |
VALUE shown; | |
XEvent ev; | |
shown = rb_iv_get(self, "@shown"); | |
if (shown == Qtrue) return Qnil; | |
rb_iv_set(self, "@shown", Qtrue); | |
GetWindow(self, winp); | |
XMapWindow(winp->xdisplay, winp->xwindow); | |
do XNextEvent(winp->xdisplay, &ev); while (ev.type != Expose); | |
{ | |
ID id; | |
VALUE args; | |
id = id_exposed; | |
args = rb_ary_new3( 1, xlib_expose_event_setup(self, (XExposeEvent *)&ev) ); | |
xlib_event(self, id_exposed, args); | |
} | |
return Qnil; | |
} | |
static VALUE | |
xlib_window_hide(self) | |
VALUE self; | |
{ | |
t_window *winp; | |
VALUE shown; | |
shown = rb_iv_get(self, "@shown"); | |
if (shown == Qfalse) return Qnil; | |
rb_iv_set(self, "@shown", Qfalse); | |
GetWindow(self, winp); | |
XUnmapWindow(winp->xdisplay, winp->xwindow); | |
return Qnil; | |
} | |
static VALUE | |
xlib_window_is_shown(self) | |
VALUE self; | |
{ | |
return rb_iv_get(self, "@shown"); | |
} | |
static VALUE | |
xlib_window_clear(self) | |
VALUE self; | |
{ | |
t_window *winp; | |
GetWindow(self, winp); | |
XClearWindow(winp->xdisplay, winp->xwindow); | |
return Qnil; | |
} | |
static VALUE | |
xlib_window_raise(self) | |
VALUE self; | |
{ | |
t_window *winp; | |
GetWindow(self, winp); | |
XRaiseWindow(winp->xdisplay, winp->xwindow); | |
return Qnil; | |
} | |
static VALUE | |
xlib_window_lower(self) | |
VALUE self; | |
{ | |
t_window *winp; | |
GetWindow(self, winp); | |
XLowerWindow(winp->xdisplay, winp->xwindow); | |
return Qnil; | |
} | |
static VALUE | |
xlib_window_clear_area(argc, argv, self) | |
int argc; | |
VALUE *argv; | |
VALUE self; | |
{ | |
t_window *winp; | |
int x, y, width, height; | |
GetWindow(self, winp); | |
xlib_scan_args_rect(argc, argv, x, y, width, height); | |
xlib_raise_if_argc_rest(argc); | |
XClearArea(winp->xdisplay, winp->xwindow, | |
NUM2INT(x), | |
NUM2INT(y), | |
NUM2INT(width), | |
NUM2INT(height), | |
False); | |
return Qnil; | |
} | |
static VALUE | |
xlib_window_copy_area(argc, argv, self) | |
int argc; | |
VALUE *argv; | |
VALUE self; | |
{ | |
t_window *winp; | |
t_window *dstp; /* destination window */ | |
t_gc *gcp; | |
int x, y, width, height; | |
int posx, posy; | |
Window win_root; | |
Window dst_root; | |
unsigned int win_x, win_y, win_width, win_height, win_border_width, win_depth; | |
unsigned int dst_x, dst_y, dst_width, dst_height, dst_border_width, dst_depth; | |
GetWindow(self, winp); | |
xlib_raise_if_argc_none(argc, "need Window"); | |
GetWindow(*argv, dstp); | |
if (--argc) ++argv; | |
xlib_raise_if_argc_none(argc, "need GraphicContext"); | |
GetGC(*argv, gcp); | |
if (--argc) ++argv; | |
xlib_scan_args_rect_size(argc, argv, x, y, width, height); | |
xlib_scan_args_point_nil(argc, argv, posx, posy); | |
xlib_raise_if_argc_rest(argc); | |
XGetGeometry(winp->xdisplay, winp->xwindow, &win_root, &win_x, &win_y, &win_width, &win_height, &win_border_width, &win_depth); | |
XGetGeometry(dstp->xdisplay, dstp->xwindow, &dst_root, &dst_x, &dst_y, &dst_width, &dst_height, &dst_border_width, &dst_depth); | |
if (win_root != dst_root ) { | |
rb_raise(rb_eRuntimeError, "the drawables must have the same root"); | |
} | |
if (win_depth != dst_depth) { | |
rb_raise(rb_eRuntimeError, "the drawables must have the same depth"); | |
} | |
XCopyArea(winp->xdisplay, winp->xwindow, dstp->xwindow, gcp->xgc, | |
x, y, width, height, | |
posx, posy); | |
return Qnil; | |
} | |
static VALUE | |
xlib_window_set_title(self, title_obj) | |
VALUE self, title_obj; | |
{ | |
t_window *winp; | |
char *title = STR2CSTR(title_obj); | |
GetWindow(self, winp); | |
/* | |
XStoreName(winp->xdisplay, winp->xwindow, title); | |
*/ | |
XmbSetWMProperties(winp->xdisplay, winp->xwindow, | |
title, title, NULL, 0, NULL, NULL, NULL); | |
return Qnil; | |
} | |
static VALUE | |
xlib_window_set_pixel(self, pixel) | |
VALUE self, pixel; | |
{ | |
t_window *winp; | |
GetWindow(self, winp); | |
XSetWindowBackground(winp->xdisplay, winp->xwindow, NUM2INT(pixel)); | |
return Qnil; | |
} | |
static VALUE | |
xlib_window_set_pixmap(self, pmap) | |
VALUE self, pmap; | |
{ | |
t_window *winp; | |
t_window *pixp; | |
GetWindow(self, winp); | |
GetWindow(pmap, pixp); | |
XSetWindowBackgroundPixmap(winp->xdisplay, winp->xwindow, pixp->xwindow); | |
return Qnil; | |
} | |
static VALUE | |
xlib_window_set_border_pixel(self, pixel) | |
VALUE self, pixel; | |
{ | |
t_window *winp; | |
GetWindow(self, winp); | |
XSetWindowBorder(winp->xdisplay, winp->xwindow, NUM2INT(pixel)); | |
return Qnil; | |
} | |
static VALUE | |
xlib_window_set_border_pixmap(self, pmap) | |
VALUE self, pmap; | |
{ | |
t_window *winp; | |
t_window *pixp; | |
GetWindow(self, winp); | |
GetWindow(pmap, pixp); | |
XSetWindowBorderPixmap(winp->xdisplay, winp->xwindow, pixp->xwindow); | |
return Qnil; | |
} | |
#define xlib_window_get_geometry(geom) \ | |
static VALUE \ | |
xlib_window_get_##geom(self) \ | |
VALUE self; \ | |
{ \ | |
t_window *winp; \ | |
Window root; \ | |
unsigned int x, y, width, height, border_width, depth; \ | |
\ | |
GetWindow(self, winp); \ | |
XGetGeometry(winp->xdisplay, winp->xwindow, \ | |
&root, &x, &y, &width, &height, &border_width, &depth); \ | |
\ | |
return INT2NUM(geom); \ | |
} | |
xlib_window_get_geometry(x) | |
xlib_window_get_geometry(y) | |
xlib_window_get_geometry(width) | |
xlib_window_get_geometry(height) | |
xlib_window_get_geometry(border_width) | |
xlib_window_get_geometry(depth) | |
#define xlib_window_configure(geom, mask) \ | |
static VALUE \ | |
xlib_window_set_##geom(self, num) \ | |
VALUE self, num; \ | |
{ \ | |
t_window *winp; \ | |
XWindowChanges attr; \ | |
\ | |
GetWindow(self, winp); \ | |
attr.geom = NUM2INT(num); \ | |
XConfigureWindow(winp->xdisplay, winp->xwindow, mask, &attr); \ | |
\ | |
return num; \ | |
} | |
xlib_window_configure(x, CWX) | |
xlib_window_configure(y, CWY) | |
xlib_window_configure(width, CWWidth) | |
xlib_window_configure(height, CWHeight) | |
xlib_window_configure(border_width, CWBorderWidth) | |
static VALUE | |
xlib_window_get_rect(self) | |
VALUE self; | |
{ | |
t_window *winp; | |
Window root; | |
unsigned int x, y, width, height, border_width, depth; | |
GetWindow(self, winp); | |
XGetGeometry(winp->xdisplay, winp->xwindow, | |
&root, &x, &y, &width, &height, &border_width, &depth); | |
return rb_funcall(cXlib_rect, rb_intern("new"), 4, | |
INT2NUM(x), | |
INT2NUM(y), | |
INT2NUM(width), | |
INT2NUM(height) ); | |
} | |
static VALUE | |
xlib_window_set_rect(self, area) | |
VALUE self, area; | |
{ | |
t_window *winp; | |
t_rect *rect; | |
GetWindow(self, winp); | |
Data_Get_Struct(area, t_rect, rect); | |
XMoveResizeWindow(winp->xdisplay, winp->xwindow, | |
rect->x, rect->y, rect->width, rect->height); | |
return Qnil; | |
} | |
static VALUE | |
xlib_window_new_window(argc, argv, self) | |
int argc; | |
VALUE *argv; | |
VALUE self; | |
{ | |
return xlib_window_create(argc, argv, cXlib_window, self); | |
} | |
static VALUE | |
xlib_window_event(argc, argv, self) | |
int argc; | |
VALUE *argv; | |
VALUE self; | |
{ | |
VALUE name, proc, hash, ary, key; | |
switch (rb_scan_args(argc, argv, "11", &name, &proc)) { | |
case 1: | |
case 2: | |
proc = rb_f_lambda(); | |
break; | |
default: | |
rb_raise(rb_eArgError, "wrong # of arguments"); | |
} | |
hash = rb_iv_get(self, "@events"); | |
key = INT2FIX(rb_intern(STR2CSTR(name))); | |
ary = rb_hash_aref(hash, key); | |
if (ary == Qnil) { | |
ary = rb_ary_new(); | |
rb_hash_aset(hash, key, ary); | |
} | |
rb_ary_push(ary, proc); | |
return Qnil; | |
} | |
VALUE | |
xlib_pixmap_setup(window, xpixmap, hotx, hoty) | |
VALUE window; | |
Pixmap xpixmap; | |
int hotx, hoty; | |
{ | |
t_display *disp; | |
t_window *pixp; | |
VALUE obj, display, hotspot; | |
display = rb_iv_get(window, "@display"); | |
hotspot = rb_funcall(cXlib_point, rb_intern("new"), 2, hotx, hoty); | |
GetDisplay(display, disp); | |
obj = Data_Make_Struct(cXlib_pixmap, t_window, 0, xlib_free_window, pixp); | |
pixp->prev = disp->window_list_head; | |
pixp->next = disp->window_list_head->next; | |
disp->window_list_head->next->prev = pixp; | |
disp->window_list_head->next = pixp; | |
pixp->xdisplay = disp->xdisplay; | |
pixp->xparent = 0; | |
pixp->xwindow = xpixmap; | |
pixp->ic = 0; | |
rb_iv_set(obj, "@display", display); | |
rb_iv_set(obj, "@hotspot", hotspot); | |
return obj; | |
} | |
static VALUE | |
xlib_window_read_xbm(self, filename) | |
VALUE self, filename; | |
{ | |
t_window *winp; | |
Pixmap xpixmap; | |
unsigned int win_width, win_height; | |
int hotx, hoty; | |
Check_Type(filename, T_STRING); | |
GetWindow(self, winp); | |
if ( XReadBitmapFile(winp->xdisplay, winp->xwindow, | |
RSTRING(filename)->ptr, &win_width, &win_height, | |
&xpixmap, &hotx, &hoty) != BitmapSuccess ) { | |
rb_raise(rb_eIOError, "fail to open xbm file"); | |
} | |
return xlib_pixmap_setup(self, xpixmap, hotx, hoty); | |
} | |
#ifdef HAVE_X11_EXTENSIONS_SHAPE_H | |
static VALUE | |
xlib_window_combine_mask(self, mask) | |
VALUE self, mask; | |
{ | |
t_display *disp; | |
t_window *winp; | |
t_window *pixp; | |
VALUE display; | |
display = rb_iv_get(self, "@display"); | |
GetDisplay(display, disp); | |
GetWindow(self, winp); | |
GetWindow(mask, pixp); | |
XShapeCombineMask(disp->xdisplay, winp->xwindow, | |
ShapeBounding, 0, 0, pixp->xwindow, ShapeSet); | |
return mask; | |
} | |
#endif | |
static VALUE | |
xlib_window_set_cursor(self, cursor) | |
VALUE self, cursor; | |
{ | |
t_window *winp; | |
t_cursor *curp; | |
GetWindow(self, winp); | |
Data_Get_Struct(cursor, t_cursor, curp); | |
XDefineCursor(winp->xdisplay, winp->xwindow, curp->xcursor); | |
return cursor; | |
} | |
static VALUE | |
xlib_window_set_icon(self, icon) | |
VALUE self, icon; | |
{ | |
t_window *winp; | |
t_window *_pmap; | |
t_window *_mask; | |
char *_name; | |
GetWindow(self, winp); | |
GetWindow(rb_iv_get(icon, "pixmap"), _pmap); | |
GetWindow(rb_iv_get(icon, "mask"), _mask); | |
_name = STR2CSTR(rb_iv_get(icon, "name")); | |
{ | |
XWMHints hint; | |
hint.flags = IconPixmapHint | IconMaskHint; | |
hint.icon_pixmap = _pmap->xwindow; | |
hint.icon_mask = _mask->xwindow; | |
XSetWMHints(winp->xdisplay, winp->xwindow, &hint); | |
} | |
XSetIconName(winp->xdisplay, winp->xwindow, _name); | |
return icon; | |
} | |
static VALUE | |
xlib_window_get_image(argc, argv, self) | |
int argc; | |
VALUE *argv; | |
VALUE self; | |
{ | |
t_window *winp; | |
int x, y, width, height; | |
XImage *image; | |
VALUE obj; | |
GetWindow(self, winp); | |
xlib_scan_args_rect_size(argc, argv, x, y, width, height); | |
xlib_raise_if_argc_rest(argc); | |
image = XGetImage(winp->xdisplay, winp->xwindow, | |
x, y, width, height, | |
AllPlanes, ZPixmap); | |
obj = Data_Wrap_Struct(cXlib_image, 0, xlib_image_free, image); | |
return obj; | |
} | |
static VALUE | |
xlib_window_put_image(argc, argv, self) | |
int argc; | |
VALUE *argv; | |
VALUE self; | |
{ | |
t_window *winp; | |
XImage *image; | |
t_gc *gcp; | |
int x, y, width, height; | |
int posx, posy; | |
GetWindow(self, winp); | |
xlib_raise_if_argc_none(argc, "need Image"); | |
Data_Get_Struct(*argv, XImage, image); | |
if (--argc) ++argv; | |
xlib_raise_if_argc_none(argc, "need GraphicContext"); | |
GetGC(*argv, gcp); | |
if (--argc) ++argv; | |
xlib_scan_args_rect_size(argc, argv, x, y, width, height); | |
xlib_scan_args_point_nil(argc, argv, posx, posy); | |
xlib_raise_if_argc_rest(argc); | |
XPutImage(winp->xdisplay, winp->xwindow, gcp->xgc, | |
image, x, y, posx, posy, width, height); | |
return Qnil; | |
} | |
static VALUE | |
xlib_window_get_motion_events(self, start, stop) | |
VALUE self, start, stop; | |
{ | |
t_window *winp; | |
int num; | |
XTimeCoord *timecoord; | |
VALUE ary; | |
GetWindow(self, winp); | |
timecoord = XGetMotionEvents(winp->xdisplay, winp->xwindow, | |
NUM2INT(start), NUM2INT(stop), &num); | |
ary = rb_ary_new(); | |
if (timecoord) { | |
int i; | |
for (i=0; i<num; i++) { | |
rb_ary_push(ary, | |
xlib_time_coord_setup(&timecoord[i]) ); | |
} | |
XFree(timecoord); | |
} | |
return ary; | |
} | |
VALUE | |
xlib_pixmap_create(argc, argv, self, window) | |
int argc; | |
VALUE *argv, self, window; | |
{ | |
t_window *winp; | |
Display *xdisplay; | |
Window xwindow; | |
Pixmap xpixmap; | |
int screen, depth; | |
XWindowAttributes attr; | |
unsigned int width, height; | |
int hotx, hoty; | |
VALUE obj; | |
GetWindow(window, winp); | |
xdisplay = winp->xdisplay; | |
xwindow = winp->xwindow; | |
XGetWindowAttributes(xdisplay, xwindow, &attr); | |
xlib_scan_args_num_nil(argc, argv, width , attr.width ); | |
xlib_scan_args_num_nil(argc, argv, height, attr.height); | |
xlib_scan_args_num_nil(argc, argv, hotx, -1); | |
xlib_scan_args_num_nil(argc, argv, hoty, -1); | |
xlib_raise_if_argc_rest(argc); | |
screen = DefaultScreen(xdisplay); | |
depth = DefaultDepth(xdisplay, screen); | |
xpixmap = XCreatePixmap(xdisplay, xwindow, width, height, depth); | |
obj = xlib_pixmap_setup(window, xpixmap, hotx, hoty); | |
return obj; | |
} | |
static VALUE | |
xlib_pixmap_new(argc, argv, self) | |
int argc; | |
VALUE *argv, self; | |
{ | |
VALUE window; | |
int argc_orig; | |
VALUE *argv_orig; | |
VALUE obj; | |
argc_orig = argc; | |
argv_orig = argv; | |
xlib_raise_if_argc_none(argc, "need Window"); | |
window = *argv; | |
if (--argc) ++argv; | |
obj = xlib_pixmap_create(argc, argv, self, window); | |
rb_funcall2(obj, id_init, 0, NULL); | |
return obj; | |
} | |
static VALUE | |
xlib_window_new_pixmap(argc, argv, self) | |
int argc; | |
VALUE *argv; | |
VALUE self; | |
{ | |
return xlib_pixmap_create(argc, argv, cXlib_pixmap, self); | |
} | |
static VALUE | |
xlib_pixmap_write_xbm(self, filename) | |
VALUE self, filename; | |
{ | |
t_window *pixp; | |
Window root; | |
unsigned int x, y, width, height, border_width, depth; | |
VALUE hotspot; | |
t_point *hotp; | |
Check_Type(filename, T_STRING); | |
GetWindow(self, pixp); | |
hotspot = rb_iv_get(self, "hotspot"); | |
Data_Get_Struct(hotspot, t_point, hotp); | |
XGetGeometry(pixp->xdisplay, pixp->xwindow, &root, &x, &y, &width, &height, &border_width, &depth); | |
if ( XWriteBitmapFile(pixp->xdisplay, RSTRING(filename)->ptr, | |
pixp->xwindow, | |
width, height, | |
hotp->x, hotp->y) != BitmapSuccess ) { | |
rb_raise(rb_eIOError, "fail to open xpm file"); | |
} | |
return Qnil; | |
} | |
#define DefineEventDummy(name) rb_define_method(cXlib_window, #name, xlib_event_dummy, -2); | |
void | |
xlib_init_window() | |
{ | |
cXlib_window = rb_define_class_under(mXlib, "Window", rb_cObject); | |
DefineSingletonMethod(window, new, -1) | |
DefineMethod(window, close, 0) | |
DefineMethod(window, show, 0) | |
DefineMethod(window, hide, 0) | |
DefineMethod(window, clear, 0) | |
DefineMethod(window, raise, 0) | |
DefineMethod(window, lower, 0) | |
DefineMethod(window, clear_area, -1) | |
DefineMethod(window, copy_area, -1) | |
DefineMethod(window, new_window, -1) | |
DefineMethod(window, new_pixmap, -1) | |
rb_define_attr(cXlib_window, "display", 1, 0); | |
rb_define_attr(cXlib_window, "parent", 1, 0); | |
rb_define_attr(cXlib_window, "events", 1, 0); | |
DefineMethodIs(window, shown) | |
DefineMethodSet(window, title) | |
DefineMethodSet(window, pixel) | |
DefineMethodSet(window, pixmap) | |
DefineMethodSet(window, border_pixel) | |
DefineMethodSet(window, border_pixmap) | |
DefineMethodGet(window, x) | |
DefineMethodSet(window, x) | |
DefineMethodGet(window, y) | |
DefineMethodSet(window, y) | |
DefineMethodGet(window, width) | |
DefineMethodSet(window, width) | |
DefineMethodGet(window, height) | |
DefineMethodSet(window, height) | |
DefineMethodGet(window, border_width) | |
DefineMethodSet(window, border_width) | |
DefineMethodGet(window, rect) | |
DefineMethodSet(window, rect) | |
DefineMethodGet(window, depth) | |
DefineMethod(window, event, -1) | |
DefineEventDummy(delete) | |
DefineEventDummy(exposed) | |
DefineEventDummy(button_press) | |
DefineEventDummy(button_release) | |
DefineEventDummy(enter_notify) | |
DefineEventDummy(leave_notify) | |
DefineEventDummy(key_press) | |
DefineEventDummy(key_release) | |
DefineEventDummy(motion_notify) | |
DefineEventDummy(configure) | |
DefineMethod(window, read_xbm, 1) | |
#ifdef HAVE_X11_EXTENSIONS_SHAPE_H | |
DefineMethod(window, combine_mask, 1) | |
#endif | |
DefineMethodSet(window, cursor) | |
DefineMethodSet(window, icon) | |
DefineMethod(window, get_image, -1) | |
DefineMethod(window, put_image, -1) | |
DefineMethod(window, get_motion_events, 2) | |
} | |
void | |
xlib_init_pixmap() | |
{ | |
SetIntern(exposed) | |
cXlib_pixmap = rb_define_class_under(mXlib, "Pixmap", rb_cObject); | |
DefineSingletonMethod(pixmap, new, -1) | |
rb_define_method(cXlib_pixmap, "close", xlib_window_close, 0); | |
rb_define_method(cXlib_pixmap, "copy_area", xlib_window_copy_area, -1); | |
rb_define_method(cXlib_pixmap, "get_image", xlib_window_get_image, -1); | |
rb_define_method(cXlib_pixmap, "put_image", xlib_window_put_image, -1); | |
rb_define_attr(cXlib_pixmap, "display", 1, 0); | |
rb_define_attr(cXlib_pixmap, "hotspot", 1, 1); | |
rb_define_method(cXlib_pixmap, "width", xlib_window_get_width, 0); | |
rb_define_method(cXlib_pixmap, "height", xlib_window_get_height, 0); | |
rb_define_method(cXlib_pixmap, "rect", xlib_window_get_rect, 0); | |
DefineMethod(pixmap, write_xbm, 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment