xstorename 0.1.0
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.
- checksums.yaml +7 -0
- data/ext/xstorename/extconf.rb +45 -0
- data/ext/xstorename/xname.c +36 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1302c685f406b59a8412277448a28e3b1901f5cb1cd8b5d5a3b3368ba90d43d2
|
4
|
+
data.tar.gz: 2643673b686b8d18697536c1fc8d6871c8a04a5d0e76114803a9d29c537a521e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9aabccc69ae65e5931aadde1c0f435b04f53749471483d67d8d3d74ea3145954ba16177f3a139bbff914421b407e92ef4ad9ee6b3c49b4f887116c75b22797e
|
7
|
+
data.tar.gz: 1fee755854b7cb8c2d315e26abc828b66ae5326551a08ced3ee7ee106d8dd97e60808f561bf240bc7d67287788980cdfa01196dabf0000163797f740ad4f01d3
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'mkmf'
|
3
|
+
|
4
|
+
def get_xlib_path
|
5
|
+
exes = find_xorg_exes
|
6
|
+
libpaths = Array.new
|
7
|
+
exes.each do |exe|
|
8
|
+
if is_wrapper_script?(exe)
|
9
|
+
exe_path = extract_exe_from_wrapper(exe)
|
10
|
+
libpaths << `#{exe_path} -showDefaultLibPath 2>&1`.chomp
|
11
|
+
else
|
12
|
+
path = `#{exe} -showDefaultLibPath 2>&1`.chomp
|
13
|
+
libpaths << path if File.directory?(path)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
libpaths.uniq.first
|
18
|
+
end
|
19
|
+
|
20
|
+
# is_wrapper? takes a filepath (String)
|
21
|
+
def is_wrapper_script?(filepath)
|
22
|
+
firstline = File.open(filepath) { |f| f.readline }
|
23
|
+
not firstline.match(/^#!/).nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns an array of all files in $PATH that are named "X11", "Xorg", or "X"
|
27
|
+
def find_xorg_exes
|
28
|
+
ENV['PATH'].split(':').flat_map { |dir| Dir.glob dir + "/**/{X11,Xorg,X}" }
|
29
|
+
.find_all { |f| File.file?(f) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def extract_exe_from_wrapper(filepath)
|
33
|
+
lines = File.readlines(filepath).map { |l| l.chomp }
|
34
|
+
basedir = lines.collect { |l| l.match(/^basedir=(.*)$/) }.compact.first[1]
|
35
|
+
exe = lines.collect { |l| l.match(/exec\s+".*\/(.*)\s+/) }.compact.last[1]
|
36
|
+
"#{basedir}/#{exe}"
|
37
|
+
end
|
38
|
+
|
39
|
+
extension_name = 'XStoreName'
|
40
|
+
|
41
|
+
$LOCAL_LIBS << "-lX11 -L#{get_xlib_path}"
|
42
|
+
|
43
|
+
dir_config(extension_name)
|
44
|
+
create_header
|
45
|
+
create_makefile(extension_name)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#include <X11/Xlib.h>
|
2
|
+
#include <ruby.h>
|
3
|
+
#include <stdio.h>
|
4
|
+
#include <stdlib.h>
|
5
|
+
#include "extconf.h"
|
6
|
+
|
7
|
+
int set_xname(VALUE _self, VALUE msg)
|
8
|
+
{
|
9
|
+
Check_Type(msg, T_STRING);
|
10
|
+
VALUE result = Qnil;
|
11
|
+
|
12
|
+
Display *dpy;
|
13
|
+
Window rootwin;
|
14
|
+
int scr;
|
15
|
+
|
16
|
+
if(!(dpy=XOpenDisplay(NULL))) {
|
17
|
+
rb_raise(rb_eRuntimeError, "ERROR: could not open X11 display.");
|
18
|
+
|
19
|
+
}
|
20
|
+
|
21
|
+
scr = DefaultScreen(dpy);
|
22
|
+
rootwin = RootWindow(dpy, scr);
|
23
|
+
|
24
|
+
XStoreName(dpy, rootwin, StringValueCStr(msg));
|
25
|
+
|
26
|
+
XCloseDisplay(dpy);
|
27
|
+
|
28
|
+
return result;
|
29
|
+
}
|
30
|
+
|
31
|
+
void Init_XStoreName() {
|
32
|
+
|
33
|
+
|
34
|
+
VALUE mod = rb_define_module("XStoreName");
|
35
|
+
rb_define_module_function(mod, "set_xname", set_xname, 1);
|
36
|
+
}
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xstorename
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bucky Wolfe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A ruby wrapper around Xlib's XStoreName
|
14
|
+
email: pmigneous@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions:
|
17
|
+
- ext/xstorename/extconf.rb
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ext/xstorename/extconf.rb
|
21
|
+
- ext/xstorename/xname.c
|
22
|
+
homepage: http://github.com/igneous/ruby-xstorename
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.0.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: xstorename
|
45
|
+
test_files: []
|