Project

General

Profile

unexist.dev

/

subtle

Assorted tidbits and projects

Snippets » History » Version 2

« Previous - Version 2/46 (diff) - Next » - Current version
Anonymous, 05/31/2009 12:17 AM


Recipes\015\012\015\012This page shows small snippets that might be useful:\015\012\015\012{{>toc}}\015\012\015\012h2. Rotate\015\012\015\012This will rotate the windows on the current view clockwise.\015\012\015\012
\015\012"S-KP_Divide" => lambda {\015\012  current_view.clients.each do |c|\015\012    c.gravity = \015\012      case(c.gravity)\015\012        when 7: 8\015\012        when 8: 6\015\012        when 9: 6\015\012        when 6: 2\015\012        when 3: 2\015\012        when 2: 4\015\012        when 1: 4\015\012        when 4: 8\015\012      end\015\012  end  \015\012}\015\012
\015\012\015\012h2. Swap\015\012\015\012This two snippets toggle the gravity mode of two windows\015\012\015\012
\015\012"S-KP_Add" => lambda {\015\012  current_view.clients.each do |c|\015\012    c.gravity = \015\012      case(c.gravity)\015\012        when 4: 4.to_mode33.to_horz\015\012        when 6: 6.to_mode66.to_horz\015\012        when 8: 8.to_mode33.to_vert\015\012        when 2: 2.to_mode66.to_vert          \015\012      end\015\012  end\015\012}\015\012
\015\012\015\012
\015\012"S-KP_Subtract" => lambda {\015\012  current_view.clients.each do |c|\015\012    c.gravity = \015\012      case(c.gravity)\015\012        when 4: 4.to_mode66.to_horz\015\012        when 6: 6.to_mode33.to_horz\015\012        when 8: 8.to_mode66.to_vert\015\012        when 2: 2.to_mode33.to_vert\015\012      end\015\012    end\015\012}\015\012
\015\012\015\012h2. Save/load\015\012\015\012These snippets save/load the gravities of the windows of the current view into/from a yaml file.\015\012\015\012
\015\012"S-KP_Add" => lambda {\015\012  require "yaml"\015\012\015\012  gravities = {}\015\012\015\012  current_view.clients.each do |c|\015\012    grav = c.gravity\015\012\015\012    grav = grav.to_horz   if(c.horz?) \015\012    grav = grav.to_vert   if(c.vert?)\015\012    grav = grav.to_mode33 if(c.mode33?)\015\012    grav = grav.to_mode66 if(c.mode66?)\015\012\015\012    gravities[c.name] = grav\015\012  end\015\012\015\012  begin\015\012    File.open(ENV["HOME"] + "/gravities.yaml", "w") { |file| file.puts(gravities.to_yaml) }\015\012  rescue\015\012    puts "Failed writing file"\015\012  end\015\012}\015\012
\015\012\015\012
\015\012"S-KP_Subtract" => lambda {\015\012  require "yaml"\015\012\015\012  gravities = {}\015\012\015\012  begin\015\012    File.open(ENV["HOME"] + "/gravities.yaml", "r") { |file|\015\012      gravities = YAML.load(file)\015\012    }\015\012  rescue\015\012    puts "Failed reading file"\015\012  end\015\012\015\012  gravities.each { |k, v|\015\012    c = find_client(k)\015\012    c.gravity = v if(!c.nil?)\015\012  }\015\012}\015\012