uh 2.0.0 → 2.1.1
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.
- checksums.yaml +5 -5
- data/README.md +12 -11
- data/ext/uh/display.c +10 -2
- data/ext/uh/event.c +22 -1
- data/ext/uh/extconf.rb +1 -1
- data/ext/uh/image.c +74 -0
- data/ext/uh/pixmap.c +0 -1
- data/ext/uh/uh.c +33 -1
- data/ext/uh/uh.h +19 -4
- data/ext/uh/window.c +30 -0
- data/lib/uh.rb +92 -0
- data/lib/uh/display.rb +24 -7
- data/lib/uh/geo.rb +7 -7
- data/lib/uh/screen.rb +1 -1
- data/lib/uh/version.rb +1 -1
- data/lib/uh/window.rb +5 -1
- metadata +12 -26
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 007c6cd4275c8fb92d69dd672ae7860fca0d947ea0b3073c8b75eab843e21915
         | 
| 4 | 
            +
              data.tar.gz: 8f07c400caa8a07f5f8d0c5c2706091639b8d5f39acbf55d87d5fe62d40289cd
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7b9afbebfe3cf8e5f67d05ea990d7968956549d9b94d71278de802508f73988b005e4a4b8147bcd71503c776758ab175b7188761f4b109acf5938a5040001ac1
         | 
| 7 | 
            +
              data.tar.gz: b36c9e3f1d360a2f350258a36e306b069ec692e0811dfb707e3b77b2ba94d31af2845284992c7be5c00d0ec8e96f6cb8b3b18cd2c8eee44505c29e18a9b7e356
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,18 +1,19 @@ | |
| 1 1 | 
             
            uh
         | 
| 2 2 | 
             
            ==
         | 
| 3 3 |  | 
| 4 | 
            -
            [![Version      ][badge-version-img]][badge-version-uri]
         | 
| 5 | 
            -
            [![Build status ][badge-build-img]][badge-build-uri]
         | 
| 6 | 
            -
            [![Code Climate ][badge-cclimate-img]][badge-cclimate-uri]
         | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 4 | 
             
              Minimalistic Xlib toolkit.
         | 
| 10 5 |  | 
| 11 6 |  | 
| 7 | 
            +
            Similar or related code
         | 
| 8 | 
            +
            -----------------------
         | 
| 12 9 |  | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 10 | 
            +
            * https://github.com/meh/ruby-x11 (gem, FFI, WM)
         | 
| 11 | 
            +
            * https://github.com/ayanko/x11_client (gem, C ext)
         | 
| 12 | 
            +
            * https://github.com/frankhale/ruby-window-management (C ext, WM)
         | 
| 13 | 
            +
            * https://github.com/christopheraue/ruby-xlib (gem, FFI)
         | 
| 14 | 
            +
            * https://github.com/rkh/ruby-xlib (C ext)
         | 
| 15 | 
            +
            * https://github.com/rramsden/ruby-x11 (pure ruby)
         | 
| 16 | 
            +
            * http://ruby-xlib-wrap.sourceforge.net/ (ext, SWIG)
         | 
| 17 | 
            +
            * http://www.moriq.com/ruby/xlib/
         | 
| 18 | 
            +
            * http://artengine.ca/matju/RubyX11/
         | 
| 19 | 
            +
            * https://github.com/mhanne/ruby-xcb (XCB, FFI)
         | 
    
        data/ext/uh/display.c
    CHANGED
    
    | @@ -11,6 +11,7 @@ | |
| 11 11 | 
             
            VALUE rdisplay_error_handler = Qnil;
         | 
| 12 12 |  | 
| 13 13 | 
             
            int display_x_error_handler(Display *dpy, XErrorEvent *e);
         | 
| 14 | 
            +
            int display_x_io_error_handler(Display *dpy);
         | 
