ruby-wmctrl 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4cf9848c86b0484717aa10282cad3b80d6fe4ea7
4
+ data.tar.gz: 893e41f4b1da558a574473149ba4109a1a13f351
5
+ SHA512:
6
+ metadata.gz: b208af445e7333c390ea5ef42780e8f9738070520599ce4ee1957b09c5e130b8393ff0572f3ac5c933cf6bcd22d0ebc27e710af0d07e914c9488f0a62ac9a544
7
+ data.tar.gz: 8286f7c16f86ffad0169ede09ce432a926fca52d8bc02e5c63121c089711b1d035ee8d0114606567be12458ec21eaefc15cee8dd2cd6e3aa619cf35ad0ce480d
@@ -168,7 +168,7 @@ end
168
168
 
169
169
  case options[:mode]
170
170
  when :list_windows
171
- windows = wm.list_windows(true)
171
+ windows = wm.windows
172
172
  str_class_size = windows.map { |w| w[:class].to_s.size }.max
173
173
  windows.each do |win|
174
174
  s = ''
@@ -238,6 +238,129 @@ static gchar *get_window_title (Display *disp, Window win)
238
238
  return title_utf8;
239
239
  }
240
240
 
241
+ static VALUE get_window_hash_data (Window win, Display *disp, Window window_active, int get_state)
242
+ {
243
+ VALUE window_obj = rb_hash_new();
244
+ gchar *title_utf8 = get_window_title(disp, win); /* UTF8 */
245
+ gchar *client_machine;
246
+ gchar *class_out = get_window_class(disp, win); /* UTF8 */
247
+ unsigned long *desktop;
248
+
249
+ if ((int) window_active < 0) {
250
+ window_active = get_active_window(disp);
251
+ }
252
+
253
+ rb_hash_aset(window_obj, key_id, INT2NUM(win));
254
+ rb_hash_aset(window_obj, key_title, (title_utf8 ? RB_UTF8_STRING_NEW2(title_utf8) : Qnil));
255
+ rb_hash_aset(window_obj, key_class, (class_out ? RB_UTF8_STRING_NEW2(class_out) : Qnil));
256
+
257
+ if (window_active == win) {
258
+ rb_hash_aset(window_obj, key_active, Qtrue);
259
+ } else {
260
+ rb_hash_aset(window_obj, key_active, Qnil);
261
+ }
262
+
263
+ /* desktop ID */
264
+ if ((desktop = (unsigned long *)get_property(disp, win,
265
+ XA_CARDINAL, "_NET_WM_DESKTOP", NULL)) == NULL) {
266
+ desktop = (unsigned long *)get_property(disp, win, XA_CARDINAL, "_WIN_WORKSPACE", NULL);
267
+ }
268
+ /* special desktop ID -1 means "all desktops", so we
269
+ have to convert the desktop value to signed long */
270
+ rb_hash_aset(window_obj, key_desktop, INT2NUM(desktop ? (signed long)*desktop : 0));
271
+
272
+ /* client machine */
273
+ client_machine = get_property(disp, win, XA_STRING, "WM_CLIENT_MACHINE", NULL);
274
+ rb_hash_aset(window_obj, key_client_machine, (client_machine ? RB_UTF8_STRING_NEW2(client_machine) : Qnil));
275
+
276
+ if (get_state) {
277
+ unsigned long *pid;
278
+ int x, y, junkx, junky;
279
+ unsigned long j;
280
+ unsigned int wwidth, wheight, bw, depth;
281
+ Window junkroot;
282
+ unsigned long state_size;
283
+ Atom *window_state;
284
+ gchar *state_name;
285
+ VALUE state_ary;
286
+ Atom *extents;
287
+ unsigned long extents_size;
288
+ VALUE extents_ary;
289
+ Atom *strut;
290
+ unsigned long strut_size;
291
+ VALUE strut_ary;
292
+
293
+ /* pid */
294
+ pid = (unsigned long *)get_property(disp, win, XA_CARDINAL, "_NET_WM_PID", NULL);
295
+ rb_hash_aset(window_obj, key_pid, (pid ? ULONG2NUM(*pid) : Qnil));
296
+ g_free(pid);
297
+
298
+ /* geometry */
299
+ XGetGeometry (disp, win, &junkroot, &junkx, &junky, &wwidth, &wheight, &bw, &depth);
300
+ XTranslateCoordinates (disp, win, junkroot, -bw, -bw, &x, &y, &junkroot);
301
+
302
+ rb_hash_aset(window_obj, key_geometry,
303
+ rb_ary_new3(4, INT2NUM(x), INT2NUM(y), INT2NUM(wwidth), INT2NUM(wheight)));
304
+
305
+ /* state */
306
+ if ((window_state = (Atom *)get_property(disp, win,
307
+ XA_ATOM, "_NET_WM_STATE", &state_size)) != NULL) {
308
+ state_ary = rb_ary_new();
309
+ for (j = 0; j < state_size / sizeof(Atom); j++) {
310
+ state_name = XGetAtomName(disp, window_state[j]);
311
+ rb_ary_push(state_ary, rb_str_new2(state_name));
312
+ g_free(state_name);
313
+ }
314
+ g_free(window_state);
315
+ } else {
316
+ state_ary = Qnil;
317
+ }
318
+ rb_hash_aset(window_obj, key_state, state_ary);
319
+
320
+ /* frame extents */
321
+ if ((extents = (unsigned long *)get_property(disp, win,
322
+ XA_CARDINAL, "_NET_FRAME_EXTENTS", &extents_size)) != NULL) {
323
+ extents_ary = rb_ary_new();
324
+ for (j = 0; j < extents_size / sizeof(unsigned long); j++) {
325
+ rb_ary_push(extents_ary, ULONG2NUM(extents[j]));
326
+ }
327
+ /* exterior frame */
328
+ if (extents) {
329
+ rb_hash_aset(window_obj, key_exterior_frame,
330
+ rb_ary_new3(4, INT2NUM(x - (int)extents[0]), INT2NUM(y - (int)extents[2]),
331
+ INT2NUM(wwidth + (int)extents[0] + (int)extents[1]),
332
+ INT2NUM(wheight + (int)extents[2] + (int)extents[3])));
333
+ }
334
+ g_free(extents);
335
+ } else {
336
+ extents_ary = Qnil;
337
+ }
338
+ rb_hash_aset(window_obj, key_frame_extents, extents_ary);
339
+
340
+ /* strut partial or strut */
341
+ if ((strut = (unsigned long *)get_property(disp, win,
342
+ XA_CARDINAL, "_NET_WM_STRUT_PARTIAL", &strut_size)) == NULL) {
343
+ strut = (unsigned long *)get_property(disp, win, XA_CARDINAL, "_NET_WM_STRUT", &strut_size);
344
+ }
345
+ if (strut) {
346
+ strut_ary = rb_ary_new();
347
+ for (j = 0; j < strut_size / sizeof(unsigned long); j++) {
348
+ rb_ary_push(strut_ary, ULONG2NUM(strut[j]));
349
+ }
350
+ g_free(strut);
351
+ } else {
352
+ strut_ary = Qnil;
353
+ }
354
+ rb_hash_aset(window_obj, key_strut, strut_ary);
355
+ }
356
+
357
+ g_free(title_utf8);
358
+ g_free(desktop);
359
+ g_free(client_machine);
360
+ g_free(class_out);
361
+ return window_obj;
362
+ }
363
+
241
364
  /*
242
365
  @overload list_windows(get_state = nil)
243
366
 
@@ -268,128 +391,25 @@ static VALUE rb_wmctrl_list_windows (int argc, VALUE *argv, VALUE self) {
268
391
  window_ary = rb_ary_new2(client_list_size);
269
392
 
270
393
  for (i = 0; i < client_list_size / sizeof(Window); i++) {
271
- VALUE window_obj = rb_hash_new();
272
- gchar *title_utf8 = get_window_title(disp, client_list[i]); /* UTF8 */
273
- gchar *client_machine;
274
- gchar *class_out = get_window_class(disp, client_list[i]); /* UTF8 */
275
- unsigned long *desktop;
276
-
277
- rb_hash_aset(window_obj, key_id, INT2NUM(client_list[i]));
278
- rb_hash_aset(window_obj, key_title, (title_utf8 ? RB_UTF8_STRING_NEW2(title_utf8) : Qnil));
279
- rb_hash_aset(window_obj, key_class, (class_out ? RB_UTF8_STRING_NEW2(class_out) : Qnil));
280
-
281
- if (window_active == client_list[i]) {
282
- rb_hash_aset(window_obj, key_active, Qtrue);
283
- } else {
284
- rb_hash_aset(window_obj, key_active, Qnil);
285
- }
286
-
287
- /* desktop ID */
288
- if ((desktop = (unsigned long *)get_property(disp, client_list[i],
289
- XA_CARDINAL, "_NET_WM_DESKTOP", NULL)) == NULL) {
290
- desktop = (unsigned long *)get_property(disp, client_list[i], XA_CARDINAL, "_WIN_WORKSPACE", NULL);
291
- }
292
- /* special desktop ID -1 means "all desktops", so we
293
- have to convert the desktop value to signed long */
294
- rb_hash_aset(window_obj, key_desktop, INT2NUM(desktop ? (signed long)*desktop : 0));
295
-
296
- /* client machine */
297
- client_machine = get_property(disp, client_list[i], XA_STRING, "WM_CLIENT_MACHINE", NULL);
298
- rb_hash_aset(window_obj, key_client_machine, (client_machine ? RB_UTF8_STRING_NEW2(client_machine) : Qnil));
299
-
300
- if (get_state) {
301
- unsigned long *pid;
302
- int x, y, junkx, junky;
303
- unsigned long j;
304
- unsigned int wwidth, wheight, bw, depth;
305
- Window junkroot;
306
- unsigned long state_size;
307
- Atom *window_state;
308
- gchar *state_name;
309
- VALUE state_ary;
310
- Atom *extents;
311
- unsigned long extents_size;
312
- VALUE extents_ary;
313
- Atom *strut;
314
- unsigned long strut_size;
315
- VALUE strut_ary;
316
-
317
- /* pid */
318
- pid = (unsigned long *)get_property(disp, client_list[i], XA_CARDINAL, "_NET_WM_PID", NULL);
319
- rb_hash_aset(window_obj, key_pid, (pid ? ULONG2NUM(*pid) : Qnil));
320
- g_free(pid);
321
-
322
- /* geometry */
323
- XGetGeometry (disp, client_list[i], &junkroot, &junkx, &junky, &wwidth, &wheight, &bw, &depth);
324
- XTranslateCoordinates (disp, client_list[i], junkroot, -bw, -bw, &x, &y, &junkroot);
325
-
326
- rb_hash_aset(window_obj, key_geometry,
327
- rb_ary_new3(4, INT2NUM(x), INT2NUM(y), INT2NUM(wwidth), INT2NUM(wheight)));
328
-
329
- /* state */
330
- if ((window_state = (Atom *)get_property(disp, client_list[i],
331
- XA_ATOM, "_NET_WM_STATE", &state_size)) != NULL) {
332
- state_ary = rb_ary_new();
333
- for (j = 0; j < state_size / sizeof(Atom); j++) {
334
- state_name = XGetAtomName(disp, window_state[j]);
335
- rb_ary_push(state_ary, rb_str_new2(state_name));
336
- g_free(state_name);
337
- }
338
- g_free(window_state);
339
- } else {
340
- state_ary = Qnil;
341
- }
342
- rb_hash_aset(window_obj, key_state, state_ary);
343
-
344
- /* frame extents */
345
- if ((extents = (unsigned long *)get_property(disp, client_list[i],
346
- XA_CARDINAL, "_NET_FRAME_EXTENTS", &extents_size)) != NULL) {
347
- extents_ary = rb_ary_new();
348
- for (j = 0; j < extents_size / sizeof(unsigned long); j++) {
349
- rb_ary_push(extents_ary, ULONG2NUM(extents[j]));
350
- }
351
- /* exterior frame */
352
- if (extents) {
353
- rb_hash_aset(window_obj, key_exterior_frame,
354
- rb_ary_new3(4, INT2NUM(x - (int)extents[0]), INT2NUM(y - (int)extents[2]),
355
- INT2NUM(wwidth + (int)extents[0] + (int)extents[1]),
356
- INT2NUM(wheight + (int)extents[2] + (int)extents[3])));
357
- }
358
- g_free(extents);
359
- } else {
360
- extents_ary = Qnil;
361
- }
362
- rb_hash_aset(window_obj, key_frame_extents, extents_ary);
363
-
364
- /* strut partial or strut */
365
- if ((strut = (unsigned long *)get_property(disp, client_list[i],
366
- XA_CARDINAL, "_NET_WM_STRUT_PARTIAL", &strut_size)) == NULL) {
367
- strut = (unsigned long *)get_property(disp, client_list[i], XA_CARDINAL, "_NET_WM_STRUT", &strut_size);
368
- }
369
- if (strut) {
370
- strut_ary = rb_ary_new();
371
- for (j = 0; j < strut_size / sizeof(unsigned long); j++) {
372
- rb_ary_push(strut_ary, ULONG2NUM(strut[j]));
373
- }
374
- g_free(strut);
375
- } else {
376
- strut_ary = Qnil;
377
- }
378
- rb_hash_aset(window_obj, key_strut, strut_ary);
379
- }
380
-
381
- rb_ary_push(window_ary, window_obj);
382
-
383
- g_free(title_utf8);
384
- g_free(desktop);
385
- g_free(client_machine);
386
- g_free(class_out);
394
+ rb_ary_push(window_ary, get_window_hash_data(client_list[i], disp, window_active, get_state));
387
395
  }
