kasten 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b66361d2e127a00ed9a108a3f634e421ca09050
4
+ data.tar.gz: c67b4ee29dd93945a2f41d9befcc5ecb4e0f0d30
5
+ SHA512:
6
+ metadata.gz: b2afe0b3624c2823cc756424d1a5ff412c97e8126b9ce618f0e6aca5011420fb562a9ac4998da943074496de01aba1205f3248d4b558d4477d8ef506dabbbd8e
7
+ data.tar.gz: 64bad617225acaadf381b723c27b1a093d4d4866faad168f443d105487c2dac1bab81a2e8ba0680e6d56be49fa95fe1cfdea81417d59e32212d79f7bc5f7545e
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kasten.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 pachacamac
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Kasten
2
+
3
+ Let users draw a Kasten (German for box) in an X environment and get it's dimensions
4
+
5
+ ## Usage
6
+
7
+ run `gem install kasten` or add it to your Gemfile and run bundle install, then:
8
+
9
+ require 'kasten'
10
+
11
+ dimensions = Kasten.kasten
12
+ p dimensions
13
+ # => {"x"=>532, "y"=>484, "w"=>265, "h"=>187}
14
+
15
+ This gives you the raw hash.
16
+
17
+ There's also a convenience class that makes things slightly more comfortable:
18
+
19
+ box = Kasten::Box.new
20
+ # => #<Kasten::Box:0x000000015840c0 @x=265, @y=701, @w=235, @h=162>
21
+ box.x
22
+ # => 265
23
+ box.to_s
24
+ # "x: 265, y: 701, w: 235, h: 162"
25
+
26
+ Yes, it's that simple.
27
+
28
+ Here, look at a demo recorded with the screen_recorder example.
29
+
30
+ ![demo gif](examples/demo.gif)
31
+
32
+
33
+ ## Troubleshooting
34
+
35
+ If the Gem doesn't compile for you, you might need to install libx11-dev. So on Debian based systems do `sudo apt-get install libx11-dev` first.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => :spec
4
+ require "rake/extensiontask"
5
+
6
+ task :build => :compile
7
+
8
+ Rake::ExtensionTask.new("kasten") do |ext|
9
+ ext.lib_dir = "lib/kasten"
10
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kasten"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/kasten ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "kasten"
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/build.sh ADDED
@@ -0,0 +1,2 @@
1
+ echo "--- COMPILING C LIB" && rake clean compile && echo "--- BUILDING GEM" && gem build kasten.gemspec && echo "--- INSTALLING GEM" && rake install
2
+ # publish with: rake publish
data/examples/demo.gif ADDED
Binary file
@@ -0,0 +1,12 @@
1
+ # This example uses the Kasten Gem and byzanz (a small cli screencast creator)
2
+ # to let you select an area of your screen and then record a short GIF from it.
3
+ # You need to install byzanz first: sudo apt-get install byzanz
4
+
5
+ require 'kasten'
6
+
7
+ box = Kasten::Box.new
8
+
9
+ seconds = 5
10
+
11
+ puts "Recording GIF for #{seconds} seconds at #{box}"
12
+ system("byzanz-record -d #{seconds} -x #{box.x} -y #{box.y} -w #{box.w} -h #{box.h} -v -c recording.gif")
@@ -0,0 +1,4 @@
1
+ require "mkmf"
2
+
3
+ have_library('X11') || raise
4
+ create_makefile("kasten/kasten")
@@ -0,0 +1,100 @@
1
+ #include "kasten.h"
2
+
3
+ VALUE rb_mKasten;
4
+
5
+ void
6
+ Init_kasten(void) {
7
+ rb_mKasten = rb_define_module("Kasten");
8
+ rb_define_singleton_method(rb_mKasten, "kasten", method_kasten, 0);
9
+ }
10
+
11
+ VALUE method_kasten(VALUE self){
12
+ int rx = 0, ry = 0, rw = 0, rh = 0, rect_x = 0, rect_y = 0, rect_w = 0, rect_h = 0, btn_pressed = 0, done = 0;
13
+ Screen *scr = NULL;
14
+ Window root = 0;
15
+ Cursor cursor, cursor2;
16
+ XGCValues gcval;
17
+ GC gc;
18
+ VALUE r_hash;
19
+ XEvent ev;
20
+ Display *disp = XOpenDisplay(NULL);
21
+ if(!disp){ return EXIT_FAILURE; }
22
+ scr = ScreenOfDisplay(disp, DefaultScreen(disp));
23
+ root = RootWindow(disp, XScreenNumberOfScreen(scr));
24
+ cursor = XCreateFontCursor(disp, XC_left_ptr);
25
+ cursor2 = XCreateFontCursor(disp, XC_lr_angle);
26
+ gcval.foreground = XWhitePixel(disp, 0);
27
+ gcval.function = GXxor;
28
+ gcval.background = XBlackPixel(disp, 0);
29
+ gcval.plane_mask = gcval.background ^ gcval.foreground;
30
+ gcval.subwindow_mode = IncludeInferiors;
31
+ gc = XCreateGC(disp, root, GCFunction | GCForeground | GCBackground | GCSubwindowMode, &gcval);
32
+
33
+ /* this XGrab* stuff makes XPending true ? */
34
+ if ((XGrabPointer (disp, root, False, ButtonMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, root, cursor, CurrentTime) != GrabSuccess)){
35
+ printf("no mouse pointer!");
36
+ }
37
+
38
+ if ((XGrabKeyboard (disp, root, False, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess)) {
39
+ printf("no keyboard!");
40
+ }
41
+
42
+ while (!done) {
43
+ //~ while (!done && XPending(disp)) {
44
+ //~ XNextEvent(disp, &ev);
45
+ if (!XPending(disp)) { usleep(1000); continue; } // fixes the 100% CPU hog issue in original code
46
+ if ( (XNextEvent(disp, &ev) >= 0) ) {
47
+ switch (ev.type) {
48
+ case MotionNotify:
49
+ /* this case is purely for drawing rect on screen */
50
+ if (btn_pressed) {
51
+ if (rect_w) {
52
+ /* re-draw the last rect to clear it */
53
+ XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h);
54
+ } else {
55
+ /* Change the cursor to show we're selecting a region */
56
+ XChangeActivePointerGrab(disp, ButtonMotionMask | ButtonReleaseMask, cursor2, CurrentTime);
57
+ }
58
+ rect_x = rx;
59
+ rect_y = ry;
60
+ rect_w = ev.xmotion.x - rect_x;
61
+ rect_h = ev.xmotion.y - rect_y;
62
+ if (rect_w < 0) { rect_x += rect_w; rect_w = 0 - rect_w; }
63
+ if (rect_h < 0) { rect_y += rect_h; rect_h = 0 - rect_h; }
64
+ /* draw rectangle */
65
+ XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h);
66
+ XFlush(disp);
67
+ }
68
+ break;
69
+ case ButtonPress:
70
+ btn_pressed = 1;
71
+ rx = ev.xbutton.x;
72
+ ry = ev.xbutton.y;
73
+ break;
74
+ case ButtonRelease:
75
+ done = 1;
76
+ break;
77
+ }
78
+ }
79
+ }
80
+ /* clear the drawn rectangle */
81
+ if (rect_w) {
82
+ XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h);
83
+ XFlush(disp);
84
+ }
85
+ rw = ev.xbutton.x - rx;
86
+ rh = ev.xbutton.y - ry;
87
+ /* cursor moves backwards */
88
+ if (rw < 0) { rx += rw; rw = 0 - rw; }
89
+ if (rh < 0) { ry += rh; rh = 0 - rh; }
90
+
91
+ XCloseDisplay(disp);
92
+ //printf("%dx%d+%d+%d\n",rw,rh,rx,ry);
93
+
94
+ r_hash = rb_hash_new();
95
+ rb_hash_aset(r_hash, rb_str_new2("x"), INT2NUM(rx));
96
+ rb_hash_aset(r_hash, rb_str_new2("y"), INT2NUM(ry));
97
+ rb_hash_aset(r_hash, rb_str_new2("w"), INT2NUM(rw));
98
+ rb_hash_aset(r_hash, rb_str_new2("h"), INT2NUM(rh));
99
+ return r_hash;
100
+ }
@@ -0,0 +1,16 @@
1
+ #ifndef KASTEN_H
2
+ #define KASTEN_H 1
3
+
4
+ #include "ruby.h"
5
+ #include<stdio.h>
6
+ #include<stdlib.h>
7
+ #include<X11/Xlib.h>
8
+ #include<X11/cursorfont.h>
9
+ #include<unistd.h>
10
+
11
+ void Init_kasten(void);
12
+ VALUE method_kasten(VALUE self);
13
+
14
+ extern VALUE rb_mKasten;
15
+
16
+ #endif /* KASTEN_H */
data/kasten.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kasten/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kasten"
8
+ spec.version = Kasten::VERSION
9
+ spec.authors = ["pachacamac"]
10
+ spec.email = ["pachacamac@inboxalias.com"]
11
+
12
+ spec.summary = %q{Create a Kasten (German for box)}
13
+ spec.description = %q{Let users draw a Kasten (German for box) in an X environment and get it's dimensions}
14
+ spec.homepage = "https://github.com/pachacamac/kasten"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "bin"
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+ spec.extensions = ["ext/kasten/extconf.rb"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rake-compiler"
26
+ end
data/lib/kasten.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'kasten/version'
2
+ require 'kasten/kasten'
3
+
4
+ module Kasten
5
+ class Box
6
+ attr_reader :x, :y, :w, :h
7
+ def initialize
8
+ d = Kasten.kasten
9
+ @x = d['x']
10
+ @y = d['y']
11
+ @w = d['w']
12
+ @h = d['h']
13
+ end
14
+
15
+ def to_s
16
+ "x: #{@x}, y: #{@y}, w: #{@w}, h: #{@h}"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Kasten
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kasten
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - pachacamac
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Let users draw a Kasten (German for box) in an X environment and get
56
+ it's dimensions
57
+ email:
58
+ - pachacamac@inboxalias.com
59
+ executables:
60
+ - console
61
+ - kasten
62
+ - setup
63
+ extensions:
64
+ - ext/kasten/extconf.rb
65
+ extra_rdoc_files: []
66
+ files:
67
+ - ".gitignore"
68
+ - ".travis.yml"
69
+ - CODE_OF_CONDUCT.md
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - bin/console
75
+ - bin/kasten
76
+ - bin/setup
77
+ - build.sh
78
+ - examples/demo.gif
79
+ - examples/screen_recorder.rb
80
+ - ext/kasten/extconf.rb
81
+ - ext/kasten/kasten.c
82
+ - ext/kasten/kasten.h
83
+ - kasten.gemspec
84
+ - lib/kasten.rb
85
+ - lib/kasten/version.rb
86
+ homepage: https://github.com/pachacamac/kasten
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.5.1
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Create a Kasten (German for box)
110
+ test_files: []