uh 2.0.0.pre2 → 2.0.0.pre3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/uh/event.c DELETED
@@ -1,168 +0,0 @@
1
- #include "uh.h"
2
-
3
-
4
- #define SET_XEV(x) \
5
- XEvent *xev;\
6
- Data_Get_Struct(x, XEvent, xev);
7
-
8
-
9
- VALUE event_make_event(VALUE klass, XEvent *xev);
10
- void event_make_configure_request(VALUE self);
11
- void event_make_key_any(VALUE self);
12
- void event_make_win_any(VALUE self);
13
-
14
-
15
- VALUE event_make(XEvent *xev) {
16
- typedef struct {
17
- int type;
18
- VALUE klass;
19
- void (*function)(VALUE self);
20
- } EvClass;
21
- EvClass ev_classes[] = {
22
- {ConfigureRequest, cConfigureRequest, event_make_configure_request},
23
- {DestroyNotify, cDestroyNotify, NULL},
24
- {Expose, cExpose, NULL},
25
- {KeyPress, cKeyPress, event_make_key_any},
26
- {KeyRelease, cKeyRelease, event_make_key_any},
27
- {MapRequest, cMapRequest, NULL},
28
- {PropertyNotify, cPropertyNotify, NULL},
29
- {UnmapNotify, cUnmapNotify, NULL}
30
- };
31
- unsigned int i;
32
- VALUE event;
33
-
34
- for (i = 0; i < (sizeof ev_classes / sizeof ev_classes[0]); i++) {
35
- if (ev_classes[i].type == xev->type) {
36
- event = event_make_event(ev_classes[i].klass, xev);
37
- event_make_win_any(event);
38
- if (ev_classes[i].function)
39
- ev_classes[i].function(event);
40
-
41
- return event;
42
- }
43
- }
44
-
45
- return event_make_event(cEvent, xev);
46
- }
47
-
48
- VALUE event_make_event(VALUE klass, XEvent *xev) {
49
- const char *type_descs[LASTEvent];
50
- VALUE event;
51
-
52
- type_descs[KeyPress] = "key_press";
53
- type_descs[KeyRelease] = "key_release";
54
- type_descs[ButtonPress] = "button_press";
55
- type_descs[ButtonRelease] = "button_release";
56
- type_descs[MotionNotify] = "motion_notify";
57
- type_descs[EnterNotify] = "enter_notify";
58
- type_descs[LeaveNotify] = "leave_notify";
59
- type_descs[FocusIn] = "focus_in";
60
- type_descs[FocusOut] = "focus_out";
61
- type_descs[KeymapNotify] = "keymap_notify";
62
- type_descs[Expose] = "expose";
63
- type_descs[GraphicsExpose] = "graphics_expose";
64
- type_descs[NoExpose] = "no_expose";
65
- type_descs[VisibilityNotify] = "visibility_notify";
66
- type_descs[CreateNotify] = "create_notify";
67
- type_descs[DestroyNotify] = "destroy_notify";
68
- type_descs[UnmapNotify] = "unmap_notify";
69
- type_descs[MapNotify] = "map_notify";
70
- type_descs[MapRequest] = "map_request";
71
- type_descs[ReparentNotify] = "reparent_notify";
72
- type_descs[ConfigureNotify] = "configure_notify";
73
- type_descs[ConfigureRequest] = "configure_request";
74
- type_descs[GravityNotify] = "gravity_notify";
75
- type_descs[ResizeRequest] = "resize_request";
76
- type_descs[CirculateNotify] = "circulate_notify";
77
- type_descs[CirculateRequest] = "circulate_request";
78
- type_descs[PropertyNotify] = "property_notify";
79
- type_descs[SelectionClear] = "selection_clear";
80
- type_descs[SelectionRequest] = "selection_request";
81
- type_descs[SelectionNotify] = "selection_notify";
82
- type_descs[ColormapNotify] = "colormap_notify";
83
- type_descs[ClientMessage] = "client_message";
84
- type_descs[MappingNotify] = "mapping_notify";
85
- type_descs[GenericEvent] = "generic";
86
-
87
- event = Data_Wrap_Struct(klass, 0, 0, xev);
88
- rb_ivar_set(event, rb_intern("@type"),
89
- ID2SYM(rb_intern(type_descs[xev->type])));
90
- rb_ivar_set(event, rb_intern("@send_event"),
91
- xev->xany.send_event ? Qtrue : Qfalse);
92
-
93
- return event;
94
- }
95
-
96
- void event_make_configure_request(VALUE self) {
97
- SET_XEV(self);
98
-
99
- if (xev->xconfigurerequest.value_mask & CWX)
100
- rb_ivar_set(self, rb_intern("@x"), INT2FIX(xev->xconfigurerequest.x));
101
-
102
- if (xev->xconfigurerequest.value_mask & CWY)
103
- rb_ivar_set(self, rb_intern("@y"), INT2FIX(xev->xconfigurerequest.y));
104
-
105
- if (xev->xconfigurerequest.value_mask & CWWidth)
106
- rb_ivar_set(self, rb_intern("@width"),
107
- INT2FIX(xev->xconfigurerequest.width));
108
-
109
- if (xev->xconfigurerequest.value_mask & CWHeight)
110
- rb_ivar_set(self, rb_intern("@height"),
111
- INT2FIX(xev->xconfigurerequest.height));
112
-
113
- rb_ivar_set(self, rb_intern("@above_window_id"),
114
- LONG2NUM(xev->xconfigurerequest.above));
115
- rb_ivar_set(self, rb_intern("@detail"),
116
- INT2FIX(xev->xconfigurerequest.detail));
117
- rb_ivar_set(self, rb_intern("@value_mask"),
118
- LONG2NUM(xev->xconfigurerequest.detail));
119
- }
120
-
121
- void event_make_key_any(VALUE self) {
122
- KeySym ks;
123
- SET_XEV(self);
124
-
125
- ks = XkbKeycodeToKeysym(xev->xany.display, xev->xkey.keycode, 0, 0);
126
- if (ks == NoSymbol)
127
- return;
128
-
129
- rb_ivar_set(self, rb_intern("@key"), rb_str_new_cstr(XKeysymToString(ks)));
130
- rb_ivar_set(self, rb_intern("@modifier_mask"), INT2FIX(xev->xkey.state));
131
- }
132
-
133
- void event_make_win_any(VALUE self) {
134
- Window window;
135
- SET_XEV(self);
136
-
137
- switch (xev->type) {
138
- case ConfigureRequest:
139
- window = xev->xconfigurerequest.window;
140
- break;
141
- case DestroyNotify:
142
- window = xev->xdestroywindow.window;
143
- break;
144
- case Expose:
145
- window = xev->xexpose.window;
146
- break;
147
- case KeyPress:
148
- window = xev->xkey.window;
149
- break;
150
- case MapRequest:
151
- window = xev->xmaprequest.window;
152
- break;
153
- case PropertyNotify:
154
- window = xev->xproperty.window;
155
- break;
156
- case UnmapNotify:
157
- rb_ivar_set(self, rb_intern("@event_window"),
158
- window_make(xev->xany.display, xev->xunmap.event));
159
- window = xev->xunmap.window;
160
- break;
161
- default:
162
- window = xev->xany.window;
163
- break;
164
- }
165
-
166
- rb_ivar_set(self, rb_intern("@window"),
167
- window_make(xev->xany.display, window));
168
- }
data/ext/uh/font.c DELETED
@@ -1,14 +0,0 @@
1
- #include "uh.h"
2
-
3
-
4
- VALUE font_make(int width, int ascent, int descent) {
5
- VALUE obj;
6
- VALUE args[0];
7
-
8
- obj = rb_class_new_instance(0, args, cFont);
9
- rb_ivar_set(obj, rb_intern("@width"), INT2FIX(width));
10
- rb_ivar_set(obj, rb_intern("@ascent"), INT2FIX(ascent));
11
- rb_ivar_set(obj, rb_intern("@descent"), INT2FIX(descent));
12
-
13
- return obj;
14
- }
data/ext/uh/pixmap.c DELETED
@@ -1,92 +0,0 @@
1
- #include "uh.h"
2
-
3
-
4
- #define SET_PIXMAP(x) \
5
- UhPixmap *pixmap;\
6
- Data_Get_Struct(x, UhPixmap, pixmap);
7
-
8
- #define DPY pixmap->dpy
9
- #define PIXMAP pixmap->pixmap
10
- #define GC pixmap->gc
11
-
12
-
13
- void pixmap_deallocate(UhPixmap *p);
14
-
15
-
16
- VALUE pixmap_draw_rect(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h) {
17
- SET_PIXMAP(self)
18
-
19
- XFillRectangle(DPY, PIXMAP, GC,
20
- FIX2INT(x), FIX2INT(y), FIX2INT(w), FIX2INT(h)
21
- );
22
-
23
- return Qnil;
24
- }
25
-
26
- VALUE pixmap_draw_string(VALUE self, VALUE x, VALUE y, VALUE str) {
27
- SET_PIXMAP(self)
28
-
29
- XDrawString(DPY, PIXMAP, GC,
30
- FIX2INT(x), FIX2INT(y), RSTRING_PTR(str), RSTRING_LEN(str)
31
- );
32
-
33
- return Qnil;
34
- }
35
-
36
- VALUE pixmap_gc_black(VALUE self) {
37
- SET_PIXMAP(self)
38
-
39
- XSetForeground(DPY, GC, BlackPixel(DPY, SCREEN_DEFAULT));
40
-
41
- return Qnil;
42
- }
43
-
44
- VALUE pixmap_gc_color(VALUE self, VALUE rcolor) {
45
- SET_PIXMAP(self)
46
-
47
- XSetForeground(DPY, GC, NUM2LONG(rb_ivar_get(rcolor, rb_intern("@pixel"))));
48
-
49
- return Qnil;
50
- }
51
-
52
- VALUE pixmap_gc_white(VALUE self) {
53
- SET_PIXMAP(self)
54
-
55
- XSetForeground(DPY, GC, WhitePixel(DPY, SCREEN_DEFAULT));
56
-
57
- return Qnil;
58
- }
59
-
60
-
61
- VALUE pixmap__copy(VALUE self, VALUE rwindow_id, VALUE rwidth, VALUE rheight) {
62
- SET_PIXMAP(self)
63
-
64
- XCopyArea(DPY, PIXMAP, FIX2INT(rwindow_id), GC,
65
- 0, 0, FIX2INT(rwidth), FIX2INT(rheight), 0, 0
66
- );
67
-
68
- return Qnil;
69
- }
70
-
71
-
72
- VALUE pixmap_make(Display *display, Pixmap xpixmap, VALUE width, VALUE height) {
73
- UhPixmap *pixmap;
74
- VALUE obj;
75
-
76
- obj = Data_Make_Struct(cPixmap, UhPixmap, 0, pixmap_deallocate, pixmap);
77
- pixmap->dpy = display;
78
- pixmap->pixmap = xpixmap;
79
- pixmap->gc = XCreateGC(display, DefaultRootWindow(display), 0, NULL);
80
-
81
- rb_ivar_set(obj, rb_intern("@width"), width);
82
- rb_ivar_set(obj, rb_intern("@height"), height);
83
-
84
- return obj;
85
- }
86
-
87
-
88
- void pixmap_deallocate(UhPixmap *pixmap) {
89
- XFreePixmap(DPY, PIXMAP);
90
- XFreeGC(DPY, GC);
91
- free(pixmap);
92
- }
data/ext/uh/screen.c DELETED
@@ -1,12 +0,0 @@
1
- #include "uh.h"
2
-
3
-
4
- VALUE screen_init(VALUE self, VALUE id, VALUE x, VALUE y, VALUE w, VALUE h) {
5
- rb_ivar_set(self, rb_intern("@id"), id);
6
- rb_ivar_set(self, rb_intern("@x"), x);
7
- rb_ivar_set(self, rb_intern("@y"), y);
8
- rb_ivar_set(self, rb_intern("@width"), w);
9
- rb_ivar_set(self, rb_intern("@height"), h);
10
-
11
- return self;
12
- }
data/ext/uh/uh.c DELETED
@@ -1,143 +0,0 @@
1
- #include "uh.h"
2
-
3
-
4
- void uh_color();
5
- void uh_display();
6
- void uh_events();
7
- void uh_font();
8
- void uh_pixmap();
9
- void uh_screen();
10
- void uh_window();
11
-
12
-
13
- void Init_uh(void) {
14
- mUh = rb_define_module("Uh");
15
-
16
- eDisplayError = rb_define_class_under(
17
- mUh, "DisplayError", rb_eStandardError
18
- );
19
-
20
- uh_color();
21
- uh_display();
22
- uh_events();
23
- uh_font();
24
- uh_pixmap();
25
- uh_screen();
26
- uh_window();
27
- }
28
-
29
- void uh_color() {
30
- cColor = rb_define_class_under(mUh, "Color", rb_cObject);
31
- rb_define_attr(cColor, "pixel", 1, 0);
32
- }
33
-
34
- void uh_display() {
35
- cDisplay = rb_define_class_under(mUh, "Display", rb_cObject);
36
- rb_define_singleton_method(cDisplay, "on_error", display_s_on_error, 0);
37
- rb_define_alloc_func(cDisplay, display_alloc);
38
- rb_define_attr(cDisplay, "name", 1, 0);
39
- rb_define_method(cDisplay, "close", display_close, 0);
40
- rb_define_method(cDisplay, "color_by_name", display_color_by_name, 1);
41
- rb_define_method(cDisplay, "create_pixmap", display_create_pixmap, 2);
42
- rb_define_method(cDisplay, "fileno", display_fileno, 0);
43
- rb_define_method(cDisplay, "flush", display_flush, 0);
44
- rb_define_method(cDisplay, "grab_key", display_grab_key, 2);
45
- rb_define_method(cDisplay, "listen_events", display_listen_events, -1);
46
- rb_define_method(cDisplay, "each_event", display_each_event, 0);
47
- rb_define_method(cDisplay, "next_event", display_next_event, 0);
48
- rb_define_method(cDisplay, "open", display_open, 0);
49
- rb_define_method(cDisplay, "pending", display_pending, 0);
50
- rb_define_method(cDisplay, "query_font", display_query_font, 0);
51
- rb_define_method(cDisplay, "root", display_root, 0);
52
- rb_define_method(cDisplay, "screens", display_screens, 0);
53
- rb_define_method(cDisplay, "sync", display_sync, 1);
54
- }
55
-
56
- void uh_events() {
57
- mEvents = rb_define_module_under(mUh, "Events");
58
-
59
- cEvent = rb_define_class_under(mEvents, "Event", rb_cObject);
60
- rb_define_attr(cEvent, "type", 1, 0);
61
- rb_define_attr(cEvent, "window", 1, 0);
62
-
63
- cConfigureRequest = rb_define_class_under(mEvents, "ConfigureRequest", cEvent);
64
- rb_define_attr(cConfigureRequest, "x", 1, 0);
65
- rb_define_attr(cConfigureRequest, "y", 1, 0);
66
- rb_define_attr(cConfigureRequest, "width", 1, 0);
67
- rb_define_attr(cConfigureRequest, "height", 1, 0);
68
- rb_define_attr(cConfigureRequest, "above_window_id", 1, 0);
69
- rb_define_attr(cConfigureRequest, "detail", 1, 0);
70
- rb_define_attr(cConfigureRequest, "value_mask", 1, 0);
71
-
72
- cDestroyNotify = rb_define_class_under(mEvents, "DestroyNotify", cEvent);
73
-
74
- cExpose = rb_define_class_under(mEvents, "Expose", cEvent);
75
-
76
- cKeyPress = rb_define_class_under(mEvents, "KeyPress", cEvent);
77
- rb_define_attr(cKeyPress, "key", 1, 0);
78
- rb_define_attr(cKeyPress, "modifier_mask", 1, 0);
79
-
80
- cKeyRelease = rb_define_class_under(mEvents, "KeyRelease", cEvent);
81
- rb_define_attr(cKeyRelease, "key", 1, 0);
82
- rb_define_attr(cKeyRelease, "modifier_mask", 1, 0);
83
-
84
- cMapRequest = rb_define_class_under(mEvents, "MapRequest", cEvent);
85
-
86
- cPropertyNotify = rb_define_class_under(mEvents, "PropertyNotify", cEvent);
87
-
88
- cUnmapNotify = rb_define_class_under(mEvents, "UnmapNotify", cEvent);
89
- }
90
-
91
- void uh_font() {
92
- cFont = rb_define_class_under(mUh, "Font", rb_cObject);
93
- rb_define_attr(cFont, "width", 1, 0);
94
- rb_define_attr(cFont, "ascent", 1, 0);
95
- rb_define_attr(cFont, "descent", 1, 0);
96
- }
97
-
98
- void uh_pixmap() {
99
- cPixmap = rb_define_class_under(mUh, "Pixmap", rb_cObject);
100
- rb_define_attr(cPixmap, "width", 1, 0);
101
- rb_define_attr(cPixmap, "height", 1, 0);
102
- rb_define_method(cPixmap, "draw_rect", pixmap_draw_rect, 4);
103
- rb_define_method(cPixmap, "draw_string", pixmap_draw_string, 3);
104
- rb_define_method(cPixmap, "gc_black", pixmap_gc_black, 0);
105
- rb_define_method(cPixmap, "gc_color", pixmap_gc_color, 1);
106
- rb_define_method(cPixmap, "gc_white", pixmap_gc_white, 0);
107
- rb_define_private_method(cPixmap, "_copy", pixmap__copy, 3);
108
- }
109
-
110
- void uh_screen() {
111
- cScreen = rb_define_class_under(mUh, "Screen", rb_cObject);
112
- rb_define_method(cScreen, "initialize", screen_init, 5);
113
- rb_define_attr(cScreen, "id", 1, 0);
114
- rb_define_attr(cScreen, "x", 1, 0);
115
- rb_define_attr(cScreen, "y", 1, 0);
116
- rb_define_attr(cScreen, "width", 1, 0);
117
- rb_define_attr(cScreen, "height", 1, 0);
118
- }
119
-
120
- void uh_window() {
121
- cWindow = rb_define_class_under(mUh, "Window", rb_cObject);
122
- rb_define_attr(cWindow, "id", 1, 0);
123
- rb_define_method(cWindow, "destroy", window_destroy, 0);
124
- rb_define_method(cWindow, "focus", window_focus, 0);
125
- rb_define_method(cWindow, "kill", window_kill, 0);
126
- rb_define_method(cWindow, "map", window_map, 0);
127
- rb_define_method(cWindow, "mask", window_mask, 0);
128
- rb_define_method(cWindow, "mask=", window_mask_set, 1);
129
- rb_define_method(cWindow, "name", window_name, 0);
130
- rb_define_method(cWindow, "name=", window_name_set, 1);
131
- rb_define_method(cWindow, "override_redirect?", window_override_redirect, 0);
132
- rb_define_method(cWindow, "raise", window_raise, 0);
133
- rb_define_method(cWindow, "unmap", window_unmap, 0);
134
- rb_define_method(cWindow, "wclass", window_wclass, 0);
135
- rb_define_method(cWindow, "icccm_wm_delete", window_icccm_wm_delete, 0);
136
- rb_define_method(cWindow, "icccm_wm_protocols", window_icccm_wm_protocols, 0);
137
- rb_define_private_method(cWindow, "_configure", window__configure, 4);
138
- rb_define_private_method(cWindow, "_configure_event",
139
- window__configure_event, 4);
140
- rb_define_private_method(cWindow, "_create", window__create, 4);
141
- rb_define_private_method(cWindow, "_create_sub", window__create_sub, 4);
142
- rb_define_private_method(cWindow, "_moveresize", window__moveresize, 4);
143
- }
data/ext/uh/uh.h DELETED
@@ -1,106 +0,0 @@
1
- #ifndef RUBY_UH
2
- #define RUBY_UH
3
-
4
- #include <ruby.h>
5
-
6
- #include <X11/Xlib.h>
7
- #include <X11/XKBlib.h>
8
- #include <X11/Xutil.h>
9
- #include <X11/extensions/Xinerama.h>
10
-
11
-
12
- #define ROOT_DEFAULT DefaultRootWindow(DPY)
13
- #define SCREEN_DEFAULT DefaultScreen(DPY)
14
-
15
-
16
- typedef struct s_display UhDisplay;
17
- typedef struct s_pixmap UhPixmap;
18
- typedef struct s_window UhWindow;
19
-
20
- struct s_display {
21
- Display *dpy;
22
- };
23
-
24
- struct s_pixmap {
25
- Display *dpy;
26
- Pixmap pixmap;
27
- GC gc;
28
- };
29
-
30
- struct s_window {
31
- Display *dpy;
32
- Window id;
33
- };
34
-
35
-
36
- VALUE mUh, mEvents,
37
- cColor,
38
- cDisplay,
39
- cEvent, cConfigureRequest, cDestroyNotify, cExpose, cKeyPress, cKeyRelease,
40
- cMapRequest, cPropertyNotify, cUnmapNotify,
41
- cFont,
42
- cPixmap,
43
- cScreen,
44
- cWindow,
45
- eDisplayError;
46
-
47
-
48
- VALUE color_make(unsigned long pixel);
49
-
50
- VALUE display_s_on_error(VALUE klass);
51
- VALUE display_alloc(VALUE klass);
52
- VALUE display_close(VALUE self);
53
- VALUE display_color_by_name(VALUE self, VALUE rcolor);
54
- VALUE display_create_pixmap(VALUE self, VALUE w, VALUE h);
55
- VALUE display_each_event(VALUE self);
56
- VALUE display_fileno(VALUE self);
57
- VALUE display_flush(VALUE self);
58
- VALUE display_grab_key(VALUE self, VALUE key, VALUE modifier);
59
- VALUE display_listen_events(int argc, VALUE *argv, VALUE self);
60
- VALUE display_next_event(VALUE self);
61
- VALUE display_open(VALUE self);
62
- VALUE display_pending(VALUE self);
63
- VALUE display_query_font(VALUE self);
64
- VALUE display_root(VALUE self);
65
- VALUE display_root_change_attributes(VALUE self, VALUE mask);
66
- VALUE display_screens(VALUE self);
67
- VALUE display_sync(VALUE self, VALUE discard);
68
-
69
- VALUE event_make(XEvent *xev);
70
-
71
- VALUE font_make(int width, int ascent, int descent);
72
-
73
- VALUE pixmap__copy(VALUE self, VALUE rwindow_id, VALUE rwidth, VALUE rheight);
74
- VALUE pixmap_draw_rect(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h);
75
- VALUE pixmap_draw_string(VALUE self, VALUE x, VALUE y, VALUE str);
76
- VALUE pixmap_gc_black(VALUE self);
77
- VALUE pixmap_gc_color(VALUE self, VALUE rcolor);
78
- VALUE pixmap_gc_white(VALUE self);
79
- VALUE pixmap_make(Display *display, Pixmap xpixmap, VALUE width, VALUE height);
80
-
81
- VALUE screen_init(VALUE self, VALUE id, VALUE x, VALUE y, VALUE w, VALUE h);
82
-
83
- VALUE window_destroy(VALUE self);
84
- VALUE window_focus(VALUE self);
85
- VALUE window_icccm_wm_delete(VALUE self);
86
- VALUE window_icccm_wm_protocols(VALUE self);
87
- VALUE window_kill(VALUE self);
88
- VALUE window_map(VALUE self);
89
- VALUE window_mask(VALUE self);
90
- VALUE window_mask_set(VALUE self, VALUE mask);
91
- VALUE window_name(VALUE self);
92
- VALUE window_name_set(VALUE self, VALUE name);
93
- VALUE window_override_redirect(VALUE self);
94
- VALUE window_raise(VALUE self);
95
- VALUE window_unmap(VALUE self);
96
- VALUE window_wclass(VALUE self);
97
- VALUE window__configure(VALUE self, VALUE rx, VALUE ry, VALUE rw, VALUE rh);
98
- VALUE window__configure_event(VALUE self, VALUE rx, VALUE ry, VALUE rw, VALUE rh);
99
- VALUE window__create(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h);
100
- VALUE window__create_sub(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h);
101
- VALUE window__moveresize(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height);
102
- int window_id(VALUE window);
103
- VALUE window_make(Display *display, Window window_id);
104
-
105
-
106
- #endif