lib/rabbit/frame.rb in rabbit-3.0.0 vs lib/rabbit/frame.rb in rabbit-3.0.1

- old
+ new

@@ -1,16 +1,19 @@ require "forwardable" require "rabbit/gtk" require "rexml/text" +begin + require "vte3" +rescue LoadError +end + require "rabbit/rabbit" require "rabbit/utils" module Rabbit - class Frame - include ScreenInfo extend Forwardable def_delegators(:@window, :icon, :icon=, :set_icon) def_delegators(:@window, :icon_list, :icon_list=, :set_icon_list) @@ -29,17 +32,21 @@ def initialize(logger, canvas) @logger = logger @canvas = canvas @geometry = nil + @notebook = nil + @terminal = nil + @running = true end def destroyed? @window.nil? or @window.destroyed? end def quit + @running = false @window.destroy unless destroyed? @window = nil true end @@ -85,10 +92,12 @@ 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 def fullscreen_available? @@ -97,22 +106,57 @@ def iconify_available? true end + 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 + + def in_terminal? + return false if @terminal.nil? + @notebook.current_page == @notebook.page_num(@terminal) + end + private 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) + @canvas.attach_to(self, @window, @notebook) + if defined?(Vte::Terminal) + init_terminal + end end + 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 + def set_window_signal set_window_signal_window_state_event set_window_signal_destroy end @@ -158,10 +202,51 @@ @window.signal_connect("drag-drop") do |widget, context, x, y, time| true end end + + 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 end class NullFrame class << self def def_null_methods(*names) @@ -182,21 +267,34 @@ end def iconify_available? false end + + def toggle_terminal + end + + def in_terminal? + false + end end class EmbedFrame < Frame - def update_title(new_title) end def fullscreen_available? false end def iconify_available? + false + end + + def toggle_terminal + end + + def in_terminal? false end def init_gui(width, height, main_window, window_type=nil) @window = Gtk::EventBox.new