ruby-wmctrl 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.yardopts +6 -0
- data/README.md +32 -0
- data/Rakefile +3 -0
- data/ext/wmctrl.c +86 -18
- data/lib/wmctrl/version.rb +2 -2
- data/lib/wmctrl.rb +2 -0
- data/sample/activate.rb +1 -0
- data/sample/change_number_of_desktops.rb +1 -0
- data/sample/change_state.rb +1 -0
- data/sample/change_state2.rb +1 -0
- data/sample/close.rb +1 -0
- data/sample/info.rb +1 -0
- data/sample/list_desktops.rb +1 -0
- data/sample/list_windows.rb +1 -0
- data/sample/move_resize.rb +1 -0
- data/sample/move_to_desktop.rb +1 -0
- data/sample/set_title.rb +1 -0
- data/sample/showing_desktop.rb +1 -0
- data/sample/switch_desktop.rb +1 -0
- metadata +10 -7
data/.gitignore
CHANGED
data/.yardopts
ADDED
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# ruby-wmctrl
|
2
|
+
|
3
|
+
Ruby bindings to control windows in EWMH and NetWM compatible X Window manager.
|
4
|
+
|
5
|
+
- <http://rubygems.org/gems/ruby-wmctrl>
|
6
|
+
- <https://github.com/ytaka/ruby-wmctrl>
|
7
|
+
|
8
|
+
## Compilation
|
9
|
+
|
10
|
+
ruby-wmctrl is a C extended library, which uses glib and x11.
|
11
|
+
For ubuntu 11.04, we should install packages.
|
12
|
+
|
13
|
+
apt-get install libx11-dev libglib2.0-dev
|
14
|
+
|
15
|
+
## License
|
16
|
+
|
17
|
+
GPLv2
|
18
|
+
|
19
|
+
## Copyright
|
20
|
+
|
21
|
+
### wmctrl
|
22
|
+
|
23
|
+
ruby-wmctrl is created from source code of wmctrl <http://sweb.cz/tripie/utils/wmctrl/>.
|
24
|
+
|
25
|
+
The copyright of originl wmctrl:
|
26
|
+
|
27
|
+
Author, current maintainer: Tomas Styblo tripie@cpan.org
|
28
|
+
Copyright (C) 2003
|
29
|
+
|
30
|
+
### ruby-wmctrl
|
31
|
+
|
32
|
+
Takayuki YAMAGUCHI d@ytak.info Copyright (C) 2011
|
data/Rakefile
CHANGED
data/ext/wmctrl.c
CHANGED
@@ -26,8 +26,32 @@
|
|
26
26
|
|
27
27
|
#define envir_utf8 TRUE
|
28
28
|
|
29
|
+
static int client_msg(Display *disp, Window win, const char *msg,
|
30
|
+
unsigned long data0, unsigned long data1,
|
31
|
+
unsigned long data2, unsigned long data3,
|
32
|
+
unsigned long data4);
|
33
|
+
static gchar *get_property (Display *disp, Window win,
|
34
|
+
Atom xa_prop_type, const gchar *prop_name, unsigned long *size);
|
35
|
+
static Window *get_client_list (Display *disp, unsigned long *size);
|
36
|
+
static gchar *get_window_class (Display *disp, Window win);
|
37
|
+
static gchar *get_window_title (Display *disp, Window win);
|
38
|
+
static int activate_window (Display *disp, Window win, gboolean switch_desktop);
|
39
|
+
static int close_window (Display *disp, Window win);
|
40
|
+
static gboolean wm_supports (Display *disp, const gchar *prop);
|
41
|
+
static int window_move_resize (Display *disp, Window win, signed long grav,
|
42
|
+
signed long x, signed long y, signed long w, signed long h);
|
43
|
+
static int window_state (Display *disp, Window win,
|
44
|
+
const char *action_str, const char *prop1_str, const char *prop2_str);
|
45
|
+
static int window_to_desktop (Display *disp, Window win, int desktop);
|
46
|
+
static void window_set_title (Display *disp, Window win, char *title, char mode);
|
47
|
+
static int action_window (Display *disp, Window win, char mode, int argc, VALUE *argv);
|
48
|
+
static Window Select_Window(Display *dpy);
|
49
|
+
static Window get_active_window(Display *disp);
|
50
|
+
static Window get_target_window (Display *disp, VALUE obj);
|
51
|
+
|
52
|
+
|
29
53
|
static VALUE rb_wmctrl_class, key_id, key_title, key_pid, key_geometry,
|
30
|
-
key_class, key_client_machine, key_desktop,
|
54
|
+
key_active, key_class, key_client_machine, key_desktop,
|
31
55
|
key_viewport, key_workarea, key_current, key_showing_desktop, key_name;
|
32
56
|
|
33
57
|
static ID id_select, id_active, id_activate, id_close, id_move_resize,
|
@@ -59,7 +83,8 @@ static VALUE rb_wmctrl_initialize(int argc, VALUE *argv, VALUE self)
|
|
59
83
|
static int client_msg(Display *disp, Window win, const char *msg,
|
60
84
|
unsigned long data0, unsigned long data1,
|
61
85
|
unsigned long data2, unsigned long data3,
|
62
|
-
unsigned long data4)
|
86
|
+
unsigned long data4)
|
87
|
+
{
|
63
88
|
XEvent event;
|
64
89
|
long mask = SubstructureRedirectMask | SubstructureNotifyMask;
|
65
90
|
|
@@ -84,7 +109,8 @@ static int client_msg(Display *disp, Window win, const char *msg,
|
|
84
109
|
|
85
110
|
/* Copy from debian package for 64bit support. */
|
86
111
|
static gchar *get_property (Display *disp, Window win,
|
87
|
-
Atom xa_prop_type, const gchar *prop_name, unsigned long *size)
|
112
|
+
Atom xa_prop_type, const gchar *prop_name, unsigned long *size)
|
113
|
+
{
|
88
114
|
Atom xa_prop_name;
|
89
115
|
Atom xa_ret_type;
|
90
116
|
int ret_format;
|
@@ -140,7 +166,8 @@ static gchar *get_property (Display *disp, Window win,
|
|
140
166
|
return ret;
|
141
167
|
}
|
142
168
|
|
143
|
-
static Window *get_client_list (Display *disp, unsigned long *size)
|
169
|
+
static Window *get_client_list (Display *disp, unsigned long *size)
|
170
|
+
{
|
144
171
|
Window *client_list;
|
145
172
|
|
146
173
|
if ((client_list = (Window *)get_property(disp, DefaultRootWindow(disp),
|
@@ -157,7 +184,8 @@ static Window *get_client_list (Display *disp, unsigned long *size) {
|
|
157
184
|
return client_list;
|
158
185
|
}
|
159
186
|
|
160
|
-
static gchar *get_window_class (Display *disp, Window win)
|
187
|
+
static gchar *get_window_class (Display *disp, Window win)
|
188
|
+
{
|
161
189
|
gchar *class_utf8;
|
162
190
|
gchar *wm_class;
|
163
191
|
unsigned long size;
|
@@ -179,7 +207,8 @@ static gchar *get_window_class (Display *disp, Window win) {
|
|
179
207
|
return class_utf8;
|
180
208
|
}
|
181
209
|
|
182
|
-
static gchar *get_window_title (Display *disp, Window win)
|
210
|
+
static gchar *get_window_title (Display *disp, Window win)
|
211
|
+
{
|
183
212
|
gchar *title_utf8;
|
184
213
|
gchar *wm_name;
|
185
214
|
gchar *net_wm_name;
|
@@ -206,9 +235,11 @@ static gchar *get_window_title (Display *disp, Window win) {
|
|
206
235
|
return title_utf8;
|
207
236
|
}
|
208
237
|
|
238
|
+
/* Get list of information of windows. */
|
209
239
|
static VALUE rb_wmctrl_list_windows (VALUE self) {
|
210
240
|
Display **ptr, *disp;
|
211
241
|
Window *client_list;
|
242
|
+
Window window_active;
|
212
243
|
unsigned long client_list_size;
|
213
244
|
unsigned int i;
|
214
245
|
VALUE window_ary;
|
@@ -221,6 +252,7 @@ static VALUE rb_wmctrl_list_windows (VALUE self) {
|
|
221
252
|
return Qfalse;
|
222
253
|
}
|
223
254
|
|
255
|
+
window_active = get_active_window(disp);
|
224
256
|
window_ary = rb_ary_new2(client_list_size);
|
225
257
|
|
226
258
|
for (i = 0; i < client_list_size / sizeof(Window); i++) {
|
@@ -240,6 +272,12 @@ static VALUE rb_wmctrl_list_windows (VALUE self) {
|
|
240
272
|
rb_hash_aset(window_obj, key_title, (title_utf8 ? RB_UTF8_STRING_NEW2(title_utf8) : Qnil));
|
241
273
|
rb_hash_aset(window_obj, key_class, (class_out ? RB_UTF8_STRING_NEW2(class_out) : Qnil));
|
242
274
|
|
275
|
+
if (window_active == client_list[i]) {
|
276
|
+
rb_hash_aset(window_obj, key_active, Qtrue);
|
277
|
+
} else {
|
278
|
+
rb_hash_aset(window_obj, key_active, Qnil);
|
279
|
+
}
|
280
|
+
|
243
281
|
/* desktop ID */
|
244
282
|
if ((desktop = (unsigned long *)get_property(disp, client_list[i],
|
245
283
|
XA_CARDINAL, "_NET_WM_DESKTOP", NULL)) == NULL) {
|
@@ -277,6 +315,7 @@ static VALUE rb_wmctrl_list_windows (VALUE self) {
|
|
277
315
|
return window_ary;
|
278
316
|
}
|
279
317
|
|
318
|
+
/* Get list of information of desktops. */
|
280
319
|
static VALUE rb_wmctrl_list_desktops (VALUE self) {
|
281
320
|
Display **ptr, *disp;
|
282
321
|
unsigned long *num_desktops = NULL;
|
@@ -498,6 +537,7 @@ static VALUE rb_wmctrl_list_desktops (VALUE self) {
|
|
498
537
|
return ret;
|
499
538
|
}
|
500
539
|
|
540
|
+
/* Switch desktop. */
|
501
541
|
static VALUE rb_wmctrl_switch_desktop (VALUE self, VALUE desktop_id) {
|
502
542
|
int target;
|
503
543
|
Display **ptr, *disp;
|
@@ -512,6 +552,7 @@ static VALUE rb_wmctrl_switch_desktop (VALUE self, VALUE desktop_id) {
|
|
512
552
|
return Qtrue;
|
513
553
|
}
|
514
554
|
|
555
|
+
/* Get hash of information of window manager. */
|
515
556
|
static VALUE rb_wmctrl_info (VALUE self) {
|
516
557
|
Display **ptr, *disp;
|
517
558
|
Window *sup_window = NULL;
|
@@ -582,6 +623,7 @@ static VALUE rb_wmctrl_info (VALUE self) {
|
|
582
623
|
return ret;
|
583
624
|
}
|
584
625
|
|
626
|
+
/* Minimize windows to show desktop. */
|
585
627
|
static VALUE rb_wmctrl_showing_desktop (VALUE self, VALUE state) {
|
586
628
|
Display **ptr, *disp;
|
587
629
|
Data_Get_Struct(self, Display*, ptr);
|
@@ -618,6 +660,7 @@ static VALUE rb_wmctrl_change_geometry (VALUE self, VALUE xnum, VALUE ynum) {
|
|
618
660
|
return Qtrue;
|
619
661
|
}
|
620
662
|
|
663
|
+
/* Change number of desktops. */
|
621
664
|
static VALUE rb_wmctrl_change_number_of_desktops (VALUE self, VALUE num) {
|
622
665
|
long n;
|
623
666
|
Display **ptr, *disp;
|
@@ -631,7 +674,8 @@ static VALUE rb_wmctrl_change_number_of_desktops (VALUE self, VALUE num) {
|
|
631
674
|
return Qtrue;
|
632
675
|
}
|
633
676
|
|
634
|
-
static int activate_window (Display *disp, Window win, gboolean switch_desktop)
|
677
|
+
static int activate_window (Display *disp, Window win, gboolean switch_desktop)
|
678
|
+
{
|
635
679
|
unsigned long *desktop;
|
636
680
|
|
637
681
|
/* desktop ID */
|
@@ -658,11 +702,13 @@ static int activate_window (Display *disp, Window win, gboolean switch_desktop)
|
|
658
702
|
return True;
|
659
703
|
}
|
660
704
|
|
661
|
-
static int close_window (Display *disp, Window win)
|
705
|
+
static int close_window (Display *disp, Window win)
|
706
|
+
{
|
662
707
|
return client_msg(disp, win, "_NET_CLOSE_WINDOW", 0, 0, 0, 0, 0);
|
663
708
|
}
|
664
709
|
|
665
|
-
static gboolean wm_supports (Display *disp, const gchar *prop)
|
710
|
+
static gboolean wm_supports (Display *disp, const gchar *prop)
|
711
|
+
{
|
666
712
|
Atom xa_prop = XInternAtom(disp, prop, False);
|
667
713
|
Atom *list;
|
668
714
|
unsigned long size;
|
@@ -686,7 +732,8 @@ static gboolean wm_supports (Display *disp, const gchar *prop) {
|
|
686
732
|
}
|
687
733
|
|
688
734
|
static int window_move_resize (Display *disp, Window win, signed long grav,
|
689
|
-
signed long x, signed long y, signed long w, signed long h)
|
735
|
+
signed long x, signed long y, signed long w, signed long h)
|
736
|
+
{
|
690
737
|
unsigned long grflags;
|
691
738
|
grflags = grav;
|
692
739
|
if (x != -1) grflags |= (1 << 8);
|
@@ -716,7 +763,8 @@ static int window_move_resize (Display *disp, Window win, signed long grav,
|
|
716
763
|
}
|
717
764
|
|
718
765
|
static int window_state (Display *disp, Window win,
|
719
|
-
const char *action_str, const char *prop1_str, const char *prop2_str)
|
766
|
+
const char *action_str, const char *prop1_str, const char *prop2_str)
|
767
|
+
{
|
720
768
|
unsigned long action;
|
721
769
|
Atom prop1 = 0;
|
722
770
|
Atom prop2 = 0;
|
@@ -754,7 +802,8 @@ static int window_state (Display *disp, Window win,
|
|
754
802
|
return client_msg(disp, win, "_NET_WM_STATE", action, (unsigned long)prop1, (unsigned long)prop2, 0, 0);
|
755
803
|
}
|
756
804
|
|
757
|
-
static int window_to_desktop (Display *disp, Window win, int desktop)
|
805
|
+
static int window_to_desktop (Display *disp, Window win, int desktop)
|
806
|
+
{
|
758
807
|
unsigned long *cur_desktop = NULL;
|
759
808
|
Window root = DefaultRootWindow(disp);
|
760
809
|
|
@@ -776,7 +825,8 @@ static int window_to_desktop (Display *disp, Window win, int desktop) {
|
|
776
825
|
return client_msg(disp, win, "_NET_WM_DESKTOP", (unsigned long)desktop, 0, 0, 0, 0);
|
777
826
|
}
|
778
827
|
|
779
|
-
static void window_set_title (Display *disp, Window win, char *title, char mode)
|
828
|
+
static void window_set_title (Display *disp, Window win, char *title, char mode)
|
829
|
+
{
|
780
830
|
gchar *title_utf8;
|
781
831
|
gchar *title_local;
|
782
832
|
|
@@ -823,7 +873,8 @@ static void window_set_title (Display *disp, Window win, char *title, char mode)
|
|
823
873
|
g_free(title_local);
|
824
874
|
}
|
825
875
|
|
826
|
-
static int action_window (Display *disp, Window win, char mode, int argc, VALUE *argv)
|
876
|
+
static int action_window (Display *disp, Window win, char mode, int argc, VALUE *argv)
|
877
|
+
{
|
827
878
|
p_verbose("Using window: 0x%.8lx\n", win);
|
828
879
|
switch (mode) {
|
829
880
|
case 'a':
|
@@ -887,7 +938,8 @@ static int action_window (Display *disp, Window win, char mode, int argc, VALUE
|
|
887
938
|
rb_raise(rb_eArgError, "Invalid argument of action_window.");
|
888
939
|
}
|
889
940
|
|
890
|
-
static Window Select_Window(Display *dpy)
|
941
|
+
static Window Select_Window(Display *dpy)
|
942
|
+
{
|
891
943
|
/*
|
892
944
|
* Routine to let user select a window using the mouse
|
893
945
|
* Taken from xfree86.
|
@@ -943,7 +995,8 @@ static Window Select_Window(Display *dpy) {
|
|
943
995
|
return(target_win);
|
944
996
|
}
|
945
997
|
|
946
|
-
static Window get_active_window(Display *disp)
|
998
|
+
static Window get_active_window(Display *disp)
|
999
|
+
{
|
947
1000
|
char *prop;
|
948
1001
|
unsigned long size;
|
949
1002
|
Window ret = (Window)0;
|
@@ -957,7 +1010,8 @@ static Window get_active_window(Display *disp) {
|
|
957
1010
|
return(ret);
|
958
1011
|
}
|
959
1012
|
|
960
|
-
static Window get_target_window (Display *disp, VALUE obj)
|
1013
|
+
static Window get_target_window (Display *disp, VALUE obj)
|
1014
|
+
{
|
961
1015
|
Window wid = 0;
|
962
1016
|
switch (TYPE(obj)) {
|
963
1017
|
case T_FIXNUM:
|
@@ -1041,6 +1095,19 @@ static Window get_target_window (Display *disp, VALUE obj) {
|
|
1041
1095
|
/* return activate; */
|
1042
1096
|
/* } */
|
1043
1097
|
|
1098
|
+
/*
|
1099
|
+
call-seq:
|
1100
|
+
wm.action_window(wid, :close)
|
1101
|
+
wm.action_window(wid, :move_resize, grav, x, y, w, h)
|
1102
|
+
wm.action_window(wid, :change_state, add, prop1, prop2 = nil)
|
1103
|
+
wm.action_window(wid, :change_state, remove, prop1, prop2 = nil)
|
1104
|
+
wm.action_window(wid, :change_state, toggle, prop1, prop2 = nil)
|
1105
|
+
wm.action_window(wid, :move_to_desktop, desktop_id)
|
1106
|
+
wm.action_window(wid, :move_to_current)
|
1107
|
+
wm.action_window(wid, :set_title_long, str)
|
1108
|
+
wm.action_window(wid, :set_title_short, str)
|
1109
|
+
wm.action_window(wid, :set_title_both, str)
|
1110
|
+
*/
|
1044
1111
|
static VALUE rb_wmctrl_action_window(int argc, VALUE *argv, VALUE self) {
|
1045
1112
|
Window wid;
|
1046
1113
|
int mode;
|
@@ -1101,7 +1168,8 @@ void Init_wmctrl()
|
|
1101
1168
|
key_id = ID2SYM(rb_intern("id"));
|
1102
1169
|
key_title = ID2SYM(rb_intern("title"));
|
1103
1170
|
key_pid = ID2SYM(rb_intern("pid"));
|
1104
|
-
key_geometry = ID2SYM(rb_intern("
|
1171
|
+
key_geometry = ID2SYM(rb_intern("geometry"));
|
1172
|
+
key_active = ID2SYM(rb_intern("active"));
|
1105
1173
|
key_class = ID2SYM(rb_intern("class"));
|
1106
1174
|
key_client_machine = ID2SYM(rb_intern("client_machine"));
|
1107
1175
|
key_desktop = ID2SYM(rb_intern("desktop"));
|
data/lib/wmctrl/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
class WMCtrl
|
2
|
+
VERSION = "0.0.2"
|
3
3
|
end
|
data/lib/wmctrl.rb
ADDED
data/sample/activate.rb
CHANGED
data/sample/change_state.rb
CHANGED
data/sample/change_state2.rb
CHANGED
data/sample/close.rb
CHANGED
data/sample/info.rb
CHANGED
data/sample/list_desktops.rb
CHANGED
data/sample/list_windows.rb
CHANGED
data/sample/move_resize.rb
CHANGED
data/sample/move_to_desktop.rb
CHANGED
data/sample/set_title.rb
CHANGED
data/sample/showing_desktop.rb
CHANGED
data/sample/switch_desktop.rb
CHANGED
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-17 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &11195400 !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: *11195400
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: yard
|
27
|
-
requirement: &
|
27
|
+
requirement: &11194980 !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: *11194980
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: pkg-config
|
38
|
-
requirement: &
|
38
|
+
requirement: &11194560 !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: *11194560
|
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:
|
@@ -54,11 +54,14 @@ extensions:
|
|
54
54
|
extra_rdoc_files: []
|
55
55
|
files:
|
56
56
|
- .gitignore
|
57
|
+
- .yardopts
|
57
58
|
- COPYING
|
58
59
|
- Gemfile
|
60
|
+
- README.md
|
59
61
|
- Rakefile
|
60
62
|
- ext/extconf.rb
|
61
63
|
- ext/wmctrl.c
|
64
|
+
- lib/wmctrl.rb
|
62
65
|
- lib/wmctrl/version.rb
|
63
66
|
- ruby-wmctrl.gemspec
|
64
67
|
- sample/activate.rb
|