uh 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d1bdf3fc9dbfc55b459073bd692630415184c49
4
- data.tar.gz: a0e9eb2a0dd64f446df63900fe1986082cd75a95
3
+ metadata.gz: 2f36e4f78b43d16a0075b8b5d3b0a0b015956ac1
4
+ data.tar.gz: 610557a1bb46d231584acb65b144b622f7fd4219
5
5
  SHA512:
6
- metadata.gz: 8308d3da480d36c5aad1b81ff866692516b641069f39c18a6f60ef3f7ef29d25d7d6066c7acf4e4be276560f4ac8e247261d3afae009575b20b0846967cd3216
7
- data.tar.gz: aaf4e16c251f97d6d0678b277d68382b00c26a65d99ab7c385b1defb43df45e567c529a01d87cc908d6d9f25de11793612c69f513b872f2e1e4a65bdf8a63ab3
6
+ metadata.gz: 9bcadc9bb615c09ad13babacc2aa9d6b12fb0bf414288a738e10b2d606ac400cbd0b525dc56405ae1488129ce09edc33c78ca1101565f2d99a37b2a959c82129
7
+ data.tar.gz: 2b2610163cff45597f98923f8a0aa8134db231779478bccff7934c09a017a5ca01820fe40b0e07889f7f047508c0b126359a8ea3c89c227694704cccde67ab77
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0
4
- - 2.1
5
3
  - 2.2
6
4
  - ruby-head
5
+ - 2.0
6
+ - 2.1
7
7
  - rbx-2
@@ -1,6 +1,10 @@
1
1
  #include "uh.h"
2
2
 
3
3
 
4
+ #define SET_DISPLAY(x) \
5
+ UhDisplay *display;\
6
+ Data_Get_Struct(x, UhDisplay, display);
7
+
4
8
  #define DPY display->dpy
5
9
 
6
10
 
