xsettings-ruby 0.0.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.
@@ -0,0 +1,68 @@
1
+ /*
2
+ * Copyright © 2001 Red Hat, Inc.
3
+ *
4
+ * Permission to use, copy, modify, distribute, and sell this software and its
5
+ * documentation for any purpose is hereby granted without fee, provided that
6
+ * the above copyright notice appear in all copies and that both that
7
+ * copyright notice and this permission notice appear in supporting
8
+ * documentation, and that the name of Red Hat not be used in advertising or
9
+ * publicity pertaining to distribution of the software without specific,
10
+ * written prior permission. Red Hat makes no representations about the
11
+ * suitability of this software for any purpose. It is provided "as is"
12
+ * without express or implied warranty.
13
+ *
14
+ * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
15
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT
16
+ * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
18
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
19
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20
+ *
21
+ * Author: Owen Taylor, Red Hat, Inc.
22
+ */
23
+ #ifndef XSETTINGS_MANAGER_H
24
+ #define XSETTINGS_MANAGER_H
25
+
26
+ #include <X11/Xlib.h>
27
+ #include "xsettings-common.h"
28
+
29
+ #ifdef __cplusplus
30
+ extern "C" {
31
+ #endif /* __cplusplus */
32
+
33
+ typedef struct _XSettingsManager XSettingsManager;
34
+
35
+ typedef void (*XSettingsTerminateFunc) (void *cb_data);
36
+
37
+ Bool xsettings_manager_check_running (Display *display,
38
+ int screen);
39
+
40
+ XSettingsManager *xsettings_manager_new (Display *display,
41
+ int screen,
42
+ XSettingsTerminateFunc terminate,
43
+ void *cb_data);
44
+
45
+ void xsettings_manager_destroy (XSettingsManager *manager);
46
+ Window xsettings_manager_get_window (XSettingsManager *manager);
47
+ Bool xsettings_manager_process_event (XSettingsManager *manager,
48
+ XEvent *xev);
49
+
50
+ XSettingsResult xsettings_manager_set_setting (XSettingsManager *manager,
51
+ XSettingsSetting *setting);
52
+ XSettingsResult xsettings_manager_set_int (XSettingsManager *manager,
53
+ const char *name,
54
+ int value);
55
+ XSettingsResult xsettings_manager_set_string (XSettingsManager *manager,
56
+ const char *name,
57
+ const char *value);
58
+ XSettingsResult xsettings_manager_set_color (XSettingsManager *manager,
59
+ const char *name,
60
+ XSettingsColor *value);
61
+ XSettingsResult xsettings_manager_notify (XSettingsManager *manager);
62
+
63
+
64
+ #ifdef __cplusplus
65
+ }
66
+ #endif /* __cplusplus */
67
+
68
+ #endif /* XSETTINGS_MANAGER_H */
@@ -0,0 +1,170 @@
1
+ #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
2
+ /* Includes */
3
+ #include <ruby.h>
4
+ #include <stdlib.h>
5
+ #include <stdio.h>
6
+ #include <string.h>
7
+ #include "gtk/gtk.h"
8
+ #include "gdk/gdk.h"
9
+ #include "gdk/gdkx.h"
10
+
11
+ /* Setup types */
12
+ /* Try not to clash with other definitions of bool... */
13
+ typedef int rubber_bool;
14
+ #define bool rubber_bool
15
+
16
+ /* Prototypes */
17
+ #include "rbglib.h"
18
+
19
+ #include "rbgtk.h"
20
+
21
+ #if defined(G_PLATFORM_WIN32) && !defined(RUBY_GTK2_STATIC_COMPILATION)
22
+ # ifdef RUBY_GTK2_COMPILATION
23
+ # define RUBY_GTK2_VAR __declspec(dllexport)
24
+ # else
25
+ # define RUBY_GTK2_VAR extern __declspec(dllimport)
26
+ # endif
27
+ #else
28
+ # define RUBY_GTK2_VAR extern
29
+ #endif
30
+
31
+ RUBY_GTK2_VAR VALUE mGtk;
32
+ RUBY_GTK2_VAR VALUE mGdk;
33
+
34
+ #define RBGTK_INITIALIZE(obj,gtkobj) (rbgtk_initialize_gtkobject(obj, GTK_OBJECT(gtkobj)))
35
+ static VALUE mXSettings;
36
+ static VALUE cManager;
37
+ static VALUE
38
+ Manager_CLASS_exists_query(VALUE self);
39
+ static VALUE
40
+ Manager_CLASS___alloc__(VALUE self);
41
+ static VALUE
42
+ Manager_terminated(VALUE self);
43
+ static VALUE
44
+ Manager_destroy(VALUE self);
45
+ static VALUE
46
+ Manager_notify(VALUE self);
47
+ static VALUE
48
+ Manager__brace_brace_equals(VALUE self, VALUE __v_name, VALUE value);
49
+
50
+ /* Inline C code */
51
+
52
+ #include "xsettings-manager.h"
53
+
54
+ static XSettingsManager *
55
+ manager_unwrap(VALUE obj)
56
+ {
57
+ XSettingsManager *manager;
58
+ Data_Get_Struct(obj, XSettingsManager, manager);
59
+ return manager;
60
+ }
61
+
62
+ static void terminate_xsettings(void *value)
63
+ {
64
+ if (value)
65
+ {
66
+ VALUE obj = (VALUE)value;
67
+ rb_funcall(obj, rb_intern("terminated"),0);
68
+ }
69
+ }
70
+
71
+
72
+ /* Code */
73
+ static VALUE
74
+ Manager_CLASS_exists_query(VALUE self)
75
+ {
76
+ VALUE __p_retval = Qnil;
77
+
78
+ #line 33 "/home/geoff/Projects/xsettings/ext/xsettings/xsettings.cr"
79
+ do { __p_retval = ((xsettings_manager_check_running(GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY()))) ? Qtrue : Qfalse); goto out; } while(0);
80
+ out:
81
+ return __p_retval;
82
+ }
83
+
84
+ static VALUE
85
+ Manager_CLASS___alloc__(VALUE self)
86
+ {
87
+ VALUE __p_retval = Qnil;
88
+
89
+ #line 37 "/home/geoff/Projects/xsettings/ext/xsettings/xsettings.cr"
90
+ do { __p_retval = Data_Wrap_Struct(self, NULL, xsettings_manager_destroy, xsettings_manager_new(GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY()), terminate_xsettings, (void*)self)); goto out; } while(0);
91
+ out:
92
+ return __p_retval;
93
+ }
94
+
95
+ static VALUE
96
+ Manager_terminated(VALUE self)
97
+ {
98
+ XSettingsManager *_self = manager_unwrap(self);
99
+
100
+ #line 44 "/home/geoff/Projects/xsettings/ext/xsettings/xsettings.cr"
101
+ _self = _self;
102
+
103
+ return Qnil;
104
+ }
105
+
106
+ static VALUE
107
+ Manager_destroy(VALUE self)
108
+ {
109
+ XSettingsManager *_self = manager_unwrap(self);
110
+
111
+ #line 47 "/home/geoff/Projects/xsettings/ext/xsettings/xsettings.cr"
112
+ xsettings_manager_destroy(_self);
113
+
114
+ return Qnil;
115
+ }
116
+
117
+ static VALUE
118
+ Manager_notify(VALUE self)
119
+ {
120
+ XSettingsManager *_self = manager_unwrap(self);
121
+
122
+ #line 50 "/home/geoff/Projects/xsettings/ext/xsettings/xsettings.cr"
123
+ xsettings_manager_notify(_self);
124
+
125
+ return Qnil;
126
+ }
127
+
128
+ static VALUE
129
+ Manager__brace_brace_equals(VALUE self, VALUE __v_name, VALUE value)
130
+ {
131
+ char * name; char * __orig_name;
132
+ XSettingsManager *_self = manager_unwrap(self);
133
+ __orig_name = name = ( NIL_P(__v_name) ? NULL : StringValuePtr(__v_name) );
134
+
135
+ #line 53 "/home/geoff/Projects/xsettings/ext/xsettings/xsettings.cr"
136
+
137
+ do {
138
+ switch(TYPE(value)) { case T_NIL: case T_TRUE: case T_FALSE: xsettings_manager_set_int(_self, name, RTEST(value));
139
+ break;
140
+ case T_FIXNUM: xsettings_manager_set_int(_self, name, NUM2INT(value));
141
+ break;
142
+ case T_STRING: xsettings_manager_set_string(_self, name, StringValuePtr(value));
143
+ break;
144
+ case T_ARRAY: if (RARRAY_LEN(value) == 4) { XSettingsColor col ;
145
+ col.red = NUM2INT(RARRAY_PTR(value)[0]);
146
+ col.green = NUM2INT(RARRAY_PTR(value)[1]);
147
+ col.blue = NUM2INT(RARRAY_PTR(value)[2]);
148
+ col.alpha = NUM2INT(RARRAY_PTR(value)[3]);
149
+ xsettings_manager_set_color(_self, name, &col);
150
+ } break;
151
+ }
152
+
153
+ } while(0);
154
+
155
+ return Qnil;
156
+ }
157
+
158
+ /* Init */
159
+ void
160
+ Init_xsettings(void)
161
+ {
162
+ mXSettings = rb_define_module("XSettings");
163
+ cManager = rb_define_class_under(mXSettings, "Manager", rb_cObject);
164
+ rb_define_singleton_method(cManager, "exists?", Manager_CLASS_exists_query, 0);
165
+ rb_define_alloc_func(cManager, Manager_CLASS___alloc__);
166
+ rb_define_method(cManager, "terminated", Manager_terminated, 0);
167
+ rb_define_method(cManager, "destroy", Manager_destroy, 0);
168
+ rb_define_method(cManager, "notify", Manager_notify, 0);
169
+ rb_define_method(cManager, "[]=", Manager__brace_brace_equals, 2);
170
+ }
@@ -0,0 +1,81 @@
1
+ %pkg-config gtk+-2.0
2
+ %include gtk/gtk.h
3
+ %include gdk/gdk.h
4
+ %include gdk/gdkx.h
5
+
6
+ %{
7
+ #include "xsettings-manager.h"
8
+
9
+ static XSettingsManager *
10
+ manager_unwrap(VALUE obj)
11
+ {
12
+ XSettingsManager *manager;
13
+ Data_Get_Struct(obj, XSettingsManager, manager);
14
+ return manager;
15
+ }
16
+
17
+ static void terminate_xsettings(void *value)
18
+ {
19
+ if (value)
20
+ {
21
+ VALUE obj = (VALUE)value;
22
+ rb_funcall(obj, rb_intern("terminated"),0);
23
+ }
24
+ }
25
+
26
+ %}
27
+
28
+ %map VALUE > XSettingsManager* : manager_unwrap(%%)
29
+
30
+ module XSettings
31
+ class Manager
32
+ pre_func XSettingsManager *_self = manager_unwrap(self);
33
+ def bool:self.exists?
34
+ return xsettings_manager_check_running(GDK_DISPLAY(),
35
+ DefaultScreen(GDK_DISPLAY()));
36
+ end
37
+ def self.__alloc__()
38
+ return Data_Wrap_Struct(self, NULL,
39
+ xsettings_manager_destroy,
40
+ xsettings_manager_new(GDK_DISPLAY(),
41
+ DefaultScreen(GDK_DISPLAY()),
42
+ terminate_xsettings, (void*)self));
43
+ end
44
+ def terminated()
45
+ _self = _self;
46
+ end
47
+ def destroy()
48
+ xsettings_manager_destroy(_self);
49
+ end
50
+ def notify
51
+ xsettings_manager_notify(_self);
52
+ end
53
+ def []=(char *name, value)
54
+ switch(TYPE(value))
55
+ {
56
+ case T_NIL:
57
+ case T_TRUE:
58
+ case T_FALSE:
59
+ xsettings_manager_set_int(_self, name, RTEST(value));
60
+ break;
61
+ case T_FIXNUM:
62
+ xsettings_manager_set_int(_self, name, NUM2INT(value));
63
+ break;
64
+ case T_STRING:
65
+ xsettings_manager_set_string(_self, name, StringValuePtr(value));
66
+ break;
67
+ case T_ARRAY:
68
+ if (RARRAY_LEN(value) == 4) {
69
+ XSettingsColor col;
70
+ col.red = NUM2INT(RARRAY_PTR(value)[0]);
71
+ col.green = NUM2INT(RARRAY_PTR(value)[1]);
72
+ col.blue = NUM2INT(RARRAY_PTR(value)[2]);
73
+ col.alpha = NUM2INT(RARRAY_PTR(value)[3]);
74
+ xsettings_manager_set_color(_self, name, &col);
75
+ }
76
+ break;
77
+ }
78
+ end
79
+ end
80
+ end
81
+
@@ -0,0 +1,16 @@
1
+ = module XSettings
2
+ == class XSettings::Manager
3
+ --- XSettings::Manager.exists?
4
+
5
+ --- XSettings::Manager__alloc__()
6
+
7
+
8
+ --- XSettings::Manager#terminated
9
+
10
+ --- XSettings::Manager#destroy
11
+
12
+ --- XSettings::Manager#notify
13
+
14
+ --- XSettings::Manager#[]=(String name, value)
15
+
16
+
@@ -0,0 +1,4 @@
1
+ require 'xsettings/version'
2
+ require 'xsettings.so'
3
+
4
+
@@ -0,0 +1,3 @@
1
+ module XSettings
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xsettings-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Geoff Youngs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubber-generate
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.17
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.17
27
+ description: |+
28
+ XSettings Manager bindings for ruby
29
+
30
+ e.g
31
+ require 'gtk2'
32
+ require 'xsettings-ruby'
33
+
34
+ email: git@intersect-uk.co.uk
35
+ executables: []
36
+ extensions:
37
+ - ext/xsettings/extconf.rb
38
+ extra_rdoc_files: []
39
+ files:
40
+ - ext/xsettings/xsettings-common.c
41
+ - ext/xsettings/xsettings-common.h
42
+ - ext/xsettings/xsettings-manager.c
43
+ - ext/xsettings/xsettings-manager.h
44
+ - ext/xsettings/xsettings.c
45
+ - ext/xsettings/xsettings.cr
46
+ - ext/xsettings/xsettings.rd
47
+ - Rakefile
48
+ - README.md
49
+ - lib/xsettings.rb
50
+ - lib/xsettings/version.rb
51
+ - ext/xsettings/extconf.rb
52
+ homepage: http://github.com/geoffyoungs/xsettings-ruby
53
+ licenses: []
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.0.3
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: xsettings bindings using rubber-generate
75
+ test_files: []