Project

General

Profile

unexist.dev

/

subtle

Assorted tidbits and projects

Snippets » History » Version 3

« Previous - Version 3/46 (diff) - Next » - Current version
Anonymous, 09/25/2009 12:26 PM


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
\015\012\015\012h2. Move client to view\015\012\015\012The following will help to move a client to a specific view.\015\012\015\012
\015\012def move_view(client, view_id)\015\012  begin\015\012    cur  = current_view\015\012    view = views[view_id - 1]\015\012\015\012    begin\015\012      tag = find_tag(view.name)\015\012    rescue\015\012      tag = add_tag(view.name)\015\012    end\015\012\015\012    # Remove client from current tag\015\012    if(client.has_tag?(cur.name))\015\012      client.untag(cur.name)\015\012    end\015\012\015\012    # Tag new view with itself\015\012    if(!view.has_tag?(tag))\015\012      view.tag(tag)\015\012    end\015\012\015\012    # Finally add tag to client\015\012    client.tag(tag)\015\012  rescue => err\015\012    puts err\015\012  end\015\012end\015\012\015\012GRABS = {\015\012  "A-C-1" => lambda { |c| move_view(c, 1) },\015\012  "A-C-2" => lambda { |c| move_view(c, 2) },\015\012  "A-C-3" => lambda { |c| move_view(c, 3) },\015\012  "A-C-4" => lambda { |c| move_view(c, 4) },\015\012}\015\012
\015\012\015\012h2. Copy client to view\015\012\015\012Similiar to the recipe above this will not move but copy the client to a view.\015\012\015\012
\015\012def copy_view(client, view_id) # {{{\015\012  begin\015\012    cur  = current_view\015\012    view = views[view_id - 1]\015\012\015\012    begin\015\012      tag = find_tag(view.name)\015\012    rescue\015\012      tag = add_tag(view.name)\015\012    end\015\012\015\012    # Tag new view with itself\015\012    if(!view.has_tag?(tag))\015\012      view.tag(tag)\015\012    end\015\012\015\012    # Finally add tag to client\015\012    client.tag(tag)\015\012  rescue => err\015\012    puts err\015\012  end\015\012end\015\012\015\012GRABS = {\015\012  "A-W-1" => lambda { |c| copy_view(c, 1) },\015\012  "A-W-2" => lambda { |c| copy_view(c, 2) },\015\012  "A-W-3" => lambda { |c| copy_view(c, 3) },\015\012  "A-W-4" => lambda { |c| copy_view(c, 4) },\015\012}\015\012
\015\012\015\012