Changeset 95:e12b10237a77
Updated to rely on xdg-open instead of own calls and added #browser_screen_num to set the screen the browser view is displayed
author | unexist |
---|---|
date | Wed, 01 Jun 2011 16:52:23 +0200 |
parents | ce5357c68ebb |
children | 99c48527502a |
files | ruby/launcher.rb |
diffstat | 1 files changed, 39 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/ruby/launcher.rb Mon May 30 22:54:10 2011 +0200 +++ b/ruby/launcher.rb Wed Jun 01 16:52:23 2011 +0200 @@ -8,7 +8,10 @@ # This program can be distributed under the terms of the GNU GPLv2. # See the file COPYING for details. # -# Launcher that combines modes/tagging of subtle and a browser search bar +# Launcher that combines modes/tagging of subtle and a browser search bar. +# +# It opens uris with your default browser via xdg-open. Easiest way to set +# it is to define $BROWSER in your shell rc files. # # Thanks, fauno, for your initial work! # @@ -55,17 +58,15 @@ end # Launcher class -module Subtle # {{{ - module Contrib # {{{ +module Subtle # {{{^ + module Contrib # {{{^ # Precompile regexps - RE_COMMAND = Regexp.new(/^([+\^\*]*[A-Za-z0-9_\-\/'"\s]+)(\s[@#][A-Za-z0-9_-]+)*$/) - RE_MODES = Regexp.new(/^([+\^\*]*)([A-Za-z0-9_\-\/'"\s]+)/) - RE_SEARCH = Regexp.new(/^[gs]\s*(.*)/) - RE_METHOD = Regexp.new(/^[:]\s*(.*)/) - RE_URI = Regexp.new(/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix) - RE_CHROME = Regexp.new(/chrom[e|ium]|iron/i) - RE_FIREFOX = Regexp.new(/navigator/i) - RE_OPERA = Regexp.new(/opera/i) + RE_COMMAND = Regexp.new(/^([+\^\*]*[A-Za-z0-9_\-\/'"\s]+)(\s[@#][A-Za-z0-9_-]+)*$/) + RE_MODES = Regexp.new(/^([+\^\*]*)([A-Za-z0-9_\-\/'"\s]+)/) + RE_SEARCH = Regexp.new(/^[gs]\s*(.*)/) + RE_METHOD = Regexp.new(/^[:]\s*(.*)/) + RE_URI = Regexp.new(/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix) + RE_BROWSER = Regexp.new(/(chrom[e|ium]|iron|navigator|firefox|opera)/i) # Launcher class class Launcher # {{{ @@ -75,6 +76,7 @@ @@font_big = "-*-*-medium-*-*-*-40-*-*-*-*-*-*-*" @@font_small = "-*-*-medium-*-*-*-14-*-*-*-*-*-*-*" @@paths = "/usr/bin" + @@screen_num = 0 # Singleton methods @@ -103,6 +105,15 @@ end end # }}} + ## browser_screen_num + # Set screen num to show browser view + # @param [Fixnum] num Screen number + ## + + def self.browser_screen_num=(num) + @screen_num = num if(num.is_a?(Fixnum)) + end # }}} + ## run {{{ # Run the launcher ## @@ -138,9 +149,11 @@ @cached_apps = {} # FIXME: Find config instance - ObjectSpace.each_object(Subtle::Config) do |c| - @cached_sender = c - @cached_methods = c.methods(false).map(&:to_s) + if(defined?(Subtle::Config)) + ObjectSpace.each_object(Subtle::Config) do |c| + @cached_sender = c + @cached_methods = c.methods(false).map(&:to_s) + end end # Something close to a skiplist @@ -443,23 +456,13 @@ client.flags = flags end end # }}} - when URI # {{{ + when URI # {{{^ find_browser - unless(@browser.nil?) - @view.jump - # Select browser - case @browser - when :chrome - system("chromium '%s'" % [ @candidate.to_s ]) - when :firefox - system("firefox -new-tab '%s'" % [ @candidate.to_s ]) - when :opera - system("opera -remote 'openURL(%s)'" % [ @candidate.to_s ]) - else - puts ">>> ERROR: Unsupported browser" - return - end + unless(@browser.nil?) + Subtlext::Screen[@@screen_num].view = @view + system("xdg-open '%s' &>/dev/null" % [ @candidate.to_s ]) + @browser.focus end # }}} end end @@ -488,19 +491,10 @@ begin if(@browser.nil?) Subtlext::Client.all.each do |c| - case c.klass - when RE_CHROME - @browser = :chrome - @view = c.views.first - return - when RE_FIREFOX - @browser = :firefox - @view = c.views.first - return - when RE_OPERA - @browser = :opera - @view = c.views.first - return + if(c.klass.match(RE_BROWSER)) + @browser = c + @view = c.views.first + return end end @@ -532,6 +526,9 @@ # Set paths # Subtle::Contrib::Launcher.paths = [ "/usr/bin", "~/bin" ] + # Set browser screen + Subtle::Contrib::Launcher.browser_screen_num = 0 + Subtle::Contrib::Launcher.run end