@@ -25,7 +29,7 @@ VALUE display_alloc(VALUE klass) {
25
29
 
26
30
 
27
31
  VALUE display_close(VALUE self) {
28
- set_display(self);
32
+ SET_DISPLAY(self);
29
33
 
30
34
  if (DPY) {
31
35
  XCloseDisplay(DPY);
@@ -38,9 +42,9 @@ VALUE display_close(VALUE self) {
38
42
  }
39
43
 
40
44
  VALUE display_color_by_name(VALUE self, VALUE rcolor) {
41
- set_display(self);
42
45
  Colormap map;
43
46
  XColor color;
47
+ SET_DISPLAY(self);
44
48
 
45
49
  map = DefaultColormap(DPY, SCREEN_DEFAULT);
46
50
 
@@ -51,8 +55,8 @@ VALUE display_color_by_name(VALUE self, VALUE rcolor) {
51
55
  }
52
56
 
53
57
  VALUE display_create_pixmap(VALUE self, VALUE width, VALUE height) {
54
- set_display(self);
55
58
  Pixmap pixmap;
59
+ SET_DISPLAY(self);
56
60
 
57
61
  pixmap = XCreatePixmap(DPY, ROOT_DEFAULT, FIX2INT(width), FIX2INT(height),
58
62
  DefaultDepth(DPY, SCREEN_DEFAULT)
@@ -62,20 +66,20 @@ VALUE display_create_pixmap(VALUE self, VALUE width, VALUE height) {
62
66
  }
63
67
 
64
68
  VALUE display_fileno(VALUE self) {
65
- set_display(self);
69
+ SET_DISPLAY(self);
66
70
 
67
71
  return INT2FIX(XConnectionNumber(DPY));
68
72
  }
69
73
 
70
74
  VALUE display_flush(VALUE self) {
71
- set_display(self);
75
+ SET_DISPLAY(self);
72
76
 
73
77
  return INT2FIX(XFlush(DPY));
74
78
  }
75
79
 
76
80
  VALUE display_each_event(VALUE self) {
77
- set_display(self);
78
81
  XEvent xev;
82
+ SET_DISPLAY(self);
79
83
 
80
84
  while (1) {
81
85
  XNextEvent(DPY, &xev);
@@ -86,9 +90,9 @@ VALUE display_each_event(VALUE self) {
86
90
  }
87
91
 
88
92
  VALUE display_grab_key(VALUE self, VALUE key, VALUE modifier) {
89
- set_display(self);
90
93
  KeySym ks;
91
94
  KeyCode kc;
95
+ SET_DISPLAY(self);
92
96
 
93
97
  ks = XStringToKeysym(RSTRING_PTR(key));
94
98
  if (ks == NoSymbol)
@@ -105,11 +109,11 @@ VALUE display_grab_key(VALUE self, VALUE key, VALUE modifier) {
105
109
  }
106
110
 
107
111
  VALUE display_listen_events(int argc, VALUE *argv, VALUE self) {
108
- set_display(self);
109
112
  VALUE arg1;
110
113
  VALUE arg2;
111
114
  Window window;
112
115
  long mask;
116
+ SET_DISPLAY(self);
113
117
 
114
118
  if (rb_scan_args(argc, argv, "11", &arg1, &arg2) == 2) {
115
119
  window = window_id(arg1);
@@ -126,8 +130,8 @@ VALUE display_listen_events(int argc, VALUE *argv, VALUE self) {
126
130
  }
127
131
 
128
132
  VALUE display_next_event(VALUE self) {
129
- set_display(self);
130
133
  XEvent xev;
134
+ SET_DISPLAY(self);
131
135
 
132
136
  XNextEvent(DPY, &xev);
133
137
 
@@ -135,7 +139,7 @@ VALUE display_next_event(VALUE self) {
135
139
  }
136
140
 
137
141
  VALUE display_open(VALUE self) {
138
- set_display(self);
142
+ SET_DISPLAY(self);
139
143
 
140
144
  if (!(DPY = XOpenDisplay(NULL))) {
141
145
  rb_raise(eDisplayError, "Can't open display");
@@ -147,15 +151,15 @@ VALUE display_open(VALUE self) {
147
151
  }
148
152
 
149
153
  VALUE display_pending(VALUE self) {
150
- set_display(self);
154
+ SET_DISPLAY(self);
151
155
 
152
156
  return INT2FIX(XPending(DPY));
153
157
  }
154
158
 
155
159
  VALUE display_query_font(VALUE self) {
156
- set_display(self);
157
160
  XFontStruct *xfs;
158
161
  VALUE font;
162
+ SET_DISPLAY(self);
159
163
 
160
164
  if (!(xfs = XQueryFont(DPY,
161
165
  XGContextFromGC(DefaultGC(DPY, SCREEN_DEFAULT)))))
@@ -168,17 +172,17 @@ VALUE display_query_font(VALUE self) {
168
172
  }
169
173
 
170
174
  VALUE display_root(VALUE self) {
171
- set_display(self);
175
+ SET_DISPLAY(self);
172
176
 
173
177
  return window_make(DPY, ROOT_DEFAULT);
174
178
  }
175
179
 
176
180
  VALUE display_screens(VALUE self) {
177
- set_display(self);
178
181
  XineramaScreenInfo *xsi;
179
182
  int n;
180
183
  VALUE screens = rb_ary_new();
181
184
  VALUE args[5];
185
+ SET_DISPLAY(self);
182
186
 
183
187
  if (XineramaIsActive(DPY)) {
184
188
  xsi = XineramaQueryScreens(DPY, &n);
@@ -207,7 +211,7 @@ VALUE display_screens(VALUE self) {
207
211
  }
208
212
 
209
213
  VALUE display_sync(VALUE self, VALUE discard) {
210
- set_display(self);
214
+ SET_DISPLAY(self);
211
215
 
212
216
  XSync(display->dpy, RTEST(discard));
213
217
 
@@ -1,7 +1,7 @@
1
1
  #include "uh.h"
2
2
 
3
3
 
4
- #define set_xev(x) \
4
+ #define SET_XEV(x) \
5
5
  XEvent *xev;\
6
6
  Data_Get_Struct(x, XEvent, xev);
7
7
 
@@ -18,7 +18,7 @@ VALUE event_make(XEvent *xev) {
18
18
  VALUE klass;
19
19
  void (*function)(VALUE self);
20
20
  } EvClass;
21
- EvClass ev_classes[] = {
21
+ EvClass ev_classes[] = {
22
22
  {ConfigureRequest, cConfigureRequest, event_make_configure_request},
23
23
  {DestroyNotify, cDestroyNotify, NULL},
24
24
  {Expose, cExpose, NULL},
@@ -28,8 +28,8 @@ VALUE event_make(XEvent *xev) {
28
28
  {PropertyNotify, cPropertyNotify, NULL},
29
29
  {UnmapNotify, cUnmapNotify, NULL}
30
30
  };
31
- int i;
32
- VALUE event;
31
+ unsigned int i;
32
+ VALUE event;
33
33
 
34
34
  for (i = 0; i < (sizeof ev_classes / sizeof ev_classes[0]); i++) {
35
35
  if (ev_classes[i].type == xev->type) {
@@ -46,8 +46,8 @@ VALUE event_make(XEvent *xev) {
46
46
  }
47
47
 
48
48
  VALUE event_make_event(VALUE klass, XEvent *xev) {
49
- char *type_descs[LASTEvent];
50
- VALUE event;
49
+ const char *type_descs[LASTEvent];
50
+ VALUE event;
51
51
 
52
52
  type_descs[KeyPress] = "key_press";
53
53
  type_descs[KeyRelease] = "key_release";
@@ -92,7 +92,7 @@ VALUE event_make_event(VALUE klass, XEvent *xev) {
92
92
  }
93
93
 
94
94
  void event_make_configure_request(VALUE self) {
95
- set_xev(self);
95
+ SET_XEV(self);
96
96
 
97
97
  if (xev->xconfigurerequest.value_mask & CWX)
98
98
  rb_ivar_set(self, rb_intern("@x"), INT2FIX(xev->xconfigurerequest.x));
@@ -117,8 +117,8 @@ void event_make_configure_request(VALUE self) {
117
117
  }
118
118
 
119
119
  void event_make_key_any(VALUE self) {
120
- set_xev(self);
121
120
  KeySym ks;
121
+ SET_XEV(self);
122
122
 
123
123
  ks = XkbKeycodeToKeysym(xev->xany.display, xev->xkey.keycode, 0, 0);
124
124
  if (ks == NoSymbol)
@@ -129,8 +129,8 @@ void event_make_key_any(VALUE self) {
129
129
  }
130
130
 
131
131
  void event_make_win_any(VALUE self) {
132
- set_xev(self);
133
132
  Window window;
133
+ SET_XEV(self);
134
134
 
135
135
  switch (xev->type) {
136
136
  case ConfigureRequest:
@@ -154,6 +154,9 @@ void event_make_win_any(VALUE self) {
154
154
  case UnmapNotify:
155
155
  window = xev->xunmap.window;
156
156
  break;
157
+ default:
158
+ window = xev->xany.window;
159
+ break;
157
160
  }
158
161
 
159
162
  rb_ivar_set(self, rb_intern("@window"),
@@ -3,8 +3,6 @@ require 'mkmf'
3
3
  fail 'libX11 is required' unless have_library 'X11'
4
4
  fail 'libXinerama is required' unless have_library 'Xinerama'
5
5
 
6
- # FIXME: -pendantic will warn "named variadic macros are a GNU extension"
7
- #$CFLAGS << ' -std=c99 -pedantic -Wall'
8
6
  $CFLAGS << ' -std=c99 -Wall'
9
7
  if %w[DEBUG VALGRIND].any? { |e| ENV.key? e }
10
8
  $CFLAGS.gsub! /-O\d\s/, '-g '
@@ -1,7 +1,7 @@
1
1
  #include "uh.h"
2
2
 
3
3
 
4
- #define set_pixmap(x) \
4
+ #define SET_PIXMAP(x) \
5
5
  UhPixmap *pixmap;\
6
6
  Data_Get_Struct(x, UhPixmap, pixmap);
7
7
 
@@ -14,7 +14,7 @@ void pixmap_deallocate(UhPixmap *p);
14
14
 
15
15
 
16
16
  VALUE pixmap_draw_rect(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h) {
17
- set_pixmap(self);
17
+ SET_PIXMAP(self)
18
18
 
19
19
  XFillRectangle(DPY, PIXMAP, GC,
20
20
  FIX2INT(x), FIX2INT(y), FIX2INT(w), FIX2INT(h)
@@ -24,7 +24,7 @@ VALUE pixmap_draw_rect(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h) {
24
24
  }
25
25
 
26
26
  VALUE pixmap_draw_string(VALUE self, VALUE x, VALUE y, VALUE str) {
27
- set_pixmap(self);
27
+ SET_PIXMAP(self)
28
28
 
29
29
  XDrawString(DPY, PIXMAP, GC,
30
30
  FIX2INT(x), FIX2INT(y), RSTRING_PTR(str), RSTRING_LEN(str)
@@ -34,7 +34,7 @@ VALUE pixmap_draw_string(VALUE self, VALUE x, VALUE y, VALUE str) {
34
34
  }
35
35
 
36
36
  VALUE pixmap_gc_black(VALUE self) {
37
- set_pixmap(self);
37
+ SET_PIXMAP(self)
38
38
 
39
39
  XSetForeground(DPY, GC, BlackPixel(DPY, SCREEN_DEFAULT));
40
40
 
@@ -42,7 +42,7 @@ VALUE pixmap_gc_black(VALUE self) {
42
42
  }
43
43
 
44
44
  VALUE pixmap_gc_color(VALUE self, VALUE rcolor) {
45
- set_pixmap(self);
45
+ SET_PIXMAP(self)
46
46
 
47
47
  XSetForeground(DPY, GC, NUM2LONG(rb_ivar_get(rcolor, rb_intern("@pixel"))));
48
48
 
@@ -50,7 +50,7 @@ VALUE pixmap_gc_color(VALUE self, VALUE rcolor) {
50
50
  }
51
51
 
52
52
  VALUE pixmap_gc_white(VALUE self) {
53
- set_pixmap(self);
53
+ SET_PIXMAP(self)
54
54
 
55
55
  XSetForeground(DPY, GC, WhitePixel(DPY, SCREEN_DEFAULT));
56
56
 
@@ -59,7 +59,7 @@ VALUE pixmap_gc_white(VALUE self) {
59
59
 
60
60
 
61
61
  VALUE pixmap__copy(VALUE self, VALUE rwindow_id, VALUE rwidth, VALUE rheight) {
62
- set_pixmap(self);
62
+ SET_PIXMAP(self)
63
63
 
64
64
  XCopyArea(DPY, PIXMAP, FIX2INT(rwindow_id), GC,
65
65
  0, 0, FIX2INT(rwidth), FIX2INT(rheight), 0, 0
@@ -9,10 +9,6 @@
9
9
  #include <X11/extensions/Xinerama.h>
10
10
 
11
11
 
12
- #define set_display(x) \
13
- UhDisplay *display;\
14
- Data_Get_Struct(x, UhDisplay, display);
15
-
16
12
  #define ROOT_DEFAULT DefaultRootWindow(DPY)
17
13
  #define SCREEN_DEFAULT DefaultScreen(DPY)
18
14
 
@@ -1,7 +1,7 @@
1
1
  #include "uh.h"
2
2
 
3
3
 
4
- #define set_window(x) \
4
+ #define SET_WINDOW(x) \
5
5
  UhWindow *window;\
6
6
  Data_Get_Struct(x, UhWindow, window);
7
7
 
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
  VALUE window_focus(VALUE self) {
13
- set_window(self);
13
+ SET_WINDOW(self);
14
14
 
15
15
  XSetInputFocus(DPY, WINDOW, RevertToPointerRoot, CurrentTime);
16
16
 
@@ -18,8 +18,8 @@ VALUE window_focus(VALUE self) {
18
18
  }
19
19
 
20
20
  VALUE window_icccm_wm_delete(VALUE self) {
21
- set_window(self);
22
21
  XEvent xev;
22
+ SET_WINDOW(self);
23
23
 
24
24
  xev.type = ClientMessage;
25
25
  xev.xclient.window = WINDOW;
@@ -33,12 +33,13 @@ VALUE window_icccm_wm_delete(VALUE self) {
33
33
  }
34
34
 
35
35
  VALUE window_icccm_wm_protocols(VALUE self) {
36
- set_window(self);
37
36
  Atom *win_protocols;
38
37
  int count;
39
38
  int i;
40
39
  char *atom_name;
41
- VALUE protocols = rb_ary_new();
40
+ VALUE protocols;
41
+ SET_WINDOW(self);
42
+ protocols = rb_ary_new();
42
43
 
43
44
  if (XGetWMProtocols(DPY, WINDOW, &win_protocols, &count)) {
44
45
  for (i = 0; i < count; i++) {
@@ -52,7 +53,7 @@ VALUE window_icccm_wm_protocols(VALUE self) {
52
53
  }
53
54
 
54
55
  VALUE window_kill(VALUE self) {
55
- set_window(self);
56
+ SET_WINDOW(self);
56
57
 
57
58
  XKillClient(DPY, WINDOW);
58
59
 
@@ -60,7 +61,7 @@ VALUE window_kill(VALUE self) {
60
61
  }
61
62
 
62
63
  VALUE window_map(VALUE self) {
63
- set_window(self);
64
+ SET_WINDOW(self);
64
65
 
65
66
  XMapWindow(DPY, WINDOW);
66
67
 
@@ -68,8 +69,8 @@ VALUE window_map(VALUE self) {
68
69
  }
69
70
 
70
71
  VALUE window_mask_set(VALUE self, VALUE mask) {
71
- set_window(self);
72
72
  XSetWindowAttributes attrs;
73
+ SET_WINDOW(self);
73
74
 
74
75
  attrs.event_mask = FIX2LONG(mask);
75
76
  XChangeWindowAttributes(DPY, WINDOW, CWEventMask, &attrs);
@@ -78,9 +79,9 @@ VALUE window_mask_set(VALUE self, VALUE mask) {
78
79
  }
79
80
 
80
81
  VALUE window_name(VALUE self) {
81
- set_window(self);
82
82
  char *wxname;
83
83
  VALUE wname;
84
+ SET_WINDOW(self);
84
85
 
85
86
  if (!XFetchName(DPY, WINDOW, &wxname))
86
87
  return Qnil;
@@ -92,8 +93,8 @@ VALUE window_name(VALUE self) {
92
93
  }
93
94
 
94
95
  VALUE window_override_redirect(VALUE self) {
95
- set_window(self);
96
96
  XWindowAttributes wa;
97
+ SET_WINDOW(self);
97
98
 
98
99
  if (!XGetWindowAttributes(DPY, WINDOW, &wa))
99
100
  return Qnil;
@@ -102,7 +103,7 @@ VALUE window_override_redirect(VALUE self) {
102
103
  }
103
104
 
104
105
  VALUE window_raise(VALUE self) {
105
- set_window(self);
106
+ SET_WINDOW(self);
106
107
 
107
108
  XRaiseWindow(DPY, WINDOW);
108
109
 
@@ -110,7 +111,7 @@ VALUE window_raise(VALUE self) {
110
111
  }
111
112
 
112
113
  VALUE window_unmap(VALUE self) {
113
- set_window(self);
114
+ SET_WINDOW(self);
114
115
 
115
116
  XUnmapWindow(DPY, WINDOW);
116
117
 
@@ -118,9 +119,9 @@ VALUE window_unmap(VALUE self) {
118
119
  }
119
120
 
120
121
  VALUE window_wclass(VALUE self) {
121
- set_window(self);
122
122
  XClassHint ch;
123
123
  VALUE wclass;
124
+ SET_WINDOW(self);
124
125
 
125
126
  if (!XGetClassHint(DPY, WINDOW, &ch))
126
127
  return Qnil;
@@ -134,9 +135,9 @@ VALUE window_wclass(VALUE self) {
134
135
 
135
136
 
136
137
  VALUE window__configure(VALUE self, VALUE rx, VALUE ry, VALUE rw, VALUE rh) {
137
- set_window(self);
138
138
  XWindowChanges wc;
139
139
  unsigned int mask;
140
+ SET_WINDOW(self);
140
141
 
141
142
  mask = CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWStackMode;
142
143
  wc.x = FIX2INT(rx);
@@ -151,8 +152,8 @@ VALUE window__configure(VALUE self, VALUE rx, VALUE ry, VALUE rw, VALUE rh) {
151
152
  }
152
153
 
153
154
  VALUE window__configure_event(VALUE self, VALUE rx, VALUE ry, VALUE rw, VALUE rh) {
154
- set_window(self);
155
155
  XConfigureEvent ev;
156
+ SET_WINDOW(self);
156
157
 
157
158
  ev.type = ConfigureNotify;
158
159
  ev.display = DPY;
@@ -171,9 +172,9 @@ VALUE window__configure_event(VALUE self, VALUE rx, VALUE ry, VALUE rw, VALUE rh
171
172
  }
172
173
 
173
174
  VALUE window__create_sub(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h) {
174
- set_window(self);
175
175
  XSetWindowAttributes wa;
176
176
  Window sub_win;
177
+ SET_WINDOW(self);
177
178
 
178
179
  wa.override_redirect = True;
179
180
  wa.background_pixmap = ParentRelative;
@@ -189,8 +190,8 @@ VALUE window__create_sub(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h) {
189
190
  }
190
191
 
191
192
  VALUE window__moveresize(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height) {
192
- set_window(self);
193
193
  XWindowChanges wc;
194
+ SET_WINDOW(self);
194
195
 
195
196
  wc.x = NUM2INT(x);
196
197
  wc.y = NUM2INT(y);
@@ -203,7 +204,7 @@ VALUE window__moveresize(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height
203
204
 
204
205
 
205
206
  int window_id(VALUE self) {
206
- set_window(self);
207
+ SET_WINDOW(self);
207
208
 
208
209
  return WINDOW;
209
210
  }
@@ -36,6 +36,7 @@ module Uh
36
36
  private
37
37
 
38
38
  def check_value(name, value)
39
+ return if value.nil?
39
40
  fail ArgumentError, "invalid #{name.to_s}: #{value}" unless value > 0
40
41
  end
41
42
  end
@@ -1,3 +1,3 @@
1
1
  module Uh
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.5'.freeze
3
3
  end
@@ -11,6 +11,10 @@ describe Uh::Geo do
11
11
  it 'raises error when invalid height is given' do
12
12
  assert_raises(Uh::ArgumentError) { Uh::Geo.new(0, 0, 640, 0) }
13
13
  end
14
+
15
+ it 'builds a geo without arguments' do
16
+ assert_instance_of Uh::Geo, Uh::Geo.new
17
+ end
14
18
  end
15
19
 
16
20
  describe '.format_xgeometry' do
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: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-04 00:00:00.000000000 Z
11
+ date: 2015-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake