Project

General

Profile

unexist.dev

/

subtle

Assorted tidbits and projects

Subtlext » History » Version 72

Anonymous, 06/21/2009 03:07 PM

1 72
h1. Subtlext\015\012\015\012[[Subtlext]] is an extension that brings the power of [[subtler]] to "Ruby":http://www.ruby-lang.org. This page includes the API with small examples of every method and some advanced examples at the bottom of the page. Some of this examples are also included in the tarball.\015\012\015\012Unit tests for [[Subtlext|sublext]] are also included. [[Development|Read more about unit tests]]\015\012\015\012{{>toc}}\015\012\015\012h2. Client\015\012\015\012h3. Attributes\015\012\015\012*id*, *win*, *name*, *gravity*, *x*, *y*, *width*, *height*\015\012\015\012h3. views()\015\012\015\012Get array of views client is on\015\012<pre><code class="ruby">\015\012client.views\015\012=> [#<Subtlext::View:xxx>, #<Subtlext::View:xxx>]\015\012\015\012client.views\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. tags()\015\012\015\012Get array of defined tags\015\012<pre><code class="ruby">\015\012client.tags\015\012=> [#<Subtlext::Tag:xxx>, #<Subtlext::Tag:xxx>]\015\012\015\012client.tags\015\012=> []\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. tag(name)\015\012\015\012Tag client with given name or tag object\015\012<pre><code class="ruby">\015\012client.tag("subtle")\015\012=> #<Subtlext::Tag:xxx>\015\012\015\012client.tag(Subtlext::Tag.new("subtle"))\015\012=> #<Subtlext::Tag:xxx>\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. untag(name)\015\012\015\012Untag client with given name or tag object\015\012<pre><code class="ruby">\015\012client.untag("subtle")\015\012=> nil\015\012\015\012client.untag(subtle.find_tag("subtle"))\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. toggle_full()\015\012\015\012Toggle fullscreen state\015\012<pre><code class="ruby">\015\012client.toggle_full\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. toggle_float()\015\012\015\012Toggle floating state\015\012<pre><code class="ruby">\015\012client.toggle_float\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. toggle_stick()\015\012\015\012Toggle urgent state\015\012<pre><code class="ruby">\015\012client.toggle_float\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. raise()\015\012\015\012Raise window\015\012<pre><code class="ruby">\015\012client.raise\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. lower()\015\012\015\012Lower window\015\012<pre><code class="ruby">\015\012client.lower\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. up()\015\012\015\012Get client above\015\012<pre><code class="ruby">\015\012client.up\015\012=> #<Subtlext::Client:xxx>\015\012\015\012client.up\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. left()\015\012\015\012Get client left\015\012<pre><code class="ruby">\015\012client.left\015\012=> #<Subtlext::Client:xxx>\015\012\015\012client.left\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. right()\015\012\015\012Get client right\015\012<pre><code class="ruby">\015\012client.right\015\012=> #<Subtlext::Client:xxx>\015\012\015\012client.right\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. down()\015\012\015\012Get client below\015\012<pre><code class="ruby">\015\012client.down\015\012=> #<Subtlext::Client:xxx>\015\012\015\012client.down\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. focus()\015\012\015\012Set focus to client\015\012<pre><code class="ruby">\015\012client.focus\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. focus?\015\012\015\012Check if client is focussed\015\012<pre><code class="ruby">\015\012client.focus?\015\012=> true\015\012\015\012client.focus?\015\012=> false\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. to_s()\015\012\015\012Convert client object to string\015\012<pre><code class="ruby">\015\012puts client\015\012=> "subtle"\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. gravity()\015\012\015\012Get client gravity\015\012<pre><code class="ruby">\015\012client.gravity\015\012=> 5\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. gravity=\015\012\015\012Set client gravity\015\012<pre><code class="ruby">\015\012client.gravity = 5\015\012=> 5\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. size()\015\012\015\012Get client size\015\012<pre><code class="ruby">\015\012client.size\015\012=> [ 0, 0, 100, 100 ]\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. size=\015\012\015\012Set client size\015\012<pre><code class="ruby">\015\012client.size = [ 0, 0, 100, 100 ]\015\012=> [ 0, 0, 100, 100 ]\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. horz?\015\012\015\012Check if client has horizontal gravity\015\012<pre><code class="ruby">\015\012client.horz?\015\012=> true\015\012\015\012client.horz?\015\012=> false\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. vert?\015\012\015\012Check if client has vertical gravity\015\012<pre><code class="ruby">\015\012client.vert?\015\012=> true\015\012\015\012client.vert?\015\012=> false\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. mode33?\015\012\015\012Check if client has mode33 gravity\015\012<pre><code class="ruby">\015\012client.mode33?\015\012=> true\015\012\015\012client.mode33?\015\012=> false\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. mode33?\015\012\015\012Check if client has mode66 gravity\015\012<pre><code class="ruby">\015\012client.mode66?\015\012=> true\015\012\015\012client.mode66?\015\012=> false\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. &#43;\015\012\015\012Add tag to client\015\012<pre><code class="ruby">\015\012client + tag\015\012=> nil\015\012\015\012client + "subtle"\015\012=> true\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. &#45;\015\012\015\012Remove tag from client\015\012<pre><code class="ruby">\015\012client - tag\015\012=> nil\015\012\015\012client - "subtle"\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h2. Gravity\015\012\015\012h3. Constants\015\012\015\012<pre><code class="ruby">\015\012TopLeft     = 7\015\012Top         = 8\015\012TopRight    = 9\015\012Left        = 4\015\012Center      = 5\015\012Right       = 6\015\012BottomLeft  = 1\015\012Bottom      = 2\015\012BottomRight = 3\015\012</code></pre>\015\012\015\012h2. Fixnum\015\012\015\012h3. to_horz()\015\012\015\012Convert fixnum to horz\015\012<pre><code class="ruby">\015\0121.to_horz\015\012=> 33\015\012</code></pre>\015\012\015\012h3. to_vert()\015\012\015\012Convert fixnum to vert\015\012<pre><code class="ruby">\015\0121.to_vert\015\012=> 65\015\012</code></pre>\015\012\015\012h3. to_mode33()\015\012\015\012Convert fixnum to mode33\015\012<pre><code class="ruby">\015\0121.to_mode33\015\012=> 129\015\012</code></pre>\015\012\015\012h3. to_mode66()\015\012\015\012Convert fixnum to mode66\015\012<pre><code class="ruby">\015\0121.to_mode66\015\012=> 257\015\012</code></pre>\015\012\015\012h2. Subtle\015\012\015\012h3. new(display, debug)\015\012\015\012Create a new [[Subtle|subtle]] object and open connection to X server\015\012<pre><code class="ruby">\015\012subtle = Subtlext::Subtle.new(":0")\015\012=> #<Subtlext::Subtle:xxx>\015\012\015\012subtle = Subtlext::Subtle.new(":0", true)\015\012<DEBUG> src/subtlext/subtlext.c:165: Connection opened (:0)\015\012=> #<Subtlext::Subtle:xxx>\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. new2(display)\015\012\015\012Create a new [[Subtle|subtle]] object *internally used only*\015\012<pre><code class="ruby">\015\012subtle = Subtlext::Subtle.new(display)\015\012=> #<Subtlext::Subtle:xxx>\015\012\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012h3. version()\015\012\015\012Get the version of [[Subtlext|subtlext]]\015\012<pre><code class="ruby">\015\012puts subtle.version \015\012=> 0.8\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. display()\015\012\015\012Get the display name\015\012<pre><code class="ruby">\015\012subtle.display\015\012=> :0\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. views()\015\012\015\012Get array of defined views\015\012<pre><code class="ruby">\015\012subtle.views\015\012=> [#<Subtlext::View:xxx>, #<Subtlext::View:xxx>]\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. tags()\015\012\015\012Get array of defined tags\015\012<pre><code class="ruby">\015\012subtle.tags\015\012=> [#<Subtlext::Tag:xxx>, #<Subtlext::Tag:xxx>]\015\012\015\012subtle.tags\015\012=> []\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. clients()\015\012\015\012Get array of clients\015\012<pre><code class="ruby">\015\012subtle.clients\015\012=> [#<Subtlext::Client:xxx>, #<Subtlext::Client:xxx>]\015\012\015\012subtle.clients\015\012=> []\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. find_view(name)\015\012\015\012Find view by given name\015\012<pre><code class="ruby">\015\012subtle.find_view("subtle")\015\012=> #<Subtlext::View:xxx>\015\012\015\012subtle.find_view("subtle")\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. find_tag(name)\015\012\015\012Find tag by given name\015\012<pre><code class="ruby">\015\012subtle.find_tag("subtle")\015\012=> #<Subtlext::Tag:xxx>\015\012\015\012subtle.find_tag("subtle")\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. find_client(name)\015\012\015\012Find tag by given name\015\012<pre><code class="ruby">\015\012subtle.find_client("subtle")\015\012=> #<Subtlext::Client:xxx>\015\012\015\012subtle.find_client("subtle")\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. focus_client(name)\015\012\015\012Find tag by given name and set focus\015\012<pre><code class="ruby">\015\012subtle.focus_client("subtle")\015\012=> #<Subtlext::Client:xxx>\015\012\015\012subtle.focus_client("subtle")\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. focus_left()\015\012\015\012Focus window left from current client\015\012<pre><code class="ruby">\015\012subtle.focus_left\015\012=> #<Subtlext::Client:xxx>\015\012\015\012subtle.focus_left\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. focus_down()\015\012\015\012Focus window below from current client\015\012<pre><code class="ruby">\015\012subtle.focus_down\015\012=> #<Subtlext::Client:xxx>\015\012\015\012subtle.focus_down\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. focus_up()\015\012\015\012Focus window above from current client\015\012<pre><code class="ruby">\015\012subtle.focus_up\015\012=> #<Subtlext::Client:xxx>\015\012\015\012subtle.focus_up\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. focus_right()\015\012\015\012Focus window right from current client\015\012<pre><code class="ruby">\015\012subtle.focus_right\015\012=> #<Subtlext::Client:xxx>\015\012\015\012subtle.focus_right\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. add_view(name)\015\012\015\012Add view with given name or view object\015\012<pre><code class="ruby">\015\012subtle.add_view("subtle")\015\012=> #<Subtlext::View:xxx>\015\012\015\012subtle.add_view(View.new("subtle"))\015\012=> #<Subtlext::View:xxx>\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. add_tag(name)\015\012\015\012Add tag with given name or tag object\015\012<pre><code class="ruby">\015\012subtle.add_tag("subtle")\015\012=> #<Subtlext::Tag:xxx>\015\012\015\012subtle.add_tag(Tag.new("subtle"))\015\012=> #<Subtlext::Tag:xxx>\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. del_client(name)\015\012\015\012Delete client by given name or client object\015\012<pre><code class="ruby">\015\012subtle.del_client("subtle")\015\012=> nil\015\012\015\012subtle.del_client(subtle.find_client("subtle"))\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. del_sublet(name)\015\012\015\012Delete sublet by given name\015\012<pre><code class="ruby">\015\012subtle.del_sublet("subtle")\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. del_tag(name)\015\012\015\012Delete tag by given name or tag object\015\012<pre><code class="ruby">\015\012subtle.del_tag("subtle")\015\012=> nil\015\012\015\012subtle.del_tag(subtle.find_tag("subtle"))\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. del_view(name)\015\012\015\012Delete view by given name or view object\015\012<pre><code class="ruby">\015\012subtle.del_view("subtle")\015\012=> nil\015\012\015\012subtle.del_view(subtle.find_view("subtle"))\015\012=> nil\015\012\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. current_view()\015\012\015\012Get current active view\015\012<pre><code class="ruby">\015\012subtle.current_view\015\012=> #<Subtlext::View:xxx>\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. current_client()\015\012\015\012Get current active client\015\012<pre><code class="ruby">\015\012subtle.current_client\015\012=> #<Subtlext::Client:xxx>\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. running?()\015\012\015\012Check if [[Subtle|subtle]] is running\015\012<pre><code class="ruby">\015\012subtle.running?\015\012=> true\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. reload()\015\012\015\012Reload config of [[Subtle|subtle]]\015\012<pre><code class="ruby">\015\012subtle.reload\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. quit()\015\012\015\012Quit [[Subtle|subtle]]\015\012<pre><code class="ruby">\015\012subtle.reload\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. to_s()\015\012\015\012Convert subtle object to string\015\012<pre><code class="ruby">\015\012puts subtle\015\012=> subtle (0.8.1113) on :2.0 (800x600)\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h2. Sublet\015\012\015\012h3. update()\015\012\015\012Update data of sublet\015\012<pre><code class="ruby">\015\012sublet.update\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. to_s()\015\012\015\012Convert sublet object to string\015\012<pre><code class="ruby">\015\012puts sublet\015\012=> sublet\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h2. Tag\015\012\015\012h3. Attributes\015\012\015\012*id*, *name*\015\012\015\012h3. new(name)\015\012\015\012Create new tag object\015\012<pre><code class="ruby">\015\012tag = Tag.new("subtle")\015\012=> #<Subtlext::Tag:xxx>\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. taggings()\015\012\015\012Get array of clients and views that are tagged with this\015\012<pre><code class="ruby">\015\012tag.taggings()\015\012=> [#<Subtlext::View:xxx>, #<Client:xxx>]\015\012\015\012tag.taggings()\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. save()\015\012\015\012Saves the tag and sends it to [[subtle]]\015\012<pre><code class="ruby">\015\012tag.save\015\012=> #<Subtlext::Tag:xxx>\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. to_s()\015\012\015\012Convert tag object to string\015\012<pre><code class="ruby">\015\012puts tag\015\012=> "subtle"\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h2. View\015\012\015\012h3. Attributes\015\012\015\012*id*, *win*, *name*\015\012\015\012h3. new(name)\015\012\015\012Create a new view object\015\012<pre><code class="ruby">\015\012view = Subtlext::View.new("subtle")\015\012=> #<Subtlext::View:xxx>\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. clients()\015\012\015\012Get array of clients on this view\015\012<pre><code class="ruby">\015\012view.clients\015\012=> [#<Subtlext::Client:xxx>, #<Subtlext::Client:xxx>]\015\012\015\012view.clients\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. tags()\015\012\015\012Get array of defined tags\015\012<pre><code class="ruby">\015\012view.tags\015\012=> [#<Subtlext::Tag:xxx>, #<Subtlext::Tag:xxx>]\015\012\015\012view.tags\015\012=> []\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. tag(name)\015\012\015\012Tag view with with given name or tag object\015\012<pre><code class="ruby">\015\012view.tag("subtle")\015\012=> #<Subtlext::Tag:xxx>\015\012\015\012view.tag(Tag.new("subtle"))\015\012=> #<Subtlext::Tag:xxx>\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. untag(name)\015\012\015\012Untag view with with given name or tag object\015\012<pre><code class="ruby">\015\012view.untag("subtle")\015\012=> nil\015\012\015\012view.untag(subtle.find_tag("subtle"))\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. jump()\015\012\015\012Jump to this view\015\012<pre><code class="ruby">\015\012view.jump()\015\012=> nil\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. current?\015\012\015\012Check if this view is the current active view\015\012<pre><code class="ruby">\015\012view.current?\015\012=> true\015\012\015\012view.current?\015\012=> false\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. save()\015\012\015\012Saves the view and sends it to [[subtle]]\015\012<pre><code class="ruby">\015\012view.save\015\012=> #<Subtlext::View:xxx>\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. to_s()\015\012\015\012Convert view object to string\015\012<pre><code class="ruby">\015\012puts view\015\012=> "subtle"\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. &#43;\015\012\015\012Add tag to view\015\012<pre><code class="ruby">\015\012view + tag\015\012=> true\015\012\015\012view + "subtle"\015\012=> true\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h3. &#45;\015\012\015\012Remove tag from view\015\012<pre><code class="ruby">\015\012view - tag\015\012=> true\015\012\015\012view - "subtle"\015\012=> true\015\012</code></pre>\015\012\015\012[[Subtlext#1|top]]\015\012\015\012h2. Examples\015\012\015\012This time a more complex example to show what you can do with this extension:\015\012\015\012<pre><code class="ruby">\015\012require("subtle/subtlext")\015\012\015\012subtle = Subtlext::Subtle.new(":2")\015\012\015\012puts "subtle %s on %s" % \015\012  [subtle.version, subtle.running? ? subtle.display : "none"]\015\012\015\012puts "Tags: %s" % [subtle.tags.join(", ")]\015\012\015\012# Views\015\012views = []\015\012subtle.views.each do |v|\015\012  views.push("%s (%s)" % [v.current? ? "[#{v}]" : v, v.tags.join(", ")])\015\012end\015\012puts "Views: %s" % [views.join(", ")]\015\012\015\012# Clients\015\012clients = []\015\012subtle.clients.each do |c|\015\012  clients.push("%s (%s)" % [c, c.tags.join(", ")])\015\012end\015\012puts "Clients: %s" % [clients.join(", ")]\015\012</code></pre>\015\012\015\012Output:\015\012<pre><code>subtle 0.8.1017 on :2.0\015\012Tags: default, float, full, editor, video, browser, terms\015\012Views: web (default, browser), [dev] (editor, terms), work (video, browser, terms)\015\012Clients: xterm (terms), xterm (terms)\015\012</code></pre>\015\012\015\012More examples are in the tarball in *dist/scripts*. Currently there is the example from above (*example.rb*), an example for a web interface with "Sinatra":http://sinatra.rubyforge.org/ (*web.rb*) and an interface with "Ruby-Gtk":http://ruby-gnome2.sourceforge.jp (*gtk.rb*).\015\012\015\012[[Subtlext#1|top]]