ruby-wmctrl 0.0.2 → 0.0.3
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/wmctrl.c +135 -32
- data/lib/wmctrl/version.rb +1 -1
- data/sample/list_windows.rb +4 -0
- data/sample/supported.rb +6 -0
- metadata +9 -8
data/ext/wmctrl.c
CHANGED
@@ -52,7 +52,8 @@ static Window get_target_window (Display *disp, VALUE obj);
|
|
52
52
|
|
53
53
|
static VALUE rb_wmctrl_class, key_id, key_title, key_pid, key_geometry,
|
54
54
|
key_active, key_class, key_client_machine, key_desktop,
|
55
|
-
key_viewport, key_workarea, key_current, key_showing_desktop, key_name
|
55
|
+
key_viewport, key_workarea, key_current, key_showing_desktop, key_name,
|
56
|
+
key_state, key_frame_extents, key_strut;
|
56
57
|
|
57
58
|
static ID id_select, id_active, id_activate, id_close, id_move_resize,
|
58
59
|
id_change_state, id_move_to_desktop, id_move_to_current,
|
@@ -235,17 +236,25 @@ static gchar *get_window_title (Display *disp, Window win)
|
|
235
236
|
return title_utf8;
|
236
237
|
}
|
237
238
|
|
238
|
-
/*
|
239
|
-
|
239
|
+
/*
|
240
|
+
call-seq:
|
241
|
+
wm.list_windows(get_state = nil)
|
242
|
+
|
243
|
+
Get list of information of windows.
|
244
|
+
@param get_state [Boolean] If the value is true then we get some properties at the same time
|
245
|
+
*/
|
246
|
+
static VALUE rb_wmctrl_list_windows (int argc, VALUE *argv, VALUE self) {
|
240
247
|
Display **ptr, *disp;
|
241
248
|
Window *client_list;
|
242
249
|
Window window_active;
|
243
250
|
unsigned long client_list_size;
|
244
251
|
unsigned int i;
|
245
|
-
|
246
|
-
|
252
|
+
int get_state;
|
253
|
+
VALUE get_state_obj, window_ary;
|
247
254
|
Data_Get_Struct(self, Display*, ptr);
|
248
255
|
disp = *ptr;
|
256
|
+
rb_scan_args(argc, argv, "01", &get_state_obj);
|
257
|
+
get_state = RTEST(get_state_obj);
|
249
258
|
|
250
259
|
if ((client_list = get_client_list(disp, &client_list_size)) == NULL) {
|
251
260
|
/* return EXIT_FAILURE; */
|
@@ -260,14 +269,8 @@ static VALUE rb_wmctrl_list_windows (VALUE self) {
|
|
260
269
|
gchar *title_utf8 = get_window_title(disp, client_list[i]); /* UTF8 */
|
261
270
|
gchar *client_machine;
|
262
271
|
gchar *class_out = get_window_class(disp, client_list[i]); /* UTF8 */
|
263
|
-
unsigned long *pid;
|
264
272
|
unsigned long *desktop;
|
265
|
-
int x, y, junkx, junky;
|
266
|
-
unsigned int wwidth, wheight, bw, depth;
|
267
|
-
Window junkroot;
|
268
273
|
|
269
|
-
/* Use strings of hexadecimal number? At the present we use simply integers. */
|
270
|
-
/* printf("0x%.8lx", client_list[i]); */
|
271
274
|
rb_hash_aset(window_obj, key_id, INT2NUM(client_list[i]));
|
272
275
|
rb_hash_aset(window_obj, key_title, (title_utf8 ? RB_UTF8_STRING_NEW2(title_utf8) : Qnil));
|
273
276
|
rb_hash_aset(window_obj, key_class, (class_out ? RB_UTF8_STRING_NEW2(class_out) : Qnil));
|
@@ -291,16 +294,79 @@ static VALUE rb_wmctrl_list_windows (VALUE self) {
|
|
291
294
|
client_machine = get_property(disp, client_list[i], XA_STRING, "WM_CLIENT_MACHINE", NULL);
|
292
295
|
rb_hash_aset(window_obj, key_client_machine, (client_machine ? RB_UTF8_STRING_NEW2(client_machine) : Qnil));
|
293
296
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
297
|
+
if (get_state) {
|
298
|
+
unsigned long *pid;
|
299
|
+
int x, y, junkx, junky;
|
300
|
+
unsigned long j;
|
301
|
+
unsigned int wwidth, wheight, bw, depth;
|
302
|
+
Window junkroot;
|
303
|
+
unsigned long state_size;
|
304
|
+
Atom *window_state;
|
305
|
+
gchar *state_name;
|
306
|
+
VALUE state_ary;
|
307
|
+
Atom *extents;
|
308
|
+
unsigned long extents_size;
|
309
|
+
VALUE extents_ary;
|
310
|
+
Atom *strut;
|
311
|
+
unsigned long strut_size;
|
312
|
+
VALUE strut_ary;
|
313
|
+
|
314
|
+
/* pid */
|
315
|
+
pid = (unsigned long *)get_property(disp, client_list[i], XA_CARDINAL, "_NET_WM_PID", NULL);
|
316
|
+
rb_hash_aset(window_obj, key_pid, (pid ? ULONG2NUM(*pid) : Qnil));
|
317
|
+
g_free(pid);
|
318
|
+
|
319
|
+
/* geometry */
|
320
|
+
XGetGeometry (disp, client_list[i], &junkroot, &junkx, &junky, &wwidth, &wheight, &bw, &depth);
|
321
|
+
XTranslateCoordinates (disp, client_list[i], junkroot, junkx, junky, &x, &y, &junkroot);
|
322
|
+
|
323
|
+
rb_hash_aset(window_obj, key_geometry,
|
324
|
+
rb_ary_new3(4, INT2NUM(x), INT2NUM(y), INT2NUM(wwidth), INT2NUM(wheight)));
|
325
|
+
|
326
|
+
/* state */
|
327
|
+
if ((window_state = (Atom *)get_property(disp, client_list[i],
|
328
|
+
XA_ATOM, "_NET_WM_STATE", &state_size)) != NULL) {
|
329
|
+
state_ary = rb_ary_new();
|
330
|
+
for (j = 0; j < state_size / sizeof(Atom); j++) {
|
331
|
+
state_name = XGetAtomName(disp, window_state[j]);
|
332
|
+
rb_ary_push(state_ary, rb_str_new2(state_name));
|
333
|
+
g_free(state_name);
|
334
|
+
}
|
335
|
+
g_free(window_state);
|
336
|
+
} else {
|
337
|
+
state_ary = Qnil;
|
338
|
+
}
|
339
|
+
rb_hash_aset(window_obj, key_state, state_ary);
|
340
|
+
|
341
|
+
/* frame extents */
|
342
|
+
if ((extents = (unsigned long *)get_property(disp, client_list[i],
|
343
|
+
XA_CARDINAL, "_NET_FRAME_EXTENTS", &extents_size)) != NULL) {
|
344
|
+
extents_ary = rb_ary_new();
|
345
|
+
for (j = 0; j < extents_size / sizeof(unsigned long); j++) {
|
346
|
+
rb_ary_push(extents_ary, ULONG2NUM(extents[j]));
|
347
|
+
}
|
348
|
+
g_free(extents);
|
349
|
+
} else {
|
350
|
+
extents_ary = Qnil;
|
351
|
+
}
|
352
|
+
rb_hash_aset(window_obj, key_frame_extents, extents_ary);
|
301
353
|
|
302
|
-
|
303
|
-
|
354
|
+
/* strut partial or strut */
|
355
|
+
if ((strut = (unsigned long *)get_property(disp, client_list[i],
|
356
|
+
XA_CARDINAL, "_NET_WM_STRUT_PARTIAL", &strut_size)) == NULL) {
|
357
|
+
strut = (unsigned long *)get_property(disp, client_list[i], XA_CARDINAL, "_NET_WM_STRUT", &strut_size);
|
358
|
+
}
|
359
|
+
if (strut) {
|
360
|
+
strut_ary = rb_ary_new();
|
361
|
+
for (j = 0; j < strut_size / sizeof(unsigned long); j++) {
|
362
|
+
rb_ary_push(strut_ary, ULONG2NUM(strut[j]));
|
363
|
+
}
|
364
|
+
g_free(strut);
|
365
|
+
} else {
|
366
|
+
strut_ary = Qnil;
|
367
|
+
}
|
368
|
+
rb_hash_aset(window_obj, key_strut, strut_ary);
|
369
|
+
}
|
304
370
|
|
305
371
|
rb_ary_push(window_ary, window_obj);
|
306
372
|
|
@@ -308,7 +374,6 @@ static VALUE rb_wmctrl_list_windows (VALUE self) {
|
|
308
374
|
g_free(desktop);
|
309
375
|
g_free(client_machine);
|
310
376
|
g_free(class_out);
|
311
|
-
g_free(pid);
|
312
377
|
}
|
313
378
|
g_free(client_list);
|
314
379
|
|
@@ -1097,16 +1162,24 @@ static Window get_target_window (Display *disp, VALUE obj)
|
|
1097
1162
|
|
1098
1163
|
/*
|
1099
1164
|
call-seq:
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1165
|
+
wm.action_window(wid, cmd, *args)
|
1166
|
+
|
1167
|
+
Manage windows.
|
1168
|
+
@param wid Window ID
|
1169
|
+
@param cmd [Symbol] Symbol of command
|
1170
|
+
@param args [Array] Arguments for the command
|
1171
|
+
|
1172
|
+
@example
|
1173
|
+
wm.action_window(wid, :close)
|
1174
|
+
wm.action_window(wid, :move_resize, grav, x, y, w, h)
|
1175
|
+
wm.action_window(wid, :change_state, add, prop1, prop2 = nil)
|
1176
|
+
wm.action_window(wid, :change_state, remove, prop1, prop2 = nil)
|
1177
|
+
wm.action_window(wid, :change_state, toggle, prop1, prop2 = nil)
|
1178
|
+
wm.action_window(wid, :move_to_desktop, desktop_id)
|
1179
|
+
wm.action_window(wid, :move_to_current)
|
1180
|
+
wm.action_window(wid, :set_title_long, str)
|
1181
|
+
wm.action_window(wid, :set_title_short, str)
|
1182
|
+
wm.action_window(wid, :set_title_both, str)
|
1110
1183
|
*/
|
1111
1184
|
static VALUE rb_wmctrl_action_window(int argc, VALUE *argv, VALUE self) {
|
1112
1185
|
Window wid;
|
@@ -1148,6 +1221,32 @@ static VALUE rb_wmctrl_action_window(int argc, VALUE *argv, VALUE self) {
|
|
1148
1221
|
}
|
1149
1222
|
}
|
1150
1223
|
|
1224
|
+
static VALUE rb_wmctrl_supported (VALUE self)
|
1225
|
+
{
|
1226
|
+
Atom *list;
|
1227
|
+
unsigned long size;
|
1228
|
+
unsigned int i;
|
1229
|
+
gchar *prop_name;
|
1230
|
+
VALUE ret;
|
1231
|
+
Display **ptr, *disp;
|
1232
|
+
Data_Get_Struct(self, Display*, ptr);
|
1233
|
+
disp = *ptr;
|
1234
|
+
|
1235
|
+
|
1236
|
+
if (!(list = (Atom *)get_property(disp, DefaultRootWindow(disp), XA_ATOM, "_NET_SUPPORTED", &size))) {
|
1237
|
+
rb_raise(rb_eStandardError, "Cannot get _NET_SUPPORTED property.");
|
1238
|
+
}
|
1239
|
+
|
1240
|
+
ret = rb_ary_new();
|
1241
|
+
for (i = 0; i < size / sizeof(Atom); i++) {
|
1242
|
+
prop_name = XGetAtomName(disp, list[i]);
|
1243
|
+
rb_ary_push(ret, rb_str_new2(prop_name));
|
1244
|
+
g_free(prop_name);
|
1245
|
+
}
|
1246
|
+
g_free(list);
|
1247
|
+
return ret;
|
1248
|
+
}
|
1249
|
+
|
1151
1250
|
void Init_wmctrl()
|
1152
1251
|
{
|
1153
1252
|
rb_wmctrl_class = rb_define_class("WMCtrl", rb_cObject);
|
@@ -1155,7 +1254,7 @@ void Init_wmctrl()
|
|
1155
1254
|
rb_define_alloc_func(rb_wmctrl_class, rb_wmctrl_alloc);
|
1156
1255
|
rb_define_private_method(rb_wmctrl_class, "initialize", rb_wmctrl_initialize, -1);
|
1157
1256
|
|
1158
|
-
rb_define_method(rb_wmctrl_class, "list_windows", rb_wmctrl_list_windows,
|
1257
|
+
rb_define_method(rb_wmctrl_class, "list_windows", rb_wmctrl_list_windows, -1);
|
1159
1258
|
rb_define_method(rb_wmctrl_class, "list_desktops", rb_wmctrl_list_desktops, 0);
|
1160
1259
|
rb_define_method(rb_wmctrl_class, "switch_desktop", rb_wmctrl_switch_desktop, 1);
|
1161
1260
|
rb_define_method(rb_wmctrl_class, "info", rb_wmctrl_info, 0);
|
@@ -1164,6 +1263,7 @@ void Init_wmctrl()
|
|
1164
1263
|
rb_define_method(rb_wmctrl_class, "change_geometry", rb_wmctrl_change_geometry, 0);
|
1165
1264
|
rb_define_method(rb_wmctrl_class, "change_number_of_desktops", rb_wmctrl_change_number_of_desktops, 1);
|
1166
1265
|
rb_define_method(rb_wmctrl_class, "action_window", rb_wmctrl_action_window, -1);
|
1266
|
+
rb_define_method(rb_wmctrl_class, "supported", rb_wmctrl_supported, 0);
|
1167
1267
|
|
1168
1268
|
key_id = ID2SYM(rb_intern("id"));
|
1169
1269
|
key_title = ID2SYM(rb_intern("title"));
|
@@ -1178,6 +1278,9 @@ void Init_wmctrl()
|
|
1178
1278
|
key_current = ID2SYM(rb_intern("current"));
|
1179
1279
|
key_showing_desktop = ID2SYM(rb_intern("showing_desktop"));
|
1180
1280
|
key_name = ID2SYM(rb_intern("name"));
|
1281
|
+
key_state = ID2SYM(rb_intern("state"));
|
1282
|
+
key_frame_extents = ID2SYM(rb_intern("frame_extents"));
|
1283
|
+
key_strut = ID2SYM(rb_intern("strut"));
|
1181
1284
|
|
1182
1285
|
id_active = rb_intern("active");
|
1183
1286
|
id_select = rb_intern("select");
|
data/lib/wmctrl/version.rb
CHANGED
data/sample/list_windows.rb
CHANGED
data/sample/supported.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-wmctrl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &9960620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *9960620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: yard
|
27
|
-
requirement: &
|
27
|
+
requirement: &9960120 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *9960120
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: pkg-config
|
38
|
-
requirement: &
|
38
|
+
requirement: &9959580 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *9959580
|
47
47
|
description: Ruby bindings to control windows in EWMH and NetWM compatible X Window
|
48
48
|
manager, which is created from source code of wmctrl command.
|
49
49
|
email:
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- sample/move_to_desktop.rb
|
77
77
|
- sample/set_title.rb
|
78
78
|
- sample/showing_desktop.rb
|
79
|
+
- sample/supported.rb
|
79
80
|
- sample/switch_desktop.rb
|
80
81
|
homepage: ''
|
81
82
|
licenses: []
|