class Rabbit::Frame

Attributes

geometry[RW]
logger[R]
window[R]

Public Class Methods

new(logger, canvas) click to toggle source
# File lib/rabbit/frame.rb, line 33
def initialize(logger, canvas)
  @logger = logger
  @canvas = canvas
  @geometry = nil
  @notebook = nil
  @terminal = nil
  @running = true
end

Public Instance Methods

destroyed?() click to toggle source
# File lib/rabbit/frame.rb, line 42
def destroyed?
  @window.nil? or @window.destroyed?
end
fullscreen() click to toggle source
# File lib/rabbit/frame.rb, line 65
def fullscreen
  @window.fullscreen
end
fullscreen?() click to toggle source
# File lib/rabbit/frame.rb, line 81
def fullscreen?
  @fullscreen
end
fullscreen_available?() click to toggle source
# File lib/rabbit/frame.rb, line 103
def fullscreen_available?
  true
end
height() click to toggle source
# File lib/rabbit/frame.rb, line 57
def height
  @window.size[1]
end
iconify_available?() click to toggle source
# File lib/rabbit/frame.rb, line 107
def iconify_available?
  true
end
in_terminal?() click to toggle source
# File lib/rabbit/frame.rb, line 121
def in_terminal?
  return false if @terminal.nil?
  @notebook.current_page == @notebook.page_num(@terminal)
end
init_gui(width, height, main_window, window_type=nil) click to toggle source
# File lib/rabbit/frame.rb, line 93
def init_gui(width, height, main_window, window_type=nil)
  init_window(width, height, window_type)
  @fullscreen = false
  @main_window = main_window
  @terminal.show if @terminal
  @notebook.show if @notebook
  @window.show
  @canvas.post_init_gui
end
main_window?() click to toggle source
# File lib/rabbit/frame.rb, line 85
def main_window?
  @main_window
end
parse(source, callback=nil, &block) click to toggle source
# File lib/rabbit/frame.rb, line 61
def parse(source, callback=nil, &block)
  @canvas.parse(source, callback, &block)
end
quit() click to toggle source
# File lib/rabbit/frame.rb, line 46
def quit
  @running = false
  @window.destroy unless destroyed?
  @window = nil
  true
end
toggle_fullscreen() click to toggle source
# File lib/rabbit/frame.rb, line 73
def toggle_fullscreen
  if fullscreen?
    unfullscreen
  else
    fullscreen
  end
end
toggle_terminal() click to toggle source
# File lib/rabbit/frame.rb, line 111
def toggle_terminal
  return if @terminal.nil?
  terminal_page = @notebook.page_num(@terminal)
  if @notebook.current_page == terminal_page
    @notebook.current_page = 0
  else
    @notebook.current_page = terminal_page
  end
end
unfullscreen() click to toggle source
# File lib/rabbit/frame.rb, line 69
def unfullscreen
  @window.unfullscreen
end
update_title(new_title) click to toggle source
# File lib/rabbit/frame.rb, line 89
def update_title(new_title)
  @window.title = Utils.unescape_title(new_title)
end
width() click to toggle source
# File lib/rabbit/frame.rb, line 53
def width
  @window.size[0]
end

Private Instance Methods

init_notebook() click to toggle source
# File lib/rabbit/frame.rb, line 144
    def init_notebook
      @notebook = Gtk::Notebook.new
      @notebook.show_tabs = false
      provider = Gtk::CssProvider.new
      provider.load(data: <<-CSS)
        notebook {
          border-width: 0px;
        }
      CSS
      @notebook.style_context.add_provider(provider,
                                           Gtk::StyleProvider::PRIORITY_USER)
      @window.add(@notebook)
    end
init_terminal() click to toggle source
# File lib/rabbit/frame.rb, line 208
def init_terminal
  @terminal = Vte::Terminal.new
  # TODO: Support theme
  terminal_font_description = ENV["RABBIT_TERMINAL_FONT_DESCRIPTION"]
  if terminal_font_description
    @terminal.font_desc =
      Pango::FontDescription.new(terminal_font_description)
  end
  terminal_color_foreground = ENV["RABBIT_TERMINAL_COLOR_FOREGROUND"]
  if terminal_color_foreground
    @terminal.color_foreground = terminal_color_foreground
  end
  terminal_color_background = ENV["RABBIT_TERMINAL_COLOR_BACKGROUND"]
  if terminal_color_background
    @terminal.color_background = terminal_color_background
  end
  @terminal.enable_sixel = true if @terminal.respond_to?(:enable_sixel=)
  @notebook.add(@terminal)
  pid = nil
  in_terminal = false
  @notebook.signal_connect(:switch_page) do |_, page,|
    if page == @terminal
      if @running
        pid = @terminal.spawn if pid.nil?
        @canvas.pre_terminal unless in_terminal
        in_terminal = true
      end
    else
      @canvas.post_terminal if in_terminal
      in_terminal = false
    end
  end
  @terminal.signal_connect(:child_exited) do
    pid = nil
    terminal_page = @notebook.page_num(@terminal)
    if @notebook.current_page == terminal_page
      @canvas.activate("ToggleTerminal")
    end
  end
end
init_window(width, height, window_type=nil) click to toggle source
# File lib/rabbit/frame.rb, line 127
def init_window(width, height, window_type=nil)
  window_type ||= :toplevel
  @window = Gtk::ApplicationWindow.new(::Rabbit.application)
  @window.set_default_size(width, height)
  @window.parse_geometry(@geometry) if @geometry
  @window.set_app_paintable(true)
  if defined?(Vte::Terminal)
    init_notebook
  end
  set_window_signal
  setup_dnd
  @canvas.attach_to(self, @window, @notebook)
  if defined?(Vte::Terminal)
    init_terminal
  end
end
set_window_signal() click to toggle source
# File lib/rabbit/frame.rb, line 158
def set_window_signal
  set_window_signal_window_state_event
  set_window_signal_destroy
end
set_window_signal_destroy() click to toggle source
# File lib/rabbit/frame.rb, line 182
def set_window_signal_destroy
  @window.signal_connect("destroy") do
    @canvas.detach
  end
end
set_window_signal_window_state_event() click to toggle source
# File lib/rabbit/frame.rb, line 163
def set_window_signal_window_state_event
  @window.signal_connect("window_state_event") do |widget, event|
    if event.changed_mask.fullscreen?
      @fullscreen = event.new_window_state.fullscreen?
      if @fullscreen
        @canvas.fullscreened
      else
        @canvas.unfullscreened
      end
    elsif event.changed_mask.iconified?
      if event.new_window_state.iconified?
        @canvas.iconified
      end
    end

    false
  end
end
setup_dnd() click to toggle source
# File lib/rabbit/frame.rb, line 188
def setup_dnd
  @window.drag_dest_set(:all,
                        [["text/uri-list", 0, 0],
                         ["_NETSCAPE_URL", 0, 0]],
                        :copy)
  @window.signal_connect("drag-data-received") do |*args|
    widget, context, x, y, selection_data, info, time = args
    uri = selection_data.data.chomp
    Gtk.idle_add do
      parse(Source::URI.new(nil, logger, uri))
      false
    end
    Gtk::Drag.finish(context, true, false, time)
  end

  @window.signal_connect("drag-drop") do |widget, context, x, y, time|
    true
  end
end