388
396
  g_free(client_list);
389
397
 
390
398
  return window_ary;
391
399
  }
392
400
 
401
+ /*
402
+ @return [Hash] Hash of specified window data
403
+ */
404
+ static VALUE rb_wmctrl_get_window_data (VALUE self, VALUE win_id_obj) {
405
+ Display **ptr, *disp;
406
+ Window win_id;
407
+ win_id = (Window) NUM2LONG(win_id_obj);
408
+ Data_Get_Struct(self, Display*, ptr);
409
+ disp = *ptr;
410
+ return get_window_hash_data(win_id, disp, -1, TRUE);
411
+ }
412
+
393
413
  /*
394
414
  Get list of information of desktops.
395
415
 
@@ -1272,6 +1292,7 @@ void Init_wmctrl()
1272
1292
  rb_define_private_method(rb_wmctrl_class, "initialize", rb_wmctrl_initialize, -1);
1273
1293
 
1274
1294
  rb_define_method(rb_wmctrl_class, "list_windows", rb_wmctrl_list_windows, -1);
1295
+ rb_define_method(rb_wmctrl_class, "get_window_data", rb_wmctrl_get_window_data, 1);
1275
1296
  rb_define_method(rb_wmctrl_class, "list_desktops", rb_wmctrl_list_desktops, 0);
1276
1297
  rb_define_method(rb_wmctrl_class, "switch_desktop", rb_wmctrl_switch_desktop, 1);
1277
1298
  rb_define_method(rb_wmctrl_class, "info", rb_wmctrl_info, 0);
@@ -1,3 +1,3 @@
1
1
  class WMCtrl
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -16,13 +16,41 @@ class WMCtrl
16
16
  end
17
17
 
18
18
  class Desktop < DataHash
19
+ # Valid keys of the method [] are :id, :current, :title, :geometry, :viewport, and :workarea.
20
+
19
21
  [:id, :current, :title, :geometry, :viewport, :workarea].each do |key|
20
22
  define_method(key) do
21
23
  self[key]
22
24
  end
23
25
  end
24
26
 
25
- # Valid keys of the method[] are :id, :current, :title, :geometry, :viewport, and :workarea.
27
+ def geometry_width
28
+ self[:geometry][0]
29
+ end
30
+
31
+ def geometry_height
32
+ self[:geometry][1]
33
+ end
34
+
35
+ # @return [Integer] X coordinate of Top left corner of workarea
36
+ def workarea_x
37
+ self[:workarea][0]
38
+ end
39
+
40
+ # @return [Integer] Y coordinate of Top left corner of workarea
41
+ def workarea_y
42
+ self[:workarea][1]
43
+ end
44
+
45
+ # @return [Integer] Width of workarea
46
+ def workarea_width
47
+ self[:workarea][2]
48
+ end
49
+
50
+ # @return [Integer] Height of workarea
51
+ def workarea_height
52
+ self[:workarea][3]
53
+ end
26
54
  end
27
55
 
28
56
  class Window < DataHash
@@ -57,8 +85,16 @@ class WMCtrl
57
85
  self[:active]
58
86
  end
59
87
 
88
+ STATE_FULLSCREEN = "_NET_WM_STATE_FULLSCREEN"
89
+
90
+ def fullscreen?
91
+ self[:state].include?(STATE_FULLSCREEN)
92
+ end
93
+
60
94
  def action(*args)
61
95
  WMCtrl.instance.action_window(self[:id], *args)
96
+ @data = WMCtrl.instance.get_window_data(self[:id])
97
+ self
62
98
  end
63
99
  private :action
64
100
 
@@ -100,6 +136,11 @@ class WMCtrl
100
136
  y = opts[:y] if opts[:y] && (opts[:y] != y)
101
137
  action(:move_resize, 0, x + self[:frame_extents][0], y + self[:frame_extents][1], width - extent_horizontal, height - extent_vertical)
102
138
  end
139
+
140
+ def position
141
+ a = self[:exterior_frame]
142
+ { :x => a[0], :y => a[1], :width => a[2], :height => a[3] }
143
+ end
103
144
  end
104
145
 
105
146
  # @return [Array] An array of WMCtrl::Desktop
@@ -2,25 +2,24 @@
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
  require "wmctrl/version"
4
4
 
5
- Gem::Specification.new do |s|
6
- s.name = "ruby-wmctrl"
7
- s.version = WMCtrl::VERSION
8
- s.authors = ["Takayuki YAMAGUCHI"]
9
- s.email = ["d@ytak.info"]
10
- s.homepage = ""
11
- s.summary = "Ruby bindings to control windows"
12
- s.description = "Ruby bindings to control windows in EWMH and NetWM compatible X Window manager, which is created from source code of wmctrl command."
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruby-wmctrl"
7
+ spec.version = WMCtrl::VERSION
8
+ spec.authors = ["Takayuki YAMAGUCHI"]
9
+ spec.email = ["d@ytak.info"]
10
+ spec.homepage = ""
11
+ spec.summary = "Ruby bindings to control windows"
12
+ spec.description = "Ruby bindings to control windows in EWMH and NetWM compatible X Window manager, which is created from source code of wmctrl command."
13
+ spec.license = "GPLv2"
13
14
 
14
- s.rubyforge_project = "ruby-wmctrl"
15
-
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib", "ext"]
20
- s.extensions = Dir.glob("ext/**/extconf.rb")
15
+ spec.files = `git ls-files`.split("\n")
16
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ spec.require_paths = ["lib", "ext"]
19
+ spec.extensions = Dir.glob("ext/**/extconf.rb")
21
20
 