| 14 15 |  | 
| 15 16 |  | 
| 16 17 | 
             
            VALUE display_s_on_error(VALUE klass) {
         | 
| @@ -132,10 +133,11 @@ VALUE display_open(VALUE self) { | |
| 132 133 | 
             
              SET_DISPLAY(self);
         | 
| 133 134 |  | 
| 134 135 | 
             
              if (!(DPY = XOpenDisplay(NULL))) {
         | 
| 135 | 
            -
                rb_raise(eDisplayError, "cannot open display");
         | 
| 136 | 
            +
                rb_raise(eDisplayError, "cannot open display %s", getenv("DISPLAY"));
         | 
| 136 137 | 
             
              }
         | 
| 137 138 |  | 
| 138 139 | 
             
              XSetErrorHandler(display_x_error_handler);
         | 
| 140 | 
            +
              XSetIOErrorHandler(display_x_io_error_handler);
         | 
| 139 141 |  | 
| 140 142 | 
             
              return self;
         | 
| 141 143 | 
             
            }
         | 
| @@ -146,7 +148,7 @@ VALUE display_opened_p(VALUE self) { | |
| 146 148 | 
             
              return DPY ? Qtrue : Qfalse;
         | 
| 147 149 | 
             
            }
         | 
| 148 150 |  | 
| 149 | 
            -
            VALUE  | 
| 151 | 
            +
            VALUE display_pending(VALUE self) {
         | 
| 150 152 | 
             
              SET_DISPLAY(self);
         | 
| 151 153 |  | 
| 152 154 | 
             
              rb_funcall(self, rb_intern("check!"), 0);
         | 
| @@ -220,3 +222,9 @@ int display_x_error_handler(Display *dpy, XErrorEvent *e) { | |
| 220 222 |  | 
| 221 223 | 
             
              return 0;
         | 
| 222 224 | 
             
            }
         | 
| 225 | 
            +
             | 
| 226 | 
            +
            int display_x_io_error_handler(Display *dpy) {
         | 
| 227 | 
            +
              rb_funcall(rdisplay_error_handler, rb_intern("call"), 0);
         | 
| 228 | 
            +
             | 
| 229 | 
            +
              return 0;
         | 
| 230 | 
            +
            }
         | 
    
        data/ext/uh/event.c
    CHANGED
    
    | @@ -7,7 +7,9 @@ | |
| 7 7 |  | 
| 8 8 |  | 
| 9 9 | 
             
            VALUE event_make_event(VALUE klass, XEvent *xev);
         | 
| 10 | 
            +
            void event_make_configure_notify(VALUE self);
         | 
| 10 11 | 
             
            void event_make_configure_request(VALUE self);
         | 
| 12 | 
            +
            void event_make_expose(VALUE self);
         | 
| 11 13 | 
             
            void event_make_key_any(VALUE self);
         | 
| 12 14 | 
             
            void event_make_win_any(VALUE self);
         | 
| 13 15 |  | 
| @@ -19,9 +21,10 @@ VALUE event_make(XEvent *xev) { | |
| 19 21 | 
             
                void  (*function)(VALUE self);
         | 
| 20 22 | 
             
              } EvClass;
         | 
| 21 23 | 
             
              EvClass       ev_classes[] = {
         | 
| 24 | 
            +
                {ConfigureNotify,   cConfigureNotify,   event_make_configure_notify},
         | 
| 22 25 | 
             
                {ConfigureRequest,  cConfigureRequest,  event_make_configure_request},
         | 
| 23 26 | 
             
                {DestroyNotify,     cDestroyNotify,     NULL},
         | 
| 24 | 
            -
                {Expose,            cExpose,             | 
| 27 | 
            +
                {Expose,            cExpose,            event_make_expose},
         | 
| 25 28 | 
             
                {KeyPress,          cKeyPress,          event_make_key_any},
         | 
| 26 29 | 
             
                {KeyRelease,        cKeyRelease,        event_make_key_any},
         | 
| 27 30 | 
             
                {MapRequest,        cMapRequest,        NULL},
         | 
| @@ -93,6 +96,15 @@ VALUE event_make_event(VALUE klass, XEvent *xev) { | |
| 93 96 | 
             
              return event;
         | 
| 94 97 | 
             
            }
         | 
| 95 98 |  | 
| 99 | 
            +
            void event_make_configure_notify(VALUE self) {
         | 
| 100 | 
            +
              SET_XEV(self);
         | 
| 101 | 
            +
             | 
| 102 | 
            +
              rb_ivar_set(self, rb_intern("@x"), INT2FIX(xev->xconfigure.x));
         | 
| 103 | 
            +
              rb_ivar_set(self, rb_intern("@y"), INT2FIX(xev->xconfigure.y));
         | 
| 104 | 
            +
              rb_ivar_set(self, rb_intern("@width"), INT2FIX(xev->xconfigure.width));
         | 
| 105 | 
            +
              rb_ivar_set(self, rb_intern("@height"), INT2FIX(xev->xconfigure.height));
         | 
| 106 | 
            +
            }
         | 
| 107 | 
            +
             | 
| 96 108 | 
             
            void event_make_configure_request(VALUE self) {
         | 
| 97 109 | 
             
              SET_XEV(self);
         | 
| 98 110 |  | 
| @@ -118,6 +130,15 @@ void event_make_configure_request(VALUE self) { | |
| 118 130 | 
             
                LONG2NUM(xev->xconfigurerequest.detail));
         | 
| 119 131 | 
             
            }
         | 
| 120 132 |  | 
| 133 | 
            +
            void event_make_expose(VALUE self) {
         | 
| 134 | 
            +
              SET_XEV(self);
         | 
| 135 | 
            +
             | 
| 136 | 
            +
              rb_ivar_set(self, rb_intern("@x"), INT2FIX(xev->xexpose.x));
         | 
| 137 | 
            +
              rb_ivar_set(self, rb_intern("@y"), INT2FIX(xev->xexpose.y));
         | 
| 138 | 
            +
              rb_ivar_set(self, rb_intern("@width"), INT2FIX(xev->xexpose.width));
         | 
| 139 | 
            +
              rb_ivar_set(self, rb_intern("@height"), INT2FIX(xev->xexpose.height));
         | 
| 140 | 
            +
            }
         | 
| 141 | 
            +
             | 
| 121 142 | 
             
            void event_make_key_any(VALUE self) {
         | 
| 122 143 | 
             
              KeySym ks;
         | 
| 123 144 | 
             
              SET_XEV(self);
         | 
    
        data/ext/uh/extconf.rb
    CHANGED
    
    
    
        data/ext/uh/image.c
    ADDED
    
    | @@ -0,0 +1,74 @@ | |
| 1 | 
            +
            #include "uh.h"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
             | 
| 4 | 
            +
            #define SET_IMAGE(x) \
         | 
| 5 | 
            +
              UhImage *image;\
         | 
| 6 | 
            +
              Data_Get_Struct(x, UhImage, image);
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            #define DPY   image->dpy
         | 
| 9 | 
            +
            #define IMAGE image->image
         | 
| 10 | 
            +
            #define GC    image->gc
         | 
| 11 | 
            +
             | 
| 12 | 
            +
             | 
| 13 | 
            +
            void image_deallocate(UhImage *image);
         | 
| 14 | 
            +
             | 
| 15 | 
            +
             | 
| 16 | 
            +
            VALUE image_s_new(VALUE klass, VALUE rdisplay, VALUE rwidth, VALUE rheight, VALUE rdata) {
         | 
| 17 | 
            +
              VALUE rimage;
         | 
| 18 | 
            +
              SET_DISPLAY(rdisplay);
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              rb_funcall(rdisplay, rb_intern("check!"), 0);
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              StringValue(rdata);
         | 
| 23 | 
            +
              rimage = image_make(
         | 
| 24 | 
            +
                display->dpy,
         | 
| 25 | 
            +
                FIX2INT(rwidth),
         | 
| 26 | 
            +
                FIX2INT(rheight),
         | 
| 27 | 
            +
                RSTRING_PTR(rdata)
         | 
| 28 | 
            +
              );
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              return rimage;
         | 
| 31 | 
            +
            }
         | 
| 32 | 
            +
             | 
| 33 | 
            +
             | 
| 34 | 
            +
            VALUE image_put(VALUE self, VALUE rwindow) {
         | 
| 35 | 
            +
              SET_IMAGE(self);
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              XPutImage(
         | 
| 38 | 
            +
                DPY,
         | 
| 39 | 
            +
                FIX2INT(rb_funcall(rwindow, rb_intern("id"), 0)),
         | 
| 40 | 
            +
                GC,
         | 
| 41 | 
            +
                IMAGE,
         | 
| 42 | 
            +
                0, 0,
         | 
| 43 | 
            +
                0, 0,
         | 
| 44 | 
            +
                IMAGE->width, IMAGE->height
         | 
| 45 | 
            +
              );
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              return Qnil;
         | 
| 48 | 
            +
            }
         | 
| 49 | 
            +
             | 
| 50 | 
            +
             | 
| 51 | 
            +
            VALUE image_make(Display *dpy, int width, int height, char *data) {
         | 
| 52 | 
            +
              UhImage *image;
         | 
| 53 | 
            +
              VALUE   rimage;
         | 
| 54 | 
            +
             | 
| 55 | 
            +
              rimage = Data_Make_Struct(cImage, UhImage, 0, image_deallocate, image);
         | 
| 56 | 
            +
              image->dpy    = dpy;
         | 
| 57 | 
            +
              image->gc     = XCreateGC(dpy, ROOT_DEFAULT, 0, NULL);
         | 
| 58 | 
            +
              image->image  = XCreateImage(
         | 
| 59 | 
            +
                DPY,
         | 
| 60 | 
            +
                DefaultVisual(DPY, DefaultScreen(DPY)),
         | 
| 61 | 
            +
                DEPTH_DEFAULT,
         | 
| 62 | 
            +
                ZPixmap, 0,
         | 
| 63 | 
            +
                data, width, height,
         | 
| 64 | 
            +
                32, 0
         | 
| 65 | 
            +
              );
         | 
| 66 | 
            +
             | 
| 67 | 
            +
              return rimage;
         | 
| 68 | 
            +
            }
         | 
| 69 | 
            +
             | 
| 70 | 
            +
             | 
| 71 | 
            +
            void image_deallocate(UhImage *image) {
         | 
| 72 | 
            +
              XDestroyImage(IMAGE);
         | 
| 73 | 
            +
              free(image);
         | 
| 74 | 
            +
            }
         | 
    
        data/ext/uh/pixmap.c
    CHANGED
    
    
    
        data/ext/uh/uh.c
    CHANGED
    
    | @@ -1,10 +1,23 @@ | |
| 1 1 | 
             
            #include "uh.h"
         | 
| 2 2 |  | 
| 3 3 |  | 
| 4 | 
            +
            VALUE mUh, mEvents,
         | 
| 5 | 
            +
              cColor,
         | 
| 6 | 
            +
              cDisplay,
         | 
| 7 | 
            +
              cEvent, cConfigureNotify, cConfigureRequest, cDestroyNotify, cExpose,
         | 
| 8 | 
            +
                cKeyPress, cKeyRelease, cMapRequest, cPropertyNotify, cUnmapNotify,
         | 
| 9 | 
            +
              cFont,
         | 
| 10 | 
            +
              cImage,
         | 
| 11 | 
            +
              cPixmap,
         | 
| 12 | 
            +
              cScreen,
         | 
| 13 | 
            +
              cWindow,
         | 
| 14 | 
            +
              eError, eRuntimeError, eArgumentError, eDisplayError;
         | 
| 15 | 
            +
             | 
| 4 16 | 
             
            void uh_color();
         | 
| 5 17 | 
             
            void uh_display();
         | 
| 6 18 | 
             
            void uh_events();
         | 
| 7 19 | 
             
            void uh_font();
         | 
| 20 | 
            +
            void uh_image();
         | 
| 8 21 | 
             
            void uh_pixmap();
         | 
| 9 22 | 
             
            void uh_screen();
         | 
| 10 23 | 
             
            void uh_window();
         | 
| @@ -22,6 +35,7 @@ void Init_uh(void) { | |
| 22 35 | 
             
              uh_display();
         | 
| 23 36 | 
             
              uh_events();
         | 
| 24 37 | 
             
              uh_font();
         | 
| 38 | 
            +
              uh_image();
         | 
| 25 39 | 
             
              uh_pixmap();
         | 
| 26 40 | 
             
              uh_screen();
         | 
| 27 41 | 
             
              uh_window();
         | 
| @@ -48,7 +62,7 @@ void uh_display() { | |
| 48 62 | 
             
              rb_define_method(cDisplay, "next_event", display_next_event, 0);
         | 
| 49 63 | 
             
              rb_define_method(cDisplay, "open", display_open, 0);
         | 
| 50 64 | 
             
              rb_define_method(cDisplay, "opened?", display_opened_p, 0);
         | 
| 51 | 
            -
              rb_define_method(cDisplay, "pending",  | 
| 65 | 
            +
              rb_define_method(cDisplay, "pending", display_pending, 0);
         | 
| 52 66 | 
             
              rb_define_method(cDisplay, "root", display_root, 0);
         | 
| 53 67 | 
             
              rb_define_method(cDisplay, "screens", display_screens, 0);
         | 
| 54 68 | 
             
              rb_define_method(cDisplay, "sync", display_sync, 1);
         | 
| @@ -61,6 +75,12 @@ void uh_events() { | |
| 61 75 | 
             
              rb_define_attr(cEvent, "type", 1, 0);
         | 
| 62 76 | 
             
              rb_define_attr(cEvent, "window", 1, 0);
         | 
| 63 77 |  | 
| 78 | 
            +
              cConfigureNotify = rb_define_class_under(mEvents, "ConfigureNotify", cEvent);
         | 
| 79 | 
            +
              rb_define_attr(cConfigureNotify, "x", 1, 0);
         | 
| 80 | 
            +
              rb_define_attr(cConfigureNotify, "y", 1, 0);
         | 
| 81 | 
            +
              rb_define_attr(cConfigureNotify, "width", 1, 0);
         | 
| 82 | 
            +
              rb_define_attr(cConfigureNotify, "height", 1, 0);
         | 
| 83 | 
            +
             | 
| 64 84 | 
             
              cConfigureRequest = rb_define_class_under(mEvents, "ConfigureRequest", cEvent);
         | 
| 65 85 | 
             
              rb_define_attr(cConfigureRequest, "x", 1, 0);
         | 
| 66 86 | 
             
              rb_define_attr(cConfigureRequest, "y", 1, 0);
         | 
| @@ -73,6 +93,10 @@ void uh_events() { | |
| 73 93 | 
             
              cDestroyNotify = rb_define_class_under(mEvents, "DestroyNotify", cEvent);
         | 
| 74 94 |  | 
| 75 95 | 
             
              cExpose = rb_define_class_under(mEvents, "Expose", cEvent);
         | 
| 96 | 
            +
              rb_define_attr(cExpose, "x", 1, 0);
         | 
| 97 | 
            +
              rb_define_attr(cExpose, "y", 1, 0);
         | 
| 98 | 
            +
              rb_define_attr(cExpose, "width", 1, 0);
         | 
| 99 | 
            +
              rb_define_attr(cExpose, "height", 1, 0);
         | 
| 76 100 |  | 
| 77 101 | 
             
              cKeyPress = rb_define_class_under(mEvents, "KeyPress", cEvent);
         | 
| 78 102 | 
             
              rb_define_attr(cKeyPress, "key", 1, 0);
         | 
| @@ -97,6 +121,12 @@ void uh_font() { | |
| 97 121 | 
             
              rb_define_attr(cFont, "descent", 1, 0);
         | 
| 98 122 | 
             
            }
         | 
| 99 123 |  | 
| 124 | 
            +
            void uh_image() {
         | 
| 125 | 
            +
              cImage = rb_define_class_under(mUh, "Image", rb_cObject);
         | 
| 126 | 
            +
              rb_define_singleton_method(cImage, "new", image_s_new, 4);
         | 
| 127 | 
            +
              rb_define_method(cImage, "put", image_put, 1);
         | 
| 128 | 
            +
            }
         | 
| 129 | 
            +
             | 
| 100 130 | 
             
            void uh_pixmap() {
         | 
| 101 131 | 
             
              cPixmap = rb_define_class_under(mUh, "Pixmap", rb_cObject);
         | 
| 102 132 | 
             
              rb_define_singleton_method(cPixmap, "new", pixmap_s_new, 3);
         | 
| @@ -128,6 +158,7 @@ void uh_window() { | |
| 128 158 | 
             
              rb_define_method(cWindow, "configure_event", window_configure_event, 1);
         | 
| 129 159 | 
             
              rb_define_method(cWindow, "create", window_create, 1);
         | 
| 130 160 | 
             
              rb_define_method(cWindow, "create_sub", window_create_sub, 1);
         | 
| 161 | 
            +
              rb_define_method(cWindow, "cursor=", window_cursor_set, 1);
         | 
| 131 162 | 
             
              rb_define_method(cWindow, "destroy", window_destroy, 0);
         | 
| 132 163 | 
             
              rb_define_method(cWindow, "focus", window_focus, 0);
         | 
| 133 164 | 
             
              rb_define_method(cWindow, "icccm_wm_delete", window_icccm_wm_delete, 0);
         | 
| @@ -144,4 +175,5 @@ void uh_window() { | |
| 144 175 | 
             
              rb_define_method(cWindow, "raise", window_raise, 0);
         | 
| 145 176 | 
             
              rb_define_method(cWindow, "unmap", window_unmap, 0);
         | 
| 146 177 | 
             
              rb_define_method(cWindow, "wclass", window_wclass, 0);
         | 
| 178 | 
            +
              rb_define_method(cWindow, "wclass=", window_wclass_set, 1);
         | 
| 147 179 | 
             
            }
         | 
    
        data/ext/uh/uh.h
    CHANGED
    
    | @@ -15,9 +15,11 @@ | |
| 15 15 |  | 
| 16 16 | 
             
            #define ROOT_DEFAULT    DefaultRootWindow(DPY)
         | 
| 17 17 | 
             
            #define SCREEN_DEFAULT  DefaultScreen(DPY)
         | 
| 18 | 
            +
            #define DEPTH_DEFAULT   DefaultDepth(DPY, SCREEN_DEFAULT)
         | 
| 18 19 |  | 
| 19 20 |  | 
| 20 21 | 
             
            typedef struct s_display  UhDisplay;
         | 
| 22 | 
            +
            typedef struct s_image    UhImage;
         | 
| 21 23 | 
             
            typedef struct s_pixmap   UhPixmap;
         | 
| 22 24 | 
             
            typedef struct s_window   UhWindow;
         | 
| 23 25 |  | 
| @@ -25,6 +27,12 @@ struct s_display { | |
| 25 27 | 
             
              Display *dpy;
         | 
| 26 28 | 
             
            };
         | 
| 27 29 |  | 
| 30 | 
            +
            struct s_image {
         | 
| 31 | 
            +
              Display *dpy;
         | 
| 32 | 
            +
              GC      gc;
         | 
| 33 | 
            +
              XImage  *image;
         | 
| 34 | 
            +
            };
         | 
| 35 | 
            +
             | 
| 28 36 | 
             
            struct s_pixmap {
         | 
| 29 37 | 
             
              Display *dpy;
         | 
| 30 38 | 
             
              Pixmap  pixmap;
         | 
| @@ -37,12 +45,13 @@ struct s_window { | |
| 37 45 | 
             
            };
         | 
| 38 46 |  | 
| 39 47 |  | 
| 40 | 
            -
            VALUE mUh, mEvents,
         | 
| 48 | 
            +
            extern VALUE mUh, mEvents,
         | 
| 41 49 | 
             
              cColor,
         | 
| 42 50 | 
             
              cDisplay,
         | 
| 43 | 
            -
              cEvent, cConfigureRequest, cDestroyNotify, cExpose, | 
| 44 | 
            -
                cMapRequest, cPropertyNotify, cUnmapNotify,
         | 
| 51 | 
            +
              cEvent, cConfigureNotify, cConfigureRequest, cDestroyNotify, cExpose,
         | 
| 52 | 
            +
                cKeyPress, cKeyRelease, cMapRequest, cPropertyNotify, cUnmapNotify,
         | 
| 45 53 | 
             
              cFont,
         | 
| 54 | 
            +
              cImage,
         | 
| 46 55 | 
             
              cPixmap,
         | 
| 47 56 | 
             
              cScreen,
         | 
| 48 57 | 
             
              cWindow,
         | 
| @@ -62,7 +71,7 @@ VALUE display_listen_events(int argc, VALUE *argv, VALUE self); | |
| 62 71 | 
             
            VALUE display_next_event(VALUE self);
         | 
| 63 72 | 
             
            VALUE display_open(VALUE self);
         | 
| 64 73 | 
             
            VALUE display_opened_p(VALUE self);
         | 
| 65 | 
            -
            VALUE  | 
| 74 | 
            +
            VALUE display_pending(VALUE self);
         | 
| 66 75 | 
             
            VALUE display_root(VALUE self);
         | 
| 67 76 | 
             
            VALUE display_root_change_attributes(VALUE self, VALUE mask);
         | 
| 68 77 | 
             
            VALUE display_screens(VALUE self);
         | 
| @@ -72,6 +81,10 @@ VALUE event_make(XEvent *xev); | |
| 72 81 |  | 
| 73 82 | 
             
            VALUE font_s_new(VALUE klass, VALUE rdisplay);
         | 
| 74 83 |  | 
| 84 | 
            +
            VALUE image_s_new(VALUE klass, VALUE rdisplay, VALUE rwidth, VALUE rheight, VALUE rdata);
         | 
| 85 | 
            +
            VALUE image_make(Display *dpy, int w, int h, char *data);
         | 
| 86 | 
            +
            VALUE image_put(VALUE self, VALUE rwindow);
         | 
| 87 | 
            +
             | 
| 75 88 | 
             
            VALUE pixmap_s_new(VALUE klass, VALUE rdisplay, VALUE rwidth, VALUE rheight);
         | 
| 76 89 | 
             
            VALUE pixmap_copy(VALUE self, VALUE rwindow);
         | 
| 77 90 | 
             
            VALUE pixmap_draw_rect(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h);
         | 
| @@ -88,6 +101,7 @@ VALUE window_configure(VALUE self, VALUE rgeo); | |
| 88 101 | 
             
            VALUE window_configure_event(VALUE self, VALUE rgeo);
         | 
| 89 102 | 
             
            VALUE window_create(VALUE self, VALUE rgeo);
         | 
| 90 103 | 
             
            VALUE window_create_sub(VALUE self, VALUE rgeo);
         | 
| 104 | 
            +
            VALUE window_cursor_set(VALUE self, VALUE cursor);
         | 
| 91 105 | 
             
            VALUE window_destroy(VALUE self);
         | 
| 92 106 | 
             
            VALUE window_focus(VALUE self);
         | 
| 93 107 | 
             
            VALUE window_icccm_wm_delete(VALUE self);
         | 
| @@ -103,6 +117,7 @@ VALUE window_override_redirect(VALUE self); | |
| 103 117 | 
             
            VALUE window_raise(VALUE self);
         | 
| 104 118 | 
             
            VALUE window_unmap(VALUE self);
         | 
| 105 119 | 
             
            VALUE window_wclass(VALUE self);
         | 
| 120 | 
            +
            VALUE window_wclass_set(VALUE self, VALUE rwclass);
         | 
| 106 121 | 
             
            int window_id(VALUE window);
         | 
| 107 122 | 
             
            VALUE window_make(Display *display, Window window_id);
         | 
| 108 123 |  | 
    
        data/ext/uh/window.c
    CHANGED
    
    | @@ -92,6 +92,16 @@ VALUE window_create_sub(VALUE self, VALUE rgeo) { | |
| 92 92 | 
             
              return window_make(DPY, sub_win);
         | 
| 93 93 | 
             
            }
         | 
| 94 94 |  | 
| 95 | 
            +
            VALUE window_cursor_set(VALUE self, VALUE rcursor) {
         | 
| 96 | 
            +
              Cursor cursor;
         | 
| 97 | 
            +
              SET_WINDOW(self);
         | 
| 98 | 
            +
             | 
| 99 | 
            +
              cursor = XCreateFontCursor(DPY, FIX2INT(rcursor));
         | 
| 100 | 
            +
              XDefineCursor(DPY, WINDOW, cursor);
         | 
| 101 | 
            +
             | 
| 102 | 
            +
              return Qnil;
         | 
| 103 | 
            +
            }
         | 
| 104 | 
            +
             | 
| 95 105 | 
             
            VALUE window_destroy(VALUE self) {
         | 
| 96 106 | 
             
              SET_WINDOW(self);
         | 
| 97 107 |  | 
| @@ -257,6 +267,26 @@ VALUE window_wclass(VALUE self) { | |
| 257 267 | 
             
              return wclass;
         | 
| 258 268 | 
             
            }
         | 
| 259 269 |  | 
| 270 | 
            +
            VALUE window_wclass_set(VALUE self, VALUE rwclass) {
         | 
| 271 | 
            +
              XClassHint  *ch;
         | 
| 272 | 
            +
              VALUE       rres_name;
         | 
| 273 | 
            +
              VALUE       rres_class;
         | 
| 274 | 
            +
              SET_WINDOW(self);
         | 
| 275 | 
            +
             | 
| 276 | 
            +
              rres_name = rb_ary_entry(rwclass, 0);
         | 
| 277 | 
            +
              StringValue(rres_name);
         | 
| 278 | 
            +
              rres_class = rb_ary_entry(rwclass, 1);
         | 
| 279 | 
            +
              StringValue(rres_class);
         | 
| 280 | 
            +
              if ((ch = XAllocClassHint())) {
         | 
| 281 | 
            +
                ch->res_name = RSTRING_PTR(rres_name);
         | 
| 282 | 
            +
                ch->res_class = RSTRING_PTR(rres_class);
         | 
| 283 | 
            +
                XSetClassHint(DPY, WINDOW, ch);
         | 
| 284 | 
            +
                XFree(ch);
         | 
| 285 | 
            +
              }
         | 
| 286 | 
            +
             | 
| 287 | 
            +
              return Qnil;
         | 
| 288 | 
            +
            }
         | 
| 289 | 
            +
             | 
| 260 290 |  | 
| 261 291 | 
             
            int window_id(VALUE self) {
         | 
| 262 292 | 
             
              SET_WINDOW(self);
         | 
    
        data/lib/uh.rb
    CHANGED
    
    | @@ -10,6 +10,87 @@ require 'uh/version' | |
| 10 10 | 
             
            require 'uh/window'
         | 
| 11 11 |  | 
| 12 12 | 
             
            module Uh
         | 
| 13 | 
            +
              CURSORS = {
         | 
| 14 | 
            +
                num_glyphs: 154,
         | 
| 15 | 
            +
                x_cursor: 0,
         | 
| 16 | 
            +
                arrow: 2,
         | 
| 17 | 
            +
                based_arrow_down: 4,
         | 
| 18 | 
            +
                based_arrow_up: 6,
         | 
| 19 | 
            +
                boat: 8,
         | 
| 20 | 
            +
                bogosity: 10,
         | 
| 21 | 
            +
                bottom_left_corner: 12,
         | 
| 22 | 
            +
                bottom_right_corner: 14,
         | 
| 23 | 
            +
                bottom_side: 16,
         | 
| 24 | 
            +
                bottom_tee: 18,
         | 
| 25 | 
            +
                box_spiral: 20,
         | 
| 26 | 
            +
                center_ptr: 22,
         | 
| 27 | 
            +
                circle: 24,
         | 
| 28 | 
            +
                clock: 26,
         | 
| 29 | 
            +
                coffee_mug: 28,
         | 
| 30 | 
            +
                cross: 30,
         | 
| 31 | 
            +
                cross_reverse: 32,
         | 
| 32 | 
            +
                crosshair: 34,
         | 
| 33 | 
            +
                diamond_cross: 36,
         | 
| 34 | 
            +
                dot: 38,
         | 
| 35 | 
            +
                dotbox: 40,
         | 
| 36 | 
            +
                double_arrow: 42,
         | 
| 37 | 
            +
                draft_large: 44,
         | 
| 38 | 
            +
                draft_small: 46,
         | 
| 39 | 
            +
                draped_box: 48,
         | 
| 40 | 
            +
                exchange: 50,
         | 
| 41 | 
            +
                fleur: 52,
         | 
| 42 | 
            +
                gobbler: 54,
         | 
| 43 | 
            +
                gumby: 56,
         | 
| 44 | 
            +
                hand1: 58,
         | 
| 45 | 
            +
                hand2: 60,
         | 
| 46 | 
            +
                heart: 62,
         | 
| 47 | 
            +
                icon: 64,
         | 
| 48 | 
            +
                iron_cross: 66,
         | 
| 49 | 
            +
                left_ptr: 68,
         | 
| 50 | 
            +
                left_side: 70,
         | 
| 51 | 
            +
                left_tee: 72,
         | 
| 52 | 
            +
                leftbutton: 74,
         | 
| 53 | 
            +
                ll_angle: 76,
         | 
| 54 | 
            +
                lr_angle: 78,
         | 
| 55 | 
            +
                man: 80,
         | 
| 56 | 
            +
                middlebutton: 82,
         | 
| 57 | 
            +
                mouse: 84,
         | 
| 58 | 
            +
                pencil: 86,
         | 
| 59 | 
            +
                pirate: 88,
         | 
| 60 | 
            +
                plus: 90,
         | 
| 61 | 
            +
                question_arrow: 92,
         | 
| 62 | 
            +
                right_ptr: 94,
         | 
| 63 | 
            +
                right_side: 96,
         | 
| 64 | 
            +
                right_tee: 98,
         | 
| 65 | 
            +
                rightbutton: 100,
         | 
| 66 | 
            +
                rtl_logo: 102,
         | 
| 67 | 
            +
                sailboat: 104,
         | 
| 68 | 
            +
                sb_down_arrow: 106,
         | 
| 69 | 
            +
                sb_h_double_arrow: 108,
         | 
| 70 | 
            +
                sb_left_arrow: 110,
         | 
| 71 | 
            +
                sb_right_arrow: 112,
         | 
| 72 | 
            +
                sb_up_arrow: 114,
         | 
| 73 | 
            +
                sb_v_double_arrow: 116,
         | 
| 74 | 
            +
                shuttle: 118,
         | 
| 75 | 
            +
                sizing: 120,
         | 
| 76 | 
            +
                spider: 122,
         | 
| 77 | 
            +
                spraycan: 124,
         | 
| 78 | 
            +
                star: 126,
         | 
| 79 | 
            +
                target: 128,
         | 
| 80 | 
            +
                tcross: 130,
         | 
| 81 | 
            +
                top_left_arrow: 132,
         | 
| 82 | 
            +
                top_left_corner: 134,
         | 
| 83 | 
            +
                top_right_corner: 136,
         | 
| 84 | 
            +
                top_side: 138,
         | 
| 85 | 
            +
                top_tee: 140,
         | 
| 86 | 
            +
                trek: 142,
         | 
| 87 | 
            +
                ul_angle: 144,
         | 
| 88 | 
            +
                umbrella: 146,
         | 
| 89 | 
            +
                ur_angle: 148,
         | 
| 90 | 
            +
                watch: 150,
         | 
| 91 | 
            +
                xterm: 152,
         | 
| 92 | 
            +
              }
         | 
| 93 | 
            +
             | 
| 13 94 | 
             
              KEY_MODIFIERS = {
         | 
| 14 95 | 
             
                shift:  1 << 0,
         | 
| 15 96 | 
             
                lock:   1 << 1,
         | 
| @@ -20,4 +101,15 @@ module Uh | |
| 20 101 | 
             
                mod4:   1 << 6,
         | 
| 21 102 | 
             
                mod5:   1 << 7
         | 
| 22 103 | 
             
              }.freeze
         | 
| 104 | 
            +
             | 
| 105 | 
            +
              class << self
         | 
| 106 | 
            +
                def open
         | 
| 107 | 
            +
                  display = Display.new.tap &:open
         | 
| 108 | 
            +
                  begin
         | 
| 109 | 
            +
                    yield display
         | 
| 110 | 
            +
                  ensure
         | 
| 111 | 
            +
                    display.close
         | 
| 112 | 
            +
                  end
         | 
| 113 | 
            +
                end
         | 
| 114 | 
            +
              end
         | 
| 23 115 | 
             
            end
         | 
    
        data/lib/uh/display.rb
    CHANGED
    
    | @@ -8,19 +8,23 @@ module Uh | |
| 8 8 | 
             
                  fail DisplayError, 'display not opened' unless opened?
         | 
| 9 9 | 
             
                end
         | 
| 10 10 |  | 
| 11 | 
            -
                def color_by_name | 
| 12 | 
            -
                  Color.new | 
| 11 | 
            +
                def color_by_name color_name
         | 
| 12 | 
            +
                  Color.new self, color_name
         | 
| 13 13 | 
             
                end
         | 
| 14 14 |  | 
| 15 | 
            -
                def  | 
| 16 | 
            -
                   | 
| 15 | 
            +
                def create_image width, height, image
         | 
| 16 | 
            +
                  Image.new self, width, height, image
         | 
| 17 17 | 
             
                end
         | 
| 18 18 |  | 
| 19 | 
            -
                def  | 
| 19 | 
            +
                def create_pixmap width, height
         | 
| 20 | 
            +
                  Pixmap.new self, width, height
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def create_window geo
         | 
| 20 24 | 
             
                  root.create geo
         | 
| 21 25 | 
             
                end
         | 
| 22 26 |  | 
| 23 | 
            -
                def create_subwindow | 
| 27 | 
            +
                def create_subwindow geo
         | 
| 24 28 | 
             
                  root.create_sub geo
         | 
| 25 29 | 
             
                end
         | 
| 26 30 |  | 
| @@ -33,7 +37,20 @@ module Uh | |
| 33 37 | 
             
                end
         | 
| 34 38 |  | 
| 35 39 | 
             
                def query_font
         | 
| 36 | 
            -
                  Font.new | 
| 40 | 
            +
                  Font.new self
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                def window **opts
         | 
| 44 | 
            +
                  window = create_window Geo.new 0, 0, 320, 240
         | 
| 45 | 
            +
                  listen_events window, opts[:events] if opts.key? :events
         | 
| 46 | 
            +
                  window.cursor opts[:cursor] if opts.key? :cursor
         | 
| 47 | 
            +
                  window.map
         | 
| 48 | 
            +
                  begin
         | 
| 49 | 
            +
                    yield window
         | 
| 50 | 
            +
                  ensure
         | 
| 51 | 
            +
                    window.unmap
         | 
| 52 | 
            +
                    window.destroy
         | 
| 53 | 
            +
                  end
         | 
| 37 54 | 
             
                end
         | 
| 38 55 | 
             
              end
         | 
| 39 56 | 
             
            end
         | 
    
        data/lib/uh/geo.rb
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            module Uh
         | 
| 2 | 
            -
              class Geo < Struct.new | 
| 2 | 
            +
              class Geo < Struct.new :x, :y, :width, :height
         | 
| 3 3 | 
             
                class << self
         | 
| 4 | 
            -
                  def format_xgeometry | 
| 4 | 
            +
                  def format_xgeometry x, y, width, height
         | 
| 5 5 | 
             
                    '%sx%s+%s+%s' % [
         | 
| 6 6 | 
             
                      width   ? width.to_s  : ??,
         | 
| 7 7 | 
             
                      height  ? height.to_s : ??,
         | 
| @@ -11,7 +11,7 @@ module Uh | |
| 11 11 | 
             
                  end
         | 
| 12 12 | 
             
                end
         | 
| 13 13 |  | 
| 14 | 
            -
                def initialize | 
| 14 | 
            +
                def initialize *args
         | 
| 15 15 | 
             
                  super
         | 
| 16 16 | 
             
                  %i[width height].each do |dimension|
         | 
| 17 17 | 
             
                    check_value dimension, send(dimension)
         | 
| @@ -22,20 +22,20 @@ module Uh | |
| 22 22 | 
             
                  self.class.format_xgeometry *values
         | 
| 23 23 | 
             
                end
         | 
| 24 24 |  | 
| 25 | 
            -
                def width= | 
| 25 | 
            +
                def width= value
         | 
| 26 26 | 
             
                  check_value :width, value
         | 
| 27 27 | 
             
                  super value
         | 
| 28 28 | 
             
                end
         | 
| 29 29 |  | 
| 30 | 
            -
                def height= | 
| 30 | 
            +
                def height= value
         | 
| 31 31 | 
             
                  check_value :height, value
         | 
| 32 32 | 
             
                  super value
         | 
| 33 33 | 
             
                end
         | 
| 34 34 |  | 
| 35 35 |  | 
| 36 | 
            -
             | 
| 36 | 
            +
              private
         | 
| 37 37 |  | 
| 38 | 
            -
                def check_value | 
| 38 | 
            +
                def check_value name, value
         | 
| 39 39 | 
             
                  return if value.nil?
         | 
| 40 40 | 
             
                  fail ArgumentError, "invalid #{name.to_s}: #{value}" unless value > 0
         | 
| 41 41 | 
             
                end
         | 
    
        data/lib/uh/screen.rb
    CHANGED
    
    
    
        data/lib/uh/version.rb
    CHANGED
    
    
    
        data/lib/uh/window.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: uh
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2. | 
| 4 | 
            +
              version: 2.1.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Thibault Jouan
         | 
| 8 | 
            -
            autorequire: | 
| 8 | 
            +
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2020-09-23 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rake
         | 
| @@ -16,28 +16,28 @@ dependencies: | |
| 16 16 | 
             
                requirements:
         | 
| 17 17 | 
             
                - - "~>"
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version: '10 | 
| 19 | 
            +
                    version: '10'
         | 
| 20 20 | 
             
              type: :development
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 24 | 
             
                - - "~>"
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            -
                    version: '10 | 
| 26 | 
            +
                    version: '10'
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: rake-compiler
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                requirements:
         | 
| 31 31 | 
             
                - - "~>"
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: '0 | 
| 33 | 
            +
                    version: '1.0'
         | 
| 34 34 | 
             
              type: :development
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 38 | 
             
                - - "~>"
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            -
                    version: '0 | 
| 40 | 
            +
                    version: '1.0'
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: minitest
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -66,21 +66,7 @@ dependencies: | |
| 66 66 | 
             
                - - "~>"
         | 
| 67 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| 68 68 | 
             
                    version: '1.0'
         | 
| 69 | 
            -
             | 
| 70 | 
            -
              name: headless
         | 
| 71 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            -
                requirements:
         | 
| 73 | 
            -
                - - "~>"
         | 
| 74 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            -
                    version: '1.0'
         | 
| 76 | 
            -
              type: :development
         | 
| 77 | 
            -
              prerelease: false
         | 
| 78 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            -
                requirements:
         | 
| 80 | 
            -
                - - "~>"
         | 
| 81 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            -
                    version: '1.0'
         | 
| 83 | 
            -
            description: uh
         | 
| 69 | 
            +
            description:
         | 
| 84 70 | 
             
            email: tj@a13.fr
         | 
| 85 71 | 
             
            executables: []
         | 
| 86 72 | 
             
            extensions:
         | 
| @@ -94,6 +80,7 @@ files: | |
| 94 80 | 
             
            - ext/uh/event.c
         | 
| 95 81 | 
             
            - ext/uh/extconf.rb
         | 
| 96 82 | 
             
            - ext/uh/font.c
         | 
| 83 | 
            +
            - ext/uh/image.c
         | 
| 97 84 | 
             
            - ext/uh/pixmap.c
         | 
| 98 85 | 
             
            - ext/uh/screen.c
         | 
| 99 86 | 
             
            - ext/uh/uh.c
         | 
| @@ -113,7 +100,7 @@ homepage: https://rubygems.org/gems/uh | |
| 113 100 | 
             
            licenses:
         | 
| 114 101 | 
             
            - BSD-3-Clause
         | 
| 115 102 | 
             
            metadata: {}
         | 
| 116 | 
            -
            post_install_message: | 
| 103 | 
            +
            post_install_message:
         | 
| 117 104 | 
             
            rdoc_options: []
         | 
| 118 105 | 
             
            require_paths:
         | 
| 119 106 | 
             
            - lib
         | 
| @@ -128,9 +115,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 128 115 | 
             
                - !ruby/object:Gem::Version
         | 
| 129 116 | 
             
                  version: '0'
         | 
| 130 117 | 
             
            requirements: []
         | 
| 131 | 
            -
             | 
| 132 | 
            -
             | 
| 133 | 
            -
            signing_key: 
         | 
| 118 | 
            +
            rubygems_version: 3.0.6
         | 
| 119 | 
            +
            signing_key:
         | 
| 134 120 | 
             
            specification_version: 4
         | 
| 135 121 | 
             
            summary: Xlib simplified toolkit
         | 
| 136 122 | 
             
            test_files: []
         |