xsettings-ruby 0.0.1

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: 9a9a4535316fec30d4ce0d920aa4d094bd445bc0
4
+ data.tar.gz: 62b8dcf4332b965bb1b84e8ee6bfe5c4ecca9b0b
5
+ SHA512:
6
+ metadata.gz: 2b5ca7d8df516011c6b1d94ed36f8b8cd427d572068f68389e3f2aa642edd3370a8b3c82fcf6ea885b5e2e322d97d15f16233b3afb187aa8ae0892d17d9e7f9a
7
+ data.tar.gz: 1f1302df4d3d3fbe53df480cbfc504a1d0ae36ff08d0b9deb14e5fccf73065f76c33dbaed452ac28829802c914a1bbee180ba3170c7c153d3b38d9907044c5e7
@@ -0,0 +1,15 @@
1
+ XSettings Manager
2
+ =================
3
+
4
+ Description
5
+ -----------
6
+ Ruby bindings for Xsettings manager library
7
+
8
+
9
+ License
10
+ -------
11
+ Copyright (c) 2011-2013 Geoff Youngs
12
+
13
+ This program is free software.
14
+ You can distribute/modify this program under the terms of
15
+ the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ gem 'rake-compiler'
3
+ require 'rake/extensiontask'
4
+ BASE_DIR = Dir.pwd
5
+ require 'rubygems/package_task'
6
+ require 'rake/testtask'
7
+
8
+ $: << './lib'
9
+
10
+ require 'xsettings/version'
11
+ exts = []
12
+
13
+ namespace :prepare do
14
+ FileList["ext/*/*.cr"].each do |cr|
15
+ dir = File.dirname(cr)
16
+ name = File.basename(dir)
17
+ desc "Generate source for #{name}"
18
+ task(name.intern) do
19
+ sh 'rubber-generate', '--build-dir', dir, cr
20
+ end
21
+ end
22
+ end
23
+
24
+ spec = Gem::Specification.new do |s|
25
+ s.name = "xsettings-ruby"
26
+ s.author = "Geoff Youngs"
27
+ s.email = "git@intersect-uk.co.uk"
28
+ s.version = XSettings::VERSION
29
+ s.homepage = "http://github.com/geoffyoungs/xsettings-ruby"
30
+ s.summary = "xsettings bindings using rubber-generate"
31
+ s.add_dependency("rubber-generate", ">= 0.0.17")
32
+ s.platform = Gem::Platform::RUBY
33
+ s.extensions = FileList["ext/*/extconf.rb"]
34
+ s.files = FileList['ext/*/*.{c,h,cr,rd}'] + ['Rakefile', 'README.md'] + FileList['lib/**/*.rb']
35
+ s.description = <<-EOF
36
+ XSettings Manager bindings for ruby
37
+
38
+ e.g
39
+ require 'gtk2'
40
+ require 'xsettings-ruby'
41
+
42
+ EOF
43
+ end
44
+ Gem::PackageTask.new(spec) do |pkg|
45
+ pkg.need_tar = true
46
+ end
47
+ Rake::ExtensionTask.new("xsettings", spec)
48
+
49
+ Rake::TestTask.new do |t|
50
+ t.test_files = FileList['test/*_test.rb']
51
+ end
52
+
53
+ task :default, :compile
54
+
@@ -0,0 +1,114 @@
1
+ require 'mkmf'
2
+ use_gems = false
3
+ begin
4
+ require 'mkmf-gnome2'
5
+ rescue LoadError
6
+ use_gems = true
7
+ end
8
+
9
+ if use_gems or Object.const_defined?('Gem')
10
+ require 'rubygems'
11
+ gem 'glib2'
12
+ require 'mkmf-gnome2'
13
+ %w[rbglib.h rbgtk.h rbpango.h rbatk.h].each do |header|
14
+ Gem.find_files(header).each do |f|
15
+ $CFLAGS += " '-I#{File.dirname(f)}'"
16
+ end
17
+ end
18
+ end
19
+ # Look for headers in {gem_root}/ext/{package}
20
+ if use_gems
21
+ %w[
22
+ glib2 gdk_pixbuf2 atk gtk2].each do |package|
23
+ require package
24
+ if Gem.loaded_specs[package]
25
+ $CFLAGS += " -I" + Gem.loaded_specs[package].full_gem_path + "/ext/" + package
26
+ else
27
+ if fn = $".find { |n| n.sub(/[.](so|rb)$/,'') == package }
28
+ dr = $:.find { |d| File.exist?(File.join(d, fn)) }
29
+ pt = File.join(dr,fn) if dr && fn
30
+ else
31
+ pt = "??"
32
+ end
33
+ STDERR.puts "require '" + package + "' loaded '"+pt+"' instead of the gem - trying to continue, but build may fail"
34
+ end
35
+ end
36
+ end
37
+ if RbConfig::CONFIG.has_key?('rubyhdrdir')
38
+ $CFLAGS += " -I" + RbConfig::CONFIG['rubyhdrdir']+'/ruby'
39
+ end
40
+
41
+ $CFLAGS += " -I."
42
+ have_func("rb_errinfo")
43
+ PKGConfig.have_package("gtk+-2.0") or exit(-1)
44
+ have_header("gtk/gtk.h") or exit(-1)
45
+ have_header("gdk/gdk.h") or exit(-1)
46
+ have_header("gdk/gdkx.h") or exit(-1)
47
+
48
+ STDOUT.print("checking for new allocation framework... ") # for ruby-1.7
49
+ if Object.respond_to? :allocate
50
+ STDOUT.print "yes
51
+ "
52
+ $defs << "-DHAVE_OBJECT_ALLOCATE"
53
+ else
54
+ STDOUT.print "no
55
+ "
56
+ end
57
+
58
+ top = File.expand_path(File.dirname(__FILE__) + '/..') # XXX
59
+ $CFLAGS += " " + ['glib/src'].map{|d|
60
+ "-I" + File.join(top, d)
61
+ }.join(" ")
62
+
63
+ have_func("rb_define_alloc_func") # for ruby-1.8
64
+
65
+ #set_output_lib('libruby-xsettings.a')
66
+ if /cygwin|mingw/ =~ RUBY_PLATFORM
67
+ top = "../.."
68
+ [
69
+ ["glib/src", "ruby-glib2"],
70
+ ].each{|d,l|
71
+ $LDFLAGS << sprintf(" -L%s/%s", top, d)
72
+ $libs << sprintf(" -l%s", l)
73
+ }
74
+ end
75
+ begin
76
+ srcdir = File.expand_path(File.dirname($0))
77
+
78
+ begin
79
+
80
+ obj_ext = "."+$OBJEXT
81
+
82
+ $libs = $libs.split(/ /).uniq.join(' ')
83
+ $source_files = Dir.glob(sprintf("%s/*.c", srcdir)).map{|fname|
84
+ fname[0, srcdir.length+1] = ''
85
+ fname
86
+ }
87
+ $objs = $source_files.collect do |item|
88
+ item.gsub(/.c$/, obj_ext)
89
+ end
90
+
91
+ #
92
+ # create Makefile
93
+ #
94
+ $defs << "-DRUBY_XSETTINGS_COMPILATION"
95
+ # $CFLAGS << $defs.join(' ')
96
+ create_makefile("xsettings", srcdir)
97
+ raise Interrupt if not FileTest.exist? "Makefile"
98
+
99
+ File.open("Makefile", "a") do |mfile|
100
+ $source_files.each do |e|
101
+ mfile.print sprintf("%s: %s
102
+ ", e.gsub(/.c$/, obj_ext), e)
103
+ end
104
+ end
105
+ ensure
106
+ #Dir.chdir ".."
107
+ end
108
+
109
+ #create_top_makefile()
110
+ rescue Interrupt
111
+ print " [error] " + $!.to_s + "
112
+ "
113
+ end
114
+
@@ -0,0 +1,261 @@
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
+ #include "string.h"
24
+ #include "stdlib.h"
25
+
26
+ #include <X11/Xlib.h>
27
+ #include <X11/Xmd.h> /* For CARD32 */
28
+
29
+ #include "xsettings-common.h"
30
+
31
+ XSettingsSetting *
32
+ xsettings_setting_copy (XSettingsSetting *setting)
33
+ {
34
+ XSettingsSetting *result;
35
+ size_t str_len;
36
+
37
+ result = malloc (sizeof *result);
38
+ if (!result)
39
+ return NULL;
40
+
41
+ str_len = strlen (setting->name);
42
+ result->name = malloc (str_len + 1);
43
+ if (!result->name)
44
+ goto err;
45
+
46
+ memcpy (result->name, setting->name, str_len + 1);
47
+
48
+ result->type = setting->type;
49
+
50
+ switch (setting->type)
51
+ {
52
+ case XSETTINGS_TYPE_INT:
53
+ result->data.v_int = setting->data.v_int;
54
+ break;
55
+ case XSETTINGS_TYPE_COLOR:
56
+ result->data.v_color = setting->data.v_color;
57
+ break;
58
+ case XSETTINGS_TYPE_STRING:
59
+ str_len = strlen (setting->data.v_string);
60
+ result->data.v_string = malloc (str_len + 1);
61
+ if (!result->data.v_string)
62
+ goto err;
63
+
64
+ memcpy (result->data.v_string, setting->data.v_string, str_len + 1);
65
+ break;
66
+ }
67
+
68
+ result->last_change_serial = setting->last_change_serial;
69
+
70
+ return result;
71
+
72
+ err:
73
+ if (result->name)
74
+ free (result->name);
75
+ free (result);
76
+
77
+ return NULL;
78
+ }
79
+
80
+ XSettingsList *
81
+ xsettings_list_copy (XSettingsList *list)
82
+ {
83
+ XSettingsList *new = NULL;
84
+ XSettingsList *old_iter = list;
85
+ XSettingsList *new_iter = NULL;
86
+
87
+ while (old_iter)
88
+ {
89
+ XSettingsList *new_node;
90
+
91
+ new_node = malloc (sizeof *new_node);
92
+ if (!new_node)
93
+ goto error;
94
+
95
+ new_node->setting = xsettings_setting_copy (old_iter->setting);
96
+ if (!new_node->setting)
97
+ {
98
+ free (new_node);
99
+ goto error;
100
+ }
101
+
102
+ if (new_iter)
103
+ new_iter->next = new_node;
104
+ else
105
+ new = new_node;
106
+
107
+ new_iter = new_node;
108
+
109
+ old_iter = old_iter->next;
110
+ }
111
+
112
+ return new;
113
+
114
+ error:
115
+ xsettings_list_free (new);
116
+ return NULL;
117
+ }
118
+
119
+ int
120
+ xsettings_setting_equal (XSettingsSetting *setting_a,
121
+ XSettingsSetting *setting_b)
122
+ {
123
+ if (setting_a->type != setting_b->type)
124
+ return 0;
125
+
126
+ if (strcmp (setting_a->name, setting_b->name) != 0)
127
+ return 0;
128
+
129
+ switch (setting_a->type)
130
+ {
131
+ case XSETTINGS_TYPE_INT:
132
+ return setting_a->data.v_int == setting_b->data.v_int;
133
+ case XSETTINGS_TYPE_COLOR:
134
+ return (setting_a->data.v_color.red == setting_b->data.v_color.red &&
135
+ setting_a->data.v_color.green == setting_b->data.v_color.green &&
136
+ setting_a->data.v_color.blue == setting_b->data.v_color.blue &&
137
+ setting_a->data.v_color.alpha == setting_b->data.v_color.alpha);
138
+ case XSETTINGS_TYPE_STRING:
139
+ return strcmp (setting_a->data.v_string, setting_b->data.v_string) == 0;
140
+ }
141
+
142
+ return 0;
143
+ }
144
+
145
+ void
146
+ xsettings_setting_free (XSettingsSetting *setting)
147
+ {
148
+ if (setting->type == XSETTINGS_TYPE_STRING)
149
+ free (setting->data.v_string);
150
+
151
+ free (setting);
152
+ }
153
+
154
+ void
155
+ xsettings_list_free (XSettingsList *list)
156
+ {
157
+ while (list)
158
+ {
159
+ XSettingsList *next = list->next;
160
+
161
+ xsettings_setting_free (list->setting);
162
+ free (list);
163
+
164
+ list = next;
165
+ }
166
+ }
167
+
168
+ XSettingsResult
169
+ xsettings_list_insert (XSettingsList **list,
170
+ XSettingsSetting *setting)
171
+ {
172
+ XSettingsList *node;
173
+ XSettingsList *iter;
174
+ XSettingsList *last = NULL;
175
+
176
+ node = malloc (sizeof *node);
177
+ if (!node)
178
+ return XSETTINGS_NO_MEM;
179
+ node->setting = setting;
180
+
181
+ iter = *list;
182
+ while (iter)
183
+ {
184
+ int cmp = strcmp (setting->name, iter->setting->name);
185
+
186
+ if (cmp < 0)
187
+ break;
188
+ else if (cmp == 0)
189
+ {
190
+ free (node);
191
+ return XSETTINGS_DUPLICATE_ENTRY;
192
+ }
193
+
194
+ last = iter;
195
+ iter = iter->next;
196
+ }
197
+
198
+ if (last)
199
+ last->next = node;
200
+ else
201
+ *list = node;
202
+
203
+ node->next = iter;
204
+
205
+ return XSETTINGS_SUCCESS;
206
+ }
207
+
208
+ XSettingsResult
209
+ xsettings_list_delete (XSettingsList **list,
210
+ const char *name)
211
+ {
212
+ XSettingsList *iter;
213
+ XSettingsList *last = NULL;
214
+
215
+ iter = *list;
216
+ while (iter)
217
+ {
218
+ if (strcmp (name, iter->setting->name) == 0)
219
+ {
220
+ if (last)
221
+ last->next = iter->next;
222
+ else
223
+ *list = iter->next;
224
+
225
+ xsettings_setting_free (iter->setting);
226
+ free (iter);
227
+
228
+ return XSETTINGS_SUCCESS;
229
+ }
230
+
231
+ last = iter;
232
+ iter = iter->next;
233
+ }
234
+
235
+ return XSETTINGS_FAILED;
236
+ }
237
+
238
+ XSettingsSetting *
239
+ xsettings_list_lookup (XSettingsList *list,
240
+ const char *name)
241
+ {
242
+ XSettingsList *iter;
243
+
244
+ iter = list;
245
+ while (iter)
246
+ {
247
+ if (strcmp (name, iter->setting->name) == 0)
248
+ return iter->setting;
249
+
250
+ iter = iter->next;
251
+ }
252
+
253
+ return NULL;
254
+ }
255
+
256
+ char
257
+ xsettings_byte_order (void)
258
+ {
259
+ CARD32 myint = 0x01020304;
260
+ return (*(char *)&myint == 1) ? MSBFirst : LSBFirst;
261
+ }