22
21
  # specify any dependencies here; for example:
23
- s.add_development_dependency "rspec"
24
- s.add_development_dependency "yard"
25
- s.add_runtime_dependency "pkg-config"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "yard"
24
+ spec.add_runtime_dependency "pkg-config"
26
25
  end
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-wmctrl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
5
- prerelease:
4
+ version: 0.0.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Takayuki YAMAGUCHI
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-08 00:00:00.000000000 Z
11
+ date: 2013-11-05 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: yard
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: pkg-config
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: Ruby bindings to control windows in EWMH and NetWM compatible X Window
@@ -69,8 +62,8 @@ extensions:
69
62
  - ext/extconf.rb
70
63
  extra_rdoc_files: []
71
64
  files:
72
- - .gitignore
73
- - .yardopts
65
+ - ".gitignore"
66
+ - ".yardopts"
74
67
  - COPYING
75
68
  - Gemfile
76
69
  - README.md
@@ -99,29 +92,29 @@ files:
99
92
  - spec/spec_helper.rb
100
93
  - spec/wmctrl_spec.rb
101
94
  homepage: ''
102
- licenses: []
95
+ licenses:
96
+ - GPLv2
97
+ metadata: {}
103
98
  post_install_message:
104
99
  rdoc_options: []
105
100
  require_paths:
106
101
  - lib
107
102
  - ext
108
103
  required_ruby_version: !ruby/object:Gem::Requirement
109
- none: false
110
104
  requirements:
111
- - - '>='
105
+ - - ">="
112
106
  - !ruby/object:Gem::Version
113
107
  version: '0'
114
108
  required_rubygems_version: !ruby/object:Gem::Requirement
115
- none: false
116
109
  requirements:
117
- - - '>='
110
+ - - ">="
118
111
  - !ruby/object:Gem::Version
119
112
  version: '0'
120
113
  requirements: []
121
- rubyforge_project: ruby-wmctrl
122
- rubygems_version: 1.8.25
114
+ rubyforge_project:
115
+ rubygems_version: 2.0.3
123
116
  signing_key:
124
- specification_version: 3
117
+ specification_version: 4
125
118
  summary: Ruby bindings to control windows
126
119
  test_files: []
127
120
  has_rdoc: