Project

General

Profile

unexist.dev

subtle

Assorted tidbits and projects

Snippets » History » Version 12

Version 11 (Anonymous, 05/22/2010 01:46 AM) → Version 12/46 (Anonymous, 05/22/2010 01:46 AM)

h1. Snippets\015\012\015\012This page shows small snippets that might be useful:\015\012\015\012{{>toc}}\015\012\015\012h2. Alt-Tab\015\012\015\012This cycles through windows of view\015\012\015\012<pre>code class="ruby">\015\012"A-Tab" => lambda { |c|\015\012 sel = 0\015\012 clients = Subtlext::View[:current].clients\015\012\015\012 clients.each_index do |idx|\015\012 if(clients[idx].id == c.id)\015\012 sel = idx + 1 if(idx < clients.size - 1)\015\012 end\015\012 end\015\012\015\012 clients[sel].focus\015\012}\015\012</code></pre>\015\012\015\012h2. Gravity tiling\015\012\015\012Tiles windows vertically that share a gravity.\015\012\015\012<pre><code class="ruby">\015\012def gravity_tile(v = nil)\015\012 v ||= Subtlext::View.current\015\012\015\012 clients = v.clients\015\012 screen = Subtlext::Screen.current\015\012\015\012 assoc = {}\015\012\015\012 clients.each do |c|\015\012 begin\015\012 assoc[c.gravity.id] << c rescue assoc[c.gravity.id] = [ c ]\015\012 rescue StandardError\015\012 # Startup errors\015\012 end\015\012 end\015\012\015\012 assoc.each do |k, v|\015\012 g = Subtlext::Gravity[k]\015\012\015\012 # Calculate gravity\015\012 x, y, w, h = g.geometry_for(screen)\015\012 width = w / v.size\015\012 pos = x\015\012\015\012 v.each do |c|\015\012 c.resize = false\015\012 c.geometry = [ pos, y, width - 2 * OPTIONS[:border], h - 2 * OPTIONS[:border] ]\015\012 pos += width\015\012 end\015\012 end\015\012end\015\012</code></pre>\015\012\015\012<pre><code class="ruby">\015\012HOOKS = {\015\012 :HookTile :HookClientGravity => method(:gravity_tile).to_proc\015\012}\015\012</code></pre> lambda { |c| gravity_tile },\015\012}\015\012</code></pre>